blob: c5d1cfc5960066e7002fea15251e429ff797b234 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006-2008 The Android Open Source Project
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004 * 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 Zongkerab5c49c2009-12-04 10:31:43 -08007 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008 * http://www.apache.org/licenses/LICENSE-2.0
Doug Zongkerab5c49c2009-12-04 10:31:43 -08009 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010 * 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
17package com.android.server;
18
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080019import com.android.internal.content.PackageMonitor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import com.android.internal.os.HandlerCaller;
21import com.android.internal.view.IInputContext;
22import com.android.internal.view.IInputMethod;
23import com.android.internal.view.IInputMethodCallback;
24import com.android.internal.view.IInputMethodClient;
25import com.android.internal.view.IInputMethodManager;
26import com.android.internal.view.IInputMethodSession;
27import com.android.internal.view.InputBindResult;
satok47a44912010-10-06 16:03:58 +090028import com.android.internal.view.InputMethodAndSubtypeEnabler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029
Joe Onorato7a0f36b2010-06-07 10:24:36 -070030import com.android.server.StatusBarManagerService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031
32import org.xmlpull.v1.XmlPullParserException;
33
34import android.app.ActivityManagerNative;
35import android.app.AlertDialog;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -070036import android.app.PendingIntent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.content.ComponentName;
38import android.content.ContentResolver;
39import android.content.Context;
40import android.content.DialogInterface;
41import android.content.IntentFilter;
42import android.content.DialogInterface.OnCancelListener;
43import android.content.Intent;
44import android.content.ServiceConnection;
Brandon Ballinger6da35a02009-10-21 00:38:13 -070045import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.content.pm.PackageManager;
47import android.content.pm.ResolveInfo;
48import android.content.pm.ServiceInfo;
Amith Yamasanie861ec12010-03-24 21:39:27 -070049import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.content.res.Resources;
51import android.content.res.TypedArray;
52import android.database.ContentObserver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.os.Binder;
54import android.os.Handler;
55import android.os.IBinder;
56import android.os.IInterface;
57import android.os.Message;
58import android.os.Parcel;
59import android.os.RemoteException;
The Android Open Source Project4df24232009-03-05 14:34:35 -080060import android.os.ResultReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.os.ServiceManager;
62import android.os.SystemClock;
63import android.provider.Settings;
Amith Yamasanie861ec12010-03-24 21:39:27 -070064import android.provider.Settings.Secure;
satokab751aa2010-09-14 19:17:36 +090065import android.provider.Settings.SettingNotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.text.TextUtils;
67import android.util.EventLog;
satokab751aa2010-09-14 19:17:36 +090068import android.util.Pair;
Joe Onorato8a9b2202010-02-26 18:56:32 -080069import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070import android.util.PrintWriterPrinter;
71import android.util.Printer;
72import android.view.IWindowManager;
73import android.view.WindowManager;
satokab751aa2010-09-14 19:17:36 +090074import android.view.inputmethod.EditorInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.view.inputmethod.InputBinding;
76import android.view.inputmethod.InputMethod;
77import android.view.inputmethod.InputMethodInfo;
78import android.view.inputmethod.InputMethodManager;
satokab751aa2010-09-14 19:17:36 +090079import android.view.inputmethod.InputMethodSubtype;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080
81import java.io.FileDescriptor;
82import java.io.IOException;
83import java.io.PrintWriter;
satok913a8922010-08-26 21:53:41 +090084import java.text.Collator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085import java.util.ArrayList;
86import java.util.HashMap;
satok7f35c8c2010-10-07 21:13:11 +090087import java.util.HashSet;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088import java.util.List;
satok913a8922010-08-26 21:53:41 +090089import java.util.Map;
90import java.util.TreeMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091
92/**
93 * This class provides a system service that manages input methods.
94 */
95public class InputMethodManagerService extends IInputMethodManager.Stub
96 implements ServiceConnection, Handler.Callback {
97 static final boolean DEBUG = false;
98 static final String TAG = "InputManagerService";
99
100 static final int MSG_SHOW_IM_PICKER = 1;
satokab751aa2010-09-14 19:17:36 +0900101 static final int MSG_SHOW_IM_SUBTYPE_PICKER = 2;
satok47a44912010-10-06 16:03:58 +0900102 static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 3;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 static final int MSG_UNBIND_INPUT = 1000;
105 static final int MSG_BIND_INPUT = 1010;
106 static final int MSG_SHOW_SOFT_INPUT = 1020;
107 static final int MSG_HIDE_SOFT_INPUT = 1030;
108 static final int MSG_ATTACH_TOKEN = 1040;
109 static final int MSG_CREATE_SESSION = 1050;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 static final int MSG_START_INPUT = 2000;
112 static final int MSG_RESTART_INPUT = 2010;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 static final int MSG_UNBIND_METHOD = 3000;
115 static final int MSG_BIND_METHOD = 3010;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 static final long TIME_TO_RECONNECT = 10*1000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800118
satokab751aa2010-09-14 19:17:36 +0900119 private static final int NOT_A_SUBTYPE_ID = -1;
120
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 final Context mContext;
122 final Handler mHandler;
satokd87c2592010-09-29 11:52:06 +0900123 final InputMethodSettings mSettings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 final SettingsObserver mSettingsObserver;
Joe Onorato089de882010-04-12 08:18:45 -0700125 final StatusBarManagerService mStatusBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 final IWindowManager mIWindowManager;
127 final HandlerCaller mCaller;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 final InputBindResult mNoBinding = new InputBindResult(null, null, -1);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 // All known input methods. mMethodMap also serves as the global
132 // lock for this class.
satokd87c2592010-09-29 11:52:06 +0900133 final ArrayList<InputMethodInfo> mMethodList = new ArrayList<InputMethodInfo>();
134 final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<String, InputMethodInfo>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 class SessionState {
137 final ClientState client;
138 final IInputMethod method;
139 final IInputMethodSession session;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 @Override
142 public String toString() {
143 return "SessionState{uid " + client.uid + " pid " + client.pid
144 + " method " + Integer.toHexString(
145 System.identityHashCode(method))
146 + " session " + Integer.toHexString(
147 System.identityHashCode(session))
148 + "}";
149 }
150
151 SessionState(ClientState _client, IInputMethod _method,
152 IInputMethodSession _session) {
153 client = _client;
154 method = _method;
155 session = _session;
156 }
157 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 class ClientState {
160 final IInputMethodClient client;
161 final IInputContext inputContext;
162 final int uid;
163 final int pid;
164 final InputBinding binding;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 boolean sessionRequested;
167 SessionState curSession;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 @Override
170 public String toString() {
171 return "ClientState{" + Integer.toHexString(
172 System.identityHashCode(this)) + " uid " + uid
173 + " pid " + pid + "}";
174 }
175
176 ClientState(IInputMethodClient _client, IInputContext _inputContext,
177 int _uid, int _pid) {
178 client = _client;
179 inputContext = _inputContext;
180 uid = _uid;
181 pid = _pid;
182 binding = new InputBinding(null, inputContext.asBinder(), uid, pid);
183 }
184 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 final HashMap<IBinder, ClientState> mClients
187 = new HashMap<IBinder, ClientState>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 /**
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700190 * Set once the system is ready to run third party code.
191 */
192 boolean mSystemReady;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800193
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700194 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 * Id of the currently selected input method.
196 */
197 String mCurMethodId;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 /**
200 * The current binding sequence number, incremented every time there is
201 * a new bind performed.
202 */
203 int mCurSeq;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 /**
206 * The client that is currently bound to an input method.
207 */
208 ClientState mCurClient;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 /**
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700211 * The last window token that gained focus.
212 */
213 IBinder mCurFocusedWindow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800214
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700215 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 * The input context last provided by the current client.
217 */
218 IInputContext mCurInputContext;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800219
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 /**
221 * The attributes last provided by the current client.
222 */
223 EditorInfo mCurAttribute;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 /**
226 * The input method ID of the input method service that we are currently
227 * connected to or in the process of connecting to.
228 */
229 String mCurId;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800230
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 /**
satokab751aa2010-09-14 19:17:36 +0900232 * The current subtype of the current input method.
233 */
234 private InputMethodSubtype mCurrentSubtype;
235
236
237 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 * Set to true if our ServiceConnection is currently actively bound to
239 * a service (whether or not we have gotten its IBinder back yet).
240 */
241 boolean mHaveConnection;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 /**
244 * Set if the client has asked for the input method to be shown.
245 */
246 boolean mShowRequested;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 /**
249 * Set if we were explicitly told to show the input method.
250 */
251 boolean mShowExplicitlyRequested;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800252
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 /**
254 * Set if we were forced to be shown.
255 */
256 boolean mShowForced;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 /**
259 * Set if we last told the input method to show itself.
260 */
261 boolean mInputShown;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 /**
264 * The Intent used to connect to the current input method.
265 */
266 Intent mCurIntent;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 /**
269 * The token we have made for the currently active input method, to
270 * identify it in the future.
271 */
272 IBinder mCurToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800273
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 /**
275 * If non-null, this is the input method service we are currently connected
276 * to.
277 */
278 IInputMethod mCurMethod;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 /**
281 * Time that we last initiated a bind to the input method, to determine
282 * if we should try to disconnect and reconnect to it.
283 */
284 long mLastBindTime;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 /**
287 * Have we called mCurMethod.bindInput()?
288 */
289 boolean mBoundToMethod;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 /**
292 * Currently enabled session. Only touched by service thread, not
293 * protected by a lock.
294 */
295 SessionState mEnabledSession;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 /**
298 * True if the screen is on. The value is true initially.
299 */
300 boolean mScreenOn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 AlertDialog.Builder mDialogBuilder;
303 AlertDialog mSwitchingDialog;
304 InputMethodInfo[] mIms;
305 CharSequence[] mItems;
satokab751aa2010-09-14 19:17:36 +0900306 int[] mSubtypeIds;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 class SettingsObserver extends ContentObserver {
309 SettingsObserver(Handler handler) {
310 super(handler);
311 ContentResolver resolver = mContext.getContentResolver();
312 resolver.registerContentObserver(Settings.Secure.getUriFor(
313 Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
satokab751aa2010-09-14 19:17:36 +0900314 resolver.registerContentObserver(Settings.Secure.getUriFor(
315 Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 @Override public void onChange(boolean selfChange) {
319 synchronized (mMethodMap) {
320 updateFromSettingsLocked();
321 }
322 }
323 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 class ScreenOnOffReceiver extends android.content.BroadcastReceiver {
326 @Override
327 public void onReceive(Context context, Intent intent) {
328 if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
329 mScreenOn = true;
330 } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
331 mScreenOn = false;
The Android Open Source Project10592532009-03-18 17:39:46 -0700332 } else if (intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
333 hideInputMethodMenu();
334 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800336 Slog.w(TAG, "Unexpected intent " + intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337 }
338
339 // Inform the current client of the change in active status
340 try {
341 if (mCurClient != null && mCurClient.client != null) {
342 mCurClient.client.setActive(mScreenOn);
343 }
344 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800345 Slog.w(TAG, "Got RemoteException sending 'screen on/off' notification to pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800346 + mCurClient.pid + " uid " + mCurClient.uid);
347 }
348 }
349 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800350
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800351 class MyPackageMonitor extends PackageMonitor {
352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 @Override
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800354 public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 synchronized (mMethodMap) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800356 String curInputMethodId = Settings.Secure.getString(mContext
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
358 final int N = mMethodList.size();
359 if (curInputMethodId != null) {
360 for (int i=0; i<N; i++) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800361 InputMethodInfo imi = mMethodList.get(i);
362 if (imi.getId().equals(curInputMethodId)) {
363 for (String pkg : packages) {
364 if (imi.getPackageName().equals(pkg)) {
365 if (!doit) {
366 return true;
367 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800368 Settings.Secure.putString(mContext.getContentResolver(),
369 Settings.Secure.DEFAULT_INPUT_METHOD, "");
satokab751aa2010-09-14 19:17:36 +0900370 resetSelectedInputMethodSubtype();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800371 chooseNewDefaultIMELocked();
372 return true;
373 }
374 }
375 }
376 }
377 }
378 }
379 return false;
380 }
381
382 @Override
383 public void onSomePackagesChanged() {
384 synchronized (mMethodMap) {
385 InputMethodInfo curIm = null;
386 String curInputMethodId = Settings.Secure.getString(mContext
387 .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
388 final int N = mMethodList.size();
389 if (curInputMethodId != null) {
390 for (int i=0; i<N; i++) {
391 InputMethodInfo imi = mMethodList.get(i);
392 if (imi.getId().equals(curInputMethodId)) {
393 curIm = imi;
394 }
395 int change = isPackageDisappearing(imi.getPackageName());
396 if (change == PACKAGE_TEMPORARY_CHANGE
397 || change == PACKAGE_PERMANENT_CHANGE) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800398 Slog.i(TAG, "Input method uninstalled, disabling: "
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800399 + imi.getComponent());
400 setInputMethodEnabledLocked(imi.getId(), false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 }
402 }
403 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800404
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800405 buildInputMethodListLocked(mMethodList, mMethodMap);
406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800408
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800409 if (curIm != null) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800410 int change = isPackageDisappearing(curIm.getPackageName());
411 if (change == PACKAGE_TEMPORARY_CHANGE
412 || change == PACKAGE_PERMANENT_CHANGE) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800413 ServiceInfo si = null;
414 try {
415 si = mContext.getPackageManager().getServiceInfo(
416 curIm.getComponent(), 0);
417 } catch (PackageManager.NameNotFoundException ex) {
418 }
419 if (si == null) {
420 // Uh oh, current input method is no longer around!
421 // Pick another one...
Joe Onorato8a9b2202010-02-26 18:56:32 -0800422 Slog.i(TAG, "Current input method removed: " + curInputMethodId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800423 if (!chooseNewDefaultIMELocked()) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800424 changed = true;
425 curIm = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800426 Slog.i(TAG, "Unsetting current input method");
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800427 Settings.Secure.putString(mContext.getContentResolver(),
satokab751aa2010-09-14 19:17:36 +0900428 Settings.Secure.DEFAULT_INPUT_METHOD, "");
429 resetSelectedInputMethodSubtype();
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800430 }
431 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800432 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800433 }
satokab751aa2010-09-14 19:17:36 +0900434
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800435 if (curIm == null) {
436 // We currently don't have a default input method... is
437 // one now available?
438 changed = chooseNewDefaultIMELocked();
439 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800440
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800441 if (changed) {
442 updateFromSettingsLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 }
444 }
445 }
446 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 class MethodCallback extends IInputMethodCallback.Stub {
449 final IInputMethod mMethod;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 MethodCallback(IInputMethod method) {
452 mMethod = method;
453 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 public void finishedEvent(int seq, boolean handled) throws RemoteException {
456 }
457
458 public void sessionCreated(IInputMethodSession session) throws RemoteException {
459 onSessionCreated(mMethod, session);
460 }
461 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800462
Joe Onorato089de882010-04-12 08:18:45 -0700463 public InputMethodManagerService(Context context, StatusBarManagerService statusBar) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 mContext = context;
465 mHandler = new Handler(this);
466 mIWindowManager = IWindowManager.Stub.asInterface(
467 ServiceManager.getService(Context.WINDOW_SERVICE));
468 mCaller = new HandlerCaller(context, new HandlerCaller.Callback() {
469 public void executeMessage(Message msg) {
470 handleMessage(msg);
471 }
472 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800473
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800474 (new MyPackageMonitor()).register(mContext, true);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 IntentFilter screenOnOffFilt = new IntentFilter();
477 screenOnOffFilt.addAction(Intent.ACTION_SCREEN_ON);
478 screenOnOffFilt.addAction(Intent.ACTION_SCREEN_OFF);
The Android Open Source Project10592532009-03-18 17:39:46 -0700479 screenOnOffFilt.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 mContext.registerReceiver(new ScreenOnOffReceiver(), screenOnOffFilt);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800481
satok913a8922010-08-26 21:53:41 +0900482 mStatusBar = statusBar;
483 statusBar.setIconVisibility("ime", false);
484
satokd87c2592010-09-29 11:52:06 +0900485 // mSettings should be created before buildInputMethodListLocked
486 mSettings = new InputMethodSettings(context.getContentResolver(), mMethodMap, mMethodList);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 buildInputMethodListLocked(mMethodList, mMethodMap);
satokd87c2592010-09-29 11:52:06 +0900488 mSettings.enableAllIMEsIfThereIsNoEnabledIME();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489
satokd87c2592010-09-29 11:52:06 +0900490 if (TextUtils.isEmpty(Settings.Secure.getString(
491 mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 InputMethodInfo defIm = null;
satokd87c2592010-09-29 11:52:06 +0900493 for (InputMethodInfo imi: mMethodList) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 if (defIm == null && imi.getIsDefaultResourceId() != 0) {
495 try {
satokd87c2592010-09-29 11:52:06 +0900496 Resources res = context.createPackageContext(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 imi.getPackageName(), 0).getResources();
498 if (res.getBoolean(imi.getIsDefaultResourceId())) {
499 defIm = imi;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800500 Slog.i(TAG, "Selected default: " + imi.getId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 }
502 } catch (PackageManager.NameNotFoundException ex) {
503 } catch (Resources.NotFoundException ex) {
504 }
505 }
506 }
satokd87c2592010-09-29 11:52:06 +0900507 if (defIm == null && mMethodList.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 defIm = mMethodList.get(0);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800509 Slog.i(TAG, "No default found, using " + defIm.getId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 if (defIm != null) {
512 Settings.Secure.putString(mContext.getContentResolver(),
513 Settings.Secure.DEFAULT_INPUT_METHOD, defIm.getId());
satokab751aa2010-09-14 19:17:36 +0900514 putSelectedInputMethodSubtype(defIm, NOT_A_SUBTYPE_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 }
516 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 mSettingsObserver = new SettingsObserver(mHandler);
519 updateFromSettingsLocked();
520 }
521
522 @Override
523 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
524 throws RemoteException {
525 try {
526 return super.onTransact(code, data, reply, flags);
527 } catch (RuntimeException e) {
528 // The input method manager only throws security exceptions, so let's
529 // log all others.
530 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800531 Slog.e(TAG, "Input Method Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 }
533 throw e;
534 }
535 }
536
537 public void systemReady() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700538 synchronized (mMethodMap) {
539 if (!mSystemReady) {
540 mSystemReady = true;
Dianne Hackborncc278702009-09-02 23:07:23 -0700541 try {
542 startInputInnerLocked();
543 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800544 Slog.w(TAG, "Unexpected exception", e);
Dianne Hackborncc278702009-09-02 23:07:23 -0700545 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700546 }
547 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 public List<InputMethodInfo> getInputMethodList() {
551 synchronized (mMethodMap) {
552 return new ArrayList<InputMethodInfo>(mMethodList);
553 }
554 }
555
556 public List<InputMethodInfo> getEnabledInputMethodList() {
557 synchronized (mMethodMap) {
satokd87c2592010-09-29 11:52:06 +0900558 return mSettings.getEnabledInputMethodListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 }
560 }
561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 public void addClient(IInputMethodClient client,
563 IInputContext inputContext, int uid, int pid) {
564 synchronized (mMethodMap) {
565 mClients.put(client.asBinder(), new ClientState(client,
566 inputContext, uid, pid));
567 }
568 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 public void removeClient(IInputMethodClient client) {
571 synchronized (mMethodMap) {
572 mClients.remove(client.asBinder());
573 }
574 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 void executeOrSendMessage(IInterface target, Message msg) {
577 if (target.asBinder() instanceof Binder) {
578 mCaller.sendMessage(msg);
579 } else {
580 handleMessage(msg);
581 msg.recycle();
582 }
583 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800584
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700585 void unbindCurrentClientLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 if (mCurClient != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800587 if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 + mCurClient.client.asBinder());
589 if (mBoundToMethod) {
590 mBoundToMethod = false;
591 if (mCurMethod != null) {
592 executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
593 MSG_UNBIND_INPUT, mCurMethod));
594 }
595 }
596 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
597 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
598 mCurClient.sessionRequested = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 // Call setActive(false) on the old client
601 try {
602 mCurClient.client.setActive(false);
603 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800604 Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 + mCurClient.pid + " uid " + mCurClient.uid);
606 }
607 mCurClient = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800608
The Android Open Source Project10592532009-03-18 17:39:46 -0700609 hideInputMethodMenuLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 }
611 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 private int getImeShowFlags() {
614 int flags = 0;
615 if (mShowForced) {
616 flags |= InputMethod.SHOW_FORCED
617 | InputMethod.SHOW_EXPLICIT;
618 } else if (mShowExplicitlyRequested) {
619 flags |= InputMethod.SHOW_EXPLICIT;
620 }
621 return flags;
622 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 private int getAppShowFlags() {
625 int flags = 0;
626 if (mShowForced) {
627 flags |= InputMethodManager.SHOW_FORCED;
628 } else if (!mShowExplicitlyRequested) {
629 flags |= InputMethodManager.SHOW_IMPLICIT;
630 }
631 return flags;
632 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 InputBindResult attachNewInputLocked(boolean initial, boolean needResult) {
635 if (!mBoundToMethod) {
636 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
637 MSG_BIND_INPUT, mCurMethod, mCurClient.binding));
638 mBoundToMethod = true;
639 }
640 final SessionState session = mCurClient.curSession;
641 if (initial) {
642 executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
643 MSG_START_INPUT, session, mCurInputContext, mCurAttribute));
644 } else {
645 executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
646 MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute));
647 }
648 if (mShowRequested) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800649 if (DEBUG) Slog.v(TAG, "Attach new input asks to show input");
The Android Open Source Project4df24232009-03-05 14:34:35 -0800650 showCurrentInputLocked(getAppShowFlags(), null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 }
652 return needResult
653 ? new InputBindResult(session.session, mCurId, mCurSeq)
654 : null;
655 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800656
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 InputBindResult startInputLocked(IInputMethodClient client,
658 IInputContext inputContext, EditorInfo attribute,
659 boolean initial, boolean needResult) {
660 // If no method is currently selected, do nothing.
661 if (mCurMethodId == null) {
662 return mNoBinding;
663 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 ClientState cs = mClients.get(client.asBinder());
666 if (cs == null) {
667 throw new IllegalArgumentException("unknown client "
668 + client.asBinder());
669 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 try {
672 if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
673 // Check with the window manager to make sure this client actually
674 // has a window with focus. If not, reject. This is thread safe
675 // because if the focus changes some time before or after, the
676 // next client receiving focus that has any interest in input will
677 // be calling through here after that change happens.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800678 Slog.w(TAG, "Starting input on non-focused client " + cs.client
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
680 return null;
681 }
682 } catch (RemoteException e) {
683 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800684
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 if (mCurClient != cs) {
686 // If the client is changing, we need to switch over to the new
687 // one.
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700688 unbindCurrentClientLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -0800689 if (DEBUG) Slog.v(TAG, "switching to client: client = "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 + cs.client.asBinder());
691
692 // If the screen is on, inform the new client it is active
693 if (mScreenOn) {
694 try {
695 cs.client.setActive(mScreenOn);
696 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800697 Slog.w(TAG, "Got RemoteException sending setActive notification to pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 + cs.pid + " uid " + cs.uid);
699 }
700 }
701 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 // Bump up the sequence for this client and attach it.
704 mCurSeq++;
705 if (mCurSeq <= 0) mCurSeq = 1;
706 mCurClient = cs;
707 mCurInputContext = inputContext;
708 mCurAttribute = attribute;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 // Check if the input method is changing.
711 if (mCurId != null && mCurId.equals(mCurMethodId)) {
712 if (cs.curSession != null) {
713 // Fast case: if we are already connected to the input method,
714 // then just return it.
715 return attachNewInputLocked(initial, needResult);
716 }
717 if (mHaveConnection) {
718 if (mCurMethod != null) {
719 if (!cs.sessionRequested) {
720 cs.sessionRequested = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800721 if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
723 MSG_CREATE_SESSION, mCurMethod,
724 new MethodCallback(mCurMethod)));
725 }
726 // Return to client, and we will get back with it when
727 // we have had a session made for it.
728 return new InputBindResult(null, mCurId, mCurSeq);
729 } else if (SystemClock.uptimeMillis()
730 < (mLastBindTime+TIME_TO_RECONNECT)) {
731 // In this case we have connected to the service, but
732 // don't yet have its interface. If it hasn't been too
733 // long since we did the connection, we'll return to
734 // the client and wait to get the service interface so
735 // we can report back. If it has been too long, we want
736 // to fall through so we can try a disconnect/reconnect
737 // to see if we can get back in touch with the service.
738 return new InputBindResult(null, mCurId, mCurSeq);
739 } else {
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800740 EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME,
741 mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 }
743 }
744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800745
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700746 return startInputInnerLocked();
747 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800748
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700749 InputBindResult startInputInnerLocked() {
750 if (mCurMethodId == null) {
751 return mNoBinding;
752 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800753
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700754 if (!mSystemReady) {
755 // If the system is not yet ready, we shouldn't be running third
756 // party code.
Dianne Hackborncc278702009-09-02 23:07:23 -0700757 return new InputBindResult(null, mCurMethodId, mCurSeq);
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700758 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800759
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 InputMethodInfo info = mMethodMap.get(mCurMethodId);
761 if (info == null) {
762 throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
763 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800764
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700765 unbindCurrentMethodLocked(false);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800766
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE);
768 mCurIntent.setComponent(info.getComponent());
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700769 mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
770 com.android.internal.R.string.input_method_binding_label);
771 mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
772 mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 if (mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE)) {
774 mLastBindTime = SystemClock.uptimeMillis();
775 mHaveConnection = true;
776 mCurId = info.getId();
777 mCurToken = new Binder();
778 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800779 if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 mIWindowManager.addWindowToken(mCurToken,
781 WindowManager.LayoutParams.TYPE_INPUT_METHOD);
782 } catch (RemoteException e) {
783 }
784 return new InputBindResult(null, mCurId, mCurSeq);
785 } else {
786 mCurIntent = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800787 Slog.w(TAG, "Failure connecting to input method service: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 + mCurIntent);
789 }
790 return null;
791 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800792
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 public InputBindResult startInput(IInputMethodClient client,
794 IInputContext inputContext, EditorInfo attribute,
795 boolean initial, boolean needResult) {
796 synchronized (mMethodMap) {
797 final long ident = Binder.clearCallingIdentity();
798 try {
799 return startInputLocked(client, inputContext, attribute,
800 initial, needResult);
801 } finally {
802 Binder.restoreCallingIdentity(ident);
803 }
804 }
805 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 public void finishInput(IInputMethodClient client) {
808 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 public void onServiceConnected(ComponentName name, IBinder service) {
811 synchronized (mMethodMap) {
812 if (mCurIntent != null && name.equals(mCurIntent.getComponent())) {
813 mCurMethod = IInputMethod.Stub.asInterface(service);
Dianne Hackborncc278702009-09-02 23:07:23 -0700814 if (mCurToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800815 Slog.w(TAG, "Service connected without a token!");
Dianne Hackborncc278702009-09-02 23:07:23 -0700816 unbindCurrentMethodLocked(false);
817 return;
818 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800819 if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken);
Dianne Hackborncc278702009-09-02 23:07:23 -0700820 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
821 MSG_ATTACH_TOKEN, mCurMethod, mCurToken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 if (mCurClient != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800823 if (DEBUG) Slog.v(TAG, "Creating first session while with client "
Dianne Hackborncc278702009-09-02 23:07:23 -0700824 + mCurClient);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
Dianne Hackborncc278702009-09-02 23:07:23 -0700826 MSG_CREATE_SESSION, mCurMethod,
827 new MethodCallback(mCurMethod)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 }
829 }
830 }
831 }
832
833 void onSessionCreated(IInputMethod method, IInputMethodSession session) {
834 synchronized (mMethodMap) {
835 if (mCurMethod != null && method != null
836 && mCurMethod.asBinder() == method.asBinder()) {
837 if (mCurClient != null) {
838 mCurClient.curSession = new SessionState(mCurClient,
839 method, session);
840 mCurClient.sessionRequested = false;
841 InputBindResult res = attachNewInputLocked(true, true);
842 if (res.method != null) {
843 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO(
844 MSG_BIND_METHOD, mCurClient.client, res));
845 }
846 }
847 }
848 }
849 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800850
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700851 void unbindCurrentMethodLocked(boolean reportToClient) {
852 if (mHaveConnection) {
853 mContext.unbindService(this);
854 mHaveConnection = false;
855 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800856
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700857 if (mCurToken != null) {
858 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800859 if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700860 mIWindowManager.removeWindowToken(mCurToken);
861 } catch (RemoteException e) {
862 }
863 mCurToken = null;
864 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800865
The Android Open Source Project10592532009-03-18 17:39:46 -0700866 mCurId = null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700867 clearCurMethodLocked();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800868
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700869 if (reportToClient && mCurClient != null) {
870 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
871 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
872 }
873 }
874
Devin Taylor0c33ed22010-02-23 13:26:46 -0600875 private void finishSession(SessionState sessionState) {
876 if (sessionState != null && sessionState.session != null) {
877 try {
878 sessionState.session.finishSession();
879 } catch (RemoteException e) {
Jean-Baptiste Queru9d0f6df2010-03-29 12:55:09 -0700880 Slog.w(TAG, "Session failed to close due to remote exception", e);
Devin Taylor0c33ed22010-02-23 13:26:46 -0600881 }
882 }
883 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800884
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700885 void clearCurMethodLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 if (mCurMethod != null) {
887 for (ClientState cs : mClients.values()) {
888 cs.sessionRequested = false;
Devin Taylor0c33ed22010-02-23 13:26:46 -0600889 finishSession(cs.curSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 cs.curSession = null;
891 }
Devin Taylor0c33ed22010-02-23 13:26:46 -0600892
893 finishSession(mEnabledSession);
894 mEnabledSession = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 mCurMethod = null;
896 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700897 mStatusBar.setIconVisibility("ime", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 public void onServiceDisconnected(ComponentName name) {
901 synchronized (mMethodMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800902 if (DEBUG) Slog.v(TAG, "Service disconnected: " + name
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 + " mCurIntent=" + mCurIntent);
904 if (mCurMethod != null && mCurIntent != null
905 && name.equals(mCurIntent.getComponent())) {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700906 clearCurMethodLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800907 // We consider this to be a new bind attempt, since the system
908 // should now try to restart the service for us.
909 mLastBindTime = SystemClock.uptimeMillis();
910 mShowRequested = mInputShown;
911 mInputShown = false;
912 if (mCurClient != null) {
913 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
914 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
915 }
916 }
917 }
918 }
919
920 public void updateStatusIcon(IBinder token, String packageName, int iconId) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -0700921 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 long ident = Binder.clearCallingIdentity();
923 try {
924 if (token == null || mCurToken != token) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -0700925 Slog.w(TAG, "Ignoring setInputMethod of uid " + uid + " token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 return;
927 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 synchronized (mMethodMap) {
930 if (iconId == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800931 if (DEBUG) Slog.d(TAG, "hide the small icon for the input method");
Joe Onorato0cbda992010-05-02 16:28:15 -0700932 mStatusBar.setIconVisibility("ime", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800933 } else if (packageName != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800934 if (DEBUG) Slog.d(TAG, "show a small icon for the input method");
Joe Onorato0cbda992010-05-02 16:28:15 -0700935 mStatusBar.setIcon("ime", packageName, iconId, 0);
936 mStatusBar.setIconVisibility("ime", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 }
938 }
939 } finally {
940 Binder.restoreCallingIdentity(ident);
941 }
942 }
943
944 void updateFromSettingsLocked() {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700945 // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and
946 // ENABLED_INPUT_METHODS is taking care of keeping them correctly in
947 // sync, so we will never have a DEFAULT_INPUT_METHOD that is not
948 // enabled.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 String id = Settings.Secure.getString(mContext.getContentResolver(),
satokab751aa2010-09-14 19:17:36 +0900950 Settings.Secure.DEFAULT_INPUT_METHOD);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700951 if (id != null && id.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 try {
satokab751aa2010-09-14 19:17:36 +0900953 setInputMethodLocked(id, getSelectedInputMethodSubtypeId(id));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800955 Slog.w(TAG, "Unknown input method from prefs: " + id, e);
The Android Open Source Project10592532009-03-18 17:39:46 -0700956 mCurMethodId = null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700957 unbindCurrentMethodLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700959 } else {
960 // There is no longer an input method set, so stop any current one.
The Android Open Source Project10592532009-03-18 17:39:46 -0700961 mCurMethodId = null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700962 unbindCurrentMethodLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 }
964 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800965
satokab751aa2010-09-14 19:17:36 +0900966 /* package */ void setInputMethodLocked(String id, int subtypeId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800967 InputMethodInfo info = mMethodMap.get(id);
968 if (info == null) {
satok913a8922010-08-26 21:53:41 +0900969 throw new IllegalArgumentException("Unknown id: " + id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800971
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 if (id.equals(mCurMethodId)) {
satokab751aa2010-09-14 19:17:36 +0900973 if (subtypeId != NOT_A_SUBTYPE_ID) {
974 InputMethodSubtype subtype = info.getSubtypes().get(subtypeId);
975 if (subtype != mCurrentSubtype) {
976 synchronized (mMethodMap) {
977 if (mCurMethod != null) {
978 try {
979 putSelectedInputMethodSubtype(info, subtypeId);
980 mCurMethod.changeInputMethodSubtype(subtype);
981 } catch (RemoteException e) {
982 return;
983 }
984 }
985 }
986 }
987 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 return;
989 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 final long ident = Binder.clearCallingIdentity();
992 try {
993 mCurMethodId = id;
satokab751aa2010-09-14 19:17:36 +0900994 // Set a subtype to this input method.
995 // subtypeId the name of a subtype which will be set.
996 if (putSelectedInputMethodSubtype(info, subtypeId)) {
997 mCurrentSubtype = info.getSubtypes().get(subtypeId);
998 } else {
999 mCurrentSubtype = null;
1000 }
1001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 Settings.Secure.putString(mContext.getContentResolver(),
satokab751aa2010-09-14 19:17:36 +09001003 Settings.Secure.DEFAULT_INPUT_METHOD, id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004
1005 if (ActivityManagerNative.isSystemReady()) {
1006 Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001007 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 intent.putExtra("input_method_id", id);
1009 mContext.sendBroadcast(intent);
1010 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001011 unbindCurrentClientLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001012 } finally {
1013 Binder.restoreCallingIdentity(ident);
1014 }
1015 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001016
The Android Open Source Project4df24232009-03-05 14:34:35 -08001017 public boolean showSoftInput(IInputMethodClient client, int flags,
1018 ResultReceiver resultReceiver) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001019 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 long ident = Binder.clearCallingIdentity();
1021 try {
1022 synchronized (mMethodMap) {
1023 if (mCurClient == null || client == null
1024 || mCurClient.client.asBinder() != client.asBinder()) {
1025 try {
1026 // We need to check if this is the current client with
1027 // focus in the window manager, to allow this call to
1028 // be made before input is started in it.
1029 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001030 Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client);
The Android Open Source Project4df24232009-03-05 14:34:35 -08001031 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001032 }
1033 } catch (RemoteException e) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001034 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 }
1036 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001037
Joe Onorato8a9b2202010-02-26 18:56:32 -08001038 if (DEBUG) Slog.v(TAG, "Client requesting input be shown");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001039 return showCurrentInputLocked(flags, resultReceiver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 }
1041 } finally {
1042 Binder.restoreCallingIdentity(ident);
1043 }
1044 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001045
The Android Open Source Project4df24232009-03-05 14:34:35 -08001046 boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 mShowRequested = true;
1048 if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) {
1049 mShowExplicitlyRequested = true;
1050 }
1051 if ((flags&InputMethodManager.SHOW_FORCED) != 0) {
1052 mShowExplicitlyRequested = true;
1053 mShowForced = true;
1054 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001055
Dianne Hackborncc278702009-09-02 23:07:23 -07001056 if (!mSystemReady) {
1057 return false;
1058 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001059
The Android Open Source Project4df24232009-03-05 14:34:35 -08001060 boolean res = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001061 if (mCurMethod != null) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001062 executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO(
1063 MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod,
1064 resultReceiver));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 mInputShown = true;
The Android Open Source Project4df24232009-03-05 14:34:35 -08001066 res = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001067 } else if (mHaveConnection && SystemClock.uptimeMillis()
1068 < (mLastBindTime+TIME_TO_RECONNECT)) {
1069 // The client has asked to have the input method shown, but
1070 // we have been sitting here too long with a connection to the
1071 // service and no interface received, so let's disconnect/connect
1072 // to try to prod things along.
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001073 EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 SystemClock.uptimeMillis()-mLastBindTime,1);
1075 mContext.unbindService(this);
1076 mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE);
1077 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001078
The Android Open Source Project4df24232009-03-05 14:34:35 -08001079 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001080 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001081
The Android Open Source Project4df24232009-03-05 14:34:35 -08001082 public boolean hideSoftInput(IInputMethodClient client, int flags,
1083 ResultReceiver resultReceiver) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001084 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 long ident = Binder.clearCallingIdentity();
1086 try {
1087 synchronized (mMethodMap) {
1088 if (mCurClient == null || client == null
1089 || mCurClient.client.asBinder() != client.asBinder()) {
1090 try {
1091 // We need to check if this is the current client with
1092 // focus in the window manager, to allow this call to
1093 // be made before input is started in it.
1094 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001095 if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid "
1096 + uid + ": " + client);
The Android Open Source Project4df24232009-03-05 14:34:35 -08001097 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 }
1099 } catch (RemoteException e) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001100 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 }
1102 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001103
Joe Onorato8a9b2202010-02-26 18:56:32 -08001104 if (DEBUG) Slog.v(TAG, "Client requesting input be hidden");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001105 return hideCurrentInputLocked(flags, resultReceiver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 }
1107 } finally {
1108 Binder.restoreCallingIdentity(ident);
1109 }
1110 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001111
The Android Open Source Project4df24232009-03-05 14:34:35 -08001112 boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0
1114 && (mShowExplicitlyRequested || mShowForced)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001115 if (DEBUG) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001116 "Not hiding: explicit show not cancelled by non-explicit hide");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001117 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 }
1119 if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001120 if (DEBUG) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 "Not hiding: forced show not cancelled by not-always hide");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001122 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08001124 boolean res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 if (mInputShown && mCurMethod != null) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001126 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
1127 MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver));
1128 res = true;
1129 } else {
1130 res = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 }
1132 mInputShown = false;
1133 mShowRequested = false;
1134 mShowExplicitlyRequested = false;
1135 mShowForced = false;
The Android Open Source Project4df24232009-03-05 14:34:35 -08001136 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001138
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001139 public void windowGainedFocus(IInputMethodClient client, IBinder windowToken,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001140 boolean viewHasFocus, boolean isTextEditor, int softInputMode,
1141 boolean first, int windowFlags) {
1142 long ident = Binder.clearCallingIdentity();
1143 try {
1144 synchronized (mMethodMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001145 if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001146 + " viewHasFocus=" + viewHasFocus
1147 + " isTextEditor=" + isTextEditor
1148 + " softInputMode=#" + Integer.toHexString(softInputMode)
1149 + " first=" + first + " flags=#"
1150 + Integer.toHexString(windowFlags));
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 if (mCurClient == null || client == null
1153 || mCurClient.client.asBinder() != client.asBinder()) {
1154 try {
1155 // We need to check if this is the current client with
1156 // focus in the window manager, to allow this call to
1157 // be made before input is started in it.
1158 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001159 Slog.w(TAG, "Client not active, ignoring focus gain of: " + client);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 return;
1161 }
1162 } catch (RemoteException e) {
1163 }
1164 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001165
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001166 if (mCurFocusedWindow == windowToken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001167 Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001168 return;
1169 }
1170 mCurFocusedWindow = windowToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) {
1173 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
1174 if (!isTextEditor || (softInputMode &
1175 WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
1176 != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) {
1177 if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) {
1178 // There is no focus view, and this window will
1179 // be behind any soft input window, so hide the
1180 // soft input window if it is shown.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001181 if (DEBUG) Slog.v(TAG, "Unspecified window will hide input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001182 hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 }
1184 } else if (isTextEditor && (softInputMode &
1185 WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
1186 == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
1187 && (softInputMode &
1188 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
1189 // There is a focus view, and we are navigating forward
1190 // into the window, so show the input window for the user.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001191 if (DEBUG) Slog.v(TAG, "Unspecified window will show input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001192 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 }
1194 break;
1195 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
1196 // Do nothing.
1197 break;
1198 case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN:
1199 if ((softInputMode &
1200 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001201 if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001202 hideCurrentInputLocked(0, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 }
1204 break;
1205 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08001206 if (DEBUG) Slog.v(TAG, "Window asks to hide input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001207 hideCurrentInputLocked(0, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 break;
1209 case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
1210 if ((softInputMode &
1211 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001212 if (DEBUG) Slog.v(TAG, "Window asks to show input going forward");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001213 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 }
1215 break;
1216 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
Joe Onorato8a9b2202010-02-26 18:56:32 -08001217 if (DEBUG) Slog.v(TAG, "Window asks to always show input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001218 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 break;
1220 }
1221 }
1222 } finally {
1223 Binder.restoreCallingIdentity(ident);
1224 }
1225 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001226
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 public void showInputMethodPickerFromClient(IInputMethodClient client) {
1228 synchronized (mMethodMap) {
1229 if (mCurClient == null || client == null
1230 || mCurClient.client.asBinder() != client.asBinder()) {
satok47a44912010-10-06 16:03:58 +09001231 Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid "
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001232 + Binder.getCallingUid() + ": " + client);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 }
1234
1235 mHandler.sendEmptyMessage(MSG_SHOW_IM_PICKER);
1236 }
1237 }
1238
satokab751aa2010-09-14 19:17:36 +09001239 public void showInputMethodSubtypePickerFromClient(IInputMethodClient client) {
1240 synchronized (mMethodMap) {
1241 if (mCurClient == null || client == null
1242 || mCurClient.client.asBinder() != client.asBinder()) {
satok47a44912010-10-06 16:03:58 +09001243 Slog.w(TAG, "Ignoring showInputMethodSubtypePickerFromClient of: " + client);
satokab751aa2010-09-14 19:17:36 +09001244 }
1245
1246 mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER);
1247 }
1248 }
1249
satok47a44912010-10-06 16:03:58 +09001250 public void showInputMethodAndSubtypeEnablerFromClient(
1251 IInputMethodClient client, String topId) {
1252 // TODO: Handle topId for setting the top position of the list activity
1253 synchronized (mMethodMap) {
1254 if (mCurClient == null || client == null
1255 || mCurClient.client.asBinder() != client.asBinder()) {
1256 Slog.w(TAG, "Ignoring showInputMethodAndSubtypeEnablerFromClient of: " + client);
1257 }
1258
1259 mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_ENABLER);
1260 }
1261 }
1262
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 public void setInputMethod(IBinder token, String id) {
satokab751aa2010-09-14 19:17:36 +09001264 setInputMethodWithSubtype(token, id, NOT_A_SUBTYPE_ID);
1265 }
1266
1267 private void setInputMethodWithSubtype(IBinder token, String id, int subtypeId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 synchronized (mMethodMap) {
1269 if (token == null) {
1270 if (mContext.checkCallingOrSelfPermission(
1271 android.Manifest.permission.WRITE_SECURE_SETTINGS)
1272 != PackageManager.PERMISSION_GRANTED) {
1273 throw new SecurityException(
1274 "Using null token requires permission "
1275 + android.Manifest.permission.WRITE_SECURE_SETTINGS);
1276 }
1277 } else if (mCurToken != token) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001278 Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid()
1279 + " token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001280 return;
1281 }
1282
1283 long ident = Binder.clearCallingIdentity();
1284 try {
satokab751aa2010-09-14 19:17:36 +09001285 setInputMethodLocked(id, subtypeId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 } finally {
1287 Binder.restoreCallingIdentity(ident);
1288 }
1289 }
1290 }
1291
1292 public void hideMySoftInput(IBinder token, int flags) {
1293 synchronized (mMethodMap) {
1294 if (token == null || mCurToken != token) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001295 if (DEBUG) Slog.w(TAG, "Ignoring hideInputMethod of uid "
1296 + Binder.getCallingUid() + " token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 return;
1298 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 long ident = Binder.clearCallingIdentity();
1300 try {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001301 hideCurrentInputLocked(flags, null);
1302 } finally {
1303 Binder.restoreCallingIdentity(ident);
1304 }
1305 }
1306 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001307
The Android Open Source Project4df24232009-03-05 14:34:35 -08001308 public void showMySoftInput(IBinder token, int flags) {
1309 synchronized (mMethodMap) {
1310 if (token == null || mCurToken != token) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001311 Slog.w(TAG, "Ignoring showMySoftInput of uid "
1312 + Binder.getCallingUid() + " token: " + token);
The Android Open Source Project4df24232009-03-05 14:34:35 -08001313 return;
1314 }
1315 long ident = Binder.clearCallingIdentity();
1316 try {
1317 showCurrentInputLocked(flags, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 } finally {
1319 Binder.restoreCallingIdentity(ident);
1320 }
1321 }
1322 }
1323
1324 void setEnabledSessionInMainThread(SessionState session) {
1325 if (mEnabledSession != session) {
1326 if (mEnabledSession != null) {
1327 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001328 if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 mEnabledSession.method.setSessionEnabled(
1330 mEnabledSession.session, false);
1331 } catch (RemoteException e) {
1332 }
1333 }
1334 mEnabledSession = session;
1335 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001336 if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 session.method.setSessionEnabled(
1338 session.session, true);
1339 } catch (RemoteException e) {
1340 }
1341 }
1342 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 public boolean handleMessage(Message msg) {
1345 HandlerCaller.SomeArgs args;
1346 switch (msg.what) {
1347 case MSG_SHOW_IM_PICKER:
1348 showInputMethodMenu();
1349 return true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001350
satokab751aa2010-09-14 19:17:36 +09001351 case MSG_SHOW_IM_SUBTYPE_PICKER:
1352 showInputMethodSubtypeMenu();
1353 return true;
1354
satok47a44912010-10-06 16:03:58 +09001355 case MSG_SHOW_IM_SUBTYPE_ENABLER:
1356 showInputMethodAndSubtypeEnabler();
1357 return true;
1358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001360
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 case MSG_UNBIND_INPUT:
1362 try {
1363 ((IInputMethod)msg.obj).unbindInput();
1364 } catch (RemoteException e) {
1365 // There is nothing interesting about the method dying.
1366 }
1367 return true;
1368 case MSG_BIND_INPUT:
1369 args = (HandlerCaller.SomeArgs)msg.obj;
1370 try {
1371 ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2);
1372 } catch (RemoteException e) {
1373 }
1374 return true;
1375 case MSG_SHOW_SOFT_INPUT:
The Android Open Source Project4df24232009-03-05 14:34:35 -08001376 args = (HandlerCaller.SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001377 try {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001378 ((IInputMethod)args.arg1).showSoftInput(msg.arg1,
1379 (ResultReceiver)args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 } catch (RemoteException e) {
1381 }
1382 return true;
1383 case MSG_HIDE_SOFT_INPUT:
The Android Open Source Project4df24232009-03-05 14:34:35 -08001384 args = (HandlerCaller.SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001385 try {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001386 ((IInputMethod)args.arg1).hideSoftInput(0,
1387 (ResultReceiver)args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001388 } catch (RemoteException e) {
1389 }
1390 return true;
1391 case MSG_ATTACH_TOKEN:
1392 args = (HandlerCaller.SomeArgs)msg.obj;
1393 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001394 if (DEBUG) Slog.v(TAG, "Sending attach of token: " + args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395 ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2);
1396 } catch (RemoteException e) {
1397 }
1398 return true;
1399 case MSG_CREATE_SESSION:
1400 args = (HandlerCaller.SomeArgs)msg.obj;
1401 try {
1402 ((IInputMethod)args.arg1).createSession(
1403 (IInputMethodCallback)args.arg2);
1404 } catch (RemoteException e) {
1405 }
1406 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001409 case MSG_START_INPUT:
1410 args = (HandlerCaller.SomeArgs)msg.obj;
1411 try {
1412 SessionState session = (SessionState)args.arg1;
1413 setEnabledSessionInMainThread(session);
1414 session.method.startInput((IInputContext)args.arg2,
1415 (EditorInfo)args.arg3);
1416 } catch (RemoteException e) {
1417 }
1418 return true;
1419 case MSG_RESTART_INPUT:
1420 args = (HandlerCaller.SomeArgs)msg.obj;
1421 try {
1422 SessionState session = (SessionState)args.arg1;
1423 setEnabledSessionInMainThread(session);
1424 session.method.restartInput((IInputContext)args.arg2,
1425 (EditorInfo)args.arg3);
1426 } catch (RemoteException e) {
1427 }
1428 return true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 case MSG_UNBIND_METHOD:
1433 try {
1434 ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1);
1435 } catch (RemoteException e) {
1436 // There is nothing interesting about the last client dying.
1437 }
1438 return true;
1439 case MSG_BIND_METHOD:
1440 args = (HandlerCaller.SomeArgs)msg.obj;
1441 try {
1442 ((IInputMethodClient)args.arg1).onBindMethod(
1443 (InputBindResult)args.arg2);
1444 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001445 Slog.w(TAG, "Client died receiving input method " + args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 }
1447 return true;
1448 }
1449 return false;
1450 }
1451
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001452 private boolean isSystemIme(InputMethodInfo inputMethod) {
1453 return (inputMethod.getServiceInfo().applicationInfo.flags
1454 & ApplicationInfo.FLAG_SYSTEM) != 0;
1455 }
1456
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001457 private boolean chooseNewDefaultIMELocked() {
satokd87c2592010-09-29 11:52:06 +09001458 List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001459 if (enabled != null && enabled.size() > 0) {
Dianne Hackborn83e48f52010-03-23 23:03:25 -07001460 // We'd prefer to fall back on a system IME, since that is safer.
1461 int i=enabled.size();
1462 while (i > 0) {
1463 i--;
1464 if ((enabled.get(i).getServiceInfo().applicationInfo.flags
1465 & ApplicationInfo.FLAG_SYSTEM) != 0) {
1466 break;
1467 }
1468 }
satokab751aa2010-09-14 19:17:36 +09001469 InputMethodInfo imi = enabled.get(i);
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001470 Settings.Secure.putString(mContext.getContentResolver(),
satokab751aa2010-09-14 19:17:36 +09001471 Settings.Secure.DEFAULT_INPUT_METHOD, imi.getId());
1472 putSelectedInputMethodSubtype(imi, NOT_A_SUBTYPE_ID);
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001473 return true;
1474 }
1475
1476 return false;
1477 }
1478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 void buildInputMethodListLocked(ArrayList<InputMethodInfo> list,
1480 HashMap<String, InputMethodInfo> map) {
1481 list.clear();
1482 map.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 PackageManager pm = mContext.getPackageManager();
Amith Yamasanie861ec12010-03-24 21:39:27 -07001485 final Configuration config = mContext.getResources().getConfiguration();
1486 final boolean haveHardKeyboard = config.keyboard == Configuration.KEYBOARD_QWERTY;
1487 String disabledSysImes = Settings.Secure.getString(mContext.getContentResolver(),
1488 Secure.DISABLED_SYSTEM_INPUT_METHODS);
1489 if (disabledSysImes == null) disabledSysImes = "";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490
1491 List<ResolveInfo> services = pm.queryIntentServices(
1492 new Intent(InputMethod.SERVICE_INTERFACE),
1493 PackageManager.GET_META_DATA);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 for (int i = 0; i < services.size(); ++i) {
1496 ResolveInfo ri = services.get(i);
1497 ServiceInfo si = ri.serviceInfo;
1498 ComponentName compName = new ComponentName(si.packageName, si.name);
1499 if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(
1500 si.permission)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001501 Slog.w(TAG, "Skipping input method " + compName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 + ": it does not require the permission "
1503 + android.Manifest.permission.BIND_INPUT_METHOD);
1504 continue;
1505 }
1506
Joe Onorato8a9b2202010-02-26 18:56:32 -08001507 if (DEBUG) Slog.d(TAG, "Checking " + compName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508
1509 try {
1510 InputMethodInfo p = new InputMethodInfo(mContext, ri);
1511 list.add(p);
Amith Yamasanie861ec12010-03-24 21:39:27 -07001512 final String id = p.getId();
1513 map.put(id, p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514
Amith Yamasanie861ec12010-03-24 21:39:27 -07001515 // System IMEs are enabled by default, unless there's a hard keyboard
1516 // and the system IME was explicitly disabled
1517 if (isSystemIme(p) && (!haveHardKeyboard || disabledSysImes.indexOf(id) < 0)) {
1518 setInputMethodEnabledLocked(id, true);
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001519 }
1520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 if (DEBUG) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001522 Slog.d(TAG, "Found a third-party input method " + p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 } catch (XmlPullParserException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001526 Slog.w(TAG, "Unable to load input method " + compName, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001528 Slog.w(TAG, "Unable to load input method " + compName, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 }
1530 }
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001531
1532 String defaultIme = Settings.Secure.getString(mContext
1533 .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
satok913a8922010-08-26 21:53:41 +09001534 if (!TextUtils.isEmpty(defaultIme) && !map.containsKey(defaultIme)) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001535 if (chooseNewDefaultIMELocked()) {
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001536 updateFromSettingsLocked();
1537 }
1538 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001539 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001542
satokab751aa2010-09-14 19:17:36 +09001543 private void showInputMethodMenu() {
1544 showInputMethodMenuInternal(false);
1545 }
1546
1547 private void showInputMethodSubtypeMenu() {
1548 showInputMethodMenuInternal(true);
1549 }
1550
satok47a44912010-10-06 16:03:58 +09001551 private void showInputMethodAndSubtypeEnabler() {
1552 Intent intent = new Intent();
1553 intent.setClassName("android", InputMethodAndSubtypeEnabler.class.getCanonicalName());
1554 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1555 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1556 mContext.startActivity(intent);
1557 }
1558
satokab751aa2010-09-14 19:17:36 +09001559 private void showInputMethodMenuInternal(boolean showSubtypes) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001560 if (DEBUG) Slog.v(TAG, "Show switching menu");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 final Context context = mContext;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001564 final PackageManager pm = context.getPackageManager();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001566 String lastInputMethodId = Settings.Secure.getString(context
1567 .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
satokab751aa2010-09-14 19:17:36 +09001568 int lastInputMethodSubtypeId = getSelectedInputMethodSubtypeId(lastInputMethodId);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001569 if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001570
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001571 synchronized (mMethodMap) {
satok7f35c8c2010-10-07 21:13:11 +09001572 final List<Pair<InputMethodInfo, ArrayList<String>>> immis =
1573 mSettings.getEnabledInputMethodAndSubtypeListLocked();
1574 ArrayList<Integer> subtypeIds = new ArrayList<Integer>();
1575
1576 if (immis == null || immis.size() == 0) {
1577 return;
1578 }
1579
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001580 hideInputMethodMenuLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001582 int N = immis.size();
satok913a8922010-08-26 21:53:41 +09001583
satokab751aa2010-09-14 19:17:36 +09001584 final Map<CharSequence, Pair<InputMethodInfo, Integer>> imMap =
1585 new TreeMap<CharSequence, Pair<InputMethodInfo, Integer>>(Collator.getInstance());
satok913a8922010-08-26 21:53:41 +09001586
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001587 for (int i = 0; i < N; ++i) {
satok7f35c8c2010-10-07 21:13:11 +09001588 InputMethodInfo property = immis.get(i).first;
1589 final ArrayList<String> enabledSubtypeIds = immis.get(i).second;
1590 HashSet<String> enabledSubtypeSet = new HashSet<String>();
1591 for (String s : enabledSubtypeIds) {
1592 enabledSubtypeSet.add(s);
1593 }
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001594 if (property == null) {
1595 continue;
1596 }
satokab751aa2010-09-14 19:17:36 +09001597 ArrayList<InputMethodSubtype> subtypes = property.getSubtypes();
1598 CharSequence label = property.loadLabel(pm);
satok7f35c8c2010-10-07 21:13:11 +09001599 if (showSubtypes && enabledSubtypeSet.size() > 0) {
satokab751aa2010-09-14 19:17:36 +09001600 for (int j = 0; j < subtypes.size(); ++j) {
1601 InputMethodSubtype subtype = subtypes.get(j);
satok7f35c8c2010-10-07 21:13:11 +09001602 if (enabledSubtypeSet.contains(String.valueOf(subtype.hashCode()))) {
1603 CharSequence title;
1604 int nameResId = subtype.getNameResId();
1605 int modeResId = subtype.getModeResId();
1606 if (nameResId != 0) {
1607 title = pm.getText(property.getPackageName(), nameResId,
1608 property.getServiceInfo().applicationInfo);
1609 } else {
1610 CharSequence language = subtype.getLocale();
1611 CharSequence mode = modeResId == 0 ? null
1612 : pm.getText(property.getPackageName(), modeResId,
1613 property.getServiceInfo().applicationInfo);
1614 // TODO: Use more friendly Title and UI
1615 title = label + "," + (mode == null ? "" : mode) + ","
1616 + (language == null ? "" : language);
1617 }
1618 imMap.put(title, new Pair<InputMethodInfo, Integer>(property, j));
satokab751aa2010-09-14 19:17:36 +09001619 }
satokab751aa2010-09-14 19:17:36 +09001620 }
1621 } else {
1622 imMap.put(label,
1623 new Pair<InputMethodInfo, Integer>(property, NOT_A_SUBTYPE_ID));
1624 subtypeIds.add(0);
1625 }
Dianne Hackborn97106ab2010-03-03 00:08:31 -08001626 }
satok913a8922010-08-26 21:53:41 +09001627
1628 N = imMap.size();
1629 mItems = imMap.keySet().toArray(new CharSequence[N]);
satokab751aa2010-09-14 19:17:36 +09001630 mIms = new InputMethodInfo[N];
1631 mSubtypeIds = new int[N];
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001632 int checkedItem = 0;
1633 for (int i = 0; i < N; ++i) {
satokab751aa2010-09-14 19:17:36 +09001634 Pair<InputMethodInfo, Integer> value = imMap.get(mItems[i]);
1635 mIms[i] = value.first;
1636 mSubtypeIds[i] = value.second;
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001637 if (mIms[i].getId().equals(lastInputMethodId)) {
satokab751aa2010-09-14 19:17:36 +09001638 int subtypeId = mSubtypeIds[i];
1639 if ((subtypeId == NOT_A_SUBTYPE_ID)
1640 || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0)
1641 || (subtypeId == lastInputMethodSubtypeId)) {
1642 checkedItem = i;
1643 }
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001644 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 }
satokab751aa2010-09-14 19:17:36 +09001646
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001647 AlertDialog.OnClickListener adocl = new AlertDialog.OnClickListener() {
1648 public void onClick(DialogInterface dialog, int which) {
1649 hideInputMethodMenu();
1650 }
1651 };
satokd87c2592010-09-29 11:52:06 +09001652
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001653 TypedArray a = context.obtainStyledAttributes(null,
1654 com.android.internal.R.styleable.DialogPreference,
1655 com.android.internal.R.attr.alertDialogStyle, 0);
1656 mDialogBuilder = new AlertDialog.Builder(context)
1657 .setTitle(com.android.internal.R.string.select_input_method)
1658 .setOnCancelListener(new OnCancelListener() {
1659 public void onCancel(DialogInterface dialog) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660 hideInputMethodMenu();
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001661 }
1662 })
1663 .setIcon(a.getDrawable(
1664 com.android.internal.R.styleable.DialogPreference_dialogTitle));
1665 a.recycle();
satokd87c2592010-09-29 11:52:06 +09001666
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001667 mDialogBuilder.setSingleChoiceItems(mItems, checkedItem,
1668 new AlertDialog.OnClickListener() {
1669 public void onClick(DialogInterface dialog, int which) {
1670 synchronized (mMethodMap) {
satokab751aa2010-09-14 19:17:36 +09001671 if (mIms == null || mIms.length <= which
1672 || mSubtypeIds == null || mSubtypeIds.length <= which) {
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001673 return;
1674 }
1675 InputMethodInfo im = mIms[which];
satokab751aa2010-09-14 19:17:36 +09001676 int subtypeId = mSubtypeIds[which];
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001677 hideInputMethodMenu();
1678 if (im != null) {
satokab751aa2010-09-14 19:17:36 +09001679 if ((subtypeId < 0)
1680 || (subtypeId >= im.getSubtypes().size())) {
1681 subtypeId = NOT_A_SUBTYPE_ID;
1682 }
1683 setInputMethodLocked(im.getId(), subtypeId);
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001684 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08001685 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001686 }
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001687 });
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001688
satok7f35c8c2010-10-07 21:13:11 +09001689 if (showSubtypes) {
1690 mDialogBuilder.setPositiveButton(com.android.internal.R.string.more_item_label,
1691 new DialogInterface.OnClickListener() {
1692 public void onClick(DialogInterface dialog, int whichButton) {
1693 showInputMethodAndSubtypeEnabler();
1694 }
1695 });
1696 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 mSwitchingDialog = mDialogBuilder.create();
1698 mSwitchingDialog.getWindow().setType(
1699 WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
1700 mSwitchingDialog.show();
1701 }
1702 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 void hideInputMethodMenu() {
The Android Open Source Project10592532009-03-18 17:39:46 -07001705 synchronized (mMethodMap) {
1706 hideInputMethodMenuLocked();
1707 }
1708 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001709
The Android Open Source Project10592532009-03-18 17:39:46 -07001710 void hideInputMethodMenuLocked() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001711 if (DEBUG) Slog.v(TAG, "Hide switching menu");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001712
The Android Open Source Project10592532009-03-18 17:39:46 -07001713 if (mSwitchingDialog != null) {
1714 mSwitchingDialog.dismiss();
1715 mSwitchingDialog = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001716 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001717
The Android Open Source Project10592532009-03-18 17:39:46 -07001718 mDialogBuilder = null;
1719 mItems = null;
1720 mIms = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001721 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001722
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001723 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001724
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001725 public boolean setInputMethodEnabled(String id, boolean enabled) {
1726 synchronized (mMethodMap) {
1727 if (mContext.checkCallingOrSelfPermission(
1728 android.Manifest.permission.WRITE_SECURE_SETTINGS)
1729 != PackageManager.PERMISSION_GRANTED) {
1730 throw new SecurityException(
1731 "Requires permission "
1732 + android.Manifest.permission.WRITE_SECURE_SETTINGS);
1733 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 long ident = Binder.clearCallingIdentity();
1736 try {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001737 return setInputMethodEnabledLocked(id, enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001738 } finally {
1739 Binder.restoreCallingIdentity(ident);
1740 }
1741 }
1742 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001743
1744 boolean setInputMethodEnabledLocked(String id, boolean enabled) {
1745 // Make sure this is a valid input method.
1746 InputMethodInfo imm = mMethodMap.get(id);
1747 if (imm == null) {
satokd87c2592010-09-29 11:52:06 +09001748 throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001749 }
1750
satokd87c2592010-09-29 11:52:06 +09001751 List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings
1752 .getEnabledInputMethodsAndSubtypeListLocked();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001753
satokd87c2592010-09-29 11:52:06 +09001754 if (enabled) {
1755 for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) {
1756 if (pair.first.equals(id)) {
1757 // We are enabling this input method, but it is already enabled.
1758 // Nothing to do. The previous state was enabled.
1759 return true;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001760 }
1761 }
satokd87c2592010-09-29 11:52:06 +09001762 mSettings.appendAndPutEnabledInputMethodLocked(id, false);
1763 // Previous state was disabled.
1764 return false;
1765 } else {
1766 StringBuilder builder = new StringBuilder();
1767 if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked(
1768 builder, enabledInputMethodsList, id)) {
1769 // Disabled input method is currently selected, switch to another one.
1770 String selId = Settings.Secure.getString(mContext.getContentResolver(),
1771 Settings.Secure.DEFAULT_INPUT_METHOD);
1772 if (id.equals(selId)) {
1773 Settings.Secure.putString(
1774 mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD,
1775 enabledInputMethodsList.size() > 0
1776 ? enabledInputMethodsList.get(0).first : "");
1777 resetSelectedInputMethodSubtype();
1778 }
1779 // Previous state was enabled.
1780 return true;
1781 } else {
1782 // We are disabling the input method but it is already disabled.
1783 // Nothing to do. The previous state was disabled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001784 return false;
1785 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001786 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001787 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08001788
satokab751aa2010-09-14 19:17:36 +09001789 private void resetSelectedInputMethodSubtype() {
1790 Settings.Secure.putInt(mContext.getContentResolver(),
1791 Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, NOT_A_SUBTYPE_ID);
1792 }
1793
1794 private boolean putSelectedInputMethodSubtype(InputMethodInfo imi, int subtypeId) {
1795 ArrayList<InputMethodSubtype> subtypes = imi.getSubtypes();
1796 if (subtypeId >= 0 && subtypeId < subtypes.size()) {
1797 Settings.Secure.putInt(mContext.getContentResolver(),
1798 Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE,
1799 subtypes.get(subtypeId).hashCode());
1800 return true;
1801 } else {
1802 resetSelectedInputMethodSubtype();
1803 return false;
1804 }
1805 }
1806
1807 private int getSelectedInputMethodSubtypeId(String id) {
1808 InputMethodInfo imi = mMethodMap.get(id);
1809 if (imi == null) {
1810 return NOT_A_SUBTYPE_ID;
1811 }
1812 ArrayList<InputMethodSubtype> subtypes = imi.getSubtypes();
1813 int subtypeId;
1814 try {
1815 subtypeId = Settings.Secure.getInt(mContext.getContentResolver(),
1816 Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE);
1817 } catch (SettingNotFoundException e) {
1818 return NOT_A_SUBTYPE_ID;
1819 }
1820 for (int i = 0; i < subtypes.size(); ++i) {
1821 InputMethodSubtype ims = subtypes.get(i);
1822 if (subtypeId == ims.hashCode()) {
1823 return i;
1824 }
1825 }
1826 return NOT_A_SUBTYPE_ID;
1827 }
1828
1829 /**
1830 * @return Return the current subtype of this input method.
1831 */
1832 public InputMethodSubtype getCurrentInputMethodSubtype() {
1833 return mCurrentSubtype;
1834 }
1835
satokd87c2592010-09-29 11:52:06 +09001836 /**
1837 * Utility class for putting and getting settings for InputMethod
1838 * TODO: Move all putters and getters of settings to this class.
1839 */
1840 private static class InputMethodSettings {
1841 // The string for enabled input method is saved as follows:
1842 // example: ("ime0;subtype0;subtype1;subtype2:ime1:ime2;subtype0")
1843 private static final char INPUT_METHOD_SEPARATER = ':';
1844 private static final char INPUT_METHOD_SUBTYPE_SEPARATER = ';';
1845 private final TextUtils.SimpleStringSplitter mStringColonSplitter =
1846 new TextUtils.SimpleStringSplitter(INPUT_METHOD_SEPARATER);
1847
1848 private final TextUtils.SimpleStringSplitter mStringSemiColonSplitter =
1849 new TextUtils.SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATER);
1850
1851 private final ContentResolver mResolver;
1852 private final HashMap<String, InputMethodInfo> mMethodMap;
1853 private final ArrayList<InputMethodInfo> mMethodList;
1854
1855 private String mEnabledInputMethodsStrCache;
1856
1857 private static void buildEnabledInputMethodsSettingString(
1858 StringBuilder builder, Pair<String, ArrayList<String>> pair) {
1859 String id = pair.first;
1860 ArrayList<String> subtypes = pair.second;
1861 builder.append(id);
1862 if (subtypes.size() > 0) {
1863 builder.append(subtypes.get(0));
1864 for (int i = 1; i < subtypes.size(); ++i) {
1865 builder.append(INPUT_METHOD_SUBTYPE_SEPARATER).append(subtypes.get(i));
1866 }
1867 }
1868 }
1869
1870 public InputMethodSettings(
1871 ContentResolver resolver, HashMap<String, InputMethodInfo> methodMap,
1872 ArrayList<InputMethodInfo> methodList) {
1873 mResolver = resolver;
1874 mMethodMap = methodMap;
1875 mMethodList = methodList;
1876 }
1877
1878 public List<InputMethodInfo> getEnabledInputMethodListLocked() {
1879 return createEnabledInputMethodListLocked(
1880 getEnabledInputMethodsAndSubtypeListLocked());
1881 }
1882
satok7f35c8c2010-10-07 21:13:11 +09001883 public List<Pair<InputMethodInfo, ArrayList<String>>>
1884 getEnabledInputMethodAndSubtypeListLocked() {
1885 return createEnabledInputMethodAndSubtypeListLocked(
1886 getEnabledInputMethodsAndSubtypeListLocked());
1887 }
1888
satokd87c2592010-09-29 11:52:06 +09001889 // At the initial boot, the settings for input methods are not set,
1890 // so we need to enable IME in that case.
1891 public void enableAllIMEsIfThereIsNoEnabledIME() {
1892 if (TextUtils.isEmpty(getEnabledInputMethodsStr())) {
1893 StringBuilder sb = new StringBuilder();
1894 final int N = mMethodList.size();
1895 for (int i = 0; i < N; i++) {
1896 InputMethodInfo imi = mMethodList.get(i);
1897 Slog.i(TAG, "Adding: " + imi.getId());
1898 if (i > 0) sb.append(':');
1899 sb.append(imi.getId());
1900 }
1901 putEnabledInputMethodsStr(sb.toString());
1902 }
1903 }
1904
1905 public List<Pair<String, ArrayList<String>>> getEnabledInputMethodsAndSubtypeListLocked() {
1906 ArrayList<Pair<String, ArrayList<String>>> imsList
1907 = new ArrayList<Pair<String, ArrayList<String>>>();
1908 final String enabledInputMethodsStr = getEnabledInputMethodsStr();
1909 if (TextUtils.isEmpty(enabledInputMethodsStr)) {
1910 return imsList;
1911 }
1912 mStringColonSplitter.setString(enabledInputMethodsStr);
1913 while (mStringColonSplitter.hasNext()) {
1914 String nextImsStr = mStringColonSplitter.next();
1915 mStringSemiColonSplitter.setString(nextImsStr);
1916 if (mStringSemiColonSplitter.hasNext()) {
1917 ArrayList<String> subtypeHashes = new ArrayList<String>();
1918 // The first element is ime id.
1919 String imeId = mStringSemiColonSplitter.next();
1920 while (mStringSemiColonSplitter.hasNext()) {
1921 subtypeHashes.add(mStringSemiColonSplitter.next());
1922 }
1923 imsList.add(new Pair<String, ArrayList<String>>(imeId, subtypeHashes));
1924 }
1925 }
1926 return imsList;
1927 }
1928
1929 public void appendAndPutEnabledInputMethodLocked(String id, boolean reloadInputMethodStr) {
1930 if (reloadInputMethodStr) {
1931 getEnabledInputMethodsStr();
1932 }
1933 if (TextUtils.isEmpty(mEnabledInputMethodsStrCache)) {
1934 // Add in the newly enabled input method.
1935 putEnabledInputMethodsStr(id);
1936 } else {
1937 putEnabledInputMethodsStr(
1938 mEnabledInputMethodsStrCache + INPUT_METHOD_SEPARATER + id);
1939 }
1940 }
1941
1942 /**
1943 * Build and put a string of EnabledInputMethods with removing specified Id.
1944 * @return the specified id was removed or not.
1945 */
1946 public boolean buildAndPutEnabledInputMethodsStrRemovingIdLocked(
1947 StringBuilder builder, List<Pair<String, ArrayList<String>>> imsList, String id) {
1948 boolean isRemoved = false;
1949 boolean needsAppendSeparator = false;
1950 for (Pair<String, ArrayList<String>> ims: imsList) {
1951 String curId = ims.first;
1952 if (curId.equals(id)) {
1953 // We are disabling this input method, and it is
1954 // currently enabled. Skip it to remove from the
1955 // new list.
1956 isRemoved = true;
1957 } else {
1958 if (needsAppendSeparator) {
1959 builder.append(INPUT_METHOD_SEPARATER);
1960 } else {
1961 needsAppendSeparator = true;
1962 }
1963 buildEnabledInputMethodsSettingString(builder, ims);
1964 }
1965 }
1966 if (isRemoved) {
1967 // Update the setting with the new list of input methods.
1968 putEnabledInputMethodsStr(builder.toString());
1969 }
1970 return isRemoved;
1971 }
1972
1973 private List<InputMethodInfo> createEnabledInputMethodListLocked(
1974 List<Pair<String, ArrayList<String>>> imsList) {
1975 final ArrayList<InputMethodInfo> res = new ArrayList<InputMethodInfo>();
1976 for (Pair<String, ArrayList<String>> ims: imsList) {
1977 InputMethodInfo info = mMethodMap.get(ims.first);
1978 if (info != null) {
1979 res.add(info);
1980 }
1981 }
1982 return res;
1983 }
1984
satok7f35c8c2010-10-07 21:13:11 +09001985 private List<Pair<InputMethodInfo, ArrayList<String>>>
1986 createEnabledInputMethodAndSubtypeListLocked(
1987 List<Pair<String, ArrayList<String>>> imsList) {
1988 final ArrayList<Pair<InputMethodInfo, ArrayList<String>>> res
1989 = new ArrayList<Pair<InputMethodInfo, ArrayList<String>>>();
1990 for (Pair<String, ArrayList<String>> ims : imsList) {
1991 InputMethodInfo info = mMethodMap.get(ims.first);
1992 if (info != null) {
1993 res.add(new Pair<InputMethodInfo, ArrayList<String>>(info, ims.second));
1994 }
1995 }
1996 return res;
1997 }
1998
satokd87c2592010-09-29 11:52:06 +09001999 private void putEnabledInputMethodsStr(String str) {
2000 Settings.Secure.putString(mResolver, Settings.Secure.ENABLED_INPUT_METHODS, str);
2001 mEnabledInputMethodsStrCache = str;
2002 }
2003
2004 private String getEnabledInputMethodsStr() {
2005 mEnabledInputMethodsStrCache = Settings.Secure.getString(
2006 mResolver, Settings.Secure.ENABLED_INPUT_METHODS);
2007 return mEnabledInputMethodsStrCache;
2008 }
2009 }
2010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002012
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013 @Override
2014 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2015 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
2016 != PackageManager.PERMISSION_GRANTED) {
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002017
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 pw.println("Permission Denial: can't dump InputMethodManager from from pid="
2019 + Binder.getCallingPid()
2020 + ", uid=" + Binder.getCallingUid());
2021 return;
2022 }
2023
2024 IInputMethod method;
2025 ClientState client;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002026
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002027 final Printer p = new PrintWriterPrinter(pw);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002029 synchronized (mMethodMap) {
2030 p.println("Current Input Method Manager state:");
2031 int N = mMethodList.size();
2032 p.println(" Input Methods:");
2033 for (int i=0; i<N; i++) {
2034 InputMethodInfo info = mMethodList.get(i);
2035 p.println(" InputMethod #" + i + ":");
2036 info.dump(p, " ");
2037 }
2038 p.println(" Clients:");
2039 for (ClientState ci : mClients.values()) {
2040 p.println(" Client " + ci + ":");
2041 p.println(" client=" + ci.client);
2042 p.println(" inputContext=" + ci.inputContext);
2043 p.println(" sessionRequested=" + ci.sessionRequested);
2044 p.println(" curSession=" + ci.curSession);
2045 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002046 p.println(" mCurMethodId=" + mCurMethodId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002047 client = mCurClient;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07002048 p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq);
2049 p.println(" mCurFocusedWindow=" + mCurFocusedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection
2051 + " mBoundToMethod=" + mBoundToMethod);
2052 p.println(" mCurToken=" + mCurToken);
2053 p.println(" mCurIntent=" + mCurIntent);
2054 method = mCurMethod;
2055 p.println(" mCurMethod=" + mCurMethod);
2056 p.println(" mEnabledSession=" + mEnabledSession);
2057 p.println(" mShowRequested=" + mShowRequested
2058 + " mShowExplicitlyRequested=" + mShowExplicitlyRequested
2059 + " mShowForced=" + mShowForced
2060 + " mInputShown=" + mInputShown);
Dianne Hackborncc278702009-09-02 23:07:23 -07002061 p.println(" mSystemReady=" + mSystemReady + " mScreenOn=" + mScreenOn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002062 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002063
Jeff Brownb88102f2010-09-08 11:49:43 -07002064 p.println(" ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 if (client != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002066 pw.flush();
2067 try {
2068 client.client.asBinder().dump(fd, args);
2069 } catch (RemoteException e) {
2070 p.println("Input method client dead: " + e);
2071 }
Jeff Brownb88102f2010-09-08 11:49:43 -07002072 } else {
2073 p.println("No input method client.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002075
Jeff Brownb88102f2010-09-08 11:49:43 -07002076 p.println(" ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002077 if (method != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 pw.flush();
2079 try {
2080 method.asBinder().dump(fd, args);
2081 } catch (RemoteException e) {
2082 p.println("Input method service dead: " + e);
2083 }
Jeff Brownb88102f2010-09-08 11:49:43 -07002084 } else {
2085 p.println("No input method service.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002086 }
2087 }
2088}