| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 4 | * use this file except in compliance with the License. You may obtain a copy of |
| 5 | * the License at |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8 | * |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | * License for the specific language governing permissions and limitations under |
| 13 | * the License. |
| 14 | */ |
| 15 | |
| 16 | package com.android.server; |
| 17 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 18 | import com.android.internal.content.PackageMonitor; |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 19 | import com.android.internal.os.AtomicFile; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import com.android.internal.os.HandlerCaller; |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 21 | import com.android.internal.util.FastXmlSerializer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import com.android.internal.view.IInputContext; |
| 23 | import com.android.internal.view.IInputMethod; |
| 24 | import com.android.internal.view.IInputMethodCallback; |
| 25 | import com.android.internal.view.IInputMethodClient; |
| 26 | import com.android.internal.view.IInputMethodManager; |
| 27 | import com.android.internal.view.IInputMethodSession; |
| 28 | import com.android.internal.view.InputBindResult; |
| Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 29 | import com.android.server.EventLogTags; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 31 | import org.xmlpull.v1.XmlPullParser; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import org.xmlpull.v1.XmlPullParserException; |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 33 | import org.xmlpull.v1.XmlSerializer; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
| 35 | import android.app.ActivityManagerNative; |
| 36 | import android.app.AlertDialog; |
| satok | f90a33e | 2011-07-19 11:55:52 +0900 | [diff] [blame] | 37 | import android.app.KeyguardManager; |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 38 | import android.app.Notification; |
| 39 | import android.app.NotificationManager; |
| Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 40 | import android.app.PendingIntent; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.content.ComponentName; |
| 42 | import android.content.ContentResolver; |
| 43 | import android.content.Context; |
| 44 | import android.content.DialogInterface; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.content.DialogInterface.OnCancelListener; |
| 46 | import android.content.Intent; |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 47 | import android.content.IntentFilter; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.content.ServiceConnection; |
| Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 49 | import android.content.pm.ApplicationInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.content.pm.PackageManager; |
| Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 51 | import android.content.pm.PackageManager.NameNotFoundException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.content.pm.ResolveInfo; |
| 53 | import android.content.pm.ServiceInfo; |
| Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 54 | import android.content.res.Configuration; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.res.Resources; |
| 56 | import android.content.res.TypedArray; |
| 57 | import android.database.ContentObserver; |
| Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 58 | import android.inputmethodservice.InputMethodService; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.os.Binder; |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 60 | import android.os.Environment; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | import android.os.Handler; |
| 62 | import android.os.IBinder; |
| 63 | import android.os.IInterface; |
| 64 | import android.os.Message; |
| 65 | import android.os.Parcel; |
| 66 | import android.os.RemoteException; |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 67 | import android.os.ResultReceiver; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.os.ServiceManager; |
| 69 | import android.os.SystemClock; |
| 70 | import android.provider.Settings; |
| Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 71 | import android.provider.Settings.Secure; |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 72 | import android.provider.Settings.SettingNotFoundException; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.text.TextUtils; |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 74 | import android.text.style.SuggestionSpan; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.util.EventLog; |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 76 | import android.util.LruCache; |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 77 | import android.util.Pair; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import android.util.PrintWriterPrinter; |
| 79 | import android.util.Printer; |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 80 | import android.util.Slog; |
| 81 | import android.util.Xml; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.view.IWindowManager; |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 83 | import android.view.LayoutInflater; |
| 84 | import android.view.View; |
| 85 | import android.view.ViewGroup; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.view.WindowManager; |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 87 | import android.view.inputmethod.EditorInfo; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import android.view.inputmethod.InputBinding; |
| 89 | import android.view.inputmethod.InputMethod; |
| 90 | import android.view.inputmethod.InputMethodInfo; |
| 91 | import android.view.inputmethod.InputMethodManager; |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 92 | import android.view.inputmethod.InputMethodSubtype; |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 93 | import android.widget.ArrayAdapter; |
| 94 | import android.widget.RadioButton; |
| 95 | import android.widget.TextView; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 97 | import java.io.File; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import java.io.FileDescriptor; |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 99 | import java.io.FileInputStream; |
| 100 | import java.io.FileOutputStream; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import java.io.IOException; |
| 102 | import java.io.PrintWriter; |
| 103 | import java.util.ArrayList; |
| Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 104 | import java.util.Comparator; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | import java.util.HashMap; |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 106 | import java.util.HashSet; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | import java.util.List; |
| satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 108 | import java.util.TreeMap; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * This class provides a system service that manages input methods. |
| 112 | */ |
| 113 | public class InputMethodManagerService extends IInputMethodManager.Stub |
| 114 | implements ServiceConnection, Handler.Callback { |
| 115 | static final boolean DEBUG = false; |
| 116 | static final String TAG = "InputManagerService"; |
| 117 | |
| 118 | static final int MSG_SHOW_IM_PICKER = 1; |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 119 | static final int MSG_SHOW_IM_SUBTYPE_PICKER = 2; |
| satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 120 | static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 3; |
| satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 121 | static final int MSG_SHOW_IM_CONFIG = 4; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 122 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | static final int MSG_UNBIND_INPUT = 1000; |
| 124 | static final int MSG_BIND_INPUT = 1010; |
| 125 | static final int MSG_SHOW_SOFT_INPUT = 1020; |
| 126 | static final int MSG_HIDE_SOFT_INPUT = 1030; |
| 127 | static final int MSG_ATTACH_TOKEN = 1040; |
| 128 | static final int MSG_CREATE_SESSION = 1050; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 129 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | static final int MSG_START_INPUT = 2000; |
| 131 | static final int MSG_RESTART_INPUT = 2010; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 132 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | static final int MSG_UNBIND_METHOD = 3000; |
| 134 | static final int MSG_BIND_METHOD = 3010; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 135 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | static final long TIME_TO_RECONNECT = 10*1000; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 137 | |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 138 | static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20; |
| 139 | |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 140 | private static final int NOT_A_SUBTYPE_ID = -1; |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 141 | private static final String NOT_A_SUBTYPE_ID_STR = String.valueOf(NOT_A_SUBTYPE_ID); |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 142 | private static final String SUBTYPE_MODE_KEYBOARD = "keyboard"; |
| 143 | private static final String SUBTYPE_MODE_VOICE = "voice"; |
| satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 144 | private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher"; |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 145 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | final Context mContext; |
| Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 147 | final Resources mRes; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | final Handler mHandler; |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 149 | final InputMethodSettings mSettings; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | final SettingsObserver mSettingsObserver; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | final IWindowManager mIWindowManager; |
| 152 | final HandlerCaller mCaller; |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 153 | private final InputMethodFileManager mFileManager; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 154 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | final InputBindResult mNoBinding = new InputBindResult(null, null, -1); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 156 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | // All known input methods. mMethodMap also serves as the global |
| 158 | // lock for this class. |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 159 | final ArrayList<InputMethodInfo> mMethodList = new ArrayList<InputMethodInfo>(); |
| 160 | final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<String, InputMethodInfo>(); |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 161 | private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans = |
| 162 | new LruCache<SuggestionSpan, InputMethodInfo>(SECURE_SUGGESTION_SPANS_MAX_SIZE); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 163 | |
| Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 164 | // Used to bring IME service up to visible adjustment while it is being shown. |
| 165 | final ServiceConnection mVisibleConnection = new ServiceConnection() { |
| 166 | @Override public void onServiceConnected(ComponentName name, IBinder service) { |
| 167 | } |
| 168 | |
| 169 | @Override public void onServiceDisconnected(ComponentName name) { |
| 170 | } |
| 171 | }; |
| 172 | boolean mVisibleBound = false; |
| 173 | |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 174 | // Ongoing notification |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 175 | private NotificationManager mNotificationManager; |
| 176 | private KeyguardManager mKeyguardManager; |
| 177 | private StatusBarManagerService mStatusBar; |
| 178 | private Notification mImeSwitcherNotification; |
| 179 | private PendingIntent mImeSwitchPendingIntent; |
| satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 180 | private boolean mShowOngoingImeSwitcherForPhones; |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 181 | private boolean mNotificationShown; |
| 182 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | class SessionState { |
| 184 | final ClientState client; |
| 185 | final IInputMethod method; |
| 186 | final IInputMethodSession session; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 187 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | @Override |
| 189 | public String toString() { |
| 190 | return "SessionState{uid " + client.uid + " pid " + client.pid |
| 191 | + " method " + Integer.toHexString( |
| 192 | System.identityHashCode(method)) |
| 193 | + " session " + Integer.toHexString( |
| 194 | System.identityHashCode(session)) |
| 195 | + "}"; |
| 196 | } |
| 197 | |
| 198 | SessionState(ClientState _client, IInputMethod _method, |
| 199 | IInputMethodSession _session) { |
| 200 | client = _client; |
| 201 | method = _method; |
| 202 | session = _session; |
| 203 | } |
| 204 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 205 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | class ClientState { |
| 207 | final IInputMethodClient client; |
| 208 | final IInputContext inputContext; |
| 209 | final int uid; |
| 210 | final int pid; |
| 211 | final InputBinding binding; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 212 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | boolean sessionRequested; |
| 214 | SessionState curSession; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 215 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | @Override |
| 217 | public String toString() { |
| 218 | return "ClientState{" + Integer.toHexString( |
| 219 | System.identityHashCode(this)) + " uid " + uid |
| 220 | + " pid " + pid + "}"; |
| 221 | } |
| 222 | |
| 223 | ClientState(IInputMethodClient _client, IInputContext _inputContext, |
| 224 | int _uid, int _pid) { |
| 225 | client = _client; |
| 226 | inputContext = _inputContext; |
| 227 | uid = _uid; |
| 228 | pid = _pid; |
| 229 | binding = new InputBinding(null, inputContext.asBinder(), uid, pid); |
| 230 | } |
| 231 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 232 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | final HashMap<IBinder, ClientState> mClients |
| 234 | = new HashMap<IBinder, ClientState>(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 235 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | /** |
| Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 237 | * Set once the system is ready to run third party code. |
| 238 | */ |
| 239 | boolean mSystemReady; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 240 | |
| Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 241 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | * Id of the currently selected input method. |
| 243 | */ |
| 244 | String mCurMethodId; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 245 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | /** |
| 247 | * The current binding sequence number, incremented every time there is |
| 248 | * a new bind performed. |
| 249 | */ |
| 250 | int mCurSeq; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 251 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | /** |
| 253 | * The client that is currently bound to an input method. |
| 254 | */ |
| 255 | ClientState mCurClient; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 256 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | /** |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 258 | * The last window token that gained focus. |
| 259 | */ |
| 260 | IBinder mCurFocusedWindow; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 261 | |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 262 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | * The input context last provided by the current client. |
| 264 | */ |
| 265 | IInputContext mCurInputContext; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 266 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | /** |
| 268 | * The attributes last provided by the current client. |
| 269 | */ |
| 270 | EditorInfo mCurAttribute; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 271 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | /** |
| 273 | * The input method ID of the input method service that we are currently |
| 274 | * connected to or in the process of connecting to. |
| 275 | */ |
| 276 | String mCurId; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 277 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | /** |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 279 | * The current subtype of the current input method. |
| 280 | */ |
| 281 | private InputMethodSubtype mCurrentSubtype; |
| 282 | |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 283 | // This list contains the pairs of InputMethodInfo and InputMethodSubtype. |
| satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 284 | private final HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>> |
| 285 | mShortcutInputMethodsAndSubtypes = |
| 286 | new HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>>(); |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 287 | |
| 288 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | * Set to true if our ServiceConnection is currently actively bound to |
| 290 | * a service (whether or not we have gotten its IBinder back yet). |
| 291 | */ |
| 292 | boolean mHaveConnection; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 293 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | /** |
| 295 | * Set if the client has asked for the input method to be shown. |
| 296 | */ |
| 297 | boolean mShowRequested; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 298 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | /** |
| 300 | * Set if we were explicitly told to show the input method. |
| 301 | */ |
| 302 | boolean mShowExplicitlyRequested; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 303 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | /** |
| 305 | * Set if we were forced to be shown. |
| 306 | */ |
| 307 | boolean mShowForced; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 308 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | /** |
| 310 | * Set if we last told the input method to show itself. |
| 311 | */ |
| 312 | boolean mInputShown; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 313 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | /** |
| 315 | * The Intent used to connect to the current input method. |
| 316 | */ |
| 317 | Intent mCurIntent; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 318 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | /** |
| 320 | * The token we have made for the currently active input method, to |
| 321 | * identify it in the future. |
| 322 | */ |
| 323 | IBinder mCurToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 324 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | /** |
| 326 | * If non-null, this is the input method service we are currently connected |
| 327 | * to. |
| 328 | */ |
| 329 | IInputMethod mCurMethod; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 330 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | /** |
| 332 | * Time that we last initiated a bind to the input method, to determine |
| 333 | * if we should try to disconnect and reconnect to it. |
| 334 | */ |
| 335 | long mLastBindTime; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 336 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | /** |
| 338 | * Have we called mCurMethod.bindInput()? |
| 339 | */ |
| 340 | boolean mBoundToMethod; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 341 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | /** |
| 343 | * Currently enabled session. Only touched by service thread, not |
| 344 | * protected by a lock. |
| 345 | */ |
| 346 | SessionState mEnabledSession; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 347 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | /** |
| 349 | * True if the screen is on. The value is true initially. |
| 350 | */ |
| 351 | boolean mScreenOn = true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 352 | |
| Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 353 | int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; |
| 354 | int mImeWindowVis; |
| 355 | |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 356 | private AlertDialog.Builder mDialogBuilder; |
| 357 | private AlertDialog mSwitchingDialog; |
| 358 | private InputMethodInfo[] mIms; |
| 359 | private int[] mSubtypeIds; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 360 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 361 | class SettingsObserver extends ContentObserver { |
| 362 | SettingsObserver(Handler handler) { |
| 363 | super(handler); |
| 364 | ContentResolver resolver = mContext.getContentResolver(); |
| 365 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 366 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this); |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 367 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| satok | b6109bb | 2011-02-03 22:24:54 +0900 | [diff] [blame] | 368 | Settings.Secure.ENABLED_INPUT_METHODS), false, this); |
| 369 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 370 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 372 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | @Override public void onChange(boolean selfChange) { |
| 374 | synchronized (mMethodMap) { |
| 375 | updateFromSettingsLocked(); |
| 376 | } |
| 377 | } |
| 378 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 379 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | class ScreenOnOffReceiver extends android.content.BroadcastReceiver { |
| 381 | @Override |
| 382 | public void onReceive(Context context, Intent intent) { |
| 383 | if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { |
| 384 | mScreenOn = true; |
| 385 | } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { |
| 386 | mScreenOn = false; |
| satok | 15452a4 | 2011-10-28 17:58:28 +0900 | [diff] [blame] | 387 | setImeWindowVisibilityStatusHiddenLocked(); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 388 | } else if (intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) { |
| 389 | hideInputMethodMenu(); |
| 390 | return; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 391 | } else { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 392 | Slog.w(TAG, "Unexpected intent " + intent); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | // Inform the current client of the change in active status |
| 396 | try { |
| 397 | if (mCurClient != null && mCurClient.client != null) { |
| 398 | mCurClient.client.setActive(mScreenOn); |
| 399 | } |
| 400 | } catch (RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 401 | Slog.w(TAG, "Got RemoteException sending 'screen on/off' notification to pid " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | + mCurClient.pid + " uid " + mCurClient.uid); |
| 403 | } |
| 404 | } |
| 405 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 406 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 407 | class MyPackageMonitor extends PackageMonitor { |
| 408 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | @Override |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 410 | public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | synchronized (mMethodMap) { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 412 | String curInputMethodId = Settings.Secure.getString(mContext |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| 414 | final int N = mMethodList.size(); |
| 415 | if (curInputMethodId != null) { |
| 416 | for (int i=0; i<N; i++) { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 417 | InputMethodInfo imi = mMethodList.get(i); |
| 418 | if (imi.getId().equals(curInputMethodId)) { |
| 419 | for (String pkg : packages) { |
| 420 | if (imi.getPackageName().equals(pkg)) { |
| 421 | if (!doit) { |
| 422 | return true; |
| 423 | } |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 424 | resetSelectedInputMethodAndSubtypeLocked(""); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 425 | chooseNewDefaultIMELocked(); |
| 426 | return true; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | return false; |
| 434 | } |
| 435 | |
| 436 | @Override |
| 437 | public void onSomePackagesChanged() { |
| 438 | synchronized (mMethodMap) { |
| 439 | InputMethodInfo curIm = null; |
| 440 | String curInputMethodId = Settings.Secure.getString(mContext |
| 441 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| 442 | final int N = mMethodList.size(); |
| 443 | if (curInputMethodId != null) { |
| 444 | for (int i=0; i<N; i++) { |
| 445 | InputMethodInfo imi = mMethodList.get(i); |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 446 | final String imiId = imi.getId(); |
| 447 | if (imiId.equals(curInputMethodId)) { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 448 | curIm = imi; |
| 449 | } |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 450 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 451 | int change = isPackageDisappearing(imi.getPackageName()); |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 452 | if (isPackageModified(imi.getPackageName())) { |
| 453 | mFileManager.deleteAllInputMethodSubtypes(imiId); |
| 454 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 455 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 456 | || change == PACKAGE_PERMANENT_CHANGE) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 457 | Slog.i(TAG, "Input method uninstalled, disabling: " |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 458 | + imi.getComponent()); |
| 459 | setInputMethodEnabledLocked(imi.getId(), false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 463 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 464 | buildInputMethodListLocked(mMethodList, mMethodMap); |
| 465 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | boolean changed = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 467 | |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 468 | if (curIm != null) { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 469 | int change = isPackageDisappearing(curIm.getPackageName()); |
| 470 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 471 | || change == PACKAGE_PERMANENT_CHANGE) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 472 | ServiceInfo si = null; |
| 473 | try { |
| 474 | si = mContext.getPackageManager().getServiceInfo( |
| 475 | curIm.getComponent(), 0); |
| 476 | } catch (PackageManager.NameNotFoundException ex) { |
| 477 | } |
| 478 | if (si == null) { |
| 479 | // Uh oh, current input method is no longer around! |
| 480 | // Pick another one... |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 481 | Slog.i(TAG, "Current input method removed: " + curInputMethodId); |
| satok | 15452a4 | 2011-10-28 17:58:28 +0900 | [diff] [blame] | 482 | setImeWindowVisibilityStatusHiddenLocked(); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 483 | if (!chooseNewDefaultIMELocked()) { |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 484 | changed = true; |
| 485 | curIm = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 486 | Slog.i(TAG, "Unsetting current input method"); |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 487 | resetSelectedInputMethodAndSubtypeLocked(""); |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 488 | } |
| 489 | } |
| Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 490 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 491 | } |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 492 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 493 | if (curIm == null) { |
| 494 | // We currently don't have a default input method... is |
| 495 | // one now available? |
| 496 | changed = chooseNewDefaultIMELocked(); |
| 497 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 498 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 499 | if (changed) { |
| 500 | updateFromSettingsLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | } |
| 504 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 505 | |
| Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 506 | private static class MethodCallback extends IInputMethodCallback.Stub { |
| 507 | private final IInputMethod mMethod; |
| 508 | private final InputMethodManagerService mParentIMMS; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 509 | |
| Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 510 | MethodCallback(final IInputMethod method, final InputMethodManagerService imms) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | mMethod = method; |
| Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 512 | mParentIMMS = imms; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 514 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 515 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | public void finishedEvent(int seq, boolean handled) throws RemoteException { |
| 517 | } |
| 518 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 519 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | public void sessionCreated(IInputMethodSession session) throws RemoteException { |
| Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 521 | mParentIMMS.onSessionCreated(mMethod, session); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | } |
| 523 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 524 | |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 525 | public InputMethodManagerService(Context context) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | mContext = context; |
| Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 527 | mRes = context.getResources(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 528 | mHandler = new Handler(this); |
| 529 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 530 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
| 531 | mCaller = new HandlerCaller(context, new HandlerCaller.Callback() { |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 532 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | public void executeMessage(Message msg) { |
| 534 | handleMessage(msg); |
| 535 | } |
| 536 | }); |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 537 | |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 538 | mImeSwitcherNotification = new Notification(); |
| 539 | mImeSwitcherNotification.icon = com.android.internal.R.drawable.ic_notification_ime_default; |
| 540 | mImeSwitcherNotification.when = 0; |
| 541 | mImeSwitcherNotification.flags = Notification.FLAG_ONGOING_EVENT; |
| 542 | mImeSwitcherNotification.tickerText = null; |
| 543 | mImeSwitcherNotification.defaults = 0; // please be quiet |
| 544 | mImeSwitcherNotification.sound = null; |
| 545 | mImeSwitcherNotification.vibrate = null; |
| 546 | Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER); |
| satok | 683e238 | 2011-07-12 08:28:52 +0900 | [diff] [blame] | 547 | mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); |
| satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 548 | |
| 549 | mShowOngoingImeSwitcherForPhones = false; |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 550 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 551 | synchronized (mMethodMap) { |
| 552 | mFileManager = new InputMethodFileManager(mMethodMap); |
| 553 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 554 | |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 555 | (new MyPackageMonitor()).register(mContext, true); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 556 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | IntentFilter screenOnOffFilt = new IntentFilter(); |
| 558 | screenOnOffFilt.addAction(Intent.ACTION_SCREEN_ON); |
| 559 | screenOnOffFilt.addAction(Intent.ACTION_SCREEN_OFF); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 560 | screenOnOffFilt.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | mContext.registerReceiver(new ScreenOnOffReceiver(), screenOnOffFilt); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 562 | |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 563 | mNotificationShown = false; |
| satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 564 | |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 565 | // mSettings should be created before buildInputMethodListLocked |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 566 | mSettings = new InputMethodSettings( |
| 567 | mRes, context.getContentResolver(), mMethodMap, mMethodList); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | buildInputMethodListLocked(mMethodList, mMethodMap); |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 569 | mSettings.enableAllIMEsIfThereIsNoEnabledIME(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 571 | if (TextUtils.isEmpty(Settings.Secure.getString( |
| 572 | mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | InputMethodInfo defIm = null; |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 574 | for (InputMethodInfo imi: mMethodList) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | if (defIm == null && imi.getIsDefaultResourceId() != 0) { |
| 576 | try { |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 577 | Resources res = context.createPackageContext( |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | imi.getPackageName(), 0).getResources(); |
| 579 | if (res.getBoolean(imi.getIsDefaultResourceId())) { |
| 580 | defIm = imi; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 581 | Slog.i(TAG, "Selected default: " + imi.getId()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | } |
| 583 | } catch (PackageManager.NameNotFoundException ex) { |
| 584 | } catch (Resources.NotFoundException ex) { |
| 585 | } |
| 586 | } |
| 587 | } |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 588 | if (defIm == null && mMethodList.size() > 0) { |
| satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 589 | defIm = getMostApplicableDefaultIMELocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 590 | Slog.i(TAG, "No default found, using " + defIm.getId()); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 591 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 592 | if (defIm != null) { |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 593 | setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | } |
| 595 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 596 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | mSettingsObserver = new SettingsObserver(mHandler); |
| 598 | updateFromSettingsLocked(); |
| 599 | } |
| 600 | |
| 601 | @Override |
| 602 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 603 | throws RemoteException { |
| 604 | try { |
| 605 | return super.onTransact(code, data, reply, flags); |
| 606 | } catch (RuntimeException e) { |
| 607 | // The input method manager only throws security exceptions, so let's |
| 608 | // log all others. |
| 609 | if (!(e instanceof SecurityException)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 610 | Slog.e(TAG, "Input Method Manager Crash", e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 611 | } |
| 612 | throw e; |
| 613 | } |
| 614 | } |
| 615 | |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 616 | public void systemReady(StatusBarManagerService statusBar) { |
| Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 617 | synchronized (mMethodMap) { |
| 618 | if (!mSystemReady) { |
| 619 | mSystemReady = true; |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 620 | mKeyguardManager = (KeyguardManager) |
| 621 | mContext.getSystemService(Context.KEYGUARD_SERVICE); |
| 622 | mNotificationManager = (NotificationManager) |
| 623 | mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
| 624 | mStatusBar = statusBar; |
| 625 | statusBar.setIconVisibility("ime", false); |
| 626 | updateImeWindowStatusLocked(); |
| satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 627 | mShowOngoingImeSwitcherForPhones = mRes.getBoolean( |
| 628 | com.android.internal.R.bool.show_ongoing_ime_switcher); |
| Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 629 | try { |
| 630 | startInputInnerLocked(); |
| 631 | } catch (RuntimeException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 632 | Slog.w(TAG, "Unexpected exception", e); |
| Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 633 | } |
| Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 637 | |
| satok | 15452a4 | 2011-10-28 17:58:28 +0900 | [diff] [blame] | 638 | private void setImeWindowVisibilityStatusHiddenLocked() { |
| 639 | mImeWindowVis = 0; |
| 640 | updateImeWindowStatusLocked(); |
| 641 | } |
| 642 | |
| 643 | private void updateImeWindowStatusLocked() { |
| satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 644 | setImeWindowStatus(mCurToken, mImeWindowVis, mBackDisposition); |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 647 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 648 | public List<InputMethodInfo> getInputMethodList() { |
| 649 | synchronized (mMethodMap) { |
| 650 | return new ArrayList<InputMethodInfo>(mMethodList); |
| 651 | } |
| 652 | } |
| 653 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 654 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 655 | public List<InputMethodInfo> getEnabledInputMethodList() { |
| 656 | synchronized (mMethodMap) { |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 657 | return mSettings.getEnabledInputMethodListLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 661 | private HashMap<InputMethodInfo, List<InputMethodSubtype>> |
| 662 | getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked() { |
| 663 | HashMap<InputMethodInfo, List<InputMethodSubtype>> enabledInputMethodAndSubtypes = |
| 664 | new HashMap<InputMethodInfo, List<InputMethodSubtype>>(); |
| 665 | for (InputMethodInfo imi: getEnabledInputMethodList()) { |
| 666 | enabledInputMethodAndSubtypes.put( |
| 667 | imi, getEnabledInputMethodSubtypeListLocked(imi, true)); |
| 668 | } |
| 669 | return enabledInputMethodAndSubtypes; |
| 670 | } |
| 671 | |
| 672 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(InputMethodInfo imi, |
| 673 | boolean allowsImplicitlySelectedSubtypes) { |
| 674 | if (imi == null && mCurMethodId != null) { |
| 675 | imi = mMethodMap.get(mCurMethodId); |
| 676 | } |
| satok | 7265d9b | 2011-02-14 15:47:30 +0900 | [diff] [blame] | 677 | List<InputMethodSubtype> enabledSubtypes = |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 678 | mSettings.getEnabledInputMethodSubtypeListLocked(imi); |
| satok | 7265d9b | 2011-02-14 15:47:30 +0900 | [diff] [blame] | 679 | if (allowsImplicitlySelectedSubtypes && enabledSubtypes.isEmpty()) { |
| satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 680 | enabledSubtypes = getImplicitlyApplicableSubtypesLocked(mRes, imi); |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 681 | } |
| satok | 7265d9b | 2011-02-14 15:47:30 +0900 | [diff] [blame] | 682 | return InputMethodSubtype.sort(mContext, 0, imi, enabledSubtypes); |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 683 | } |
| 684 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 685 | @Override |
| satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 686 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(InputMethodInfo imi, |
| 687 | boolean allowsImplicitlySelectedSubtypes) { |
| satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 688 | synchronized (mMethodMap) { |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 689 | return getEnabledInputMethodSubtypeListLocked(imi, allowsImplicitlySelectedSubtypes); |
| satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 693 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | public void addClient(IInputMethodClient client, |
| 695 | IInputContext inputContext, int uid, int pid) { |
| 696 | synchronized (mMethodMap) { |
| 697 | mClients.put(client.asBinder(), new ClientState(client, |
| 698 | inputContext, uid, pid)); |
| 699 | } |
| 700 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 701 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 702 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | public void removeClient(IInputMethodClient client) { |
| 704 | synchronized (mMethodMap) { |
| 705 | mClients.remove(client.asBinder()); |
| 706 | } |
| 707 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 708 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | void executeOrSendMessage(IInterface target, Message msg) { |
| 710 | if (target.asBinder() instanceof Binder) { |
| 711 | mCaller.sendMessage(msg); |
| 712 | } else { |
| 713 | handleMessage(msg); |
| 714 | msg.recycle(); |
| 715 | } |
| 716 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 717 | |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 718 | void unbindCurrentClientLocked() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | if (mCurClient != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 720 | if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | + mCurClient.client.asBinder()); |
| 722 | if (mBoundToMethod) { |
| 723 | mBoundToMethod = false; |
| 724 | if (mCurMethod != null) { |
| 725 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 726 | MSG_UNBIND_INPUT, mCurMethod)); |
| 727 | } |
| 728 | } |
| 729 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 730 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 731 | mCurClient.sessionRequested = false; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 732 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | // Call setActive(false) on the old client |
| 734 | try { |
| 735 | mCurClient.client.setActive(false); |
| 736 | } catch (RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 737 | Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | + mCurClient.pid + " uid " + mCurClient.uid); |
| 739 | } |
| 740 | mCurClient = null; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 741 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 742 | hideInputMethodMenuLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | } |
| 744 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 745 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 746 | private int getImeShowFlags() { |
| 747 | int flags = 0; |
| 748 | if (mShowForced) { |
| 749 | flags |= InputMethod.SHOW_FORCED |
| 750 | | InputMethod.SHOW_EXPLICIT; |
| 751 | } else if (mShowExplicitlyRequested) { |
| 752 | flags |= InputMethod.SHOW_EXPLICIT; |
| 753 | } |
| 754 | return flags; |
| 755 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 756 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | private int getAppShowFlags() { |
| 758 | int flags = 0; |
| 759 | if (mShowForced) { |
| 760 | flags |= InputMethodManager.SHOW_FORCED; |
| 761 | } else if (!mShowExplicitlyRequested) { |
| 762 | flags |= InputMethodManager.SHOW_IMPLICIT; |
| 763 | } |
| 764 | return flags; |
| 765 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 766 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | InputBindResult attachNewInputLocked(boolean initial, boolean needResult) { |
| 768 | if (!mBoundToMethod) { |
| 769 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 770 | MSG_BIND_INPUT, mCurMethod, mCurClient.binding)); |
| 771 | mBoundToMethod = true; |
| 772 | } |
| 773 | final SessionState session = mCurClient.curSession; |
| 774 | if (initial) { |
| 775 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 776 | MSG_START_INPUT, session, mCurInputContext, mCurAttribute)); |
| 777 | } else { |
| 778 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 779 | MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute)); |
| 780 | } |
| 781 | if (mShowRequested) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 782 | if (DEBUG) Slog.v(TAG, "Attach new input asks to show input"); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 783 | showCurrentInputLocked(getAppShowFlags(), null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | } |
| 785 | return needResult |
| 786 | ? new InputBindResult(session.session, mCurId, mCurSeq) |
| 787 | : null; |
| 788 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 789 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 790 | InputBindResult startInputLocked(IInputMethodClient client, |
| 791 | IInputContext inputContext, EditorInfo attribute, |
| 792 | boolean initial, boolean needResult) { |
| 793 | // If no method is currently selected, do nothing. |
| 794 | if (mCurMethodId == null) { |
| 795 | return mNoBinding; |
| 796 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 797 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | ClientState cs = mClients.get(client.asBinder()); |
| 799 | if (cs == null) { |
| 800 | throw new IllegalArgumentException("unknown client " |
| 801 | + client.asBinder()); |
| 802 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 803 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | try { |
| 805 | if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) { |
| 806 | // Check with the window manager to make sure this client actually |
| 807 | // has a window with focus. If not, reject. This is thread safe |
| 808 | // because if the focus changes some time before or after, the |
| 809 | // next client receiving focus that has any interest in input will |
| 810 | // be calling through here after that change happens. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 811 | Slog.w(TAG, "Starting input on non-focused client " + cs.client |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
| 813 | return null; |
| 814 | } |
| 815 | } catch (RemoteException e) { |
| 816 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 817 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 818 | if (mCurClient != cs) { |
| 819 | // If the client is changing, we need to switch over to the new |
| 820 | // one. |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 821 | unbindCurrentClientLocked(); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 822 | if (DEBUG) Slog.v(TAG, "switching to client: client = " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | + cs.client.asBinder()); |
| 824 | |
| 825 | // If the screen is on, inform the new client it is active |
| 826 | if (mScreenOn) { |
| 827 | try { |
| 828 | cs.client.setActive(mScreenOn); |
| 829 | } catch (RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 830 | Slog.w(TAG, "Got RemoteException sending setActive notification to pid " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | + cs.pid + " uid " + cs.uid); |
| 832 | } |
| 833 | } |
| 834 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 835 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 836 | // Bump up the sequence for this client and attach it. |
| 837 | mCurSeq++; |
| 838 | if (mCurSeq <= 0) mCurSeq = 1; |
| 839 | mCurClient = cs; |
| 840 | mCurInputContext = inputContext; |
| 841 | mCurAttribute = attribute; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 842 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 843 | // Check if the input method is changing. |
| 844 | if (mCurId != null && mCurId.equals(mCurMethodId)) { |
| 845 | if (cs.curSession != null) { |
| 846 | // Fast case: if we are already connected to the input method, |
| 847 | // then just return it. |
| 848 | return attachNewInputLocked(initial, needResult); |
| 849 | } |
| 850 | if (mHaveConnection) { |
| 851 | if (mCurMethod != null) { |
| 852 | if (!cs.sessionRequested) { |
| 853 | cs.sessionRequested = true; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 854 | if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 856 | MSG_CREATE_SESSION, mCurMethod, |
| Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 857 | new MethodCallback(mCurMethod, this))); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | } |
| 859 | // Return to client, and we will get back with it when |
| 860 | // we have had a session made for it. |
| 861 | return new InputBindResult(null, mCurId, mCurSeq); |
| 862 | } else if (SystemClock.uptimeMillis() |
| 863 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 864 | // In this case we have connected to the service, but |
| 865 | // don't yet have its interface. If it hasn't been too |
| 866 | // long since we did the connection, we'll return to |
| 867 | // the client and wait to get the service interface so |
| 868 | // we can report back. If it has been too long, we want |
| 869 | // to fall through so we can try a disconnect/reconnect |
| 870 | // to see if we can get back in touch with the service. |
| 871 | return new InputBindResult(null, mCurId, mCurSeq); |
| 872 | } else { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 873 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, |
| 874 | mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 878 | |
| Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 879 | return startInputInnerLocked(); |
| 880 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 881 | |
| Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 882 | InputBindResult startInputInnerLocked() { |
| 883 | if (mCurMethodId == null) { |
| 884 | return mNoBinding; |
| 885 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 886 | |
| Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 887 | if (!mSystemReady) { |
| 888 | // If the system is not yet ready, we shouldn't be running third |
| 889 | // party code. |
| Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 890 | return new InputBindResult(null, mCurMethodId, mCurSeq); |
| Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 891 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 892 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | InputMethodInfo info = mMethodMap.get(mCurMethodId); |
| 894 | if (info == null) { |
| 895 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 896 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 897 | |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 898 | unbindCurrentMethodLocked(false); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 899 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE); |
| 901 | mCurIntent.setComponent(info.getComponent()); |
| Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 902 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 903 | com.android.internal.R.string.input_method_binding_label); |
| 904 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 905 | mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0)); |
| Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 906 | if (mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE |
| 907 | | Context.BIND_NOT_VISIBLE)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 908 | mLastBindTime = SystemClock.uptimeMillis(); |
| 909 | mHaveConnection = true; |
| 910 | mCurId = info.getId(); |
| 911 | mCurToken = new Binder(); |
| 912 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 913 | if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 914 | mIWindowManager.addWindowToken(mCurToken, |
| 915 | WindowManager.LayoutParams.TYPE_INPUT_METHOD); |
| 916 | } catch (RemoteException e) { |
| 917 | } |
| 918 | return new InputBindResult(null, mCurId, mCurSeq); |
| 919 | } else { |
| 920 | mCurIntent = null; |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 921 | Slog.w(TAG, "Failure connecting to input method service: " |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | + mCurIntent); |
| 923 | } |
| 924 | return null; |
| 925 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 926 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 927 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | public InputBindResult startInput(IInputMethodClient client, |
| 929 | IInputContext inputContext, EditorInfo attribute, |
| 930 | boolean initial, boolean needResult) { |
| 931 | synchronized (mMethodMap) { |
| 932 | final long ident = Binder.clearCallingIdentity(); |
| 933 | try { |
| 934 | return startInputLocked(client, inputContext, attribute, |
| 935 | initial, needResult); |
| 936 | } finally { |
| 937 | Binder.restoreCallingIdentity(ident); |
| 938 | } |
| 939 | } |
| 940 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 941 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 942 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | public void finishInput(IInputMethodClient client) { |
| 944 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 945 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 946 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 948 | synchronized (mMethodMap) { |
| 949 | if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { |
| 950 | mCurMethod = IInputMethod.Stub.asInterface(service); |
| Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 951 | if (mCurToken == null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 952 | Slog.w(TAG, "Service connected without a token!"); |
| Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 953 | unbindCurrentMethodLocked(false); |
| 954 | return; |
| 955 | } |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 956 | if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); |
| Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 957 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 958 | MSG_ATTACH_TOKEN, mCurMethod, mCurToken)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | if (mCurClient != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 960 | if (DEBUG) Slog.v(TAG, "Creating first session while with client " |
| Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 961 | + mCurClient); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 963 | MSG_CREATE_SESSION, mCurMethod, |
| Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 964 | new MethodCallback(mCurMethod, this))); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | } |
| 966 | } |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | void onSessionCreated(IInputMethod method, IInputMethodSession session) { |
| 971 | synchronized (mMethodMap) { |
| 972 | if (mCurMethod != null && method != null |
| 973 | && mCurMethod.asBinder() == method.asBinder()) { |
| 974 | if (mCurClient != null) { |
| 975 | mCurClient.curSession = new SessionState(mCurClient, |
| 976 | method, session); |
| 977 | mCurClient.sessionRequested = false; |
| 978 | InputBindResult res = attachNewInputLocked(true, true); |
| 979 | if (res.method != null) { |
| 980 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
| 981 | MSG_BIND_METHOD, mCurClient.client, res)); |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 987 | |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 988 | void unbindCurrentMethodLocked(boolean reportToClient) { |
| Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 989 | if (mVisibleBound) { |
| 990 | mContext.unbindService(mVisibleConnection); |
| 991 | mVisibleBound = false; |
| 992 | } |
| 993 | |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 994 | if (mHaveConnection) { |
| 995 | mContext.unbindService(this); |
| 996 | mHaveConnection = false; |
| 997 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 998 | |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 999 | if (mCurToken != null) { |
| 1000 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1001 | if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken); |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1002 | mIWindowManager.removeWindowToken(mCurToken); |
| 1003 | } catch (RemoteException e) { |
| 1004 | } |
| 1005 | mCurToken = null; |
| 1006 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1007 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1008 | mCurId = null; |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1009 | clearCurMethodLocked(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1010 | |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1011 | if (reportToClient && mCurClient != null) { |
| 1012 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 1013 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 1017 | private void finishSession(SessionState sessionState) { |
| 1018 | if (sessionState != null && sessionState.session != null) { |
| 1019 | try { |
| 1020 | sessionState.session.finishSession(); |
| 1021 | } catch (RemoteException e) { |
| Jean-Baptiste Queru | 9d0f6df | 2010-03-29 12:55:09 -0700 | [diff] [blame] | 1022 | Slog.w(TAG, "Session failed to close due to remote exception", e); |
| satok | 15452a4 | 2011-10-28 17:58:28 +0900 | [diff] [blame] | 1023 | setImeWindowVisibilityStatusHiddenLocked(); |
| Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 1024 | } |
| 1025 | } |
| 1026 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1027 | |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1028 | void clearCurMethodLocked() { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | if (mCurMethod != null) { |
| 1030 | for (ClientState cs : mClients.values()) { |
| 1031 | cs.sessionRequested = false; |
| Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 1032 | finishSession(cs.curSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | cs.curSession = null; |
| 1034 | } |
| Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 1035 | |
| 1036 | finishSession(mEnabledSession); |
| 1037 | mEnabledSession = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1038 | mCurMethod = null; |
| 1039 | } |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1040 | if (mStatusBar != null) { |
| 1041 | mStatusBar.setIconVisibility("ime", false); |
| 1042 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1044 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1045 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | public void onServiceDisconnected(ComponentName name) { |
| 1047 | synchronized (mMethodMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1048 | if (DEBUG) Slog.v(TAG, "Service disconnected: " + name |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | + " mCurIntent=" + mCurIntent); |
| 1050 | if (mCurMethod != null && mCurIntent != null |
| 1051 | && name.equals(mCurIntent.getComponent())) { |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1052 | clearCurMethodLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1053 | // We consider this to be a new bind attempt, since the system |
| 1054 | // should now try to restart the service for us. |
| 1055 | mLastBindTime = SystemClock.uptimeMillis(); |
| 1056 | mShowRequested = mInputShown; |
| 1057 | mInputShown = false; |
| 1058 | if (mCurClient != null) { |
| 1059 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 1060 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | } |
| 1065 | |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1066 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | public void updateStatusIcon(IBinder token, String packageName, int iconId) { |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1068 | int uid = Binder.getCallingUid(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | long ident = Binder.clearCallingIdentity(); |
| 1070 | try { |
| 1071 | if (token == null || mCurToken != token) { |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1072 | Slog.w(TAG, "Ignoring setInputMethod of uid " + uid + " token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1073 | return; |
| 1074 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1075 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1076 | synchronized (mMethodMap) { |
| 1077 | if (iconId == 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1078 | if (DEBUG) Slog.d(TAG, "hide the small icon for the input method"); |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1079 | if (mStatusBar != null) { |
| 1080 | mStatusBar.setIconVisibility("ime", false); |
| 1081 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1082 | } else if (packageName != null) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1083 | if (DEBUG) Slog.d(TAG, "show a small icon for the input method"); |
| Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 1084 | CharSequence contentDescription = null; |
| 1085 | try { |
| 1086 | PackageManager packageManager = mContext.getPackageManager(); |
| 1087 | contentDescription = packageManager.getApplicationLabel( |
| 1088 | packageManager.getApplicationInfo(packageName, 0)); |
| 1089 | } catch (NameNotFoundException nnfe) { |
| 1090 | /* ignore */ |
| 1091 | } |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1092 | if (mStatusBar != null) { |
| 1093 | mStatusBar.setIcon("ime", packageName, iconId, 0, |
| 1094 | contentDescription != null |
| 1095 | ? contentDescription.toString() : null); |
| 1096 | mStatusBar.setIconVisibility("ime", true); |
| 1097 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | } |
| 1099 | } |
| 1100 | } finally { |
| 1101 | Binder.restoreCallingIdentity(ident); |
| 1102 | } |
| 1103 | } |
| 1104 | |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1105 | private boolean needsToShowImeSwitchOngoingNotification() { |
| 1106 | if (!mShowOngoingImeSwitcherForPhones) return false; |
| 1107 | synchronized (mMethodMap) { |
| 1108 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 1109 | final int N = imis.size(); |
| satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 1110 | if (N > 2) return true; |
| 1111 | if (N < 1) return false; |
| 1112 | int nonAuxCount = 0; |
| 1113 | int auxCount = 0; |
| 1114 | InputMethodSubtype nonAuxSubtype = null; |
| 1115 | InputMethodSubtype auxSubtype = null; |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1116 | for(int i = 0; i < N; ++i) { |
| 1117 | final InputMethodInfo imi = imis.get(i); |
| 1118 | final List<InputMethodSubtype> subtypes = getEnabledInputMethodSubtypeListLocked( |
| 1119 | imi, true); |
| 1120 | final int subtypeCount = subtypes.size(); |
| 1121 | if (subtypeCount == 0) { |
| satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 1122 | ++nonAuxCount; |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1123 | } else { |
| 1124 | for (int j = 0; j < subtypeCount; ++j) { |
| satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 1125 | final InputMethodSubtype subtype = subtypes.get(j); |
| 1126 | if (!subtype.isAuxiliary()) { |
| 1127 | ++nonAuxCount; |
| 1128 | nonAuxSubtype = subtype; |
| 1129 | } else { |
| 1130 | ++auxCount; |
| 1131 | auxSubtype = subtype; |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1132 | } |
| 1133 | } |
| 1134 | } |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1135 | } |
| satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 1136 | if (nonAuxCount > 1 || auxCount > 1) { |
| 1137 | return true; |
| 1138 | } else if (nonAuxCount == 1 && auxCount == 1) { |
| 1139 | if (nonAuxSubtype != null && auxSubtype != null |
| satok | 9747f89 | 2011-09-12 15:56:40 +0900 | [diff] [blame] | 1140 | && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale()) |
| 1141 | || auxSubtype.overridesImplicitlyEnabledSubtype() |
| 1142 | || nonAuxSubtype.overridesImplicitlyEnabledSubtype()) |
| satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 1143 | && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) { |
| 1144 | return false; |
| 1145 | } |
| 1146 | return true; |
| 1147 | } |
| 1148 | return false; |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1149 | } |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1150 | } |
| 1151 | |
| satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 1152 | @SuppressWarnings("deprecation") |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1153 | @Override |
| Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 1154 | public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { |
| satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 1155 | int uid = Binder.getCallingUid(); |
| 1156 | long ident = Binder.clearCallingIdentity(); |
| 1157 | try { |
| 1158 | if (token == null || mCurToken != token) { |
| Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 1159 | Slog.w(TAG, "Ignoring setImeWindowStatus of uid " + uid + " token: " + token); |
| satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 1160 | return; |
| 1161 | } |
| 1162 | |
| 1163 | synchronized (mMethodMap) { |
| Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 1164 | mImeWindowVis = vis; |
| 1165 | mBackDisposition = backDisposition; |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1166 | if (mStatusBar != null) { |
| 1167 | mStatusBar.setImeWindowStatus(token, vis, backDisposition); |
| 1168 | } |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1169 | final boolean iconVisibility = (vis & InputMethodService.IME_ACTIVE) != 0; |
| satok | 5bc8e73 | 2011-07-22 21:07:23 +0900 | [diff] [blame] | 1170 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 1171 | if (imi != null && iconVisibility && needsToShowImeSwitchOngoingNotification()) { |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1172 | final PackageManager pm = mContext.getPackageManager(); |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1173 | final CharSequence title = mRes.getText( |
| 1174 | com.android.internal.R.string.select_input_method); |
| satok | 5bc8e73 | 2011-07-22 21:07:23 +0900 | [diff] [blame] | 1175 | final CharSequence imiLabel = imi.loadLabel(pm); |
| 1176 | final CharSequence summary = mCurrentSubtype != null |
| 1177 | ? TextUtils.concat(mCurrentSubtype.getDisplayName(mContext, |
| 1178 | imi.getPackageName(), imi.getServiceInfo().applicationInfo), |
| 1179 | (TextUtils.isEmpty(imiLabel) ? |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 1180 | "" : " - " + imiLabel)) |
| satok | 5bc8e73 | 2011-07-22 21:07:23 +0900 | [diff] [blame] | 1181 | : imiLabel; |
| 1182 | |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1183 | mImeSwitcherNotification.setLatestEventInfo( |
| satok | 5bc8e73 | 2011-07-22 21:07:23 +0900 | [diff] [blame] | 1184 | mContext, title, summary, mImeSwitchPendingIntent); |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1185 | if (mNotificationManager != null) { |
| 1186 | mNotificationManager.notify( |
| 1187 | com.android.internal.R.string.select_input_method, |
| 1188 | mImeSwitcherNotification); |
| 1189 | mNotificationShown = true; |
| 1190 | } |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1191 | } else { |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1192 | if (mNotificationShown && mNotificationManager != null) { |
| satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1193 | mNotificationManager.cancel( |
| 1194 | com.android.internal.R.string.select_input_method); |
| 1195 | mNotificationShown = false; |
| 1196 | } |
| 1197 | } |
| satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 1198 | } |
| 1199 | } finally { |
| 1200 | Binder.restoreCallingIdentity(ident); |
| 1201 | } |
| 1202 | } |
| 1203 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1204 | @Override |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1205 | public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) { |
| 1206 | synchronized (mMethodMap) { |
| 1207 | final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId); |
| 1208 | for (int i = 0; i < spans.length; ++i) { |
| 1209 | SuggestionSpan ss = spans[i]; |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1210 | if (!TextUtils.isEmpty(ss.getNotificationTargetClassName())) { |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1211 | mSecureSuggestionSpans.put(ss, currentImi); |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1212 | final InputMethodInfo targetImi = mSecureSuggestionSpans.get(ss); |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1213 | } |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1218 | @Override |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1219 | public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) { |
| 1220 | synchronized (mMethodMap) { |
| 1221 | final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span); |
| 1222 | // TODO: Do not send the intent if the process of the targetImi is already dead. |
| 1223 | if (targetImi != null) { |
| 1224 | final String[] suggestions = span.getSuggestions(); |
| 1225 | if (index < 0 || index >= suggestions.length) return false; |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1226 | final String className = span.getNotificationTargetClassName(); |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1227 | final Intent intent = new Intent(); |
| 1228 | // Ensures that only a class in the original IME package will receive the |
| 1229 | // notification. |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1230 | intent.setClassName(targetImi.getPackageName(), className); |
| satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1231 | intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED); |
| 1232 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString); |
| 1233 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]); |
| 1234 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode()); |
| 1235 | mContext.sendBroadcast(intent); |
| 1236 | return true; |
| 1237 | } |
| 1238 | } |
| 1239 | return false; |
| 1240 | } |
| 1241 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | void updateFromSettingsLocked() { |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1243 | // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and |
| 1244 | // ENABLED_INPUT_METHODS is taking care of keeping them correctly in |
| 1245 | // sync, so we will never have a DEFAULT_INPUT_METHOD that is not |
| 1246 | // enabled. |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | String id = Settings.Secure.getString(mContext.getContentResolver(), |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1248 | Settings.Secure.DEFAULT_INPUT_METHOD); |
| satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 1249 | // There is no input method selected, try to choose new applicable input method. |
| 1250 | if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) { |
| 1251 | id = Settings.Secure.getString(mContext.getContentResolver(), |
| 1252 | Settings.Secure.DEFAULT_INPUT_METHOD); |
| 1253 | } |
| 1254 | if (!TextUtils.isEmpty(id)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | try { |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1256 | setInputMethodLocked(id, getSelectedInputMethodSubtypeId(id)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | } catch (IllegalArgumentException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1258 | Slog.w(TAG, "Unknown input method from prefs: " + id, e); |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1259 | mCurMethodId = null; |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1260 | unbindCurrentMethodLocked(true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1261 | } |
| satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 1262 | mShortcutInputMethodsAndSubtypes.clear(); |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1263 | } else { |
| 1264 | // There is no longer an input method set, so stop any current one. |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1265 | mCurMethodId = null; |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1266 | unbindCurrentMethodLocked(true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1267 | } |
| 1268 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1269 | |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1270 | /* package */ void setInputMethodLocked(String id, int subtypeId) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | InputMethodInfo info = mMethodMap.get(id); |
| 1272 | if (info == null) { |
| satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1273 | throw new IllegalArgumentException("Unknown id: " + id); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1274 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1275 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | if (id.equals(mCurMethodId)) { |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1277 | InputMethodSubtype subtype = null; |
| Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 1278 | if (subtypeId >= 0 && subtypeId < info.getSubtypeCount()) { |
| 1279 | subtype = info.getSubtypeAt(subtypeId); |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1280 | } |
| 1281 | if (subtype != mCurrentSubtype) { |
| 1282 | synchronized (mMethodMap) { |
| satok | ca83021 | 2011-01-13 21:15:04 +0900 | [diff] [blame] | 1283 | if (subtype != null) { |
| 1284 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true); |
| 1285 | } |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1286 | if (mCurMethod != null) { |
| 1287 | try { |
| satok | e40dea0 | 2011-01-30 01:14:02 +0900 | [diff] [blame] | 1288 | final Configuration conf = mRes.getConfiguration(); |
| 1289 | final boolean haveHardKeyboard = conf.keyboard |
| 1290 | != Configuration.KEYBOARD_NOKEYS; |
| 1291 | final boolean hardKeyShown = haveHardKeyboard |
| Ken Wakasa | 8710e76 | 2011-01-30 11:02:09 +0900 | [diff] [blame] | 1292 | && conf.hardKeyboardHidden |
| 1293 | != Configuration.HARDKEYBOARDHIDDEN_YES; |
| satok | e40dea0 | 2011-01-30 01:14:02 +0900 | [diff] [blame] | 1294 | mImeWindowVis = (mInputShown || hardKeyShown) ? ( |
| 1295 | InputMethodService.IME_ACTIVE | InputMethodService.IME_VISIBLE) |
| 1296 | : 0; |
| Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1297 | updateImeWindowStatusLocked(); |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1298 | // If subtype is null, try to find the most applicable one from |
| 1299 | // getCurrentInputMethodSubtype. |
| 1300 | if (subtype == null) { |
| 1301 | subtype = getCurrentInputMethodSubtype(); |
| 1302 | } |
| 1303 | mCurMethod.changeInputMethodSubtype(subtype); |
| 1304 | } catch (RemoteException e) { |
| 1305 | return; |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1310 | return; |
| 1311 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1312 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | final long ident = Binder.clearCallingIdentity(); |
| 1314 | try { |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1315 | // Set a subtype to this input method. |
| 1316 | // subtypeId the name of a subtype which will be set. |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1317 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false); |
| 1318 | // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked() |
| 1319 | // because mCurMethodId is stored as a history in |
| 1320 | // setSelectedInputMethodAndSubtypeLocked(). |
| 1321 | mCurMethodId = id; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | |
| 1323 | if (ActivityManagerNative.isSystemReady()) { |
| 1324 | Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); |
| Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 1325 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1326 | intent.putExtra("input_method_id", id); |
| 1327 | mContext.sendBroadcast(intent); |
| 1328 | } |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1329 | unbindCurrentClientLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | } finally { |
| 1331 | Binder.restoreCallingIdentity(ident); |
| 1332 | } |
| 1333 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1334 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1335 | @Override |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1336 | public boolean showSoftInput(IInputMethodClient client, int flags, |
| 1337 | ResultReceiver resultReceiver) { |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1338 | int uid = Binder.getCallingUid(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1339 | long ident = Binder.clearCallingIdentity(); |
| 1340 | try { |
| 1341 | synchronized (mMethodMap) { |
| 1342 | if (mCurClient == null || client == null |
| 1343 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1344 | try { |
| 1345 | // We need to check if this is the current client with |
| 1346 | // focus in the window manager, to allow this call to |
| 1347 | // be made before input is started in it. |
| 1348 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1349 | Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1350 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1351 | } |
| 1352 | } catch (RemoteException e) { |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1353 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | } |
| 1355 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1356 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1357 | if (DEBUG) Slog.v(TAG, "Client requesting input be shown"); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1358 | return showCurrentInputLocked(flags, resultReceiver); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1359 | } |
| 1360 | } finally { |
| 1361 | Binder.restoreCallingIdentity(ident); |
| 1362 | } |
| 1363 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1364 | |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1365 | boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1366 | mShowRequested = true; |
| 1367 | if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) { |
| 1368 | mShowExplicitlyRequested = true; |
| 1369 | } |
| 1370 | if ((flags&InputMethodManager.SHOW_FORCED) != 0) { |
| 1371 | mShowExplicitlyRequested = true; |
| 1372 | mShowForced = true; |
| 1373 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1374 | |
| Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1375 | if (!mSystemReady) { |
| 1376 | return false; |
| 1377 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1378 | |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1379 | boolean res = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1380 | if (mCurMethod != null) { |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1381 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 1382 | MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod, |
| 1383 | resultReceiver)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1384 | mInputShown = true; |
| Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 1385 | if (mHaveConnection && !mVisibleBound) { |
| 1386 | mContext.bindService(mCurIntent, mVisibleConnection, Context.BIND_AUTO_CREATE); |
| 1387 | mVisibleBound = true; |
| 1388 | } |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1389 | res = true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1390 | } else if (mHaveConnection && SystemClock.uptimeMillis() |
| satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 1391 | >= (mLastBindTime+TIME_TO_RECONNECT)) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1392 | // The client has asked to have the input method shown, but |
| 1393 | // we have been sitting here too long with a connection to the |
| 1394 | // service and no interface received, so let's disconnect/connect |
| 1395 | // to try to prod things along. |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1396 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1397 | SystemClock.uptimeMillis()-mLastBindTime,1); |
| satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 1398 | Slog.w(TAG, "Force disconnect/connect to the IME in showCurrentInputLocked()"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | mContext.unbindService(this); |
| Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 1400 | mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE |
| 1401 | | Context.BIND_NOT_VISIBLE); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1403 | |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1404 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1405 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1406 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1407 | @Override |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1408 | public boolean hideSoftInput(IInputMethodClient client, int flags, |
| 1409 | ResultReceiver resultReceiver) { |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1410 | int uid = Binder.getCallingUid(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | long ident = Binder.clearCallingIdentity(); |
| 1412 | try { |
| 1413 | synchronized (mMethodMap) { |
| 1414 | if (mCurClient == null || client == null |
| 1415 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1416 | try { |
| 1417 | // We need to check if this is the current client with |
| 1418 | // focus in the window manager, to allow this call to |
| 1419 | // be made before input is started in it. |
| 1420 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1421 | if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid " |
| 1422 | + uid + ": " + client); |
| satok | 15452a4 | 2011-10-28 17:58:28 +0900 | [diff] [blame] | 1423 | setImeWindowVisibilityStatusHiddenLocked(); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1424 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | } |
| 1426 | } catch (RemoteException e) { |
| satok | 15452a4 | 2011-10-28 17:58:28 +0900 | [diff] [blame] | 1427 | setImeWindowVisibilityStatusHiddenLocked(); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1428 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1429 | } |
| 1430 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1431 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1432 | if (DEBUG) Slog.v(TAG, "Client requesting input be hidden"); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1433 | return hideCurrentInputLocked(flags, resultReceiver); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1434 | } |
| 1435 | } finally { |
| 1436 | Binder.restoreCallingIdentity(ident); |
| 1437 | } |
| 1438 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1439 | |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1440 | boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1441 | if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0 |
| 1442 | && (mShowExplicitlyRequested || mShowForced)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1443 | if (DEBUG) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | "Not hiding: explicit show not cancelled by non-explicit hide"); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1445 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | } |
| 1447 | if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1448 | if (DEBUG) Slog.v(TAG, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | "Not hiding: forced show not cancelled by not-always hide"); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1450 | return false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | } |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1452 | boolean res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | if (mInputShown && mCurMethod != null) { |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1454 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 1455 | MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver)); |
| 1456 | res = true; |
| 1457 | } else { |
| 1458 | res = false; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1459 | } |
| Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 1460 | if (mHaveConnection && mVisibleBound) { |
| 1461 | mContext.unbindService(mVisibleConnection); |
| 1462 | mVisibleBound = false; |
| 1463 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1464 | mInputShown = false; |
| 1465 | mShowRequested = false; |
| 1466 | mShowExplicitlyRequested = false; |
| 1467 | mShowForced = false; |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1468 | return res; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1469 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1470 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1471 | @Override |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1472 | public void windowGainedFocus(IInputMethodClient client, IBinder windowToken, |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1473 | boolean viewHasFocus, boolean isTextEditor, int softInputMode, |
| 1474 | boolean first, int windowFlags) { |
| 1475 | long ident = Binder.clearCallingIdentity(); |
| 1476 | try { |
| 1477 | synchronized (mMethodMap) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1478 | if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder() |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | + " viewHasFocus=" + viewHasFocus |
| 1480 | + " isTextEditor=" + isTextEditor |
| 1481 | + " softInputMode=#" + Integer.toHexString(softInputMode) |
| 1482 | + " first=" + first + " flags=#" |
| 1483 | + Integer.toHexString(windowFlags)); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1484 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1485 | if (mCurClient == null || client == null |
| 1486 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1487 | try { |
| 1488 | // We need to check if this is the current client with |
| 1489 | // focus in the window manager, to allow this call to |
| 1490 | // be made before input is started in it. |
| 1491 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1492 | Slog.w(TAG, "Client not active, ignoring focus gain of: " + client); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | return; |
| 1494 | } |
| 1495 | } catch (RemoteException e) { |
| 1496 | } |
| 1497 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1498 | |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1499 | if (mCurFocusedWindow == windowToken) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1500 | Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client); |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1501 | return; |
| 1502 | } |
| 1503 | mCurFocusedWindow = windowToken; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1504 | |
| Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1505 | // Should we auto-show the IME even if the caller has not |
| 1506 | // specified what should be done with it? |
| 1507 | // We only do this automatically if the window can resize |
| 1508 | // to accommodate the IME (so what the user sees will give |
| 1509 | // them good context without input information being obscured |
| 1510 | // by the IME) or if running on a large screen where there |
| 1511 | // is more room for the target window + IME. |
| 1512 | final boolean doAutoShow = |
| 1513 | (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 1514 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
| 1515 | || mRes.getConfiguration().isLayoutSizeAtLeast( |
| 1516 | Configuration.SCREENLAYOUT_SIZE_LARGE); |
| 1517 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1518 | switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) { |
| 1519 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: |
| Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1520 | if (!isTextEditor || !doAutoShow) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1521 | if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) { |
| 1522 | // There is no focus view, and this window will |
| 1523 | // be behind any soft input window, so hide the |
| 1524 | // soft input window if it is shown. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1525 | if (DEBUG) Slog.v(TAG, "Unspecified window will hide input"); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1526 | hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | } |
| Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1528 | } else if (isTextEditor && doAutoShow && (softInputMode & |
| 1529 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | // There is a focus view, and we are navigating forward |
| 1531 | // into the window, so show the input window for the user. |
| Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1532 | // We only do this automatically if the window an resize |
| 1533 | // to accomodate the IME (so what the user sees will give |
| 1534 | // them good context without input information being obscured |
| 1535 | // by the IME) or if running on a large screen where there |
| 1536 | // is more room for the target window + IME. |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1537 | if (DEBUG) Slog.v(TAG, "Unspecified window will show input"); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1538 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1539 | } |
| 1540 | break; |
| 1541 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED: |
| 1542 | // Do nothing. |
| 1543 | break; |
| 1544 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN: |
| 1545 | if ((softInputMode & |
| 1546 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1547 | if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward"); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1548 | hideCurrentInputLocked(0, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1549 | } |
| 1550 | break; |
| 1551 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1552 | if (DEBUG) Slog.v(TAG, "Window asks to hide input"); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1553 | hideCurrentInputLocked(0, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1554 | break; |
| 1555 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE: |
| 1556 | if ((softInputMode & |
| 1557 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1558 | if (DEBUG) Slog.v(TAG, "Window asks to show input going forward"); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1559 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1560 | } |
| 1561 | break; |
| 1562 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1563 | if (DEBUG) Slog.v(TAG, "Window asks to always show input"); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1564 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1565 | break; |
| 1566 | } |
| 1567 | } |
| 1568 | } finally { |
| 1569 | Binder.restoreCallingIdentity(ident); |
| 1570 | } |
| 1571 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1572 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1573 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | public void showInputMethodPickerFromClient(IInputMethodClient client) { |
| 1575 | synchronized (mMethodMap) { |
| 1576 | if (mCurClient == null || client == null |
| 1577 | || mCurClient.client.asBinder() != client.asBinder()) { |
| satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1578 | Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid " |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1579 | + Binder.getCallingUid() + ": " + client); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | } |
| 1581 | |
| satok | 440aab5 | 2010-11-25 09:43:11 +0900 | [diff] [blame] | 1582 | // Always call subtype picker, because subtype picker is a superset of input method |
| 1583 | // picker. |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1584 | mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER); |
| 1585 | } |
| 1586 | } |
| 1587 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1588 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | public void setInputMethod(IBinder token, String id) { |
| satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 1590 | setInputMethodWithSubtypeId(token, id, NOT_A_SUBTYPE_ID); |
| 1591 | } |
| 1592 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1593 | @Override |
| satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 1594 | public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) { |
| 1595 | synchronized (mMethodMap) { |
| 1596 | if (subtype != null) { |
| 1597 | setInputMethodWithSubtypeId(token, id, getSubtypeIdFromHashCode( |
| 1598 | mMethodMap.get(id), subtype.hashCode())); |
| 1599 | } else { |
| 1600 | setInputMethod(token, id); |
| 1601 | } |
| 1602 | } |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1603 | } |
| 1604 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1605 | @Override |
| satok | b416a71e | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 1606 | public void showInputMethodAndSubtypeEnablerFromClient( |
| satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1607 | IInputMethodClient client, String inputMethodId) { |
| satok | b416a71e | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 1608 | synchronized (mMethodMap) { |
| 1609 | if (mCurClient == null || client == null |
| 1610 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1611 | Slog.w(TAG, "Ignoring showInputMethodAndSubtypeEnablerFromClient of: " + client); |
| 1612 | } |
| satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 1613 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 1614 | MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId)); |
| satok | b416a71e | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 1615 | } |
| 1616 | } |
| 1617 | |
| satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 1618 | @Override |
| satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 1619 | public boolean switchToLastInputMethod(IBinder token) { |
| 1620 | synchronized (mMethodMap) { |
| satok | c445bcd | 2011-01-25 18:57:24 +0900 | [diff] [blame] | 1621 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
| satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 1622 | final InputMethodInfo lastImi; |
| satok | 208d563 | 2011-05-20 22:13:38 +0900 | [diff] [blame] | 1623 | if (lastIme != null) { |
| satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 1624 | lastImi = mMethodMap.get(lastIme.first); |
| 1625 | } else { |
| 1626 | lastImi = null; |
| satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 1627 | } |
| satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 1628 | String targetLastImiId = null; |
| 1629 | int subtypeId = NOT_A_SUBTYPE_ID; |
| 1630 | if (lastIme != null && lastImi != null) { |
| 1631 | final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId); |
| 1632 | final int lastSubtypeHash = Integer.valueOf(lastIme.second); |
| 1633 | final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID |
| 1634 | : mCurrentSubtype.hashCode(); |
| 1635 | // If the last IME is the same as the current IME and the last subtype is not |
| 1636 | // defined, there is no need to switch to the last IME. |
| 1637 | if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) { |
| 1638 | targetLastImiId = lastIme.first; |
| 1639 | subtypeId = getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | if (TextUtils.isEmpty(targetLastImiId) && !canAddToLastInputMethod(mCurrentSubtype)) { |
| 1644 | // This is a safety net. If the currentSubtype can't be added to the history |
| 1645 | // and the framework couldn't find the last ime, we will make the last ime be |
| 1646 | // the most applicable enabled keyboard subtype of the system imes. |
| 1647 | final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 1648 | if (enabled != null) { |
| 1649 | final int N = enabled.size(); |
| 1650 | final String locale = mCurrentSubtype == null |
| 1651 | ? mRes.getConfiguration().locale.toString() |
| 1652 | : mCurrentSubtype.getLocale(); |
| 1653 | for (int i = 0; i < N; ++i) { |
| 1654 | final InputMethodInfo imi = enabled.get(i); |
| 1655 | if (imi.getSubtypeCount() > 0 && isSystemIme(imi)) { |
| 1656 | InputMethodSubtype keyboardSubtype = |
| 1657 | findLastResortApplicableSubtypeLocked(mRes, getSubtypes(imi), |
| 1658 | SUBTYPE_MODE_KEYBOARD, locale, true); |
| 1659 | if (keyboardSubtype != null) { |
| 1660 | targetLastImiId = imi.getId(); |
| 1661 | subtypeId = getSubtypeIdFromHashCode( |
| 1662 | imi, keyboardSubtype.hashCode()); |
| 1663 | if(keyboardSubtype.getLocale().equals(locale)) { |
| 1664 | break; |
| 1665 | } |
| 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | if (!TextUtils.isEmpty(targetLastImiId)) { |
| 1673 | if (DEBUG) { |
| 1674 | Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second |
| 1675 | + ", from: " + mCurMethodId + ", " + subtypeId); |
| 1676 | } |
| 1677 | setInputMethodWithSubtypeId(token, targetLastImiId, subtypeId); |
| 1678 | return true; |
| 1679 | } else { |
| 1680 | return false; |
| 1681 | } |
| satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 1682 | } |
| 1683 | } |
| 1684 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1685 | @Override |
| satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 1686 | public InputMethodSubtype getLastInputMethodSubtype() { |
| 1687 | synchronized (mMethodMap) { |
| 1688 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
| 1689 | // TODO: Handle the case of the last IME with no subtypes |
| 1690 | if (lastIme == null || TextUtils.isEmpty(lastIme.first) |
| 1691 | || TextUtils.isEmpty(lastIme.second)) return null; |
| 1692 | final InputMethodInfo lastImi = mMethodMap.get(lastIme.first); |
| 1693 | if (lastImi == null) return null; |
| 1694 | try { |
| 1695 | final int lastSubtypeHash = Integer.valueOf(lastIme.second); |
| satok | 0e7d7d6 | 2011-07-05 13:28:06 +0900 | [diff] [blame] | 1696 | final int lastSubtypeId = getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
| 1697 | if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) { |
| 1698 | return null; |
| 1699 | } |
| 1700 | return lastImi.getSubtypeAt(lastSubtypeId); |
| satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 1701 | } catch (NumberFormatException e) { |
| 1702 | return null; |
| 1703 | } |
| 1704 | } |
| 1705 | } |
| 1706 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1707 | @Override |
| satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 1708 | public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) { |
| satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 1709 | // By this IPC call, only a process which shares the same uid with the IME can add |
| 1710 | // additional input method subtypes to the IME. |
| satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 1711 | if (TextUtils.isEmpty(imiId) || subtypes == null || subtypes.length == 0) return; |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1712 | synchronized (mMethodMap) { |
| satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 1713 | final InputMethodInfo imi = mMethodMap.get(imiId); |
| satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 1714 | if (imi == null) return; |
| satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 1715 | final PackageManager pm = mContext.getPackageManager(); |
| 1716 | final String[] packageInfos = pm.getPackagesForUid(Binder.getCallingUid()); |
| 1717 | if (packageInfos != null) { |
| 1718 | final int packageNum = packageInfos.length; |
| 1719 | for (int i = 0; i < packageNum; ++i) { |
| 1720 | if (packageInfos[i].equals(imi.getPackageName())) { |
| 1721 | mFileManager.addInputMethodSubtypes(imi, subtypes); |
| satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 1722 | final long ident = Binder.clearCallingIdentity(); |
| 1723 | try { |
| 1724 | buildInputMethodListLocked(mMethodList, mMethodMap); |
| 1725 | } finally { |
| 1726 | Binder.restoreCallingIdentity(ident); |
| 1727 | } |
| satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 1728 | return; |
| satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 1729 | } |
| 1730 | } |
| 1731 | } |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1732 | } |
| satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 1733 | return; |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1734 | } |
| 1735 | |
| satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 1736 | private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1737 | synchronized (mMethodMap) { |
| 1738 | if (token == null) { |
| 1739 | if (mContext.checkCallingOrSelfPermission( |
| 1740 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 1741 | != PackageManager.PERMISSION_GRANTED) { |
| 1742 | throw new SecurityException( |
| 1743 | "Using null token requires permission " |
| 1744 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 1745 | } |
| 1746 | } else if (mCurToken != token) { |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1747 | Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid() |
| 1748 | + " token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1749 | return; |
| 1750 | } |
| 1751 | |
| satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 1752 | final long ident = Binder.clearCallingIdentity(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1753 | try { |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1754 | setInputMethodLocked(id, subtypeId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | } finally { |
| 1756 | Binder.restoreCallingIdentity(ident); |
| 1757 | } |
| 1758 | } |
| 1759 | } |
| 1760 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1761 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1762 | public void hideMySoftInput(IBinder token, int flags) { |
| 1763 | synchronized (mMethodMap) { |
| 1764 | if (token == null || mCurToken != token) { |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1765 | if (DEBUG) Slog.w(TAG, "Ignoring hideInputMethod of uid " |
| 1766 | + Binder.getCallingUid() + " token: " + token); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1767 | return; |
| 1768 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1769 | long ident = Binder.clearCallingIdentity(); |
| 1770 | try { |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1771 | hideCurrentInputLocked(flags, null); |
| 1772 | } finally { |
| 1773 | Binder.restoreCallingIdentity(ident); |
| 1774 | } |
| 1775 | } |
| 1776 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1777 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1778 | @Override |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1779 | public void showMySoftInput(IBinder token, int flags) { |
| 1780 | synchronized (mMethodMap) { |
| 1781 | if (token == null || mCurToken != token) { |
| Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1782 | Slog.w(TAG, "Ignoring showMySoftInput of uid " |
| 1783 | + Binder.getCallingUid() + " token: " + token); |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1784 | return; |
| 1785 | } |
| 1786 | long ident = Binder.clearCallingIdentity(); |
| 1787 | try { |
| 1788 | showCurrentInputLocked(flags, null); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1789 | } finally { |
| 1790 | Binder.restoreCallingIdentity(ident); |
| 1791 | } |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | void setEnabledSessionInMainThread(SessionState session) { |
| 1796 | if (mEnabledSession != session) { |
| 1797 | if (mEnabledSession != null) { |
| 1798 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1799 | if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1800 | mEnabledSession.method.setSessionEnabled( |
| 1801 | mEnabledSession.session, false); |
| 1802 | } catch (RemoteException e) { |
| 1803 | } |
| 1804 | } |
| 1805 | mEnabledSession = session; |
| 1806 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1807 | if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1808 | session.method.setSessionEnabled( |
| 1809 | session.session, true); |
| 1810 | } catch (RemoteException e) { |
| 1811 | } |
| 1812 | } |
| 1813 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1814 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1815 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1816 | public boolean handleMessage(Message msg) { |
| 1817 | HandlerCaller.SomeArgs args; |
| 1818 | switch (msg.what) { |
| 1819 | case MSG_SHOW_IM_PICKER: |
| 1820 | showInputMethodMenu(); |
| 1821 | return true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1822 | |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1823 | case MSG_SHOW_IM_SUBTYPE_PICKER: |
| 1824 | showInputMethodSubtypeMenu(); |
| 1825 | return true; |
| 1826 | |
| satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1827 | case MSG_SHOW_IM_SUBTYPE_ENABLER: |
| satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1828 | args = (HandlerCaller.SomeArgs)msg.obj; |
| satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 1829 | showInputMethodAndSubtypeEnabler((String)args.arg1); |
| satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1830 | return true; |
| 1831 | |
| 1832 | case MSG_SHOW_IM_CONFIG: |
| 1833 | showConfigureInputMethods(); |
| satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1834 | return true; |
| 1835 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1836 | // --------------------------------------------------------- |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1837 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1838 | case MSG_UNBIND_INPUT: |
| 1839 | try { |
| 1840 | ((IInputMethod)msg.obj).unbindInput(); |
| 1841 | } catch (RemoteException e) { |
| 1842 | // There is nothing interesting about the method dying. |
| 1843 | } |
| 1844 | return true; |
| 1845 | case MSG_BIND_INPUT: |
| 1846 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1847 | try { |
| 1848 | ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2); |
| 1849 | } catch (RemoteException e) { |
| 1850 | } |
| 1851 | return true; |
| 1852 | case MSG_SHOW_SOFT_INPUT: |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1853 | args = (HandlerCaller.SomeArgs)msg.obj; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1854 | try { |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1855 | ((IInputMethod)args.arg1).showSoftInput(msg.arg1, |
| 1856 | (ResultReceiver)args.arg2); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1857 | } catch (RemoteException e) { |
| 1858 | } |
| 1859 | return true; |
| 1860 | case MSG_HIDE_SOFT_INPUT: |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1861 | args = (HandlerCaller.SomeArgs)msg.obj; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1862 | try { |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1863 | ((IInputMethod)args.arg1).hideSoftInput(0, |
| 1864 | (ResultReceiver)args.arg2); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1865 | } catch (RemoteException e) { |
| 1866 | } |
| 1867 | return true; |
| 1868 | case MSG_ATTACH_TOKEN: |
| 1869 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1870 | try { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1871 | if (DEBUG) Slog.v(TAG, "Sending attach of token: " + args.arg2); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1872 | ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2); |
| 1873 | } catch (RemoteException e) { |
| 1874 | } |
| 1875 | return true; |
| 1876 | case MSG_CREATE_SESSION: |
| 1877 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1878 | try { |
| 1879 | ((IInputMethod)args.arg1).createSession( |
| 1880 | (IInputMethodCallback)args.arg2); |
| 1881 | } catch (RemoteException e) { |
| 1882 | } |
| 1883 | return true; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | // --------------------------------------------------------- |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1885 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1886 | case MSG_START_INPUT: |
| 1887 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1888 | try { |
| 1889 | SessionState session = (SessionState)args.arg1; |
| 1890 | setEnabledSessionInMainThread(session); |
| 1891 | session.method.startInput((IInputContext)args.arg2, |
| 1892 | (EditorInfo)args.arg3); |
| 1893 | } catch (RemoteException e) { |
| 1894 | } |
| 1895 | return true; |
| 1896 | case MSG_RESTART_INPUT: |
| 1897 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1898 | try { |
| 1899 | SessionState session = (SessionState)args.arg1; |
| 1900 | setEnabledSessionInMainThread(session); |
| 1901 | session.method.restartInput((IInputContext)args.arg2, |
| 1902 | (EditorInfo)args.arg3); |
| 1903 | } catch (RemoteException e) { |
| 1904 | } |
| 1905 | return true; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1906 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1907 | // --------------------------------------------------------- |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1908 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1909 | case MSG_UNBIND_METHOD: |
| 1910 | try { |
| 1911 | ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1); |
| 1912 | } catch (RemoteException e) { |
| 1913 | // There is nothing interesting about the last client dying. |
| 1914 | } |
| 1915 | return true; |
| 1916 | case MSG_BIND_METHOD: |
| 1917 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1918 | try { |
| 1919 | ((IInputMethodClient)args.arg1).onBindMethod( |
| 1920 | (InputBindResult)args.arg2); |
| 1921 | } catch (RemoteException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1922 | Slog.w(TAG, "Client died receiving input method " + args.arg2); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1923 | } |
| 1924 | return true; |
| 1925 | } |
| 1926 | return false; |
| 1927 | } |
| 1928 | |
| Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1929 | private boolean isSystemIme(InputMethodInfo inputMethod) { |
| 1930 | return (inputMethod.getServiceInfo().applicationInfo.flags |
| 1931 | & ApplicationInfo.FLAG_SYSTEM) != 0; |
| 1932 | } |
| 1933 | |
| Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 1934 | private static ArrayList<InputMethodSubtype> getSubtypes(InputMethodInfo imi) { |
| 1935 | ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); |
| 1936 | final int subtypeCount = imi.getSubtypeCount(); |
| 1937 | for (int i = 0; i < subtypeCount; ++i) { |
| 1938 | subtypes.add(imi.getSubtypeAt(i)); |
| 1939 | } |
| 1940 | return subtypes; |
| 1941 | } |
| 1942 | |
| satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 1943 | |
| 1944 | private static ArrayList<InputMethodSubtype> getOverridingImplicitlyEnabledSubtypes( |
| 1945 | InputMethodInfo imi, String mode) { |
| 1946 | ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); |
| 1947 | final int subtypeCount = imi.getSubtypeCount(); |
| 1948 | for (int i = 0; i < subtypeCount; ++i) { |
| 1949 | final InputMethodSubtype subtype = imi.getSubtypeAt(i); |
| 1950 | if (subtype.overridesImplicitlyEnabledSubtype() && subtype.getMode().equals(mode)) { |
| 1951 | subtypes.add(subtype); |
| 1952 | } |
| 1953 | } |
| 1954 | return subtypes; |
| 1955 | } |
| 1956 | |
| satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 1957 | private InputMethodInfo getMostApplicableDefaultIMELocked() { |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1958 | List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1959 | if (enabled != null && enabled.size() > 0) { |
| Dianne Hackborn | 83e48f5 | 2010-03-23 23:03:25 -0700 | [diff] [blame] | 1960 | // We'd prefer to fall back on a system IME, since that is safer. |
| 1961 | int i=enabled.size(); |
| 1962 | while (i > 0) { |
| 1963 | i--; |
| satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 1964 | final InputMethodInfo imi = enabled.get(i); |
| 1965 | if (isSystemIme(imi) && !imi.isAuxiliaryIme()) { |
| Dianne Hackborn | 83e48f5 | 2010-03-23 23:03:25 -0700 | [diff] [blame] | 1966 | break; |
| 1967 | } |
| 1968 | } |
| satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 1969 | return enabled.get(i); |
| 1970 | } |
| 1971 | return null; |
| 1972 | } |
| 1973 | |
| 1974 | private boolean chooseNewDefaultIMELocked() { |
| 1975 | final InputMethodInfo imi = getMostApplicableDefaultIMELocked(); |
| 1976 | if (imi != null) { |
| satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 1977 | if (DEBUG) { |
| 1978 | Slog.d(TAG, "New default IME was selected: " + imi.getId()); |
| 1979 | } |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1980 | resetSelectedInputMethodAndSubtypeLocked(imi.getId()); |
| Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1981 | return true; |
| 1982 | } |
| 1983 | |
| 1984 | return false; |
| 1985 | } |
| 1986 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1987 | void buildInputMethodListLocked(ArrayList<InputMethodInfo> list, |
| 1988 | HashMap<String, InputMethodInfo> map) { |
| 1989 | list.clear(); |
| 1990 | map.clear(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1991 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1992 | PackageManager pm = mContext.getPackageManager(); |
| Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1993 | final Configuration config = mRes.getConfiguration(); |
| Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1994 | final boolean haveHardKeyboard = config.keyboard == Configuration.KEYBOARD_QWERTY; |
| 1995 | String disabledSysImes = Settings.Secure.getString(mContext.getContentResolver(), |
| 1996 | Secure.DISABLED_SYSTEM_INPUT_METHODS); |
| 1997 | if (disabledSysImes == null) disabledSysImes = ""; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1998 | |
| 1999 | List<ResolveInfo> services = pm.queryIntentServices( |
| 2000 | new Intent(InputMethod.SERVICE_INTERFACE), |
| 2001 | PackageManager.GET_META_DATA); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2002 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2003 | final HashMap<String, List<InputMethodSubtype>> additionalSubtypes = |
| 2004 | mFileManager.getAllAdditionalInputMethodSubtypes(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2005 | for (int i = 0; i < services.size(); ++i) { |
| 2006 | ResolveInfo ri = services.get(i); |
| 2007 | ServiceInfo si = ri.serviceInfo; |
| 2008 | ComponentName compName = new ComponentName(si.packageName, si.name); |
| 2009 | if (!android.Manifest.permission.BIND_INPUT_METHOD.equals( |
| 2010 | si.permission)) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2011 | Slog.w(TAG, "Skipping input method " + compName |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2012 | + ": it does not require the permission " |
| 2013 | + android.Manifest.permission.BIND_INPUT_METHOD); |
| 2014 | continue; |
| 2015 | } |
| 2016 | |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2017 | if (DEBUG) Slog.d(TAG, "Checking " + compName); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2018 | |
| 2019 | try { |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2020 | InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | list.add(p); |
| Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 2022 | final String id = p.getId(); |
| 2023 | map.put(id, p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2024 | |
| Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 2025 | // System IMEs are enabled by default, unless there's a hard keyboard |
| 2026 | // and the system IME was explicitly disabled |
| 2027 | if (isSystemIme(p) && (!haveHardKeyboard || disabledSysImes.indexOf(id) < 0)) { |
| 2028 | setInputMethodEnabledLocked(id, true); |
| Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2031 | if (DEBUG) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2032 | Slog.d(TAG, "Found a third-party input method " + p); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2033 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2034 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2035 | } catch (XmlPullParserException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2036 | Slog.w(TAG, "Unable to load input method " + compName, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2037 | } catch (IOException e) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2038 | Slog.w(TAG, "Unable to load input method " + compName, e); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2039 | } |
| 2040 | } |
| Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 2041 | |
| 2042 | String defaultIme = Settings.Secure.getString(mContext |
| 2043 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 2044 | if (!TextUtils.isEmpty(defaultIme) && !map.containsKey(defaultIme)) { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2045 | if (chooseNewDefaultIMELocked()) { |
| Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 2046 | updateFromSettingsLocked(); |
| 2047 | } |
| 2048 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2049 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2050 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2051 | // ---------------------------------------------------------------------- |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2052 | |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2053 | private void showInputMethodMenu() { |
| 2054 | showInputMethodMenuInternal(false); |
| 2055 | } |
| 2056 | |
| 2057 | private void showInputMethodSubtypeMenu() { |
| 2058 | showInputMethodMenuInternal(true); |
| 2059 | } |
| 2060 | |
| satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 2061 | private void showInputMethodAndSubtypeEnabler(String inputMethodId) { |
| Tadashi G. Takaoka | f49688f | 2011-01-20 17:56:13 +0900 | [diff] [blame] | 2062 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); |
| satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 2063 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| satok | 86417ea | 2010-10-27 14:11:03 +0900 | [diff] [blame] | 2064 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 2065 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 2066 | if (!TextUtils.isEmpty(inputMethodId)) { |
| Tadashi G. Takaoka | 2548020 | 2011-01-20 23:13:02 +0900 | [diff] [blame] | 2067 | intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId); |
| satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 2068 | } |
| satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 2069 | mContext.startActivity(intent); |
| 2070 | } |
| 2071 | |
| 2072 | private void showConfigureInputMethods() { |
| 2073 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS); |
| 2074 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2075 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 2076 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 2077 | mContext.startActivity(intent); |
| 2078 | } |
| 2079 | |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2080 | private void showInputMethodMenuInternal(boolean showSubtypes) { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2081 | if (DEBUG) Slog.v(TAG, "Show switching menu"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2082 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | final Context context = mContext; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2084 | final PackageManager pm = context.getPackageManager(); |
| satok | bc81b69 | 2011-08-26 16:22:22 +0900 | [diff] [blame] | 2085 | final boolean isScreenLocked = mKeyguardManager != null |
| 2086 | && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure(); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2087 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2088 | String lastInputMethodId = Settings.Secure.getString(context |
| 2089 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2090 | int lastInputMethodSubtypeId = getSelectedInputMethodSubtypeId(lastInputMethodId); |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2091 | if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2092 | |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2093 | synchronized (mMethodMap) { |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2094 | final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = |
| 2095 | getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(); |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2096 | if (immis == null || immis.size() == 0) { |
| 2097 | return; |
| 2098 | } |
| 2099 | |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2100 | hideInputMethodMenuLocked(); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2101 | |
| Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 2102 | final TreeMap<InputMethodInfo, List<InputMethodSubtype>> sortedImmis = |
| 2103 | new TreeMap<InputMethodInfo, List<InputMethodSubtype>>( |
| 2104 | new Comparator<InputMethodInfo>() { |
| 2105 | @Override |
| 2106 | public int compare(InputMethodInfo imi1, InputMethodInfo imi2) { |
| 2107 | if (imi2 == null) return 0; |
| 2108 | if (imi1 == null) return 1; |
| 2109 | if (pm == null) { |
| 2110 | return imi1.getId().compareTo(imi2.getId()); |
| 2111 | } |
| 2112 | CharSequence imiId1 = imi1.loadLabel(pm) + "/" + imi1.getId(); |
| 2113 | CharSequence imiId2 = imi2.loadLabel(pm) + "/" + imi2.getId(); |
| 2114 | return imiId1.toString().compareTo(imiId2.toString()); |
| 2115 | } |
| 2116 | }); |
| satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 2117 | |
| Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 2118 | sortedImmis.putAll(immis); |
| 2119 | |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 2120 | final ArrayList<ImeSubtypeListItem> imList = new ArrayList<ImeSubtypeListItem>(); |
| Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 2121 | |
| 2122 | for (InputMethodInfo imi : sortedImmis.keySet()) { |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2123 | if (imi == null) continue; |
| 2124 | List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypeList = immis.get(imi); |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2125 | HashSet<String> enabledSubtypeSet = new HashSet<String>(); |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2126 | for (InputMethodSubtype subtype: explicitlyOrImplicitlyEnabledSubtypeList) { |
| 2127 | enabledSubtypeSet.add(String.valueOf(subtype.hashCode())); |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2128 | } |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2129 | ArrayList<InputMethodSubtype> subtypes = getSubtypes(imi); |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 2130 | final CharSequence imeLabel = imi.loadLabel(pm); |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2131 | if (showSubtypes && enabledSubtypeSet.size() > 0) { |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2132 | final int subtypeCount = imi.getSubtypeCount(); |
| satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 2133 | if (DEBUG) { |
| 2134 | Slog.v(TAG, "Add subtypes: " + subtypeCount + ", " + imi.getId()); |
| 2135 | } |
| Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2136 | for (int j = 0; j < subtypeCount; ++j) { |
| satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 2137 | final InputMethodSubtype subtype = imi.getSubtypeAt(j); |
| 2138 | final String subtypeHashCode = String.valueOf(subtype.hashCode()); |
| 2139 | // We show all enabled IMEs and subtypes when an IME is shown. |
| 2140 | if (enabledSubtypeSet.contains(subtypeHashCode) |
| satok | bc81b69 | 2011-08-26 16:22:22 +0900 | [diff] [blame] | 2141 | && ((mInputShown && !isScreenLocked) || !subtype.isAuxiliary())) { |
| satok | 38aac04 | 2011-09-06 14:41:33 +0900 | [diff] [blame] | 2142 | final CharSequence subtypeLabel = |
| 2143 | subtype.overridesImplicitlyEnabledSubtype() ? null |
| 2144 | : subtype.getDisplayName(context, imi.getPackageName(), |
| 2145 | imi.getServiceInfo().applicationInfo); |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 2146 | imList.add(new ImeSubtypeListItem(imeLabel, subtypeLabel, imi, j)); |
| 2147 | |
| satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 2148 | // Removing this subtype from enabledSubtypeSet because we no longer |
| 2149 | // need to add an entry of this subtype to imList to avoid duplicated |
| 2150 | // entries. |
| 2151 | enabledSubtypeSet.remove(subtypeHashCode); |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2152 | } |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2153 | } |
| 2154 | } else { |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 2155 | imList.add(new ImeSubtypeListItem(imeLabel, null, imi, NOT_A_SUBTYPE_ID)); |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2156 | } |
| Dianne Hackborn | 97106ab | 2010-03-03 00:08:31 -0800 | [diff] [blame] | 2157 | } |
| satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 2158 | |
| Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 2159 | final int N = imList.size(); |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2160 | mIms = new InputMethodInfo[N]; |
| 2161 | mSubtypeIds = new int[N]; |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2162 | int checkedItem = 0; |
| 2163 | for (int i = 0; i < N; ++i) { |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 2164 | final ImeSubtypeListItem item = imList.get(i); |
| 2165 | mIms[i] = item.mImi; |
| 2166 | mSubtypeIds[i] = item.mSubtypeId; |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2167 | if (mIms[i].getId().equals(lastInputMethodId)) { |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2168 | int subtypeId = mSubtypeIds[i]; |
| 2169 | if ((subtypeId == NOT_A_SUBTYPE_ID) |
| 2170 | || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) |
| 2171 | || (subtypeId == lastInputMethodSubtypeId)) { |
| 2172 | checkedItem = i; |
| 2173 | } |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2174 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2175 | } |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2176 | |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 2177 | final TypedArray a = context.obtainStyledAttributes(null, |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2178 | com.android.internal.R.styleable.DialogPreference, |
| 2179 | com.android.internal.R.attr.alertDialogStyle, 0); |
| 2180 | mDialogBuilder = new AlertDialog.Builder(context) |
| 2181 | .setTitle(com.android.internal.R.string.select_input_method) |
| 2182 | .setOnCancelListener(new OnCancelListener() { |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2183 | @Override |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2184 | public void onCancel(DialogInterface dialog) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | hideInputMethodMenu(); |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2186 | } |
| 2187 | }) |
| 2188 | .setIcon(a.getDrawable( |
| 2189 | com.android.internal.R.styleable.DialogPreference_dialogTitle)); |
| 2190 | a.recycle(); |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2191 | |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 2192 | final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(context, |
| 2193 | com.android.internal.R.layout.simple_list_item_2_single_choice, imList, |
| 2194 | checkedItem); |
| 2195 | |
| 2196 | mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2197 | new AlertDialog.OnClickListener() { |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2198 | @Override |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2199 | public void onClick(DialogInterface dialog, int which) { |
| 2200 | synchronized (mMethodMap) { |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2201 | if (mIms == null || mIms.length <= which |
| 2202 | || mSubtypeIds == null || mSubtypeIds.length <= which) { |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2203 | return; |
| 2204 | } |
| 2205 | InputMethodInfo im = mIms[which]; |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2206 | int subtypeId = mSubtypeIds[which]; |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2207 | hideInputMethodMenu(); |
| 2208 | if (im != null) { |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2209 | if ((subtypeId < 0) |
| Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2210 | || (subtypeId >= im.getSubtypeCount())) { |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2211 | subtypeId = NOT_A_SUBTYPE_ID; |
| 2212 | } |
| 2213 | setInputMethodLocked(im.getId(), subtypeId); |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2214 | } |
| Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 2215 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2216 | } |
| Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 2217 | }); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | |
| satok | bc81b69 | 2011-08-26 16:22:22 +0900 | [diff] [blame] | 2219 | if (showSubtypes && !isScreenLocked) { |
| satok | 82beadf | 2010-12-27 19:03:06 +0900 | [diff] [blame] | 2220 | mDialogBuilder.setPositiveButton( |
| 2221 | com.android.internal.R.string.configure_input_methods, |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2222 | new DialogInterface.OnClickListener() { |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2223 | @Override |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2224 | public void onClick(DialogInterface dialog, int whichButton) { |
| satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 2225 | showConfigureInputMethods(); |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2226 | } |
| 2227 | }); |
| 2228 | } |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2229 | mSwitchingDialog = mDialogBuilder.create(); |
| Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 2230 | mSwitchingDialog.setCanceledOnTouchOutside(true); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2231 | mSwitchingDialog.getWindow().setType( |
| 2232 | WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG); |
| Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 2233 | mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2234 | mSwitchingDialog.show(); |
| 2235 | } |
| 2236 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2237 | |
| Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 2238 | private static class ImeSubtypeListItem { |
| 2239 | public final CharSequence mImeName; |
| 2240 | public final CharSequence mSubtypeName; |
| 2241 | public final InputMethodInfo mImi; |
| 2242 | public final int mSubtypeId; |
| 2243 | public ImeSubtypeListItem(CharSequence imeName, CharSequence subtypeName, |
| 2244 | InputMethodInfo imi, int subtypeId) { |
| 2245 | mImeName = imeName; |
| 2246 | mSubtypeName = subtypeName; |
| 2247 | mImi = imi; |
| 2248 | mSubtypeId = subtypeId; |
| 2249 | } |
| 2250 | } |
| 2251 | |
| 2252 | private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> { |
| 2253 | private final LayoutInflater mInflater; |
| 2254 | private final int mTextViewResourceId; |
| 2255 | private final List<ImeSubtypeListItem> mItemsList; |
| 2256 | private final int mCheckedItem; |
| 2257 | public ImeSubtypeListAdapter(Context context, int textViewResourceId, |
| 2258 | List<ImeSubtypeListItem> itemsList, int checkedItem) { |
| 2259 | super(context, textViewResourceId, itemsList); |
| 2260 | mTextViewResourceId = textViewResourceId; |
| 2261 | mItemsList = itemsList; |
| 2262 | mCheckedItem = checkedItem; |
| 2263 | mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 2264 | } |
| 2265 | |
| 2266 | @Override |
| 2267 | public View getView(int position, View convertView, ViewGroup parent) { |
| 2268 | final View view = convertView != null ? convertView |
| 2269 | : mInflater.inflate(mTextViewResourceId, null); |
| 2270 | if (position < 0 || position >= mItemsList.size()) return view; |
| 2271 | final ImeSubtypeListItem item = mItemsList.get(position); |
| 2272 | final CharSequence imeName = item.mImeName; |
| 2273 | final CharSequence subtypeName = item.mSubtypeName; |
| 2274 | final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1); |
| 2275 | final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2); |
| 2276 | if (TextUtils.isEmpty(subtypeName)) { |
| 2277 | firstTextView.setText(imeName); |
| 2278 | secondTextView.setVisibility(View.GONE); |
| 2279 | } else { |
| 2280 | firstTextView.setText(subtypeName); |
| 2281 | secondTextView.setText(imeName); |
| 2282 | secondTextView.setVisibility(View.VISIBLE); |
| 2283 | } |
| 2284 | final RadioButton radioButton = |
| 2285 | (RadioButton)view.findViewById(com.android.internal.R.id.radio); |
| 2286 | radioButton.setChecked(position == mCheckedItem); |
| 2287 | return view; |
| 2288 | } |
| 2289 | } |
| 2290 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2291 | void hideInputMethodMenu() { |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2292 | synchronized (mMethodMap) { |
| 2293 | hideInputMethodMenuLocked(); |
| 2294 | } |
| 2295 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2296 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2297 | void hideInputMethodMenuLocked() { |
| Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2298 | if (DEBUG) Slog.v(TAG, "Hide switching menu"); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2299 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2300 | if (mSwitchingDialog != null) { |
| 2301 | mSwitchingDialog.dismiss(); |
| 2302 | mSwitchingDialog = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2303 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2304 | |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2305 | mDialogBuilder = null; |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2306 | mIms = null; |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2307 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2308 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2309 | // ---------------------------------------------------------------------- |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2310 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2311 | @Override |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2312 | public boolean setInputMethodEnabled(String id, boolean enabled) { |
| 2313 | synchronized (mMethodMap) { |
| 2314 | if (mContext.checkCallingOrSelfPermission( |
| 2315 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 2316 | != PackageManager.PERMISSION_GRANTED) { |
| 2317 | throw new SecurityException( |
| 2318 | "Requires permission " |
| 2319 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 2320 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2321 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | long ident = Binder.clearCallingIdentity(); |
| 2323 | try { |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2324 | return setInputMethodEnabledLocked(id, enabled); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | } finally { |
| 2326 | Binder.restoreCallingIdentity(ident); |
| 2327 | } |
| 2328 | } |
| 2329 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2330 | |
| 2331 | boolean setInputMethodEnabledLocked(String id, boolean enabled) { |
| 2332 | // Make sure this is a valid input method. |
| 2333 | InputMethodInfo imm = mMethodMap.get(id); |
| 2334 | if (imm == null) { |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2335 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2336 | } |
| 2337 | |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2338 | List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings |
| 2339 | .getEnabledInputMethodsAndSubtypeListLocked(); |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2340 | |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2341 | if (enabled) { |
| 2342 | for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) { |
| 2343 | if (pair.first.equals(id)) { |
| 2344 | // We are enabling this input method, but it is already enabled. |
| 2345 | // Nothing to do. The previous state was enabled. |
| 2346 | return true; |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2347 | } |
| 2348 | } |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2349 | mSettings.appendAndPutEnabledInputMethodLocked(id, false); |
| 2350 | // Previous state was disabled. |
| 2351 | return false; |
| 2352 | } else { |
| 2353 | StringBuilder builder = new StringBuilder(); |
| 2354 | if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 2355 | builder, enabledInputMethodsList, id)) { |
| 2356 | // Disabled input method is currently selected, switch to another one. |
| 2357 | String selId = Settings.Secure.getString(mContext.getContentResolver(), |
| 2358 | Settings.Secure.DEFAULT_INPUT_METHOD); |
| satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2359 | if (id.equals(selId) && !chooseNewDefaultIMELocked()) { |
| 2360 | Slog.i(TAG, "Can't find new IME, unsetting the current input method."); |
| 2361 | resetSelectedInputMethodAndSubtypeLocked(""); |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2362 | } |
| 2363 | // Previous state was enabled. |
| 2364 | return true; |
| 2365 | } else { |
| 2366 | // We are disabling the input method but it is already disabled. |
| 2367 | // Nothing to do. The previous state was disabled. |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2368 | return false; |
| 2369 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2370 | } |
| Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2371 | } |
| The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2372 | |
| satok | 57ffc00 | 2011-01-25 00:11:47 +0900 | [diff] [blame] | 2373 | private boolean canAddToLastInputMethod(InputMethodSubtype subtype) { |
| 2374 | if (subtype == null) return true; |
| satok | 9b41579 | 2011-05-30 12:37:52 +0900 | [diff] [blame] | 2375 | return !subtype.isAuxiliary(); |
| satok | 57ffc00 | 2011-01-25 00:11:47 +0900 | [diff] [blame] | 2376 | } |
| 2377 | |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2378 | private void saveCurrentInputMethodAndSubtypeToHistory() { |
| 2379 | String subtypeId = NOT_A_SUBTYPE_ID_STR; |
| 2380 | if (mCurrentSubtype != null) { |
| 2381 | subtypeId = String.valueOf(mCurrentSubtype.hashCode()); |
| 2382 | } |
| satok | 57ffc00 | 2011-01-25 00:11:47 +0900 | [diff] [blame] | 2383 | if (canAddToLastInputMethod(mCurrentSubtype)) { |
| 2384 | mSettings.addSubtypeToHistory(mCurMethodId, subtypeId); |
| 2385 | } |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2386 | } |
| 2387 | |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2388 | private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId, |
| 2389 | boolean setSubtypeOnly) { |
| 2390 | // Update the history of InputMethod and Subtype |
| 2391 | saveCurrentInputMethodAndSubtypeToHistory(); |
| 2392 | |
| 2393 | // Set Subtype here |
| 2394 | if (imi == null || subtypeId < 0) { |
| 2395 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
| Tadashi G. Takaoka | 0ba75bb | 2010-11-09 12:19:32 -0800 | [diff] [blame] | 2396 | mCurrentSubtype = null; |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2397 | } else { |
| Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2398 | if (subtypeId < imi.getSubtypeCount()) { |
| 2399 | InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId); |
| 2400 | mSettings.putSelectedSubtype(subtype.hashCode()); |
| 2401 | mCurrentSubtype = subtype; |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2402 | } else { |
| 2403 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
| 2404 | mCurrentSubtype = null; |
| 2405 | } |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2406 | } |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2407 | |
| 2408 | if (!setSubtypeOnly) { |
| 2409 | // Set InputMethod here |
| 2410 | mSettings.putSelectedInputMethod(imi != null ? imi.getId() : ""); |
| 2411 | } |
| 2412 | } |
| 2413 | |
| 2414 | private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) { |
| 2415 | InputMethodInfo imi = mMethodMap.get(newDefaultIme); |
| 2416 | int lastSubtypeId = NOT_A_SUBTYPE_ID; |
| 2417 | // newDefaultIme is empty when there is no candidate for the selected IME. |
| 2418 | if (imi != null && !TextUtils.isEmpty(newDefaultIme)) { |
| 2419 | String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme); |
| 2420 | if (subtypeHashCode != null) { |
| 2421 | try { |
| 2422 | lastSubtypeId = getSubtypeIdFromHashCode( |
| 2423 | imi, Integer.valueOf(subtypeHashCode)); |
| 2424 | } catch (NumberFormatException e) { |
| 2425 | Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e); |
| 2426 | } |
| 2427 | } |
| 2428 | } |
| 2429 | setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false); |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | private int getSelectedInputMethodSubtypeId(String id) { |
| 2433 | InputMethodInfo imi = mMethodMap.get(id); |
| 2434 | if (imi == null) { |
| 2435 | return NOT_A_SUBTYPE_ID; |
| 2436 | } |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2437 | int subtypeId; |
| 2438 | try { |
| 2439 | subtypeId = Settings.Secure.getInt(mContext.getContentResolver(), |
| 2440 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE); |
| 2441 | } catch (SettingNotFoundException e) { |
| 2442 | return NOT_A_SUBTYPE_ID; |
| 2443 | } |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2444 | return getSubtypeIdFromHashCode(imi, subtypeId); |
| 2445 | } |
| 2446 | |
| 2447 | private int getSubtypeIdFromHashCode(InputMethodInfo imi, int subtypeHashCode) { |
| satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2448 | if (imi != null) { |
| Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2449 | final int subtypeCount = imi.getSubtypeCount(); |
| 2450 | for (int i = 0; i < subtypeCount; ++i) { |
| 2451 | InputMethodSubtype ims = imi.getSubtypeAt(i); |
| satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2452 | if (subtypeHashCode == ims.hashCode()) { |
| 2453 | return i; |
| 2454 | } |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2455 | } |
| 2456 | } |
| 2457 | return NOT_A_SUBTYPE_ID; |
| 2458 | } |
| 2459 | |
| satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 2460 | private static ArrayList<InputMethodSubtype> getImplicitlyApplicableSubtypesLocked( |
| 2461 | Resources res, InputMethodInfo imi) { |
| 2462 | final List<InputMethodSubtype> subtypes = getSubtypes(imi); |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2463 | final String systemLocale = res.getConfiguration().locale.toString(); |
| satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2464 | if (TextUtils.isEmpty(systemLocale)) return new ArrayList<InputMethodSubtype>(); |
| satok | 4a553e3 | 2011-10-03 17:05:50 +0900 | [diff] [blame] | 2465 | final HashMap<String, InputMethodSubtype> applicableModeAndSubtypesMap = |
| satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2466 | new HashMap<String, InputMethodSubtype>(); |
| satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2467 | final int N = subtypes.size(); |
| 2468 | boolean containsKeyboardSubtype = false; |
| 2469 | for (int i = 0; i < N; ++i) { |
| satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 2470 | // scan overriding implicitly enabled subtypes. |
| 2471 | InputMethodSubtype subtype = subtypes.get(i); |
| 2472 | if (subtype.overridesImplicitlyEnabledSubtype()) { |
| 2473 | final String mode = subtype.getMode(); |
| 2474 | if (!applicableModeAndSubtypesMap.containsKey(mode)) { |
| 2475 | applicableModeAndSubtypesMap.put(mode, subtype); |
| 2476 | } |
| 2477 | } |
| 2478 | } |
| 2479 | if (applicableModeAndSubtypesMap.size() > 0) { |
| 2480 | return new ArrayList<InputMethodSubtype>(applicableModeAndSubtypesMap.values()); |
| 2481 | } |
| 2482 | for (int i = 0; i < N; ++i) { |
| satok | 4a553e3 | 2011-10-03 17:05:50 +0900 | [diff] [blame] | 2483 | final InputMethodSubtype subtype = subtypes.get(i); |
| satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2484 | final String locale = subtype.getLocale(); |
| 2485 | final String mode = subtype.getMode(); |
| 2486 | // When system locale starts with subtype's locale, that subtype will be applicable |
| 2487 | // for system locale |
| 2488 | // For instance, it's clearly applicable for cases like system locale = en_US and |
| 2489 | // subtype = en, but it is not necessarily considered applicable for cases like system |
| 2490 | // locale = en and subtype = en_US. |
| 2491 | // We just call systemLocale.startsWith(locale) in this function because there is no |
| 2492 | // need to find applicable subtypes aggressively unlike |
| 2493 | // findLastResortApplicableSubtypeLocked. |
| 2494 | if (systemLocale.startsWith(locale)) { |
| satok | 4a553e3 | 2011-10-03 17:05:50 +0900 | [diff] [blame] | 2495 | final InputMethodSubtype applicableSubtype = applicableModeAndSubtypesMap.get(mode); |
| satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2496 | // If more applicable subtypes are contained, skip. |
| satok | 4a553e3 | 2011-10-03 17:05:50 +0900 | [diff] [blame] | 2497 | if (applicableSubtype != null) { |
| 2498 | if (systemLocale.equals(applicableSubtype.getLocale())) continue; |
| 2499 | if (!systemLocale.equals(locale)) continue; |
| 2500 | } |
| satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2501 | applicableModeAndSubtypesMap.put(mode, subtype); |
| satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2502 | if (!containsKeyboardSubtype |
| 2503 | && SUBTYPE_MODE_KEYBOARD.equalsIgnoreCase(subtype.getMode())) { |
| 2504 | containsKeyboardSubtype = true; |
| 2505 | } |
| 2506 | } |
| 2507 | } |
| satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 2508 | final ArrayList<InputMethodSubtype> applicableSubtypes = new ArrayList<InputMethodSubtype>( |
| satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2509 | applicableModeAndSubtypesMap.values()); |
| satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2510 | if (!containsKeyboardSubtype) { |
| 2511 | InputMethodSubtype lastResortKeyboardSubtype = findLastResortApplicableSubtypeLocked( |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2512 | res, subtypes, SUBTYPE_MODE_KEYBOARD, systemLocale, true); |
| satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2513 | if (lastResortKeyboardSubtype != null) { |
| 2514 | applicableSubtypes.add(lastResortKeyboardSubtype); |
| 2515 | } |
| 2516 | } |
| 2517 | return applicableSubtypes; |
| 2518 | } |
| 2519 | |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2520 | /** |
| 2521 | * If there are no selected subtypes, tries finding the most applicable one according to the |
| 2522 | * given locale. |
| 2523 | * @param subtypes this function will search the most applicable subtype in subtypes |
| 2524 | * @param mode subtypes will be filtered by mode |
| 2525 | * @param locale subtypes will be filtered by locale |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2526 | * @param canIgnoreLocaleAsLastResort if this function can't find the most applicable subtype, |
| 2527 | * it will return the first subtype matched with mode |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2528 | * @return the most applicable subtypeId |
| 2529 | */ |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2530 | private static InputMethodSubtype findLastResortApplicableSubtypeLocked( |
| 2531 | Resources res, List<InputMethodSubtype> subtypes, String mode, String locale, |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2532 | boolean canIgnoreLocaleAsLastResort) { |
| satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2533 | if (subtypes == null || subtypes.size() == 0) { |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2534 | return null; |
| satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2535 | } |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2536 | if (TextUtils.isEmpty(locale)) { |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2537 | locale = res.getConfiguration().locale.toString(); |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2538 | } |
| satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2539 | final String language = locale.substring(0, 2); |
| 2540 | boolean partialMatchFound = false; |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2541 | InputMethodSubtype applicableSubtype = null; |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2542 | InputMethodSubtype firstMatchedModeSubtype = null; |
| satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2543 | final int N = subtypes.size(); |
| 2544 | for (int i = 0; i < N; ++i) { |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2545 | InputMethodSubtype subtype = subtypes.get(i); |
| 2546 | final String subtypeLocale = subtype.getLocale(); |
| satok | d871343 | 2011-01-18 00:55:13 +0900 | [diff] [blame] | 2547 | // An applicable subtype should match "mode". If mode is null, mode will be ignored, |
| 2548 | // and all subtypes with all modes can be candidates. |
| 2549 | if (mode == null || subtypes.get(i).getMode().equalsIgnoreCase(mode)) { |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2550 | if (firstMatchedModeSubtype == null) { |
| 2551 | firstMatchedModeSubtype = subtype; |
| 2552 | } |
| satok | 9ef0283 | 2010-11-04 21:17:48 +0900 | [diff] [blame] | 2553 | if (locale.equals(subtypeLocale)) { |
| 2554 | // Exact match (e.g. system locale is "en_US" and subtype locale is "en_US") |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2555 | applicableSubtype = subtype; |
| satok | 9ef0283 | 2010-11-04 21:17:48 +0900 | [diff] [blame] | 2556 | break; |
| 2557 | } else if (!partialMatchFound && subtypeLocale.startsWith(language)) { |
| 2558 | // Partial match (e.g. system locale is "en_US" and subtype locale is "en") |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2559 | applicableSubtype = subtype; |
| satok | 9ef0283 | 2010-11-04 21:17:48 +0900 | [diff] [blame] | 2560 | partialMatchFound = true; |
| 2561 | } |
| satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2562 | } |
| 2563 | } |
| 2564 | |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2565 | if (applicableSubtype == null && canIgnoreLocaleAsLastResort) { |
| 2566 | return firstMatchedModeSubtype; |
| satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2567 | } |
| 2568 | |
| satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2569 | // The first subtype applicable to the system locale will be defined as the most applicable |
| 2570 | // subtype. |
| 2571 | if (DEBUG) { |
| satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2572 | if (applicableSubtype != null) { |
| 2573 | Slog.d(TAG, "Applicable InputMethodSubtype was found: " |
| 2574 | + applicableSubtype.getMode() + "," + applicableSubtype.getLocale()); |
| 2575 | } |
| satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2576 | } |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2577 | return applicableSubtype; |
| satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2578 | } |
| 2579 | |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2580 | // If there are no selected shortcuts, tries finding the most applicable ones. |
| 2581 | private Pair<InputMethodInfo, InputMethodSubtype> |
| 2582 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) { |
| 2583 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 2584 | InputMethodInfo mostApplicableIMI = null; |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2585 | InputMethodSubtype mostApplicableSubtype = null; |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2586 | boolean foundInSystemIME = false; |
| 2587 | |
| 2588 | // Search applicable subtype for each InputMethodInfo |
| 2589 | for (InputMethodInfo imi: imis) { |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2590 | final String imiId = imi.getId(); |
| 2591 | if (foundInSystemIME && !imiId.equals(mCurMethodId)) { |
| 2592 | continue; |
| 2593 | } |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2594 | InputMethodSubtype subtype = null; |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2595 | final List<InputMethodSubtype> enabledSubtypes = |
| 2596 | getEnabledInputMethodSubtypeList(imi, true); |
| 2597 | // 1. Search by the current subtype's locale from enabledSubtypes. |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2598 | if (mCurrentSubtype != null) { |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2599 | subtype = findLastResortApplicableSubtypeLocked( |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2600 | mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false); |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2601 | } |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2602 | // 2. Search by the system locale from enabledSubtypes. |
| 2603 | // 3. Search the first enabled subtype matched with mode from enabledSubtypes. |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2604 | if (subtype == null) { |
| 2605 | subtype = findLastResortApplicableSubtypeLocked( |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2606 | mRes, enabledSubtypes, mode, null, true); |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2607 | } |
| satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 2608 | final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes = |
| 2609 | getOverridingImplicitlyEnabledSubtypes(imi, mode); |
| 2610 | final ArrayList<InputMethodSubtype> subtypesForSearch = |
| 2611 | overridingImplicitlyEnabledSubtypes.isEmpty() |
| 2612 | ? getSubtypes(imi) : overridingImplicitlyEnabledSubtypes; |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2613 | // 4. Search by the current subtype's locale from all subtypes. |
| 2614 | if (subtype == null && mCurrentSubtype != null) { |
| 2615 | subtype = findLastResortApplicableSubtypeLocked( |
| satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 2616 | mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false); |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2617 | } |
| 2618 | // 5. Search by the system locale from all subtypes. |
| 2619 | // 6. Search the first enabled subtype matched with mode from all subtypes. |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2620 | if (subtype == null) { |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2621 | subtype = findLastResortApplicableSubtypeLocked( |
| satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 2622 | mRes, subtypesForSearch, mode, null, true); |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2623 | } |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2624 | if (subtype != null) { |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2625 | if (imiId.equals(mCurMethodId)) { |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2626 | // The current input method is the most applicable IME. |
| 2627 | mostApplicableIMI = imi; |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2628 | mostApplicableSubtype = subtype; |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2629 | break; |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2630 | } else if (!foundInSystemIME) { |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2631 | // The system input method is 2nd applicable IME. |
| 2632 | mostApplicableIMI = imi; |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2633 | mostApplicableSubtype = subtype; |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2634 | if ((imi.getServiceInfo().applicationInfo.flags |
| 2635 | & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 2636 | foundInSystemIME = true; |
| 2637 | } |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2638 | } |
| 2639 | } |
| 2640 | } |
| 2641 | if (DEBUG) { |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2642 | if (mostApplicableIMI != null) { |
| 2643 | Slog.w(TAG, "Most applicable shortcut input method was:" |
| 2644 | + mostApplicableIMI.getId()); |
| 2645 | if (mostApplicableSubtype != null) { |
| 2646 | Slog.w(TAG, "Most applicable shortcut input method subtype was:" |
| 2647 | + "," + mostApplicableSubtype.getMode() + "," |
| 2648 | + mostApplicableSubtype.getLocale()); |
| 2649 | } |
| 2650 | } |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2651 | } |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2652 | if (mostApplicableIMI != null) { |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2653 | return new Pair<InputMethodInfo, InputMethodSubtype> (mostApplicableIMI, |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2654 | mostApplicableSubtype); |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2655 | } else { |
| 2656 | return null; |
| 2657 | } |
| 2658 | } |
| 2659 | |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2660 | /** |
| 2661 | * @return Return the current subtype of this input method. |
| 2662 | */ |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2663 | @Override |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2664 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2665 | boolean subtypeIsSelected = false; |
| 2666 | try { |
| 2667 | subtypeIsSelected = Settings.Secure.getInt(mContext.getContentResolver(), |
| 2668 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE) != NOT_A_SUBTYPE_ID; |
| 2669 | } catch (SettingNotFoundException e) { |
| 2670 | } |
| satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2671 | synchronized (mMethodMap) { |
| satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2672 | if (!subtypeIsSelected || mCurrentSubtype == null) { |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2673 | String lastInputMethodId = Settings.Secure.getString( |
| 2674 | mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2675 | int subtypeId = getSelectedInputMethodSubtypeId(lastInputMethodId); |
| 2676 | if (subtypeId == NOT_A_SUBTYPE_ID) { |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2677 | InputMethodInfo imi = mMethodMap.get(lastInputMethodId); |
| 2678 | if (imi != null) { |
| 2679 | // If there are no selected subtypes, the framework will try to find |
| satok | d871343 | 2011-01-18 00:55:13 +0900 | [diff] [blame] | 2680 | // the most applicable subtype from explicitly or implicitly enabled |
| 2681 | // subtypes. |
| 2682 | List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = |
| 2683 | getEnabledInputMethodSubtypeList(imi, true); |
| 2684 | // If there is only one explicitly or implicitly enabled subtype, |
| 2685 | // just returns it. |
| 2686 | if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) { |
| 2687 | mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0); |
| 2688 | } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) { |
| 2689 | mCurrentSubtype = findLastResortApplicableSubtypeLocked( |
| 2690 | mRes, explicitlyOrImplicitlyEnabledSubtypes, |
| 2691 | SUBTYPE_MODE_KEYBOARD, null, true); |
| 2692 | if (mCurrentSubtype == null) { |
| 2693 | mCurrentSubtype = findLastResortApplicableSubtypeLocked( |
| 2694 | mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, |
| 2695 | true); |
| 2696 | } |
| 2697 | } |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2698 | } |
| satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2699 | } else { |
| satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2700 | mCurrentSubtype = |
| Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2701 | getSubtypes(mMethodMap.get(lastInputMethodId)).get(subtypeId); |
| satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2702 | } |
| satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2703 | } |
| satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2704 | return mCurrentSubtype; |
| satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2705 | } |
| satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2706 | } |
| 2707 | |
| satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2708 | private void addShortcutInputMethodAndSubtypes(InputMethodInfo imi, |
| 2709 | InputMethodSubtype subtype) { |
| 2710 | if (mShortcutInputMethodsAndSubtypes.containsKey(imi)) { |
| 2711 | mShortcutInputMethodsAndSubtypes.get(imi).add(subtype); |
| 2712 | } else { |
| 2713 | ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); |
| 2714 | subtypes.add(subtype); |
| 2715 | mShortcutInputMethodsAndSubtypes.put(imi, subtypes); |
| 2716 | } |
| 2717 | } |
| 2718 | |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2719 | // TODO: We should change the return type from List to List<Parcelable> |
| satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 2720 | @SuppressWarnings("rawtypes") |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2721 | @Override |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2722 | public List getShortcutInputMethodsAndSubtypes() { |
| 2723 | synchronized (mMethodMap) { |
| satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2724 | ArrayList<Object> ret = new ArrayList<Object>(); |
| satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2725 | if (mShortcutInputMethodsAndSubtypes.size() == 0) { |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2726 | // If there are no selected shortcut subtypes, the framework will try to find |
| 2727 | // the most applicable subtype from all subtypes whose mode is |
| 2728 | // SUBTYPE_MODE_VOICE. This is an exceptional case, so we will hardcode the mode. |
| satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2729 | Pair<InputMethodInfo, InputMethodSubtype> info = |
| 2730 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked( |
| 2731 | SUBTYPE_MODE_VOICE); |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2732 | if (info != null) { |
| satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2733 | ret.add(info.first); |
| 2734 | ret.add(info.second); |
| satok | 7599a7fb | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 2735 | } |
| satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 2736 | return ret; |
| satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2737 | } |
| satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2738 | for (InputMethodInfo imi: mShortcutInputMethodsAndSubtypes.keySet()) { |
| 2739 | ret.add(imi); |
| 2740 | for (InputMethodSubtype subtype: mShortcutInputMethodsAndSubtypes.get(imi)) { |
| 2741 | ret.add(subtype); |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2742 | } |
| 2743 | } |
| satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2744 | return ret; |
| satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2745 | } |
| 2746 | } |
| 2747 | |
| satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2748 | @Override |
| satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 2749 | public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) { |
| 2750 | synchronized (mMethodMap) { |
| 2751 | if (subtype != null && mCurMethodId != null) { |
| 2752 | InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 2753 | int subtypeId = getSubtypeIdFromHashCode(imi, subtype.hashCode()); |
| 2754 | if (subtypeId != NOT_A_SUBTYPE_ID) { |
| 2755 | setInputMethodLocked(mCurMethodId, subtypeId); |
| 2756 | return true; |
| 2757 | } |
| 2758 | } |
| 2759 | return false; |
| 2760 | } |
| 2761 | } |
| 2762 | |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2763 | /** |
| 2764 | * Utility class for putting and getting settings for InputMethod |
| 2765 | * TODO: Move all putters and getters of settings to this class. |
| 2766 | */ |
| 2767 | private static class InputMethodSettings { |
| 2768 | // The string for enabled input method is saved as follows: |
| 2769 | // example: ("ime0;subtype0;subtype1;subtype2:ime1:ime2;subtype0") |
| 2770 | private static final char INPUT_METHOD_SEPARATER = ':'; |
| 2771 | private static final char INPUT_METHOD_SUBTYPE_SEPARATER = ';'; |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2772 | private final TextUtils.SimpleStringSplitter mInputMethodSplitter = |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2773 | new TextUtils.SimpleStringSplitter(INPUT_METHOD_SEPARATER); |
| 2774 | |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2775 | private final TextUtils.SimpleStringSplitter mSubtypeSplitter = |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2776 | new TextUtils.SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATER); |
| 2777 | |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2778 | private final Resources mRes; |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2779 | private final ContentResolver mResolver; |
| 2780 | private final HashMap<String, InputMethodInfo> mMethodMap; |
| 2781 | private final ArrayList<InputMethodInfo> mMethodList; |
| 2782 | |
| 2783 | private String mEnabledInputMethodsStrCache; |
| 2784 | |
| 2785 | private static void buildEnabledInputMethodsSettingString( |
| 2786 | StringBuilder builder, Pair<String, ArrayList<String>> pair) { |
| 2787 | String id = pair.first; |
| 2788 | ArrayList<String> subtypes = pair.second; |
| 2789 | builder.append(id); |
| satok | 57c767c | 2010-11-01 22:34:08 +0900 | [diff] [blame] | 2790 | // Inputmethod and subtypes are saved in the settings as follows: |
| 2791 | // ime0;subtype0;subtype1:ime1;subtype0:ime2:ime3;subtype0;subtype1 |
| 2792 | for (String subtypeId: subtypes) { |
| 2793 | builder.append(INPUT_METHOD_SUBTYPE_SEPARATER).append(subtypeId); |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | public InputMethodSettings( |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 2798 | Resources res, ContentResolver resolver, |
| 2799 | HashMap<String, InputMethodInfo> methodMap, ArrayList<InputMethodInfo> methodList) { |
| 2800 | mRes = res; |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2801 | mResolver = resolver; |
| 2802 | mMethodMap = methodMap; |
| 2803 | mMethodList = methodList; |
| 2804 | } |
| 2805 | |
| 2806 | public List<InputMethodInfo> getEnabledInputMethodListLocked() { |
| 2807 | return createEnabledInputMethodListLocked( |
| 2808 | getEnabledInputMethodsAndSubtypeListLocked()); |
| 2809 | } |
| 2810 | |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2811 | public List<Pair<InputMethodInfo, ArrayList<String>>> |
| satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2812 | getEnabledInputMethodAndSubtypeHashCodeListLocked() { |
| 2813 | return createEnabledInputMethodAndSubtypeHashCodeListLocked( |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2814 | getEnabledInputMethodsAndSubtypeListLocked()); |
| 2815 | } |
| 2816 | |
| satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2817 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked( |
| 2818 | InputMethodInfo imi) { |
| 2819 | List<Pair<String, ArrayList<String>>> imsList = |
| 2820 | getEnabledInputMethodsAndSubtypeListLocked(); |
| 2821 | ArrayList<InputMethodSubtype> enabledSubtypes = |
| 2822 | new ArrayList<InputMethodSubtype>(); |
| satok | 884ef9a | 2010-11-18 10:39:46 +0900 | [diff] [blame] | 2823 | if (imi != null) { |
| 2824 | for (Pair<String, ArrayList<String>> imsPair : imsList) { |
| 2825 | InputMethodInfo info = mMethodMap.get(imsPair.first); |
| 2826 | if (info != null && info.getId().equals(imi.getId())) { |
| Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 2827 | final int subtypeCount = info.getSubtypeCount(); |
| 2828 | for (int i = 0; i < subtypeCount; ++i) { |
| 2829 | InputMethodSubtype ims = info.getSubtypeAt(i); |
| satok | 884ef9a | 2010-11-18 10:39:46 +0900 | [diff] [blame] | 2830 | for (String s: imsPair.second) { |
| 2831 | if (String.valueOf(ims.hashCode()).equals(s)) { |
| 2832 | enabledSubtypes.add(ims); |
| 2833 | } |
| satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2834 | } |
| 2835 | } |
| satok | 884ef9a | 2010-11-18 10:39:46 +0900 | [diff] [blame] | 2836 | break; |
| satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2837 | } |
| satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2838 | } |
| 2839 | } |
| 2840 | return enabledSubtypes; |
| 2841 | } |
| 2842 | |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2843 | // At the initial boot, the settings for input methods are not set, |
| 2844 | // so we need to enable IME in that case. |
| 2845 | public void enableAllIMEsIfThereIsNoEnabledIME() { |
| 2846 | if (TextUtils.isEmpty(getEnabledInputMethodsStr())) { |
| 2847 | StringBuilder sb = new StringBuilder(); |
| 2848 | final int N = mMethodList.size(); |
| 2849 | for (int i = 0; i < N; i++) { |
| 2850 | InputMethodInfo imi = mMethodList.get(i); |
| 2851 | Slog.i(TAG, "Adding: " + imi.getId()); |
| 2852 | if (i > 0) sb.append(':'); |
| 2853 | sb.append(imi.getId()); |
| 2854 | } |
| 2855 | putEnabledInputMethodsStr(sb.toString()); |
| 2856 | } |
| 2857 | } |
| 2858 | |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2859 | private List<Pair<String, ArrayList<String>>> getEnabledInputMethodsAndSubtypeListLocked() { |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2860 | ArrayList<Pair<String, ArrayList<String>>> imsList |
| 2861 | = new ArrayList<Pair<String, ArrayList<String>>>(); |
| 2862 | final String enabledInputMethodsStr = getEnabledInputMethodsStr(); |
| 2863 | if (TextUtils.isEmpty(enabledInputMethodsStr)) { |
| 2864 | return imsList; |
| 2865 | } |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2866 | mInputMethodSplitter.setString(enabledInputMethodsStr); |
| 2867 | while (mInputMethodSplitter.hasNext()) { |
| 2868 | String nextImsStr = mInputMethodSplitter.next(); |
| 2869 | mSubtypeSplitter.setString(nextImsStr); |
| 2870 | if (mSubtypeSplitter.hasNext()) { |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2871 | ArrayList<String> subtypeHashes = new ArrayList<String>(); |
| 2872 | // The first element is ime id. |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2873 | String imeId = mSubtypeSplitter.next(); |
| 2874 | while (mSubtypeSplitter.hasNext()) { |
| 2875 | subtypeHashes.add(mSubtypeSplitter.next()); |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2876 | } |
| 2877 | imsList.add(new Pair<String, ArrayList<String>>(imeId, subtypeHashes)); |
| 2878 | } |
| 2879 | } |
| 2880 | return imsList; |
| 2881 | } |
| 2882 | |
| 2883 | public void appendAndPutEnabledInputMethodLocked(String id, boolean reloadInputMethodStr) { |
| 2884 | if (reloadInputMethodStr) { |
| 2885 | getEnabledInputMethodsStr(); |
| 2886 | } |
| 2887 | if (TextUtils.isEmpty(mEnabledInputMethodsStrCache)) { |
| 2888 | // Add in the newly enabled input method. |
| 2889 | putEnabledInputMethodsStr(id); |
| 2890 | } else { |
| 2891 | putEnabledInputMethodsStr( |
| 2892 | mEnabledInputMethodsStrCache + INPUT_METHOD_SEPARATER + id); |
| 2893 | } |
| 2894 | } |
| 2895 | |
| 2896 | /** |
| 2897 | * Build and put a string of EnabledInputMethods with removing specified Id. |
| 2898 | * @return the specified id was removed or not. |
| 2899 | */ |
| 2900 | public boolean buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 2901 | StringBuilder builder, List<Pair<String, ArrayList<String>>> imsList, String id) { |
| 2902 | boolean isRemoved = false; |
| 2903 | boolean needsAppendSeparator = false; |
| 2904 | for (Pair<String, ArrayList<String>> ims: imsList) { |
| 2905 | String curId = ims.first; |
| 2906 | if (curId.equals(id)) { |
| 2907 | // We are disabling this input method, and it is |
| 2908 | // currently enabled. Skip it to remove from the |
| 2909 | // new list. |
| 2910 | isRemoved = true; |
| 2911 | } else { |
| 2912 | if (needsAppendSeparator) { |
| 2913 | builder.append(INPUT_METHOD_SEPARATER); |
| 2914 | } else { |
| 2915 | needsAppendSeparator = true; |
| 2916 | } |
| 2917 | buildEnabledInputMethodsSettingString(builder, ims); |
| 2918 | } |
| 2919 | } |
| 2920 | if (isRemoved) { |
| 2921 | // Update the setting with the new list of input methods. |
| 2922 | putEnabledInputMethodsStr(builder.toString()); |
| 2923 | } |
| 2924 | return isRemoved; |
| 2925 | } |
| 2926 | |
| 2927 | private List<InputMethodInfo> createEnabledInputMethodListLocked( |
| 2928 | List<Pair<String, ArrayList<String>>> imsList) { |
| 2929 | final ArrayList<InputMethodInfo> res = new ArrayList<InputMethodInfo>(); |
| 2930 | for (Pair<String, ArrayList<String>> ims: imsList) { |
| 2931 | InputMethodInfo info = mMethodMap.get(ims.first); |
| 2932 | if (info != null) { |
| 2933 | res.add(info); |
| 2934 | } |
| 2935 | } |
| 2936 | return res; |
| 2937 | } |
| 2938 | |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2939 | private List<Pair<InputMethodInfo, ArrayList<String>>> |
| satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2940 | createEnabledInputMethodAndSubtypeHashCodeListLocked( |
| satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2941 | List<Pair<String, ArrayList<String>>> imsList) { |
| 2942 | final ArrayList<Pair<InputMethodInfo, ArrayList<String>>> res |
| 2943 | = new ArrayList<Pair<InputMethodInfo, ArrayList<String>>>(); |
| 2944 | for (Pair<String, ArrayList<String>> ims : imsList) { |
| 2945 | InputMethodInfo info = mMethodMap.get(ims.first); |
| 2946 | if (info != null) { |
| 2947 | res.add(new Pair<InputMethodInfo, ArrayList<String>>(info, ims.second)); |
| 2948 | } |
| 2949 | } |
| 2950 | return res; |
| 2951 | } |
| 2952 | |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2953 | private void putEnabledInputMethodsStr(String str) { |
| 2954 | Settings.Secure.putString(mResolver, Settings.Secure.ENABLED_INPUT_METHODS, str); |
| 2955 | mEnabledInputMethodsStrCache = str; |
| 2956 | } |
| 2957 | |
| 2958 | private String getEnabledInputMethodsStr() { |
| 2959 | mEnabledInputMethodsStrCache = Settings.Secure.getString( |
| 2960 | mResolver, Settings.Secure.ENABLED_INPUT_METHODS); |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2961 | if (DEBUG) { |
| 2962 | Slog.d(TAG, "getEnabledInputMethodsStr: " + mEnabledInputMethodsStrCache); |
| 2963 | } |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2964 | return mEnabledInputMethodsStrCache; |
| 2965 | } |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2966 | |
| 2967 | private void saveSubtypeHistory( |
| 2968 | List<Pair<String, String>> savedImes, String newImeId, String newSubtypeId) { |
| 2969 | StringBuilder builder = new StringBuilder(); |
| 2970 | boolean isImeAdded = false; |
| 2971 | if (!TextUtils.isEmpty(newImeId) && !TextUtils.isEmpty(newSubtypeId)) { |
| 2972 | builder.append(newImeId).append(INPUT_METHOD_SUBTYPE_SEPARATER).append( |
| 2973 | newSubtypeId); |
| 2974 | isImeAdded = true; |
| 2975 | } |
| 2976 | for (Pair<String, String> ime: savedImes) { |
| 2977 | String imeId = ime.first; |
| 2978 | String subtypeId = ime.second; |
| 2979 | if (TextUtils.isEmpty(subtypeId)) { |
| 2980 | subtypeId = NOT_A_SUBTYPE_ID_STR; |
| 2981 | } |
| 2982 | if (isImeAdded) { |
| 2983 | builder.append(INPUT_METHOD_SEPARATER); |
| 2984 | } else { |
| 2985 | isImeAdded = true; |
| 2986 | } |
| 2987 | builder.append(imeId).append(INPUT_METHOD_SUBTYPE_SEPARATER).append( |
| 2988 | subtypeId); |
| 2989 | } |
| 2990 | // Remove the last INPUT_METHOD_SEPARATER |
| 2991 | putSubtypeHistoryStr(builder.toString()); |
| 2992 | } |
| 2993 | |
| 2994 | public void addSubtypeToHistory(String imeId, String subtypeId) { |
| 2995 | List<Pair<String, String>> subtypeHistory = loadInputMethodAndSubtypeHistoryLocked(); |
| 2996 | for (Pair<String, String> ime: subtypeHistory) { |
| 2997 | if (ime.first.equals(imeId)) { |
| 2998 | if (DEBUG) { |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 2999 | Slog.v(TAG, "Subtype found in the history: " + imeId + ", " |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3000 | + ime.second); |
| 3001 | } |
| 3002 | // We should break here |
| 3003 | subtypeHistory.remove(ime); |
| 3004 | break; |
| 3005 | } |
| 3006 | } |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 3007 | if (DEBUG) { |
| 3008 | Slog.v(TAG, "Add subtype to the history: " + imeId + ", " + subtypeId); |
| 3009 | } |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3010 | saveSubtypeHistory(subtypeHistory, imeId, subtypeId); |
| 3011 | } |
| 3012 | |
| 3013 | private void putSubtypeHistoryStr(String str) { |
| 3014 | if (DEBUG) { |
| 3015 | Slog.d(TAG, "putSubtypeHistoryStr: " + str); |
| 3016 | } |
| 3017 | Settings.Secure.putString( |
| 3018 | mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY, str); |
| 3019 | } |
| 3020 | |
| 3021 | public Pair<String, String> getLastInputMethodAndSubtypeLocked() { |
| 3022 | // Gets the first one from the history |
| 3023 | return getLastSubtypeForInputMethodLockedInternal(null); |
| 3024 | } |
| 3025 | |
| 3026 | public String getLastSubtypeForInputMethodLocked(String imeId) { |
| 3027 | Pair<String, String> ime = getLastSubtypeForInputMethodLockedInternal(imeId); |
| 3028 | if (ime != null) { |
| 3029 | return ime.second; |
| 3030 | } else { |
| 3031 | return null; |
| 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | private Pair<String, String> getLastSubtypeForInputMethodLockedInternal(String imeId) { |
| 3036 | List<Pair<String, ArrayList<String>>> enabledImes = |
| 3037 | getEnabledInputMethodsAndSubtypeListLocked(); |
| 3038 | List<Pair<String, String>> subtypeHistory = loadInputMethodAndSubtypeHistoryLocked(); |
| satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3039 | for (Pair<String, String> imeAndSubtype : subtypeHistory) { |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3040 | final String imeInTheHistory = imeAndSubtype.first; |
| 3041 | // If imeId is empty, returns the first IME and subtype in the history |
| 3042 | if (TextUtils.isEmpty(imeId) || imeInTheHistory.equals(imeId)) { |
| 3043 | final String subtypeInTheHistory = imeAndSubtype.second; |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3044 | final String subtypeHashCode = |
| 3045 | getEnabledSubtypeHashCodeForInputMethodAndSubtypeLocked( |
| 3046 | enabledImes, imeInTheHistory, subtypeInTheHistory); |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3047 | if (!TextUtils.isEmpty(subtypeHashCode)) { |
| 3048 | if (DEBUG) { |
| satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 3049 | Slog.d(TAG, "Enabled subtype found in the history: " + subtypeHashCode); |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3050 | } |
| 3051 | return new Pair<String, String>(imeInTheHistory, subtypeHashCode); |
| 3052 | } |
| 3053 | } |
| 3054 | } |
| 3055 | if (DEBUG) { |
| 3056 | Slog.d(TAG, "No enabled IME found in the history"); |
| 3057 | } |
| 3058 | return null; |
| 3059 | } |
| 3060 | |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3061 | private String getEnabledSubtypeHashCodeForInputMethodAndSubtypeLocked(List<Pair<String, |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3062 | ArrayList<String>>> enabledImes, String imeId, String subtypeHashCode) { |
| 3063 | for (Pair<String, ArrayList<String>> enabledIme: enabledImes) { |
| 3064 | if (enabledIme.first.equals(imeId)) { |
| satok | f6cafb6 | 2011-01-17 16:29:02 +0900 | [diff] [blame] | 3065 | final ArrayList<String> explicitlyEnabledSubtypes = enabledIme.second; |
| 3066 | if (explicitlyEnabledSubtypes.size() == 0) { |
| 3067 | // If there are no explicitly enabled subtypes, applicable subtypes are |
| 3068 | // enabled implicitly. |
| satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 3069 | InputMethodInfo imi = mMethodMap.get(imeId); |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3070 | // If IME is enabled and no subtypes are enabled, applicable subtypes |
| 3071 | // are enabled implicitly, so needs to treat them to be enabled. |
| satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 3072 | if (imi != null && imi.getSubtypeCount() > 0) { |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3073 | List<InputMethodSubtype> implicitlySelectedSubtypes = |
| satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 3074 | getImplicitlyApplicableSubtypesLocked(mRes, imi); |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3075 | if (implicitlySelectedSubtypes != null) { |
| 3076 | final int N = implicitlySelectedSubtypes.size(); |
| 3077 | for (int i = 0; i < N; ++i) { |
| 3078 | final InputMethodSubtype st = implicitlySelectedSubtypes.get(i); |
| 3079 | if (String.valueOf(st.hashCode()).equals(subtypeHashCode)) { |
| 3080 | return subtypeHashCode; |
| 3081 | } |
| 3082 | } |
| 3083 | } |
| 3084 | } |
| 3085 | } else { |
| satok | f6cafb6 | 2011-01-17 16:29:02 +0900 | [diff] [blame] | 3086 | for (String s: explicitlyEnabledSubtypes) { |
| satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3087 | if (s.equals(subtypeHashCode)) { |
| 3088 | // If both imeId and subtypeId are enabled, return subtypeId. |
| 3089 | return s; |
| 3090 | } |
| satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | // If imeId was enabled but subtypeId was disabled. |
| 3094 | return NOT_A_SUBTYPE_ID_STR; |
| 3095 | } |
| 3096 | } |
| 3097 | // If both imeId and subtypeId are disabled, return null |
| 3098 | return null; |
| 3099 | } |
| 3100 | |
| 3101 | private List<Pair<String, String>> loadInputMethodAndSubtypeHistoryLocked() { |
| 3102 | ArrayList<Pair<String, String>> imsList = new ArrayList<Pair<String, String>>(); |
| 3103 | final String subtypeHistoryStr = getSubtypeHistoryStr(); |
| 3104 | if (TextUtils.isEmpty(subtypeHistoryStr)) { |
| 3105 | return imsList; |
| 3106 | } |
| 3107 | mInputMethodSplitter.setString(subtypeHistoryStr); |
| 3108 | while (mInputMethodSplitter.hasNext()) { |
| 3109 | String nextImsStr = mInputMethodSplitter.next(); |
| 3110 | mSubtypeSplitter.setString(nextImsStr); |
| 3111 | if (mSubtypeSplitter.hasNext()) { |
| 3112 | String subtypeId = NOT_A_SUBTYPE_ID_STR; |
| 3113 | // The first element is ime id. |
| 3114 | String imeId = mSubtypeSplitter.next(); |
| 3115 | while (mSubtypeSplitter.hasNext()) { |
| 3116 | subtypeId = mSubtypeSplitter.next(); |
| 3117 | break; |
| 3118 | } |
| 3119 | imsList.add(new Pair<String, String>(imeId, subtypeId)); |
| 3120 | } |
| 3121 | } |
| 3122 | return imsList; |
| 3123 | } |
| 3124 | |
| 3125 | private String getSubtypeHistoryStr() { |
| 3126 | if (DEBUG) { |
| 3127 | Slog.d(TAG, "getSubtypeHistoryStr: " + Settings.Secure.getString( |
| 3128 | mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY)); |
| 3129 | } |
| 3130 | return Settings.Secure.getString( |
| 3131 | mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY); |
| 3132 | } |
| 3133 | |
| 3134 | public void putSelectedInputMethod(String imeId) { |
| 3135 | Settings.Secure.putString(mResolver, Settings.Secure.DEFAULT_INPUT_METHOD, imeId); |
| 3136 | } |
| 3137 | |
| 3138 | public void putSelectedSubtype(int subtypeId) { |
| 3139 | Settings.Secure.putInt( |
| 3140 | mResolver, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, subtypeId); |
| 3141 | } |
| satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3142 | } |
| 3143 | |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3144 | private static class InputMethodFileManager { |
| 3145 | private static final String SYSTEM_PATH = "system"; |
| 3146 | private static final String INPUT_METHOD_PATH = "inputmethod"; |
| 3147 | private static final String ADDITIONAL_SUBTYPES_FILE_NAME = "subtypes.xml"; |
| 3148 | private static final String NODE_SUBTYPES = "subtypes"; |
| 3149 | private static final String NODE_SUBTYPE = "subtype"; |
| 3150 | private static final String NODE_IMI = "imi"; |
| 3151 | private static final String ATTR_ID = "id"; |
| 3152 | private static final String ATTR_LABEL = "label"; |
| 3153 | private static final String ATTR_ICON = "icon"; |
| 3154 | private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale"; |
| 3155 | private static final String ATTR_IME_SUBTYPE_MODE = "imeSubtypeMode"; |
| 3156 | private static final String ATTR_IME_SUBTYPE_EXTRA_VALUE = "imeSubtypeExtraValue"; |
| 3157 | private static final String ATTR_IS_AUXILIARY = "isAuxiliary"; |
| 3158 | private final AtomicFile mAdditionalInputMethodSubtypeFile; |
| 3159 | private final HashMap<String, InputMethodInfo> mMethodMap; |
| 3160 | private final HashMap<String, List<InputMethodSubtype>> mSubtypesMap = |
| 3161 | new HashMap<String, List<InputMethodSubtype>>(); |
| 3162 | public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap) { |
| 3163 | if (methodMap == null) { |
| 3164 | throw new NullPointerException("methodMap is null"); |
| 3165 | } |
| 3166 | mMethodMap = methodMap; |
| 3167 | final File systemDir = new File(Environment.getDataDirectory(), SYSTEM_PATH); |
| 3168 | final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH); |
| 3169 | if (!inputMethodDir.mkdirs()) { |
| 3170 | Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath()); |
| 3171 | } |
| 3172 | final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME); |
| 3173 | mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile); |
| 3174 | if (!subtypeFile.exists()) { |
| 3175 | // If "subtypes.xml" doesn't exist, create a blank file. |
| 3176 | writeAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile, |
| 3177 | methodMap); |
| 3178 | } else { |
| 3179 | readAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile); |
| 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | private void deleteAllInputMethodSubtypes(String imiId) { |
| 3184 | synchronized (mMethodMap) { |
| 3185 | mSubtypesMap.remove(imiId); |
| 3186 | writeAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile, |
| 3187 | mMethodMap); |
| 3188 | } |
| 3189 | } |
| 3190 | |
| 3191 | public void addInputMethodSubtypes( |
| satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 3192 | InputMethodInfo imi, InputMethodSubtype[] additionalSubtypes) { |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3193 | synchronized (mMethodMap) { |
| 3194 | final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); |
| 3195 | final int N = additionalSubtypes.length; |
| 3196 | for (int i = 0; i < N; ++i) { |
| 3197 | final InputMethodSubtype subtype = additionalSubtypes[i]; |
| satok | ed2b24e | 2011-08-31 18:03:21 +0900 | [diff] [blame] | 3198 | if (!subtypes.contains(subtype)) { |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3199 | subtypes.add(subtype); |
| 3200 | } |
| 3201 | } |
| satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 3202 | mSubtypesMap.put(imi.getId(), subtypes); |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3203 | writeAdditionalInputMethodSubtypes(mSubtypesMap, mAdditionalInputMethodSubtypeFile, |
| 3204 | mMethodMap); |
| 3205 | } |
| 3206 | } |
| 3207 | |
| 3208 | public HashMap<String, List<InputMethodSubtype>> getAllAdditionalInputMethodSubtypes() { |
| 3209 | synchronized (mMethodMap) { |
| 3210 | return mSubtypesMap; |
| 3211 | } |
| 3212 | } |
| 3213 | |
| 3214 | private static void writeAdditionalInputMethodSubtypes( |
| 3215 | HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile, |
| 3216 | HashMap<String, InputMethodInfo> methodMap) { |
| 3217 | // Safety net for the case that this function is called before methodMap is set. |
| 3218 | final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0; |
| 3219 | FileOutputStream fos = null; |
| 3220 | try { |
| 3221 | fos = subtypesFile.startWrite(); |
| 3222 | final XmlSerializer out = new FastXmlSerializer(); |
| 3223 | out.setOutput(fos, "utf-8"); |
| 3224 | out.startDocument(null, true); |
| 3225 | out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 3226 | out.startTag(null, NODE_SUBTYPES); |
| 3227 | for (String imiId : allSubtypes.keySet()) { |
| 3228 | if (isSetMethodMap && !methodMap.containsKey(imiId)) { |
| 3229 | Slog.w(TAG, "IME uninstalled or not valid.: " + imiId); |
| 3230 | continue; |
| 3231 | } |
| 3232 | out.startTag(null, NODE_IMI); |
| 3233 | out.attribute(null, ATTR_ID, imiId); |
| 3234 | final List<InputMethodSubtype> subtypesList = allSubtypes.get(imiId); |
| 3235 | final int N = subtypesList.size(); |
| 3236 | for (int i = 0; i < N; ++i) { |
| 3237 | final InputMethodSubtype subtype = subtypesList.get(i); |
| 3238 | out.startTag(null, NODE_SUBTYPE); |
| 3239 | out.attribute(null, ATTR_ICON, String.valueOf(subtype.getIconResId())); |
| 3240 | out.attribute(null, ATTR_LABEL, String.valueOf(subtype.getNameResId())); |
| 3241 | out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale()); |
| 3242 | out.attribute(null, ATTR_IME_SUBTYPE_MODE, subtype.getMode()); |
| 3243 | out.attribute(null, ATTR_IME_SUBTYPE_EXTRA_VALUE, subtype.getExtraValue()); |
| 3244 | out.attribute(null, ATTR_IS_AUXILIARY, |
| 3245 | String.valueOf(subtype.isAuxiliary() ? 1 : 0)); |
| 3246 | out.endTag(null, NODE_SUBTYPE); |
| 3247 | } |
| 3248 | out.endTag(null, NODE_IMI); |
| 3249 | } |
| 3250 | out.endTag(null, NODE_SUBTYPES); |
| 3251 | out.endDocument(); |
| 3252 | subtypesFile.finishWrite(fos); |
| 3253 | } catch (java.io.IOException e) { |
| 3254 | Slog.w(TAG, "Error writing subtypes", e); |
| 3255 | if (fos != null) { |
| 3256 | subtypesFile.failWrite(fos); |
| 3257 | } |
| 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | private static void readAdditionalInputMethodSubtypes( |
| 3262 | HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) { |
| 3263 | if (allSubtypes == null || subtypesFile == null) return; |
| 3264 | allSubtypes.clear(); |
| 3265 | FileInputStream fis = null; |
| 3266 | try { |
| 3267 | fis = subtypesFile.openRead(); |
| 3268 | final XmlPullParser parser = Xml.newPullParser(); |
| 3269 | parser.setInput(fis, null); |
| 3270 | int type = parser.getEventType(); |
| 3271 | // Skip parsing until START_TAG |
| 3272 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 3273 | && type != XmlPullParser.END_DOCUMENT) {} |
| 3274 | String firstNodeName = parser.getName(); |
| 3275 | if (!NODE_SUBTYPES.equals(firstNodeName)) { |
| 3276 | throw new XmlPullParserException("Xml doesn't start with subtypes"); |
| 3277 | } |
| 3278 | final int depth =parser.getDepth(); |
| 3279 | String currentImiId = null; |
| 3280 | ArrayList<InputMethodSubtype> tempSubtypesArray = null; |
| 3281 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 3282 | || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
| 3283 | if (type != XmlPullParser.START_TAG) |
| 3284 | continue; |
| 3285 | final String nodeName = parser.getName(); |
| 3286 | if (NODE_IMI.equals(nodeName)) { |
| 3287 | currentImiId = parser.getAttributeValue(null, ATTR_ID); |
| 3288 | if (TextUtils.isEmpty(currentImiId)) { |
| 3289 | Slog.w(TAG, "Invalid imi id found in subtypes.xml"); |
| 3290 | continue; |
| 3291 | } |
| 3292 | tempSubtypesArray = new ArrayList<InputMethodSubtype>(); |
| 3293 | allSubtypes.put(currentImiId, tempSubtypesArray); |
| 3294 | } else if (NODE_SUBTYPE.equals(nodeName)) { |
| 3295 | if (TextUtils.isEmpty(currentImiId) || tempSubtypesArray == null) { |
| 3296 | Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId); |
| 3297 | continue; |
| 3298 | } |
| 3299 | final int icon = Integer.valueOf( |
| 3300 | parser.getAttributeValue(null, ATTR_ICON)); |
| 3301 | final int label = Integer.valueOf( |
| 3302 | parser.getAttributeValue(null, ATTR_LABEL)); |
| 3303 | final String imeSubtypeLocale = |
| 3304 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE); |
| 3305 | final String imeSubtypeMode = |
| 3306 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_MODE); |
| 3307 | final String imeSubtypeExtraValue = |
| 3308 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_EXTRA_VALUE); |
| satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 3309 | final boolean isAuxiliary = "1".equals(String.valueOf( |
| 3310 | parser.getAttributeValue(null, ATTR_IS_AUXILIARY))); |
| satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3311 | final InputMethodSubtype subtype = |
| 3312 | new InputMethodSubtype(label, icon, imeSubtypeLocale, |
| 3313 | imeSubtypeMode, imeSubtypeExtraValue, isAuxiliary); |
| 3314 | tempSubtypesArray.add(subtype); |
| 3315 | } |
| 3316 | } |
| 3317 | } catch (XmlPullParserException e) { |
| 3318 | Slog.w(TAG, "Error reading subtypes: " + e); |
| 3319 | return; |
| 3320 | } catch (java.io.IOException e) { |
| 3321 | Slog.w(TAG, "Error reading subtypes: " + e); |
| 3322 | return; |
| 3323 | } catch (NumberFormatException e) { |
| 3324 | Slog.w(TAG, "Error reading subtypes: " + e); |
| 3325 | return; |
| 3326 | } finally { |
| 3327 | if (fis != null) { |
| 3328 | try { |
| 3329 | fis.close(); |
| 3330 | } catch (java.io.IOException e1) { |
| 3331 | Slog.w(TAG, "Failed to close."); |
| 3332 | } |
| 3333 | } |
| 3334 | } |
| 3335 | } |
| 3336 | } |
| 3337 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3338 | // ---------------------------------------------------------------------- |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3339 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3340 | @Override |
| 3341 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 3342 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 3343 | != PackageManager.PERMISSION_GRANTED) { |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3344 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3345 | pw.println("Permission Denial: can't dump InputMethodManager from from pid=" |
| 3346 | + Binder.getCallingPid() |
| 3347 | + ", uid=" + Binder.getCallingUid()); |
| 3348 | return; |
| 3349 | } |
| 3350 | |
| 3351 | IInputMethod method; |
| 3352 | ClientState client; |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3353 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3354 | final Printer p = new PrintWriterPrinter(pw); |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3355 | |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3356 | synchronized (mMethodMap) { |
| 3357 | p.println("Current Input Method Manager state:"); |
| 3358 | int N = mMethodList.size(); |
| 3359 | p.println(" Input Methods:"); |
| 3360 | for (int i=0; i<N; i++) { |
| 3361 | InputMethodInfo info = mMethodList.get(i); |
| 3362 | p.println(" InputMethod #" + i + ":"); |
| 3363 | info.dump(p, " "); |
| 3364 | } |
| 3365 | p.println(" Clients:"); |
| 3366 | for (ClientState ci : mClients.values()) { |
| 3367 | p.println(" Client " + ci + ":"); |
| 3368 | p.println(" client=" + ci.client); |
| 3369 | p.println(" inputContext=" + ci.inputContext); |
| 3370 | p.println(" sessionRequested=" + ci.sessionRequested); |
| 3371 | p.println(" curSession=" + ci.curSession); |
| 3372 | } |
| The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3373 | p.println(" mCurMethodId=" + mCurMethodId); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3374 | client = mCurClient; |
| The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 3375 | p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq); |
| 3376 | p.println(" mCurFocusedWindow=" + mCurFocusedWindow); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3377 | p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection |
| 3378 | + " mBoundToMethod=" + mBoundToMethod); |
| 3379 | p.println(" mCurToken=" + mCurToken); |
| 3380 | p.println(" mCurIntent=" + mCurIntent); |
| 3381 | method = mCurMethod; |
| 3382 | p.println(" mCurMethod=" + mCurMethod); |
| 3383 | p.println(" mEnabledSession=" + mEnabledSession); |
| 3384 | p.println(" mShowRequested=" + mShowRequested |
| 3385 | + " mShowExplicitlyRequested=" + mShowExplicitlyRequested |
| 3386 | + " mShowForced=" + mShowForced |
| 3387 | + " mInputShown=" + mInputShown); |
| Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 3388 | p.println(" mSystemReady=" + mSystemReady + " mScreenOn=" + mScreenOn); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3389 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3390 | |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3391 | p.println(" "); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3392 | if (client != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3393 | pw.flush(); |
| 3394 | try { |
| 3395 | client.client.asBinder().dump(fd, args); |
| 3396 | } catch (RemoteException e) { |
| 3397 | p.println("Input method client dead: " + e); |
| 3398 | } |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3399 | } else { |
| 3400 | p.println("No input method client."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3401 | } |
| Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3402 | |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3403 | p.println(" "); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3404 | if (method != null) { |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3405 | pw.flush(); |
| 3406 | try { |
| 3407 | method.asBinder().dump(fd, args); |
| 3408 | } catch (RemoteException e) { |
| 3409 | p.println("Input method service dead: " + e); |
| 3410 | } |
| Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3411 | } else { |
| 3412 | p.println("No input method service."); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3413 | } |
| 3414 | } |
| 3415 | } |