blob: dc4194cb16831f1bff40c68513faa9654ac6e17e [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;
87import java.util.List;
satok913a8922010-08-26 21:53:41 +090088import java.util.Map;
89import java.util.TreeMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
91/**
92 * This class provides a system service that manages input methods.
93 */
94public class InputMethodManagerService extends IInputMethodManager.Stub
95 implements ServiceConnection, Handler.Callback {
96 static final boolean DEBUG = false;
97 static final String TAG = "InputManagerService";
98
99 static final int MSG_SHOW_IM_PICKER = 1;
satokab751aa2010-09-14 19:17:36 +0900100 static final int MSG_SHOW_IM_SUBTYPE_PICKER = 2;
satok47a44912010-10-06 16:03:58 +0900101 static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 3;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 static final int MSG_UNBIND_INPUT = 1000;
104 static final int MSG_BIND_INPUT = 1010;
105 static final int MSG_SHOW_SOFT_INPUT = 1020;
106 static final int MSG_HIDE_SOFT_INPUT = 1030;
107 static final int MSG_ATTACH_TOKEN = 1040;
108 static final int MSG_CREATE_SESSION = 1050;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800109
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800110 static final int MSG_START_INPUT = 2000;
111 static final int MSG_RESTART_INPUT = 2010;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 static final int MSG_UNBIND_METHOD = 3000;
114 static final int MSG_BIND_METHOD = 3010;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 static final long TIME_TO_RECONNECT = 10*1000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800117
satokab751aa2010-09-14 19:17:36 +0900118 private static final int NOT_A_SUBTYPE_ID = -1;
119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 final Context mContext;
121 final Handler mHandler;
satokd87c2592010-09-29 11:52:06 +0900122 final InputMethodSettings mSettings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 final SettingsObserver mSettingsObserver;
Joe Onorato089de882010-04-12 08:18:45 -0700124 final StatusBarManagerService mStatusBar;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 final IWindowManager mIWindowManager;
126 final HandlerCaller mCaller;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 final InputBindResult mNoBinding = new InputBindResult(null, null, -1);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 // All known input methods. mMethodMap also serves as the global
131 // lock for this class.
satokd87c2592010-09-29 11:52:06 +0900132 final ArrayList<InputMethodInfo> mMethodList = new ArrayList<InputMethodInfo>();
133 final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<String, InputMethodInfo>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 class SessionState {
136 final ClientState client;
137 final IInputMethod method;
138 final IInputMethodSession session;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 @Override
141 public String toString() {
142 return "SessionState{uid " + client.uid + " pid " + client.pid
143 + " method " + Integer.toHexString(
144 System.identityHashCode(method))
145 + " session " + Integer.toHexString(
146 System.identityHashCode(session))
147 + "}";
148 }
149
150 SessionState(ClientState _client, IInputMethod _method,
151 IInputMethodSession _session) {
152 client = _client;
153 method = _method;
154 session = _session;
155 }
156 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 class ClientState {
159 final IInputMethodClient client;
160 final IInputContext inputContext;
161 final int uid;
162 final int pid;
163 final InputBinding binding;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 boolean sessionRequested;
166 SessionState curSession;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 @Override
169 public String toString() {
170 return "ClientState{" + Integer.toHexString(
171 System.identityHashCode(this)) + " uid " + uid
172 + " pid " + pid + "}";
173 }
174
175 ClientState(IInputMethodClient _client, IInputContext _inputContext,
176 int _uid, int _pid) {
177 client = _client;
178 inputContext = _inputContext;
179 uid = _uid;
180 pid = _pid;
181 binding = new InputBinding(null, inputContext.asBinder(), uid, pid);
182 }
183 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 final HashMap<IBinder, ClientState> mClients
186 = new HashMap<IBinder, ClientState>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800187
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 /**
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700189 * Set once the system is ready to run third party code.
190 */
191 boolean mSystemReady;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800192
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700193 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 * Id of the currently selected input method.
195 */
196 String mCurMethodId;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 /**
199 * The current binding sequence number, incremented every time there is
200 * a new bind performed.
201 */
202 int mCurSeq;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 /**
205 * The client that is currently bound to an input method.
206 */
207 ClientState mCurClient;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 /**
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700210 * The last window token that gained focus.
211 */
212 IBinder mCurFocusedWindow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800213
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700214 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 * The input context last provided by the current client.
216 */
217 IInputContext mCurInputContext;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 /**
220 * The attributes last provided by the current client.
221 */
222 EditorInfo mCurAttribute;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 /**
225 * The input method ID of the input method service that we are currently
226 * connected to or in the process of connecting to.
227 */
228 String mCurId;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 /**
satokab751aa2010-09-14 19:17:36 +0900231 * The current subtype of the current input method.
232 */
233 private InputMethodSubtype mCurrentSubtype;
234
235
236 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 * Set to true if our ServiceConnection is currently actively bound to
238 * a service (whether or not we have gotten its IBinder back yet).
239 */
240 boolean mHaveConnection;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 /**
243 * Set if the client has asked for the input method to be shown.
244 */
245 boolean mShowRequested;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 /**
248 * Set if we were explicitly told to show the input method.
249 */
250 boolean mShowExplicitlyRequested;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 /**
253 * Set if we were forced to be shown.
254 */
255 boolean mShowForced;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 /**
258 * Set if we last told the input method to show itself.
259 */
260 boolean mInputShown;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 /**
263 * The Intent used to connect to the current input method.
264 */
265 Intent mCurIntent;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 /**
268 * The token we have made for the currently active input method, to
269 * identify it in the future.
270 */
271 IBinder mCurToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800272
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 /**
274 * If non-null, this is the input method service we are currently connected
275 * to.
276 */
277 IInputMethod mCurMethod;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 /**
280 * Time that we last initiated a bind to the input method, to determine
281 * if we should try to disconnect and reconnect to it.
282 */
283 long mLastBindTime;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 /**
286 * Have we called mCurMethod.bindInput()?
287 */
288 boolean mBoundToMethod;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 /**
291 * Currently enabled session. Only touched by service thread, not
292 * protected by a lock.
293 */
294 SessionState mEnabledSession;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 /**
297 * True if the screen is on. The value is true initially.
298 */
299 boolean mScreenOn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 AlertDialog.Builder mDialogBuilder;
302 AlertDialog mSwitchingDialog;
303 InputMethodInfo[] mIms;
304 CharSequence[] mItems;
satokab751aa2010-09-14 19:17:36 +0900305 int[] mSubtypeIds;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 class SettingsObserver extends ContentObserver {
308 SettingsObserver(Handler handler) {
309 super(handler);
310 ContentResolver resolver = mContext.getContentResolver();
311 resolver.registerContentObserver(Settings.Secure.getUriFor(
312 Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
satokab751aa2010-09-14 19:17:36 +0900313 resolver.registerContentObserver(Settings.Secure.getUriFor(
314 Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 @Override public void onChange(boolean selfChange) {
318 synchronized (mMethodMap) {
319 updateFromSettingsLocked();
320 }
321 }
322 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800323
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 class ScreenOnOffReceiver extends android.content.BroadcastReceiver {
325 @Override
326 public void onReceive(Context context, Intent intent) {
327 if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
328 mScreenOn = true;
329 } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
330 mScreenOn = false;
The Android Open Source Project10592532009-03-18 17:39:46 -0700331 } else if (intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
332 hideInputMethodMenu();
333 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800335 Slog.w(TAG, "Unexpected intent " + intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 }
337
338 // Inform the current client of the change in active status
339 try {
340 if (mCurClient != null && mCurClient.client != null) {
341 mCurClient.client.setActive(mScreenOn);
342 }
343 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800344 Slog.w(TAG, "Got RemoteException sending 'screen on/off' notification to pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 + mCurClient.pid + " uid " + mCurClient.uid);
346 }
347 }
348 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800349
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800350 class MyPackageMonitor extends PackageMonitor {
351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 @Override
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800353 public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 synchronized (mMethodMap) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800355 String curInputMethodId = Settings.Secure.getString(mContext
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
357 final int N = mMethodList.size();
358 if (curInputMethodId != null) {
359 for (int i=0; i<N; i++) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800360 InputMethodInfo imi = mMethodList.get(i);
361 if (imi.getId().equals(curInputMethodId)) {
362 for (String pkg : packages) {
363 if (imi.getPackageName().equals(pkg)) {
364 if (!doit) {
365 return true;
366 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800367 Settings.Secure.putString(mContext.getContentResolver(),
368 Settings.Secure.DEFAULT_INPUT_METHOD, "");
satokab751aa2010-09-14 19:17:36 +0900369 resetSelectedInputMethodSubtype();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800370 chooseNewDefaultIMELocked();
371 return true;
372 }
373 }
374 }
375 }
376 }
377 }
378 return false;
379 }
380
381 @Override
382 public void onSomePackagesChanged() {
383 synchronized (mMethodMap) {
384 InputMethodInfo curIm = null;
385 String curInputMethodId = Settings.Secure.getString(mContext
386 .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
387 final int N = mMethodList.size();
388 if (curInputMethodId != null) {
389 for (int i=0; i<N; i++) {
390 InputMethodInfo imi = mMethodList.get(i);
391 if (imi.getId().equals(curInputMethodId)) {
392 curIm = imi;
393 }
394 int change = isPackageDisappearing(imi.getPackageName());
395 if (change == PACKAGE_TEMPORARY_CHANGE
396 || change == PACKAGE_PERMANENT_CHANGE) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800397 Slog.i(TAG, "Input method uninstalled, disabling: "
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800398 + imi.getComponent());
399 setInputMethodEnabledLocked(imi.getId(), false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 }
401 }
402 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800403
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800404 buildInputMethodListLocked(mMethodList, mMethodMap);
405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800407
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800408 if (curIm != null) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800409 int change = isPackageDisappearing(curIm.getPackageName());
410 if (change == PACKAGE_TEMPORARY_CHANGE
411 || change == PACKAGE_PERMANENT_CHANGE) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800412 ServiceInfo si = null;
413 try {
414 si = mContext.getPackageManager().getServiceInfo(
415 curIm.getComponent(), 0);
416 } catch (PackageManager.NameNotFoundException ex) {
417 }
418 if (si == null) {
419 // Uh oh, current input method is no longer around!
420 // Pick another one...
Joe Onorato8a9b2202010-02-26 18:56:32 -0800421 Slog.i(TAG, "Current input method removed: " + curInputMethodId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800422 if (!chooseNewDefaultIMELocked()) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800423 changed = true;
424 curIm = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800425 Slog.i(TAG, "Unsetting current input method");
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800426 Settings.Secure.putString(mContext.getContentResolver(),
satokab751aa2010-09-14 19:17:36 +0900427 Settings.Secure.DEFAULT_INPUT_METHOD, "");
428 resetSelectedInputMethodSubtype();
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800429 }
430 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800431 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800432 }
satokab751aa2010-09-14 19:17:36 +0900433
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800434 if (curIm == null) {
435 // We currently don't have a default input method... is
436 // one now available?
437 changed = chooseNewDefaultIMELocked();
438 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800439
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800440 if (changed) {
441 updateFromSettingsLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 }
443 }
444 }
445 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800446
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 class MethodCallback extends IInputMethodCallback.Stub {
448 final IInputMethod mMethod;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 MethodCallback(IInputMethod method) {
451 mMethod = method;
452 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 public void finishedEvent(int seq, boolean handled) throws RemoteException {
455 }
456
457 public void sessionCreated(IInputMethodSession session) throws RemoteException {
458 onSessionCreated(mMethod, session);
459 }
460 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800461
Joe Onorato089de882010-04-12 08:18:45 -0700462 public InputMethodManagerService(Context context, StatusBarManagerService statusBar) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 mContext = context;
464 mHandler = new Handler(this);
465 mIWindowManager = IWindowManager.Stub.asInterface(
466 ServiceManager.getService(Context.WINDOW_SERVICE));
467 mCaller = new HandlerCaller(context, new HandlerCaller.Callback() {
468 public void executeMessage(Message msg) {
469 handleMessage(msg);
470 }
471 });
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800472
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800473 (new MyPackageMonitor()).register(mContext, true);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 IntentFilter screenOnOffFilt = new IntentFilter();
476 screenOnOffFilt.addAction(Intent.ACTION_SCREEN_ON);
477 screenOnOffFilt.addAction(Intent.ACTION_SCREEN_OFF);
The Android Open Source Project10592532009-03-18 17:39:46 -0700478 screenOnOffFilt.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 mContext.registerReceiver(new ScreenOnOffReceiver(), screenOnOffFilt);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800480
satok913a8922010-08-26 21:53:41 +0900481 mStatusBar = statusBar;
482 statusBar.setIconVisibility("ime", false);
483
satokd87c2592010-09-29 11:52:06 +0900484 // mSettings should be created before buildInputMethodListLocked
485 mSettings = new InputMethodSettings(context.getContentResolver(), mMethodMap, mMethodList);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 buildInputMethodListLocked(mMethodList, mMethodMap);
satokd87c2592010-09-29 11:52:06 +0900487 mSettings.enableAllIMEsIfThereIsNoEnabledIME();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488
satokd87c2592010-09-29 11:52:06 +0900489 if (TextUtils.isEmpty(Settings.Secure.getString(
490 mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD))) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 InputMethodInfo defIm = null;
satokd87c2592010-09-29 11:52:06 +0900492 for (InputMethodInfo imi: mMethodList) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 if (defIm == null && imi.getIsDefaultResourceId() != 0) {
494 try {
satokd87c2592010-09-29 11:52:06 +0900495 Resources res = context.createPackageContext(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 imi.getPackageName(), 0).getResources();
497 if (res.getBoolean(imi.getIsDefaultResourceId())) {
498 defIm = imi;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800499 Slog.i(TAG, "Selected default: " + imi.getId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 }
501 } catch (PackageManager.NameNotFoundException ex) {
502 } catch (Resources.NotFoundException ex) {
503 }
504 }
505 }
satokd87c2592010-09-29 11:52:06 +0900506 if (defIm == null && mMethodList.size() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 defIm = mMethodList.get(0);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800508 Slog.i(TAG, "No default found, using " + defIm.getId());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 if (defIm != null) {
511 Settings.Secure.putString(mContext.getContentResolver(),
512 Settings.Secure.DEFAULT_INPUT_METHOD, defIm.getId());
satokab751aa2010-09-14 19:17:36 +0900513 putSelectedInputMethodSubtype(defIm, NOT_A_SUBTYPE_ID);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 }
515 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 mSettingsObserver = new SettingsObserver(mHandler);
518 updateFromSettingsLocked();
519 }
520
521 @Override
522 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
523 throws RemoteException {
524 try {
525 return super.onTransact(code, data, reply, flags);
526 } catch (RuntimeException e) {
527 // The input method manager only throws security exceptions, so let's
528 // log all others.
529 if (!(e instanceof SecurityException)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800530 Slog.e(TAG, "Input Method Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 }
532 throw e;
533 }
534 }
535
536 public void systemReady() {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700537 synchronized (mMethodMap) {
538 if (!mSystemReady) {
539 mSystemReady = true;
Dianne Hackborncc278702009-09-02 23:07:23 -0700540 try {
541 startInputInnerLocked();
542 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800543 Slog.w(TAG, "Unexpected exception", e);
Dianne Hackborncc278702009-09-02 23:07:23 -0700544 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700545 }
546 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800548
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 public List<InputMethodInfo> getInputMethodList() {
550 synchronized (mMethodMap) {
551 return new ArrayList<InputMethodInfo>(mMethodList);
552 }
553 }
554
555 public List<InputMethodInfo> getEnabledInputMethodList() {
556 synchronized (mMethodMap) {
satokd87c2592010-09-29 11:52:06 +0900557 return mSettings.getEnabledInputMethodListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 }
559 }
560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 public void addClient(IInputMethodClient client,
562 IInputContext inputContext, int uid, int pid) {
563 synchronized (mMethodMap) {
564 mClients.put(client.asBinder(), new ClientState(client,
565 inputContext, uid, pid));
566 }
567 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800568
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 public void removeClient(IInputMethodClient client) {
570 synchronized (mMethodMap) {
571 mClients.remove(client.asBinder());
572 }
573 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800574
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 void executeOrSendMessage(IInterface target, Message msg) {
576 if (target.asBinder() instanceof Binder) {
577 mCaller.sendMessage(msg);
578 } else {
579 handleMessage(msg);
580 msg.recycle();
581 }
582 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800583
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700584 void unbindCurrentClientLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 if (mCurClient != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800586 if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 + mCurClient.client.asBinder());
588 if (mBoundToMethod) {
589 mBoundToMethod = false;
590 if (mCurMethod != null) {
591 executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
592 MSG_UNBIND_INPUT, mCurMethod));
593 }
594 }
595 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
596 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
597 mCurClient.sessionRequested = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 // Call setActive(false) on the old client
600 try {
601 mCurClient.client.setActive(false);
602 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800603 Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604 + mCurClient.pid + " uid " + mCurClient.uid);
605 }
606 mCurClient = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800607
The Android Open Source Project10592532009-03-18 17:39:46 -0700608 hideInputMethodMenuLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 }
610 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800611
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 private int getImeShowFlags() {
613 int flags = 0;
614 if (mShowForced) {
615 flags |= InputMethod.SHOW_FORCED
616 | InputMethod.SHOW_EXPLICIT;
617 } else if (mShowExplicitlyRequested) {
618 flags |= InputMethod.SHOW_EXPLICIT;
619 }
620 return flags;
621 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 private int getAppShowFlags() {
624 int flags = 0;
625 if (mShowForced) {
626 flags |= InputMethodManager.SHOW_FORCED;
627 } else if (!mShowExplicitlyRequested) {
628 flags |= InputMethodManager.SHOW_IMPLICIT;
629 }
630 return flags;
631 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 InputBindResult attachNewInputLocked(boolean initial, boolean needResult) {
634 if (!mBoundToMethod) {
635 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
636 MSG_BIND_INPUT, mCurMethod, mCurClient.binding));
637 mBoundToMethod = true;
638 }
639 final SessionState session = mCurClient.curSession;
640 if (initial) {
641 executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
642 MSG_START_INPUT, session, mCurInputContext, mCurAttribute));
643 } else {
644 executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
645 MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute));
646 }
647 if (mShowRequested) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800648 if (DEBUG) Slog.v(TAG, "Attach new input asks to show input");
The Android Open Source Project4df24232009-03-05 14:34:35 -0800649 showCurrentInputLocked(getAppShowFlags(), null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 }
651 return needResult
652 ? new InputBindResult(session.session, mCurId, mCurSeq)
653 : null;
654 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 InputBindResult startInputLocked(IInputMethodClient client,
657 IInputContext inputContext, EditorInfo attribute,
658 boolean initial, boolean needResult) {
659 // If no method is currently selected, do nothing.
660 if (mCurMethodId == null) {
661 return mNoBinding;
662 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 ClientState cs = mClients.get(client.asBinder());
665 if (cs == null) {
666 throw new IllegalArgumentException("unknown client "
667 + client.asBinder());
668 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800669
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 try {
671 if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
672 // Check with the window manager to make sure this client actually
673 // has a window with focus. If not, reject. This is thread safe
674 // because if the focus changes some time before or after, the
675 // next client receiving focus that has any interest in input will
676 // be calling through here after that change happens.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800677 Slog.w(TAG, "Starting input on non-focused client " + cs.client
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
679 return null;
680 }
681 } catch (RemoteException e) {
682 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800683
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 if (mCurClient != cs) {
685 // If the client is changing, we need to switch over to the new
686 // one.
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700687 unbindCurrentClientLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -0800688 if (DEBUG) Slog.v(TAG, "switching to client: client = "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 + cs.client.asBinder());
690
691 // If the screen is on, inform the new client it is active
692 if (mScreenOn) {
693 try {
694 cs.client.setActive(mScreenOn);
695 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800696 Slog.w(TAG, "Got RemoteException sending setActive notification to pid "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 + cs.pid + " uid " + cs.uid);
698 }
699 }
700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800702 // Bump up the sequence for this client and attach it.
703 mCurSeq++;
704 if (mCurSeq <= 0) mCurSeq = 1;
705 mCurClient = cs;
706 mCurInputContext = inputContext;
707 mCurAttribute = attribute;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 // Check if the input method is changing.
710 if (mCurId != null && mCurId.equals(mCurMethodId)) {
711 if (cs.curSession != null) {
712 // Fast case: if we are already connected to the input method,
713 // then just return it.
714 return attachNewInputLocked(initial, needResult);
715 }
716 if (mHaveConnection) {
717 if (mCurMethod != null) {
718 if (!cs.sessionRequested) {
719 cs.sessionRequested = true;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800720 if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800721 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
722 MSG_CREATE_SESSION, mCurMethod,
723 new MethodCallback(mCurMethod)));
724 }
725 // Return to client, and we will get back with it when
726 // we have had a session made for it.
727 return new InputBindResult(null, mCurId, mCurSeq);
728 } else if (SystemClock.uptimeMillis()
729 < (mLastBindTime+TIME_TO_RECONNECT)) {
730 // In this case we have connected to the service, but
731 // don't yet have its interface. If it hasn't been too
732 // long since we did the connection, we'll return to
733 // the client and wait to get the service interface so
734 // we can report back. If it has been too long, we want
735 // to fall through so we can try a disconnect/reconnect
736 // to see if we can get back in touch with the service.
737 return new InputBindResult(null, mCurId, mCurSeq);
738 } else {
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800739 EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME,
740 mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 }
742 }
743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800744
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700745 return startInputInnerLocked();
746 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800747
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700748 InputBindResult startInputInnerLocked() {
749 if (mCurMethodId == null) {
750 return mNoBinding;
751 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800752
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700753 if (!mSystemReady) {
754 // If the system is not yet ready, we shouldn't be running third
755 // party code.
Dianne Hackborncc278702009-09-02 23:07:23 -0700756 return new InputBindResult(null, mCurMethodId, mCurSeq);
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700757 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 InputMethodInfo info = mMethodMap.get(mCurMethodId);
760 if (info == null) {
761 throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
762 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800763
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700764 unbindCurrentMethodLocked(false);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800765
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE);
767 mCurIntent.setComponent(info.getComponent());
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700768 mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
769 com.android.internal.R.string.input_method_binding_label);
770 mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
771 mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 if (mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE)) {
773 mLastBindTime = SystemClock.uptimeMillis();
774 mHaveConnection = true;
775 mCurId = info.getId();
776 mCurToken = new Binder();
777 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800778 if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 mIWindowManager.addWindowToken(mCurToken,
780 WindowManager.LayoutParams.TYPE_INPUT_METHOD);
781 } catch (RemoteException e) {
782 }
783 return new InputBindResult(null, mCurId, mCurSeq);
784 } else {
785 mCurIntent = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800786 Slog.w(TAG, "Failure connecting to input method service: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 + mCurIntent);
788 }
789 return null;
790 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 public InputBindResult startInput(IInputMethodClient client,
793 IInputContext inputContext, EditorInfo attribute,
794 boolean initial, boolean needResult) {
795 synchronized (mMethodMap) {
796 final long ident = Binder.clearCallingIdentity();
797 try {
798 return startInputLocked(client, inputContext, attribute,
799 initial, needResult);
800 } finally {
801 Binder.restoreCallingIdentity(ident);
802 }
803 }
804 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 public void finishInput(IInputMethodClient client) {
807 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800808
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 public void onServiceConnected(ComponentName name, IBinder service) {
810 synchronized (mMethodMap) {
811 if (mCurIntent != null && name.equals(mCurIntent.getComponent())) {
812 mCurMethod = IInputMethod.Stub.asInterface(service);
Dianne Hackborncc278702009-09-02 23:07:23 -0700813 if (mCurToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800814 Slog.w(TAG, "Service connected without a token!");
Dianne Hackborncc278702009-09-02 23:07:23 -0700815 unbindCurrentMethodLocked(false);
816 return;
817 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800818 if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken);
Dianne Hackborncc278702009-09-02 23:07:23 -0700819 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
820 MSG_ATTACH_TOKEN, mCurMethod, mCurToken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 if (mCurClient != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800822 if (DEBUG) Slog.v(TAG, "Creating first session while with client "
Dianne Hackborncc278702009-09-02 23:07:23 -0700823 + mCurClient);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
Dianne Hackborncc278702009-09-02 23:07:23 -0700825 MSG_CREATE_SESSION, mCurMethod,
826 new MethodCallback(mCurMethod)));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 }
828 }
829 }
830 }
831
832 void onSessionCreated(IInputMethod method, IInputMethodSession session) {
833 synchronized (mMethodMap) {
834 if (mCurMethod != null && method != null
835 && mCurMethod.asBinder() == method.asBinder()) {
836 if (mCurClient != null) {
837 mCurClient.curSession = new SessionState(mCurClient,
838 method, session);
839 mCurClient.sessionRequested = false;
840 InputBindResult res = attachNewInputLocked(true, true);
841 if (res.method != null) {
842 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO(
843 MSG_BIND_METHOD, mCurClient.client, res));
844 }
845 }
846 }
847 }
848 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800849
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700850 void unbindCurrentMethodLocked(boolean reportToClient) {
851 if (mHaveConnection) {
852 mContext.unbindService(this);
853 mHaveConnection = false;
854 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800855
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700856 if (mCurToken != null) {
857 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800858 if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700859 mIWindowManager.removeWindowToken(mCurToken);
860 } catch (RemoteException e) {
861 }
862 mCurToken = null;
863 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800864
The Android Open Source Project10592532009-03-18 17:39:46 -0700865 mCurId = null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700866 clearCurMethodLocked();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800867
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700868 if (reportToClient && mCurClient != null) {
869 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
870 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
871 }
872 }
873
Devin Taylor0c33ed22010-02-23 13:26:46 -0600874 private void finishSession(SessionState sessionState) {
875 if (sessionState != null && sessionState.session != null) {
876 try {
877 sessionState.session.finishSession();
878 } catch (RemoteException e) {
Jean-Baptiste Queru9d0f6df2010-03-29 12:55:09 -0700879 Slog.w(TAG, "Session failed to close due to remote exception", e);
Devin Taylor0c33ed22010-02-23 13:26:46 -0600880 }
881 }
882 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800883
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700884 void clearCurMethodLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 if (mCurMethod != null) {
886 for (ClientState cs : mClients.values()) {
887 cs.sessionRequested = false;
Devin Taylor0c33ed22010-02-23 13:26:46 -0600888 finishSession(cs.curSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 cs.curSession = null;
890 }
Devin Taylor0c33ed22010-02-23 13:26:46 -0600891
892 finishSession(mEnabledSession);
893 mEnabledSession = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 mCurMethod = null;
895 }
Joe Onorato0cbda992010-05-02 16:28:15 -0700896 mStatusBar.setIconVisibility("ime", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800898
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 public void onServiceDisconnected(ComponentName name) {
900 synchronized (mMethodMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800901 if (DEBUG) Slog.v(TAG, "Service disconnected: " + name
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 + " mCurIntent=" + mCurIntent);
903 if (mCurMethod != null && mCurIntent != null
904 && name.equals(mCurIntent.getComponent())) {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700905 clearCurMethodLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 // We consider this to be a new bind attempt, since the system
907 // should now try to restart the service for us.
908 mLastBindTime = SystemClock.uptimeMillis();
909 mShowRequested = mInputShown;
910 mInputShown = false;
911 if (mCurClient != null) {
912 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
913 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
914 }
915 }
916 }
917 }
918
919 public void updateStatusIcon(IBinder token, String packageName, int iconId) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -0700920 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800921 long ident = Binder.clearCallingIdentity();
922 try {
923 if (token == null || mCurToken != token) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -0700924 Slog.w(TAG, "Ignoring setInputMethod of uid " + uid + " token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 return;
926 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800927
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 synchronized (mMethodMap) {
929 if (iconId == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800930 if (DEBUG) Slog.d(TAG, "hide the small icon for the input method");
Joe Onorato0cbda992010-05-02 16:28:15 -0700931 mStatusBar.setIconVisibility("ime", false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 } else if (packageName != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800933 if (DEBUG) Slog.d(TAG, "show a small icon for the input method");
Joe Onorato0cbda992010-05-02 16:28:15 -0700934 mStatusBar.setIcon("ime", packageName, iconId, 0);
935 mStatusBar.setIconVisibility("ime", true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 }
937 }
938 } finally {
939 Binder.restoreCallingIdentity(ident);
940 }
941 }
942
943 void updateFromSettingsLocked() {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700944 // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and
945 // ENABLED_INPUT_METHODS is taking care of keeping them correctly in
946 // sync, so we will never have a DEFAULT_INPUT_METHOD that is not
947 // enabled.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 String id = Settings.Secure.getString(mContext.getContentResolver(),
satokab751aa2010-09-14 19:17:36 +0900949 Settings.Secure.DEFAULT_INPUT_METHOD);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700950 if (id != null && id.length() > 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 try {
satokab751aa2010-09-14 19:17:36 +0900952 setInputMethodLocked(id, getSelectedInputMethodSubtypeId(id));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800954 Slog.w(TAG, "Unknown input method from prefs: " + id, e);
The Android Open Source Project10592532009-03-18 17:39:46 -0700955 mCurMethodId = null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700956 unbindCurrentMethodLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700958 } else {
959 // There is no longer an input method set, so stop any current one.
The Android Open Source Project10592532009-03-18 17:39:46 -0700960 mCurMethodId = null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700961 unbindCurrentMethodLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 }
963 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800964
satokab751aa2010-09-14 19:17:36 +0900965 /* package */ void setInputMethodLocked(String id, int subtypeId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 InputMethodInfo info = mMethodMap.get(id);
967 if (info == null) {
satok913a8922010-08-26 21:53:41 +0900968 throw new IllegalArgumentException("Unknown id: " + id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 if (id.equals(mCurMethodId)) {
satokab751aa2010-09-14 19:17:36 +0900972 if (subtypeId != NOT_A_SUBTYPE_ID) {
973 InputMethodSubtype subtype = info.getSubtypes().get(subtypeId);
974 if (subtype != mCurrentSubtype) {
975 synchronized (mMethodMap) {
976 if (mCurMethod != null) {
977 try {
978 putSelectedInputMethodSubtype(info, subtypeId);
979 mCurMethod.changeInputMethodSubtype(subtype);
980 } catch (RemoteException e) {
981 return;
982 }
983 }
984 }
985 }
986 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 return;
988 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800989
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 final long ident = Binder.clearCallingIdentity();
991 try {
992 mCurMethodId = id;
satokab751aa2010-09-14 19:17:36 +0900993 // Set a subtype to this input method.
994 // subtypeId the name of a subtype which will be set.
995 if (putSelectedInputMethodSubtype(info, subtypeId)) {
996 mCurrentSubtype = info.getSubtypes().get(subtypeId);
997 } else {
998 mCurrentSubtype = null;
999 }
1000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 Settings.Secure.putString(mContext.getContentResolver(),
satokab751aa2010-09-14 19:17:36 +09001002 Settings.Secure.DEFAULT_INPUT_METHOD, id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003
1004 if (ActivityManagerNative.isSystemReady()) {
1005 Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001006 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 intent.putExtra("input_method_id", id);
1008 mContext.sendBroadcast(intent);
1009 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001010 unbindCurrentClientLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 } finally {
1012 Binder.restoreCallingIdentity(ident);
1013 }
1014 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001015
The Android Open Source Project4df24232009-03-05 14:34:35 -08001016 public boolean showSoftInput(IInputMethodClient client, int flags,
1017 ResultReceiver resultReceiver) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001018 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001019 long ident = Binder.clearCallingIdentity();
1020 try {
1021 synchronized (mMethodMap) {
1022 if (mCurClient == null || client == null
1023 || mCurClient.client.asBinder() != client.asBinder()) {
1024 try {
1025 // We need to check if this is the current client with
1026 // focus in the window manager, to allow this call to
1027 // be made before input is started in it.
1028 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001029 Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client);
The Android Open Source Project4df24232009-03-05 14:34:35 -08001030 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 }
1032 } catch (RemoteException e) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001033 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 }
1035 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001036
Joe Onorato8a9b2202010-02-26 18:56:32 -08001037 if (DEBUG) Slog.v(TAG, "Client requesting input be shown");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001038 return showCurrentInputLocked(flags, resultReceiver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 }
1040 } finally {
1041 Binder.restoreCallingIdentity(ident);
1042 }
1043 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001044
The Android Open Source Project4df24232009-03-05 14:34:35 -08001045 boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 mShowRequested = true;
1047 if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) {
1048 mShowExplicitlyRequested = true;
1049 }
1050 if ((flags&InputMethodManager.SHOW_FORCED) != 0) {
1051 mShowExplicitlyRequested = true;
1052 mShowForced = true;
1053 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001054
Dianne Hackborncc278702009-09-02 23:07:23 -07001055 if (!mSystemReady) {
1056 return false;
1057 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001058
The Android Open Source Project4df24232009-03-05 14:34:35 -08001059 boolean res = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001060 if (mCurMethod != null) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001061 executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO(
1062 MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod,
1063 resultReceiver));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001064 mInputShown = true;
The Android Open Source Project4df24232009-03-05 14:34:35 -08001065 res = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 } else if (mHaveConnection && SystemClock.uptimeMillis()
1067 < (mLastBindTime+TIME_TO_RECONNECT)) {
1068 // The client has asked to have the input method shown, but
1069 // we have been sitting here too long with a connection to the
1070 // service and no interface received, so let's disconnect/connect
1071 // to try to prod things along.
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001072 EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 SystemClock.uptimeMillis()-mLastBindTime,1);
1074 mContext.unbindService(this);
1075 mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE);
1076 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001077
The Android Open Source Project4df24232009-03-05 14:34:35 -08001078 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001080
The Android Open Source Project4df24232009-03-05 14:34:35 -08001081 public boolean hideSoftInput(IInputMethodClient client, int flags,
1082 ResultReceiver resultReceiver) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001083 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 long ident = Binder.clearCallingIdentity();
1085 try {
1086 synchronized (mMethodMap) {
1087 if (mCurClient == null || client == null
1088 || mCurClient.client.asBinder() != client.asBinder()) {
1089 try {
1090 // We need to check if this is the current client with
1091 // focus in the window manager, to allow this call to
1092 // be made before input is started in it.
1093 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001094 if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid "
1095 + uid + ": " + client);
The Android Open Source Project4df24232009-03-05 14:34:35 -08001096 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 }
1098 } catch (RemoteException e) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001099 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 }
1101 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001102
Joe Onorato8a9b2202010-02-26 18:56:32 -08001103 if (DEBUG) Slog.v(TAG, "Client requesting input be hidden");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001104 return hideCurrentInputLocked(flags, resultReceiver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 }
1106 } finally {
1107 Binder.restoreCallingIdentity(ident);
1108 }
1109 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001110
The Android Open Source Project4df24232009-03-05 14:34:35 -08001111 boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0
1113 && (mShowExplicitlyRequested || mShowForced)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001114 if (DEBUG) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001115 "Not hiding: explicit show not cancelled by non-explicit hide");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001116 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 }
1118 if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001119 if (DEBUG) Slog.v(TAG,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 "Not hiding: forced show not cancelled by not-always hide");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001121 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08001123 boolean res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 if (mInputShown && mCurMethod != null) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001125 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
1126 MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver));
1127 res = true;
1128 } else {
1129 res = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 }
1131 mInputShown = false;
1132 mShowRequested = false;
1133 mShowExplicitlyRequested = false;
1134 mShowForced = false;
The Android Open Source Project4df24232009-03-05 14:34:35 -08001135 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001137
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001138 public void windowGainedFocus(IInputMethodClient client, IBinder windowToken,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 boolean viewHasFocus, boolean isTextEditor, int softInputMode,
1140 boolean first, int windowFlags) {
1141 long ident = Binder.clearCallingIdentity();
1142 try {
1143 synchronized (mMethodMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001144 if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 + " viewHasFocus=" + viewHasFocus
1146 + " isTextEditor=" + isTextEditor
1147 + " softInputMode=#" + Integer.toHexString(softInputMode)
1148 + " first=" + first + " flags=#"
1149 + Integer.toHexString(windowFlags));
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 if (mCurClient == null || client == null
1152 || mCurClient.client.asBinder() != client.asBinder()) {
1153 try {
1154 // We need to check if this is the current client with
1155 // focus in the window manager, to allow this call to
1156 // be made before input is started in it.
1157 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001158 Slog.w(TAG, "Client not active, ignoring focus gain of: " + client);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 return;
1160 }
1161 } catch (RemoteException e) {
1162 }
1163 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001164
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001165 if (mCurFocusedWindow == windowToken) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001166 Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001167 return;
1168 }
1169 mCurFocusedWindow = windowToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) {
1172 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
1173 if (!isTextEditor || (softInputMode &
1174 WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
1175 != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) {
1176 if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) {
1177 // There is no focus view, and this window will
1178 // be behind any soft input window, so hide the
1179 // soft input window if it is shown.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001180 if (DEBUG) Slog.v(TAG, "Unspecified window will hide input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001181 hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 }
1183 } else if (isTextEditor && (softInputMode &
1184 WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
1185 == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
1186 && (softInputMode &
1187 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
1188 // There is a focus view, and we are navigating forward
1189 // into the window, so show the input window for the user.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001190 if (DEBUG) Slog.v(TAG, "Unspecified window will show input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001191 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 }
1193 break;
1194 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
1195 // Do nothing.
1196 break;
1197 case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN:
1198 if ((softInputMode &
1199 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001200 if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001201 hideCurrentInputLocked(0, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 }
1203 break;
1204 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08001205 if (DEBUG) Slog.v(TAG, "Window asks to hide input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001206 hideCurrentInputLocked(0, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 break;
1208 case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
1209 if ((softInputMode &
1210 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001211 if (DEBUG) Slog.v(TAG, "Window asks to show input going forward");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001212 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 }
1214 break;
1215 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
Joe Onorato8a9b2202010-02-26 18:56:32 -08001216 if (DEBUG) Slog.v(TAG, "Window asks to always show input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001217 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001218 break;
1219 }
1220 }
1221 } finally {
1222 Binder.restoreCallingIdentity(ident);
1223 }
1224 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 public void showInputMethodPickerFromClient(IInputMethodClient client) {
1227 synchronized (mMethodMap) {
1228 if (mCurClient == null || client == null
1229 || mCurClient.client.asBinder() != client.asBinder()) {
satok47a44912010-10-06 16:03:58 +09001230 Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid "
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001231 + Binder.getCallingUid() + ": " + client);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 }
1233
1234 mHandler.sendEmptyMessage(MSG_SHOW_IM_PICKER);
1235 }
1236 }
1237
satokab751aa2010-09-14 19:17:36 +09001238 public void showInputMethodSubtypePickerFromClient(IInputMethodClient client) {
1239 synchronized (mMethodMap) {
1240 if (mCurClient == null || client == null
1241 || mCurClient.client.asBinder() != client.asBinder()) {
satok47a44912010-10-06 16:03:58 +09001242 Slog.w(TAG, "Ignoring showInputMethodSubtypePickerFromClient of: " + client);
satokab751aa2010-09-14 19:17:36 +09001243 }
1244
1245 mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER);
1246 }
1247 }
1248
satok47a44912010-10-06 16:03:58 +09001249 public void showInputMethodAndSubtypeEnablerFromClient(
1250 IInputMethodClient client, String topId) {
1251 // TODO: Handle topId for setting the top position of the list activity
1252 synchronized (mMethodMap) {
1253 if (mCurClient == null || client == null
1254 || mCurClient.client.asBinder() != client.asBinder()) {
1255 Slog.w(TAG, "Ignoring showInputMethodAndSubtypeEnablerFromClient of: " + client);
1256 }
1257
1258 mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_ENABLER);
1259 }
1260 }
1261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001262 public void setInputMethod(IBinder token, String id) {
satokab751aa2010-09-14 19:17:36 +09001263 setInputMethodWithSubtype(token, id, NOT_A_SUBTYPE_ID);
1264 }
1265
1266 private void setInputMethodWithSubtype(IBinder token, String id, int subtypeId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 synchronized (mMethodMap) {
1268 if (token == null) {
1269 if (mContext.checkCallingOrSelfPermission(
1270 android.Manifest.permission.WRITE_SECURE_SETTINGS)
1271 != PackageManager.PERMISSION_GRANTED) {
1272 throw new SecurityException(
1273 "Using null token requires permission "
1274 + android.Manifest.permission.WRITE_SECURE_SETTINGS);
1275 }
1276 } else if (mCurToken != token) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001277 Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid()
1278 + " token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 return;
1280 }
1281
1282 long ident = Binder.clearCallingIdentity();
1283 try {
satokab751aa2010-09-14 19:17:36 +09001284 setInputMethodLocked(id, subtypeId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 } finally {
1286 Binder.restoreCallingIdentity(ident);
1287 }
1288 }
1289 }
1290
1291 public void hideMySoftInput(IBinder token, int flags) {
1292 synchronized (mMethodMap) {
1293 if (token == null || mCurToken != token) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001294 if (DEBUG) Slog.w(TAG, "Ignoring hideInputMethod of uid "
1295 + Binder.getCallingUid() + " token: " + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 return;
1297 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 long ident = Binder.clearCallingIdentity();
1299 try {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001300 hideCurrentInputLocked(flags, null);
1301 } finally {
1302 Binder.restoreCallingIdentity(ident);
1303 }
1304 }
1305 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001306
The Android Open Source Project4df24232009-03-05 14:34:35 -08001307 public void showMySoftInput(IBinder token, int flags) {
1308 synchronized (mMethodMap) {
1309 if (token == null || mCurToken != token) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001310 Slog.w(TAG, "Ignoring showMySoftInput of uid "
1311 + Binder.getCallingUid() + " token: " + token);
The Android Open Source Project4df24232009-03-05 14:34:35 -08001312 return;
1313 }
1314 long ident = Binder.clearCallingIdentity();
1315 try {
1316 showCurrentInputLocked(flags, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 } finally {
1318 Binder.restoreCallingIdentity(ident);
1319 }
1320 }
1321 }
1322
1323 void setEnabledSessionInMainThread(SessionState session) {
1324 if (mEnabledSession != session) {
1325 if (mEnabledSession != null) {
1326 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001327 if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 mEnabledSession.method.setSessionEnabled(
1329 mEnabledSession.session, false);
1330 } catch (RemoteException e) {
1331 }
1332 }
1333 mEnabledSession = session;
1334 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001335 if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001336 session.method.setSessionEnabled(
1337 session.session, true);
1338 } catch (RemoteException e) {
1339 }
1340 }
1341 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001343 public boolean handleMessage(Message msg) {
1344 HandlerCaller.SomeArgs args;
1345 switch (msg.what) {
1346 case MSG_SHOW_IM_PICKER:
1347 showInputMethodMenu();
1348 return true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001349
satokab751aa2010-09-14 19:17:36 +09001350 case MSG_SHOW_IM_SUBTYPE_PICKER:
1351 showInputMethodSubtypeMenu();
1352 return true;
1353
satok47a44912010-10-06 16:03:58 +09001354 case MSG_SHOW_IM_SUBTYPE_ENABLER:
1355 showInputMethodAndSubtypeEnabler();
1356 return true;
1357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001358 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 case MSG_UNBIND_INPUT:
1361 try {
1362 ((IInputMethod)msg.obj).unbindInput();
1363 } catch (RemoteException e) {
1364 // There is nothing interesting about the method dying.
1365 }
1366 return true;
1367 case MSG_BIND_INPUT:
1368 args = (HandlerCaller.SomeArgs)msg.obj;
1369 try {
1370 ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2);
1371 } catch (RemoteException e) {
1372 }
1373 return true;
1374 case MSG_SHOW_SOFT_INPUT:
The Android Open Source Project4df24232009-03-05 14:34:35 -08001375 args = (HandlerCaller.SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 try {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001377 ((IInputMethod)args.arg1).showSoftInput(msg.arg1,
1378 (ResultReceiver)args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379 } catch (RemoteException e) {
1380 }
1381 return true;
1382 case MSG_HIDE_SOFT_INPUT:
The Android Open Source Project4df24232009-03-05 14:34:35 -08001383 args = (HandlerCaller.SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 try {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001385 ((IInputMethod)args.arg1).hideSoftInput(0,
1386 (ResultReceiver)args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001387 } catch (RemoteException e) {
1388 }
1389 return true;
1390 case MSG_ATTACH_TOKEN:
1391 args = (HandlerCaller.SomeArgs)msg.obj;
1392 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001393 if (DEBUG) Slog.v(TAG, "Sending attach of token: " + args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2);
1395 } catch (RemoteException e) {
1396 }
1397 return true;
1398 case MSG_CREATE_SESSION:
1399 args = (HandlerCaller.SomeArgs)msg.obj;
1400 try {
1401 ((IInputMethod)args.arg1).createSession(
1402 (IInputMethodCallback)args.arg2);
1403 } catch (RemoteException e) {
1404 }
1405 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 case MSG_START_INPUT:
1409 args = (HandlerCaller.SomeArgs)msg.obj;
1410 try {
1411 SessionState session = (SessionState)args.arg1;
1412 setEnabledSessionInMainThread(session);
1413 session.method.startInput((IInputContext)args.arg2,
1414 (EditorInfo)args.arg3);
1415 } catch (RemoteException e) {
1416 }
1417 return true;
1418 case MSG_RESTART_INPUT:
1419 args = (HandlerCaller.SomeArgs)msg.obj;
1420 try {
1421 SessionState session = (SessionState)args.arg1;
1422 setEnabledSessionInMainThread(session);
1423 session.method.restartInput((IInputContext)args.arg2,
1424 (EditorInfo)args.arg3);
1425 } catch (RemoteException e) {
1426 }
1427 return true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001431 case MSG_UNBIND_METHOD:
1432 try {
1433 ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1);
1434 } catch (RemoteException e) {
1435 // There is nothing interesting about the last client dying.
1436 }
1437 return true;
1438 case MSG_BIND_METHOD:
1439 args = (HandlerCaller.SomeArgs)msg.obj;
1440 try {
1441 ((IInputMethodClient)args.arg1).onBindMethod(
1442 (InputBindResult)args.arg2);
1443 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001444 Slog.w(TAG, "Client died receiving input method " + args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 }
1446 return true;
1447 }
1448 return false;
1449 }
1450
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001451 private boolean isSystemIme(InputMethodInfo inputMethod) {
1452 return (inputMethod.getServiceInfo().applicationInfo.flags
1453 & ApplicationInfo.FLAG_SYSTEM) != 0;
1454 }
1455
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001456 private boolean chooseNewDefaultIMELocked() {
satokd87c2592010-09-29 11:52:06 +09001457 List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001458 if (enabled != null && enabled.size() > 0) {
Dianne Hackborn83e48f52010-03-23 23:03:25 -07001459 // We'd prefer to fall back on a system IME, since that is safer.
1460 int i=enabled.size();
1461 while (i > 0) {
1462 i--;
1463 if ((enabled.get(i).getServiceInfo().applicationInfo.flags
1464 & ApplicationInfo.FLAG_SYSTEM) != 0) {
1465 break;
1466 }
1467 }
satokab751aa2010-09-14 19:17:36 +09001468 InputMethodInfo imi = enabled.get(i);
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001469 Settings.Secure.putString(mContext.getContentResolver(),
satokab751aa2010-09-14 19:17:36 +09001470 Settings.Secure.DEFAULT_INPUT_METHOD, imi.getId());
1471 putSelectedInputMethodSubtype(imi, NOT_A_SUBTYPE_ID);
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001472 return true;
1473 }
1474
1475 return false;
1476 }
1477
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 void buildInputMethodListLocked(ArrayList<InputMethodInfo> list,
1479 HashMap<String, InputMethodInfo> map) {
1480 list.clear();
1481 map.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 PackageManager pm = mContext.getPackageManager();
Amith Yamasanie861ec12010-03-24 21:39:27 -07001484 final Configuration config = mContext.getResources().getConfiguration();
1485 final boolean haveHardKeyboard = config.keyboard == Configuration.KEYBOARD_QWERTY;
1486 String disabledSysImes = Settings.Secure.getString(mContext.getContentResolver(),
1487 Secure.DISABLED_SYSTEM_INPUT_METHODS);
1488 if (disabledSysImes == null) disabledSysImes = "";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489
1490 List<ResolveInfo> services = pm.queryIntentServices(
1491 new Intent(InputMethod.SERVICE_INTERFACE),
1492 PackageManager.GET_META_DATA);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494 for (int i = 0; i < services.size(); ++i) {
1495 ResolveInfo ri = services.get(i);
1496 ServiceInfo si = ri.serviceInfo;
1497 ComponentName compName = new ComponentName(si.packageName, si.name);
1498 if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(
1499 si.permission)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001500 Slog.w(TAG, "Skipping input method " + compName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 + ": it does not require the permission "
1502 + android.Manifest.permission.BIND_INPUT_METHOD);
1503 continue;
1504 }
1505
Joe Onorato8a9b2202010-02-26 18:56:32 -08001506 if (DEBUG) Slog.d(TAG, "Checking " + compName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507
1508 try {
1509 InputMethodInfo p = new InputMethodInfo(mContext, ri);
1510 list.add(p);
Amith Yamasanie861ec12010-03-24 21:39:27 -07001511 final String id = p.getId();
1512 map.put(id, p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513
Amith Yamasanie861ec12010-03-24 21:39:27 -07001514 // System IMEs are enabled by default, unless there's a hard keyboard
1515 // and the system IME was explicitly disabled
1516 if (isSystemIme(p) && (!haveHardKeyboard || disabledSysImes.indexOf(id) < 0)) {
1517 setInputMethodEnabledLocked(id, true);
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001518 }
1519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 if (DEBUG) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001521 Slog.d(TAG, "Found a third-party input method " + p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 } catch (XmlPullParserException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001525 Slog.w(TAG, "Unable to load input method " + compName, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001527 Slog.w(TAG, "Unable to load input method " + compName, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 }
1529 }
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001530
1531 String defaultIme = Settings.Secure.getString(mContext
1532 .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
satok913a8922010-08-26 21:53:41 +09001533 if (!TextUtils.isEmpty(defaultIme) && !map.containsKey(defaultIme)) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001534 if (chooseNewDefaultIMELocked()) {
Brandon Ballinger6da35a02009-10-21 00:38:13 -07001535 updateFromSettingsLocked();
1536 }
1537 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001541
satokab751aa2010-09-14 19:17:36 +09001542 private void showInputMethodMenu() {
1543 showInputMethodMenuInternal(false);
1544 }
1545
1546 private void showInputMethodSubtypeMenu() {
1547 showInputMethodMenuInternal(true);
1548 }
1549
satok47a44912010-10-06 16:03:58 +09001550 private void showInputMethodAndSubtypeEnabler() {
1551 Intent intent = new Intent();
1552 intent.setClassName("android", InputMethodAndSubtypeEnabler.class.getCanonicalName());
1553 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1554 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1555 mContext.startActivity(intent);
1556 }
1557
satokab751aa2010-09-14 19:17:36 +09001558 private void showInputMethodMenuInternal(boolean showSubtypes) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001559 if (DEBUG) Slog.v(TAG, "Show switching menu");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 final Context context = mContext;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001562
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 final PackageManager pm = context.getPackageManager();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001565 String lastInputMethodId = Settings.Secure.getString(context
1566 .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
satokab751aa2010-09-14 19:17:36 +09001567 int lastInputMethodSubtypeId = getSelectedInputMethodSubtypeId(lastInputMethodId);
Joe Onorato8a9b2202010-02-26 18:56:32 -08001568 if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 final List<InputMethodInfo> immis = getEnabledInputMethodList();
satokab751aa2010-09-14 19:17:36 +09001571 ArrayList<Integer> subtypeIds = new ArrayList<Integer>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001572
Dianne Hackborn97106ab2010-03-03 00:08:31 -08001573 if (immis == null) {
1574 return;
1575 }
satokab751aa2010-09-14 19:17:36 +09001576
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001577 synchronized (mMethodMap) {
1578 hideInputMethodMenuLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001580 int N = immis.size();
satok913a8922010-08-26 21:53:41 +09001581
satokab751aa2010-09-14 19:17:36 +09001582 final Map<CharSequence, Pair<InputMethodInfo, Integer>> imMap =
1583 new TreeMap<CharSequence, Pair<InputMethodInfo, Integer>>(Collator.getInstance());
satok913a8922010-08-26 21:53:41 +09001584
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001585 for (int i = 0; i < N; ++i) {
1586 InputMethodInfo property = immis.get(i);
1587 if (property == null) {
1588 continue;
1589 }
satokab751aa2010-09-14 19:17:36 +09001590 // TODO: Show only enabled subtypes
1591 ArrayList<InputMethodSubtype> subtypes = property.getSubtypes();
1592 CharSequence label = property.loadLabel(pm);
1593 if (showSubtypes && subtypes.size() > 0) {
1594 for (int j = 0; j < subtypes.size(); ++j) {
1595 InputMethodSubtype subtype = subtypes.get(j);
1596 CharSequence title;
1597 int nameResId = subtype.getNameResId();
1598 int modeResId = subtype.getModeResId();
1599 if (nameResId != 0) {
1600 title = pm.getText(property.getPackageName(), nameResId,
1601 property.getServiceInfo().applicationInfo);
1602 } else {
1603 CharSequence language = subtype.getLocale();
1604 CharSequence mode = modeResId == 0 ? null
1605 : pm.getText(property.getPackageName(), modeResId,
1606 property.getServiceInfo().applicationInfo);
1607 // TODO: Use more friendly Title and UI
1608 title = label + "," + (mode == null ? "" : mode) + ","
1609 + (language == null ? "" : language);
1610 }
1611 imMap.put(title, new Pair<InputMethodInfo, Integer>(property, j));
1612 }
1613 } else {
1614 imMap.put(label,
1615 new Pair<InputMethodInfo, Integer>(property, NOT_A_SUBTYPE_ID));
1616 subtypeIds.add(0);
1617 }
Dianne Hackborn97106ab2010-03-03 00:08:31 -08001618 }
satok913a8922010-08-26 21:53:41 +09001619
1620 N = imMap.size();
1621 mItems = imMap.keySet().toArray(new CharSequence[N]);
satokab751aa2010-09-14 19:17:36 +09001622 mIms = new InputMethodInfo[N];
1623 mSubtypeIds = new int[N];
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001624 int checkedItem = 0;
1625 for (int i = 0; i < N; ++i) {
satokab751aa2010-09-14 19:17:36 +09001626 Pair<InputMethodInfo, Integer> value = imMap.get(mItems[i]);
1627 mIms[i] = value.first;
1628 mSubtypeIds[i] = value.second;
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001629 if (mIms[i].getId().equals(lastInputMethodId)) {
satokab751aa2010-09-14 19:17:36 +09001630 int subtypeId = mSubtypeIds[i];
1631 if ((subtypeId == NOT_A_SUBTYPE_ID)
1632 || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0)
1633 || (subtypeId == lastInputMethodSubtypeId)) {
1634 checkedItem = i;
1635 }
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001636 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 }
satokab751aa2010-09-14 19:17:36 +09001638
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001639 AlertDialog.OnClickListener adocl = new AlertDialog.OnClickListener() {
1640 public void onClick(DialogInterface dialog, int which) {
1641 hideInputMethodMenu();
1642 }
1643 };
satokd87c2592010-09-29 11:52:06 +09001644
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001645 TypedArray a = context.obtainStyledAttributes(null,
1646 com.android.internal.R.styleable.DialogPreference,
1647 com.android.internal.R.attr.alertDialogStyle, 0);
1648 mDialogBuilder = new AlertDialog.Builder(context)
1649 .setTitle(com.android.internal.R.string.select_input_method)
1650 .setOnCancelListener(new OnCancelListener() {
1651 public void onCancel(DialogInterface dialog) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 hideInputMethodMenu();
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001653 }
1654 })
1655 .setIcon(a.getDrawable(
1656 com.android.internal.R.styleable.DialogPreference_dialogTitle));
1657 a.recycle();
satokd87c2592010-09-29 11:52:06 +09001658
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001659 mDialogBuilder.setSingleChoiceItems(mItems, checkedItem,
1660 new AlertDialog.OnClickListener() {
1661 public void onClick(DialogInterface dialog, int which) {
1662 synchronized (mMethodMap) {
satokab751aa2010-09-14 19:17:36 +09001663 if (mIms == null || mIms.length <= which
1664 || mSubtypeIds == null || mSubtypeIds.length <= which) {
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001665 return;
1666 }
1667 InputMethodInfo im = mIms[which];
satokab751aa2010-09-14 19:17:36 +09001668 int subtypeId = mSubtypeIds[which];
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001669 hideInputMethodMenu();
1670 if (im != null) {
satokab751aa2010-09-14 19:17:36 +09001671 if ((subtypeId < 0)
1672 || (subtypeId >= im.getSubtypes().size())) {
1673 subtypeId = NOT_A_SUBTYPE_ID;
1674 }
1675 setInputMethodLocked(im.getId(), subtypeId);
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001676 }
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08001677 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 }
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07001679 });
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 mSwitchingDialog = mDialogBuilder.create();
1682 mSwitchingDialog.getWindow().setType(
1683 WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
1684 mSwitchingDialog.show();
1685 }
1686 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001688 void hideInputMethodMenu() {
The Android Open Source Project10592532009-03-18 17:39:46 -07001689 synchronized (mMethodMap) {
1690 hideInputMethodMenuLocked();
1691 }
1692 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001693
The Android Open Source Project10592532009-03-18 17:39:46 -07001694 void hideInputMethodMenuLocked() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001695 if (DEBUG) Slog.v(TAG, "Hide switching menu");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001696
The Android Open Source Project10592532009-03-18 17:39:46 -07001697 if (mSwitchingDialog != null) {
1698 mSwitchingDialog.dismiss();
1699 mSwitchingDialog = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001700 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001701
The Android Open Source Project10592532009-03-18 17:39:46 -07001702 mDialogBuilder = null;
1703 mItems = null;
1704 mIms = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001707 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001709 public boolean setInputMethodEnabled(String id, boolean enabled) {
1710 synchronized (mMethodMap) {
1711 if (mContext.checkCallingOrSelfPermission(
1712 android.Manifest.permission.WRITE_SECURE_SETTINGS)
1713 != PackageManager.PERMISSION_GRANTED) {
1714 throw new SecurityException(
1715 "Requires permission "
1716 + android.Manifest.permission.WRITE_SECURE_SETTINGS);
1717 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001719 long ident = Binder.clearCallingIdentity();
1720 try {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001721 return setInputMethodEnabledLocked(id, enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001722 } finally {
1723 Binder.restoreCallingIdentity(ident);
1724 }
1725 }
1726 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001727
1728 boolean setInputMethodEnabledLocked(String id, boolean enabled) {
1729 // Make sure this is a valid input method.
1730 InputMethodInfo imm = mMethodMap.get(id);
1731 if (imm == null) {
satokd87c2592010-09-29 11:52:06 +09001732 throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001733 }
1734
satokd87c2592010-09-29 11:52:06 +09001735 List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings
1736 .getEnabledInputMethodsAndSubtypeListLocked();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001737
satokd87c2592010-09-29 11:52:06 +09001738 if (enabled) {
1739 for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) {
1740 if (pair.first.equals(id)) {
1741 // We are enabling this input method, but it is already enabled.
1742 // Nothing to do. The previous state was enabled.
1743 return true;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001744 }
1745 }
satokd87c2592010-09-29 11:52:06 +09001746 mSettings.appendAndPutEnabledInputMethodLocked(id, false);
1747 // Previous state was disabled.
1748 return false;
1749 } else {
1750 StringBuilder builder = new StringBuilder();
1751 if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked(
1752 builder, enabledInputMethodsList, id)) {
1753 // Disabled input method is currently selected, switch to another one.
1754 String selId = Settings.Secure.getString(mContext.getContentResolver(),
1755 Settings.Secure.DEFAULT_INPUT_METHOD);
1756 if (id.equals(selId)) {
1757 Settings.Secure.putString(
1758 mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD,
1759 enabledInputMethodsList.size() > 0
1760 ? enabledInputMethodsList.get(0).first : "");
1761 resetSelectedInputMethodSubtype();
1762 }
1763 // Previous state was enabled.
1764 return true;
1765 } else {
1766 // We are disabling the input method but it is already disabled.
1767 // Nothing to do. The previous state was disabled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001768 return false;
1769 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001770 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08001771 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08001772
satokab751aa2010-09-14 19:17:36 +09001773 private void resetSelectedInputMethodSubtype() {
1774 Settings.Secure.putInt(mContext.getContentResolver(),
1775 Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, NOT_A_SUBTYPE_ID);
1776 }
1777
1778 private boolean putSelectedInputMethodSubtype(InputMethodInfo imi, int subtypeId) {
1779 ArrayList<InputMethodSubtype> subtypes = imi.getSubtypes();
1780 if (subtypeId >= 0 && subtypeId < subtypes.size()) {
1781 Settings.Secure.putInt(mContext.getContentResolver(),
1782 Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE,
1783 subtypes.get(subtypeId).hashCode());
1784 return true;
1785 } else {
1786 resetSelectedInputMethodSubtype();
1787 return false;
1788 }
1789 }
1790
1791 private int getSelectedInputMethodSubtypeId(String id) {
1792 InputMethodInfo imi = mMethodMap.get(id);
1793 if (imi == null) {
1794 return NOT_A_SUBTYPE_ID;
1795 }
1796 ArrayList<InputMethodSubtype> subtypes = imi.getSubtypes();
1797 int subtypeId;
1798 try {
1799 subtypeId = Settings.Secure.getInt(mContext.getContentResolver(),
1800 Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE);
1801 } catch (SettingNotFoundException e) {
1802 return NOT_A_SUBTYPE_ID;
1803 }
1804 for (int i = 0; i < subtypes.size(); ++i) {
1805 InputMethodSubtype ims = subtypes.get(i);
1806 if (subtypeId == ims.hashCode()) {
1807 return i;
1808 }
1809 }
1810 return NOT_A_SUBTYPE_ID;
1811 }
1812
1813 /**
1814 * @return Return the current subtype of this input method.
1815 */
1816 public InputMethodSubtype getCurrentInputMethodSubtype() {
1817 return mCurrentSubtype;
1818 }
1819
satokd87c2592010-09-29 11:52:06 +09001820 /**
1821 * Utility class for putting and getting settings for InputMethod
1822 * TODO: Move all putters and getters of settings to this class.
1823 */
1824 private static class InputMethodSettings {
1825 // The string for enabled input method is saved as follows:
1826 // example: ("ime0;subtype0;subtype1;subtype2:ime1:ime2;subtype0")
1827 private static final char INPUT_METHOD_SEPARATER = ':';
1828 private static final char INPUT_METHOD_SUBTYPE_SEPARATER = ';';
1829 private final TextUtils.SimpleStringSplitter mStringColonSplitter =
1830 new TextUtils.SimpleStringSplitter(INPUT_METHOD_SEPARATER);
1831
1832 private final TextUtils.SimpleStringSplitter mStringSemiColonSplitter =
1833 new TextUtils.SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATER);
1834
1835 private final ContentResolver mResolver;
1836 private final HashMap<String, InputMethodInfo> mMethodMap;
1837 private final ArrayList<InputMethodInfo> mMethodList;
1838
1839 private String mEnabledInputMethodsStrCache;
1840
1841 private static void buildEnabledInputMethodsSettingString(
1842 StringBuilder builder, Pair<String, ArrayList<String>> pair) {
1843 String id = pair.first;
1844 ArrayList<String> subtypes = pair.second;
1845 builder.append(id);
1846 if (subtypes.size() > 0) {
1847 builder.append(subtypes.get(0));
1848 for (int i = 1; i < subtypes.size(); ++i) {
1849 builder.append(INPUT_METHOD_SUBTYPE_SEPARATER).append(subtypes.get(i));
1850 }
1851 }
1852 }
1853
1854 public InputMethodSettings(
1855 ContentResolver resolver, HashMap<String, InputMethodInfo> methodMap,
1856 ArrayList<InputMethodInfo> methodList) {
1857 mResolver = resolver;
1858 mMethodMap = methodMap;
1859 mMethodList = methodList;
1860 }
1861
1862 public List<InputMethodInfo> getEnabledInputMethodListLocked() {
1863 return createEnabledInputMethodListLocked(
1864 getEnabledInputMethodsAndSubtypeListLocked());
1865 }
1866
1867 // At the initial boot, the settings for input methods are not set,
1868 // so we need to enable IME in that case.
1869 public void enableAllIMEsIfThereIsNoEnabledIME() {
1870 if (TextUtils.isEmpty(getEnabledInputMethodsStr())) {
1871 StringBuilder sb = new StringBuilder();
1872 final int N = mMethodList.size();
1873 for (int i = 0; i < N; i++) {
1874 InputMethodInfo imi = mMethodList.get(i);
1875 Slog.i(TAG, "Adding: " + imi.getId());
1876 if (i > 0) sb.append(':');
1877 sb.append(imi.getId());
1878 }
1879 putEnabledInputMethodsStr(sb.toString());
1880 }
1881 }
1882
1883 public List<Pair<String, ArrayList<String>>> getEnabledInputMethodsAndSubtypeListLocked() {
1884 ArrayList<Pair<String, ArrayList<String>>> imsList
1885 = new ArrayList<Pair<String, ArrayList<String>>>();
1886 final String enabledInputMethodsStr = getEnabledInputMethodsStr();
1887 if (TextUtils.isEmpty(enabledInputMethodsStr)) {
1888 return imsList;
1889 }
1890 mStringColonSplitter.setString(enabledInputMethodsStr);
1891 while (mStringColonSplitter.hasNext()) {
1892 String nextImsStr = mStringColonSplitter.next();
1893 mStringSemiColonSplitter.setString(nextImsStr);
1894 if (mStringSemiColonSplitter.hasNext()) {
1895 ArrayList<String> subtypeHashes = new ArrayList<String>();
1896 // The first element is ime id.
1897 String imeId = mStringSemiColonSplitter.next();
1898 while (mStringSemiColonSplitter.hasNext()) {
1899 subtypeHashes.add(mStringSemiColonSplitter.next());
1900 }
1901 imsList.add(new Pair<String, ArrayList<String>>(imeId, subtypeHashes));
1902 }
1903 }
1904 return imsList;
1905 }
1906
1907 public void appendAndPutEnabledInputMethodLocked(String id, boolean reloadInputMethodStr) {
1908 if (reloadInputMethodStr) {
1909 getEnabledInputMethodsStr();
1910 }
1911 if (TextUtils.isEmpty(mEnabledInputMethodsStrCache)) {
1912 // Add in the newly enabled input method.
1913 putEnabledInputMethodsStr(id);
1914 } else {
1915 putEnabledInputMethodsStr(
1916 mEnabledInputMethodsStrCache + INPUT_METHOD_SEPARATER + id);
1917 }
1918 }
1919
1920 /**
1921 * Build and put a string of EnabledInputMethods with removing specified Id.
1922 * @return the specified id was removed or not.
1923 */
1924 public boolean buildAndPutEnabledInputMethodsStrRemovingIdLocked(
1925 StringBuilder builder, List<Pair<String, ArrayList<String>>> imsList, String id) {
1926 boolean isRemoved = false;
1927 boolean needsAppendSeparator = false;
1928 for (Pair<String, ArrayList<String>> ims: imsList) {
1929 String curId = ims.first;
1930 if (curId.equals(id)) {
1931 // We are disabling this input method, and it is
1932 // currently enabled. Skip it to remove from the
1933 // new list.
1934 isRemoved = true;
1935 } else {
1936 if (needsAppendSeparator) {
1937 builder.append(INPUT_METHOD_SEPARATER);
1938 } else {
1939 needsAppendSeparator = true;
1940 }
1941 buildEnabledInputMethodsSettingString(builder, ims);
1942 }
1943 }
1944 if (isRemoved) {
1945 // Update the setting with the new list of input methods.
1946 putEnabledInputMethodsStr(builder.toString());
1947 }
1948 return isRemoved;
1949 }
1950
1951 private List<InputMethodInfo> createEnabledInputMethodListLocked(
1952 List<Pair<String, ArrayList<String>>> imsList) {
1953 final ArrayList<InputMethodInfo> res = new ArrayList<InputMethodInfo>();
1954 for (Pair<String, ArrayList<String>> ims: imsList) {
1955 InputMethodInfo info = mMethodMap.get(ims.first);
1956 if (info != null) {
1957 res.add(info);
1958 }
1959 }
1960 return res;
1961 }
1962
1963 private void putEnabledInputMethodsStr(String str) {
1964 Settings.Secure.putString(mResolver, Settings.Secure.ENABLED_INPUT_METHODS, str);
1965 mEnabledInputMethodsStrCache = str;
1966 }
1967
1968 private String getEnabledInputMethodsStr() {
1969 mEnabledInputMethodsStrCache = Settings.Secure.getString(
1970 mResolver, Settings.Secure.ENABLED_INPUT_METHODS);
1971 return mEnabledInputMethodsStrCache;
1972 }
1973 }
1974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001975 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 @Override
1978 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1979 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1980 != PackageManager.PERMISSION_GRANTED) {
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001981
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 pw.println("Permission Denial: can't dump InputMethodManager from from pid="
1983 + Binder.getCallingPid()
1984 + ", uid=" + Binder.getCallingUid());
1985 return;
1986 }
1987
1988 IInputMethod method;
1989 ClientState client;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001991 final Printer p = new PrintWriterPrinter(pw);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 synchronized (mMethodMap) {
1994 p.println("Current Input Method Manager state:");
1995 int N = mMethodList.size();
1996 p.println(" Input Methods:");
1997 for (int i=0; i<N; i++) {
1998 InputMethodInfo info = mMethodList.get(i);
1999 p.println(" InputMethod #" + i + ":");
2000 info.dump(p, " ");
2001 }
2002 p.println(" Clients:");
2003 for (ClientState ci : mClients.values()) {
2004 p.println(" Client " + ci + ":");
2005 p.println(" client=" + ci.client);
2006 p.println(" inputContext=" + ci.inputContext);
2007 p.println(" sessionRequested=" + ci.sessionRequested);
2008 p.println(" curSession=" + ci.curSession);
2009 }
The Android Open Source Project10592532009-03-18 17:39:46 -07002010 p.println(" mCurMethodId=" + mCurMethodId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 client = mCurClient;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07002012 p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq);
2013 p.println(" mCurFocusedWindow=" + mCurFocusedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection
2015 + " mBoundToMethod=" + mBoundToMethod);
2016 p.println(" mCurToken=" + mCurToken);
2017 p.println(" mCurIntent=" + mCurIntent);
2018 method = mCurMethod;
2019 p.println(" mCurMethod=" + mCurMethod);
2020 p.println(" mEnabledSession=" + mEnabledSession);
2021 p.println(" mShowRequested=" + mShowRequested
2022 + " mShowExplicitlyRequested=" + mShowExplicitlyRequested
2023 + " mShowForced=" + mShowForced
2024 + " mInputShown=" + mInputShown);
Dianne Hackborncc278702009-09-02 23:07:23 -07002025 p.println(" mSystemReady=" + mSystemReady + " mScreenOn=" + mScreenOn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002027
Jeff Brownb88102f2010-09-08 11:49:43 -07002028 p.println(" ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002029 if (client != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 pw.flush();
2031 try {
2032 client.client.asBinder().dump(fd, args);
2033 } catch (RemoteException e) {
2034 p.println("Input method client dead: " + e);
2035 }
Jeff Brownb88102f2010-09-08 11:49:43 -07002036 } else {
2037 p.println("No input method client.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002039
Jeff Brownb88102f2010-09-08 11:49:43 -07002040 p.println(" ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 if (method != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 pw.flush();
2043 try {
2044 method.asBinder().dump(fd, args);
2045 } catch (RemoteException e) {
2046 p.println("Input method service dead: " + e);
2047 }
Jeff Brownb88102f2010-09-08 11:49:43 -07002048 } else {
2049 p.println("No input method service.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 }
2051 }
2052}