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; |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 28 | import com.android.internal.view.InputMethodAndSubtypeEnabler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
Joe Onorato | 7a0f36b | 2010-06-07 10:24:36 -0700 | [diff] [blame] | 30 | import com.android.server.StatusBarManagerService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
| 32 | import org.xmlpull.v1.XmlPullParserException; |
| 33 | |
| 34 | import android.app.ActivityManagerNative; |
| 35 | import android.app.AlertDialog; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 36 | import android.app.PendingIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.content.ComponentName; |
| 38 | import android.content.ContentResolver; |
| 39 | import android.content.Context; |
| 40 | import android.content.DialogInterface; |
| 41 | import android.content.IntentFilter; |
| 42 | import android.content.DialogInterface.OnCancelListener; |
| 43 | import android.content.Intent; |
| 44 | import android.content.ServiceConnection; |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 45 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.content.pm.PackageManager; |
| 47 | import android.content.pm.ResolveInfo; |
| 48 | import android.content.pm.ServiceInfo; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 49 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.content.res.Resources; |
| 51 | import android.content.res.TypedArray; |
| 52 | import android.database.ContentObserver; |
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; |
| 67 | import android.util.EventLog; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 68 | import android.util.Pair; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 69 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.util.PrintWriterPrinter; |
| 71 | import android.util.Printer; |
| 72 | import android.view.IWindowManager; |
| 73 | import android.view.WindowManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 74 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.view.inputmethod.InputBinding; |
| 76 | import android.view.inputmethod.InputMethod; |
| 77 | import android.view.inputmethod.InputMethodInfo; |
| 78 | import android.view.inputmethod.InputMethodManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 79 | import android.view.inputmethod.InputMethodSubtype; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | |
| 81 | import java.io.FileDescriptor; |
| 82 | import java.io.IOException; |
| 83 | import java.io.PrintWriter; |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 84 | import java.text.Collator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import java.util.ArrayList; |
| 86 | import java.util.HashMap; |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame^] | 87 | import java.util.HashSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | import java.util.List; |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 89 | import java.util.Map; |
| 90 | import java.util.TreeMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * This class provides a system service that manages input methods. |
| 94 | */ |
| 95 | public class InputMethodManagerService extends IInputMethodManager.Stub |
| 96 | implements ServiceConnection, Handler.Callback { |
| 97 | static final boolean DEBUG = false; |
| 98 | static final String TAG = "InputManagerService"; |
| 99 | |
| 100 | static final int MSG_SHOW_IM_PICKER = 1; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 101 | static final int MSG_SHOW_IM_SUBTYPE_PICKER = 2; |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 102 | static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 3; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | static final int MSG_UNBIND_INPUT = 1000; |
| 105 | static final int MSG_BIND_INPUT = 1010; |
| 106 | static final int MSG_SHOW_SOFT_INPUT = 1020; |
| 107 | static final int MSG_HIDE_SOFT_INPUT = 1030; |
| 108 | static final int MSG_ATTACH_TOKEN = 1040; |
| 109 | static final int MSG_CREATE_SESSION = 1050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | static final int MSG_START_INPUT = 2000; |
| 112 | static final int MSG_RESTART_INPUT = 2010; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | static final int MSG_UNBIND_METHOD = 3000; |
| 115 | static final int MSG_BIND_METHOD = 3010; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | static final long TIME_TO_RECONNECT = 10*1000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 118 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 119 | private static final int NOT_A_SUBTYPE_ID = -1; |
| 120 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | final Context mContext; |
| 122 | final Handler mHandler; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 123 | final InputMethodSettings mSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | final SettingsObserver mSettingsObserver; |
Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 125 | final StatusBarManagerService mStatusBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | final IWindowManager mIWindowManager; |
| 127 | final HandlerCaller mCaller; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 128 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | final InputBindResult mNoBinding = new InputBindResult(null, null, -1); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | // All known input methods. mMethodMap also serves as the global |
| 132 | // lock for this class. |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 133 | final ArrayList<InputMethodInfo> mMethodList = new ArrayList<InputMethodInfo>(); |
| 134 | final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<String, InputMethodInfo>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | class SessionState { |
| 137 | final ClientState client; |
| 138 | final IInputMethod method; |
| 139 | final IInputMethodSession session; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | @Override |
| 142 | public String toString() { |
| 143 | return "SessionState{uid " + client.uid + " pid " + client.pid |
| 144 | + " method " + Integer.toHexString( |
| 145 | System.identityHashCode(method)) |
| 146 | + " session " + Integer.toHexString( |
| 147 | System.identityHashCode(session)) |
| 148 | + "}"; |
| 149 | } |
| 150 | |
| 151 | SessionState(ClientState _client, IInputMethod _method, |
| 152 | IInputMethodSession _session) { |
| 153 | client = _client; |
| 154 | method = _method; |
| 155 | session = _session; |
| 156 | } |
| 157 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | class ClientState { |
| 160 | final IInputMethodClient client; |
| 161 | final IInputContext inputContext; |
| 162 | final int uid; |
| 163 | final int pid; |
| 164 | final InputBinding binding; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | boolean sessionRequested; |
| 167 | SessionState curSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | @Override |
| 170 | public String toString() { |
| 171 | return "ClientState{" + Integer.toHexString( |
| 172 | System.identityHashCode(this)) + " uid " + uid |
| 173 | + " pid " + pid + "}"; |
| 174 | } |
| 175 | |
| 176 | ClientState(IInputMethodClient _client, IInputContext _inputContext, |
| 177 | int _uid, int _pid) { |
| 178 | client = _client; |
| 179 | inputContext = _inputContext; |
| 180 | uid = _uid; |
| 181 | pid = _pid; |
| 182 | binding = new InputBinding(null, inputContext.asBinder(), uid, pid); |
| 183 | } |
| 184 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | final HashMap<IBinder, ClientState> mClients |
| 187 | = new HashMap<IBinder, ClientState>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 188 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | /** |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 190 | * Set once the system is ready to run third party code. |
| 191 | */ |
| 192 | boolean mSystemReady; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 193 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 194 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | * Id of the currently selected input method. |
| 196 | */ |
| 197 | String mCurMethodId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | /** |
| 200 | * The current binding sequence number, incremented every time there is |
| 201 | * a new bind performed. |
| 202 | */ |
| 203 | int mCurSeq; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 204 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | /** |
| 206 | * The client that is currently bound to an input method. |
| 207 | */ |
| 208 | ClientState mCurClient; |
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 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 211 | * The last window token that gained focus. |
| 212 | */ |
| 213 | IBinder mCurFocusedWindow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 214 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 215 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | * The input context last provided by the current client. |
| 217 | */ |
| 218 | IInputContext mCurInputContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 219 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | /** |
| 221 | * The attributes last provided by the current client. |
| 222 | */ |
| 223 | EditorInfo mCurAttribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | /** |
| 226 | * The input method ID of the input method service that we are currently |
| 227 | * connected to or in the process of connecting to. |
| 228 | */ |
| 229 | String mCurId; |
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 | /** |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 232 | * The current subtype of the current input method. |
| 233 | */ |
| 234 | private InputMethodSubtype mCurrentSubtype; |
| 235 | |
| 236 | |
| 237 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | * Set to true if our ServiceConnection is currently actively bound to |
| 239 | * a service (whether or not we have gotten its IBinder back yet). |
| 240 | */ |
| 241 | boolean mHaveConnection; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 242 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | /** |
| 244 | * Set if the client has asked for the input method to be shown. |
| 245 | */ |
| 246 | boolean mShowRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | /** |
| 249 | * Set if we were explicitly told to show the input method. |
| 250 | */ |
| 251 | boolean mShowExplicitlyRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 252 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | /** |
| 254 | * Set if we were forced to be shown. |
| 255 | */ |
| 256 | boolean mShowForced; |
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 we last told the input method to show itself. |
| 260 | */ |
| 261 | boolean mInputShown; |
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 | * The Intent used to connect to the current input method. |
| 265 | */ |
| 266 | Intent mCurIntent; |
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 | * The token we have made for the currently active input method, to |
| 270 | * identify it in the future. |
| 271 | */ |
| 272 | IBinder mCurToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | /** |
| 275 | * If non-null, this is the input method service we are currently connected |
| 276 | * to. |
| 277 | */ |
| 278 | IInputMethod mCurMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | /** |
| 281 | * Time that we last initiated a bind to the input method, to determine |
| 282 | * if we should try to disconnect and reconnect to it. |
| 283 | */ |
| 284 | long mLastBindTime; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | /** |
| 287 | * Have we called mCurMethod.bindInput()? |
| 288 | */ |
| 289 | boolean mBoundToMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | /** |
| 292 | * Currently enabled session. Only touched by service thread, not |
| 293 | * protected by a lock. |
| 294 | */ |
| 295 | SessionState mEnabledSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | /** |
| 298 | * True if the screen is on. The value is true initially. |
| 299 | */ |
| 300 | boolean mScreenOn = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | AlertDialog.Builder mDialogBuilder; |
| 303 | AlertDialog mSwitchingDialog; |
| 304 | InputMethodInfo[] mIms; |
| 305 | CharSequence[] mItems; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 306 | int[] mSubtypeIds; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 307 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | class SettingsObserver extends ContentObserver { |
| 309 | SettingsObserver(Handler handler) { |
| 310 | super(handler); |
| 311 | ContentResolver resolver = mContext.getContentResolver(); |
| 312 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 313 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 314 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 315 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | @Override public void onChange(boolean selfChange) { |
| 319 | synchronized (mMethodMap) { |
| 320 | updateFromSettingsLocked(); |
| 321 | } |
| 322 | } |
| 323 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 324 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | class ScreenOnOffReceiver extends android.content.BroadcastReceiver { |
| 326 | @Override |
| 327 | public void onReceive(Context context, Intent intent) { |
| 328 | if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { |
| 329 | mScreenOn = true; |
| 330 | } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { |
| 331 | mScreenOn = false; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 332 | } else if (intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) { |
| 333 | hideInputMethodMenu(); |
| 334 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 336 | Slog.w(TAG, "Unexpected intent " + intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | // Inform the current client of the change in active status |
| 340 | try { |
| 341 | if (mCurClient != null && mCurClient.client != null) { |
| 342 | mCurClient.client.setActive(mScreenOn); |
| 343 | } |
| 344 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 345 | 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] | 346 | + mCurClient.pid + " uid " + mCurClient.uid); |
| 347 | } |
| 348 | } |
| 349 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 350 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 351 | class MyPackageMonitor extends PackageMonitor { |
| 352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 354 | 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] | 355 | synchronized (mMethodMap) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 356 | String curInputMethodId = Settings.Secure.getString(mContext |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| 358 | final int N = mMethodList.size(); |
| 359 | if (curInputMethodId != null) { |
| 360 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 361 | InputMethodInfo imi = mMethodList.get(i); |
| 362 | if (imi.getId().equals(curInputMethodId)) { |
| 363 | for (String pkg : packages) { |
| 364 | if (imi.getPackageName().equals(pkg)) { |
| 365 | if (!doit) { |
| 366 | return true; |
| 367 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 368 | Settings.Secure.putString(mContext.getContentResolver(), |
| 369 | Settings.Secure.DEFAULT_INPUT_METHOD, ""); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 370 | resetSelectedInputMethodSubtype(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 371 | chooseNewDefaultIMELocked(); |
| 372 | return true; |
| 373 | } |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | return false; |
| 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public void onSomePackagesChanged() { |
| 384 | synchronized (mMethodMap) { |
| 385 | InputMethodInfo curIm = null; |
| 386 | String curInputMethodId = Settings.Secure.getString(mContext |
| 387 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| 388 | final int N = mMethodList.size(); |
| 389 | if (curInputMethodId != null) { |
| 390 | for (int i=0; i<N; i++) { |
| 391 | InputMethodInfo imi = mMethodList.get(i); |
| 392 | if (imi.getId().equals(curInputMethodId)) { |
| 393 | curIm = imi; |
| 394 | } |
| 395 | int change = isPackageDisappearing(imi.getPackageName()); |
| 396 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 397 | || change == PACKAGE_PERMANENT_CHANGE) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 398 | Slog.i(TAG, "Input method uninstalled, disabling: " |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 399 | + imi.getComponent()); |
| 400 | setInputMethodEnabledLocked(imi.getId(), false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 404 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 405 | buildInputMethodListLocked(mMethodList, mMethodMap); |
| 406 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 408 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 409 | if (curIm != null) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 410 | int change = isPackageDisappearing(curIm.getPackageName()); |
| 411 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 412 | || change == PACKAGE_PERMANENT_CHANGE) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 413 | ServiceInfo si = null; |
| 414 | try { |
| 415 | si = mContext.getPackageManager().getServiceInfo( |
| 416 | curIm.getComponent(), 0); |
| 417 | } catch (PackageManager.NameNotFoundException ex) { |
| 418 | } |
| 419 | if (si == null) { |
| 420 | // Uh oh, current input method is no longer around! |
| 421 | // Pick another one... |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 422 | Slog.i(TAG, "Current input method removed: " + curInputMethodId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 423 | if (!chooseNewDefaultIMELocked()) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 424 | changed = true; |
| 425 | curIm = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 426 | Slog.i(TAG, "Unsetting current input method"); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 427 | Settings.Secure.putString(mContext.getContentResolver(), |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 428 | Settings.Secure.DEFAULT_INPUT_METHOD, ""); |
| 429 | resetSelectedInputMethodSubtype(); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 430 | } |
| 431 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 432 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 433 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 434 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 435 | if (curIm == null) { |
| 436 | // We currently don't have a default input method... is |
| 437 | // one now available? |
| 438 | changed = chooseNewDefaultIMELocked(); |
| 439 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 440 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 441 | if (changed) { |
| 442 | updateFromSettingsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | } |
| 446 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 447 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | class MethodCallback extends IInputMethodCallback.Stub { |
| 449 | final IInputMethod mMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | MethodCallback(IInputMethod method) { |
| 452 | mMethod = method; |
| 453 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | public void finishedEvent(int seq, boolean handled) throws RemoteException { |
| 456 | } |
| 457 | |
| 458 | public void sessionCreated(IInputMethodSession session) throws RemoteException { |
| 459 | onSessionCreated(mMethod, session); |
| 460 | } |
| 461 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 462 | |
Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 463 | public InputMethodManagerService(Context context, StatusBarManagerService statusBar) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | mContext = context; |
| 465 | mHandler = new Handler(this); |
| 466 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 467 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
| 468 | mCaller = new HandlerCaller(context, new HandlerCaller.Callback() { |
| 469 | public void executeMessage(Message msg) { |
| 470 | handleMessage(msg); |
| 471 | } |
| 472 | }); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 473 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 474 | (new MyPackageMonitor()).register(mContext, true); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | IntentFilter screenOnOffFilt = new IntentFilter(); |
| 477 | screenOnOffFilt.addAction(Intent.ACTION_SCREEN_ON); |
| 478 | screenOnOffFilt.addAction(Intent.ACTION_SCREEN_OFF); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 479 | screenOnOffFilt.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | mContext.registerReceiver(new ScreenOnOffReceiver(), screenOnOffFilt); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 481 | |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 482 | mStatusBar = statusBar; |
| 483 | statusBar.setIconVisibility("ime", false); |
| 484 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 485 | // mSettings should be created before buildInputMethodListLocked |
| 486 | mSettings = new InputMethodSettings(context.getContentResolver(), mMethodMap, mMethodList); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | buildInputMethodListLocked(mMethodList, mMethodMap); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 488 | mSettings.enableAllIMEsIfThereIsNoEnabledIME(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 490 | if (TextUtils.isEmpty(Settings.Secure.getString( |
| 491 | mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | InputMethodInfo defIm = null; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 493 | for (InputMethodInfo imi: mMethodList) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | if (defIm == null && imi.getIsDefaultResourceId() != 0) { |
| 495 | try { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 496 | Resources res = context.createPackageContext( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | imi.getPackageName(), 0).getResources(); |
| 498 | if (res.getBoolean(imi.getIsDefaultResourceId())) { |
| 499 | defIm = imi; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 500 | Slog.i(TAG, "Selected default: " + imi.getId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | } |
| 502 | } catch (PackageManager.NameNotFoundException ex) { |
| 503 | } catch (Resources.NotFoundException ex) { |
| 504 | } |
| 505 | } |
| 506 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 507 | if (defIm == null && mMethodList.size() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 | defIm = mMethodList.get(0); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 509 | Slog.i(TAG, "No default found, using " + defIm.getId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | if (defIm != null) { |
| 512 | Settings.Secure.putString(mContext.getContentResolver(), |
| 513 | Settings.Secure.DEFAULT_INPUT_METHOD, defIm.getId()); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 514 | putSelectedInputMethodSubtype(defIm, NOT_A_SUBTYPE_ID); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | } |
| 516 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 517 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | mSettingsObserver = new SettingsObserver(mHandler); |
| 519 | updateFromSettingsLocked(); |
| 520 | } |
| 521 | |
| 522 | @Override |
| 523 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 524 | throws RemoteException { |
| 525 | try { |
| 526 | return super.onTransact(code, data, reply, flags); |
| 527 | } catch (RuntimeException e) { |
| 528 | // The input method manager only throws security exceptions, so let's |
| 529 | // log all others. |
| 530 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 531 | Slog.e(TAG, "Input Method Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | } |
| 533 | throw e; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | public void systemReady() { |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 538 | synchronized (mMethodMap) { |
| 539 | if (!mSystemReady) { |
| 540 | mSystemReady = true; |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 541 | try { |
| 542 | startInputInnerLocked(); |
| 543 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 544 | Slog.w(TAG, "Unexpected exception", e); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 545 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 546 | } |
| 547 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 550 | public List<InputMethodInfo> getInputMethodList() { |
| 551 | synchronized (mMethodMap) { |
| 552 | return new ArrayList<InputMethodInfo>(mMethodList); |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | public List<InputMethodInfo> getEnabledInputMethodList() { |
| 557 | synchronized (mMethodMap) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 558 | return mSettings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | public void addClient(IInputMethodClient client, |
| 563 | IInputContext inputContext, int uid, int pid) { |
| 564 | synchronized (mMethodMap) { |
| 565 | mClients.put(client.asBinder(), new ClientState(client, |
| 566 | inputContext, uid, pid)); |
| 567 | } |
| 568 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 569 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | public void removeClient(IInputMethodClient client) { |
| 571 | synchronized (mMethodMap) { |
| 572 | mClients.remove(client.asBinder()); |
| 573 | } |
| 574 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 575 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | void executeOrSendMessage(IInterface target, Message msg) { |
| 577 | if (target.asBinder() instanceof Binder) { |
| 578 | mCaller.sendMessage(msg); |
| 579 | } else { |
| 580 | handleMessage(msg); |
| 581 | msg.recycle(); |
| 582 | } |
| 583 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 584 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 585 | void unbindCurrentClientLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | if (mCurClient != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 587 | if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | + mCurClient.client.asBinder()); |
| 589 | if (mBoundToMethod) { |
| 590 | mBoundToMethod = false; |
| 591 | if (mCurMethod != null) { |
| 592 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 593 | MSG_UNBIND_INPUT, mCurMethod)); |
| 594 | } |
| 595 | } |
| 596 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 597 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 598 | mCurClient.sessionRequested = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 599 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | // Call setActive(false) on the old client |
| 601 | try { |
| 602 | mCurClient.client.setActive(false); |
| 603 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 604 | 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] | 605 | + mCurClient.pid + " uid " + mCurClient.uid); |
| 606 | } |
| 607 | mCurClient = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 608 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 609 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | } |
| 611 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | private int getImeShowFlags() { |
| 614 | int flags = 0; |
| 615 | if (mShowForced) { |
| 616 | flags |= InputMethod.SHOW_FORCED |
| 617 | | InputMethod.SHOW_EXPLICIT; |
| 618 | } else if (mShowExplicitlyRequested) { |
| 619 | flags |= InputMethod.SHOW_EXPLICIT; |
| 620 | } |
| 621 | return flags; |
| 622 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 623 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | private int getAppShowFlags() { |
| 625 | int flags = 0; |
| 626 | if (mShowForced) { |
| 627 | flags |= InputMethodManager.SHOW_FORCED; |
| 628 | } else if (!mShowExplicitlyRequested) { |
| 629 | flags |= InputMethodManager.SHOW_IMPLICIT; |
| 630 | } |
| 631 | return flags; |
| 632 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | InputBindResult attachNewInputLocked(boolean initial, boolean needResult) { |
| 635 | if (!mBoundToMethod) { |
| 636 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 637 | MSG_BIND_INPUT, mCurMethod, mCurClient.binding)); |
| 638 | mBoundToMethod = true; |
| 639 | } |
| 640 | final SessionState session = mCurClient.curSession; |
| 641 | if (initial) { |
| 642 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 643 | MSG_START_INPUT, session, mCurInputContext, mCurAttribute)); |
| 644 | } else { |
| 645 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 646 | MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute)); |
| 647 | } |
| 648 | if (mShowRequested) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 649 | 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] | 650 | showCurrentInputLocked(getAppShowFlags(), null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 651 | } |
| 652 | return needResult |
| 653 | ? new InputBindResult(session.session, mCurId, mCurSeq) |
| 654 | : null; |
| 655 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | InputBindResult startInputLocked(IInputMethodClient client, |
| 658 | IInputContext inputContext, EditorInfo attribute, |
| 659 | boolean initial, boolean needResult) { |
| 660 | // If no method is currently selected, do nothing. |
| 661 | if (mCurMethodId == null) { |
| 662 | return mNoBinding; |
| 663 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | ClientState cs = mClients.get(client.asBinder()); |
| 666 | if (cs == null) { |
| 667 | throw new IllegalArgumentException("unknown client " |
| 668 | + client.asBinder()); |
| 669 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 670 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | try { |
| 672 | if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) { |
| 673 | // Check with the window manager to make sure this client actually |
| 674 | // has a window with focus. If not, reject. This is thread safe |
| 675 | // because if the focus changes some time before or after, the |
| 676 | // next client receiving focus that has any interest in input will |
| 677 | // be calling through here after that change happens. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 678 | 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] | 679 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
| 680 | return null; |
| 681 | } |
| 682 | } catch (RemoteException e) { |
| 683 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | if (mCurClient != cs) { |
| 686 | // If the client is changing, we need to switch over to the new |
| 687 | // one. |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 688 | unbindCurrentClientLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 689 | if (DEBUG) Slog.v(TAG, "switching to client: client = " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | + cs.client.asBinder()); |
| 691 | |
| 692 | // If the screen is on, inform the new client it is active |
| 693 | if (mScreenOn) { |
| 694 | try { |
| 695 | cs.client.setActive(mScreenOn); |
| 696 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 697 | 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] | 698 | + cs.pid + " uid " + cs.uid); |
| 699 | } |
| 700 | } |
| 701 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | // Bump up the sequence for this client and attach it. |
| 704 | mCurSeq++; |
| 705 | if (mCurSeq <= 0) mCurSeq = 1; |
| 706 | mCurClient = cs; |
| 707 | mCurInputContext = inputContext; |
| 708 | mCurAttribute = attribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 709 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | // Check if the input method is changing. |
| 711 | if (mCurId != null && mCurId.equals(mCurMethodId)) { |
| 712 | if (cs.curSession != null) { |
| 713 | // Fast case: if we are already connected to the input method, |
| 714 | // then just return it. |
| 715 | return attachNewInputLocked(initial, needResult); |
| 716 | } |
| 717 | if (mHaveConnection) { |
| 718 | if (mCurMethod != null) { |
| 719 | if (!cs.sessionRequested) { |
| 720 | cs.sessionRequested = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 721 | 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] | 722 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 723 | MSG_CREATE_SESSION, mCurMethod, |
| 724 | new MethodCallback(mCurMethod))); |
| 725 | } |
| 726 | // Return to client, and we will get back with it when |
| 727 | // we have had a session made for it. |
| 728 | return new InputBindResult(null, mCurId, mCurSeq); |
| 729 | } else if (SystemClock.uptimeMillis() |
| 730 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 731 | // In this case we have connected to the service, but |
| 732 | // don't yet have its interface. If it hasn't been too |
| 733 | // long since we did the connection, we'll return to |
| 734 | // the client and wait to get the service interface so |
| 735 | // we can report back. If it has been too long, we want |
| 736 | // to fall through so we can try a disconnect/reconnect |
| 737 | // to see if we can get back in touch with the service. |
| 738 | return new InputBindResult(null, mCurId, mCurSeq); |
| 739 | } else { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 740 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, |
| 741 | mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 745 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 746 | return startInputInnerLocked(); |
| 747 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 748 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 749 | InputBindResult startInputInnerLocked() { |
| 750 | if (mCurMethodId == null) { |
| 751 | return mNoBinding; |
| 752 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 753 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 754 | if (!mSystemReady) { |
| 755 | // If the system is not yet ready, we shouldn't be running third |
| 756 | // party code. |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 757 | return new InputBindResult(null, mCurMethodId, mCurSeq); |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 758 | } |
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 | InputMethodInfo info = mMethodMap.get(mCurMethodId); |
| 761 | if (info == null) { |
| 762 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 763 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 764 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 765 | unbindCurrentMethodLocked(false); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 766 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 767 | mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE); |
| 768 | mCurIntent.setComponent(info.getComponent()); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 769 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 770 | com.android.internal.R.string.input_method_binding_label); |
| 771 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 772 | 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] | 773 | if (mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE)) { |
| 774 | mLastBindTime = SystemClock.uptimeMillis(); |
| 775 | mHaveConnection = true; |
| 776 | mCurId = info.getId(); |
| 777 | mCurToken = new Binder(); |
| 778 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 779 | if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | mIWindowManager.addWindowToken(mCurToken, |
| 781 | WindowManager.LayoutParams.TYPE_INPUT_METHOD); |
| 782 | } catch (RemoteException e) { |
| 783 | } |
| 784 | return new InputBindResult(null, mCurId, mCurSeq); |
| 785 | } else { |
| 786 | mCurIntent = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 787 | Slog.w(TAG, "Failure connecting to input method service: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | + mCurIntent); |
| 789 | } |
| 790 | return null; |
| 791 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | public InputBindResult startInput(IInputMethodClient client, |
| 794 | IInputContext inputContext, EditorInfo attribute, |
| 795 | boolean initial, boolean needResult) { |
| 796 | synchronized (mMethodMap) { |
| 797 | final long ident = Binder.clearCallingIdentity(); |
| 798 | try { |
| 799 | return startInputLocked(client, inputContext, attribute, |
| 800 | initial, needResult); |
| 801 | } finally { |
| 802 | Binder.restoreCallingIdentity(ident); |
| 803 | } |
| 804 | } |
| 805 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | public void finishInput(IInputMethodClient client) { |
| 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 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 811 | synchronized (mMethodMap) { |
| 812 | if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { |
| 813 | mCurMethod = IInputMethod.Stub.asInterface(service); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 814 | if (mCurToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 815 | Slog.w(TAG, "Service connected without a token!"); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 816 | unbindCurrentMethodLocked(false); |
| 817 | return; |
| 818 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 819 | if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 820 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 821 | MSG_ATTACH_TOKEN, mCurMethod, mCurToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 822 | if (mCurClient != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 823 | if (DEBUG) Slog.v(TAG, "Creating first session while with client " |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 824 | + mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 826 | MSG_CREATE_SESSION, mCurMethod, |
| 827 | new MethodCallback(mCurMethod))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | void onSessionCreated(IInputMethod method, IInputMethodSession session) { |
| 834 | synchronized (mMethodMap) { |
| 835 | if (mCurMethod != null && method != null |
| 836 | && mCurMethod.asBinder() == method.asBinder()) { |
| 837 | if (mCurClient != null) { |
| 838 | mCurClient.curSession = new SessionState(mCurClient, |
| 839 | method, session); |
| 840 | mCurClient.sessionRequested = false; |
| 841 | InputBindResult res = attachNewInputLocked(true, true); |
| 842 | if (res.method != null) { |
| 843 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
| 844 | MSG_BIND_METHOD, mCurClient.client, res)); |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 850 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 851 | void unbindCurrentMethodLocked(boolean reportToClient) { |
| 852 | if (mHaveConnection) { |
| 853 | mContext.unbindService(this); |
| 854 | mHaveConnection = false; |
| 855 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 856 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 857 | if (mCurToken != null) { |
| 858 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 859 | if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 860 | mIWindowManager.removeWindowToken(mCurToken); |
| 861 | } catch (RemoteException e) { |
| 862 | } |
| 863 | mCurToken = null; |
| 864 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 865 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 866 | mCurId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 867 | clearCurMethodLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 868 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 869 | if (reportToClient && mCurClient != null) { |
| 870 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 871 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 872 | } |
| 873 | } |
| 874 | |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 875 | private void finishSession(SessionState sessionState) { |
| 876 | if (sessionState != null && sessionState.session != null) { |
| 877 | try { |
| 878 | sessionState.session.finishSession(); |
| 879 | } catch (RemoteException e) { |
Jean-Baptiste Queru | 9d0f6df | 2010-03-29 12:55:09 -0700 | [diff] [blame] | 880 | Slog.w(TAG, "Session failed to close due to remote exception", e); |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 884 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 885 | void clearCurMethodLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | if (mCurMethod != null) { |
| 887 | for (ClientState cs : mClients.values()) { |
| 888 | cs.sessionRequested = false; |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 889 | finishSession(cs.curSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | cs.curSession = null; |
| 891 | } |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 892 | |
| 893 | finishSession(mEnabledSession); |
| 894 | mEnabledSession = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | mCurMethod = null; |
| 896 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 897 | mStatusBar.setIconVisibility("ime", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 898 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 899 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | public void onServiceDisconnected(ComponentName name) { |
| 901 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 902 | if (DEBUG) Slog.v(TAG, "Service disconnected: " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | + " mCurIntent=" + mCurIntent); |
| 904 | if (mCurMethod != null && mCurIntent != null |
| 905 | && name.equals(mCurIntent.getComponent())) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 906 | clearCurMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | // We consider this to be a new bind attempt, since the system |
| 908 | // should now try to restart the service for us. |
| 909 | mLastBindTime = SystemClock.uptimeMillis(); |
| 910 | mShowRequested = mInputShown; |
| 911 | mInputShown = false; |
| 912 | if (mCurClient != null) { |
| 913 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 914 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 915 | } |
| 916 | } |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | public void updateStatusIcon(IBinder token, String packageName, int iconId) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 921 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | long ident = Binder.clearCallingIdentity(); |
| 923 | try { |
| 924 | if (token == null || mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 925 | 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] | 926 | return; |
| 927 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 928 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | synchronized (mMethodMap) { |
| 930 | if (iconId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 931 | 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] | 932 | mStatusBar.setIconVisibility("ime", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | } else if (packageName != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 934 | 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] | 935 | mStatusBar.setIcon("ime", packageName, iconId, 0); |
| 936 | mStatusBar.setIconVisibility("ime", true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | } finally { |
| 940 | Binder.restoreCallingIdentity(ident); |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | void updateFromSettingsLocked() { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 945 | // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and |
| 946 | // ENABLED_INPUT_METHODS is taking care of keeping them correctly in |
| 947 | // sync, so we will never have a DEFAULT_INPUT_METHOD that is not |
| 948 | // enabled. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | String id = Settings.Secure.getString(mContext.getContentResolver(), |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 950 | Settings.Secure.DEFAULT_INPUT_METHOD); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 951 | if (id != null && id.length() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 952 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 953 | setInputMethodLocked(id, getSelectedInputMethodSubtypeId(id)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 954 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 955 | 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] | 956 | mCurMethodId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 957 | unbindCurrentMethodLocked(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 958 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 959 | } else { |
| 960 | // 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] | 961 | mCurMethodId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 962 | unbindCurrentMethodLocked(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 963 | } |
| 964 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 965 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 966 | /* package */ void setInputMethodLocked(String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | InputMethodInfo info = mMethodMap.get(id); |
| 968 | if (info == null) { |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 969 | throw new IllegalArgumentException("Unknown id: " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 971 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | if (id.equals(mCurMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 973 | if (subtypeId != NOT_A_SUBTYPE_ID) { |
| 974 | InputMethodSubtype subtype = info.getSubtypes().get(subtypeId); |
| 975 | if (subtype != mCurrentSubtype) { |
| 976 | synchronized (mMethodMap) { |
| 977 | if (mCurMethod != null) { |
| 978 | try { |
| 979 | putSelectedInputMethodSubtype(info, subtypeId); |
| 980 | mCurMethod.changeInputMethodSubtype(subtype); |
| 981 | } catch (RemoteException e) { |
| 982 | return; |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | return; |
| 989 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 990 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | final long ident = Binder.clearCallingIdentity(); |
| 992 | try { |
| 993 | mCurMethodId = id; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 994 | // Set a subtype to this input method. |
| 995 | // subtypeId the name of a subtype which will be set. |
| 996 | if (putSelectedInputMethodSubtype(info, subtypeId)) { |
| 997 | mCurrentSubtype = info.getSubtypes().get(subtypeId); |
| 998 | } else { |
| 999 | mCurrentSubtype = null; |
| 1000 | } |
| 1001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | Settings.Secure.putString(mContext.getContentResolver(), |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1003 | Settings.Secure.DEFAULT_INPUT_METHOD, id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | |
| 1005 | if (ActivityManagerNative.isSystemReady()) { |
| 1006 | Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 1007 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | intent.putExtra("input_method_id", id); |
| 1009 | mContext.sendBroadcast(intent); |
| 1010 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1011 | unbindCurrentClientLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | } finally { |
| 1013 | Binder.restoreCallingIdentity(ident); |
| 1014 | } |
| 1015 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1016 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1017 | public boolean showSoftInput(IInputMethodClient client, int flags, |
| 1018 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1019 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1020 | long ident = Binder.clearCallingIdentity(); |
| 1021 | try { |
| 1022 | synchronized (mMethodMap) { |
| 1023 | if (mCurClient == null || client == null |
| 1024 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1025 | try { |
| 1026 | // We need to check if this is the current client with |
| 1027 | // focus in the window manager, to allow this call to |
| 1028 | // be made before input is started in it. |
| 1029 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1030 | Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1031 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1032 | } |
| 1033 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1034 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | } |
| 1036 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1037 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1038 | 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] | 1039 | return showCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | } |
| 1041 | } finally { |
| 1042 | Binder.restoreCallingIdentity(ident); |
| 1043 | } |
| 1044 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1045 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1046 | boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | mShowRequested = true; |
| 1048 | if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) { |
| 1049 | mShowExplicitlyRequested = true; |
| 1050 | } |
| 1051 | if ((flags&InputMethodManager.SHOW_FORCED) != 0) { |
| 1052 | mShowExplicitlyRequested = true; |
| 1053 | mShowForced = true; |
| 1054 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1055 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1056 | if (!mSystemReady) { |
| 1057 | return false; |
| 1058 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1059 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1060 | boolean res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1061 | if (mCurMethod != null) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1062 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 1063 | MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod, |
| 1064 | resultReceiver)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1065 | mInputShown = true; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1066 | res = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | } else if (mHaveConnection && SystemClock.uptimeMillis() |
| 1068 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 1069 | // The client has asked to have the input method shown, but |
| 1070 | // we have been sitting here too long with a connection to the |
| 1071 | // service and no interface received, so let's disconnect/connect |
| 1072 | // to try to prod things along. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1073 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | SystemClock.uptimeMillis()-mLastBindTime,1); |
| 1075 | mContext.unbindService(this); |
| 1076 | mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE); |
| 1077 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1078 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1079 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1080 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1081 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1082 | public boolean hideSoftInput(IInputMethodClient client, int flags, |
| 1083 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1084 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1085 | long ident = Binder.clearCallingIdentity(); |
| 1086 | try { |
| 1087 | synchronized (mMethodMap) { |
| 1088 | if (mCurClient == null || client == null |
| 1089 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1090 | try { |
| 1091 | // We need to check if this is the current client with |
| 1092 | // focus in the window manager, to allow this call to |
| 1093 | // be made before input is started in it. |
| 1094 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1095 | if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid " |
| 1096 | + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1097 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | } |
| 1099 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1100 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | } |
| 1102 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1103 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1104 | 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] | 1105 | return hideCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | } |
| 1107 | } finally { |
| 1108 | Binder.restoreCallingIdentity(ident); |
| 1109 | } |
| 1110 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1111 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1112 | boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1113 | if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0 |
| 1114 | && (mShowExplicitlyRequested || mShowForced)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1115 | if (DEBUG) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | "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] | 1117 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | } |
| 1119 | if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1120 | if (DEBUG) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | "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] | 1122 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1124 | boolean res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1125 | if (mInputShown && mCurMethod != null) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1126 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 1127 | MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver)); |
| 1128 | res = true; |
| 1129 | } else { |
| 1130 | res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1131 | } |
| 1132 | mInputShown = false; |
| 1133 | mShowRequested = false; |
| 1134 | mShowExplicitlyRequested = false; |
| 1135 | mShowForced = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1136 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1137 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1138 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1139 | public void windowGainedFocus(IInputMethodClient client, IBinder windowToken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | boolean viewHasFocus, boolean isTextEditor, int softInputMode, |
| 1141 | boolean first, int windowFlags) { |
| 1142 | long ident = Binder.clearCallingIdentity(); |
| 1143 | try { |
| 1144 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1145 | if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1146 | + " viewHasFocus=" + viewHasFocus |
| 1147 | + " isTextEditor=" + isTextEditor |
| 1148 | + " softInputMode=#" + Integer.toHexString(softInputMode) |
| 1149 | + " first=" + first + " flags=#" |
| 1150 | + Integer.toHexString(windowFlags)); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1151 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1159 | 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] | 1160 | return; |
| 1161 | } |
| 1162 | } catch (RemoteException e) { |
| 1163 | } |
| 1164 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1165 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1166 | if (mCurFocusedWindow == windowToken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1167 | 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] | 1168 | return; |
| 1169 | } |
| 1170 | mCurFocusedWindow = windowToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) { |
| 1173 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: |
| 1174 | if (!isTextEditor || (softInputMode & |
| 1175 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 1176 | != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) { |
| 1177 | if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) { |
| 1178 | // There is no focus view, and this window will |
| 1179 | // be behind any soft input window, so hide the |
| 1180 | // soft input window if it is shown. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1181 | 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] | 1182 | hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1183 | } |
| 1184 | } else if (isTextEditor && (softInputMode & |
| 1185 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 1186 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
| 1187 | && (softInputMode & |
| 1188 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
| 1189 | // There is a focus view, and we are navigating forward |
| 1190 | // into the window, so show the input window for the user. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1191 | 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] | 1192 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1193 | } |
| 1194 | break; |
| 1195 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED: |
| 1196 | // Do nothing. |
| 1197 | break; |
| 1198 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN: |
| 1199 | if ((softInputMode & |
| 1200 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1201 | 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] | 1202 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1203 | } |
| 1204 | break; |
| 1205 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1206 | 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] | 1207 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1208 | break; |
| 1209 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE: |
| 1210 | if ((softInputMode & |
| 1211 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1212 | 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] | 1213 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1214 | } |
| 1215 | break; |
| 1216 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1217 | 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] | 1218 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | break; |
| 1220 | } |
| 1221 | } |
| 1222 | } finally { |
| 1223 | Binder.restoreCallingIdentity(ident); |
| 1224 | } |
| 1225 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | public void showInputMethodPickerFromClient(IInputMethodClient client) { |
| 1228 | synchronized (mMethodMap) { |
| 1229 | if (mCurClient == null || client == null |
| 1230 | || mCurClient.client.asBinder() != client.asBinder()) { |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1231 | Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid " |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1232 | + Binder.getCallingUid() + ": " + client); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | mHandler.sendEmptyMessage(MSG_SHOW_IM_PICKER); |
| 1236 | } |
| 1237 | } |
| 1238 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1239 | public void showInputMethodSubtypePickerFromClient(IInputMethodClient client) { |
| 1240 | synchronized (mMethodMap) { |
| 1241 | if (mCurClient == null || client == null |
| 1242 | || mCurClient.client.asBinder() != client.asBinder()) { |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1243 | Slog.w(TAG, "Ignoring showInputMethodSubtypePickerFromClient of: " + client); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER); |
| 1247 | } |
| 1248 | } |
| 1249 | |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1250 | public void showInputMethodAndSubtypeEnablerFromClient( |
| 1251 | IInputMethodClient client, String topId) { |
| 1252 | // TODO: Handle topId for setting the top position of the list activity |
| 1253 | synchronized (mMethodMap) { |
| 1254 | if (mCurClient == null || client == null |
| 1255 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1256 | Slog.w(TAG, "Ignoring showInputMethodAndSubtypeEnablerFromClient of: " + client); |
| 1257 | } |
| 1258 | |
| 1259 | mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_ENABLER); |
| 1260 | } |
| 1261 | } |
| 1262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1263 | public void setInputMethod(IBinder token, String id) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1264 | setInputMethodWithSubtype(token, id, NOT_A_SUBTYPE_ID); |
| 1265 | } |
| 1266 | |
| 1267 | private void setInputMethodWithSubtype(IBinder token, String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | synchronized (mMethodMap) { |
| 1269 | if (token == null) { |
| 1270 | if (mContext.checkCallingOrSelfPermission( |
| 1271 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 1272 | != PackageManager.PERMISSION_GRANTED) { |
| 1273 | throw new SecurityException( |
| 1274 | "Using null token requires permission " |
| 1275 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 1276 | } |
| 1277 | } else if (mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1278 | Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid() |
| 1279 | + " token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1280 | return; |
| 1281 | } |
| 1282 | |
| 1283 | long ident = Binder.clearCallingIdentity(); |
| 1284 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1285 | setInputMethodLocked(id, subtypeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1286 | } finally { |
| 1287 | Binder.restoreCallingIdentity(ident); |
| 1288 | } |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | public void hideMySoftInput(IBinder token, int flags) { |
| 1293 | synchronized (mMethodMap) { |
| 1294 | if (token == null || mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1295 | if (DEBUG) Slog.w(TAG, "Ignoring hideInputMethod of uid " |
| 1296 | + Binder.getCallingUid() + " token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | return; |
| 1298 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | long ident = Binder.clearCallingIdentity(); |
| 1300 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1301 | hideCurrentInputLocked(flags, null); |
| 1302 | } finally { |
| 1303 | Binder.restoreCallingIdentity(ident); |
| 1304 | } |
| 1305 | } |
| 1306 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1307 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1308 | public void showMySoftInput(IBinder token, int flags) { |
| 1309 | synchronized (mMethodMap) { |
| 1310 | if (token == null || mCurToken != token) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 1311 | Slog.w(TAG, "Ignoring showMySoftInput of uid " |
| 1312 | + Binder.getCallingUid() + " token: " + token); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1313 | return; |
| 1314 | } |
| 1315 | long ident = Binder.clearCallingIdentity(); |
| 1316 | try { |
| 1317 | showCurrentInputLocked(flags, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | } finally { |
| 1319 | Binder.restoreCallingIdentity(ident); |
| 1320 | } |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | void setEnabledSessionInMainThread(SessionState session) { |
| 1325 | if (mEnabledSession != session) { |
| 1326 | if (mEnabledSession != null) { |
| 1327 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1328 | if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1329 | mEnabledSession.method.setSessionEnabled( |
| 1330 | mEnabledSession.session, false); |
| 1331 | } catch (RemoteException e) { |
| 1332 | } |
| 1333 | } |
| 1334 | mEnabledSession = session; |
| 1335 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1336 | if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1337 | session.method.setSessionEnabled( |
| 1338 | session.session, true); |
| 1339 | } catch (RemoteException e) { |
| 1340 | } |
| 1341 | } |
| 1342 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1344 | public boolean handleMessage(Message msg) { |
| 1345 | HandlerCaller.SomeArgs args; |
| 1346 | switch (msg.what) { |
| 1347 | case MSG_SHOW_IM_PICKER: |
| 1348 | showInputMethodMenu(); |
| 1349 | return true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1350 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1351 | case MSG_SHOW_IM_SUBTYPE_PICKER: |
| 1352 | showInputMethodSubtypeMenu(); |
| 1353 | return true; |
| 1354 | |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1355 | case MSG_SHOW_IM_SUBTYPE_ENABLER: |
| 1356 | showInputMethodAndSubtypeEnabler(); |
| 1357 | return true; |
| 1358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1359 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1360 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1361 | case MSG_UNBIND_INPUT: |
| 1362 | try { |
| 1363 | ((IInputMethod)msg.obj).unbindInput(); |
| 1364 | } catch (RemoteException e) { |
| 1365 | // There is nothing interesting about the method dying. |
| 1366 | } |
| 1367 | return true; |
| 1368 | case MSG_BIND_INPUT: |
| 1369 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1370 | try { |
| 1371 | ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2); |
| 1372 | } catch (RemoteException e) { |
| 1373 | } |
| 1374 | return true; |
| 1375 | case MSG_SHOW_SOFT_INPUT: |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1376 | args = (HandlerCaller.SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1378 | ((IInputMethod)args.arg1).showSoftInput(msg.arg1, |
| 1379 | (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1380 | } catch (RemoteException e) { |
| 1381 | } |
| 1382 | return true; |
| 1383 | case MSG_HIDE_SOFT_INPUT: |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1384 | args = (HandlerCaller.SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1386 | ((IInputMethod)args.arg1).hideSoftInput(0, |
| 1387 | (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1388 | } catch (RemoteException e) { |
| 1389 | } |
| 1390 | return true; |
| 1391 | case MSG_ATTACH_TOKEN: |
| 1392 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1393 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1394 | 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] | 1395 | ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2); |
| 1396 | } catch (RemoteException e) { |
| 1397 | } |
| 1398 | return true; |
| 1399 | case MSG_CREATE_SESSION: |
| 1400 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1401 | try { |
| 1402 | ((IInputMethod)args.arg1).createSession( |
| 1403 | (IInputMethodCallback)args.arg2); |
| 1404 | } catch (RemoteException e) { |
| 1405 | } |
| 1406 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1407 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1409 | case MSG_START_INPUT: |
| 1410 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1411 | try { |
| 1412 | SessionState session = (SessionState)args.arg1; |
| 1413 | setEnabledSessionInMainThread(session); |
| 1414 | session.method.startInput((IInputContext)args.arg2, |
| 1415 | (EditorInfo)args.arg3); |
| 1416 | } catch (RemoteException e) { |
| 1417 | } |
| 1418 | return true; |
| 1419 | case MSG_RESTART_INPUT: |
| 1420 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1421 | try { |
| 1422 | SessionState session = (SessionState)args.arg1; |
| 1423 | setEnabledSessionInMainThread(session); |
| 1424 | session.method.restartInput((IInputContext)args.arg2, |
| 1425 | (EditorInfo)args.arg3); |
| 1426 | } catch (RemoteException e) { |
| 1427 | } |
| 1428 | return true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1429 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1430 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | case MSG_UNBIND_METHOD: |
| 1433 | try { |
| 1434 | ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1); |
| 1435 | } catch (RemoteException e) { |
| 1436 | // There is nothing interesting about the last client dying. |
| 1437 | } |
| 1438 | return true; |
| 1439 | case MSG_BIND_METHOD: |
| 1440 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1441 | try { |
| 1442 | ((IInputMethodClient)args.arg1).onBindMethod( |
| 1443 | (InputBindResult)args.arg2); |
| 1444 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1445 | 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] | 1446 | } |
| 1447 | return true; |
| 1448 | } |
| 1449 | return false; |
| 1450 | } |
| 1451 | |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1452 | private boolean isSystemIme(InputMethodInfo inputMethod) { |
| 1453 | return (inputMethod.getServiceInfo().applicationInfo.flags |
| 1454 | & ApplicationInfo.FLAG_SYSTEM) != 0; |
| 1455 | } |
| 1456 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1457 | private boolean chooseNewDefaultIMELocked() { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1458 | List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1459 | if (enabled != null && enabled.size() > 0) { |
Dianne Hackborn | 83e48f5 | 2010-03-23 23:03:25 -0700 | [diff] [blame] | 1460 | // We'd prefer to fall back on a system IME, since that is safer. |
| 1461 | int i=enabled.size(); |
| 1462 | while (i > 0) { |
| 1463 | i--; |
| 1464 | if ((enabled.get(i).getServiceInfo().applicationInfo.flags |
| 1465 | & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 1466 | break; |
| 1467 | } |
| 1468 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1469 | InputMethodInfo imi = enabled.get(i); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1470 | Settings.Secure.putString(mContext.getContentResolver(), |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1471 | Settings.Secure.DEFAULT_INPUT_METHOD, imi.getId()); |
| 1472 | putSelectedInputMethodSubtype(imi, NOT_A_SUBTYPE_ID); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1473 | return true; |
| 1474 | } |
| 1475 | |
| 1476 | return false; |
| 1477 | } |
| 1478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | void buildInputMethodListLocked(ArrayList<InputMethodInfo> list, |
| 1480 | HashMap<String, InputMethodInfo> map) { |
| 1481 | list.clear(); |
| 1482 | map.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1483 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1484 | PackageManager pm = mContext.getPackageManager(); |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1485 | final Configuration config = mContext.getResources().getConfiguration(); |
| 1486 | final boolean haveHardKeyboard = config.keyboard == Configuration.KEYBOARD_QWERTY; |
| 1487 | String disabledSysImes = Settings.Secure.getString(mContext.getContentResolver(), |
| 1488 | Secure.DISABLED_SYSTEM_INPUT_METHODS); |
| 1489 | if (disabledSysImes == null) disabledSysImes = ""; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1490 | |
| 1491 | List<ResolveInfo> services = pm.queryIntentServices( |
| 1492 | new Intent(InputMethod.SERVICE_INTERFACE), |
| 1493 | PackageManager.GET_META_DATA); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | for (int i = 0; i < services.size(); ++i) { |
| 1496 | ResolveInfo ri = services.get(i); |
| 1497 | ServiceInfo si = ri.serviceInfo; |
| 1498 | ComponentName compName = new ComponentName(si.packageName, si.name); |
| 1499 | if (!android.Manifest.permission.BIND_INPUT_METHOD.equals( |
| 1500 | si.permission)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1501 | Slog.w(TAG, "Skipping input method " + compName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | + ": it does not require the permission " |
| 1503 | + android.Manifest.permission.BIND_INPUT_METHOD); |
| 1504 | continue; |
| 1505 | } |
| 1506 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1507 | if (DEBUG) Slog.d(TAG, "Checking " + compName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1508 | |
| 1509 | try { |
| 1510 | InputMethodInfo p = new InputMethodInfo(mContext, ri); |
| 1511 | list.add(p); |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1512 | final String id = p.getId(); |
| 1513 | map.put(id, p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1514 | |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1515 | // System IMEs are enabled by default, unless there's a hard keyboard |
| 1516 | // and the system IME was explicitly disabled |
| 1517 | if (isSystemIme(p) && (!haveHardKeyboard || disabledSysImes.indexOf(id) < 0)) { |
| 1518 | setInputMethodEnabledLocked(id, true); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1521 | if (DEBUG) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1522 | 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] | 1523 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1524 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1525 | } catch (XmlPullParserException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1526 | 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] | 1527 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1528 | 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] | 1529 | } |
| 1530 | } |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1531 | |
| 1532 | String defaultIme = Settings.Secure.getString(mContext |
| 1533 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1534 | if (!TextUtils.isEmpty(defaultIme) && !map.containsKey(defaultIme)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1535 | if (chooseNewDefaultIMELocked()) { |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1536 | updateFromSettingsLocked(); |
| 1537 | } |
| 1538 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1539 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1540 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1542 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1543 | private void showInputMethodMenu() { |
| 1544 | showInputMethodMenuInternal(false); |
| 1545 | } |
| 1546 | |
| 1547 | private void showInputMethodSubtypeMenu() { |
| 1548 | showInputMethodMenuInternal(true); |
| 1549 | } |
| 1550 | |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 1551 | private void showInputMethodAndSubtypeEnabler() { |
| 1552 | Intent intent = new Intent(); |
| 1553 | intent.setClassName("android", InputMethodAndSubtypeEnabler.class.getCanonicalName()); |
| 1554 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 1555 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 1556 | mContext.startActivity(intent); |
| 1557 | } |
| 1558 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1559 | private void showInputMethodMenuInternal(boolean showSubtypes) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1560 | if (DEBUG) Slog.v(TAG, "Show switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1562 | final Context context = mContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | final PackageManager pm = context.getPackageManager(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | String lastInputMethodId = Settings.Secure.getString(context |
| 1567 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1568 | int lastInputMethodSubtypeId = getSelectedInputMethodSubtypeId(lastInputMethodId); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1569 | if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1570 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1571 | synchronized (mMethodMap) { |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame^] | 1572 | final List<Pair<InputMethodInfo, ArrayList<String>>> immis = |
| 1573 | mSettings.getEnabledInputMethodAndSubtypeListLocked(); |
| 1574 | ArrayList<Integer> subtypeIds = new ArrayList<Integer>(); |
| 1575 | |
| 1576 | if (immis == null || immis.size() == 0) { |
| 1577 | return; |
| 1578 | } |
| 1579 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1580 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1581 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1582 | int N = immis.size(); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1583 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1584 | final Map<CharSequence, Pair<InputMethodInfo, Integer>> imMap = |
| 1585 | new TreeMap<CharSequence, Pair<InputMethodInfo, Integer>>(Collator.getInstance()); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1586 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1587 | for (int i = 0; i < N; ++i) { |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame^] | 1588 | InputMethodInfo property = immis.get(i).first; |
| 1589 | final ArrayList<String> enabledSubtypeIds = immis.get(i).second; |
| 1590 | HashSet<String> enabledSubtypeSet = new HashSet<String>(); |
| 1591 | for (String s : enabledSubtypeIds) { |
| 1592 | enabledSubtypeSet.add(s); |
| 1593 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1594 | if (property == null) { |
| 1595 | continue; |
| 1596 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1597 | ArrayList<InputMethodSubtype> subtypes = property.getSubtypes(); |
| 1598 | CharSequence label = property.loadLabel(pm); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame^] | 1599 | if (showSubtypes && enabledSubtypeSet.size() > 0) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1600 | for (int j = 0; j < subtypes.size(); ++j) { |
| 1601 | InputMethodSubtype subtype = subtypes.get(j); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame^] | 1602 | if (enabledSubtypeSet.contains(String.valueOf(subtype.hashCode()))) { |
| 1603 | CharSequence title; |
| 1604 | int nameResId = subtype.getNameResId(); |
| 1605 | int modeResId = subtype.getModeResId(); |
| 1606 | if (nameResId != 0) { |
| 1607 | title = pm.getText(property.getPackageName(), nameResId, |
| 1608 | property.getServiceInfo().applicationInfo); |
| 1609 | } else { |
| 1610 | CharSequence language = subtype.getLocale(); |
| 1611 | CharSequence mode = modeResId == 0 ? null |
| 1612 | : pm.getText(property.getPackageName(), modeResId, |
| 1613 | property.getServiceInfo().applicationInfo); |
| 1614 | // TODO: Use more friendly Title and UI |
| 1615 | title = label + "," + (mode == null ? "" : mode) + "," |
| 1616 | + (language == null ? "" : language); |
| 1617 | } |
| 1618 | imMap.put(title, new Pair<InputMethodInfo, Integer>(property, j)); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1619 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1620 | } |
| 1621 | } else { |
| 1622 | imMap.put(label, |
| 1623 | new Pair<InputMethodInfo, Integer>(property, NOT_A_SUBTYPE_ID)); |
| 1624 | subtypeIds.add(0); |
| 1625 | } |
Dianne Hackborn | 97106ab | 2010-03-03 00:08:31 -0800 | [diff] [blame] | 1626 | } |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1627 | |
| 1628 | N = imMap.size(); |
| 1629 | mItems = imMap.keySet().toArray(new CharSequence[N]); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1630 | mIms = new InputMethodInfo[N]; |
| 1631 | mSubtypeIds = new int[N]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1632 | int checkedItem = 0; |
| 1633 | for (int i = 0; i < N; ++i) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1634 | Pair<InputMethodInfo, Integer> value = imMap.get(mItems[i]); |
| 1635 | mIms[i] = value.first; |
| 1636 | mSubtypeIds[i] = value.second; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1637 | if (mIms[i].getId().equals(lastInputMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1638 | int subtypeId = mSubtypeIds[i]; |
| 1639 | if ((subtypeId == NOT_A_SUBTYPE_ID) |
| 1640 | || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) |
| 1641 | || (subtypeId == lastInputMethodSubtypeId)) { |
| 1642 | checkedItem = i; |
| 1643 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1644 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1646 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1647 | AlertDialog.OnClickListener adocl = new AlertDialog.OnClickListener() { |
| 1648 | public void onClick(DialogInterface dialog, int which) { |
| 1649 | hideInputMethodMenu(); |
| 1650 | } |
| 1651 | }; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1652 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1653 | TypedArray a = context.obtainStyledAttributes(null, |
| 1654 | com.android.internal.R.styleable.DialogPreference, |
| 1655 | com.android.internal.R.attr.alertDialogStyle, 0); |
| 1656 | mDialogBuilder = new AlertDialog.Builder(context) |
| 1657 | .setTitle(com.android.internal.R.string.select_input_method) |
| 1658 | .setOnCancelListener(new OnCancelListener() { |
| 1659 | public void onCancel(DialogInterface dialog) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1660 | hideInputMethodMenu(); |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1661 | } |
| 1662 | }) |
| 1663 | .setIcon(a.getDrawable( |
| 1664 | com.android.internal.R.styleable.DialogPreference_dialogTitle)); |
| 1665 | a.recycle(); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1666 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1667 | mDialogBuilder.setSingleChoiceItems(mItems, checkedItem, |
| 1668 | new AlertDialog.OnClickListener() { |
| 1669 | public void onClick(DialogInterface dialog, int which) { |
| 1670 | synchronized (mMethodMap) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1671 | if (mIms == null || mIms.length <= which |
| 1672 | || mSubtypeIds == null || mSubtypeIds.length <= which) { |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1673 | return; |
| 1674 | } |
| 1675 | InputMethodInfo im = mIms[which]; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1676 | int subtypeId = mSubtypeIds[which]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1677 | hideInputMethodMenu(); |
| 1678 | if (im != null) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1679 | if ((subtypeId < 0) |
| 1680 | || (subtypeId >= im.getSubtypes().size())) { |
| 1681 | subtypeId = NOT_A_SUBTYPE_ID; |
| 1682 | } |
| 1683 | setInputMethodLocked(im.getId(), subtypeId); |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1684 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 1685 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1687 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1688 | |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame^] | 1689 | if (showSubtypes) { |
| 1690 | mDialogBuilder.setPositiveButton(com.android.internal.R.string.more_item_label, |
| 1691 | new DialogInterface.OnClickListener() { |
| 1692 | public void onClick(DialogInterface dialog, int whichButton) { |
| 1693 | showInputMethodAndSubtypeEnabler(); |
| 1694 | } |
| 1695 | }); |
| 1696 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1697 | mSwitchingDialog = mDialogBuilder.create(); |
| 1698 | mSwitchingDialog.getWindow().setType( |
| 1699 | WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG); |
| 1700 | mSwitchingDialog.show(); |
| 1701 | } |
| 1702 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1703 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1704 | void hideInputMethodMenu() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1705 | synchronized (mMethodMap) { |
| 1706 | hideInputMethodMenuLocked(); |
| 1707 | } |
| 1708 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1709 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1710 | void hideInputMethodMenuLocked() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1711 | if (DEBUG) Slog.v(TAG, "Hide switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1712 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1713 | if (mSwitchingDialog != null) { |
| 1714 | mSwitchingDialog.dismiss(); |
| 1715 | mSwitchingDialog = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1717 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1718 | mDialogBuilder = null; |
| 1719 | mItems = null; |
| 1720 | mIms = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1721 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1725 | public boolean setInputMethodEnabled(String id, boolean enabled) { |
| 1726 | synchronized (mMethodMap) { |
| 1727 | if (mContext.checkCallingOrSelfPermission( |
| 1728 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 1729 | != PackageManager.PERMISSION_GRANTED) { |
| 1730 | throw new SecurityException( |
| 1731 | "Requires permission " |
| 1732 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 1733 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1735 | long ident = Binder.clearCallingIdentity(); |
| 1736 | try { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1737 | return setInputMethodEnabledLocked(id, enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1738 | } finally { |
| 1739 | Binder.restoreCallingIdentity(ident); |
| 1740 | } |
| 1741 | } |
| 1742 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1743 | |
| 1744 | boolean setInputMethodEnabledLocked(String id, boolean enabled) { |
| 1745 | // Make sure this is a valid input method. |
| 1746 | InputMethodInfo imm = mMethodMap.get(id); |
| 1747 | if (imm == null) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1748 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1749 | } |
| 1750 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1751 | List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings |
| 1752 | .getEnabledInputMethodsAndSubtypeListLocked(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1753 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1754 | if (enabled) { |
| 1755 | for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) { |
| 1756 | if (pair.first.equals(id)) { |
| 1757 | // We are enabling this input method, but it is already enabled. |
| 1758 | // Nothing to do. The previous state was enabled. |
| 1759 | return true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1760 | } |
| 1761 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1762 | mSettings.appendAndPutEnabledInputMethodLocked(id, false); |
| 1763 | // Previous state was disabled. |
| 1764 | return false; |
| 1765 | } else { |
| 1766 | StringBuilder builder = new StringBuilder(); |
| 1767 | if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 1768 | builder, enabledInputMethodsList, id)) { |
| 1769 | // Disabled input method is currently selected, switch to another one. |
| 1770 | String selId = Settings.Secure.getString(mContext.getContentResolver(), |
| 1771 | Settings.Secure.DEFAULT_INPUT_METHOD); |
| 1772 | if (id.equals(selId)) { |
| 1773 | Settings.Secure.putString( |
| 1774 | mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD, |
| 1775 | enabledInputMethodsList.size() > 0 |
| 1776 | ? enabledInputMethodsList.get(0).first : ""); |
| 1777 | resetSelectedInputMethodSubtype(); |
| 1778 | } |
| 1779 | // Previous state was enabled. |
| 1780 | return true; |
| 1781 | } else { |
| 1782 | // We are disabling the input method but it is already disabled. |
| 1783 | // Nothing to do. The previous state was disabled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1784 | return false; |
| 1785 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1786 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1787 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1788 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1789 | private void resetSelectedInputMethodSubtype() { |
| 1790 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 1791 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, NOT_A_SUBTYPE_ID); |
| 1792 | } |
| 1793 | |
| 1794 | private boolean putSelectedInputMethodSubtype(InputMethodInfo imi, int subtypeId) { |
| 1795 | ArrayList<InputMethodSubtype> subtypes = imi.getSubtypes(); |
| 1796 | if (subtypeId >= 0 && subtypeId < subtypes.size()) { |
| 1797 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 1798 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, |
| 1799 | subtypes.get(subtypeId).hashCode()); |
| 1800 | return true; |
| 1801 | } else { |
| 1802 | resetSelectedInputMethodSubtype(); |
| 1803 | return false; |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | private int getSelectedInputMethodSubtypeId(String id) { |
| 1808 | InputMethodInfo imi = mMethodMap.get(id); |
| 1809 | if (imi == null) { |
| 1810 | return NOT_A_SUBTYPE_ID; |
| 1811 | } |
| 1812 | ArrayList<InputMethodSubtype> subtypes = imi.getSubtypes(); |
| 1813 | int subtypeId; |
| 1814 | try { |
| 1815 | subtypeId = Settings.Secure.getInt(mContext.getContentResolver(), |
| 1816 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE); |
| 1817 | } catch (SettingNotFoundException e) { |
| 1818 | return NOT_A_SUBTYPE_ID; |
| 1819 | } |
| 1820 | for (int i = 0; i < subtypes.size(); ++i) { |
| 1821 | InputMethodSubtype ims = subtypes.get(i); |
| 1822 | if (subtypeId == ims.hashCode()) { |
| 1823 | return i; |
| 1824 | } |
| 1825 | } |
| 1826 | return NOT_A_SUBTYPE_ID; |
| 1827 | } |
| 1828 | |
| 1829 | /** |
| 1830 | * @return Return the current subtype of this input method. |
| 1831 | */ |
| 1832 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
| 1833 | return mCurrentSubtype; |
| 1834 | } |
| 1835 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1836 | /** |
| 1837 | * Utility class for putting and getting settings for InputMethod |
| 1838 | * TODO: Move all putters and getters of settings to this class. |
| 1839 | */ |
| 1840 | private static class InputMethodSettings { |
| 1841 | // The string for enabled input method is saved as follows: |
| 1842 | // example: ("ime0;subtype0;subtype1;subtype2:ime1:ime2;subtype0") |
| 1843 | private static final char INPUT_METHOD_SEPARATER = ':'; |
| 1844 | private static final char INPUT_METHOD_SUBTYPE_SEPARATER = ';'; |
| 1845 | private final TextUtils.SimpleStringSplitter mStringColonSplitter = |
| 1846 | new TextUtils.SimpleStringSplitter(INPUT_METHOD_SEPARATER); |
| 1847 | |
| 1848 | private final TextUtils.SimpleStringSplitter mStringSemiColonSplitter = |
| 1849 | new TextUtils.SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATER); |
| 1850 | |
| 1851 | private final ContentResolver mResolver; |
| 1852 | private final HashMap<String, InputMethodInfo> mMethodMap; |
| 1853 | private final ArrayList<InputMethodInfo> mMethodList; |
| 1854 | |
| 1855 | private String mEnabledInputMethodsStrCache; |
| 1856 | |
| 1857 | private static void buildEnabledInputMethodsSettingString( |
| 1858 | StringBuilder builder, Pair<String, ArrayList<String>> pair) { |
| 1859 | String id = pair.first; |
| 1860 | ArrayList<String> subtypes = pair.second; |
| 1861 | builder.append(id); |
| 1862 | if (subtypes.size() > 0) { |
| 1863 | builder.append(subtypes.get(0)); |
| 1864 | for (int i = 1; i < subtypes.size(); ++i) { |
| 1865 | builder.append(INPUT_METHOD_SUBTYPE_SEPARATER).append(subtypes.get(i)); |
| 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | public InputMethodSettings( |
| 1871 | ContentResolver resolver, HashMap<String, InputMethodInfo> methodMap, |
| 1872 | ArrayList<InputMethodInfo> methodList) { |
| 1873 | mResolver = resolver; |
| 1874 | mMethodMap = methodMap; |
| 1875 | mMethodList = methodList; |
| 1876 | } |
| 1877 | |
| 1878 | public List<InputMethodInfo> getEnabledInputMethodListLocked() { |
| 1879 | return createEnabledInputMethodListLocked( |
| 1880 | getEnabledInputMethodsAndSubtypeListLocked()); |
| 1881 | } |
| 1882 | |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame^] | 1883 | public List<Pair<InputMethodInfo, ArrayList<String>>> |
| 1884 | getEnabledInputMethodAndSubtypeListLocked() { |
| 1885 | return createEnabledInputMethodAndSubtypeListLocked( |
| 1886 | getEnabledInputMethodsAndSubtypeListLocked()); |
| 1887 | } |
| 1888 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1889 | // At the initial boot, the settings for input methods are not set, |
| 1890 | // so we need to enable IME in that case. |
| 1891 | public void enableAllIMEsIfThereIsNoEnabledIME() { |
| 1892 | if (TextUtils.isEmpty(getEnabledInputMethodsStr())) { |
| 1893 | StringBuilder sb = new StringBuilder(); |
| 1894 | final int N = mMethodList.size(); |
| 1895 | for (int i = 0; i < N; i++) { |
| 1896 | InputMethodInfo imi = mMethodList.get(i); |
| 1897 | Slog.i(TAG, "Adding: " + imi.getId()); |
| 1898 | if (i > 0) sb.append(':'); |
| 1899 | sb.append(imi.getId()); |
| 1900 | } |
| 1901 | putEnabledInputMethodsStr(sb.toString()); |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | public List<Pair<String, ArrayList<String>>> getEnabledInputMethodsAndSubtypeListLocked() { |
| 1906 | ArrayList<Pair<String, ArrayList<String>>> imsList |
| 1907 | = new ArrayList<Pair<String, ArrayList<String>>>(); |
| 1908 | final String enabledInputMethodsStr = getEnabledInputMethodsStr(); |
| 1909 | if (TextUtils.isEmpty(enabledInputMethodsStr)) { |
| 1910 | return imsList; |
| 1911 | } |
| 1912 | mStringColonSplitter.setString(enabledInputMethodsStr); |
| 1913 | while (mStringColonSplitter.hasNext()) { |
| 1914 | String nextImsStr = mStringColonSplitter.next(); |
| 1915 | mStringSemiColonSplitter.setString(nextImsStr); |
| 1916 | if (mStringSemiColonSplitter.hasNext()) { |
| 1917 | ArrayList<String> subtypeHashes = new ArrayList<String>(); |
| 1918 | // The first element is ime id. |
| 1919 | String imeId = mStringSemiColonSplitter.next(); |
| 1920 | while (mStringSemiColonSplitter.hasNext()) { |
| 1921 | subtypeHashes.add(mStringSemiColonSplitter.next()); |
| 1922 | } |
| 1923 | imsList.add(new Pair<String, ArrayList<String>>(imeId, subtypeHashes)); |
| 1924 | } |
| 1925 | } |
| 1926 | return imsList; |
| 1927 | } |
| 1928 | |
| 1929 | public void appendAndPutEnabledInputMethodLocked(String id, boolean reloadInputMethodStr) { |
| 1930 | if (reloadInputMethodStr) { |
| 1931 | getEnabledInputMethodsStr(); |
| 1932 | } |
| 1933 | if (TextUtils.isEmpty(mEnabledInputMethodsStrCache)) { |
| 1934 | // Add in the newly enabled input method. |
| 1935 | putEnabledInputMethodsStr(id); |
| 1936 | } else { |
| 1937 | putEnabledInputMethodsStr( |
| 1938 | mEnabledInputMethodsStrCache + INPUT_METHOD_SEPARATER + id); |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | /** |
| 1943 | * Build and put a string of EnabledInputMethods with removing specified Id. |
| 1944 | * @return the specified id was removed or not. |
| 1945 | */ |
| 1946 | public boolean buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 1947 | StringBuilder builder, List<Pair<String, ArrayList<String>>> imsList, String id) { |
| 1948 | boolean isRemoved = false; |
| 1949 | boolean needsAppendSeparator = false; |
| 1950 | for (Pair<String, ArrayList<String>> ims: imsList) { |
| 1951 | String curId = ims.first; |
| 1952 | if (curId.equals(id)) { |
| 1953 | // We are disabling this input method, and it is |
| 1954 | // currently enabled. Skip it to remove from the |
| 1955 | // new list. |
| 1956 | isRemoved = true; |
| 1957 | } else { |
| 1958 | if (needsAppendSeparator) { |
| 1959 | builder.append(INPUT_METHOD_SEPARATER); |
| 1960 | } else { |
| 1961 | needsAppendSeparator = true; |
| 1962 | } |
| 1963 | buildEnabledInputMethodsSettingString(builder, ims); |
| 1964 | } |
| 1965 | } |
| 1966 | if (isRemoved) { |
| 1967 | // Update the setting with the new list of input methods. |
| 1968 | putEnabledInputMethodsStr(builder.toString()); |
| 1969 | } |
| 1970 | return isRemoved; |
| 1971 | } |
| 1972 | |
| 1973 | private List<InputMethodInfo> createEnabledInputMethodListLocked( |
| 1974 | List<Pair<String, ArrayList<String>>> imsList) { |
| 1975 | final ArrayList<InputMethodInfo> res = new ArrayList<InputMethodInfo>(); |
| 1976 | for (Pair<String, ArrayList<String>> ims: imsList) { |
| 1977 | InputMethodInfo info = mMethodMap.get(ims.first); |
| 1978 | if (info != null) { |
| 1979 | res.add(info); |
| 1980 | } |
| 1981 | } |
| 1982 | return res; |
| 1983 | } |
| 1984 | |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame^] | 1985 | private List<Pair<InputMethodInfo, ArrayList<String>>> |
| 1986 | createEnabledInputMethodAndSubtypeListLocked( |
| 1987 | List<Pair<String, ArrayList<String>>> imsList) { |
| 1988 | final ArrayList<Pair<InputMethodInfo, ArrayList<String>>> res |
| 1989 | = new ArrayList<Pair<InputMethodInfo, ArrayList<String>>>(); |
| 1990 | for (Pair<String, ArrayList<String>> ims : imsList) { |
| 1991 | InputMethodInfo info = mMethodMap.get(ims.first); |
| 1992 | if (info != null) { |
| 1993 | res.add(new Pair<InputMethodInfo, ArrayList<String>>(info, ims.second)); |
| 1994 | } |
| 1995 | } |
| 1996 | return res; |
| 1997 | } |
| 1998 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1999 | private void putEnabledInputMethodsStr(String str) { |
| 2000 | Settings.Secure.putString(mResolver, Settings.Secure.ENABLED_INPUT_METHODS, str); |
| 2001 | mEnabledInputMethodsStrCache = str; |
| 2002 | } |
| 2003 | |
| 2004 | private String getEnabledInputMethodsStr() { |
| 2005 | mEnabledInputMethodsStrCache = Settings.Secure.getString( |
| 2006 | mResolver, Settings.Secure.ENABLED_INPUT_METHODS); |
| 2007 | return mEnabledInputMethodsStrCache; |
| 2008 | } |
| 2009 | } |
| 2010 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2011 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2012 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2013 | @Override |
| 2014 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2015 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 2016 | != PackageManager.PERMISSION_GRANTED) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2017 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2018 | pw.println("Permission Denial: can't dump InputMethodManager from from pid=" |
| 2019 | + Binder.getCallingPid() |
| 2020 | + ", uid=" + Binder.getCallingUid()); |
| 2021 | return; |
| 2022 | } |
| 2023 | |
| 2024 | IInputMethod method; |
| 2025 | ClientState client; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2026 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2027 | final Printer p = new PrintWriterPrinter(pw); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2028 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2029 | synchronized (mMethodMap) { |
| 2030 | p.println("Current Input Method Manager state:"); |
| 2031 | int N = mMethodList.size(); |
| 2032 | p.println(" Input Methods:"); |
| 2033 | for (int i=0; i<N; i++) { |
| 2034 | InputMethodInfo info = mMethodList.get(i); |
| 2035 | p.println(" InputMethod #" + i + ":"); |
| 2036 | info.dump(p, " "); |
| 2037 | } |
| 2038 | p.println(" Clients:"); |
| 2039 | for (ClientState ci : mClients.values()) { |
| 2040 | p.println(" Client " + ci + ":"); |
| 2041 | p.println(" client=" + ci.client); |
| 2042 | p.println(" inputContext=" + ci.inputContext); |
| 2043 | p.println(" sessionRequested=" + ci.sessionRequested); |
| 2044 | p.println(" curSession=" + ci.curSession); |
| 2045 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2046 | p.println(" mCurMethodId=" + mCurMethodId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2047 | client = mCurClient; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2048 | p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq); |
| 2049 | p.println(" mCurFocusedWindow=" + mCurFocusedWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2050 | p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection |
| 2051 | + " mBoundToMethod=" + mBoundToMethod); |
| 2052 | p.println(" mCurToken=" + mCurToken); |
| 2053 | p.println(" mCurIntent=" + mCurIntent); |
| 2054 | method = mCurMethod; |
| 2055 | p.println(" mCurMethod=" + mCurMethod); |
| 2056 | p.println(" mEnabledSession=" + mEnabledSession); |
| 2057 | p.println(" mShowRequested=" + mShowRequested |
| 2058 | + " mShowExplicitlyRequested=" + mShowExplicitlyRequested |
| 2059 | + " mShowForced=" + mShowForced |
| 2060 | + " mInputShown=" + mInputShown); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2061 | p.println(" mSystemReady=" + mSystemReady + " mScreenOn=" + mScreenOn); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2062 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2063 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2064 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2065 | if (client != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2066 | pw.flush(); |
| 2067 | try { |
| 2068 | client.client.asBinder().dump(fd, args); |
| 2069 | } catch (RemoteException e) { |
| 2070 | p.println("Input method client dead: " + e); |
| 2071 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2072 | } else { |
| 2073 | p.println("No input method client."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2075 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2076 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | if (method != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | pw.flush(); |
| 2079 | try { |
| 2080 | method.asBinder().dump(fd, args); |
| 2081 | } catch (RemoteException e) { |
| 2082 | p.println("Input method service dead: " + e); |
| 2083 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 2084 | } else { |
| 2085 | p.println("No input method service."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2086 | } |
| 2087 | } |
| 2088 | } |