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