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