The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006-2008 The Android Open Source Project |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | * use this file except in compliance with the License. You may obtain a copy of |
| 6 | * the License at |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 7 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 9 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations under |
| 14 | * the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server; |
| 18 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 19 | import com.android.internal.content.PackageMonitor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import com.android.internal.os.HandlerCaller; |
| 21 | import com.android.internal.view.IInputContext; |
| 22 | import com.android.internal.view.IInputMethod; |
| 23 | import com.android.internal.view.IInputMethodCallback; |
| 24 | import com.android.internal.view.IInputMethodClient; |
| 25 | import com.android.internal.view.IInputMethodManager; |
| 26 | import com.android.internal.view.IInputMethodSession; |
| 27 | import com.android.internal.view.InputBindResult; |
| 28 | |
Joe Onorato | 7a0f36b | 2010-06-07 10:24:36 -0700 | [diff] [blame] | 29 | import com.android.server.StatusBarManagerService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| 31 | import org.xmlpull.v1.XmlPullParserException; |
| 32 | |
| 33 | import android.app.ActivityManagerNative; |
| 34 | import android.app.AlertDialog; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 35 | import android.app.PendingIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.content.ComponentName; |
| 37 | import android.content.ContentResolver; |
| 38 | import android.content.Context; |
| 39 | import android.content.DialogInterface; |
| 40 | import android.content.IntentFilter; |
| 41 | import android.content.DialogInterface.OnCancelListener; |
| 42 | import android.content.Intent; |
| 43 | import android.content.ServiceConnection; |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 44 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
| 46 | import android.content.pm.ResolveInfo; |
| 47 | import android.content.pm.ServiceInfo; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 48 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.content.res.Resources; |
| 50 | import android.content.res.TypedArray; |
| 51 | import android.database.ContentObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.os.Binder; |
| 53 | import android.os.Handler; |
| 54 | import android.os.IBinder; |
| 55 | import android.os.IInterface; |
| 56 | import android.os.Message; |
| 57 | import android.os.Parcel; |
| 58 | import android.os.RemoteException; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 59 | import android.os.ResultReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.os.ServiceManager; |
| 61 | import android.os.SystemClock; |
| 62 | import android.provider.Settings; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 63 | import android.provider.Settings.Secure; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 64 | import android.provider.Settings.SettingNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.text.TextUtils; |
| 66 | import android.util.EventLog; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 67 | import android.util.Pair; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 68 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.util.PrintWriterPrinter; |
| 70 | import android.util.Printer; |
| 71 | import android.view.IWindowManager; |
| 72 | import android.view.WindowManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 73 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.view.inputmethod.InputBinding; |
| 75 | import android.view.inputmethod.InputMethod; |
| 76 | import android.view.inputmethod.InputMethodInfo; |
| 77 | import android.view.inputmethod.InputMethodManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 78 | import android.view.inputmethod.InputMethodSubtype; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | |
| 80 | import java.io.FileDescriptor; |
| 81 | import java.io.IOException; |
| 82 | import java.io.PrintWriter; |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 83 | import java.text.Collator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import java.util.ArrayList; |
| 85 | import java.util.HashMap; |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 86 | import java.util.HashSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import java.util.List; |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 88 | import java.util.Map; |
| 89 | import java.util.TreeMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * This class provides a system service that manages input methods. |
| 93 | */ |
| 94 | public class InputMethodManagerService extends IInputMethodManager.Stub |
| 95 | implements ServiceConnection, Handler.Callback { |
| 96 | static final boolean DEBUG = false; |
| 97 | static final String TAG = "InputManagerService"; |
| 98 | |
| 99 | static final int MSG_SHOW_IM_PICKER = 1; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 100 | static final int MSG_SHOW_IM_SUBTYPE_PICKER = 2; |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 101 | static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 3; |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 102 | static final int MSG_SHOW_IM_CONFIG = 4; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | static final int MSG_UNBIND_INPUT = 1000; |
| 105 | static final int MSG_BIND_INPUT = 1010; |
| 106 | static final int MSG_SHOW_SOFT_INPUT = 1020; |
| 107 | static final int MSG_HIDE_SOFT_INPUT = 1030; |
| 108 | static final int MSG_ATTACH_TOKEN = 1040; |
| 109 | static final int MSG_CREATE_SESSION = 1050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | static final int MSG_START_INPUT = 2000; |
| 112 | static final int MSG_RESTART_INPUT = 2010; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | static final int MSG_UNBIND_METHOD = 3000; |
| 115 | static final int MSG_BIND_METHOD = 3010; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | static final long TIME_TO_RECONNECT = 10*1000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 118 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 119 | private static final int NOT_A_SUBTYPE_ID = -1; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 120 | private static final String NOT_A_SUBTYPE_ID_STR = String.valueOf(NOT_A_SUBTYPE_ID); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 121 | private static final String EXTRA_INPUT_METHOD_ID = "input_method_id"; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 122 | private static final String SUBTYPE_MODE_KEYBOARD = "keyboard"; |
| 123 | private static final String SUBTYPE_MODE_VOICE = "voice"; |
| 124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | final Context mContext; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 126 | final Resources mRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | final Handler mHandler; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 128 | final InputMethodSettings mSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | final SettingsObserver mSettingsObserver; |
Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 130 | final StatusBarManagerService mStatusBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | final IWindowManager mIWindowManager; |
| 132 | final HandlerCaller mCaller; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | final InputBindResult mNoBinding = new InputBindResult(null, null, -1); |
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 | // All known input methods. mMethodMap also serves as the global |
| 137 | // lock for this class. |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 138 | final ArrayList<InputMethodInfo> mMethodList = new ArrayList<InputMethodInfo>(); |
| 139 | final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<String, InputMethodInfo>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | class SessionState { |
| 142 | final ClientState client; |
| 143 | final IInputMethod method; |
| 144 | final IInputMethodSession session; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | @Override |
| 147 | public String toString() { |
| 148 | return "SessionState{uid " + client.uid + " pid " + client.pid |
| 149 | + " method " + Integer.toHexString( |
| 150 | System.identityHashCode(method)) |
| 151 | + " session " + Integer.toHexString( |
| 152 | System.identityHashCode(session)) |
| 153 | + "}"; |
| 154 | } |
| 155 | |
| 156 | SessionState(ClientState _client, IInputMethod _method, |
| 157 | IInputMethodSession _session) { |
| 158 | client = _client; |
| 159 | method = _method; |
| 160 | session = _session; |
| 161 | } |
| 162 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | class ClientState { |
| 165 | final IInputMethodClient client; |
| 166 | final IInputContext inputContext; |
| 167 | final int uid; |
| 168 | final int pid; |
| 169 | final InputBinding binding; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 170 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | boolean sessionRequested; |
| 172 | SessionState curSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | @Override |
| 175 | public String toString() { |
| 176 | return "ClientState{" + Integer.toHexString( |
| 177 | System.identityHashCode(this)) + " uid " + uid |
| 178 | + " pid " + pid + "}"; |
| 179 | } |
| 180 | |
| 181 | ClientState(IInputMethodClient _client, IInputContext _inputContext, |
| 182 | int _uid, int _pid) { |
| 183 | client = _client; |
| 184 | inputContext = _inputContext; |
| 185 | uid = _uid; |
| 186 | pid = _pid; |
| 187 | binding = new InputBinding(null, inputContext.asBinder(), uid, pid); |
| 188 | } |
| 189 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | final HashMap<IBinder, ClientState> mClients |
| 192 | = new HashMap<IBinder, ClientState>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | /** |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 195 | * Set once the system is ready to run third party code. |
| 196 | */ |
| 197 | boolean mSystemReady; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 198 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 199 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | * Id of the currently selected input method. |
| 201 | */ |
| 202 | String mCurMethodId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | /** |
| 205 | * The current binding sequence number, incremented every time there is |
| 206 | * a new bind performed. |
| 207 | */ |
| 208 | int mCurSeq; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 209 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | /** |
| 211 | * The client that is currently bound to an input method. |
| 212 | */ |
| 213 | ClientState mCurClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 216 | * The last window token that gained focus. |
| 217 | */ |
| 218 | IBinder mCurFocusedWindow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 219 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 220 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | * The input context last provided by the current client. |
| 222 | */ |
| 223 | IInputContext mCurInputContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | /** |
| 226 | * The attributes last provided by the current client. |
| 227 | */ |
| 228 | EditorInfo mCurAttribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | /** |
| 231 | * The input method ID of the input method service that we are currently |
| 232 | * connected to or in the process of connecting to. |
| 233 | */ |
| 234 | String mCurId; |
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 | /** |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 237 | * The current subtype of the current input method. |
| 238 | */ |
| 239 | private InputMethodSubtype mCurrentSubtype; |
| 240 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 241 | // This list contains the pairs of InputMethodInfo and InputMethodSubtype. |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 242 | private final HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>> |
| 243 | mShortcutInputMethodsAndSubtypes = |
| 244 | new HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>>(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 245 | |
| 246 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | * Set to true if our ServiceConnection is currently actively bound to |
| 248 | * a service (whether or not we have gotten its IBinder back yet). |
| 249 | */ |
| 250 | boolean mHaveConnection; |
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 | * Set if the client has asked for the input method to be shown. |
| 254 | */ |
| 255 | boolean mShowRequested; |
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 | /** |
| 258 | * Set if we were explicitly told to show the input method. |
| 259 | */ |
| 260 | boolean mShowExplicitlyRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | /** |
| 263 | * Set if we were forced to be shown. |
| 264 | */ |
| 265 | boolean mShowForced; |
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 | * Set if we last told the input method to show itself. |
| 269 | */ |
| 270 | boolean mInputShown; |
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 Intent used to connect to the current input method. |
| 274 | */ |
| 275 | Intent mCurIntent; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 276 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 277 | /** |
| 278 | * The token we have made for the currently active input method, to |
| 279 | * identify it in the future. |
| 280 | */ |
| 281 | IBinder mCurToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | /** |
| 284 | * If non-null, this is the input method service we are currently connected |
| 285 | * to. |
| 286 | */ |
| 287 | IInputMethod mCurMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | /** |
| 290 | * Time that we last initiated a bind to the input method, to determine |
| 291 | * if we should try to disconnect and reconnect to it. |
| 292 | */ |
| 293 | long mLastBindTime; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | /** |
| 296 | * Have we called mCurMethod.bindInput()? |
| 297 | */ |
| 298 | boolean mBoundToMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 299 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | /** |
| 301 | * Currently enabled session. Only touched by service thread, not |
| 302 | * protected by a lock. |
| 303 | */ |
| 304 | SessionState mEnabledSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | /** |
| 307 | * True if the screen is on. The value is true initially. |
| 308 | */ |
| 309 | boolean mScreenOn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 310 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | AlertDialog.Builder mDialogBuilder; |
| 312 | AlertDialog mSwitchingDialog; |
| 313 | InputMethodInfo[] mIms; |
| 314 | CharSequence[] mItems; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 315 | int[] mSubtypeIds; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | class SettingsObserver extends ContentObserver { |
| 318 | SettingsObserver(Handler handler) { |
| 319 | super(handler); |
| 320 | ContentResolver resolver = mContext.getContentResolver(); |
| 321 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 322 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 323 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 324 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | @Override public void onChange(boolean selfChange) { |
| 328 | synchronized (mMethodMap) { |
| 329 | updateFromSettingsLocked(); |
| 330 | } |
| 331 | } |
| 332 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | class ScreenOnOffReceiver extends android.content.BroadcastReceiver { |
| 335 | @Override |
| 336 | public void onReceive(Context context, Intent intent) { |
| 337 | if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { |
| 338 | mScreenOn = true; |
| 339 | } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { |
| 340 | mScreenOn = false; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 341 | } else if (intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) { |
| 342 | hideInputMethodMenu(); |
| 343 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 345 | Slog.w(TAG, "Unexpected intent " + intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | // Inform the current client of the change in active status |
| 349 | try { |
| 350 | if (mCurClient != null && mCurClient.client != null) { |
| 351 | mCurClient.client.setActive(mScreenOn); |
| 352 | } |
| 353 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 354 | 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] | 355 | + mCurClient.pid + " uid " + mCurClient.uid); |
| 356 | } |
| 357 | } |
| 358 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 359 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 360 | class MyPackageMonitor extends PackageMonitor { |
| 361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 363 | 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] | 364 | synchronized (mMethodMap) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 365 | String curInputMethodId = Settings.Secure.getString(mContext |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| 367 | final int N = mMethodList.size(); |
| 368 | if (curInputMethodId != null) { |
| 369 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 370 | InputMethodInfo imi = mMethodList.get(i); |
| 371 | if (imi.getId().equals(curInputMethodId)) { |
| 372 | for (String pkg : packages) { |
| 373 | if (imi.getPackageName().equals(pkg)) { |
| 374 | if (!doit) { |
| 375 | return true; |
| 376 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 377 | resetSelectedInputMethodAndSubtypeLocked(""); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 378 | chooseNewDefaultIMELocked(); |
| 379 | return true; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | @Override |
| 390 | public void onSomePackagesChanged() { |
| 391 | synchronized (mMethodMap) { |
| 392 | InputMethodInfo curIm = null; |
| 393 | String curInputMethodId = Settings.Secure.getString(mContext |
| 394 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| 395 | final int N = mMethodList.size(); |
| 396 | if (curInputMethodId != null) { |
| 397 | for (int i=0; i<N; i++) { |
| 398 | InputMethodInfo imi = mMethodList.get(i); |
| 399 | if (imi.getId().equals(curInputMethodId)) { |
| 400 | curIm = imi; |
| 401 | } |
| 402 | int change = isPackageDisappearing(imi.getPackageName()); |
| 403 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 404 | || change == PACKAGE_PERMANENT_CHANGE) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 405 | Slog.i(TAG, "Input method uninstalled, disabling: " |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 406 | + imi.getComponent()); |
| 407 | setInputMethodEnabledLocked(imi.getId(), false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 411 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 412 | buildInputMethodListLocked(mMethodList, mMethodMap); |
| 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 415 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 416 | if (curIm != null) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 417 | int change = isPackageDisappearing(curIm.getPackageName()); |
| 418 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 419 | || change == PACKAGE_PERMANENT_CHANGE) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 420 | ServiceInfo si = null; |
| 421 | try { |
| 422 | si = mContext.getPackageManager().getServiceInfo( |
| 423 | curIm.getComponent(), 0); |
| 424 | } catch (PackageManager.NameNotFoundException ex) { |
| 425 | } |
| 426 | if (si == null) { |
| 427 | // Uh oh, current input method is no longer around! |
| 428 | // Pick another one... |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 429 | Slog.i(TAG, "Current input method removed: " + curInputMethodId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 430 | if (!chooseNewDefaultIMELocked()) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 431 | changed = true; |
| 432 | curIm = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 433 | Slog.i(TAG, "Unsetting current input method"); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 434 | resetSelectedInputMethodAndSubtypeLocked(""); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 435 | } |
| 436 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 437 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 438 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 439 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 440 | if (curIm == null) { |
| 441 | // We currently don't have a default input method... is |
| 442 | // one now available? |
| 443 | changed = chooseNewDefaultIMELocked(); |
| 444 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 445 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 446 | if (changed) { |
| 447 | updateFromSettingsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | } |
| 449 | } |
| 450 | } |
| 451 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 452 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | class MethodCallback extends IInputMethodCallback.Stub { |
| 454 | final IInputMethod mMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | MethodCallback(IInputMethod method) { |
| 457 | mMethod = method; |
| 458 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 459 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | public void finishedEvent(int seq, boolean handled) throws RemoteException { |
| 461 | } |
| 462 | |
| 463 | public void sessionCreated(IInputMethodSession session) throws RemoteException { |
| 464 | onSessionCreated(mMethod, session); |
| 465 | } |
| 466 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 467 | |
Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 468 | public InputMethodManagerService(Context context, StatusBarManagerService statusBar) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | mContext = context; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 470 | mRes = context.getResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | mHandler = new Handler(this); |
| 472 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 473 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
| 474 | mCaller = new HandlerCaller(context, new HandlerCaller.Callback() { |
| 475 | public void executeMessage(Message msg) { |
| 476 | handleMessage(msg); |
| 477 | } |
| 478 | }); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 479 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 480 | (new MyPackageMonitor()).register(mContext, true); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 481 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | IntentFilter screenOnOffFilt = new IntentFilter(); |
| 483 | screenOnOffFilt.addAction(Intent.ACTION_SCREEN_ON); |
| 484 | screenOnOffFilt.addAction(Intent.ACTION_SCREEN_OFF); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 485 | screenOnOffFilt.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | mContext.registerReceiver(new ScreenOnOffReceiver(), screenOnOffFilt); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 487 | |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 488 | mStatusBar = statusBar; |
| 489 | statusBar.setIconVisibility("ime", false); |
| 490 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 491 | // mSettings should be created before buildInputMethodListLocked |
| 492 | mSettings = new InputMethodSettings(context.getContentResolver(), mMethodMap, mMethodList); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | buildInputMethodListLocked(mMethodList, mMethodMap); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 494 | mSettings.enableAllIMEsIfThereIsNoEnabledIME(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 496 | if (TextUtils.isEmpty(Settings.Secure.getString( |
| 497 | mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | InputMethodInfo defIm = null; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 499 | for (InputMethodInfo imi: mMethodList) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | if (defIm == null && imi.getIsDefaultResourceId() != 0) { |
| 501 | try { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 502 | Resources res = context.createPackageContext( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | imi.getPackageName(), 0).getResources(); |
| 504 | if (res.getBoolean(imi.getIsDefaultResourceId())) { |
| 505 | defIm = imi; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 506 | Slog.i(TAG, "Selected default: " + imi.getId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | } |
| 508 | } catch (PackageManager.NameNotFoundException ex) { |
| 509 | } catch (Resources.NotFoundException ex) { |
| 510 | } |
| 511 | } |
| 512 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 513 | if (defIm == null && mMethodList.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | defIm = mMethodList.get(0); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 515 | Slog.i(TAG, "No default found, using " + defIm.getId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 517 | if (defIm != null) { |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 518 | setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | } |
| 520 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 521 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | mSettingsObserver = new SettingsObserver(mHandler); |
| 523 | updateFromSettingsLocked(); |
| 524 | } |
| 525 | |
| 526 | @Override |
| 527 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 528 | throws RemoteException { |
| 529 | try { |
| 530 | return super.onTransact(code, data, reply, flags); |
| 531 | } catch (RuntimeException e) { |
| 532 | // The input method manager only throws security exceptions, so let's |
| 533 | // log all others. |
| 534 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 535 | Slog.e(TAG, "Input Method Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | } |
| 537 | throw e; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | public void systemReady() { |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 542 | synchronized (mMethodMap) { |
| 543 | if (!mSystemReady) { |
| 544 | mSystemReady = true; |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 545 | try { |
| 546 | startInputInnerLocked(); |
| 547 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 548 | Slog.w(TAG, "Unexpected exception", e); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 549 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 553 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | public List<InputMethodInfo> getInputMethodList() { |
| 555 | synchronized (mMethodMap) { |
| 556 | return new ArrayList<InputMethodInfo>(mMethodList); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | public List<InputMethodInfo> getEnabledInputMethodList() { |
| 561 | synchronized (mMethodMap) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 562 | return mSettings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 566 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(InputMethodInfo imi, |
| 567 | boolean allowsImplicitlySelectedSubtypes) { |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 568 | synchronized (mMethodMap) { |
satok | 884ef9a | 2010-11-18 10:39:46 +0900 | [diff] [blame] | 569 | if (imi == null && mCurMethodId != null) { |
| 570 | imi = mMethodMap.get(mCurMethodId); |
| 571 | } |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 572 | final List<InputMethodSubtype> enabledSubtypes = |
| 573 | mSettings.getEnabledInputMethodSubtypeListLocked(imi); |
| 574 | if (!allowsImplicitlySelectedSubtypes || enabledSubtypes.size() > 0) { |
| 575 | return enabledSubtypes; |
| 576 | } else { |
| 577 | return getApplicableSubtypesLocked(imi.getSubtypes()); |
| 578 | } |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | public void addClient(IInputMethodClient client, |
| 583 | IInputContext inputContext, int uid, int pid) { |
| 584 | synchronized (mMethodMap) { |
| 585 | mClients.put(client.asBinder(), new ClientState(client, |
| 586 | inputContext, uid, pid)); |
| 587 | } |
| 588 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | public void removeClient(IInputMethodClient client) { |
| 591 | synchronized (mMethodMap) { |
| 592 | mClients.remove(client.asBinder()); |
| 593 | } |
| 594 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 595 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | void executeOrSendMessage(IInterface target, Message msg) { |
| 597 | if (target.asBinder() instanceof Binder) { |
| 598 | mCaller.sendMessage(msg); |
| 599 | } else { |
| 600 | handleMessage(msg); |
| 601 | msg.recycle(); |
| 602 | } |
| 603 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 604 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 605 | void unbindCurrentClientLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | if (mCurClient != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 607 | if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | + mCurClient.client.asBinder()); |
| 609 | if (mBoundToMethod) { |
| 610 | mBoundToMethod = false; |
| 611 | if (mCurMethod != null) { |
| 612 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 613 | MSG_UNBIND_INPUT, mCurMethod)); |
| 614 | } |
| 615 | } |
| 616 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 617 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 618 | mCurClient.sessionRequested = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 619 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | // Call setActive(false) on the old client |
| 621 | try { |
| 622 | mCurClient.client.setActive(false); |
| 623 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 624 | 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] | 625 | + mCurClient.pid + " uid " + mCurClient.uid); |
| 626 | } |
| 627 | mCurClient = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 628 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 629 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | } |
| 631 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | private int getImeShowFlags() { |
| 634 | int flags = 0; |
| 635 | if (mShowForced) { |
| 636 | flags |= InputMethod.SHOW_FORCED |
| 637 | | InputMethod.SHOW_EXPLICIT; |
| 638 | } else if (mShowExplicitlyRequested) { |
| 639 | flags |= InputMethod.SHOW_EXPLICIT; |
| 640 | } |
| 641 | return flags; |
| 642 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 643 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | private int getAppShowFlags() { |
| 645 | int flags = 0; |
| 646 | if (mShowForced) { |
| 647 | flags |= InputMethodManager.SHOW_FORCED; |
| 648 | } else if (!mShowExplicitlyRequested) { |
| 649 | flags |= InputMethodManager.SHOW_IMPLICIT; |
| 650 | } |
| 651 | return flags; |
| 652 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 653 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 654 | InputBindResult attachNewInputLocked(boolean initial, boolean needResult) { |
| 655 | if (!mBoundToMethod) { |
| 656 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 657 | MSG_BIND_INPUT, mCurMethod, mCurClient.binding)); |
| 658 | mBoundToMethod = true; |
| 659 | } |
| 660 | final SessionState session = mCurClient.curSession; |
| 661 | if (initial) { |
| 662 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 663 | MSG_START_INPUT, session, mCurInputContext, mCurAttribute)); |
| 664 | } else { |
| 665 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 666 | MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute)); |
| 667 | } |
| 668 | if (mShowRequested) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 669 | 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] | 670 | showCurrentInputLocked(getAppShowFlags(), null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | } |
| 672 | return needResult |
| 673 | ? new InputBindResult(session.session, mCurId, mCurSeq) |
| 674 | : null; |
| 675 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 677 | InputBindResult startInputLocked(IInputMethodClient client, |
| 678 | IInputContext inputContext, EditorInfo attribute, |
| 679 | boolean initial, boolean needResult) { |
| 680 | // If no method is currently selected, do nothing. |
| 681 | if (mCurMethodId == null) { |
| 682 | return mNoBinding; |
| 683 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | ClientState cs = mClients.get(client.asBinder()); |
| 686 | if (cs == null) { |
| 687 | throw new IllegalArgumentException("unknown client " |
| 688 | + client.asBinder()); |
| 689 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 690 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | try { |
| 692 | if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) { |
| 693 | // Check with the window manager to make sure this client actually |
| 694 | // has a window with focus. If not, reject. This is thread safe |
| 695 | // because if the focus changes some time before or after, the |
| 696 | // next client receiving focus that has any interest in input will |
| 697 | // be calling through here after that change happens. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 698 | 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] | 699 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
| 700 | return null; |
| 701 | } |
| 702 | } catch (RemoteException e) { |
| 703 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 704 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | if (mCurClient != cs) { |
| 706 | // If the client is changing, we need to switch over to the new |
| 707 | // one. |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 708 | unbindCurrentClientLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 709 | if (DEBUG) Slog.v(TAG, "switching to client: client = " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | + cs.client.asBinder()); |
| 711 | |
| 712 | // If the screen is on, inform the new client it is active |
| 713 | if (mScreenOn) { |
| 714 | try { |
| 715 | cs.client.setActive(mScreenOn); |
| 716 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 717 | 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] | 718 | + cs.pid + " uid " + cs.uid); |
| 719 | } |
| 720 | } |
| 721 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 723 | // Bump up the sequence for this client and attach it. |
| 724 | mCurSeq++; |
| 725 | if (mCurSeq <= 0) mCurSeq = 1; |
| 726 | mCurClient = cs; |
| 727 | mCurInputContext = inputContext; |
| 728 | mCurAttribute = attribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 729 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | // Check if the input method is changing. |
| 731 | if (mCurId != null && mCurId.equals(mCurMethodId)) { |
| 732 | if (cs.curSession != null) { |
| 733 | // Fast case: if we are already connected to the input method, |
| 734 | // then just return it. |
| 735 | return attachNewInputLocked(initial, needResult); |
| 736 | } |
| 737 | if (mHaveConnection) { |
| 738 | if (mCurMethod != null) { |
| 739 | if (!cs.sessionRequested) { |
| 740 | cs.sessionRequested = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 741 | 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] | 742 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 743 | MSG_CREATE_SESSION, mCurMethod, |
| 744 | new MethodCallback(mCurMethod))); |
| 745 | } |
| 746 | // Return to client, and we will get back with it when |
| 747 | // we have had a session made for it. |
| 748 | return new InputBindResult(null, mCurId, mCurSeq); |
| 749 | } else if (SystemClock.uptimeMillis() |
| 750 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 751 | // In this case we have connected to the service, but |
| 752 | // don't yet have its interface. If it hasn't been too |
| 753 | // long since we did the connection, we'll return to |
| 754 | // the client and wait to get the service interface so |
| 755 | // we can report back. If it has been too long, we want |
| 756 | // to fall through so we can try a disconnect/reconnect |
| 757 | // to see if we can get back in touch with the service. |
| 758 | return new InputBindResult(null, mCurId, mCurSeq); |
| 759 | } else { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 760 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, |
| 761 | mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 765 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 766 | return startInputInnerLocked(); |
| 767 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 768 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 769 | InputBindResult startInputInnerLocked() { |
| 770 | if (mCurMethodId == null) { |
| 771 | return mNoBinding; |
| 772 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 773 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 774 | if (!mSystemReady) { |
| 775 | // If the system is not yet ready, we shouldn't be running third |
| 776 | // party code. |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 777 | return new InputBindResult(null, mCurMethodId, mCurSeq); |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 778 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 779 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | InputMethodInfo info = mMethodMap.get(mCurMethodId); |
| 781 | if (info == null) { |
| 782 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 783 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 784 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 785 | unbindCurrentMethodLocked(false); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE); |
| 788 | mCurIntent.setComponent(info.getComponent()); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 789 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 790 | com.android.internal.R.string.input_method_binding_label); |
| 791 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 792 | mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | if (mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE)) { |
| 794 | mLastBindTime = SystemClock.uptimeMillis(); |
| 795 | mHaveConnection = true; |
| 796 | mCurId = info.getId(); |
| 797 | mCurToken = new Binder(); |
| 798 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 799 | if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | mIWindowManager.addWindowToken(mCurToken, |
| 801 | WindowManager.LayoutParams.TYPE_INPUT_METHOD); |
| 802 | } catch (RemoteException e) { |
| 803 | } |
| 804 | return new InputBindResult(null, mCurId, mCurSeq); |
| 805 | } else { |
| 806 | mCurIntent = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 807 | Slog.w(TAG, "Failure connecting to input method service: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | + mCurIntent); |
| 809 | } |
| 810 | return null; |
| 811 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 812 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | public InputBindResult startInput(IInputMethodClient client, |
| 814 | IInputContext inputContext, EditorInfo attribute, |
| 815 | boolean initial, boolean needResult) { |
| 816 | synchronized (mMethodMap) { |
| 817 | final long ident = Binder.clearCallingIdentity(); |
| 818 | try { |
| 819 | return startInputLocked(client, inputContext, attribute, |
| 820 | initial, needResult); |
| 821 | } finally { |
| 822 | Binder.restoreCallingIdentity(ident); |
| 823 | } |
| 824 | } |
| 825 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 826 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | public void finishInput(IInputMethodClient client) { |
| 828 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 829 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 831 | synchronized (mMethodMap) { |
| 832 | if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { |
| 833 | mCurMethod = IInputMethod.Stub.asInterface(service); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 834 | if (mCurToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 835 | Slog.w(TAG, "Service connected without a token!"); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 836 | unbindCurrentMethodLocked(false); |
| 837 | return; |
| 838 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 839 | if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 840 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 841 | MSG_ATTACH_TOKEN, mCurMethod, mCurToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | if (mCurClient != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 843 | if (DEBUG) Slog.v(TAG, "Creating first session while with client " |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 844 | + mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 845 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 846 | MSG_CREATE_SESSION, mCurMethod, |
| 847 | new MethodCallback(mCurMethod))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | void onSessionCreated(IInputMethod method, IInputMethodSession session) { |
| 854 | synchronized (mMethodMap) { |
| 855 | if (mCurMethod != null && method != null |
| 856 | && mCurMethod.asBinder() == method.asBinder()) { |
| 857 | if (mCurClient != null) { |
| 858 | mCurClient.curSession = new SessionState(mCurClient, |
| 859 | method, session); |
| 860 | mCurClient.sessionRequested = false; |
| 861 | InputBindResult res = attachNewInputLocked(true, true); |
| 862 | if (res.method != null) { |
| 863 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
| 864 | MSG_BIND_METHOD, mCurClient.client, res)); |
| 865 | } |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 870 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 871 | void unbindCurrentMethodLocked(boolean reportToClient) { |
| 872 | if (mHaveConnection) { |
| 873 | mContext.unbindService(this); |
| 874 | mHaveConnection = false; |
| 875 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 876 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 877 | if (mCurToken != null) { |
| 878 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 879 | if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 880 | mIWindowManager.removeWindowToken(mCurToken); |
| 881 | } catch (RemoteException e) { |
| 882 | } |
| 883 | mCurToken = null; |
| 884 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 885 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 886 | mCurId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 887 | clearCurMethodLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 888 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 889 | if (reportToClient && mCurClient != null) { |
| 890 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 891 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 892 | } |
| 893 | } |
| 894 | |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 895 | private void finishSession(SessionState sessionState) { |
| 896 | if (sessionState != null && sessionState.session != null) { |
| 897 | try { |
| 898 | sessionState.session.finishSession(); |
| 899 | } catch (RemoteException e) { |
Jean-Baptiste Queru | 9d0f6df | 2010-03-29 12:55:09 -0700 | [diff] [blame] | 900 | Slog.w(TAG, "Session failed to close due to remote exception", e); |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 904 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 905 | void clearCurMethodLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | if (mCurMethod != null) { |
| 907 | for (ClientState cs : mClients.values()) { |
| 908 | cs.sessionRequested = false; |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 909 | finishSession(cs.curSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | cs.curSession = null; |
| 911 | } |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 912 | |
| 913 | finishSession(mEnabledSession); |
| 914 | mEnabledSession = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | mCurMethod = null; |
| 916 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 917 | mStatusBar.setIconVisibility("ime", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 918 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | public void onServiceDisconnected(ComponentName name) { |
| 921 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 922 | if (DEBUG) Slog.v(TAG, "Service disconnected: " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | + " mCurIntent=" + mCurIntent); |
| 924 | if (mCurMethod != null && mCurIntent != null |
| 925 | && name.equals(mCurIntent.getComponent())) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 926 | clearCurMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 927 | // We consider this to be a new bind attempt, since the system |
| 928 | // should now try to restart the service for us. |
| 929 | mLastBindTime = SystemClock.uptimeMillis(); |
| 930 | mShowRequested = mInputShown; |
| 931 | mInputShown = false; |
| 932 | if (mCurClient != null) { |
| 933 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 934 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 935 | } |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | public void updateStatusIcon(IBinder token, String packageName, int iconId) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 941 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 942 | long ident = Binder.clearCallingIdentity(); |
| 943 | try { |
| 944 | if (token == null || mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 945 | 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] | 946 | return; |
| 947 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 948 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | synchronized (mMethodMap) { |
| 950 | if (iconId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 951 | if (DEBUG) Slog.d(TAG, "hide the small icon for the input method"); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 952 | mStatusBar.setIconVisibility("ime", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | } else if (packageName != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 954 | if (DEBUG) Slog.d(TAG, "show a small icon for the input method"); |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 955 | mStatusBar.setIcon("ime", packageName, iconId, 0); |
| 956 | mStatusBar.setIconVisibility("ime", true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | } finally { |
| 960 | Binder.restoreCallingIdentity(ident); |
| 961 | } |
| 962 | } |
| 963 | |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 964 | public void setIMEButtonVisible(IBinder token, boolean visible) { |
| 965 | int uid = Binder.getCallingUid(); |
| 966 | long ident = Binder.clearCallingIdentity(); |
| 967 | try { |
| 968 | if (token == null || mCurToken != token) { |
| 969 | Slog.w(TAG, "Ignoring setIMEButtonVisible of uid " + uid + " token: " + token); |
| 970 | return; |
| 971 | } |
| 972 | |
| 973 | synchronized (mMethodMap) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 974 | mStatusBar.setIMEButtonVisible(token, visible); |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 975 | } |
| 976 | } finally { |
| 977 | Binder.restoreCallingIdentity(ident); |
| 978 | } |
| 979 | } |
| 980 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | void updateFromSettingsLocked() { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 982 | // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and |
| 983 | // ENABLED_INPUT_METHODS is taking care of keeping them correctly in |
| 984 | // sync, so we will never have a DEFAULT_INPUT_METHOD that is not |
| 985 | // enabled. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | String id = Settings.Secure.getString(mContext.getContentResolver(), |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 987 | Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 988 | // There is no input method selected, try to choose new applicable input method. |
| 989 | if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) { |
| 990 | id = Settings.Secure.getString(mContext.getContentResolver(), |
| 991 | Settings.Secure.DEFAULT_INPUT_METHOD); |
| 992 | } |
| 993 | if (!TextUtils.isEmpty(id)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 994 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 995 | setInputMethodLocked(id, getSelectedInputMethodSubtypeId(id)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 997 | 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] | 998 | mCurMethodId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 999 | unbindCurrentMethodLocked(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 1001 | mShortcutInputMethodsAndSubtypes.clear(); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1002 | } else { |
| 1003 | // 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] | 1004 | mCurMethodId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1005 | unbindCurrentMethodLocked(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | } |
| 1007 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1008 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1009 | /* package */ void setInputMethodLocked(String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1010 | InputMethodInfo info = mMethodMap.get(id); |
| 1011 | if (info == null) { |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1012 | throw new IllegalArgumentException("Unknown id: " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1013 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | if (id.equals(mCurMethodId)) { |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 1016 | ArrayList<InputMethodSubtype> subtypes = info.getSubtypes(); |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1017 | InputMethodSubtype subtype = null; |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 1018 | if (subtypeId >= 0 && subtypeId < subtypes.size()) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1019 | subtype = subtypes.get(subtypeId); |
| 1020 | } |
| 1021 | if (subtype != mCurrentSubtype) { |
| 1022 | synchronized (mMethodMap) { |
| 1023 | if (mCurMethod != null) { |
| 1024 | try { |
| 1025 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true); |
| 1026 | if (mInputShown) { |
| 1027 | // If mInputShown is false, there is no IME button on the |
| 1028 | // system bar. |
| 1029 | // Thus there is no need to make it invisible explicitly. |
| 1030 | mStatusBar.setIMEButtonVisible(mCurToken, true); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1031 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1032 | // If subtype is null, try to find the most applicable one from |
| 1033 | // getCurrentInputMethodSubtype. |
| 1034 | if (subtype == null) { |
| 1035 | subtype = getCurrentInputMethodSubtype(); |
| 1036 | } |
| 1037 | mCurMethod.changeInputMethodSubtype(subtype); |
| 1038 | } catch (RemoteException e) { |
| 1039 | return; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | return; |
| 1045 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | final long ident = Binder.clearCallingIdentity(); |
| 1048 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1049 | // Set a subtype to this input method. |
| 1050 | // subtypeId the name of a subtype which will be set. |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1051 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false); |
| 1052 | // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked() |
| 1053 | // because mCurMethodId is stored as a history in |
| 1054 | // setSelectedInputMethodAndSubtypeLocked(). |
| 1055 | mCurMethodId = id; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | |
| 1057 | if (ActivityManagerNative.isSystemReady()) { |
| 1058 | Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 1059 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1060 | intent.putExtra("input_method_id", id); |
| 1061 | mContext.sendBroadcast(intent); |
| 1062 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1063 | unbindCurrentClientLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1064 | } finally { |
| 1065 | Binder.restoreCallingIdentity(ident); |
| 1066 | } |
| 1067 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1068 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1069 | public boolean showSoftInput(IInputMethodClient client, int flags, |
| 1070 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1071 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1072 | long ident = Binder.clearCallingIdentity(); |
| 1073 | try { |
| 1074 | synchronized (mMethodMap) { |
| 1075 | if (mCurClient == null || client == null |
| 1076 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1077 | try { |
| 1078 | // We need to check if this is the current client with |
| 1079 | // focus in the window manager, to allow this call to |
| 1080 | // be made before input is started in it. |
| 1081 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1082 | Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1083 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | } |
| 1085 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1086 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | } |
| 1088 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1089 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1090 | 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] | 1091 | return showCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | } |
| 1093 | } finally { |
| 1094 | Binder.restoreCallingIdentity(ident); |
| 1095 | } |
| 1096 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1097 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1098 | boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | mShowRequested = true; |
| 1100 | if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) { |
| 1101 | mShowExplicitlyRequested = true; |
| 1102 | } |
| 1103 | if ((flags&InputMethodManager.SHOW_FORCED) != 0) { |
| 1104 | mShowExplicitlyRequested = true; |
| 1105 | mShowForced = true; |
| 1106 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1107 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1108 | if (!mSystemReady) { |
| 1109 | return false; |
| 1110 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1111 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1112 | boolean res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1113 | if (mCurMethod != null) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1114 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 1115 | MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod, |
| 1116 | resultReceiver)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | mInputShown = true; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1118 | res = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1119 | } else if (mHaveConnection && SystemClock.uptimeMillis() |
| 1120 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 1121 | // The client has asked to have the input method shown, but |
| 1122 | // we have been sitting here too long with a connection to the |
| 1123 | // service and no interface received, so let's disconnect/connect |
| 1124 | // to try to prod things along. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1125 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | SystemClock.uptimeMillis()-mLastBindTime,1); |
| 1127 | mContext.unbindService(this); |
| 1128 | mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE); |
| 1129 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1130 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1131 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1132 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1133 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1134 | public boolean hideSoftInput(IInputMethodClient client, int flags, |
| 1135 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1136 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1137 | long ident = Binder.clearCallingIdentity(); |
| 1138 | try { |
| 1139 | synchronized (mMethodMap) { |
| 1140 | if (mCurClient == null || client == null |
| 1141 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1142 | try { |
| 1143 | // We need to check if this is the current client with |
| 1144 | // focus in the window manager, to allow this call to |
| 1145 | // be made before input is started in it. |
| 1146 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1147 | if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid " |
| 1148 | + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1149 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | } |
| 1151 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1152 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | } |
| 1154 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1155 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1156 | 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] | 1157 | return hideCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | } |
| 1159 | } finally { |
| 1160 | Binder.restoreCallingIdentity(ident); |
| 1161 | } |
| 1162 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1163 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1164 | boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0 |
| 1166 | && (mShowExplicitlyRequested || mShowForced)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1167 | if (DEBUG) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | "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] | 1169 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1170 | } |
| 1171 | if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1172 | if (DEBUG) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | "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] | 1174 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1176 | boolean res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | if (mInputShown && mCurMethod != null) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1178 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 1179 | MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver)); |
| 1180 | res = true; |
| 1181 | } else { |
| 1182 | res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1183 | } |
| 1184 | mInputShown = false; |
| 1185 | mShowRequested = false; |
| 1186 | mShowExplicitlyRequested = false; |
| 1187 | mShowForced = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1188 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1190 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1191 | public void windowGainedFocus(IInputMethodClient client, IBinder windowToken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | boolean viewHasFocus, boolean isTextEditor, int softInputMode, |
| 1193 | boolean first, int windowFlags) { |
| 1194 | long ident = Binder.clearCallingIdentity(); |
| 1195 | try { |
| 1196 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1197 | if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | + " viewHasFocus=" + viewHasFocus |
| 1199 | + " isTextEditor=" + isTextEditor |
| 1200 | + " softInputMode=#" + Integer.toHexString(softInputMode) |
| 1201 | + " first=" + first + " flags=#" |
| 1202 | + Integer.toHexString(windowFlags)); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1204 | if (mCurClient == null || client == null |
| 1205 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1206 | try { |
| 1207 | // We need to check if this is the current client with |
| 1208 | // focus in the window manager, to allow this call to |
| 1209 | // be made before input is started in it. |
| 1210 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1211 | 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] | 1212 | return; |
| 1213 | } |
| 1214 | } catch (RemoteException e) { |
| 1215 | } |
| 1216 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1217 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1218 | if (mCurFocusedWindow == windowToken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1219 | 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] | 1220 | return; |
| 1221 | } |
| 1222 | mCurFocusedWindow = windowToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1223 | |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1224 | // Should we auto-show the IME even if the caller has not |
| 1225 | // specified what should be done with it? |
| 1226 | // We only do this automatically if the window can resize |
| 1227 | // to accommodate the IME (so what the user sees will give |
| 1228 | // them good context without input information being obscured |
| 1229 | // by the IME) or if running on a large screen where there |
| 1230 | // is more room for the target window + IME. |
| 1231 | final boolean doAutoShow = |
| 1232 | (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 1233 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
| 1234 | || mRes.getConfiguration().isLayoutSizeAtLeast( |
| 1235 | Configuration.SCREENLAYOUT_SIZE_LARGE); |
| 1236 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1237 | switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) { |
| 1238 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1239 | if (!isTextEditor || !doAutoShow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) { |
| 1241 | // There is no focus view, and this window will |
| 1242 | // be behind any soft input window, so hide the |
| 1243 | // soft input window if it is shown. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1244 | 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] | 1245 | hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1246 | } |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1247 | } else if (isTextEditor && doAutoShow && (softInputMode & |
| 1248 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | // There is a focus view, and we are navigating forward |
| 1250 | // into the window, so show the input window for the user. |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1251 | // We only do this automatically if the window an resize |
| 1252 | // to accomodate the IME (so what the user sees will give |
| 1253 | // them good context without input information being obscured |
| 1254 | // by the IME) or if running on a large screen where there |
| 1255 | // is more room for the target window + IME. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1256 | 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] | 1257 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | } |
| 1259 | break; |
| 1260 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED: |
| 1261 | // Do nothing. |
| 1262 | break; |
| 1263 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN: |
| 1264 | if ((softInputMode & |
| 1265 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1266 | 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] | 1267 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | } |
| 1269 | break; |
| 1270 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1271 | 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] | 1272 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1273 | break; |
| 1274 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE: |
| 1275 | if ((softInputMode & |
| 1276 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1277 | 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] | 1278 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1279 | } |
| 1280 | break; |
| 1281 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1282 | 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] | 1283 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1284 | break; |
| 1285 | } |
| 1286 | } |
| 1287 | } finally { |
| 1288 | Binder.restoreCallingIdentity(ident); |
| 1289 | } |
| 1290 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1292 | public void showInputMethodPickerFromClient(IInputMethodClient client) { |
| 1293 | synchronized (mMethodMap) { |
| 1294 | if (mCurClient == null || client == null |
| 1295 | || mCurClient.client.asBinder() != client.asBinder()) { |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1296 | Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid " |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1297 | + Binder.getCallingUid() + ": " + client); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1298 | } |
| 1299 | |
satok | 440aab5 | 2010-11-25 09:43:11 +0900 | [diff] [blame] | 1300 | // Always call subtype picker, because subtype picker is a superset of input method |
| 1301 | // picker. |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1302 | mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER); |
| 1303 | } |
| 1304 | } |
| 1305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | public void setInputMethod(IBinder token, String id) { |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 1307 | setInputMethodWithSubtypeId(token, id, NOT_A_SUBTYPE_ID); |
| 1308 | } |
| 1309 | |
| 1310 | public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) { |
| 1311 | synchronized (mMethodMap) { |
| 1312 | if (subtype != null) { |
| 1313 | setInputMethodWithSubtypeId(token, id, getSubtypeIdFromHashCode( |
| 1314 | mMethodMap.get(id), subtype.hashCode())); |
| 1315 | } else { |
| 1316 | setInputMethod(token, id); |
| 1317 | } |
| 1318 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1319 | } |
| 1320 | |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 1321 | public void showInputMethodAndSubtypeEnablerFromClient( |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1322 | IInputMethodClient client, String inputMethodId) { |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 1323 | synchronized (mMethodMap) { |
| 1324 | if (mCurClient == null || client == null |
| 1325 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1326 | Slog.w(TAG, "Ignoring showInputMethodAndSubtypeEnablerFromClient of: " + client); |
| 1327 | } |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 1328 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 1329 | MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId)); |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 1333 | public boolean switchToLastInputMethod(IBinder token) { |
| 1334 | synchronized (mMethodMap) { |
| 1335 | Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
| 1336 | if (lastIme != null) { |
| 1337 | InputMethodInfo imi = mMethodMap.get(lastIme.first); |
| 1338 | if (imi != null) { |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 1339 | setInputMethodWithSubtypeId(token, lastIme.first, getSubtypeIdFromHashCode( |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 1340 | imi, Integer.valueOf(lastIme.second))); |
| 1341 | return true; |
| 1342 | } |
| 1343 | } |
| 1344 | return false; |
| 1345 | } |
| 1346 | } |
| 1347 | |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 1348 | private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1349 | synchronized (mMethodMap) { |
| 1350 | if (token == null) { |
| 1351 | if (mContext.checkCallingOrSelfPermission( |
| 1352 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 1353 | != PackageManager.PERMISSION_GRANTED) { |
| 1354 | throw new SecurityException( |
| 1355 | "Using null token requires permission " |
| 1356 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 1357 | } |
| 1358 | } else if (mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1359 | Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid() |
| 1360 | + " token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1361 | return; |
| 1362 | } |
| 1363 | |
| 1364 | long ident = Binder.clearCallingIdentity(); |
| 1365 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1366 | setInputMethodLocked(id, subtypeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1367 | } finally { |
| 1368 | Binder.restoreCallingIdentity(ident); |
| 1369 | } |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | public void hideMySoftInput(IBinder token, int flags) { |
| 1374 | synchronized (mMethodMap) { |
| 1375 | if (token == null || mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1376 | if (DEBUG) Slog.w(TAG, "Ignoring hideInputMethod of uid " |
| 1377 | + Binder.getCallingUid() + " token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1378 | return; |
| 1379 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1380 | long ident = Binder.clearCallingIdentity(); |
| 1381 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1382 | hideCurrentInputLocked(flags, null); |
| 1383 | } finally { |
| 1384 | Binder.restoreCallingIdentity(ident); |
| 1385 | } |
| 1386 | } |
| 1387 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1388 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1389 | public void showMySoftInput(IBinder token, int flags) { |
| 1390 | synchronized (mMethodMap) { |
| 1391 | if (token == null || mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1392 | Slog.w(TAG, "Ignoring showMySoftInput of uid " |
| 1393 | + Binder.getCallingUid() + " token: " + token); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1394 | return; |
| 1395 | } |
| 1396 | long ident = Binder.clearCallingIdentity(); |
| 1397 | try { |
| 1398 | showCurrentInputLocked(flags, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | } finally { |
| 1400 | Binder.restoreCallingIdentity(ident); |
| 1401 | } |
| 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | void setEnabledSessionInMainThread(SessionState session) { |
| 1406 | if (mEnabledSession != session) { |
| 1407 | if (mEnabledSession != null) { |
| 1408 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1409 | if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1410 | mEnabledSession.method.setSessionEnabled( |
| 1411 | mEnabledSession.session, false); |
| 1412 | } catch (RemoteException e) { |
| 1413 | } |
| 1414 | } |
| 1415 | mEnabledSession = session; |
| 1416 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1417 | if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1418 | session.method.setSessionEnabled( |
| 1419 | session.session, true); |
| 1420 | } catch (RemoteException e) { |
| 1421 | } |
| 1422 | } |
| 1423 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | public boolean handleMessage(Message msg) { |
| 1426 | HandlerCaller.SomeArgs args; |
| 1427 | switch (msg.what) { |
| 1428 | case MSG_SHOW_IM_PICKER: |
| 1429 | showInputMethodMenu(); |
| 1430 | return true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1431 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1432 | case MSG_SHOW_IM_SUBTYPE_PICKER: |
| 1433 | showInputMethodSubtypeMenu(); |
| 1434 | return true; |
| 1435 | |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1436 | case MSG_SHOW_IM_SUBTYPE_ENABLER: |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1437 | args = (HandlerCaller.SomeArgs)msg.obj; |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 1438 | showInputMethodAndSubtypeEnabler((String)args.arg1); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1439 | return true; |
| 1440 | |
| 1441 | case MSG_SHOW_IM_CONFIG: |
| 1442 | showConfigureInputMethods(); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1443 | return true; |
| 1444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1445 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1447 | case MSG_UNBIND_INPUT: |
| 1448 | try { |
| 1449 | ((IInputMethod)msg.obj).unbindInput(); |
| 1450 | } catch (RemoteException e) { |
| 1451 | // There is nothing interesting about the method dying. |
| 1452 | } |
| 1453 | return true; |
| 1454 | case MSG_BIND_INPUT: |
| 1455 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1456 | try { |
| 1457 | ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2); |
| 1458 | } catch (RemoteException e) { |
| 1459 | } |
| 1460 | return true; |
| 1461 | case MSG_SHOW_SOFT_INPUT: |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1462 | args = (HandlerCaller.SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1464 | ((IInputMethod)args.arg1).showSoftInput(msg.arg1, |
| 1465 | (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1466 | } catch (RemoteException e) { |
| 1467 | } |
| 1468 | return true; |
| 1469 | case MSG_HIDE_SOFT_INPUT: |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1470 | args = (HandlerCaller.SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1471 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1472 | ((IInputMethod)args.arg1).hideSoftInput(0, |
| 1473 | (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | } catch (RemoteException e) { |
| 1475 | } |
| 1476 | return true; |
| 1477 | case MSG_ATTACH_TOKEN: |
| 1478 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1479 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1480 | 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] | 1481 | ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2); |
| 1482 | } catch (RemoteException e) { |
| 1483 | } |
| 1484 | return true; |
| 1485 | case MSG_CREATE_SESSION: |
| 1486 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1487 | try { |
| 1488 | ((IInputMethod)args.arg1).createSession( |
| 1489 | (IInputMethodCallback)args.arg2); |
| 1490 | } catch (RemoteException e) { |
| 1491 | } |
| 1492 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | case MSG_START_INPUT: |
| 1496 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1497 | try { |
| 1498 | SessionState session = (SessionState)args.arg1; |
| 1499 | setEnabledSessionInMainThread(session); |
| 1500 | session.method.startInput((IInputContext)args.arg2, |
| 1501 | (EditorInfo)args.arg3); |
| 1502 | } catch (RemoteException e) { |
| 1503 | } |
| 1504 | return true; |
| 1505 | case MSG_RESTART_INPUT: |
| 1506 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1507 | try { |
| 1508 | SessionState session = (SessionState)args.arg1; |
| 1509 | setEnabledSessionInMainThread(session); |
| 1510 | session.method.restartInput((IInputContext)args.arg2, |
| 1511 | (EditorInfo)args.arg3); |
| 1512 | } catch (RemoteException e) { |
| 1513 | } |
| 1514 | return true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1515 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1518 | case MSG_UNBIND_METHOD: |
| 1519 | try { |
| 1520 | ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1); |
| 1521 | } catch (RemoteException e) { |
| 1522 | // There is nothing interesting about the last client dying. |
| 1523 | } |
| 1524 | return true; |
| 1525 | case MSG_BIND_METHOD: |
| 1526 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1527 | try { |
| 1528 | ((IInputMethodClient)args.arg1).onBindMethod( |
| 1529 | (InputBindResult)args.arg2); |
| 1530 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1531 | 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] | 1532 | } |
| 1533 | return true; |
| 1534 | } |
| 1535 | return false; |
| 1536 | } |
| 1537 | |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1538 | private boolean isSystemIme(InputMethodInfo inputMethod) { |
| 1539 | return (inputMethod.getServiceInfo().applicationInfo.flags |
| 1540 | & ApplicationInfo.FLAG_SYSTEM) != 0; |
| 1541 | } |
| 1542 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1543 | private boolean chooseNewDefaultIMELocked() { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1544 | List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1545 | if (enabled != null && enabled.size() > 0) { |
Dianne Hackborn | 83e48f5 | 2010-03-23 23:03:25 -0700 | [diff] [blame] | 1546 | // We'd prefer to fall back on a system IME, since that is safer. |
| 1547 | int i=enabled.size(); |
| 1548 | while (i > 0) { |
| 1549 | i--; |
| 1550 | if ((enabled.get(i).getServiceInfo().applicationInfo.flags |
| 1551 | & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 1552 | break; |
| 1553 | } |
| 1554 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1555 | InputMethodInfo imi = enabled.get(i); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 1556 | if (DEBUG) { |
| 1557 | Slog.d(TAG, "New default IME was selected: " + imi.getId()); |
| 1558 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1559 | resetSelectedInputMethodAndSubtypeLocked(imi.getId()); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1560 | return true; |
| 1561 | } |
| 1562 | |
| 1563 | return false; |
| 1564 | } |
| 1565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | void buildInputMethodListLocked(ArrayList<InputMethodInfo> list, |
| 1567 | HashMap<String, InputMethodInfo> map) { |
| 1568 | list.clear(); |
| 1569 | map.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | PackageManager pm = mContext.getPackageManager(); |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1572 | final Configuration config = mRes.getConfiguration(); |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1573 | final boolean haveHardKeyboard = config.keyboard == Configuration.KEYBOARD_QWERTY; |
| 1574 | String disabledSysImes = Settings.Secure.getString(mContext.getContentResolver(), |
| 1575 | Secure.DISABLED_SYSTEM_INPUT_METHODS); |
| 1576 | if (disabledSysImes == null) disabledSysImes = ""; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1577 | |
| 1578 | List<ResolveInfo> services = pm.queryIntentServices( |
| 1579 | new Intent(InputMethod.SERVICE_INTERFACE), |
| 1580 | PackageManager.GET_META_DATA); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1582 | for (int i = 0; i < services.size(); ++i) { |
| 1583 | ResolveInfo ri = services.get(i); |
| 1584 | ServiceInfo si = ri.serviceInfo; |
| 1585 | ComponentName compName = new ComponentName(si.packageName, si.name); |
| 1586 | if (!android.Manifest.permission.BIND_INPUT_METHOD.equals( |
| 1587 | si.permission)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1588 | Slog.w(TAG, "Skipping input method " + compName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1589 | + ": it does not require the permission " |
| 1590 | + android.Manifest.permission.BIND_INPUT_METHOD); |
| 1591 | continue; |
| 1592 | } |
| 1593 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1594 | if (DEBUG) Slog.d(TAG, "Checking " + compName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | |
| 1596 | try { |
| 1597 | InputMethodInfo p = new InputMethodInfo(mContext, ri); |
| 1598 | list.add(p); |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1599 | final String id = p.getId(); |
| 1600 | map.put(id, p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1601 | |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1602 | // System IMEs are enabled by default, unless there's a hard keyboard |
| 1603 | // and the system IME was explicitly disabled |
| 1604 | if (isSystemIme(p) && (!haveHardKeyboard || disabledSysImes.indexOf(id) < 0)) { |
| 1605 | setInputMethodEnabledLocked(id, true); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | if (DEBUG) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1609 | 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] | 1610 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1611 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1612 | } catch (XmlPullParserException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1613 | 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] | 1614 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1615 | 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] | 1616 | } |
| 1617 | } |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1618 | |
| 1619 | String defaultIme = Settings.Secure.getString(mContext |
| 1620 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1621 | if (!TextUtils.isEmpty(defaultIme) && !map.containsKey(defaultIme)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1622 | if (chooseNewDefaultIMELocked()) { |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1623 | updateFromSettingsLocked(); |
| 1624 | } |
| 1625 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1626 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1627 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1629 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1630 | private void showInputMethodMenu() { |
| 1631 | showInputMethodMenuInternal(false); |
| 1632 | } |
| 1633 | |
| 1634 | private void showInputMethodSubtypeMenu() { |
| 1635 | showInputMethodMenuInternal(true); |
| 1636 | } |
| 1637 | |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1638 | private void showInputMethodAndSubtypeEnabler(String inputMethodId) { |
satok | 86417ea | 2010-10-27 14:11:03 +0900 | [diff] [blame] | 1639 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_AND_SUBTYPE_ENABLER); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1640 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
satok | 86417ea | 2010-10-27 14:11:03 +0900 | [diff] [blame] | 1641 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 1642 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 1643 | if (!TextUtils.isEmpty(inputMethodId)) { |
| 1644 | intent.putExtra(EXTRA_INPUT_METHOD_ID, inputMethodId); |
| 1645 | } |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1646 | mContext.startActivity(intent); |
| 1647 | } |
| 1648 | |
| 1649 | private void showConfigureInputMethods() { |
| 1650 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS); |
| 1651 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1652 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 1653 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1654 | mContext.startActivity(intent); |
| 1655 | } |
| 1656 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1657 | private void showInputMethodMenuInternal(boolean showSubtypes) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1658 | if (DEBUG) Slog.v(TAG, "Show switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1660 | final Context context = mContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1661 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1662 | final PackageManager pm = context.getPackageManager(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1663 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1664 | String lastInputMethodId = Settings.Secure.getString(context |
| 1665 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1666 | int lastInputMethodSubtypeId = getSelectedInputMethodSubtypeId(lastInputMethodId); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1667 | if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1668 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1669 | synchronized (mMethodMap) { |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 1670 | final List<Pair<InputMethodInfo, ArrayList<String>>> immis = |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1671 | mSettings.getEnabledInputMethodAndSubtypeHashCodeListLocked(); |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 1672 | int N = immis.size(); |
| 1673 | |
| 1674 | // Add applicable subtypes if no subtype for each IME is enabled. |
| 1675 | for (int i = 0; i < N; ++i) { |
| 1676 | InputMethodInfo imi = immis.get(i).first; |
| 1677 | ArrayList<String> subtypes = immis.get(i).second; |
| 1678 | if (subtypes != null && subtypes.size() == 0) { |
| 1679 | ArrayList<InputMethodSubtype> applicableSubtypes = |
| 1680 | getApplicableSubtypesLocked(imi.getSubtypes()); |
| 1681 | final int numSubtypes = applicableSubtypes.size(); |
| 1682 | for (int j = 0; j < numSubtypes; ++j) { |
| 1683 | subtypes.add(String.valueOf(applicableSubtypes.get(j).hashCode())); |
| 1684 | } |
| 1685 | } |
| 1686 | } |
| 1687 | |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 1688 | ArrayList<Integer> subtypeIds = new ArrayList<Integer>(); |
| 1689 | |
| 1690 | if (immis == null || immis.size() == 0) { |
| 1691 | return; |
| 1692 | } |
| 1693 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1694 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1695 | |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1696 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1697 | final Map<CharSequence, Pair<InputMethodInfo, Integer>> imMap = |
| 1698 | new TreeMap<CharSequence, Pair<InputMethodInfo, Integer>>(Collator.getInstance()); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1699 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1700 | for (int i = 0; i < N; ++i) { |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 1701 | InputMethodInfo property = immis.get(i).first; |
| 1702 | final ArrayList<String> enabledSubtypeIds = immis.get(i).second; |
| 1703 | HashSet<String> enabledSubtypeSet = new HashSet<String>(); |
| 1704 | for (String s : enabledSubtypeIds) { |
| 1705 | enabledSubtypeSet.add(s); |
| 1706 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1707 | if (property == null) { |
| 1708 | continue; |
| 1709 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1710 | ArrayList<InputMethodSubtype> subtypes = property.getSubtypes(); |
| 1711 | CharSequence label = property.loadLabel(pm); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 1712 | if (showSubtypes && enabledSubtypeSet.size() > 0) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1713 | for (int j = 0; j < subtypes.size(); ++j) { |
| 1714 | InputMethodSubtype subtype = subtypes.get(j); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 1715 | if (enabledSubtypeSet.contains(String.valueOf(subtype.hashCode()))) { |
| 1716 | CharSequence title; |
| 1717 | int nameResId = subtype.getNameResId(); |
satok | 9ef0283 | 2010-11-04 21:17:48 +0900 | [diff] [blame] | 1718 | String mode = subtype.getMode(); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 1719 | if (nameResId != 0) { |
| 1720 | title = pm.getText(property.getPackageName(), nameResId, |
| 1721 | property.getServiceInfo().applicationInfo); |
| 1722 | } else { |
| 1723 | CharSequence language = subtype.getLocale(); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 1724 | // TODO: Use more friendly Title and UI |
| 1725 | title = label + "," + (mode == null ? "" : mode) + "," |
| 1726 | + (language == null ? "" : language); |
| 1727 | } |
| 1728 | imMap.put(title, new Pair<InputMethodInfo, Integer>(property, j)); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1729 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1730 | } |
| 1731 | } else { |
| 1732 | imMap.put(label, |
| 1733 | new Pair<InputMethodInfo, Integer>(property, NOT_A_SUBTYPE_ID)); |
| 1734 | subtypeIds.add(0); |
| 1735 | } |
Dianne Hackborn | 97106ab | 2010-03-03 00:08:31 -0800 | [diff] [blame] | 1736 | } |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1737 | |
| 1738 | N = imMap.size(); |
| 1739 | mItems = imMap.keySet().toArray(new CharSequence[N]); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1740 | mIms = new InputMethodInfo[N]; |
| 1741 | mSubtypeIds = new int[N]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1742 | int checkedItem = 0; |
| 1743 | for (int i = 0; i < N; ++i) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1744 | Pair<InputMethodInfo, Integer> value = imMap.get(mItems[i]); |
| 1745 | mIms[i] = value.first; |
| 1746 | mSubtypeIds[i] = value.second; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1747 | if (mIms[i].getId().equals(lastInputMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1748 | int subtypeId = mSubtypeIds[i]; |
| 1749 | if ((subtypeId == NOT_A_SUBTYPE_ID) |
| 1750 | || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) |
| 1751 | || (subtypeId == lastInputMethodSubtypeId)) { |
| 1752 | checkedItem = i; |
| 1753 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1754 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1756 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1757 | AlertDialog.OnClickListener adocl = new AlertDialog.OnClickListener() { |
| 1758 | public void onClick(DialogInterface dialog, int which) { |
| 1759 | hideInputMethodMenu(); |
| 1760 | } |
| 1761 | }; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1762 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1763 | TypedArray a = context.obtainStyledAttributes(null, |
| 1764 | com.android.internal.R.styleable.DialogPreference, |
| 1765 | com.android.internal.R.attr.alertDialogStyle, 0); |
| 1766 | mDialogBuilder = new AlertDialog.Builder(context) |
| 1767 | .setTitle(com.android.internal.R.string.select_input_method) |
| 1768 | .setOnCancelListener(new OnCancelListener() { |
| 1769 | public void onCancel(DialogInterface dialog) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1770 | hideInputMethodMenu(); |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1771 | } |
| 1772 | }) |
| 1773 | .setIcon(a.getDrawable( |
| 1774 | com.android.internal.R.styleable.DialogPreference_dialogTitle)); |
| 1775 | a.recycle(); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1776 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1777 | mDialogBuilder.setSingleChoiceItems(mItems, checkedItem, |
| 1778 | new AlertDialog.OnClickListener() { |
| 1779 | public void onClick(DialogInterface dialog, int which) { |
| 1780 | synchronized (mMethodMap) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1781 | if (mIms == null || mIms.length <= which |
| 1782 | || mSubtypeIds == null || mSubtypeIds.length <= which) { |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1783 | return; |
| 1784 | } |
| 1785 | InputMethodInfo im = mIms[which]; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1786 | int subtypeId = mSubtypeIds[which]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1787 | hideInputMethodMenu(); |
| 1788 | if (im != null) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1789 | if ((subtypeId < 0) |
| 1790 | || (subtypeId >= im.getSubtypes().size())) { |
| 1791 | subtypeId = NOT_A_SUBTYPE_ID; |
| 1792 | } |
| 1793 | setInputMethodLocked(im.getId(), subtypeId); |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1794 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 1795 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1796 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1797 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1798 | |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 1799 | if (showSubtypes) { |
| 1800 | mDialogBuilder.setPositiveButton(com.android.internal.R.string.more_item_label, |
| 1801 | new DialogInterface.OnClickListener() { |
| 1802 | public void onClick(DialogInterface dialog, int whichButton) { |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 1803 | showConfigureInputMethods(); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 1804 | } |
| 1805 | }); |
| 1806 | } |
satok | 0ff647b | 2010-10-08 13:49:28 +0900 | [diff] [blame] | 1807 | mDialogBuilder.setNegativeButton(com.android.internal.R.string.cancel, |
| 1808 | new DialogInterface.OnClickListener() { |
| 1809 | public void onClick(DialogInterface dialog, int whichButton) { |
| 1810 | hideInputMethodMenu(); |
| 1811 | } |
| 1812 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1813 | mSwitchingDialog = mDialogBuilder.create(); |
| 1814 | mSwitchingDialog.getWindow().setType( |
| 1815 | WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG); |
| 1816 | mSwitchingDialog.show(); |
| 1817 | } |
| 1818 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1819 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1820 | void hideInputMethodMenu() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1821 | synchronized (mMethodMap) { |
| 1822 | hideInputMethodMenuLocked(); |
| 1823 | } |
| 1824 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1825 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1826 | void hideInputMethodMenuLocked() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1827 | if (DEBUG) Slog.v(TAG, "Hide switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1828 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1829 | if (mSwitchingDialog != null) { |
| 1830 | mSwitchingDialog.dismiss(); |
| 1831 | mSwitchingDialog = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1832 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1833 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1834 | mDialogBuilder = null; |
| 1835 | mItems = null; |
| 1836 | mIms = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1837 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1838 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1839 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1840 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1841 | public boolean setInputMethodEnabled(String id, boolean enabled) { |
| 1842 | synchronized (mMethodMap) { |
| 1843 | if (mContext.checkCallingOrSelfPermission( |
| 1844 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 1845 | != PackageManager.PERMISSION_GRANTED) { |
| 1846 | throw new SecurityException( |
| 1847 | "Requires permission " |
| 1848 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 1849 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1851 | long ident = Binder.clearCallingIdentity(); |
| 1852 | try { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1853 | return setInputMethodEnabledLocked(id, enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1854 | } finally { |
| 1855 | Binder.restoreCallingIdentity(ident); |
| 1856 | } |
| 1857 | } |
| 1858 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1859 | |
| 1860 | boolean setInputMethodEnabledLocked(String id, boolean enabled) { |
| 1861 | // Make sure this is a valid input method. |
| 1862 | InputMethodInfo imm = mMethodMap.get(id); |
| 1863 | if (imm == null) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1864 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1865 | } |
| 1866 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1867 | List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings |
| 1868 | .getEnabledInputMethodsAndSubtypeListLocked(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1869 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1870 | if (enabled) { |
| 1871 | for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) { |
| 1872 | if (pair.first.equals(id)) { |
| 1873 | // We are enabling this input method, but it is already enabled. |
| 1874 | // Nothing to do. The previous state was enabled. |
| 1875 | return true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1876 | } |
| 1877 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1878 | mSettings.appendAndPutEnabledInputMethodLocked(id, false); |
| 1879 | // Previous state was disabled. |
| 1880 | return false; |
| 1881 | } else { |
| 1882 | StringBuilder builder = new StringBuilder(); |
| 1883 | if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 1884 | builder, enabledInputMethodsList, id)) { |
| 1885 | // Disabled input method is currently selected, switch to another one. |
| 1886 | String selId = Settings.Secure.getString(mContext.getContentResolver(), |
| 1887 | Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 1888 | if (id.equals(selId) && !chooseNewDefaultIMELocked()) { |
| 1889 | Slog.i(TAG, "Can't find new IME, unsetting the current input method."); |
| 1890 | resetSelectedInputMethodAndSubtypeLocked(""); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1891 | } |
| 1892 | // Previous state was enabled. |
| 1893 | return true; |
| 1894 | } else { |
| 1895 | // We are disabling the input method but it is already disabled. |
| 1896 | // Nothing to do. The previous state was disabled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1897 | return false; |
| 1898 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1899 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1900 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1901 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1902 | private void saveCurrentInputMethodAndSubtypeToHistory() { |
| 1903 | String subtypeId = NOT_A_SUBTYPE_ID_STR; |
| 1904 | if (mCurrentSubtype != null) { |
| 1905 | subtypeId = String.valueOf(mCurrentSubtype.hashCode()); |
| 1906 | } |
| 1907 | mSettings.addSubtypeToHistory(mCurMethodId, subtypeId); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1908 | } |
| 1909 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1910 | private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId, |
| 1911 | boolean setSubtypeOnly) { |
| 1912 | // Update the history of InputMethod and Subtype |
| 1913 | saveCurrentInputMethodAndSubtypeToHistory(); |
| 1914 | |
| 1915 | // Set Subtype here |
| 1916 | if (imi == null || subtypeId < 0) { |
| 1917 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
Tadashi G. Takaoka | 0ba75bb | 2010-11-09 12:19:32 -0800 | [diff] [blame] | 1918 | mCurrentSubtype = null; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1919 | } else { |
| 1920 | final ArrayList<InputMethodSubtype> subtypes = imi.getSubtypes(); |
| 1921 | if (subtypeId < subtypes.size()) { |
| 1922 | mSettings.putSelectedSubtype(subtypes.get(subtypeId).hashCode()); |
| 1923 | mCurrentSubtype = subtypes.get(subtypeId); |
| 1924 | } else { |
| 1925 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
| 1926 | mCurrentSubtype = null; |
| 1927 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1928 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1929 | |
| 1930 | if (!setSubtypeOnly) { |
| 1931 | // Set InputMethod here |
| 1932 | mSettings.putSelectedInputMethod(imi != null ? imi.getId() : ""); |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) { |
| 1937 | InputMethodInfo imi = mMethodMap.get(newDefaultIme); |
| 1938 | int lastSubtypeId = NOT_A_SUBTYPE_ID; |
| 1939 | // newDefaultIme is empty when there is no candidate for the selected IME. |
| 1940 | if (imi != null && !TextUtils.isEmpty(newDefaultIme)) { |
| 1941 | String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme); |
| 1942 | if (subtypeHashCode != null) { |
| 1943 | try { |
| 1944 | lastSubtypeId = getSubtypeIdFromHashCode( |
| 1945 | imi, Integer.valueOf(subtypeHashCode)); |
| 1946 | } catch (NumberFormatException e) { |
| 1947 | Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e); |
| 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | private int getSelectedInputMethodSubtypeId(String id) { |
| 1955 | InputMethodInfo imi = mMethodMap.get(id); |
| 1956 | if (imi == null) { |
| 1957 | return NOT_A_SUBTYPE_ID; |
| 1958 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1959 | int subtypeId; |
| 1960 | try { |
| 1961 | subtypeId = Settings.Secure.getInt(mContext.getContentResolver(), |
| 1962 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE); |
| 1963 | } catch (SettingNotFoundException e) { |
| 1964 | return NOT_A_SUBTYPE_ID; |
| 1965 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1966 | return getSubtypeIdFromHashCode(imi, subtypeId); |
| 1967 | } |
| 1968 | |
| 1969 | private int getSubtypeIdFromHashCode(InputMethodInfo imi, int subtypeHashCode) { |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 1970 | if (imi != null) { |
| 1971 | ArrayList<InputMethodSubtype> subtypes = imi.getSubtypes(); |
| 1972 | for (int i = 0; i < subtypes.size(); ++i) { |
| 1973 | InputMethodSubtype ims = subtypes.get(i); |
| 1974 | if (subtypeHashCode == ims.hashCode()) { |
| 1975 | return i; |
| 1976 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | return NOT_A_SUBTYPE_ID; |
| 1980 | } |
| 1981 | |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 1982 | private ArrayList<InputMethodSubtype> getApplicableSubtypesLocked( |
| 1983 | List<InputMethodSubtype> subtypes) { |
| 1984 | ArrayList<InputMethodSubtype> applicableSubtypes = new ArrayList<InputMethodSubtype>(); |
| 1985 | final String systemLocale = mRes.getConfiguration().locale.toString(); |
| 1986 | if (TextUtils.isEmpty(systemLocale)) return applicableSubtypes; |
| 1987 | final int N = subtypes.size(); |
| 1988 | boolean containsKeyboardSubtype = false; |
| 1989 | for (int i = 0; i < N; ++i) { |
| 1990 | InputMethodSubtype subtype = subtypes.get(i); |
| 1991 | if (subtype.getLocale().equals(systemLocale)) { |
| 1992 | applicableSubtypes.add(subtype); |
| 1993 | if (!containsKeyboardSubtype |
| 1994 | && SUBTYPE_MODE_KEYBOARD.equalsIgnoreCase(subtype.getMode())) { |
| 1995 | containsKeyboardSubtype = true; |
| 1996 | } |
| 1997 | } |
| 1998 | } |
| 1999 | if (!containsKeyboardSubtype) { |
| 2000 | InputMethodSubtype lastResortKeyboardSubtype = findLastResortApplicableSubtypeLocked( |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2001 | subtypes, SUBTYPE_MODE_KEYBOARD, systemLocale, true); |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2002 | if (lastResortKeyboardSubtype != null) { |
| 2003 | applicableSubtypes.add(lastResortKeyboardSubtype); |
| 2004 | } |
| 2005 | } |
| 2006 | return applicableSubtypes; |
| 2007 | } |
| 2008 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2009 | /** |
| 2010 | * If there are no selected subtypes, tries finding the most applicable one according to the |
| 2011 | * given locale. |
| 2012 | * @param subtypes this function will search the most applicable subtype in subtypes |
| 2013 | * @param mode subtypes will be filtered by mode |
| 2014 | * @param locale subtypes will be filtered by locale |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2015 | * @param canIgnoreLocaleAsLastResort if this function can't find the most applicable subtype, |
| 2016 | * it will return the first subtype matched with mode |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2017 | * @return the most applicable subtypeId |
| 2018 | */ |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2019 | private InputMethodSubtype findLastResortApplicableSubtypeLocked( |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2020 | List<InputMethodSubtype> subtypes, String mode, String locale, |
| 2021 | boolean canIgnoreLocaleAsLastResort) { |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2022 | if (subtypes == null || subtypes.size() == 0) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2023 | return null; |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2024 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2025 | if (TextUtils.isEmpty(locale)) { |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2026 | locale = mRes.getConfiguration().locale.toString(); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2027 | } |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2028 | final String language = locale.substring(0, 2); |
| 2029 | boolean partialMatchFound = false; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2030 | InputMethodSubtype applicableSubtype = null; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2031 | InputMethodSubtype firstMatchedModeSubtype = null; |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2032 | final int N = subtypes.size(); |
| 2033 | for (int i = 0; i < N; ++i) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2034 | InputMethodSubtype subtype = subtypes.get(i); |
| 2035 | final String subtypeLocale = subtype.getLocale(); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2036 | // An applicable subtype should match "mode". |
| 2037 | if (subtypes.get(i).getMode().equalsIgnoreCase(mode)) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2038 | if (firstMatchedModeSubtype == null) { |
| 2039 | firstMatchedModeSubtype = subtype; |
| 2040 | } |
satok | 9ef0283 | 2010-11-04 21:17:48 +0900 | [diff] [blame] | 2041 | if (locale.equals(subtypeLocale)) { |
| 2042 | // 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] | 2043 | applicableSubtype = subtype; |
satok | 9ef0283 | 2010-11-04 21:17:48 +0900 | [diff] [blame] | 2044 | break; |
| 2045 | } else if (!partialMatchFound && subtypeLocale.startsWith(language)) { |
| 2046 | // 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] | 2047 | applicableSubtype = subtype; |
satok | 9ef0283 | 2010-11-04 21:17:48 +0900 | [diff] [blame] | 2048 | partialMatchFound = true; |
| 2049 | } |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2050 | } |
| 2051 | } |
| 2052 | |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2053 | if (applicableSubtype == null && canIgnoreLocaleAsLastResort) { |
| 2054 | return firstMatchedModeSubtype; |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2055 | } |
| 2056 | |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2057 | // The first subtype applicable to the system locale will be defined as the most applicable |
| 2058 | // subtype. |
| 2059 | if (DEBUG) { |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2060 | if (applicableSubtype != null) { |
| 2061 | Slog.d(TAG, "Applicable InputMethodSubtype was found: " |
| 2062 | + applicableSubtype.getMode() + "," + applicableSubtype.getLocale()); |
| 2063 | } |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2064 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2065 | return applicableSubtype; |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2066 | } |
| 2067 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2068 | // If there are no selected shortcuts, tries finding the most applicable ones. |
| 2069 | private Pair<InputMethodInfo, InputMethodSubtype> |
| 2070 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) { |
| 2071 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 2072 | InputMethodInfo mostApplicableIMI = null; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2073 | InputMethodSubtype mostApplicableSubtype = null; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2074 | boolean foundInSystemIME = false; |
| 2075 | |
| 2076 | // Search applicable subtype for each InputMethodInfo |
| 2077 | for (InputMethodInfo imi: imis) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2078 | final String imiId = imi.getId(); |
| 2079 | if (foundInSystemIME && !imiId.equals(mCurMethodId)) { |
| 2080 | continue; |
| 2081 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2082 | InputMethodSubtype subtype = null; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2083 | final List<InputMethodSubtype> explicitlyEnabledSubtypes = |
| 2084 | mSettings.getEnabledInputMethodSubtypeListLocked(imi); |
| 2085 | // 1. Search by the current subtype's locale from explicitlyEnabledSubtypes. |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2086 | if (mCurrentSubtype != null) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2087 | subtype = findLastResortApplicableSubtypeLocked( |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2088 | explicitlyEnabledSubtypes, mode, mCurrentSubtype.getLocale(), false); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2089 | } |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2090 | // 2. Search by the system locale from explicitlyEnabledSubtypes. |
| 2091 | // 3. Search the first enabled subtype matched with mode from explicitlyEnabledSubtypes. |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2092 | if (subtype == null) { |
| 2093 | subtype = findLastResortApplicableSubtypeLocked( |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2094 | explicitlyEnabledSubtypes, mode, null, true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2095 | } |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2096 | // 4. Search by the current subtype's locale from all subtypes. |
| 2097 | if (subtype == null && mCurrentSubtype != null) { |
| 2098 | subtype = findLastResortApplicableSubtypeLocked( |
| 2099 | imi.getSubtypes(), mode, mCurrentSubtype.getLocale(), false); |
| 2100 | } |
| 2101 | // 5. Search by the system locale from all subtypes. |
| 2102 | // 6. Search the first enabled subtype matched with mode from all subtypes. |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2103 | if (subtype == null) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2104 | subtype = findLastResortApplicableSubtypeLocked( |
| 2105 | imi.getSubtypes(), mode, null, true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2106 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2107 | if (subtype != null) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2108 | if (imiId.equals(mCurMethodId)) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2109 | // The current input method is the most applicable IME. |
| 2110 | mostApplicableIMI = imi; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2111 | mostApplicableSubtype = subtype; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2112 | break; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2113 | } else if (!foundInSystemIME) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2114 | // The system input method is 2nd applicable IME. |
| 2115 | mostApplicableIMI = imi; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2116 | mostApplicableSubtype = subtype; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2117 | if ((imi.getServiceInfo().applicationInfo.flags |
| 2118 | & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 2119 | foundInSystemIME = true; |
| 2120 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2121 | } |
| 2122 | } |
| 2123 | } |
| 2124 | if (DEBUG) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2125 | if (mostApplicableIMI != null) { |
| 2126 | Slog.w(TAG, "Most applicable shortcut input method was:" |
| 2127 | + mostApplicableIMI.getId()); |
| 2128 | if (mostApplicableSubtype != null) { |
| 2129 | Slog.w(TAG, "Most applicable shortcut input method subtype was:" |
| 2130 | + "," + mostApplicableSubtype.getMode() + "," |
| 2131 | + mostApplicableSubtype.getLocale()); |
| 2132 | } |
| 2133 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2134 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2135 | if (mostApplicableIMI != null) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2136 | return new Pair<InputMethodInfo, InputMethodSubtype> (mostApplicableIMI, |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2137 | mostApplicableSubtype); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2138 | } else { |
| 2139 | return null; |
| 2140 | } |
| 2141 | } |
| 2142 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2143 | /** |
| 2144 | * @return Return the current subtype of this input method. |
| 2145 | */ |
| 2146 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2147 | boolean subtypeIsSelected = false; |
| 2148 | try { |
| 2149 | subtypeIsSelected = Settings.Secure.getInt(mContext.getContentResolver(), |
| 2150 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE) != NOT_A_SUBTYPE_ID; |
| 2151 | } catch (SettingNotFoundException e) { |
| 2152 | } |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2153 | synchronized (mMethodMap) { |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2154 | if (!subtypeIsSelected || mCurrentSubtype == null) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2155 | String lastInputMethodId = Settings.Secure.getString( |
| 2156 | mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2157 | int subtypeId = getSelectedInputMethodSubtypeId(lastInputMethodId); |
| 2158 | if (subtypeId == NOT_A_SUBTYPE_ID) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2159 | InputMethodInfo imi = mMethodMap.get(lastInputMethodId); |
| 2160 | if (imi != null) { |
| 2161 | // If there are no selected subtypes, the framework will try to find |
| 2162 | // the most applicable subtype from all subtypes whose mode is |
| 2163 | // SUBTYPE_MODE_KEYBOARD. This is an exceptional case, so we will hardcode |
| 2164 | // the mode. |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2165 | mCurrentSubtype = findLastResortApplicableSubtypeLocked(imi.getSubtypes(), |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2166 | SUBTYPE_MODE_KEYBOARD, null, true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2167 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2168 | } else { |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2169 | mCurrentSubtype = |
| 2170 | mMethodMap.get(lastInputMethodId).getSubtypes().get(subtypeId); |
| 2171 | } |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2172 | } |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 2173 | return mCurrentSubtype; |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 2174 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2175 | } |
| 2176 | |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2177 | private void addShortcutInputMethodAndSubtypes(InputMethodInfo imi, |
| 2178 | InputMethodSubtype subtype) { |
| 2179 | if (mShortcutInputMethodsAndSubtypes.containsKey(imi)) { |
| 2180 | mShortcutInputMethodsAndSubtypes.get(imi).add(subtype); |
| 2181 | } else { |
| 2182 | ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>(); |
| 2183 | subtypes.add(subtype); |
| 2184 | mShortcutInputMethodsAndSubtypes.put(imi, subtypes); |
| 2185 | } |
| 2186 | } |
| 2187 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2188 | // TODO: We should change the return type from List to List<Parcelable> |
| 2189 | public List getShortcutInputMethodsAndSubtypes() { |
| 2190 | synchronized (mMethodMap) { |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2191 | if (mShortcutInputMethodsAndSubtypes.size() == 0) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2192 | // If there are no selected shortcut subtypes, the framework will try to find |
| 2193 | // the most applicable subtype from all subtypes whose mode is |
| 2194 | // 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] | 2195 | Pair<InputMethodInfo, InputMethodSubtype> info = |
| 2196 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked( |
| 2197 | SUBTYPE_MODE_VOICE); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame^] | 2198 | if (info != null) { |
| 2199 | addShortcutInputMethodAndSubtypes(info.first, info.second); |
| 2200 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2201 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2202 | ArrayList<Object> ret = new ArrayList<Object>(); |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2203 | for (InputMethodInfo imi: mShortcutInputMethodsAndSubtypes.keySet()) { |
| 2204 | ret.add(imi); |
| 2205 | for (InputMethodSubtype subtype: mShortcutInputMethodsAndSubtypes.get(imi)) { |
| 2206 | ret.add(subtype); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2207 | } |
| 2208 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2209 | return ret; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2210 | } |
| 2211 | } |
| 2212 | |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 2213 | public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) { |
| 2214 | synchronized (mMethodMap) { |
| 2215 | if (subtype != null && mCurMethodId != null) { |
| 2216 | InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 2217 | int subtypeId = getSubtypeIdFromHashCode(imi, subtype.hashCode()); |
| 2218 | if (subtypeId != NOT_A_SUBTYPE_ID) { |
| 2219 | setInputMethodLocked(mCurMethodId, subtypeId); |
| 2220 | return true; |
| 2221 | } |
| 2222 | } |
| 2223 | return false; |
| 2224 | } |
| 2225 | } |
| 2226 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2227 | /** |
| 2228 | * Utility class for putting and getting settings for InputMethod |
| 2229 | * TODO: Move all putters and getters of settings to this class. |
| 2230 | */ |
| 2231 | private static class InputMethodSettings { |
| 2232 | // The string for enabled input method is saved as follows: |
| 2233 | // example: ("ime0;subtype0;subtype1;subtype2:ime1:ime2;subtype0") |
| 2234 | private static final char INPUT_METHOD_SEPARATER = ':'; |
| 2235 | private static final char INPUT_METHOD_SUBTYPE_SEPARATER = ';'; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2236 | private final TextUtils.SimpleStringSplitter mInputMethodSplitter = |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2237 | new TextUtils.SimpleStringSplitter(INPUT_METHOD_SEPARATER); |
| 2238 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2239 | private final TextUtils.SimpleStringSplitter mSubtypeSplitter = |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2240 | new TextUtils.SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATER); |
| 2241 | |
| 2242 | private final ContentResolver mResolver; |
| 2243 | private final HashMap<String, InputMethodInfo> mMethodMap; |
| 2244 | private final ArrayList<InputMethodInfo> mMethodList; |
| 2245 | |
| 2246 | private String mEnabledInputMethodsStrCache; |
| 2247 | |
| 2248 | private static void buildEnabledInputMethodsSettingString( |
| 2249 | StringBuilder builder, Pair<String, ArrayList<String>> pair) { |
| 2250 | String id = pair.first; |
| 2251 | ArrayList<String> subtypes = pair.second; |
| 2252 | builder.append(id); |
satok | 57c767c | 2010-11-01 22:34:08 +0900 | [diff] [blame] | 2253 | // Inputmethod and subtypes are saved in the settings as follows: |
| 2254 | // ime0;subtype0;subtype1:ime1;subtype0:ime2:ime3;subtype0;subtype1 |
| 2255 | for (String subtypeId: subtypes) { |
| 2256 | builder.append(INPUT_METHOD_SUBTYPE_SEPARATER).append(subtypeId); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | public InputMethodSettings( |
| 2261 | ContentResolver resolver, HashMap<String, InputMethodInfo> methodMap, |
| 2262 | ArrayList<InputMethodInfo> methodList) { |
| 2263 | mResolver = resolver; |
| 2264 | mMethodMap = methodMap; |
| 2265 | mMethodList = methodList; |
| 2266 | } |
| 2267 | |
| 2268 | public List<InputMethodInfo> getEnabledInputMethodListLocked() { |
| 2269 | return createEnabledInputMethodListLocked( |
| 2270 | getEnabledInputMethodsAndSubtypeListLocked()); |
| 2271 | } |
| 2272 | |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2273 | public List<Pair<InputMethodInfo, ArrayList<String>>> |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2274 | getEnabledInputMethodAndSubtypeHashCodeListLocked() { |
| 2275 | return createEnabledInputMethodAndSubtypeHashCodeListLocked( |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2276 | getEnabledInputMethodsAndSubtypeListLocked()); |
| 2277 | } |
| 2278 | |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2279 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked( |
| 2280 | InputMethodInfo imi) { |
| 2281 | List<Pair<String, ArrayList<String>>> imsList = |
| 2282 | getEnabledInputMethodsAndSubtypeListLocked(); |
| 2283 | ArrayList<InputMethodSubtype> enabledSubtypes = |
| 2284 | new ArrayList<InputMethodSubtype>(); |
satok | 884ef9a | 2010-11-18 10:39:46 +0900 | [diff] [blame] | 2285 | if (imi != null) { |
| 2286 | for (Pair<String, ArrayList<String>> imsPair : imsList) { |
| 2287 | InputMethodInfo info = mMethodMap.get(imsPair.first); |
| 2288 | if (info != null && info.getId().equals(imi.getId())) { |
| 2289 | ArrayList<InputMethodSubtype> subtypes = info.getSubtypes(); |
| 2290 | for (InputMethodSubtype ims: subtypes) { |
| 2291 | for (String s: imsPair.second) { |
| 2292 | if (String.valueOf(ims.hashCode()).equals(s)) { |
| 2293 | enabledSubtypes.add(ims); |
| 2294 | } |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2295 | } |
| 2296 | } |
satok | 884ef9a | 2010-11-18 10:39:46 +0900 | [diff] [blame] | 2297 | break; |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2298 | } |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2299 | } |
| 2300 | } |
| 2301 | return enabledSubtypes; |
| 2302 | } |
| 2303 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2304 | // At the initial boot, the settings for input methods are not set, |
| 2305 | // so we need to enable IME in that case. |
| 2306 | public void enableAllIMEsIfThereIsNoEnabledIME() { |
| 2307 | if (TextUtils.isEmpty(getEnabledInputMethodsStr())) { |
| 2308 | StringBuilder sb = new StringBuilder(); |
| 2309 | final int N = mMethodList.size(); |
| 2310 | for (int i = 0; i < N; i++) { |
| 2311 | InputMethodInfo imi = mMethodList.get(i); |
| 2312 | Slog.i(TAG, "Adding: " + imi.getId()); |
| 2313 | if (i > 0) sb.append(':'); |
| 2314 | sb.append(imi.getId()); |
| 2315 | } |
| 2316 | putEnabledInputMethodsStr(sb.toString()); |
| 2317 | } |
| 2318 | } |
| 2319 | |
| 2320 | public List<Pair<String, ArrayList<String>>> getEnabledInputMethodsAndSubtypeListLocked() { |
| 2321 | ArrayList<Pair<String, ArrayList<String>>> imsList |
| 2322 | = new ArrayList<Pair<String, ArrayList<String>>>(); |
| 2323 | final String enabledInputMethodsStr = getEnabledInputMethodsStr(); |
| 2324 | if (TextUtils.isEmpty(enabledInputMethodsStr)) { |
| 2325 | return imsList; |
| 2326 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2327 | mInputMethodSplitter.setString(enabledInputMethodsStr); |
| 2328 | while (mInputMethodSplitter.hasNext()) { |
| 2329 | String nextImsStr = mInputMethodSplitter.next(); |
| 2330 | mSubtypeSplitter.setString(nextImsStr); |
| 2331 | if (mSubtypeSplitter.hasNext()) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2332 | ArrayList<String> subtypeHashes = new ArrayList<String>(); |
| 2333 | // The first element is ime id. |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2334 | String imeId = mSubtypeSplitter.next(); |
| 2335 | while (mSubtypeSplitter.hasNext()) { |
| 2336 | subtypeHashes.add(mSubtypeSplitter.next()); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2337 | } |
| 2338 | imsList.add(new Pair<String, ArrayList<String>>(imeId, subtypeHashes)); |
| 2339 | } |
| 2340 | } |
| 2341 | return imsList; |
| 2342 | } |
| 2343 | |
| 2344 | public void appendAndPutEnabledInputMethodLocked(String id, boolean reloadInputMethodStr) { |
| 2345 | if (reloadInputMethodStr) { |
| 2346 | getEnabledInputMethodsStr(); |
| 2347 | } |
| 2348 | if (TextUtils.isEmpty(mEnabledInputMethodsStrCache)) { |
| 2349 | // Add in the newly enabled input method. |
| 2350 | putEnabledInputMethodsStr(id); |
| 2351 | } else { |
| 2352 | putEnabledInputMethodsStr( |
| 2353 | mEnabledInputMethodsStrCache + INPUT_METHOD_SEPARATER + id); |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | /** |
| 2358 | * Build and put a string of EnabledInputMethods with removing specified Id. |
| 2359 | * @return the specified id was removed or not. |
| 2360 | */ |
| 2361 | public boolean buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 2362 | StringBuilder builder, List<Pair<String, ArrayList<String>>> imsList, String id) { |
| 2363 | boolean isRemoved = false; |
| 2364 | boolean needsAppendSeparator = false; |
| 2365 | for (Pair<String, ArrayList<String>> ims: imsList) { |
| 2366 | String curId = ims.first; |
| 2367 | if (curId.equals(id)) { |
| 2368 | // We are disabling this input method, and it is |
| 2369 | // currently enabled. Skip it to remove from the |
| 2370 | // new list. |
| 2371 | isRemoved = true; |
| 2372 | } else { |
| 2373 | if (needsAppendSeparator) { |
| 2374 | builder.append(INPUT_METHOD_SEPARATER); |
| 2375 | } else { |
| 2376 | needsAppendSeparator = true; |
| 2377 | } |
| 2378 | buildEnabledInputMethodsSettingString(builder, ims); |
| 2379 | } |
| 2380 | } |
| 2381 | if (isRemoved) { |
| 2382 | // Update the setting with the new list of input methods. |
| 2383 | putEnabledInputMethodsStr(builder.toString()); |
| 2384 | } |
| 2385 | return isRemoved; |
| 2386 | } |
| 2387 | |
| 2388 | private List<InputMethodInfo> createEnabledInputMethodListLocked( |
| 2389 | List<Pair<String, ArrayList<String>>> imsList) { |
| 2390 | final ArrayList<InputMethodInfo> res = new ArrayList<InputMethodInfo>(); |
| 2391 | for (Pair<String, ArrayList<String>> ims: imsList) { |
| 2392 | InputMethodInfo info = mMethodMap.get(ims.first); |
| 2393 | if (info != null) { |
| 2394 | res.add(info); |
| 2395 | } |
| 2396 | } |
| 2397 | return res; |
| 2398 | } |
| 2399 | |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2400 | private List<Pair<InputMethodInfo, ArrayList<String>>> |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2401 | createEnabledInputMethodAndSubtypeHashCodeListLocked( |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 2402 | List<Pair<String, ArrayList<String>>> imsList) { |
| 2403 | final ArrayList<Pair<InputMethodInfo, ArrayList<String>>> res |
| 2404 | = new ArrayList<Pair<InputMethodInfo, ArrayList<String>>>(); |
| 2405 | for (Pair<String, ArrayList<String>> ims : imsList) { |
| 2406 | InputMethodInfo info = mMethodMap.get(ims.first); |
| 2407 | if (info != null) { |
| 2408 | res.add(new Pair<InputMethodInfo, ArrayList<String>>(info, ims.second)); |
| 2409 | } |
| 2410 | } |
| 2411 | return res; |
| 2412 | } |
| 2413 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2414 | private void putEnabledInputMethodsStr(String str) { |
| 2415 | Settings.Secure.putString(mResolver, Settings.Secure.ENABLED_INPUT_METHODS, str); |
| 2416 | mEnabledInputMethodsStrCache = str; |
| 2417 | } |
| 2418 | |
| 2419 | private String getEnabledInputMethodsStr() { |
| 2420 | mEnabledInputMethodsStrCache = Settings.Secure.getString( |
| 2421 | mResolver, Settings.Secure.ENABLED_INPUT_METHODS); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2422 | if (DEBUG) { |
| 2423 | Slog.d(TAG, "getEnabledInputMethodsStr: " + mEnabledInputMethodsStrCache); |
| 2424 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2425 | return mEnabledInputMethodsStrCache; |
| 2426 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2427 | |
| 2428 | private void saveSubtypeHistory( |
| 2429 | List<Pair<String, String>> savedImes, String newImeId, String newSubtypeId) { |
| 2430 | StringBuilder builder = new StringBuilder(); |
| 2431 | boolean isImeAdded = false; |
| 2432 | if (!TextUtils.isEmpty(newImeId) && !TextUtils.isEmpty(newSubtypeId)) { |
| 2433 | builder.append(newImeId).append(INPUT_METHOD_SUBTYPE_SEPARATER).append( |
| 2434 | newSubtypeId); |
| 2435 | isImeAdded = true; |
| 2436 | } |
| 2437 | for (Pair<String, String> ime: savedImes) { |
| 2438 | String imeId = ime.first; |
| 2439 | String subtypeId = ime.second; |
| 2440 | if (TextUtils.isEmpty(subtypeId)) { |
| 2441 | subtypeId = NOT_A_SUBTYPE_ID_STR; |
| 2442 | } |
| 2443 | if (isImeAdded) { |
| 2444 | builder.append(INPUT_METHOD_SEPARATER); |
| 2445 | } else { |
| 2446 | isImeAdded = true; |
| 2447 | } |
| 2448 | builder.append(imeId).append(INPUT_METHOD_SUBTYPE_SEPARATER).append( |
| 2449 | subtypeId); |
| 2450 | } |
| 2451 | // Remove the last INPUT_METHOD_SEPARATER |
| 2452 | putSubtypeHistoryStr(builder.toString()); |
| 2453 | } |
| 2454 | |
| 2455 | public void addSubtypeToHistory(String imeId, String subtypeId) { |
| 2456 | List<Pair<String, String>> subtypeHistory = loadInputMethodAndSubtypeHistoryLocked(); |
| 2457 | for (Pair<String, String> ime: subtypeHistory) { |
| 2458 | if (ime.first.equals(imeId)) { |
| 2459 | if (DEBUG) { |
| 2460 | Slog.v(TAG, "Subtype found in the history: " + imeId |
| 2461 | + ime.second); |
| 2462 | } |
| 2463 | // We should break here |
| 2464 | subtypeHistory.remove(ime); |
| 2465 | break; |
| 2466 | } |
| 2467 | } |
| 2468 | saveSubtypeHistory(subtypeHistory, imeId, subtypeId); |
| 2469 | } |
| 2470 | |
| 2471 | private void putSubtypeHistoryStr(String str) { |
| 2472 | if (DEBUG) { |
| 2473 | Slog.d(TAG, "putSubtypeHistoryStr: " + str); |
| 2474 | } |
| 2475 | Settings.Secure.putString( |
| 2476 | mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY, str); |
| 2477 | } |
| 2478 | |
| 2479 | public Pair<String, String> getLastInputMethodAndSubtypeLocked() { |
| 2480 | // Gets the first one from the history |
| 2481 | return getLastSubtypeForInputMethodLockedInternal(null); |
| 2482 | } |
| 2483 | |
| 2484 | public String getLastSubtypeForInputMethodLocked(String imeId) { |
| 2485 | Pair<String, String> ime = getLastSubtypeForInputMethodLockedInternal(imeId); |
| 2486 | if (ime != null) { |
| 2487 | return ime.second; |
| 2488 | } else { |
| 2489 | return null; |
| 2490 | } |
| 2491 | } |
| 2492 | |
| 2493 | private Pair<String, String> getLastSubtypeForInputMethodLockedInternal(String imeId) { |
| 2494 | List<Pair<String, ArrayList<String>>> enabledImes = |
| 2495 | getEnabledInputMethodsAndSubtypeListLocked(); |
| 2496 | List<Pair<String, String>> subtypeHistory = loadInputMethodAndSubtypeHistoryLocked(); |
| 2497 | for (Pair<String, String> imeAndSubtype: subtypeHistory) { |
| 2498 | final String imeInTheHistory = imeAndSubtype.first; |
| 2499 | // If imeId is empty, returns the first IME and subtype in the history |
| 2500 | if (TextUtils.isEmpty(imeId) || imeInTheHistory.equals(imeId)) { |
| 2501 | final String subtypeInTheHistory = imeAndSubtype.second; |
| 2502 | final String subtypeHashCode = getEnabledSubtypeForInputMethodAndSubtypeLocked( |
| 2503 | enabledImes, imeInTheHistory, subtypeInTheHistory); |
| 2504 | if (!TextUtils.isEmpty(subtypeHashCode)) { |
| 2505 | if (DEBUG) { |
| 2506 | Slog.d(TAG, "Enabled subtype found in the history:" + subtypeHashCode); |
| 2507 | } |
| 2508 | return new Pair<String, String>(imeInTheHistory, subtypeHashCode); |
| 2509 | } |
| 2510 | } |
| 2511 | } |
| 2512 | if (DEBUG) { |
| 2513 | Slog.d(TAG, "No enabled IME found in the history"); |
| 2514 | } |
| 2515 | return null; |
| 2516 | } |
| 2517 | |
| 2518 | private String getEnabledSubtypeForInputMethodAndSubtypeLocked(List<Pair<String, |
| 2519 | ArrayList<String>>> enabledImes, String imeId, String subtypeHashCode) { |
| 2520 | for (Pair<String, ArrayList<String>> enabledIme: enabledImes) { |
| 2521 | if (enabledIme.first.equals(imeId)) { |
| 2522 | for (String s: enabledIme.second) { |
| 2523 | if (s.equals(subtypeHashCode)) { |
| 2524 | // If both imeId and subtypeId are enabled, return subtypeId. |
| 2525 | return s; |
| 2526 | } |
| 2527 | } |
| 2528 | // If imeId was enabled but subtypeId was disabled. |
| 2529 | return NOT_A_SUBTYPE_ID_STR; |
| 2530 | } |
| 2531 | } |
| 2532 | // If both imeId and subtypeId are disabled, return null |
| 2533 | return null; |
| 2534 | } |
| 2535 | |
| 2536 | private List<Pair<String, String>> loadInputMethodAndSubtypeHistoryLocked() { |
| 2537 | ArrayList<Pair<String, String>> imsList = new ArrayList<Pair<String, String>>(); |
| 2538 | final String subtypeHistoryStr = getSubtypeHistoryStr(); |
| 2539 | if (TextUtils.isEmpty(subtypeHistoryStr)) { |
| 2540 | return imsList; |
| 2541 | } |
| 2542 | mInputMethodSplitter.setString(subtypeHistoryStr); |
| 2543 | while (mInputMethodSplitter.hasNext()) { |
| 2544 | String nextImsStr = mInputMethodSplitter.next(); |
| 2545 | mSubtypeSplitter.setString(nextImsStr); |
| 2546 | if (mSubtypeSplitter.hasNext()) { |
| 2547 | String subtypeId = NOT_A_SUBTYPE_ID_STR; |
| 2548 | // The first element is ime id. |
| 2549 | String imeId = mSubtypeSplitter.next(); |
| 2550 | while (mSubtypeSplitter.hasNext()) { |
| 2551 | subtypeId = mSubtypeSplitter.next(); |
| 2552 | break; |
| 2553 | } |
| 2554 | imsList.add(new Pair<String, String>(imeId, subtypeId)); |
| 2555 | } |
| 2556 | } |
| 2557 | return imsList; |
| 2558 | } |
| 2559 | |
| 2560 | private String getSubtypeHistoryStr() { |
| 2561 | if (DEBUG) { |
| 2562 | Slog.d(TAG, "getSubtypeHistoryStr: " + Settings.Secure.getString( |
| 2563 | mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY)); |
| 2564 | } |
| 2565 | return Settings.Secure.getString( |
| 2566 | mResolver, Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY); |
| 2567 | } |
| 2568 | |
| 2569 | public void putSelectedInputMethod(String imeId) { |
| 2570 | Settings.Secure.putString(mResolver, Settings.Secure.DEFAULT_INPUT_METHOD, imeId); |
| 2571 | } |
| 2572 | |
| 2573 | public void putSelectedSubtype(int subtypeId) { |
| 2574 | Settings.Secure.putInt( |
| 2575 | mResolver, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, subtypeId); |
| 2576 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 2577 | } |
| 2578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2579 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2580 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2581 | @Override |
| 2582 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2583 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 2584 | != PackageManager.PERMISSION_GRANTED) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2585 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2586 | pw.println("Permission Denial: can't dump InputMethodManager from from pid=" |
| 2587 | + Binder.getCallingPid() |
| 2588 | + ", uid=" + Binder.getCallingUid()); |
| 2589 | return; |
| 2590 | } |
| 2591 | |
| 2592 | IInputMethod method; |
| 2593 | ClientState client; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2594 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2595 | final Printer p = new PrintWriterPrinter(pw); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2596 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2597 | synchronized (mMethodMap) { |
| 2598 | p.println("Current Input Method Manager state:"); |
| 2599 | int N = mMethodList.size(); |
| 2600 | p.println(" Input Methods:"); |
| 2601 | for (int i=0; i<N; i++) { |
| 2602 | InputMethodInfo info = mMethodList.get(i); |
| 2603 | p.println(" InputMethod #" + i + ":"); |
| 2604 | info.dump(p, " "); |
| 2605 | } |
| 2606 | p.println(" Clients:"); |
| 2607 | for (ClientState ci : mClients.values()) { |
| 2608 | p.println(" Client " + ci + ":"); |
| 2609 | p.println(" client=" + ci.client); |
| 2610 | p.println(" inputContext=" + ci.inputContext); |
| 2611 | p.println(" sessionRequested=" + ci.sessionRequested); |
| 2612 | p.println(" curSession=" + ci.curSession); |
| 2613 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2614 | p.println(" mCurMethodId=" + mCurMethodId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2615 | client = mCurClient; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2616 | p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq); |
| 2617 | p.println(" mCurFocusedWindow=" + mCurFocusedWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2618 | p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection |
| 2619 | + " mBoundToMethod=" + mBoundToMethod); |
| 2620 | p.println(" mCurToken=" + mCurToken); |
| 2621 | p.println(" mCurIntent=" + mCurIntent); |
| 2622 | method = mCurMethod; |
| 2623 | p.println(" mCurMethod=" + mCurMethod); |
| 2624 | p.println(" mEnabledSession=" + mEnabledSession); |
| 2625 | p.println(" mShowRequested=" + mShowRequested |
| 2626 | + " mShowExplicitlyRequested=" + mShowExplicitlyRequested |
| 2627 | + " mShowForced=" + mShowForced |
| 2628 | + " mInputShown=" + mInputShown); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2629 | p.println(" mSystemReady=" + mSystemReady + " mScreenOn=" + mScreenOn); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2630 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2631 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2632 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2633 | if (client != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2634 | pw.flush(); |
| 2635 | try { |
| 2636 | client.client.asBinder().dump(fd, args); |
| 2637 | } catch (RemoteException e) { |
| 2638 | p.println("Input method client dead: " + e); |
| 2639 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2640 | } else { |
| 2641 | p.println("No input method client."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2642 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2643 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2644 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2645 | if (method != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2646 | pw.flush(); |
| 2647 | try { |
| 2648 | method.asBinder().dump(fd, args); |
| 2649 | } catch (RemoteException e) { |
| 2650 | p.println("Input method service dead: " + e); |
| 2651 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2652 | } else { |
| 2653 | p.println("No input method service."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2654 | } |
| 2655 | } |
| 2656 | } |