blob: edea274c155f533350387c0b676d473f8b9b7681 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 * use this file except in compliance with the License. You may obtain a copy of
5 * the License at
Doug Zongkerab5c49c2009-12-04 10:31:43 -08006 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08007 * http://www.apache.org/licenses/LICENSE-2.0
Doug Zongkerab5c49c2009-12-04 10:31:43 -08008 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08009 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 * License for the specific language governing permissions and limitations under
13 * the License.
14 */
15
16package com.android.server;
17
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080018import com.android.internal.content.PackageMonitor;
Satoshi Kataokad7443c82013-10-15 17:45:43 +090019import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController;
Satoshi Kataokad787f692013-10-26 04:44:21 +090020import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +090021import com.android.internal.inputmethod.InputMethodUtils;
22import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import com.android.internal.os.HandlerCaller;
Svetoslav Ganov758143e2012-08-06 16:40:27 -070024import com.android.internal.os.SomeArgs;
satoke7c6998e2011-06-03 17:57:59 +090025import com.android.internal.util.FastXmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import com.android.internal.view.IInputContext;
27import com.android.internal.view.IInputMethod;
Michael Wright52a53522013-03-14 10:59:38 -070028import com.android.internal.view.IInputSessionCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import com.android.internal.view.IInputMethodClient;
30import com.android.internal.view.IInputMethodManager;
31import com.android.internal.view.IInputMethodSession;
32import com.android.internal.view.InputBindResult;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080033import com.android.server.statusbar.StatusBarManagerService;
satok01038492012-04-09 21:08:27 +090034import com.android.server.wm.WindowManagerService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
satoke7c6998e2011-06-03 17:57:59 +090036import org.xmlpull.v1.XmlPullParser;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import org.xmlpull.v1.XmlPullParserException;
satoke7c6998e2011-06-03 17:57:59 +090038import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
40import android.app.ActivityManagerNative;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +090041import android.app.AppGlobals;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.app.AlertDialog;
Yohei Yukawae63b5fa2014-09-19 13:14:55 +090043import android.app.AppOpsManager;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +090044import android.app.IUserSwitchObserver;
satokf90a33e2011-07-19 11:55:52 +090045import android.app.KeyguardManager;
satok7cfc0ed2011-06-20 21:29:36 +090046import android.app.Notification;
47import android.app.NotificationManager;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -070048import android.app.PendingIntent;
satok5b927c432012-05-01 20:09:34 +090049import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.content.ComponentName;
51import android.content.ContentResolver;
52import android.content.Context;
53import android.content.DialogInterface;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.content.DialogInterface.OnCancelListener;
Tadashi G. Takaokad130b802014-08-01 14:05:47 +090055import android.content.DialogInterface.OnClickListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.content.Intent;
satoke7c6998e2011-06-03 17:57:59 +090057import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.content.ServiceConnection;
Brandon Ballinger6da35a02009-10-21 00:38:13 -070059import android.content.pm.ApplicationInfo;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +090060import android.content.pm.IPackageManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.content.pm.PackageManager;
62import android.content.pm.ResolveInfo;
63import android.content.pm.ServiceInfo;
Amith Yamasani734983f2014-03-04 16:48:05 -080064import android.content.pm.UserInfo;
Amith Yamasanie861ec12010-03-24 21:39:27 -070065import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.content.res.Resources;
67import android.content.res.TypedArray;
68import android.database.ContentObserver;
Joe Onorato857fd9b2011-01-27 15:08:35 -080069import android.inputmethodservice.InputMethodService;
Michael Wright7b5a96b2014-08-09 19:28:42 -070070import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071import android.os.Binder;
satoke7c6998e2011-06-03 17:57:59 +090072import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073import android.os.Handler;
74import android.os.IBinder;
75import android.os.IInterface;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +090076import android.os.IRemoteCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077import android.os.Message;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +090078import android.os.Process;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079import android.os.Parcel;
80import android.os.RemoteException;
The Android Open Source Project4df24232009-03-05 14:34:35 -080081import android.os.ResultReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082import android.os.ServiceManager;
83import android.os.SystemClock;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +090084import android.os.UserHandle;
Amith Yamasani734983f2014-03-04 16:48:05 -080085import android.os.UserManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086import android.provider.Settings;
87import android.text.TextUtils;
satokf9f01002011-05-19 21:31:50 +090088import android.text.style.SuggestionSpan;
Dianne Hackborn39606a02012-07-31 17:54:35 -070089import android.util.AtomicFile;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.util.EventLog;
satokf9f01002011-05-19 21:31:50 +090091import android.util.LruCache;
satokab751aa2010-09-14 19:17:36 +090092import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093import android.util.PrintWriterPrinter;
94import android.util.Printer;
satoke7c6998e2011-06-03 17:57:59 +090095import android.util.Slog;
96import android.util.Xml;
Tadashi G. Takaokad130b802014-08-01 14:05:47 +090097import android.view.ContextThemeWrapper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098import android.view.IWindowManager;
Jeff Brownc28867a2013-03-26 15:42:39 -070099import android.view.InputChannel;
Ken Wakasa05dbb652011-08-22 15:22:43 +0900100import android.view.LayoutInflater;
101import android.view.View;
102import android.view.ViewGroup;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103import android.view.WindowManager;
satokab751aa2010-09-14 19:17:36 +0900104import android.view.inputmethod.EditorInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105import android.view.inputmethod.InputBinding;
106import android.view.inputmethod.InputMethod;
107import android.view.inputmethod.InputMethodInfo;
108import android.view.inputmethod.InputMethodManager;
satokab751aa2010-09-14 19:17:36 +0900109import android.view.inputmethod.InputMethodSubtype;
Yohei Yukawa443c2ba2014-09-10 14:10:30 +0900110import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
Ken Wakasa05dbb652011-08-22 15:22:43 +0900111import android.widget.ArrayAdapter;
satok01038492012-04-09 21:08:27 +0900112import android.widget.CompoundButton;
113import android.widget.CompoundButton.OnCheckedChangeListener;
Ken Wakasa05dbb652011-08-22 15:22:43 +0900114import android.widget.RadioButton;
satok01038492012-04-09 21:08:27 +0900115import android.widget.Switch;
Ken Wakasa05dbb652011-08-22 15:22:43 +0900116import android.widget.TextView;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117
satoke7c6998e2011-06-03 17:57:59 +0900118import java.io.File;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119import java.io.FileDescriptor;
satoke7c6998e2011-06-03 17:57:59 +0900120import java.io.FileInputStream;
121import java.io.FileOutputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122import java.io.IOException;
123import java.io.PrintWriter;
124import java.util.ArrayList;
satok688bd472012-02-09 20:09:17 +0900125import java.util.Collections;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126import java.util.HashMap;
127import java.util.List;
satok5b927c432012-05-01 20:09:34 +0900128import java.util.Locale;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129
130/**
131 * This class provides a system service that manages input methods.
132 */
133public class InputMethodManagerService extends IInputMethodManager.Stub
134 implements ServiceConnection, Handler.Callback {
135 static final boolean DEBUG = false;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700136 static final String TAG = "InputMethodManagerService";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137
138 static final int MSG_SHOW_IM_PICKER = 1;
satokab751aa2010-09-14 19:17:36 +0900139 static final int MSG_SHOW_IM_SUBTYPE_PICKER = 2;
satok47a44912010-10-06 16:03:58 +0900140 static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 3;
satok217f5482010-12-15 05:19:19 +0900141 static final int MSG_SHOW_IM_CONFIG = 4;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 static final int MSG_UNBIND_INPUT = 1000;
144 static final int MSG_BIND_INPUT = 1010;
145 static final int MSG_SHOW_SOFT_INPUT = 1020;
146 static final int MSG_HIDE_SOFT_INPUT = 1030;
147 static final int MSG_ATTACH_TOKEN = 1040;
148 static final int MSG_CREATE_SESSION = 1050;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 static final int MSG_START_INPUT = 2000;
151 static final int MSG_RESTART_INPUT = 2010;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 static final int MSG_UNBIND_METHOD = 3000;
154 static final int MSG_BIND_METHOD = 3010;
Dianne Hackborna6e41342012-05-22 16:30:34 -0700155 static final int MSG_SET_ACTIVE = 3020;
Yohei Yukawa3d1e8122014-06-06 19:12:47 +0900156 static final int MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER = 3040;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800157
satok01038492012-04-09 21:08:27 +0900158 static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000;
159
Satoshi Kataokabcacc322013-10-21 17:57:27 -0700160 static final long TIME_TO_RECONNECT = 3 * 1000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800161
satokf9f01002011-05-19 21:31:50 +0900162 static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20;
163
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +0900164 private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
satokb6359412011-06-28 17:47:41 +0900165 private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher";
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +0900166
satok4e4569d2010-11-19 18:45:53 +0900167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 final Context mContext;
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -0800169 final Resources mRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 final Handler mHandler;
satokd87c2592010-09-29 11:52:06 +0900171 final InputMethodSettings mSettings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 final SettingsObserver mSettingsObserver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 final IWindowManager mIWindowManager;
174 final HandlerCaller mCaller;
Dianne Hackborn119bbc32013-03-22 17:27:25 -0700175 final boolean mHasFeature;
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +0900176 private InputMethodFileManager mFileManager;
satok01038492012-04-09 21:08:27 +0900177 private final HardKeyboardListener mHardKeyboardListener;
178 private final WindowManagerService mWindowManagerService;
Yohei Yukawae63b5fa2014-09-19 13:14:55 +0900179 private final AppOpsManager mAppOpsManager;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800180
Yohei Yukawa3d1e8122014-06-06 19:12:47 +0900181 final InputBindResult mNoBinding = new InputBindResult(null, null, null, -1, -1);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 // All known input methods. mMethodMap also serves as the global
184 // lock for this class.
satokd87c2592010-09-29 11:52:06 +0900185 final ArrayList<InputMethodInfo> mMethodList = new ArrayList<InputMethodInfo>();
186 final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<String, InputMethodInfo>();
satokf9f01002011-05-19 21:31:50 +0900187 private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans =
188 new LruCache<SuggestionSpan, InputMethodInfo>(SECURE_SUGGESTION_SPANS_MAX_SIZE);
Satoshi Kataokad787f692013-10-26 04:44:21 +0900189 private final InputMethodSubtypeSwitchingController mSwitchingController;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800190
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700191 // Used to bring IME service up to visible adjustment while it is being shown.
192 final ServiceConnection mVisibleConnection = new ServiceConnection() {
193 @Override public void onServiceConnected(ComponentName name, IBinder service) {
194 }
195
196 @Override public void onServiceDisconnected(ComponentName name) {
197 }
198 };
199 boolean mVisibleBound = false;
200
satok7cfc0ed2011-06-20 21:29:36 +0900201 // Ongoing notification
Dianne Hackborn661cd522011-08-22 00:26:20 -0700202 private NotificationManager mNotificationManager;
203 private KeyguardManager mKeyguardManager;
204 private StatusBarManagerService mStatusBar;
205 private Notification mImeSwitcherNotification;
206 private PendingIntent mImeSwitchPendingIntent;
satokb858c732011-07-22 19:54:34 +0900207 private boolean mShowOngoingImeSwitcherForPhones;
satok7cfc0ed2011-06-20 21:29:36 +0900208 private boolean mNotificationShown;
satok0a1bcf42012-05-16 19:26:31 +0900209 private final boolean mImeSelectedOnBoot;
satok7cfc0ed2011-06-20 21:29:36 +0900210
Tadashi G. Takaoka8c6d4772014-08-05 15:29:17 +0900211 static class SessionState {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 final ClientState client;
213 final IInputMethod method;
Jeff Brownc28867a2013-03-26 15:42:39 -0700214
215 IInputMethodSession session;
216 InputChannel channel;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800217
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 @Override
219 public String toString() {
220 return "SessionState{uid " + client.uid + " pid " + client.pid
221 + " method " + Integer.toHexString(
222 System.identityHashCode(method))
223 + " session " + Integer.toHexString(
224 System.identityHashCode(session))
Jeff Brownc28867a2013-03-26 15:42:39 -0700225 + " channel " + channel
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 + "}";
227 }
228
229 SessionState(ClientState _client, IInputMethod _method,
Jeff Brownc28867a2013-03-26 15:42:39 -0700230 IInputMethodSession _session, InputChannel _channel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 client = _client;
232 method = _method;
233 session = _session;
Jeff Brownc28867a2013-03-26 15:42:39 -0700234 channel = _channel;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 }
236 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800237
Jeff Brownc28867a2013-03-26 15:42:39 -0700238 static final class ClientState {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 final IInputMethodClient client;
240 final IInputContext inputContext;
241 final int uid;
242 final int pid;
243 final InputBinding binding;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800244
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 boolean sessionRequested;
246 SessionState curSession;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 @Override
249 public String toString() {
250 return "ClientState{" + Integer.toHexString(
251 System.identityHashCode(this)) + " uid " + uid
252 + " pid " + pid + "}";
253 }
254
255 ClientState(IInputMethodClient _client, IInputContext _inputContext,
256 int _uid, int _pid) {
257 client = _client;
258 inputContext = _inputContext;
259 uid = _uid;
260 pid = _pid;
261 binding = new InputBinding(null, inputContext.asBinder(), uid, pid);
262 }
263 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 final HashMap<IBinder, ClientState> mClients
266 = new HashMap<IBinder, ClientState>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 /**
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700269 * Set once the system is ready to run third party code.
270 */
271 boolean mSystemReady;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800272
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700273 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 * Id of the currently selected input method.
275 */
276 String mCurMethodId;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 /**
279 * The current binding sequence number, incremented every time there is
280 * a new bind performed.
281 */
282 int mCurSeq;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 /**
285 * The client that is currently bound to an input method.
286 */
287 ClientState mCurClient;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 /**
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700290 * The last window token that gained focus.
291 */
292 IBinder mCurFocusedWindow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800293
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700294 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 * The input context last provided by the current client.
296 */
297 IInputContext mCurInputContext;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800298
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 /**
300 * The attributes last provided by the current client.
301 */
302 EditorInfo mCurAttribute;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800303
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 /**
305 * The input method ID of the input method service that we are currently
306 * connected to or in the process of connecting to.
307 */
308 String mCurId;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 /**
satokab751aa2010-09-14 19:17:36 +0900311 * The current subtype of the current input method.
312 */
313 private InputMethodSubtype mCurrentSubtype;
314
satok4e4569d2010-11-19 18:45:53 +0900315 // This list contains the pairs of InputMethodInfo and InputMethodSubtype.
satokf3db1af2010-11-23 13:34:33 +0900316 private final HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>>
317 mShortcutInputMethodsAndSubtypes =
318 new HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>>();
satokab751aa2010-09-14 19:17:36 +0900319
John Spurlocke0980502013-10-25 11:59:29 -0400320 // Was the keyguard locked when this client became current?
321 private boolean mCurClientInKeyguard;
322
satokab751aa2010-09-14 19:17:36 +0900323 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 * Set to true if our ServiceConnection is currently actively bound to
325 * a service (whether or not we have gotten its IBinder back yet).
326 */
327 boolean mHaveConnection;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 /**
330 * Set if the client has asked for the input method to be shown.
331 */
332 boolean mShowRequested;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800333
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 /**
335 * Set if we were explicitly told to show the input method.
336 */
337 boolean mShowExplicitlyRequested;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 /**
340 * Set if we were forced to be shown.
341 */
342 boolean mShowForced;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 /**
345 * Set if we last told the input method to show itself.
346 */
347 boolean mInputShown;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800348
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 /**
350 * The Intent used to connect to the current input method.
351 */
352 Intent mCurIntent;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 /**
355 * The token we have made for the currently active input method, to
356 * identify it in the future.
357 */
358 IBinder mCurToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 /**
361 * If non-null, this is the input method service we are currently connected
362 * to.
363 */
364 IInputMethod mCurMethod;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 /**
367 * Time that we last initiated a bind to the input method, to determine
368 * if we should try to disconnect and reconnect to it.
369 */
370 long mLastBindTime;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800371
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 /**
373 * Have we called mCurMethod.bindInput()?
374 */
375 boolean mBoundToMethod;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800376
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377 /**
378 * Currently enabled session. Only touched by service thread, not
379 * protected by a lock.
380 */
381 SessionState mEnabledSession;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 /**
384 * True if the screen is on. The value is true initially.
385 */
386 boolean mScreenOn = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800387
Yohei Yukawa3d1e8122014-06-06 19:12:47 +0900388 int mCurUserActionNotificationSequenceNumber = 0;
389
Joe Onorato857fd9b2011-01-27 15:08:35 -0800390 int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT;
391 int mImeWindowVis;
392
Ken Wakasa05dbb652011-08-22 15:22:43 +0900393 private AlertDialog.Builder mDialogBuilder;
394 private AlertDialog mSwitchingDialog;
satok01038492012-04-09 21:08:27 +0900395 private View mSwitchingDialogTitleView;
Ken Wakasa05dbb652011-08-22 15:22:43 +0900396 private InputMethodInfo[] mIms;
397 private int[] mSubtypeIds;
satok5b927c432012-05-01 20:09:34 +0900398 private Locale mLastSystemLocale;
Michael Wright7b5a96b2014-08-09 19:28:42 -0700399 private boolean mShowImeWithHardKeyboard;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900400 private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor();
401 private final IPackageManager mIPackageManager;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800402
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 class SettingsObserver extends ContentObserver {
Dianne Hackbornfd7aded2013-01-22 17:10:23 -0800404 String mLastEnabled = "";
405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 SettingsObserver(Handler handler) {
407 super(handler);
408 ContentResolver resolver = mContext.getContentResolver();
409 resolver.registerContentObserver(Settings.Secure.getUriFor(
410 Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
satokab751aa2010-09-14 19:17:36 +0900411 resolver.registerContentObserver(Settings.Secure.getUriFor(
satokb6109bb2011-02-03 22:24:54 +0900412 Settings.Secure.ENABLED_INPUT_METHODS), false, this);
413 resolver.registerContentObserver(Settings.Secure.getUriFor(
satokab751aa2010-09-14 19:17:36 +0900414 Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this);
Michael Wright7b5a96b2014-08-09 19:28:42 -0700415 resolver.registerContentObserver(Settings.Secure.getUriFor(
416 Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD), false, this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800418
Michael Wright7b5a96b2014-08-09 19:28:42 -0700419 @Override public void onChange(boolean selfChange, Uri uri) {
420 final Uri showImeUri =
421 Settings.Secure.getUriFor(Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 synchronized (mMethodMap) {
Michael Wright7b5a96b2014-08-09 19:28:42 -0700423 if (showImeUri.equals(uri)) {
424 updateKeyboardFromSettingsLocked();
425 } else {
426 boolean enabledChanged = false;
427 String newEnabled = mSettings.getEnabledInputMethodsStr();
428 if (!mLastEnabled.equals(newEnabled)) {
429 mLastEnabled = newEnabled;
430 enabledChanged = true;
431 }
432 updateInputMethodsFromSettingsLocked(enabledChanged);
Dianne Hackbornfd7aded2013-01-22 17:10:23 -0800433 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 }
435 }
436 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800437
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900438 class ImmsBroadcastReceiver extends android.content.BroadcastReceiver {
439 private void updateActive() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 // Inform the current client of the change in active status
Dianne Hackborna6e41342012-05-22 16:30:34 -0700441 if (mCurClient != null && mCurClient.client != null) {
442 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
443 MSG_SET_ACTIVE, mScreenOn ? 1 : 0, mCurClient));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 }
445 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900446
447 @Override
448 public void onReceive(Context context, Intent intent) {
449 final String action = intent.getAction();
450 if (Intent.ACTION_SCREEN_ON.equals(action)) {
451 mScreenOn = true;
452 refreshImeWindowVisibilityLocked();
453 updateActive();
454 return;
455 } else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
456 mScreenOn = false;
457 setImeWindowVisibilityStatusHiddenLocked();
458 updateActive();
459 return;
460 } else if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
461 hideInputMethodMenu();
462 // No need to updateActive
463 return;
Amith Yamasani734983f2014-03-04 16:48:05 -0800464 } else if (Intent.ACTION_USER_ADDED.equals(action)
465 || Intent.ACTION_USER_REMOVED.equals(action)) {
Kenny Guy2a764942014-04-02 13:29:20 +0100466 updateCurrentProfileIds();
Amith Yamasani734983f2014-03-04 16:48:05 -0800467 return;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900468 } else {
469 Slog.w(TAG, "Unexpected intent " + intent);
470 }
471 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800473
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800474 class MyPackageMonitor extends PackageMonitor {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900475 private boolean isChangingPackagesOfCurrentUser() {
476 final int userId = getChangingUserId();
477 final boolean retval = userId == mSettings.getCurrentUserId();
478 if (DEBUG) {
satok81f8b7c2012-12-04 20:42:56 +0900479 if (!retval) {
480 Slog.d(TAG, "--- ignore this call back from a background user: " + userId);
481 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900482 }
483 return retval;
484 }
485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 @Override
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800487 public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900488 if (!isChangingPackagesOfCurrentUser()) {
489 return false;
490 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 synchronized (mMethodMap) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900492 String curInputMethodId = mSettings.getSelectedInputMethod();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 final int N = mMethodList.size();
494 if (curInputMethodId != null) {
495 for (int i=0; i<N; i++) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800496 InputMethodInfo imi = mMethodList.get(i);
497 if (imi.getId().equals(curInputMethodId)) {
498 for (String pkg : packages) {
499 if (imi.getPackageName().equals(pkg)) {
500 if (!doit) {
501 return true;
502 }
satok723a27e2010-11-11 14:58:11 +0900503 resetSelectedInputMethodAndSubtypeLocked("");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800504 chooseNewDefaultIMELocked();
505 return true;
506 }
507 }
508 }
509 }
510 }
511 }
512 return false;
513 }
514
515 @Override
516 public void onSomePackagesChanged() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900517 if (!isChangingPackagesOfCurrentUser()) {
518 return;
519 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800520 synchronized (mMethodMap) {
521 InputMethodInfo curIm = null;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900522 String curInputMethodId = mSettings.getSelectedInputMethod();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800523 final int N = mMethodList.size();
524 if (curInputMethodId != null) {
525 for (int i=0; i<N; i++) {
526 InputMethodInfo imi = mMethodList.get(i);
satoke7c6998e2011-06-03 17:57:59 +0900527 final String imiId = imi.getId();
528 if (imiId.equals(curInputMethodId)) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800529 curIm = imi;
530 }
satoke7c6998e2011-06-03 17:57:59 +0900531
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800532 int change = isPackageDisappearing(imi.getPackageName());
satoke7c6998e2011-06-03 17:57:59 +0900533 if (isPackageModified(imi.getPackageName())) {
534 mFileManager.deleteAllInputMethodSubtypes(imiId);
535 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800536 if (change == PACKAGE_TEMPORARY_CHANGE
537 || change == PACKAGE_PERMANENT_CHANGE) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800538 Slog.i(TAG, "Input method uninstalled, disabling: "
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800539 + imi.getComponent());
540 setInputMethodEnabledLocked(imi.getId(), false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 }
542 }
543 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800544
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900545 buildInputMethodListLocked(
546 mMethodList, mMethodMap, false /* resetDefaultEnabledIme */);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800549
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800550 if (curIm != null) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800551 int change = isPackageDisappearing(curIm.getPackageName());
552 if (change == PACKAGE_TEMPORARY_CHANGE
553 || change == PACKAGE_PERMANENT_CHANGE) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800554 ServiceInfo si = null;
555 try {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900556 si = mIPackageManager.getServiceInfo(
557 curIm.getComponent(), 0, mSettings.getCurrentUserId());
558 } catch (RemoteException ex) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800559 }
560 if (si == null) {
561 // Uh oh, current input method is no longer around!
562 // Pick another one...
Joe Onorato8a9b2202010-02-26 18:56:32 -0800563 Slog.i(TAG, "Current input method removed: " + curInputMethodId);
satok15452a42011-10-28 17:58:28 +0900564 setImeWindowVisibilityStatusHiddenLocked();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800565 if (!chooseNewDefaultIMELocked()) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800566 changed = true;
567 curIm = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800568 Slog.i(TAG, "Unsetting current input method");
satok723a27e2010-11-11 14:58:11 +0900569 resetSelectedInputMethodAndSubtypeLocked("");
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800570 }
571 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800572 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800573 }
satokab751aa2010-09-14 19:17:36 +0900574
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800575 if (curIm == null) {
576 // We currently don't have a default input method... is
577 // one now available?
578 changed = chooseNewDefaultIMELocked();
579 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800580
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800581 if (changed) {
Dianne Hackbornfd7aded2013-01-22 17:10:23 -0800582 updateFromSettingsLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 }
584 }
585 }
586 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800587
Jeff Brownc28867a2013-03-26 15:42:39 -0700588 private static final class MethodCallback extends IInputSessionCallback.Stub {
Jean Chalarde0d32a62011-10-20 20:36:07 +0900589 private final InputMethodManagerService mParentIMMS;
Jeff Brownc28867a2013-03-26 15:42:39 -0700590 private final IInputMethod mMethod;
591 private final InputChannel mChannel;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800592
Jeff Brownc28867a2013-03-26 15:42:39 -0700593 MethodCallback(InputMethodManagerService imms, IInputMethod method,
594 InputChannel channel) {
Jean Chalarde0d32a62011-10-20 20:36:07 +0900595 mParentIMMS = imms;
Jeff Brownc28867a2013-03-26 15:42:39 -0700596 mMethod = method;
597 mChannel = channel;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800599
satoke7c6998e2011-06-03 17:57:59 +0900600 @Override
Jeff Brownc28867a2013-03-26 15:42:39 -0700601 public void sessionCreated(IInputMethodSession session) {
Dianne Hackborn6b6b3fd2014-03-24 11:27:18 -0700602 long ident = Binder.clearCallingIdentity();
603 try {
604 mParentIMMS.onSessionCreated(mMethod, session, mChannel);
605 } finally {
606 Binder.restoreCallingIdentity(ident);
607 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 }
609 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800610
satok01038492012-04-09 21:08:27 +0900611 private class HardKeyboardListener
612 implements WindowManagerService.OnHardKeyboardStatusChangeListener {
613 @Override
Michael Wright7b5a96b2014-08-09 19:28:42 -0700614 public void onHardKeyboardStatusChange(boolean available) {
615 mHandler.sendMessage(mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED,
616 available ? 1 : 0));
satok01038492012-04-09 21:08:27 +0900617 }
618
Michael Wright7b5a96b2014-08-09 19:28:42 -0700619 public void handleHardKeyboardStatusChange(boolean available) {
satok01038492012-04-09 21:08:27 +0900620 if (DEBUG) {
Michael Wright7b5a96b2014-08-09 19:28:42 -0700621 Slog.w(TAG, "HardKeyboardStatusChanged: available=" + available);
satok01038492012-04-09 21:08:27 +0900622 }
623 synchronized(mMethodMap) {
624 if (mSwitchingDialog != null && mSwitchingDialogTitleView != null
625 && mSwitchingDialog.isShowing()) {
626 mSwitchingDialogTitleView.findViewById(
627 com.android.internal.R.id.hard_keyboard_section).setVisibility(
628 available ? View.VISIBLE : View.GONE);
629 }
630 }
631 }
632 }
633
634 public InputMethodManagerService(Context context, WindowManagerService windowManager) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900635 mIPackageManager = AppGlobals.getPackageManager();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 mContext = context;
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -0800637 mRes = context.getResources();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 mHandler = new Handler(this);
639 mIWindowManager = IWindowManager.Stub.asInterface(
640 ServiceManager.getService(Context.WINDOW_SERVICE));
Mita Yuned218c72012-12-06 17:18:25 -0800641 mCaller = new HandlerCaller(context, null, new HandlerCaller.Callback() {
satoke7c6998e2011-06-03 17:57:59 +0900642 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 public void executeMessage(Message msg) {
644 handleMessage(msg);
645 }
Mita Yuned218c72012-12-06 17:18:25 -0800646 }, true /*asyncHandler*/);
satok01038492012-04-09 21:08:27 +0900647 mWindowManagerService = windowManager;
Yohei Yukawae63b5fa2014-09-19 13:14:55 +0900648 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
satok01038492012-04-09 21:08:27 +0900649 mHardKeyboardListener = new HardKeyboardListener();
Dianne Hackborn119bbc32013-03-22 17:27:25 -0700650 mHasFeature = context.getPackageManager().hasSystemFeature(
651 PackageManager.FEATURE_INPUT_METHODS);
satok7cfc0ed2011-06-20 21:29:36 +0900652
satok7cfc0ed2011-06-20 21:29:36 +0900653 mImeSwitcherNotification = new Notification();
654 mImeSwitcherNotification.icon = com.android.internal.R.drawable.ic_notification_ime_default;
655 mImeSwitcherNotification.when = 0;
656 mImeSwitcherNotification.flags = Notification.FLAG_ONGOING_EVENT;
657 mImeSwitcherNotification.tickerText = null;
658 mImeSwitcherNotification.defaults = 0; // please be quiet
659 mImeSwitcherNotification.sound = null;
660 mImeSwitcherNotification.vibrate = null;
Daniel Sandler590d5152012-06-14 16:10:13 -0400661
662 // Tag this notification specially so SystemUI knows it's important
John Spurlockfd7f1e02014-03-18 16:41:57 -0400663 mImeSwitcherNotification.extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true);
664 mImeSwitcherNotification.category = Notification.CATEGORY_SYSTEM;
Daniel Sandler590d5152012-06-14 16:10:13 -0400665
satok7cfc0ed2011-06-20 21:29:36 +0900666 Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER);
satok683e2382011-07-12 08:28:52 +0900667 mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
satokb858c732011-07-22 19:54:34 +0900668
669 mShowOngoingImeSwitcherForPhones = false;
satok7cfc0ed2011-06-20 21:29:36 +0900670
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900671 final IntentFilter broadcastFilter = new IntentFilter();
672 broadcastFilter.addAction(Intent.ACTION_SCREEN_ON);
673 broadcastFilter.addAction(Intent.ACTION_SCREEN_OFF);
674 broadcastFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
Amith Yamasani734983f2014-03-04 16:48:05 -0800675 broadcastFilter.addAction(Intent.ACTION_USER_ADDED);
676 broadcastFilter.addAction(Intent.ACTION_USER_REMOVED);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900677 mContext.registerReceiver(new ImmsBroadcastReceiver(), broadcastFilter);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800678
satok7cfc0ed2011-06-20 21:29:36 +0900679 mNotificationShown = false;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900680 int userId = 0;
681 try {
682 ActivityManagerNative.getDefault().registerUserSwitchObserver(
683 new IUserSwitchObserver.Stub() {
684 @Override
685 public void onUserSwitching(int newUserId, IRemoteCallback reply) {
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +0900686 synchronized(mMethodMap) {
687 switchUserLocked(newUserId);
688 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900689 if (reply != null) {
690 try {
691 reply.sendResult(null);
692 } catch (RemoteException e) {
693 }
694 }
695 }
696
697 @Override
698 public void onUserSwitchComplete(int newUserId) throws RemoteException {
699 }
700 });
701 userId = ActivityManagerNative.getDefault().getCurrentUser().id;
702 } catch (RemoteException e) {
703 Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e);
704 }
satok81f8b7c2012-12-04 20:42:56 +0900705 mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true);
satok913a8922010-08-26 21:53:41 +0900706
satokd87c2592010-09-29 11:52:06 +0900707 // mSettings should be created before buildInputMethodListLocked
satokdf31ae62011-01-15 06:19:44 +0900708 mSettings = new InputMethodSettings(
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900709 mRes, context.getContentResolver(), mMethodMap, mMethodList, userId);
Kenny Guy2a764942014-04-02 13:29:20 +0100710 updateCurrentProfileIds();
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +0900711 mFileManager = new InputMethodFileManager(mMethodMap, userId);
Yohei Yukawa5a647b692014-05-22 12:49:00 +0900712 synchronized (mMethodMap) {
713 mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked(
714 mSettings, context);
715 }
satok0a1bcf42012-05-16 19:26:31 +0900716
717 // Just checking if defaultImiId is empty or not
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900718 final String defaultImiId = mSettings.getSelectedInputMethod();
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900719 if (DEBUG) {
720 Slog.d(TAG, "Initial default ime = " + defaultImiId);
721 }
satok0a1bcf42012-05-16 19:26:31 +0900722 mImeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId);
723
Yohei Yukawa5a647b692014-05-22 12:49:00 +0900724 synchronized (mMethodMap) {
725 buildInputMethodListLocked(mMethodList, mMethodMap,
726 !mImeSelectedOnBoot /* resetDefaultEnabledIme */);
727 }
satokd87c2592010-09-29 11:52:06 +0900728 mSettings.enableAllIMEsIfThereIsNoEnabledIME();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729
satok0a1bcf42012-05-16 19:26:31 +0900730 if (!mImeSelectedOnBoot) {
731 Slog.w(TAG, "No IME selected. Choose the most applicable IME.");
Yohei Yukawa5a647b692014-05-22 12:49:00 +0900732 synchronized (mMethodMap) {
733 resetDefaultImeLocked(context);
734 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 mSettingsObserver = new SettingsObserver(mHandler);
Yohei Yukawa5a647b692014-05-22 12:49:00 +0900738 synchronized (mMethodMap) {
739 updateFromSettingsLocked(true);
740 }
satok5b927c432012-05-01 20:09:34 +0900741
742 // IMMS wants to receive Intent.ACTION_LOCALE_CHANGED in order to update the current IME
743 // according to the new system locale.
744 final IntentFilter filter = new IntentFilter();
745 filter.addAction(Intent.ACTION_LOCALE_CHANGED);
746 mContext.registerReceiver(
747 new BroadcastReceiver() {
748 @Override
749 public void onReceive(Context context, Intent intent) {
750 synchronized(mMethodMap) {
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +0900751 resetStateIfCurrentLocaleChangedLocked();
satok5b927c432012-05-01 20:09:34 +0900752 }
753 }
754 }, filter);
755 }
756
satok5b927c432012-05-01 20:09:34 +0900757 private void resetDefaultImeLocked(Context context) {
758 // Do not reset the default (current) IME when it is a 3rd-party IME
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +0900759 if (mCurMethodId != null
760 && !InputMethodUtils.isSystemIme(mMethodMap.get(mCurMethodId))) {
satok5b927c432012-05-01 20:09:34 +0900761 return;
762 }
763
764 InputMethodInfo defIm = null;
765 for (InputMethodInfo imi : mMethodList) {
766 if (defIm == null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +0900767 if (InputMethodUtils.isValidSystemDefaultIme(
768 mSystemReady, imi, context)) {
satok5b927c432012-05-01 20:09:34 +0900769 defIm = imi;
770 Slog.i(TAG, "Selected default: " + imi.getId());
771 }
772 }
773 }
774 if (defIm == null && mMethodList.size() > 0) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +0900775 defIm = InputMethodUtils.getMostApplicableDefaultIME(
776 mSettings.getEnabledInputMethodListLocked());
Hyejin Kim5baaaac2014-10-27 17:17:06 +0900777 if (defIm != null) {
778 Slog.i(TAG, "Default found, using " + defIm.getId());
779 } else {
780 Slog.i(TAG, "No default found");
781 }
satok5b927c432012-05-01 20:09:34 +0900782 }
783 if (defIm != null) {
784 setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false);
785 }
786 }
787
Satoshi Kataoka7f7535f2013-02-18 12:54:16 +0900788 private void resetAllInternalStateLocked(final boolean updateOnlyWhenLocaleChanged,
789 final boolean resetDefaultEnabledIme) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900790 if (!mSystemReady) {
791 // not system ready
792 return;
793 }
794 final Locale newLocale = mRes.getConfiguration().locale;
795 if (!updateOnlyWhenLocaleChanged
796 || (newLocale != null && !newLocale.equals(mLastSystemLocale))) {
797 if (!updateOnlyWhenLocaleChanged) {
798 hideCurrentInputLocked(0, null);
799 mCurMethodId = null;
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -0700800 unbindCurrentMethodLocked(true, false);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900801 }
802 if (DEBUG) {
803 Slog.i(TAG, "Locale has been changed to " + newLocale);
804 }
Satoshi Kataoka7f7535f2013-02-18 12:54:16 +0900805 buildInputMethodListLocked(mMethodList, mMethodMap, resetDefaultEnabledIme);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900806 if (!updateOnlyWhenLocaleChanged) {
807 final String selectedImiId = mSettings.getSelectedInputMethod();
808 if (TextUtils.isEmpty(selectedImiId)) {
809 // This is the first time of the user switch and
810 // set the current ime to the proper one.
811 resetDefaultImeLocked(mContext);
812 }
Satoshi Kataokad08a9232012-09-28 15:59:58 +0900813 } else {
814 // If the locale is changed, needs to reset the default ime
815 resetDefaultImeLocked(mContext);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900816 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -0800817 updateFromSettingsLocked(true);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900818 mLastSystemLocale = newLocale;
819 if (!updateOnlyWhenLocaleChanged) {
820 try {
821 startInputInnerLocked();
822 } catch (RuntimeException e) {
823 Slog.w(TAG, "Unexpected exception", e);
824 }
825 }
826 }
827 }
828
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +0900829 private void resetStateIfCurrentLocaleChangedLocked() {
Satoshi Kataoka7f7535f2013-02-18 12:54:16 +0900830 resetAllInternalStateLocked(true /* updateOnlyWhenLocaleChanged */,
831 true /* resetDefaultImeLocked */);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900832 }
833
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +0900834 private void switchUserLocked(int newUserId) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900835 mSettings.setCurrentUserId(newUserId);
Kenny Guy2a764942014-04-02 13:29:20 +0100836 updateCurrentProfileIds();
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +0900837 // InputMethodFileManager should be reset when the user is changed
838 mFileManager = new InputMethodFileManager(mMethodMap, newUserId);
Satoshi Kataoka7f7535f2013-02-18 12:54:16 +0900839 final String defaultImiId = mSettings.getSelectedInputMethod();
Satoshi Kataoka7c4a2a12013-02-25 15:25:43 +0900840 // For secondary users, the list of enabled IMEs may not have been updated since the
841 // callbacks to PackageMonitor are ignored for the secondary user. Here, defaultImiId may
842 // not be empty even if the IME has been uninstalled by the primary user.
843 // Even in such cases, IMMS works fine because it will find the most applicable
844 // IME for that user.
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +0900845 final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId);
Satoshi Kataoka7f7535f2013-02-18 12:54:16 +0900846 if (DEBUG) {
847 Slog.d(TAG, "Switch user: " + newUserId + " current ime = " + defaultImiId);
848 }
849 resetAllInternalStateLocked(false /* updateOnlyWhenLocaleChanged */,
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +0900850 initialUserSwitch /* needsToResetDefaultIme */);
851 if (initialUserSwitch) {
852 InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mContext.getPackageManager(),
853 mSettings.getEnabledInputMethodListLocked());
854 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900855 }
856
Kenny Guy2a764942014-04-02 13:29:20 +0100857 void updateCurrentProfileIds() {
858 List<UserInfo> profiles =
859 UserManager.get(mContext).getProfiles(mSettings.getCurrentUserId());
860 int[] currentProfileIds = new int[profiles.size()]; // profiles will not be null
861 for (int i = 0; i < currentProfileIds.length; i++) {
862 currentProfileIds[i] = profiles.get(i).id;
Amith Yamasani734983f2014-03-04 16:48:05 -0800863 }
Kenny Guy2a764942014-04-02 13:29:20 +0100864 mSettings.setCurrentProfileIds(currentProfileIds);
Amith Yamasani734983f2014-03-04 16:48:05 -0800865 }
866
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800867 @Override
868 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
869 throws RemoteException {
870 try {
871 return super.onTransact(code, data, reply, flags);
872 } catch (RuntimeException e) {
873 // The input method manager only throws security exceptions, so let's
874 // log all others.
875 if (!(e instanceof SecurityException)) {
Dianne Hackborn164371f2013-10-01 19:10:13 -0700876 Slog.wtf(TAG, "Input Method Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 }
878 throw e;
879 }
880 }
881
Svetoslav Ganova0027152013-06-25 14:59:53 -0700882 public void systemRunning(StatusBarManagerService statusBar) {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700883 synchronized (mMethodMap) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900884 if (DEBUG) {
885 Slog.d(TAG, "--- systemReady");
886 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700887 if (!mSystemReady) {
888 mSystemReady = true;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900889 mKeyguardManager =
890 (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700891 mNotificationManager = (NotificationManager)
892 mContext.getSystemService(Context.NOTIFICATION_SERVICE);
893 mStatusBar = statusBar;
894 statusBar.setIconVisibility("ime", false);
895 updateImeWindowStatusLocked();
satokb858c732011-07-22 19:54:34 +0900896 mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
897 com.android.internal.R.bool.show_ongoing_ime_switcher);
satok01038492012-04-09 21:08:27 +0900898 if (mShowOngoingImeSwitcherForPhones) {
899 mWindowManagerService.setOnHardKeyboardStatusChangeListener(
900 mHardKeyboardListener);
901 }
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900902 buildInputMethodListLocked(mMethodList, mMethodMap,
903 !mImeSelectedOnBoot /* resetDefaultEnabledIme */);
satok0a1bcf42012-05-16 19:26:31 +0900904 if (!mImeSelectedOnBoot) {
905 Slog.w(TAG, "Reset the default IME as \"Resource\" is ready here.");
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +0900906 resetStateIfCurrentLocaleChangedLocked();
907 InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(
908 mContext.getPackageManager(),
909 mSettings.getEnabledInputMethodListLocked());
satok0a1bcf42012-05-16 19:26:31 +0900910 }
911 mLastSystemLocale = mRes.getConfiguration().locale;
Dianne Hackborncc278702009-09-02 23:07:23 -0700912 try {
913 startInputInnerLocked();
914 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800915 Slog.w(TAG, "Unexpected exception", e);
Dianne Hackborncc278702009-09-02 23:07:23 -0700916 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700917 }
918 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800920
satok15452a42011-10-28 17:58:28 +0900921 private void setImeWindowVisibilityStatusHiddenLocked() {
922 mImeWindowVis = 0;
923 updateImeWindowStatusLocked();
924 }
925
satok3afd6c02011-11-18 08:38:19 +0900926 private void refreshImeWindowVisibilityLocked() {
927 final Configuration conf = mRes.getConfiguration();
928 final boolean haveHardKeyboard = conf.keyboard
929 != Configuration.KEYBOARD_NOKEYS;
930 final boolean hardKeyShown = haveHardKeyboard
931 && conf.hardKeyboardHidden
932 != Configuration.HARDKEYBOARDHIDDEN_YES;
John Spurlocke0980502013-10-25 11:59:29 -0400933
934 final boolean isScreenLocked = isKeyguardLocked();
935 final boolean inputActive = !isScreenLocked && (mInputShown || hardKeyShown);
John Spurlock36439b42013-10-23 16:36:47 -0400936 // We assume the softkeyboard is shown when the input is active as long as the
937 // hard keyboard is not shown.
938 final boolean inputVisible = inputActive && !hardKeyShown;
939 mImeWindowVis = (inputActive ? InputMethodService.IME_ACTIVE : 0)
940 | (inputVisible ? InputMethodService.IME_VISIBLE : 0);
satok3afd6c02011-11-18 08:38:19 +0900941 updateImeWindowStatusLocked();
942 }
943
satok15452a42011-10-28 17:58:28 +0900944 private void updateImeWindowStatusLocked() {
satokdbf29502011-08-25 15:28:23 +0900945 setImeWindowStatus(mCurToken, mImeWindowVis, mBackDisposition);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700946 }
947
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900948 // ---------------------------------------------------------------------------------------
949 // Check whether or not this is a valid IPC. Assumes an IPC is valid when either
950 // 1) it comes from the system process
951 // 2) the calling process' user id is identical to the current user id IMMS thinks.
952 private boolean calledFromValidUser() {
953 final int uid = Binder.getCallingUid();
954 final int userId = UserHandle.getUserId(uid);
955 if (DEBUG) {
956 Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? "
957 + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID
958 + " calling userId = " + userId + ", foreground user id = "
Satoshi Kataoka87c29142013-07-31 23:11:54 +0900959 + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid()
960 + InputMethodUtils.getApiCallStack());
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900961 }
Kenny Guy2a764942014-04-02 13:29:20 +0100962 if (uid == Process.SYSTEM_UID || mSettings.isCurrentProfile(userId)) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900963 return true;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900964 }
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +0900965
966 // Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the
967 // foreground user, not for the user of that process. Accordingly InputMethodManagerService
968 // must not manage background users' states in any functions.
969 // Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded
970 // by a token.
971 if (mContext.checkCallingOrSelfPermission(
972 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
973 == PackageManager.PERMISSION_GRANTED) {
974 if (DEBUG) {
975 Slog.d(TAG, "--- Access granted because the calling process has "
976 + "the INTERACT_ACROSS_USERS_FULL permission");
977 }
978 return true;
979 }
Satoshi Kataoka0766eb02013-07-31 18:30:13 +0900980 Slog.w(TAG, "--- IPC called from background users. Ignore. \n"
981 + InputMethodUtils.getStackTrace());
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +0900982 return false;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900983 }
984
Yohei Yukawa22c97be2014-06-04 19:43:36 +0900985
986 /**
987 * Returns true iff the caller is identified to be the current input method with the token.
988 * @param token The window token given to the input method when it was started.
989 * @return true if and only if non-null valid token is specified.
990 */
991 private boolean calledWithValidToken(IBinder token) {
992 if (token == null || mCurToken != token) {
993 return false;
994 }
995 return true;
996 }
997
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900998 private boolean bindCurrentInputMethodService(
999 Intent service, ServiceConnection conn, int flags) {
1000 if (service == null || conn == null) {
1001 Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn);
1002 return false;
1003 }
Amith Yamasani27b89e62013-01-16 12:30:11 -08001004 return mContext.bindServiceAsUser(service, conn, flags,
1005 new UserHandle(mSettings.getCurrentUserId()));
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001006 }
1007
satoke7c6998e2011-06-03 17:57:59 +09001008 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 public List<InputMethodInfo> getInputMethodList() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001010 // TODO: Make this work even for non-current users?
1011 if (!calledFromValidUser()) {
1012 return Collections.emptyList();
1013 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 synchronized (mMethodMap) {
1015 return new ArrayList<InputMethodInfo>(mMethodList);
1016 }
1017 }
1018
satoke7c6998e2011-06-03 17:57:59 +09001019 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 public List<InputMethodInfo> getEnabledInputMethodList() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001021 // TODO: Make this work even for non-current users?
1022 if (!calledFromValidUser()) {
1023 return Collections.emptyList();
1024 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 synchronized (mMethodMap) {
satokd87c2592010-09-29 11:52:06 +09001026 return mSettings.getEnabledInputMethodListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001027 }
1028 }
1029
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001030 /**
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001031 * @param imiId if null, returns enabled subtypes for the current imi
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001032 * @return enabled subtypes of the specified imi
1033 */
satoke7c6998e2011-06-03 17:57:59 +09001034 @Override
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001035 public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId,
satok16331c82010-12-20 23:48:46 +09001036 boolean allowsImplicitlySelectedSubtypes) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001037 // TODO: Make this work even for non-current users?
1038 if (!calledFromValidUser()) {
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001039 return Collections.<InputMethodSubtype>emptyList();
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001040 }
satok67ddf9c2010-11-17 09:45:54 +09001041 synchronized (mMethodMap) {
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001042 final InputMethodInfo imi;
1043 if (imiId == null && mCurMethodId != null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001044 imi = mMethodMap.get(mCurMethodId);
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001045 } else {
1046 imi = mMethodMap.get(imiId);
1047 }
1048 if (imi == null) {
1049 return Collections.<InputMethodSubtype>emptyList();
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001050 }
1051 return mSettings.getEnabledInputMethodSubtypeListLocked(
1052 mContext, imi, allowsImplicitlySelectedSubtypes);
satok67ddf9c2010-11-17 09:45:54 +09001053 }
1054 }
1055
satoke7c6998e2011-06-03 17:57:59 +09001056 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 public void addClient(IInputMethodClient client,
1058 IInputContext inputContext, int uid, int pid) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001059 if (!calledFromValidUser()) {
1060 return;
1061 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 synchronized (mMethodMap) {
1063 mClients.put(client.asBinder(), new ClientState(client,
1064 inputContext, uid, pid));
1065 }
1066 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001067
satoke7c6998e2011-06-03 17:57:59 +09001068 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 public void removeClient(IInputMethodClient client) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001070 if (!calledFromValidUser()) {
1071 return;
1072 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 synchronized (mMethodMap) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001074 ClientState cs = mClients.remove(client.asBinder());
1075 if (cs != null) {
1076 clearClientSessionLocked(cs);
1077 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 }
1079 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 void executeOrSendMessage(IInterface target, Message msg) {
1082 if (target.asBinder() instanceof Binder) {
1083 mCaller.sendMessage(msg);
1084 } else {
1085 handleMessage(msg);
1086 msg.recycle();
1087 }
1088 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001089
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001090 void unbindCurrentClientLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 if (mCurClient != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001092 if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001093 + mCurClient.client.asBinder());
1094 if (mBoundToMethod) {
1095 mBoundToMethod = false;
1096 if (mCurMethod != null) {
1097 executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
1098 MSG_UNBIND_INPUT, mCurMethod));
1099 }
1100 }
Dianne Hackborna6e41342012-05-22 16:30:34 -07001101
1102 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
1103 MSG_SET_ACTIVE, 0, mCurClient));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
1105 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
1106 mCurClient.sessionRequested = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 mCurClient = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001108
The Android Open Source Project10592532009-03-18 17:39:46 -07001109 hideInputMethodMenuLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 }
1111 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001112
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001113 private int getImeShowFlags() {
1114 int flags = 0;
1115 if (mShowForced) {
1116 flags |= InputMethod.SHOW_FORCED
1117 | InputMethod.SHOW_EXPLICIT;
1118 } else if (mShowExplicitlyRequested) {
1119 flags |= InputMethod.SHOW_EXPLICIT;
1120 }
1121 return flags;
1122 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 private int getAppShowFlags() {
1125 int flags = 0;
1126 if (mShowForced) {
1127 flags |= InputMethodManager.SHOW_FORCED;
1128 } else if (!mShowExplicitlyRequested) {
1129 flags |= InputMethodManager.SHOW_IMPLICIT;
1130 }
1131 return flags;
1132 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001133
Dianne Hackborn7663d802012-02-24 13:08:49 -08001134 InputBindResult attachNewInputLocked(boolean initial) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 if (!mBoundToMethod) {
1136 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
1137 MSG_BIND_INPUT, mCurMethod, mCurClient.binding));
1138 mBoundToMethod = true;
1139 }
1140 final SessionState session = mCurClient.curSession;
1141 if (initial) {
1142 executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
1143 MSG_START_INPUT, session, mCurInputContext, mCurAttribute));
1144 } else {
1145 executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
1146 MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute));
1147 }
1148 if (mShowRequested) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001149 if (DEBUG) Slog.v(TAG, "Attach new input asks to show input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001150 showCurrentInputLocked(getAppShowFlags(), null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 }
Jeff Brown1951ce82013-04-04 22:45:12 -07001152 return new InputBindResult(session.session,
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001153 (session.channel != null ? session.channel.dup() : null),
1154 mCurId, mCurSeq, mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 InputBindResult startInputLocked(IInputMethodClient client,
Dianne Hackborn7663d802012-02-24 13:08:49 -08001158 IInputContext inputContext, EditorInfo attribute, int controlFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 // If no method is currently selected, do nothing.
1160 if (mCurMethodId == null) {
1161 return mNoBinding;
1162 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 ClientState cs = mClients.get(client.asBinder());
1165 if (cs == null) {
1166 throw new IllegalArgumentException("unknown client "
1167 + client.asBinder());
1168 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 try {
1171 if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
1172 // Check with the window manager to make sure this client actually
1173 // has a window with focus. If not, reject. This is thread safe
1174 // because if the focus changes some time before or after, the
1175 // next client receiving focus that has any interest in input will
1176 // be calling through here after that change happens.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001177 Slog.w(TAG, "Starting input on non-focused client " + cs.client
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
1179 return null;
1180 }
1181 } catch (RemoteException e) {
1182 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001183
Dianne Hackborn7663d802012-02-24 13:08:49 -08001184 return startInputUncheckedLocked(cs, inputContext, attribute, controlFlags);
1185 }
1186
1187 InputBindResult startInputUncheckedLocked(ClientState cs,
1188 IInputContext inputContext, EditorInfo attribute, int controlFlags) {
1189 // If no method is currently selected, do nothing.
1190 if (mCurMethodId == null) {
1191 return mNoBinding;
1192 }
1193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001194 if (mCurClient != cs) {
John Spurlocke0980502013-10-25 11:59:29 -04001195 // Was the keyguard locked when switching over to the new client?
1196 mCurClientInKeyguard = isKeyguardLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 // If the client is changing, we need to switch over to the new
1198 // one.
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001199 unbindCurrentClientLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001200 if (DEBUG) Slog.v(TAG, "switching to client: client = "
John Spurlocke0980502013-10-25 11:59:29 -04001201 + cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202
1203 // If the screen is on, inform the new client it is active
1204 if (mScreenOn) {
Dianne Hackborna6e41342012-05-22 16:30:34 -07001205 executeOrSendMessage(cs.client, mCaller.obtainMessageIO(
1206 MSG_SET_ACTIVE, mScreenOn ? 1 : 0, cs));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 }
1208 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 // Bump up the sequence for this client and attach it.
1211 mCurSeq++;
1212 if (mCurSeq <= 0) mCurSeq = 1;
1213 mCurClient = cs;
1214 mCurInputContext = inputContext;
1215 mCurAttribute = attribute;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001216
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 // Check if the input method is changing.
1218 if (mCurId != null && mCurId.equals(mCurMethodId)) {
1219 if (cs.curSession != null) {
1220 // Fast case: if we are already connected to the input method,
1221 // then just return it.
Dianne Hackborn7663d802012-02-24 13:08:49 -08001222 return attachNewInputLocked(
1223 (controlFlags&InputMethodManager.CONTROL_START_INITIAL) != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 }
1225 if (mHaveConnection) {
1226 if (mCurMethod != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 // Return to client, and we will get back with it when
1228 // we have had a session made for it.
Jeff Brownc28867a2013-03-26 15:42:39 -07001229 requestClientSessionLocked(cs);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001230 return new InputBindResult(null, null, mCurId, mCurSeq,
1231 mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001232 } else if (SystemClock.uptimeMillis()
1233 < (mLastBindTime+TIME_TO_RECONNECT)) {
1234 // In this case we have connected to the service, but
1235 // don't yet have its interface. If it hasn't been too
1236 // long since we did the connection, we'll return to
1237 // the client and wait to get the service interface so
1238 // we can report back. If it has been too long, we want
1239 // to fall through so we can try a disconnect/reconnect
1240 // to see if we can get back in touch with the service.
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001241 return new InputBindResult(null, null, mCurId, mCurSeq,
1242 mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001243 } else {
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001244 EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME,
1245 mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001246 }
1247 }
1248 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001249
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001250 return startInputInnerLocked();
1251 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001252
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001253 InputBindResult startInputInnerLocked() {
1254 if (mCurMethodId == null) {
1255 return mNoBinding;
1256 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001257
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001258 if (!mSystemReady) {
1259 // If the system is not yet ready, we shouldn't be running third
1260 // party code.
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001261 return new InputBindResult(null, null, mCurMethodId, mCurSeq,
1262 mCurUserActionNotificationSequenceNumber);
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001263 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 InputMethodInfo info = mMethodMap.get(mCurMethodId);
1266 if (info == null) {
1267 throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
1268 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001269
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001270 unbindCurrentMethodLocked(false, true);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE);
1273 mCurIntent.setComponent(info.getComponent());
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07001274 mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
1275 com.android.internal.R.string.input_method_binding_label);
1276 mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
1277 mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0));
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001278 if (bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
Dianne Hackbornf0f94d12014-03-17 16:04:21 -07001279 | Context.BIND_NOT_VISIBLE | Context.BIND_NOT_FOREGROUND
1280 | Context.BIND_SHOWING_UI)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 mLastBindTime = SystemClock.uptimeMillis();
1282 mHaveConnection = true;
1283 mCurId = info.getId();
1284 mCurToken = new Binder();
1285 try {
Craig Mautnerca0ac712013-03-14 09:43:02 -07001286 if (true || DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 mIWindowManager.addWindowToken(mCurToken,
1288 WindowManager.LayoutParams.TYPE_INPUT_METHOD);
1289 } catch (RemoteException e) {
1290 }
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001291 return new InputBindResult(null, null, mCurId, mCurSeq,
1292 mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293 } else {
1294 mCurIntent = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001295 Slog.w(TAG, "Failure connecting to input method service: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001296 + mCurIntent);
1297 }
1298 return null;
1299 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001300
satoke7c6998e2011-06-03 17:57:59 +09001301 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 public InputBindResult startInput(IInputMethodClient client,
Dianne Hackborn7663d802012-02-24 13:08:49 -08001303 IInputContext inputContext, EditorInfo attribute, int controlFlags) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001304 if (!calledFromValidUser()) {
1305 return null;
1306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 synchronized (mMethodMap) {
1308 final long ident = Binder.clearCallingIdentity();
1309 try {
Dianne Hackborn7663d802012-02-24 13:08:49 -08001310 return startInputLocked(client, inputContext, attribute, controlFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311 } finally {
1312 Binder.restoreCallingIdentity(ident);
1313 }
1314 }
1315 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001316
satoke7c6998e2011-06-03 17:57:59 +09001317 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 public void finishInput(IInputMethodClient client) {
1319 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001320
satoke7c6998e2011-06-03 17:57:59 +09001321 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 public void onServiceConnected(ComponentName name, IBinder service) {
1323 synchronized (mMethodMap) {
1324 if (mCurIntent != null && name.equals(mCurIntent.getComponent())) {
1325 mCurMethod = IInputMethod.Stub.asInterface(service);
Dianne Hackborncc278702009-09-02 23:07:23 -07001326 if (mCurToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001327 Slog.w(TAG, "Service connected without a token!");
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001328 unbindCurrentMethodLocked(false, false);
Dianne Hackborncc278702009-09-02 23:07:23 -07001329 return;
1330 }
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07001331 if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken);
Dianne Hackborncc278702009-09-02 23:07:23 -07001332 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
1333 MSG_ATTACH_TOKEN, mCurMethod, mCurToken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 if (mCurClient != null) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001335 clearClientSessionLocked(mCurClient);
1336 requestClientSessionLocked(mCurClient);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 }
1338 }
1339 }
1340 }
1341
Jeff Brownc28867a2013-03-26 15:42:39 -07001342 void onSessionCreated(IInputMethod method, IInputMethodSession session,
1343 InputChannel channel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 synchronized (mMethodMap) {
1345 if (mCurMethod != null && method != null
1346 && mCurMethod.asBinder() == method.asBinder()) {
1347 if (mCurClient != null) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001348 clearClientSessionLocked(mCurClient);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001349 mCurClient.curSession = new SessionState(mCurClient,
Jeff Brownc28867a2013-03-26 15:42:39 -07001350 method, session, channel);
Dianne Hackborn7663d802012-02-24 13:08:49 -08001351 InputBindResult res = attachNewInputLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001352 if (res.method != null) {
1353 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO(
1354 MSG_BIND_METHOD, mCurClient.client, res));
1355 }
Jeff Brownc28867a2013-03-26 15:42:39 -07001356 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001357 }
1358 }
1359 }
Jeff Brownc28867a2013-03-26 15:42:39 -07001360
1361 // Session abandoned. Close its associated input channel.
1362 channel.dispose();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001363 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001364
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001365 void unbindCurrentMethodLocked(boolean reportToClient, boolean savePosition) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001366 if (mVisibleBound) {
1367 mContext.unbindService(mVisibleConnection);
1368 mVisibleBound = false;
1369 }
1370
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001371 if (mHaveConnection) {
1372 mContext.unbindService(this);
1373 mHaveConnection = false;
1374 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001375
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001376 if (mCurToken != null) {
1377 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001378 if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001379 if ((mImeWindowVis & InputMethodService.IME_ACTIVE) != 0 && savePosition) {
satoke0a99412012-05-10 02:22:58 +09001380 // The current IME is shown. Hence an IME switch (transition) is happening.
1381 mWindowManagerService.saveLastInputMethodWindowForTransition();
1382 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001383 mIWindowManager.removeWindowToken(mCurToken);
1384 } catch (RemoteException e) {
1385 }
1386 mCurToken = null;
1387 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001388
The Android Open Source Project10592532009-03-18 17:39:46 -07001389 mCurId = null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001390 clearCurMethodLocked();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001391
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001392 if (reportToClient && mCurClient != null) {
1393 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
1394 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
1395 }
1396 }
Jeff Brownc28867a2013-03-26 15:42:39 -07001397
1398 void requestClientSessionLocked(ClientState cs) {
1399 if (!cs.sessionRequested) {
1400 if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs);
1401 InputChannel[] channels = InputChannel.openInputChannelPair(cs.toString());
1402 cs.sessionRequested = true;
1403 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOOO(
1404 MSG_CREATE_SESSION, mCurMethod, channels[1],
1405 new MethodCallback(this, mCurMethod, channels[0])));
1406 }
1407 }
1408
1409 void clearClientSessionLocked(ClientState cs) {
1410 finishSessionLocked(cs.curSession);
1411 cs.curSession = null;
1412 cs.sessionRequested = false;
1413 }
1414
1415 private void finishSessionLocked(SessionState sessionState) {
1416 if (sessionState != null) {
1417 if (sessionState.session != null) {
1418 try {
1419 sessionState.session.finishSession();
1420 } catch (RemoteException e) {
1421 Slog.w(TAG, "Session failed to close due to remote exception", e);
1422 setImeWindowVisibilityStatusHiddenLocked();
1423 }
1424 sessionState.session = null;
1425 }
1426 if (sessionState.channel != null) {
1427 sessionState.channel.dispose();
1428 sessionState.channel = null;
Devin Taylor0c33ed22010-02-23 13:26:46 -06001429 }
1430 }
1431 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001432
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001433 void clearCurMethodLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 if (mCurMethod != null) {
1435 for (ClientState cs : mClients.values()) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001436 clearClientSessionLocked(cs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 }
Devin Taylor0c33ed22010-02-23 13:26:46 -06001438
Jeff Brownc28867a2013-03-26 15:42:39 -07001439 finishSessionLocked(mEnabledSession);
Devin Taylor0c33ed22010-02-23 13:26:46 -06001440 mEnabledSession = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001441 mCurMethod = null;
1442 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07001443 if (mStatusBar != null) {
1444 mStatusBar.setIconVisibility("ime", false);
1445 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001447
satoke7c6998e2011-06-03 17:57:59 +09001448 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 public void onServiceDisconnected(ComponentName name) {
1450 synchronized (mMethodMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001451 if (DEBUG) Slog.v(TAG, "Service disconnected: " + name
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 + " mCurIntent=" + mCurIntent);
1453 if (mCurMethod != null && mCurIntent != null
1454 && name.equals(mCurIntent.getComponent())) {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001455 clearCurMethodLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 // We consider this to be a new bind attempt, since the system
1457 // should now try to restart the service for us.
1458 mLastBindTime = SystemClock.uptimeMillis();
1459 mShowRequested = mInputShown;
1460 mInputShown = false;
1461 if (mCurClient != null) {
1462 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
1463 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
1464 }
1465 }
1466 }
1467 }
1468
satokf9f01002011-05-19 21:31:50 +09001469 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001470 public void updateStatusIcon(IBinder token, String packageName, int iconId) {
1471 long ident = Binder.clearCallingIdentity();
1472 try {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 synchronized (mMethodMap) {
Yohei Yukawaa0755742014-06-04 20:28:18 +09001474 if (!calledWithValidToken(token)) {
1475 final int uid = Binder.getCallingUid();
1476 Slog.e(TAG, "Ignoring updateStatusIcon due to an invalid token. uid:" + uid
1477 + " token:" + token);
1478 return;
1479 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 if (iconId == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001481 if (DEBUG) Slog.d(TAG, "hide the small icon for the input method");
Dianne Hackborn661cd522011-08-22 00:26:20 -07001482 if (mStatusBar != null) {
1483 mStatusBar.setIconVisibility("ime", false);
1484 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 } else if (packageName != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001486 if (DEBUG) Slog.d(TAG, "show a small icon for the input method");
Svetoslav Ganov6179ea32011-06-28 01:12:41 -07001487 CharSequence contentDescription = null;
1488 try {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001489 // Use PackageManager to load label
1490 final PackageManager packageManager = mContext.getPackageManager();
Svetoslav Ganov6179ea32011-06-28 01:12:41 -07001491 contentDescription = packageManager.getApplicationLabel(
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001492 mIPackageManager.getApplicationInfo(packageName, 0,
1493 mSettings.getCurrentUserId()));
1494 } catch (RemoteException e) {
Svetoslav Ganov6179ea32011-06-28 01:12:41 -07001495 /* ignore */
1496 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07001497 if (mStatusBar != null) {
1498 mStatusBar.setIcon("ime", packageName, iconId, 0,
1499 contentDescription != null
1500 ? contentDescription.toString() : null);
1501 mStatusBar.setIconVisibility("ime", true);
1502 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 }
1504 }
1505 } finally {
1506 Binder.restoreCallingIdentity(ident);
1507 }
1508 }
1509
satok7cfc0ed2011-06-20 21:29:36 +09001510 private boolean needsToShowImeSwitchOngoingNotification() {
1511 if (!mShowOngoingImeSwitcherForPhones) return false;
Jason Monk807ef762014-05-08 15:47:46 -04001512 if (mSwitchingDialog != null) return false;
satok2c93efc2012-04-02 19:33:47 +09001513 if (isScreenLocked()) return false;
satok7cfc0ed2011-06-20 21:29:36 +09001514 synchronized (mMethodMap) {
1515 List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
1516 final int N = imis.size();
satokb6359412011-06-28 17:47:41 +09001517 if (N > 2) return true;
1518 if (N < 1) return false;
1519 int nonAuxCount = 0;
1520 int auxCount = 0;
1521 InputMethodSubtype nonAuxSubtype = null;
1522 InputMethodSubtype auxSubtype = null;
satok7cfc0ed2011-06-20 21:29:36 +09001523 for(int i = 0; i < N; ++i) {
1524 final InputMethodInfo imi = imis.get(i);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001525 final List<InputMethodSubtype> subtypes =
1526 mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
satok7cfc0ed2011-06-20 21:29:36 +09001527 final int subtypeCount = subtypes.size();
1528 if (subtypeCount == 0) {
satokb6359412011-06-28 17:47:41 +09001529 ++nonAuxCount;
satok7cfc0ed2011-06-20 21:29:36 +09001530 } else {
1531 for (int j = 0; j < subtypeCount; ++j) {
satokb6359412011-06-28 17:47:41 +09001532 final InputMethodSubtype subtype = subtypes.get(j);
1533 if (!subtype.isAuxiliary()) {
1534 ++nonAuxCount;
1535 nonAuxSubtype = subtype;
1536 } else {
1537 ++auxCount;
1538 auxSubtype = subtype;
satok7cfc0ed2011-06-20 21:29:36 +09001539 }
1540 }
1541 }
satok7cfc0ed2011-06-20 21:29:36 +09001542 }
satokb6359412011-06-28 17:47:41 +09001543 if (nonAuxCount > 1 || auxCount > 1) {
1544 return true;
1545 } else if (nonAuxCount == 1 && auxCount == 1) {
1546 if (nonAuxSubtype != null && auxSubtype != null
satok9747f892011-09-12 15:56:40 +09001547 && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale())
1548 || auxSubtype.overridesImplicitlyEnabledSubtype()
1549 || nonAuxSubtype.overridesImplicitlyEnabledSubtype())
satokb6359412011-06-28 17:47:41 +09001550 && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) {
1551 return false;
1552 }
1553 return true;
1554 }
1555 return false;
satok7cfc0ed2011-06-20 21:29:36 +09001556 }
satok7cfc0ed2011-06-20 21:29:36 +09001557 }
1558
John Spurlocke0980502013-10-25 11:59:29 -04001559 private boolean isKeyguardLocked() {
1560 return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked();
1561 }
1562
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001563 // Caution! This method is called in this class. Handle multi-user carefully
satokdbf29502011-08-25 15:28:23 +09001564 @SuppressWarnings("deprecation")
satokf9f01002011-05-19 21:31:50 +09001565 @Override
Joe Onorato857fd9b2011-01-27 15:08:35 -08001566 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001567 final long ident = Binder.clearCallingIdentity();
satok06487a52010-10-29 11:37:18 +09001568 try {
Yohei Yukawa22c97be2014-06-04 19:43:36 +09001569 if (!calledWithValidToken(token)) {
1570 final int uid = Binder.getCallingUid();
1571 Slog.e(TAG, "Ignoring setImeWindowStatus due to an invalid token. uid:" + uid
1572 + " token:" + token);
satok06487a52010-10-29 11:37:18 +09001573 return;
1574 }
satok06487a52010-10-29 11:37:18 +09001575 synchronized (mMethodMap) {
John Spurlocke0980502013-10-25 11:59:29 -04001576 // apply policy for binder calls
1577 if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) {
1578 vis = 0;
1579 }
Joe Onorato857fd9b2011-01-27 15:08:35 -08001580 mImeWindowVis = vis;
1581 mBackDisposition = backDisposition;
jungheang.lee217fd292013-02-26 16:53:22 +09001582 final boolean iconVisibility = ((vis & (InputMethodService.IME_ACTIVE)) != 0)
1583 && (mWindowManagerService.isHardKeyboardAvailable()
1584 || (vis & (InputMethodService.IME_VISIBLE)) != 0);
Jason Monkb605fec2014-05-02 17:04:10 -04001585 final boolean needsToShowImeSwitcher = iconVisibility
1586 && needsToShowImeSwitchOngoingNotification();
1587 if (mStatusBar != null) {
1588 mStatusBar.setImeWindowStatus(token, vis, backDisposition,
1589 needsToShowImeSwitcher);
1590 }
satok5bc8e732011-07-22 21:07:23 +09001591 final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
Jason Monkb605fec2014-05-02 17:04:10 -04001592 if (imi != null && needsToShowImeSwitcher) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001593 // Used to load label
satok7cfc0ed2011-06-20 21:29:36 +09001594 final CharSequence title = mRes.getText(
1595 com.android.internal.R.string.select_input_method);
Satoshi Kataokab2827262013-07-04 19:43:14 +09001596 final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName(
1597 mContext, imi, mCurrentSubtype);
satok5bc8e732011-07-22 21:07:23 +09001598
Selim Cinek255dd042014-08-19 22:29:02 +02001599 mImeSwitcherNotification.color = mContext.getResources().getColor(
1600 com.android.internal.R.color.system_notification_accent_color);
satok7cfc0ed2011-06-20 21:29:36 +09001601 mImeSwitcherNotification.setLatestEventInfo(
satok5bc8e732011-07-22 21:07:23 +09001602 mContext, title, summary, mImeSwitchPendingIntent);
Jason Monke463c742014-05-02 12:31:45 -04001603 if ((mNotificationManager != null)
1604 && !mWindowManagerService.hasNavigationBar()) {
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +09001605 if (DEBUG) {
Satoshi Kataokab2827262013-07-04 19:43:14 +09001606 Slog.d(TAG, "--- show notification: label = " + summary);
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +09001607 }
1608 mNotificationManager.notifyAsUser(null,
Dianne Hackborn661cd522011-08-22 00:26:20 -07001609 com.android.internal.R.string.select_input_method,
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +09001610 mImeSwitcherNotification, UserHandle.ALL);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001611 mNotificationShown = true;
1612 }
satok7cfc0ed2011-06-20 21:29:36 +09001613 } else {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001614 if (mNotificationShown && mNotificationManager != null) {
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +09001615 if (DEBUG) {
1616 Slog.d(TAG, "--- hide notification");
1617 }
1618 mNotificationManager.cancelAsUser(null,
1619 com.android.internal.R.string.select_input_method, UserHandle.ALL);
satok7cfc0ed2011-06-20 21:29:36 +09001620 mNotificationShown = false;
1621 }
1622 }
satok06487a52010-10-29 11:37:18 +09001623 }
1624 } finally {
1625 Binder.restoreCallingIdentity(ident);
1626 }
1627 }
1628
satoke7c6998e2011-06-03 17:57:59 +09001629 @Override
satokf9f01002011-05-19 21:31:50 +09001630 public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001631 if (!calledFromValidUser()) {
1632 return;
1633 }
satokf9f01002011-05-19 21:31:50 +09001634 synchronized (mMethodMap) {
1635 final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
1636 for (int i = 0; i < spans.length; ++i) {
1637 SuggestionSpan ss = spans[i];
satok42c5a162011-05-26 16:46:14 +09001638 if (!TextUtils.isEmpty(ss.getNotificationTargetClassName())) {
satokf9f01002011-05-19 21:31:50 +09001639 mSecureSuggestionSpans.put(ss, currentImi);
1640 }
1641 }
1642 }
1643 }
1644
satoke7c6998e2011-06-03 17:57:59 +09001645 @Override
satokf9f01002011-05-19 21:31:50 +09001646 public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001647 if (!calledFromValidUser()) {
1648 return false;
1649 }
satokf9f01002011-05-19 21:31:50 +09001650 synchronized (mMethodMap) {
1651 final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span);
1652 // TODO: Do not send the intent if the process of the targetImi is already dead.
1653 if (targetImi != null) {
1654 final String[] suggestions = span.getSuggestions();
1655 if (index < 0 || index >= suggestions.length) return false;
satok42c5a162011-05-26 16:46:14 +09001656 final String className = span.getNotificationTargetClassName();
satokf9f01002011-05-19 21:31:50 +09001657 final Intent intent = new Intent();
1658 // Ensures that only a class in the original IME package will receive the
1659 // notification.
satok42c5a162011-05-26 16:46:14 +09001660 intent.setClassName(targetImi.getPackageName(), className);
satokf9f01002011-05-19 21:31:50 +09001661 intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED);
1662 intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString);
1663 intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]);
1664 intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode());
Amith Yamasanif043de92012-10-24 06:42:40 -07001665 final long ident = Binder.clearCallingIdentity();
1666 try {
1667 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
1668 } finally {
1669 Binder.restoreCallingIdentity(ident);
1670 }
satokf9f01002011-05-19 21:31:50 +09001671 return true;
1672 }
1673 }
1674 return false;
1675 }
1676
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001677 void updateFromSettingsLocked(boolean enabledMayChange) {
Michael Wright7b5a96b2014-08-09 19:28:42 -07001678 updateInputMethodsFromSettingsLocked(enabledMayChange);
1679 updateKeyboardFromSettingsLocked();
1680 }
1681
1682 void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) {
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001683 if (enabledMayChange) {
1684 List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
1685 for (int i=0; i<enabled.size(); i++) {
1686 // We allow the user to select "disabled until used" apps, so if they
1687 // are enabling one of those here we now need to make it enabled.
1688 InputMethodInfo imm = enabled.get(i);
1689 try {
1690 ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(),
1691 PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
1692 mSettings.getCurrentUserId());
Satoshi Kataoka7987a312013-04-17 18:59:33 +09001693 if (ai != null && ai.enabledSetting
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001694 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +09001695 if (DEBUG) {
1696 Slog.d(TAG, "Update state(" + imm.getId()
1697 + "): DISABLED_UNTIL_USED -> DEFAULT");
1698 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001699 mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(),
1700 PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07001701 PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(),
1702 mContext.getBasePackageName());
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001703 }
1704 } catch (RemoteException e) {
1705 }
1706 }
1707 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001708 // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and
1709 // ENABLED_INPUT_METHODS is taking care of keeping them correctly in
1710 // sync, so we will never have a DEFAULT_INPUT_METHOD that is not
1711 // enabled.
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001712 String id = mSettings.getSelectedInputMethod();
satok03eb319a2010-11-11 18:17:42 +09001713 // There is no input method selected, try to choose new applicable input method.
1714 if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001715 id = mSettings.getSelectedInputMethod();
satok03eb319a2010-11-11 18:17:42 +09001716 }
1717 if (!TextUtils.isEmpty(id)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001718 try {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001719 setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001721 Slog.w(TAG, "Unknown input method from prefs: " + id, e);
The Android Open Source Project10592532009-03-18 17:39:46 -07001722 mCurMethodId = null;
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001723 unbindCurrentMethodLocked(true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001724 }
satokf3db1af2010-11-23 13:34:33 +09001725 mShortcutInputMethodsAndSubtypes.clear();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001726 } else {
1727 // There is no longer an input method set, so stop any current one.
The Android Open Source Project10592532009-03-18 17:39:46 -07001728 mCurMethodId = null;
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001729 unbindCurrentMethodLocked(true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 }
Yohei Yukawa3d46bab2014-05-30 18:10:18 +09001731 // Here is not the perfect place to reset the switching controller. Ideally
1732 // mSwitchingController and mSettings should be able to share the same state.
1733 // TODO: Make sure that mSwitchingController and mSettings are sharing the
1734 // the same enabled IMEs list.
1735 mSwitchingController.resetCircularListLocked(mContext);
Michael Wright7b5a96b2014-08-09 19:28:42 -07001736
1737 }
1738
1739 public void updateKeyboardFromSettingsLocked() {
1740 mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled();
1741 if (mSwitchingDialog != null
1742 && mSwitchingDialogTitleView != null
1743 && mSwitchingDialog.isShowing()) {
1744 final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById(
1745 com.android.internal.R.id.hard_keyboard_switch);
1746 hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
1747 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001748 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001749
satokab751aa2010-09-14 19:17:36 +09001750 /* package */ void setInputMethodLocked(String id, int subtypeId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001751 InputMethodInfo info = mMethodMap.get(id);
1752 if (info == null) {
satok913a8922010-08-26 21:53:41 +09001753 throw new IllegalArgumentException("Unknown id: " + id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001755
Yohei Yukawae63b5fa2014-09-19 13:14:55 +09001756 if (mCurClient != null && mCurAttribute != null) {
1757 final int uid = mCurClient.uid;
1758 final String packageName = mCurAttribute.packageName;
1759 if (SystemConfig.getInstance().getFixedImeApps().contains(packageName)) {
1760 if (InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, uid, packageName)) {
1761 return;
1762 }
1763 // TODO: Do we need to lock the input method when the application reported an
1764 // incorrect package name?
1765 Slog.e(TAG, "Ignoring FixedImeApps due to the validation failure. uid=" + uid
1766 + " package=" + packageName);
1767 }
1768 }
1769
satokd81e9502012-05-21 12:58:45 +09001770 // See if we need to notify a subtype change within the same IME.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771 if (id.equals(mCurMethodId)) {
satokd81e9502012-05-21 12:58:45 +09001772 final int subtypeCount = info.getSubtypeCount();
1773 if (subtypeCount <= 0) {
1774 return;
satokcd7cd292010-11-20 15:46:23 +09001775 }
satokd81e9502012-05-21 12:58:45 +09001776 final InputMethodSubtype oldSubtype = mCurrentSubtype;
1777 final InputMethodSubtype newSubtype;
1778 if (subtypeId >= 0 && subtypeId < subtypeCount) {
1779 newSubtype = info.getSubtypeAt(subtypeId);
1780 } else {
1781 // If subtype is null, try to find the most applicable one from
1782 // getCurrentInputMethodSubtype.
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001783 newSubtype = getCurrentInputMethodSubtypeLocked();
satokd81e9502012-05-21 12:58:45 +09001784 }
1785 if (newSubtype == null || oldSubtype == null) {
1786 Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype
1787 + ", new subtype = " + newSubtype);
1788 return;
1789 }
1790 if (newSubtype != oldSubtype) {
1791 setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true);
1792 if (mCurMethod != null) {
1793 try {
1794 refreshImeWindowVisibilityLocked();
1795 mCurMethod.changeInputMethodSubtype(newSubtype);
1796 } catch (RemoteException e) {
1797 Slog.w(TAG, "Failed to call changeInputMethodSubtype");
satokab751aa2010-09-14 19:17:36 +09001798 }
1799 }
1800 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001801 return;
1802 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001803
satokd81e9502012-05-21 12:58:45 +09001804 // Changing to a different IME.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 final long ident = Binder.clearCallingIdentity();
1806 try {
satokab751aa2010-09-14 19:17:36 +09001807 // Set a subtype to this input method.
1808 // subtypeId the name of a subtype which will be set.
satok723a27e2010-11-11 14:58:11 +09001809 setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false);
1810 // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked()
1811 // because mCurMethodId is stored as a history in
1812 // setSelectedInputMethodAndSubtypeLocked().
1813 mCurMethodId = id;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814
1815 if (ActivityManagerNative.isSystemReady()) {
1816 Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001817 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001818 intent.putExtra("input_method_id", id);
Amith Yamasanicd757062012-10-19 18:23:52 -07001819 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001820 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001821 unbindCurrentClientLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 } finally {
1823 Binder.restoreCallingIdentity(ident);
1824 }
1825 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001826
satok42c5a162011-05-26 16:46:14 +09001827 @Override
The Android Open Source Project4df24232009-03-05 14:34:35 -08001828 public boolean showSoftInput(IInputMethodClient client, int flags,
1829 ResultReceiver resultReceiver) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001830 if (!calledFromValidUser()) {
1831 return false;
1832 }
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001833 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 long ident = Binder.clearCallingIdentity();
1835 try {
1836 synchronized (mMethodMap) {
1837 if (mCurClient == null || client == null
1838 || mCurClient.client.asBinder() != client.asBinder()) {
1839 try {
1840 // We need to check if this is the current client with
1841 // focus in the window manager, to allow this call to
1842 // be made before input is started in it.
1843 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001844 Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client);
The Android Open Source Project4df24232009-03-05 14:34:35 -08001845 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 }
1847 } catch (RemoteException e) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001848 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001849 }
1850 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001851
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07001852 if (DEBUG) Slog.v(TAG, "Client requesting input be shown");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001853 return showCurrentInputLocked(flags, resultReceiver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001854 }
1855 } finally {
1856 Binder.restoreCallingIdentity(ident);
1857 }
1858 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001859
The Android Open Source Project4df24232009-03-05 14:34:35 -08001860 boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 mShowRequested = true;
1862 if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) {
1863 mShowExplicitlyRequested = true;
1864 }
1865 if ((flags&InputMethodManager.SHOW_FORCED) != 0) {
1866 mShowExplicitlyRequested = true;
1867 mShowForced = true;
1868 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001869
Dianne Hackborncc278702009-09-02 23:07:23 -07001870 if (!mSystemReady) {
1871 return false;
1872 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001873
The Android Open Source Project4df24232009-03-05 14:34:35 -08001874 boolean res = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 if (mCurMethod != null) {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07001876 if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken);
The Android Open Source Project4df24232009-03-05 14:34:35 -08001877 executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO(
1878 MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod,
1879 resultReceiver));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 mInputShown = true;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001881 if (mHaveConnection && !mVisibleBound) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001882 bindCurrentInputMethodService(
Dianne Hackbornf0f94d12014-03-17 16:04:21 -07001883 mCurIntent, mVisibleConnection, Context.BIND_AUTO_CREATE
1884 | Context.BIND_TREAT_LIKE_ACTIVITY);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001885 mVisibleBound = true;
1886 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08001887 res = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888 } else if (mHaveConnection && SystemClock.uptimeMillis()
satok59b424c2011-09-30 17:21:46 +09001889 >= (mLastBindTime+TIME_TO_RECONNECT)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 // The client has asked to have the input method shown, but
1891 // we have been sitting here too long with a connection to the
1892 // service and no interface received, so let's disconnect/connect
1893 // to try to prod things along.
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001894 EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001895 SystemClock.uptimeMillis()-mLastBindTime,1);
satok59b424c2011-09-30 17:21:46 +09001896 Slog.w(TAG, "Force disconnect/connect to the IME in showCurrentInputLocked()");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897 mContext.unbindService(this);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001898 bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001899 | Context.BIND_NOT_VISIBLE);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001900 } else {
1901 if (DEBUG) {
1902 Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = "
1903 + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis()));
1904 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001905 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001906
The Android Open Source Project4df24232009-03-05 14:34:35 -08001907 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001908 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001909
satok42c5a162011-05-26 16:46:14 +09001910 @Override
The Android Open Source Project4df24232009-03-05 14:34:35 -08001911 public boolean hideSoftInput(IInputMethodClient client, int flags,
1912 ResultReceiver resultReceiver) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001913 if (!calledFromValidUser()) {
1914 return false;
1915 }
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001916 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001917 long ident = Binder.clearCallingIdentity();
1918 try {
1919 synchronized (mMethodMap) {
1920 if (mCurClient == null || client == null
1921 || mCurClient.client.asBinder() != client.asBinder()) {
1922 try {
1923 // We need to check if this is the current client with
1924 // focus in the window manager, to allow this call to
1925 // be made before input is started in it.
1926 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001927 if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid "
1928 + uid + ": " + client);
satok15452a42011-10-28 17:58:28 +09001929 setImeWindowVisibilityStatusHiddenLocked();
The Android Open Source Project4df24232009-03-05 14:34:35 -08001930 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001931 }
1932 } catch (RemoteException e) {
satok15452a42011-10-28 17:58:28 +09001933 setImeWindowVisibilityStatusHiddenLocked();
The Android Open Source Project4df24232009-03-05 14:34:35 -08001934 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001935 }
1936 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001937
Joe Onorato8a9b2202010-02-26 18:56:32 -08001938 if (DEBUG) Slog.v(TAG, "Client requesting input be hidden");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001939 return hideCurrentInputLocked(flags, resultReceiver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 }
1941 } finally {
1942 Binder.restoreCallingIdentity(ident);
1943 }
1944 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001945
The Android Open Source Project4df24232009-03-05 14:34:35 -08001946 boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0
1948 && (mShowExplicitlyRequested || mShowForced)) {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07001949 if (DEBUG) Slog.v(TAG, "Not hiding: explicit show not cancelled by non-explicit hide");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001950 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 }
1952 if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07001953 if (DEBUG) Slog.v(TAG, "Not hiding: forced show not cancelled by not-always hide");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001954 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08001956 boolean res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 if (mInputShown && mCurMethod != null) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001958 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
1959 MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver));
1960 res = true;
1961 } else {
1962 res = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001964 if (mHaveConnection && mVisibleBound) {
1965 mContext.unbindService(mVisibleConnection);
1966 mVisibleBound = false;
1967 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968 mInputShown = false;
1969 mShowRequested = false;
1970 mShowExplicitlyRequested = false;
1971 mShowForced = false;
The Android Open Source Project4df24232009-03-05 14:34:35 -08001972 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001974
satok42c5a162011-05-26 16:46:14 +09001975 @Override
Dianne Hackborn7663d802012-02-24 13:08:49 -08001976 public InputBindResult windowGainedFocus(IInputMethodClient client, IBinder windowToken,
1977 int controlFlags, int softInputMode, int windowFlags,
1978 EditorInfo attribute, IInputContext inputContext) {
Satoshi Kataoka8d033052012-11-19 17:30:40 +09001979 // Needs to check the validity before clearing calling identity
1980 final boolean calledFromValidUser = calledFromValidUser();
1981
Dianne Hackborn7663d802012-02-24 13:08:49 -08001982 InputBindResult res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001983 long ident = Binder.clearCallingIdentity();
1984 try {
1985 synchronized (mMethodMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001986 if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder()
Dianne Hackborn7663d802012-02-24 13:08:49 -08001987 + " controlFlags=#" + Integer.toHexString(controlFlags)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 + " softInputMode=#" + Integer.toHexString(softInputMode)
Dianne Hackborn7663d802012-02-24 13:08:49 -08001989 + " windowFlags=#" + Integer.toHexString(windowFlags));
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001990
Dianne Hackborn7663d802012-02-24 13:08:49 -08001991 ClientState cs = mClients.get(client.asBinder());
1992 if (cs == null) {
1993 throw new IllegalArgumentException("unknown client "
1994 + client.asBinder());
1995 }
1996
1997 try {
1998 if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
1999 // Check with the window manager to make sure this client actually
2000 // has a window with focus. If not, reject. This is thread safe
2001 // because if the focus changes some time before or after, the
2002 // next client receiving focus that has any interest in input will
2003 // be calling through here after that change happens.
2004 Slog.w(TAG, "Focus gain on non-focused client " + cs.client
2005 + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
2006 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002007 }
Dianne Hackborn7663d802012-02-24 13:08:49 -08002008 } catch (RemoteException e) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002010
Satoshi Kataoka8d033052012-11-19 17:30:40 +09002011 if (!calledFromValidUser) {
2012 Slog.w(TAG, "A background user is requesting window. Hiding IME.");
2013 Slog.w(TAG, "If you want to interect with IME, you need "
2014 + "android.permission.INTERACT_ACROSS_USERS_FULL");
2015 hideCurrentInputLocked(0, null);
2016 return null;
2017 }
2018
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07002019 if (mCurFocusedWindow == windowToken) {
Dianne Hackbornac920872012-05-22 11:49:49 -07002020 Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client
Satoshi Kataoka35739502012-10-02 19:00:26 +09002021 + " attribute=" + attribute + ", token = " + windowToken);
Dianne Hackborn7663d802012-02-24 13:08:49 -08002022 if (attribute != null) {
2023 return startInputUncheckedLocked(cs, inputContext, attribute,
2024 controlFlags);
2025 }
2026 return null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07002027 }
2028 mCurFocusedWindow = windowToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002029
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002030 // Should we auto-show the IME even if the caller has not
2031 // specified what should be done with it?
2032 // We only do this automatically if the window can resize
2033 // to accommodate the IME (so what the user sees will give
2034 // them good context without input information being obscured
2035 // by the IME) or if running on a large screen where there
2036 // is more room for the target window + IME.
2037 final boolean doAutoShow =
2038 (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
2039 == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
2040 || mRes.getConfiguration().isLayoutSizeAtLeast(
2041 Configuration.SCREENLAYOUT_SIZE_LARGE);
Dianne Hackborn7663d802012-02-24 13:08:49 -08002042 final boolean isTextEditor =
2043 (controlFlags&InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0;
2044
2045 // We want to start input before showing the IME, but after closing
2046 // it. We want to do this after closing it to help the IME disappear
2047 // more quickly (not get stuck behind it initializing itself for the
2048 // new focused input, even if its window wants to hide the IME).
2049 boolean didStart = false;
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002051 switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) {
2052 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002053 if (!isTextEditor || !doAutoShow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002054 if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) {
2055 // There is no focus view, and this window will
2056 // be behind any soft input window, so hide the
2057 // soft input window if it is shown.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002058 if (DEBUG) Slog.v(TAG, "Unspecified window will hide input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08002059 hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 }
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002061 } else if (isTextEditor && doAutoShow && (softInputMode &
2062 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002063 // There is a focus view, and we are navigating forward
2064 // into the window, so show the input window for the user.
Dianne Hackborn7663d802012-02-24 13:08:49 -08002065 // We only do this automatically if the window can resize
2066 // to accommodate the IME (so what the user sees will give
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002067 // them good context without input information being obscured
2068 // by the IME) or if running on a large screen where there
2069 // is more room for the target window + IME.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002070 if (DEBUG) Slog.v(TAG, "Unspecified window will show input");
Dianne Hackborn7663d802012-02-24 13:08:49 -08002071 if (attribute != null) {
2072 res = startInputUncheckedLocked(cs, inputContext, attribute,
2073 controlFlags);
2074 didStart = true;
2075 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002076 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002077 }
2078 break;
2079 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
2080 // Do nothing.
2081 break;
2082 case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN:
2083 if ((softInputMode &
2084 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002085 if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward");
The Android Open Source Project4df24232009-03-05 14:34:35 -08002086 hideCurrentInputLocked(0, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087 }
2088 break;
2089 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08002090 if (DEBUG) Slog.v(TAG, "Window asks to hide input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08002091 hideCurrentInputLocked(0, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 break;
2093 case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
2094 if ((softInputMode &
2095 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002096 if (DEBUG) Slog.v(TAG, "Window asks to show input going forward");
Dianne Hackborn7663d802012-02-24 13:08:49 -08002097 if (attribute != null) {
2098 res = startInputUncheckedLocked(cs, inputContext, attribute,
2099 controlFlags);
2100 didStart = true;
2101 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002102 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002103 }
2104 break;
2105 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
Joe Onorato8a9b2202010-02-26 18:56:32 -08002106 if (DEBUG) Slog.v(TAG, "Window asks to always show input");
Dianne Hackborn7663d802012-02-24 13:08:49 -08002107 if (attribute != null) {
2108 res = startInputUncheckedLocked(cs, inputContext, attribute,
2109 controlFlags);
2110 didStart = true;
2111 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002112 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002113 break;
2114 }
Dianne Hackborn7663d802012-02-24 13:08:49 -08002115
2116 if (!didStart && attribute != null) {
2117 res = startInputUncheckedLocked(cs, inputContext, attribute,
2118 controlFlags);
2119 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 }
2121 } finally {
2122 Binder.restoreCallingIdentity(ident);
2123 }
Dianne Hackborn7663d802012-02-24 13:08:49 -08002124
2125 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002127
satok42c5a162011-05-26 16:46:14 +09002128 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002129 public void showInputMethodPickerFromClient(IInputMethodClient client) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002130 if (!calledFromValidUser()) {
2131 return;
2132 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 synchronized (mMethodMap) {
2134 if (mCurClient == null || client == null
2135 || mCurClient.client.asBinder() != client.asBinder()) {
satok47a44912010-10-06 16:03:58 +09002136 Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid "
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002137 + Binder.getCallingUid() + ": " + client);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 }
2139
satok440aab52010-11-25 09:43:11 +09002140 // Always call subtype picker, because subtype picker is a superset of input method
2141 // picker.
satokab751aa2010-09-14 19:17:36 +09002142 mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER);
2143 }
2144 }
2145
satok42c5a162011-05-26 16:46:14 +09002146 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 public void setInputMethod(IBinder token, String id) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002148 if (!calledFromValidUser()) {
2149 return;
2150 }
satok28203512010-11-24 11:06:49 +09002151 setInputMethodWithSubtypeId(token, id, NOT_A_SUBTYPE_ID);
2152 }
2153
satok42c5a162011-05-26 16:46:14 +09002154 @Override
satok28203512010-11-24 11:06:49 +09002155 public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002156 if (!calledFromValidUser()) {
2157 return;
2158 }
satok28203512010-11-24 11:06:49 +09002159 synchronized (mMethodMap) {
2160 if (subtype != null) {
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002161 setInputMethodWithSubtypeIdLocked(token, id,
2162 InputMethodUtils.getSubtypeIdFromHashCode(mMethodMap.get(id),
2163 subtype.hashCode()));
satok28203512010-11-24 11:06:49 +09002164 } else {
2165 setInputMethod(token, id);
2166 }
2167 }
satokab751aa2010-09-14 19:17:36 +09002168 }
2169
satok42c5a162011-05-26 16:46:14 +09002170 @Override
satokb416a712010-11-25 20:42:14 +09002171 public void showInputMethodAndSubtypeEnablerFromClient(
satok217f5482010-12-15 05:19:19 +09002172 IInputMethodClient client, String inputMethodId) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002173 if (!calledFromValidUser()) {
2174 return;
2175 }
satokb416a712010-11-25 20:42:14 +09002176 synchronized (mMethodMap) {
2177 if (mCurClient == null || client == null
2178 || mCurClient.client.asBinder() != client.asBinder()) {
2179 Slog.w(TAG, "Ignoring showInputMethodAndSubtypeEnablerFromClient of: " + client);
2180 }
satok7fee71f2010-12-17 18:54:26 +09002181 executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
2182 MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId));
satokb416a712010-11-25 20:42:14 +09002183 }
2184 }
2185
satok4fc87d62011-05-20 16:13:43 +09002186 @Override
satok735cf382010-11-11 20:40:09 +09002187 public boolean switchToLastInputMethod(IBinder token) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002188 if (!calledFromValidUser()) {
2189 return false;
2190 }
satok735cf382010-11-11 20:40:09 +09002191 synchronized (mMethodMap) {
satokc445bcd2011-01-25 18:57:24 +09002192 final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
satok4fc87d62011-05-20 16:13:43 +09002193 final InputMethodInfo lastImi;
satok208d5632011-05-20 22:13:38 +09002194 if (lastIme != null) {
satok4fc87d62011-05-20 16:13:43 +09002195 lastImi = mMethodMap.get(lastIme.first);
2196 } else {
2197 lastImi = null;
satok735cf382010-11-11 20:40:09 +09002198 }
satok4fc87d62011-05-20 16:13:43 +09002199 String targetLastImiId = null;
2200 int subtypeId = NOT_A_SUBTYPE_ID;
2201 if (lastIme != null && lastImi != null) {
2202 final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId);
2203 final int lastSubtypeHash = Integer.valueOf(lastIme.second);
2204 final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID
2205 : mCurrentSubtype.hashCode();
2206 // If the last IME is the same as the current IME and the last subtype is not
2207 // defined, there is no need to switch to the last IME.
2208 if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) {
2209 targetLastImiId = lastIme.first;
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002210 subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
satok4fc87d62011-05-20 16:13:43 +09002211 }
2212 }
2213
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002214 if (TextUtils.isEmpty(targetLastImiId)
2215 && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) {
satok4fc87d62011-05-20 16:13:43 +09002216 // This is a safety net. If the currentSubtype can't be added to the history
2217 // and the framework couldn't find the last ime, we will make the last ime be
2218 // the most applicable enabled keyboard subtype of the system imes.
2219 final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
2220 if (enabled != null) {
2221 final int N = enabled.size();
2222 final String locale = mCurrentSubtype == null
2223 ? mRes.getConfiguration().locale.toString()
2224 : mCurrentSubtype.getLocale();
2225 for (int i = 0; i < N; ++i) {
2226 final InputMethodInfo imi = enabled.get(i);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002227 if (imi.getSubtypeCount() > 0 && InputMethodUtils.isSystemIme(imi)) {
satok4fc87d62011-05-20 16:13:43 +09002228 InputMethodSubtype keyboardSubtype =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002229 InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes,
2230 InputMethodUtils.getSubtypes(imi),
2231 InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true);
satok4fc87d62011-05-20 16:13:43 +09002232 if (keyboardSubtype != null) {
2233 targetLastImiId = imi.getId();
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002234 subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
satok4fc87d62011-05-20 16:13:43 +09002235 imi, keyboardSubtype.hashCode());
2236 if(keyboardSubtype.getLocale().equals(locale)) {
2237 break;
2238 }
2239 }
2240 }
2241 }
2242 }
2243 }
2244
2245 if (!TextUtils.isEmpty(targetLastImiId)) {
2246 if (DEBUG) {
2247 Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second
2248 + ", from: " + mCurMethodId + ", " + subtypeId);
2249 }
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002250 setInputMethodWithSubtypeIdLocked(token, targetLastImiId, subtypeId);
satok4fc87d62011-05-20 16:13:43 +09002251 return true;
2252 } else {
2253 return false;
2254 }
satok735cf382010-11-11 20:40:09 +09002255 }
2256 }
2257
satoke7c6998e2011-06-03 17:57:59 +09002258 @Override
satok688bd472012-02-09 20:09:17 +09002259 public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002260 if (!calledFromValidUser()) {
2261 return false;
2262 }
satok688bd472012-02-09 20:09:17 +09002263 synchronized (mMethodMap) {
Yohei Yukawaa0755742014-06-04 20:28:18 +09002264 if (!calledWithValidToken(token)) {
2265 final int uid = Binder.getCallingUid();
2266 Slog.e(TAG, "Ignoring switchToNextInputMethod due to an invalid token. uid:" + uid
2267 + " token:" + token);
2268 return false;
2269 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002270 final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
satok688bd472012-02-09 20:09:17 +09002271 onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype);
2272 if (nextSubtype == null) {
2273 return false;
2274 }
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002275 setInputMethodWithSubtypeIdLocked(token, nextSubtype.mImi.getId(),
2276 nextSubtype.mSubtypeId);
satok688bd472012-02-09 20:09:17 +09002277 return true;
2278 }
2279 }
2280
2281 @Override
Satoshi Kataoka2b10b522013-08-21 20:39:12 +09002282 public boolean shouldOfferSwitchingToNextInputMethod(IBinder token) {
2283 if (!calledFromValidUser()) {
2284 return false;
2285 }
2286 synchronized (mMethodMap) {
Yohei Yukawaa0755742014-06-04 20:28:18 +09002287 if (!calledWithValidToken(token)) {
2288 final int uid = Binder.getCallingUid();
2289 Slog.e(TAG, "Ignoring shouldOfferSwitchingToNextInputMethod due to an invalid "
2290 + "token. uid:" + uid + " token:" + token);
2291 return false;
2292 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002293 final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
Satoshi Kataoka2b10b522013-08-21 20:39:12 +09002294 false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype);
2295 if (nextSubtype == null) {
2296 return false;
2297 }
2298 return true;
2299 }
2300 }
2301
2302 @Override
satok68f1b782011-04-11 14:26:04 +09002303 public InputMethodSubtype getLastInputMethodSubtype() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002304 if (!calledFromValidUser()) {
2305 return null;
2306 }
satok68f1b782011-04-11 14:26:04 +09002307 synchronized (mMethodMap) {
2308 final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
2309 // TODO: Handle the case of the last IME with no subtypes
2310 if (lastIme == null || TextUtils.isEmpty(lastIme.first)
2311 || TextUtils.isEmpty(lastIme.second)) return null;
2312 final InputMethodInfo lastImi = mMethodMap.get(lastIme.first);
2313 if (lastImi == null) return null;
2314 try {
2315 final int lastSubtypeHash = Integer.valueOf(lastIme.second);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002316 final int lastSubtypeId =
2317 InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
satok0e7d7d62011-07-05 13:28:06 +09002318 if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) {
2319 return null;
2320 }
2321 return lastImi.getSubtypeAt(lastSubtypeId);
satok68f1b782011-04-11 14:26:04 +09002322 } catch (NumberFormatException e) {
2323 return null;
2324 }
2325 }
2326 }
2327
satoke7c6998e2011-06-03 17:57:59 +09002328 @Override
satokee5e77c2011-09-02 18:50:15 +09002329 public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002330 if (!calledFromValidUser()) {
2331 return;
2332 }
satok91e88122011-07-18 11:11:42 +09002333 // By this IPC call, only a process which shares the same uid with the IME can add
2334 // additional input method subtypes to the IME.
satokee5e77c2011-09-02 18:50:15 +09002335 if (TextUtils.isEmpty(imiId) || subtypes == null || subtypes.length == 0) return;
satoke7c6998e2011-06-03 17:57:59 +09002336 synchronized (mMethodMap) {
satok91e88122011-07-18 11:11:42 +09002337 final InputMethodInfo imi = mMethodMap.get(imiId);
satokee5e77c2011-09-02 18:50:15 +09002338 if (imi == null) return;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002339 final String[] packageInfos;
2340 try {
2341 packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid());
2342 } catch (RemoteException e) {
2343 Slog.e(TAG, "Failed to get package infos");
2344 return;
2345 }
satok91e88122011-07-18 11:11:42 +09002346 if (packageInfos != null) {
2347 final int packageNum = packageInfos.length;
2348 for (int i = 0; i < packageNum; ++i) {
2349 if (packageInfos[i].equals(imi.getPackageName())) {
2350 mFileManager.addInputMethodSubtypes(imi, subtypes);
satokc5933802011-08-31 21:26:04 +09002351 final long ident = Binder.clearCallingIdentity();
2352 try {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09002353 buildInputMethodListLocked(mMethodList, mMethodMap,
2354 false /* resetDefaultEnabledIme */);
satokc5933802011-08-31 21:26:04 +09002355 } finally {
2356 Binder.restoreCallingIdentity(ident);
2357 }
satokee5e77c2011-09-02 18:50:15 +09002358 return;
satok91e88122011-07-18 11:11:42 +09002359 }
2360 }
2361 }
satoke7c6998e2011-06-03 17:57:59 +09002362 }
satokee5e77c2011-09-02 18:50:15 +09002363 return;
satoke7c6998e2011-06-03 17:57:59 +09002364 }
2365
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09002366 @Override
2367 public int getInputMethodWindowVisibleHeight() {
2368 return mWindowManagerService.getInputMethodWindowVisibleHeight();
2369 }
2370
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002371 @Override
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002372 public void notifyUserAction(int sequenceNumber) {
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002373 if (DEBUG) {
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002374 Slog.d(TAG, "Got the notification of a user action. sequenceNumber:" + sequenceNumber);
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002375 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002376 synchronized (mMethodMap) {
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002377 if (mCurUserActionNotificationSequenceNumber != sequenceNumber) {
2378 if (DEBUG) {
2379 Slog.d(TAG, "Ignoring the user action notification due to the sequence number "
2380 + "mismatch. expected:" + mCurUserActionNotificationSequenceNumber
2381 + " actual: " + sequenceNumber);
2382 }
2383 return;
2384 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002385 final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
2386 if (imi != null) {
Yohei Yukawa02970512014-06-05 16:16:18 +09002387 mSwitchingController.onUserActionLocked(imi, mCurrentSubtype);
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002388 }
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002389 }
2390 }
2391
satok28203512010-11-24 11:06:49 +09002392 private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 synchronized (mMethodMap) {
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002394 setInputMethodWithSubtypeIdLocked(token, id, subtypeId);
2395 }
2396 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002398 private void setInputMethodWithSubtypeIdLocked(IBinder token, String id, int subtypeId) {
2399 if (token == null) {
2400 if (mContext.checkCallingOrSelfPermission(
2401 android.Manifest.permission.WRITE_SECURE_SETTINGS)
2402 != PackageManager.PERMISSION_GRANTED) {
2403 throw new SecurityException(
2404 "Using null token requires permission "
2405 + android.Manifest.permission.WRITE_SECURE_SETTINGS);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 }
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002407 } else if (mCurToken != token) {
2408 Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid()
2409 + " token: " + token);
2410 return;
2411 }
2412
2413 final long ident = Binder.clearCallingIdentity();
2414 try {
2415 setInputMethodLocked(id, subtypeId);
2416 } finally {
2417 Binder.restoreCallingIdentity(ident);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 }
2419 }
2420
satok42c5a162011-05-26 16:46:14 +09002421 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 public void hideMySoftInput(IBinder token, int flags) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002423 if (!calledFromValidUser()) {
2424 return;
2425 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002426 synchronized (mMethodMap) {
Yohei Yukawa22c97be2014-06-04 19:43:36 +09002427 if (!calledWithValidToken(token)) {
2428 final int uid = Binder.getCallingUid();
2429 Slog.e(TAG, "Ignoring hideInputMethod due to an invalid token. uid:"
2430 + uid + " token:" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002431 return;
2432 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 long ident = Binder.clearCallingIdentity();
2434 try {
The Android Open Source Project4df24232009-03-05 14:34:35 -08002435 hideCurrentInputLocked(flags, null);
2436 } finally {
2437 Binder.restoreCallingIdentity(ident);
2438 }
2439 }
2440 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002441
satok42c5a162011-05-26 16:46:14 +09002442 @Override
The Android Open Source Project4df24232009-03-05 14:34:35 -08002443 public void showMySoftInput(IBinder token, int flags) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002444 if (!calledFromValidUser()) {
2445 return;
2446 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002447 synchronized (mMethodMap) {
Yohei Yukawa22c97be2014-06-04 19:43:36 +09002448 if (!calledWithValidToken(token)) {
2449 final int uid = Binder.getCallingUid();
2450 Slog.e(TAG, "Ignoring showMySoftInput due to an invalid token. uid:"
2451 + uid + " token:" + token);
The Android Open Source Project4df24232009-03-05 14:34:35 -08002452 return;
2453 }
2454 long ident = Binder.clearCallingIdentity();
2455 try {
2456 showCurrentInputLocked(flags, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 } finally {
2458 Binder.restoreCallingIdentity(ident);
2459 }
2460 }
2461 }
2462
2463 void setEnabledSessionInMainThread(SessionState session) {
2464 if (mEnabledSession != session) {
Yohei Yukawa9d91b432014-05-19 16:03:24 +09002465 if (mEnabledSession != null && mEnabledSession.session != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002466 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002467 if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession);
Yohei Yukawa9d91b432014-05-19 16:03:24 +09002468 mEnabledSession.method.setSessionEnabled(mEnabledSession.session, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 } catch (RemoteException e) {
2470 }
2471 }
2472 mEnabledSession = session;
Yohei Yukawa9d91b432014-05-19 16:03:24 +09002473 if (mEnabledSession != null && mEnabledSession.session != null) {
2474 try {
2475 if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession);
2476 mEnabledSession.method.setSessionEnabled(mEnabledSession.session, true);
2477 } catch (RemoteException e) {
2478 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 }
2480 }
2481 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002482
satok42c5a162011-05-26 16:46:14 +09002483 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 public boolean handleMessage(Message msg) {
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002485 SomeArgs args;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002486 switch (msg.what) {
2487 case MSG_SHOW_IM_PICKER:
2488 showInputMethodMenu();
2489 return true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002490
satokab751aa2010-09-14 19:17:36 +09002491 case MSG_SHOW_IM_SUBTYPE_PICKER:
2492 showInputMethodSubtypeMenu();
2493 return true;
2494
satok47a44912010-10-06 16:03:58 +09002495 case MSG_SHOW_IM_SUBTYPE_ENABLER:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002496 args = (SomeArgs)msg.obj;
satok7fee71f2010-12-17 18:54:26 +09002497 showInputMethodAndSubtypeEnabler((String)args.arg1);
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002498 args.recycle();
satok217f5482010-12-15 05:19:19 +09002499 return true;
2500
2501 case MSG_SHOW_IM_CONFIG:
2502 showConfigureInputMethods();
satok47a44912010-10-06 16:03:58 +09002503 return true;
2504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 case MSG_UNBIND_INPUT:
2508 try {
2509 ((IInputMethod)msg.obj).unbindInput();
2510 } catch (RemoteException e) {
2511 // There is nothing interesting about the method dying.
2512 }
2513 return true;
2514 case MSG_BIND_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002515 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 try {
2517 ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2);
2518 } catch (RemoteException e) {
2519 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002520 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 return true;
2522 case MSG_SHOW_SOFT_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002523 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 try {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002525 if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput("
Craig Mautner6efb4c72013-03-13 10:17:41 -07002526 + msg.arg1 + ", " + args.arg2 + ")");
Craig Mautnerca0ac712013-03-14 09:43:02 -07002527 ((IInputMethod)args.arg1).showSoftInput(msg.arg1, (ResultReceiver)args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528 } catch (RemoteException e) {
2529 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002530 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 return true;
2532 case MSG_HIDE_SOFT_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002533 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 try {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002535 if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, "
Craig Mautner6efb4c72013-03-13 10:17:41 -07002536 + args.arg2 + ")");
Craig Mautnerca0ac712013-03-14 09:43:02 -07002537 ((IInputMethod)args.arg1).hideSoftInput(0, (ResultReceiver)args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002538 } catch (RemoteException e) {
2539 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002540 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 return true;
2542 case MSG_ATTACH_TOKEN:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002543 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 try {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002545 if (DEBUG) Slog.v(TAG, "Sending attach of token: " + args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002546 ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2);
2547 } catch (RemoteException e) {
2548 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002549 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 return true;
Jeff Brownc28867a2013-03-26 15:42:39 -07002551 case MSG_CREATE_SESSION: {
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002552 args = (SomeArgs)msg.obj;
Jeff Brown1951ce82013-04-04 22:45:12 -07002553 IInputMethod method = (IInputMethod)args.arg1;
Jeff Brownc28867a2013-03-26 15:42:39 -07002554 InputChannel channel = (InputChannel)args.arg2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 try {
Jeff Brown1951ce82013-04-04 22:45:12 -07002556 method.createSession(channel, (IInputSessionCallback)args.arg3);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 } catch (RemoteException e) {
Jeff Brownc28867a2013-03-26 15:42:39 -07002558 } finally {
Jeff Brown1951ce82013-04-04 22:45:12 -07002559 // Dispose the channel if the input method is not local to this process
2560 // because the remote proxy will get its own copy when unparceled.
2561 if (channel != null && Binder.isProxy(method)) {
Jeff Brownc28867a2013-03-26 15:42:39 -07002562 channel.dispose();
2563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002565 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 return true;
Jeff Brownc28867a2013-03-26 15:42:39 -07002567 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002569
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570 case MSG_START_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002571 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 try {
2573 SessionState session = (SessionState)args.arg1;
2574 setEnabledSessionInMainThread(session);
2575 session.method.startInput((IInputContext)args.arg2,
2576 (EditorInfo)args.arg3);
2577 } catch (RemoteException e) {
2578 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002579 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 return true;
2581 case MSG_RESTART_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002582 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002583 try {
2584 SessionState session = (SessionState)args.arg1;
2585 setEnabledSessionInMainThread(session);
2586 session.method.restartInput((IInputContext)args.arg2,
2587 (EditorInfo)args.arg3);
2588 } catch (RemoteException e) {
2589 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002590 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 return true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002594
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002595 case MSG_UNBIND_METHOD:
2596 try {
2597 ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1);
2598 } catch (RemoteException e) {
2599 // There is nothing interesting about the last client dying.
2600 }
2601 return true;
Jeff Brown1951ce82013-04-04 22:45:12 -07002602 case MSG_BIND_METHOD: {
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002603 args = (SomeArgs)msg.obj;
Jeff Brown1951ce82013-04-04 22:45:12 -07002604 IInputMethodClient client = (IInputMethodClient)args.arg1;
2605 InputBindResult res = (InputBindResult)args.arg2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002606 try {
Jeff Brown1951ce82013-04-04 22:45:12 -07002607 client.onBindMethod(res);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002608 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002609 Slog.w(TAG, "Client died receiving input method " + args.arg2);
Jeff Brown1951ce82013-04-04 22:45:12 -07002610 } finally {
2611 // Dispose the channel if the input method is not local to this process
2612 // because the remote proxy will get its own copy when unparceled.
2613 if (res.channel != null && Binder.isProxy(client)) {
2614 res.channel.dispose();
2615 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002616 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002617 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 return true;
Jeff Brown1951ce82013-04-04 22:45:12 -07002619 }
Dianne Hackborna6e41342012-05-22 16:30:34 -07002620 case MSG_SET_ACTIVE:
2621 try {
2622 ((ClientState)msg.obj).client.setActive(msg.arg1 != 0);
2623 } catch (RemoteException e) {
2624 Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid "
2625 + ((ClientState)msg.obj).pid + " uid "
2626 + ((ClientState)msg.obj).uid);
2627 }
2628 return true;
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002629 case MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER: {
2630 final int sequenceNumber = msg.arg1;
Yohei Yukawa080fa342014-08-31 16:10:05 -07002631 final ClientState clientState = (ClientState)msg.obj;
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002632 try {
Yohei Yukawa080fa342014-08-31 16:10:05 -07002633 clientState.client.setUserActionNotificationSequenceNumber(sequenceNumber);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002634 } catch (RemoteException e) {
2635 Slog.w(TAG, "Got RemoteException sending "
2636 + "setUserActionNotificationSequenceNumber("
2637 + sequenceNumber + ") notification to pid "
Yohei Yukawa080fa342014-08-31 16:10:05 -07002638 + clientState.pid + " uid "
2639 + clientState.uid);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002640 }
2641 return true;
2642 }
satok01038492012-04-09 21:08:27 +09002643
2644 // --------------------------------------------------------------
2645 case MSG_HARD_KEYBOARD_SWITCH_CHANGED:
Michael Wright7b5a96b2014-08-09 19:28:42 -07002646 mHardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1);
satok01038492012-04-09 21:08:27 +09002647 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 }
2649 return false;
2650 }
2651
satokdc9ddae2011-10-06 12:22:36 +09002652 private boolean chooseNewDefaultIMELocked() {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002653 final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME(
2654 mSettings.getEnabledInputMethodListLocked());
satokdc9ddae2011-10-06 12:22:36 +09002655 if (imi != null) {
satok03eb319a2010-11-11 18:17:42 +09002656 if (DEBUG) {
2657 Slog.d(TAG, "New default IME was selected: " + imi.getId());
2658 }
satok723a27e2010-11-11 14:58:11 +09002659 resetSelectedInputMethodAndSubtypeLocked(imi.getId());
Brandon Ballinger6da35a02009-10-21 00:38:13 -07002660 return true;
2661 }
2662
2663 return false;
2664 }
2665
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 void buildInputMethodListLocked(ArrayList<InputMethodInfo> list,
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09002667 HashMap<String, InputMethodInfo> map, boolean resetDefaultEnabledIme) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002668 if (DEBUG) {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09002669 Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme
Satoshi Kataoka0766eb02013-07-31 18:30:13 +09002670 + " \n ------ \n" + InputMethodUtils.getStackTrace());
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002671 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002672 list.clear();
2673 map.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002674
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002675 // Use for queryIntentServicesAsUser
2676 final PackageManager pm = mContext.getPackageManager();
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002677 String disabledSysImes = mSettings.getDisabledSystemInputMethods();
Amith Yamasanie861ec12010-03-24 21:39:27 -07002678 if (disabledSysImes == null) disabledSysImes = "";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002679
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002680 final List<ResolveInfo> services = pm.queryIntentServicesAsUser(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002681 new Intent(InputMethod.SERVICE_INTERFACE),
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08002682 PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
2683 mSettings.getCurrentUserId());
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002684
satoke7c6998e2011-06-03 17:57:59 +09002685 final HashMap<String, List<InputMethodSubtype>> additionalSubtypes =
2686 mFileManager.getAllAdditionalInputMethodSubtypes();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687 for (int i = 0; i < services.size(); ++i) {
2688 ResolveInfo ri = services.get(i);
2689 ServiceInfo si = ri.serviceInfo;
2690 ComponentName compName = new ComponentName(si.packageName, si.name);
2691 if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(
2692 si.permission)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002693 Slog.w(TAG, "Skipping input method " + compName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002694 + ": it does not require the permission "
2695 + android.Manifest.permission.BIND_INPUT_METHOD);
2696 continue;
2697 }
2698
Joe Onorato8a9b2202010-02-26 18:56:32 -08002699 if (DEBUG) Slog.d(TAG, "Checking " + compName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700
2701 try {
satoke7c6998e2011-06-03 17:57:59 +09002702 InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002703 list.add(p);
Amith Yamasanie861ec12010-03-24 21:39:27 -07002704 final String id = p.getId();
2705 map.put(id, p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002706
2707 if (DEBUG) {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09002708 Slog.d(TAG, "Found an input method " + p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 } catch (XmlPullParserException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002712 Slog.w(TAG, "Unable to load input method " + compName, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002714 Slog.w(TAG, "Unable to load input method " + compName, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002715 }
2716 }
Brandon Ballinger6da35a02009-10-21 00:38:13 -07002717
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09002718 if (resetDefaultEnabledIme) {
2719 final ArrayList<InputMethodInfo> defaultEnabledIme =
2720 InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, list);
2721 for (int i = 0; i < defaultEnabledIme.size(); ++i) {
2722 final InputMethodInfo imi = defaultEnabledIme.get(i);
2723 if (DEBUG) {
2724 Slog.d(TAG, "--- enable ime = " + imi);
2725 }
2726 setInputMethodEnabledLocked(imi.getId(), true);
2727 }
2728 }
2729
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002730 final String defaultImiId = mSettings.getSelectedInputMethod();
satok0a1bcf42012-05-16 19:26:31 +09002731 if (!TextUtils.isEmpty(defaultImiId)) {
2732 if (!map.containsKey(defaultImiId)) {
2733 Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
2734 if (chooseNewDefaultIMELocked()) {
Michael Wright7b5a96b2014-08-09 19:28:42 -07002735 updateInputMethodsFromSettingsLocked(true);
satok0a1bcf42012-05-16 19:26:31 +09002736 }
2737 } else {
2738 // Double check that the default IME is certainly enabled.
2739 setInputMethodEnabledLocked(defaultImiId, true);
Brandon Ballinger6da35a02009-10-21 00:38:13 -07002740 }
2741 }
Yohei Yukawa3d46bab2014-05-30 18:10:18 +09002742 // Here is not the perfect place to reset the switching controller. Ideally
2743 // mSwitchingController and mSettings should be able to share the same state.
2744 // TODO: Make sure that mSwitchingController and mSettings are sharing the
2745 // the same enabled IMEs list.
Yohei Yukawac834a252014-05-21 22:42:32 +09002746 mSwitchingController.resetCircularListLocked(mContext);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002749 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002750
satokab751aa2010-09-14 19:17:36 +09002751 private void showInputMethodMenu() {
2752 showInputMethodMenuInternal(false);
2753 }
2754
2755 private void showInputMethodSubtypeMenu() {
2756 showInputMethodMenuInternal(true);
2757 }
2758
satok217f5482010-12-15 05:19:19 +09002759 private void showInputMethodAndSubtypeEnabler(String inputMethodId) {
Tadashi G. Takaokaf49688f2011-01-20 17:56:13 +09002760 Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
satok47a44912010-10-06 16:03:58 +09002761 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
satok86417ea2010-10-27 14:11:03 +09002762 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
2763 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
satok7fee71f2010-12-17 18:54:26 +09002764 if (!TextUtils.isEmpty(inputMethodId)) {
Tadashi G. Takaoka25480202011-01-20 23:13:02 +09002765 intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId);
satok7fee71f2010-12-17 18:54:26 +09002766 }
Satoshi Kataoka3ba439d2012-10-05 18:30:13 +09002767 mContext.startActivityAsUser(intent, null, UserHandle.CURRENT);
satok217f5482010-12-15 05:19:19 +09002768 }
2769
2770 private void showConfigureInputMethods() {
2771 Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
2772 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2773 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
2774 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Satoshi Kataoka3ba439d2012-10-05 18:30:13 +09002775 mContext.startActivityAsUser(intent, null, UserHandle.CURRENT);
satok47a44912010-10-06 16:03:58 +09002776 }
2777
satok2c93efc2012-04-02 19:33:47 +09002778 private boolean isScreenLocked() {
2779 return mKeyguardManager != null
2780 && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure();
2781 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002782
satokab751aa2010-09-14 19:17:36 +09002783 private void showInputMethodMenuInternal(boolean showSubtypes) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002784 if (DEBUG) Slog.v(TAG, "Show switching menu");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 final Context context = mContext;
satok2c93efc2012-04-02 19:33:47 +09002787 final boolean isScreenLocked = isScreenLocked();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002788
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002789 final String lastInputMethodId = mSettings.getSelectedInputMethod();
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002790 int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002791 if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002792
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002793 synchronized (mMethodMap) {
satokbb4aa062011-01-19 21:40:27 +09002794 final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis =
Satoshi Kataokad787f692013-10-26 04:44:21 +09002795 mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(
2796 mContext);
satok7f35c8c2010-10-07 21:13:11 +09002797 if (immis == null || immis.size() == 0) {
2798 return;
2799 }
2800
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002801 hideInputMethodMenuLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802
satok688bd472012-02-09 20:09:17 +09002803 final List<ImeSubtypeListItem> imList =
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002804 mSwitchingController.getSortedInputMethodAndSubtypeListLocked(
satok688bd472012-02-09 20:09:17 +09002805 showSubtypes, mInputShown, isScreenLocked);
satok913a8922010-08-26 21:53:41 +09002806
satokc3690562012-01-10 20:14:43 +09002807 if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002808 final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
satokc3690562012-01-10 20:14:43 +09002809 if (currentSubtype != null) {
2810 final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002811 lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
2812 currentImi, currentSubtype.hashCode());
satokc3690562012-01-10 20:14:43 +09002813 }
2814 }
2815
Ken Wakasa761eb372011-03-04 19:06:18 +09002816 final int N = imList.size();
satokab751aa2010-09-14 19:17:36 +09002817 mIms = new InputMethodInfo[N];
2818 mSubtypeIds = new int[N];
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002819 int checkedItem = 0;
2820 for (int i = 0; i < N; ++i) {
Ken Wakasa05dbb652011-08-22 15:22:43 +09002821 final ImeSubtypeListItem item = imList.get(i);
2822 mIms[i] = item.mImi;
2823 mSubtypeIds[i] = item.mSubtypeId;
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002824 if (mIms[i].getId().equals(lastInputMethodId)) {
satokab751aa2010-09-14 19:17:36 +09002825 int subtypeId = mSubtypeIds[i];
2826 if ((subtypeId == NOT_A_SUBTYPE_ID)
2827 || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0)
2828 || (subtypeId == lastInputMethodSubtypeId)) {
2829 checkedItem = i;
2830 }
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002831 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002833 final Context themedContext = new ContextThemeWrapper(context,
2834 android.R.style.Theme_DeviceDefault_Settings);
2835 mDialogBuilder = new AlertDialog.Builder(themedContext);
2836 final TypedArray a = themedContext.obtainStyledAttributes(null,
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002837 com.android.internal.R.styleable.DialogPreference,
2838 com.android.internal.R.attr.alertDialogStyle, 0);
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002839 mDialogBuilder.setIcon(a.getDrawable(
2840 com.android.internal.R.styleable.DialogPreference_dialogIcon));
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002841 a.recycle();
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002842 mDialogBuilder.setOnCancelListener(new OnCancelListener() {
2843 @Override
2844 public void onCancel(DialogInterface dialog) {
2845 hideInputMethodMenu();
2846 }
2847 });
satok01038492012-04-09 21:08:27 +09002848 final LayoutInflater inflater =
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002849 (LayoutInflater)themedContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
satok01038492012-04-09 21:08:27 +09002850 final View tv = inflater.inflate(
2851 com.android.internal.R.layout.input_method_switch_dialog_title, null);
2852 mDialogBuilder.setCustomTitle(tv);
2853
2854 // Setup layout for a toggle switch of the hardware keyboard
2855 mSwitchingDialogTitleView = tv;
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002856 mSwitchingDialogTitleView
2857 .findViewById(com.android.internal.R.id.hard_keyboard_section)
2858 .setVisibility(mWindowManagerService.isHardKeyboardAvailable()
2859 ? View.VISIBLE : View.GONE);
2860 final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById(
2861 com.android.internal.R.id.hard_keyboard_switch);
Michael Wright7b5a96b2014-08-09 19:28:42 -07002862 hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002863 hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
2864 @Override
2865 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Michael Wright7b5a96b2014-08-09 19:28:42 -07002866 mSettings.setShowImeWithHardKeyboard(isChecked);
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002867 // Ensure that the input method dialog is dismissed when changing
2868 // the hardware keyboard state.
2869 hideInputMethodMenu();
2870 }
2871 });
2872
2873 final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(themedContext,
2874 com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
2875 final OnClickListener choiceListener = new OnClickListener() {
2876 @Override
2877 public void onClick(final DialogInterface dialog, final int which) {
2878 synchronized (mMethodMap) {
2879 if (mIms == null || mIms.length <= which || mSubtypeIds == null
2880 || mSubtypeIds.length <= which) {
2881 return;
satok01038492012-04-09 21:08:27 +09002882 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002883 final InputMethodInfo im = mIms[which];
2884 int subtypeId = mSubtypeIds[which];
2885 adapter.mCheckedItem = which;
2886 adapter.notifyDataSetChanged();
2887 hideInputMethodMenu();
2888 if (im != null) {
2889 if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) {
2890 subtypeId = NOT_A_SUBTYPE_ID;
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08002891 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002892 setInputMethodLocked(im.getId(), subtypeId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002893 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002894 }
2895 }
2896 };
2897 mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002898
satokbc81b692011-08-26 16:22:22 +09002899 if (showSubtypes && !isScreenLocked) {
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002900 final OnClickListener positiveListener = new OnClickListener() {
2901 @Override
2902 public void onClick(DialogInterface dialog, int whichButton) {
2903 showConfigureInputMethods();
2904 }
2905 };
satok82beadf2010-12-27 19:03:06 +09002906 mDialogBuilder.setPositiveButton(
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002907 com.android.internal.R.string.configure_input_methods, positiveListener);
satok7f35c8c2010-10-07 21:13:11 +09002908 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 mSwitchingDialog = mDialogBuilder.create();
Dianne Hackborne3a7f622011-03-03 21:48:24 -08002910 mSwitchingDialog.setCanceledOnTouchOutside(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 mSwitchingDialog.getWindow().setType(
2912 WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
Satoshi Kataokac86884c2012-10-09 15:20:29 +09002913 mSwitchingDialog.getWindow().getAttributes().privateFlags |=
2914 WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborne3a7f622011-03-03 21:48:24 -08002915 mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
Jason Monk807ef762014-05-08 15:47:46 -04002916 updateImeWindowStatusLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 mSwitchingDialog.show();
2918 }
2919 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002920
Ken Wakasa05dbb652011-08-22 15:22:43 +09002921 private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> {
2922 private final LayoutInflater mInflater;
2923 private final int mTextViewResourceId;
2924 private final List<ImeSubtypeListItem> mItemsList;
Satoshi Kataokad2142962012-11-12 18:43:06 +09002925 public int mCheckedItem;
Ken Wakasa05dbb652011-08-22 15:22:43 +09002926 public ImeSubtypeListAdapter(Context context, int textViewResourceId,
2927 List<ImeSubtypeListItem> itemsList, int checkedItem) {
2928 super(context, textViewResourceId, itemsList);
2929 mTextViewResourceId = textViewResourceId;
2930 mItemsList = itemsList;
2931 mCheckedItem = checkedItem;
2932 mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
2933 }
2934
2935 @Override
2936 public View getView(int position, View convertView, ViewGroup parent) {
2937 final View view = convertView != null ? convertView
2938 : mInflater.inflate(mTextViewResourceId, null);
2939 if (position < 0 || position >= mItemsList.size()) return view;
2940 final ImeSubtypeListItem item = mItemsList.get(position);
2941 final CharSequence imeName = item.mImeName;
2942 final CharSequence subtypeName = item.mSubtypeName;
2943 final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1);
2944 final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2);
2945 if (TextUtils.isEmpty(subtypeName)) {
2946 firstTextView.setText(imeName);
2947 secondTextView.setVisibility(View.GONE);
2948 } else {
2949 firstTextView.setText(subtypeName);
2950 secondTextView.setText(imeName);
2951 secondTextView.setVisibility(View.VISIBLE);
2952 }
2953 final RadioButton radioButton =
2954 (RadioButton)view.findViewById(com.android.internal.R.id.radio);
2955 radioButton.setChecked(position == mCheckedItem);
2956 return view;
2957 }
2958 }
2959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 void hideInputMethodMenu() {
The Android Open Source Project10592532009-03-18 17:39:46 -07002961 synchronized (mMethodMap) {
2962 hideInputMethodMenuLocked();
2963 }
2964 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002965
The Android Open Source Project10592532009-03-18 17:39:46 -07002966 void hideInputMethodMenuLocked() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002967 if (DEBUG) Slog.v(TAG, "Hide switching menu");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968
The Android Open Source Project10592532009-03-18 17:39:46 -07002969 if (mSwitchingDialog != null) {
2970 mSwitchingDialog.dismiss();
2971 mSwitchingDialog = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002972 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002973
Jason Monk807ef762014-05-08 15:47:46 -04002974 updateImeWindowStatusLocked();
The Android Open Source Project10592532009-03-18 17:39:46 -07002975 mDialogBuilder = null;
The Android Open Source Project10592532009-03-18 17:39:46 -07002976 mIms = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002980
satok42c5a162011-05-26 16:46:14 +09002981 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 public boolean setInputMethodEnabled(String id, boolean enabled) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002983 // TODO: Make this work even for non-current users?
2984 if (!calledFromValidUser()) {
2985 return false;
2986 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 synchronized (mMethodMap) {
2988 if (mContext.checkCallingOrSelfPermission(
2989 android.Manifest.permission.WRITE_SECURE_SETTINGS)
2990 != PackageManager.PERMISSION_GRANTED) {
2991 throw new SecurityException(
2992 "Requires permission "
2993 + android.Manifest.permission.WRITE_SECURE_SETTINGS);
2994 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002996 long ident = Binder.clearCallingIdentity();
2997 try {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002998 return setInputMethodEnabledLocked(id, enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 } finally {
3000 Binder.restoreCallingIdentity(ident);
3001 }
3002 }
3003 }
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003004
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003005 boolean setInputMethodEnabledLocked(String id, boolean enabled) {
3006 // Make sure this is a valid input method.
3007 InputMethodInfo imm = mMethodMap.get(id);
3008 if (imm == null) {
satokd87c2592010-09-29 11:52:06 +09003009 throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003010 }
3011
satokd87c2592010-09-29 11:52:06 +09003012 List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings
3013 .getEnabledInputMethodsAndSubtypeListLocked();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003014
satokd87c2592010-09-29 11:52:06 +09003015 if (enabled) {
3016 for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) {
3017 if (pair.first.equals(id)) {
3018 // We are enabling this input method, but it is already enabled.
3019 // Nothing to do. The previous state was enabled.
3020 return true;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003021 }
3022 }
satokd87c2592010-09-29 11:52:06 +09003023 mSettings.appendAndPutEnabledInputMethodLocked(id, false);
3024 // Previous state was disabled.
3025 return false;
3026 } else {
3027 StringBuilder builder = new StringBuilder();
3028 if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked(
3029 builder, enabledInputMethodsList, id)) {
3030 // Disabled input method is currently selected, switch to another one.
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003031 final String selId = mSettings.getSelectedInputMethod();
satok03eb319a2010-11-11 18:17:42 +09003032 if (id.equals(selId) && !chooseNewDefaultIMELocked()) {
3033 Slog.i(TAG, "Can't find new IME, unsetting the current input method.");
3034 resetSelectedInputMethodAndSubtypeLocked("");
satokd87c2592010-09-29 11:52:06 +09003035 }
3036 // Previous state was enabled.
3037 return true;
3038 } else {
3039 // We are disabling the input method but it is already disabled.
3040 // Nothing to do. The previous state was disabled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003041 return false;
3042 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003043 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003044 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08003045
satok723a27e2010-11-11 14:58:11 +09003046 private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId,
3047 boolean setSubtypeOnly) {
3048 // Update the history of InputMethod and Subtype
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003049 mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype);
satok723a27e2010-11-11 14:58:11 +09003050
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09003051 mCurUserActionNotificationSequenceNumber =
3052 Math.max(mCurUserActionNotificationSequenceNumber + 1, 1);
3053 if (DEBUG) {
3054 Slog.d(TAG, "Bump mCurUserActionNotificationSequenceNumber:"
3055 + mCurUserActionNotificationSequenceNumber);
3056 }
3057
3058 if (mCurClient != null && mCurClient.client != null) {
3059 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
3060 MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER,
Yohei Yukawa080fa342014-08-31 16:10:05 -07003061 mCurUserActionNotificationSequenceNumber, mCurClient));
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09003062 }
3063
satok723a27e2010-11-11 14:58:11 +09003064 // Set Subtype here
3065 if (imi == null || subtypeId < 0) {
3066 mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
Tadashi G. Takaoka0ba75bb2010-11-09 12:19:32 -08003067 mCurrentSubtype = null;
satok723a27e2010-11-11 14:58:11 +09003068 } else {
Ken Wakasa586f0512011-01-20 22:31:01 +09003069 if (subtypeId < imi.getSubtypeCount()) {
3070 InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId);
3071 mSettings.putSelectedSubtype(subtype.hashCode());
3072 mCurrentSubtype = subtype;
satok723a27e2010-11-11 14:58:11 +09003073 } else {
3074 mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
satokd81e9502012-05-21 12:58:45 +09003075 // If the subtype is not specified, choose the most applicable one
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003076 mCurrentSubtype = getCurrentInputMethodSubtypeLocked();
satok723a27e2010-11-11 14:58:11 +09003077 }
satokab751aa2010-09-14 19:17:36 +09003078 }
satok723a27e2010-11-11 14:58:11 +09003079
satok4c0e7152012-06-20 20:08:44 +09003080 // Workaround.
3081 // ASEC is not ready in the IMMS constructor. Accordingly, forward-locked
3082 // IMEs are not recognized and considered uninstalled.
3083 // Actually, we can't move everything after SystemReady because
3084 // IMMS needs to run in the encryption lock screen. So, we just skip changing
3085 // the default IME here and try cheking the default IME again in systemReady().
3086 // TODO: Do nothing before system ready and implement a separated logic for
3087 // the encryption lock screen.
3088 // TODO: ASEC should be ready before IMMS is instantiated.
3089 if (mSystemReady && !setSubtypeOnly) {
satok723a27e2010-11-11 14:58:11 +09003090 // Set InputMethod here
3091 mSettings.putSelectedInputMethod(imi != null ? imi.getId() : "");
3092 }
3093 }
3094
3095 private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) {
3096 InputMethodInfo imi = mMethodMap.get(newDefaultIme);
3097 int lastSubtypeId = NOT_A_SUBTYPE_ID;
3098 // newDefaultIme is empty when there is no candidate for the selected IME.
3099 if (imi != null && !TextUtils.isEmpty(newDefaultIme)) {
3100 String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme);
3101 if (subtypeHashCode != null) {
3102 try {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003103 lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
satok723a27e2010-11-11 14:58:11 +09003104 imi, Integer.valueOf(subtypeHashCode));
3105 } catch (NumberFormatException e) {
3106 Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e);
3107 }
3108 }
3109 }
3110 setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false);
satokab751aa2010-09-14 19:17:36 +09003111 }
3112
satok4e4569d2010-11-19 18:45:53 +09003113 // If there are no selected shortcuts, tries finding the most applicable ones.
3114 private Pair<InputMethodInfo, InputMethodSubtype>
3115 findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) {
3116 List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
3117 InputMethodInfo mostApplicableIMI = null;
satokcd7cd292010-11-20 15:46:23 +09003118 InputMethodSubtype mostApplicableSubtype = null;
satok4e4569d2010-11-19 18:45:53 +09003119 boolean foundInSystemIME = false;
3120
3121 // Search applicable subtype for each InputMethodInfo
3122 for (InputMethodInfo imi: imis) {
satok7599a7f2010-12-22 13:45:23 +09003123 final String imiId = imi.getId();
3124 if (foundInSystemIME && !imiId.equals(mCurMethodId)) {
3125 continue;
3126 }
satokcd7cd292010-11-20 15:46:23 +09003127 InputMethodSubtype subtype = null;
satokdf31ae62011-01-15 06:19:44 +09003128 final List<InputMethodSubtype> enabledSubtypes =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003129 mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
satokdf31ae62011-01-15 06:19:44 +09003130 // 1. Search by the current subtype's locale from enabledSubtypes.
satok4e4569d2010-11-19 18:45:53 +09003131 if (mCurrentSubtype != null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003132 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satokdf31ae62011-01-15 06:19:44 +09003133 mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false);
satok4e4569d2010-11-19 18:45:53 +09003134 }
satokdf31ae62011-01-15 06:19:44 +09003135 // 2. Search by the system locale from enabledSubtypes.
3136 // 3. Search the first enabled subtype matched with mode from enabledSubtypes.
satokcd7cd292010-11-20 15:46:23 +09003137 if (subtype == null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003138 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satokdf31ae62011-01-15 06:19:44 +09003139 mRes, enabledSubtypes, mode, null, true);
satok4e4569d2010-11-19 18:45:53 +09003140 }
satoka86f5e42011-09-02 17:12:42 +09003141 final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003142 InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode);
satoka86f5e42011-09-02 17:12:42 +09003143 final ArrayList<InputMethodSubtype> subtypesForSearch =
3144 overridingImplicitlyEnabledSubtypes.isEmpty()
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003145 ? InputMethodUtils.getSubtypes(imi)
3146 : overridingImplicitlyEnabledSubtypes;
satok7599a7f2010-12-22 13:45:23 +09003147 // 4. Search by the current subtype's locale from all subtypes.
3148 if (subtype == null && mCurrentSubtype != null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003149 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satoka86f5e42011-09-02 17:12:42 +09003150 mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false);
satok7599a7f2010-12-22 13:45:23 +09003151 }
3152 // 5. Search by the system locale from all subtypes.
3153 // 6. Search the first enabled subtype matched with mode from all subtypes.
satokcd7cd292010-11-20 15:46:23 +09003154 if (subtype == null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003155 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satoka86f5e42011-09-02 17:12:42 +09003156 mRes, subtypesForSearch, mode, null, true);
satok4e4569d2010-11-19 18:45:53 +09003157 }
satokcd7cd292010-11-20 15:46:23 +09003158 if (subtype != null) {
satok7599a7f2010-12-22 13:45:23 +09003159 if (imiId.equals(mCurMethodId)) {
satok4e4569d2010-11-19 18:45:53 +09003160 // The current input method is the most applicable IME.
3161 mostApplicableIMI = imi;
satokcd7cd292010-11-20 15:46:23 +09003162 mostApplicableSubtype = subtype;
satok4e4569d2010-11-19 18:45:53 +09003163 break;
satok7599a7f2010-12-22 13:45:23 +09003164 } else if (!foundInSystemIME) {
satok4e4569d2010-11-19 18:45:53 +09003165 // The system input method is 2nd applicable IME.
3166 mostApplicableIMI = imi;
satokcd7cd292010-11-20 15:46:23 +09003167 mostApplicableSubtype = subtype;
satok7599a7f2010-12-22 13:45:23 +09003168 if ((imi.getServiceInfo().applicationInfo.flags
3169 & ApplicationInfo.FLAG_SYSTEM) != 0) {
3170 foundInSystemIME = true;
3171 }
satok4e4569d2010-11-19 18:45:53 +09003172 }
3173 }
3174 }
3175 if (DEBUG) {
satokcd7cd292010-11-20 15:46:23 +09003176 if (mostApplicableIMI != null) {
3177 Slog.w(TAG, "Most applicable shortcut input method was:"
3178 + mostApplicableIMI.getId());
3179 if (mostApplicableSubtype != null) {
3180 Slog.w(TAG, "Most applicable shortcut input method subtype was:"
3181 + "," + mostApplicableSubtype.getMode() + ","
3182 + mostApplicableSubtype.getLocale());
3183 }
3184 }
satok4e4569d2010-11-19 18:45:53 +09003185 }
satokcd7cd292010-11-20 15:46:23 +09003186 if (mostApplicableIMI != null) {
satok4e4569d2010-11-19 18:45:53 +09003187 return new Pair<InputMethodInfo, InputMethodSubtype> (mostApplicableIMI,
satokcd7cd292010-11-20 15:46:23 +09003188 mostApplicableSubtype);
satok4e4569d2010-11-19 18:45:53 +09003189 } else {
3190 return null;
3191 }
3192 }
3193
satokab751aa2010-09-14 19:17:36 +09003194 /**
3195 * @return Return the current subtype of this input method.
3196 */
satok42c5a162011-05-26 16:46:14 +09003197 @Override
satokab751aa2010-09-14 19:17:36 +09003198 public InputMethodSubtype getCurrentInputMethodSubtype() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003199 // TODO: Make this work even for non-current users?
3200 if (!calledFromValidUser()) {
3201 return null;
3202 }
3203 synchronized (mMethodMap) {
3204 return getCurrentInputMethodSubtypeLocked();
3205 }
3206 }
3207
3208 private InputMethodSubtype getCurrentInputMethodSubtypeLocked() {
satokfdf419e2012-05-08 16:52:08 +09003209 if (mCurMethodId == null) {
3210 return null;
3211 }
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003212 final boolean subtypeIsSelected = mSettings.isSubtypeSelected();
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003213 final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
3214 if (imi == null || imi.getSubtypeCount() == 0) {
3215 return null;
satok4e4569d2010-11-19 18:45:53 +09003216 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003217 if (!subtypeIsSelected || mCurrentSubtype == null
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003218 || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) {
3219 int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003220 if (subtypeId == NOT_A_SUBTYPE_ID) {
3221 // If there are no selected subtypes, the framework will try to find
3222 // the most applicable subtype from explicitly or implicitly enabled
3223 // subtypes.
3224 List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003225 mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003226 // If there is only one explicitly or implicitly enabled subtype,
3227 // just returns it.
3228 if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) {
3229 mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0);
3230 } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003231 mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003232 mRes, explicitlyOrImplicitlyEnabledSubtypes,
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003233 InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003234 if (mCurrentSubtype == null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003235 mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003236 mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null,
3237 true);
satok4e4569d2010-11-19 18:45:53 +09003238 }
satok3ef8b292010-11-23 06:06:29 +09003239 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003240 } else {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003241 mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId);
satok8fbb1e82010-11-02 23:15:58 +09003242 }
3243 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003244 return mCurrentSubtype;
satokab751aa2010-09-14 19:17:36 +09003245 }
3246
satokf3db1af2010-11-23 13:34:33 +09003247 private void addShortcutInputMethodAndSubtypes(InputMethodInfo imi,
3248 InputMethodSubtype subtype) {
3249 if (mShortcutInputMethodsAndSubtypes.containsKey(imi)) {
3250 mShortcutInputMethodsAndSubtypes.get(imi).add(subtype);
3251 } else {
3252 ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
3253 subtypes.add(subtype);
3254 mShortcutInputMethodsAndSubtypes.put(imi, subtypes);
3255 }
3256 }
3257
satok4e4569d2010-11-19 18:45:53 +09003258 // TODO: We should change the return type from List to List<Parcelable>
satokdbf29502011-08-25 15:28:23 +09003259 @SuppressWarnings("rawtypes")
satoke7c6998e2011-06-03 17:57:59 +09003260 @Override
satok4e4569d2010-11-19 18:45:53 +09003261 public List getShortcutInputMethodsAndSubtypes() {
3262 synchronized (mMethodMap) {
satok3da92232011-01-11 22:46:30 +09003263 ArrayList<Object> ret = new ArrayList<Object>();
satokf3db1af2010-11-23 13:34:33 +09003264 if (mShortcutInputMethodsAndSubtypes.size() == 0) {
satok4e4569d2010-11-19 18:45:53 +09003265 // If there are no selected shortcut subtypes, the framework will try to find
3266 // the most applicable subtype from all subtypes whose mode is
3267 // SUBTYPE_MODE_VOICE. This is an exceptional case, so we will hardcode the mode.
satokf3db1af2010-11-23 13:34:33 +09003268 Pair<InputMethodInfo, InputMethodSubtype> info =
3269 findLastResortApplicableShortcutInputMethodAndSubtypeLocked(
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003270 InputMethodUtils.SUBTYPE_MODE_VOICE);
satok7599a7f2010-12-22 13:45:23 +09003271 if (info != null) {
satok3da92232011-01-11 22:46:30 +09003272 ret.add(info.first);
3273 ret.add(info.second);
satok7599a7f2010-12-22 13:45:23 +09003274 }
satok3da92232011-01-11 22:46:30 +09003275 return ret;
satokf3db1af2010-11-23 13:34:33 +09003276 }
satokf3db1af2010-11-23 13:34:33 +09003277 for (InputMethodInfo imi: mShortcutInputMethodsAndSubtypes.keySet()) {
3278 ret.add(imi);
3279 for (InputMethodSubtype subtype: mShortcutInputMethodsAndSubtypes.get(imi)) {
3280 ret.add(subtype);
satok4e4569d2010-11-19 18:45:53 +09003281 }
3282 }
satokf3db1af2010-11-23 13:34:33 +09003283 return ret;
satok4e4569d2010-11-19 18:45:53 +09003284 }
3285 }
3286
satok42c5a162011-05-26 16:46:14 +09003287 @Override
satokb66d2872010-11-10 01:04:04 +09003288 public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003289 // TODO: Make this work even for non-current users?
3290 if (!calledFromValidUser()) {
3291 return false;
3292 }
satokb66d2872010-11-10 01:04:04 +09003293 synchronized (mMethodMap) {
3294 if (subtype != null && mCurMethodId != null) {
3295 InputMethodInfo imi = mMethodMap.get(mCurMethodId);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003296 int subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode());
satokb66d2872010-11-10 01:04:04 +09003297 if (subtypeId != NOT_A_SUBTYPE_ID) {
3298 setInputMethodLocked(mCurMethodId, subtypeId);
3299 return true;
3300 }
3301 }
3302 return false;
3303 }
3304 }
3305
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +09003306 // TODO: Cache the state for each user and reset when the cached user is removed.
satoke7c6998e2011-06-03 17:57:59 +09003307 private static class InputMethodFileManager {
3308 private static final String SYSTEM_PATH = "system";
3309 private static final String INPUT_METHOD_PATH = "inputmethod";
3310 private static final String ADDITIONAL_SUBTYPES_FILE_NAME = "subtypes.xml";
3311 private static final String NODE_SUBTYPES = "subtypes";
3312 private static final String NODE_SUBTYPE = "subtype";
3313 private static final String NODE_IMI = "imi";
3314 private static final String ATTR_ID = "id";
3315 private static final String ATTR_LABEL = "label";
3316 private static final String ATTR_ICON = "icon";
3317 private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale";
3318 private static final String ATTR_IME_SUBTYPE_MODE = "imeSubtypeMode";
3319 private static final String ATTR_IME_SUBTYPE_EXTRA_VALUE = "imeSubtypeExtraValue";
3320 private static final String ATTR_IS_AUXILIARY = "isAuxiliary";
3321 private final AtomicFile mAdditionalInputMethodSubtypeFile;
3322 private final HashMap<String, InputMethodInfo> mMethodMap;
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003323 private final HashMap<String, List<InputMethodSubtype>> mAdditionalSubtypesMap =
satoke7c6998e2011-06-03 17:57:59 +09003324 new HashMap<String, List<InputMethodSubtype>>();
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +09003325 public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap, int userId) {
satoke7c6998e2011-06-03 17:57:59 +09003326 if (methodMap == null) {
3327 throw new NullPointerException("methodMap is null");
3328 }
3329 mMethodMap = methodMap;
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +09003330 final File systemDir = userId == UserHandle.USER_OWNER
3331 ? new File(Environment.getDataDirectory(), SYSTEM_PATH)
3332 : Environment.getUserSystemDirectory(userId);
satoke7c6998e2011-06-03 17:57:59 +09003333 final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH);
3334 if (!inputMethodDir.mkdirs()) {
3335 Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath());
3336 }
3337 final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME);
3338 mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile);
3339 if (!subtypeFile.exists()) {
3340 // If "subtypes.xml" doesn't exist, create a blank file.
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003341 writeAdditionalInputMethodSubtypes(
3342 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, methodMap);
satoke7c6998e2011-06-03 17:57:59 +09003343 } else {
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003344 readAdditionalInputMethodSubtypes(
3345 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile);
satoke7c6998e2011-06-03 17:57:59 +09003346 }
3347 }
3348
3349 private void deleteAllInputMethodSubtypes(String imiId) {
3350 synchronized (mMethodMap) {
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003351 mAdditionalSubtypesMap.remove(imiId);
3352 writeAdditionalInputMethodSubtypes(
3353 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap);
satoke7c6998e2011-06-03 17:57:59 +09003354 }
3355 }
3356
3357 public void addInputMethodSubtypes(
satok4a28bde2011-06-29 21:03:40 +09003358 InputMethodInfo imi, InputMethodSubtype[] additionalSubtypes) {
satoke7c6998e2011-06-03 17:57:59 +09003359 synchronized (mMethodMap) {
3360 final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
3361 final int N = additionalSubtypes.length;
3362 for (int i = 0; i < N; ++i) {
3363 final InputMethodSubtype subtype = additionalSubtypes[i];
satoked2b24e2011-08-31 18:03:21 +09003364 if (!subtypes.contains(subtype)) {
satoke7c6998e2011-06-03 17:57:59 +09003365 subtypes.add(subtype);
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003366 } else {
3367 Slog.w(TAG, "Duplicated subtype definition found: "
3368 + subtype.getLocale() + ", " + subtype.getMode());
satoke7c6998e2011-06-03 17:57:59 +09003369 }
3370 }
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003371 mAdditionalSubtypesMap.put(imi.getId(), subtypes);
3372 writeAdditionalInputMethodSubtypes(
3373 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap);
satoke7c6998e2011-06-03 17:57:59 +09003374 }
3375 }
3376
3377 public HashMap<String, List<InputMethodSubtype>> getAllAdditionalInputMethodSubtypes() {
3378 synchronized (mMethodMap) {
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003379 return mAdditionalSubtypesMap;
satoke7c6998e2011-06-03 17:57:59 +09003380 }
3381 }
3382
3383 private static void writeAdditionalInputMethodSubtypes(
3384 HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile,
3385 HashMap<String, InputMethodInfo> methodMap) {
3386 // Safety net for the case that this function is called before methodMap is set.
3387 final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0;
3388 FileOutputStream fos = null;
3389 try {
3390 fos = subtypesFile.startWrite();
3391 final XmlSerializer out = new FastXmlSerializer();
3392 out.setOutput(fos, "utf-8");
3393 out.startDocument(null, true);
3394 out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
3395 out.startTag(null, NODE_SUBTYPES);
3396 for (String imiId : allSubtypes.keySet()) {
3397 if (isSetMethodMap && !methodMap.containsKey(imiId)) {
3398 Slog.w(TAG, "IME uninstalled or not valid.: " + imiId);
3399 continue;
3400 }
3401 out.startTag(null, NODE_IMI);
3402 out.attribute(null, ATTR_ID, imiId);
3403 final List<InputMethodSubtype> subtypesList = allSubtypes.get(imiId);
3404 final int N = subtypesList.size();
3405 for (int i = 0; i < N; ++i) {
3406 final InputMethodSubtype subtype = subtypesList.get(i);
3407 out.startTag(null, NODE_SUBTYPE);
3408 out.attribute(null, ATTR_ICON, String.valueOf(subtype.getIconResId()));
3409 out.attribute(null, ATTR_LABEL, String.valueOf(subtype.getNameResId()));
3410 out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale());
3411 out.attribute(null, ATTR_IME_SUBTYPE_MODE, subtype.getMode());
3412 out.attribute(null, ATTR_IME_SUBTYPE_EXTRA_VALUE, subtype.getExtraValue());
3413 out.attribute(null, ATTR_IS_AUXILIARY,
3414 String.valueOf(subtype.isAuxiliary() ? 1 : 0));
3415 out.endTag(null, NODE_SUBTYPE);
3416 }
3417 out.endTag(null, NODE_IMI);
3418 }
3419 out.endTag(null, NODE_SUBTYPES);
3420 out.endDocument();
3421 subtypesFile.finishWrite(fos);
3422 } catch (java.io.IOException e) {
3423 Slog.w(TAG, "Error writing subtypes", e);
3424 if (fos != null) {
3425 subtypesFile.failWrite(fos);
3426 }
3427 }
3428 }
3429
3430 private static void readAdditionalInputMethodSubtypes(
3431 HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) {
3432 if (allSubtypes == null || subtypesFile == null) return;
3433 allSubtypes.clear();
3434 FileInputStream fis = null;
3435 try {
3436 fis = subtypesFile.openRead();
3437 final XmlPullParser parser = Xml.newPullParser();
3438 parser.setInput(fis, null);
3439 int type = parser.getEventType();
3440 // Skip parsing until START_TAG
3441 while ((type = parser.next()) != XmlPullParser.START_TAG
3442 && type != XmlPullParser.END_DOCUMENT) {}
3443 String firstNodeName = parser.getName();
3444 if (!NODE_SUBTYPES.equals(firstNodeName)) {
3445 throw new XmlPullParserException("Xml doesn't start with subtypes");
3446 }
3447 final int depth =parser.getDepth();
3448 String currentImiId = null;
3449 ArrayList<InputMethodSubtype> tempSubtypesArray = null;
3450 while (((type = parser.next()) != XmlPullParser.END_TAG
3451 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
3452 if (type != XmlPullParser.START_TAG)
3453 continue;
3454 final String nodeName = parser.getName();
3455 if (NODE_IMI.equals(nodeName)) {
3456 currentImiId = parser.getAttributeValue(null, ATTR_ID);
3457 if (TextUtils.isEmpty(currentImiId)) {
3458 Slog.w(TAG, "Invalid imi id found in subtypes.xml");
3459 continue;
3460 }
3461 tempSubtypesArray = new ArrayList<InputMethodSubtype>();
3462 allSubtypes.put(currentImiId, tempSubtypesArray);
3463 } else if (NODE_SUBTYPE.equals(nodeName)) {
3464 if (TextUtils.isEmpty(currentImiId) || tempSubtypesArray == null) {
3465 Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId);
3466 continue;
3467 }
3468 final int icon = Integer.valueOf(
3469 parser.getAttributeValue(null, ATTR_ICON));
3470 final int label = Integer.valueOf(
3471 parser.getAttributeValue(null, ATTR_LABEL));
3472 final String imeSubtypeLocale =
3473 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE);
3474 final String imeSubtypeMode =
3475 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_MODE);
3476 final String imeSubtypeExtraValue =
3477 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_EXTRA_VALUE);
satok4a28bde2011-06-29 21:03:40 +09003478 final boolean isAuxiliary = "1".equals(String.valueOf(
3479 parser.getAttributeValue(null, ATTR_IS_AUXILIARY)));
Yohei Yukawa443c2ba2014-09-10 14:10:30 +09003480 final InputMethodSubtype subtype = new InputMethodSubtypeBuilder()
3481 .setSubtypeNameResId(label)
3482 .setSubtypeIconResId(icon)
3483 .setSubtypeLocale(imeSubtypeLocale)
3484 .setSubtypeMode(imeSubtypeMode)
3485 .setSubtypeExtraValue(imeSubtypeExtraValue)
3486 .setIsAuxiliary(isAuxiliary)
3487 .build();
satoke7c6998e2011-06-03 17:57:59 +09003488 tempSubtypesArray.add(subtype);
3489 }
3490 }
3491 } catch (XmlPullParserException e) {
3492 Slog.w(TAG, "Error reading subtypes: " + e);
3493 return;
3494 } catch (java.io.IOException e) {
3495 Slog.w(TAG, "Error reading subtypes: " + e);
3496 return;
3497 } catch (NumberFormatException e) {
3498 Slog.w(TAG, "Error reading subtypes: " + e);
3499 return;
3500 } finally {
3501 if (fis != null) {
3502 try {
3503 fis.close();
3504 } catch (java.io.IOException e1) {
3505 Slog.w(TAG, "Failed to close.");
3506 }
3507 }
3508 }
3509 }
3510 }
3511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003512 @Override
3513 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
3514 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3515 != PackageManager.PERMISSION_GRANTED) {
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 pw.println("Permission Denial: can't dump InputMethodManager from from pid="
3518 + Binder.getCallingPid()
3519 + ", uid=" + Binder.getCallingUid());
3520 return;
3521 }
3522
3523 IInputMethod method;
3524 ClientState client;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003525
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526 final Printer p = new PrintWriterPrinter(pw);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003527
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 synchronized (mMethodMap) {
3529 p.println("Current Input Method Manager state:");
3530 int N = mMethodList.size();
3531 p.println(" Input Methods:");
3532 for (int i=0; i<N; i++) {
3533 InputMethodInfo info = mMethodList.get(i);
3534 p.println(" InputMethod #" + i + ":");
3535 info.dump(p, " ");
3536 }
3537 p.println(" Clients:");
3538 for (ClientState ci : mClients.values()) {
3539 p.println(" Client " + ci + ":");
3540 p.println(" client=" + ci.client);
3541 p.println(" inputContext=" + ci.inputContext);
3542 p.println(" sessionRequested=" + ci.sessionRequested);
3543 p.println(" curSession=" + ci.curSession);
3544 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003545 p.println(" mCurMethodId=" + mCurMethodId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 client = mCurClient;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07003547 p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq);
3548 p.println(" mCurFocusedWindow=" + mCurFocusedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003549 p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection
3550 + " mBoundToMethod=" + mBoundToMethod);
3551 p.println(" mCurToken=" + mCurToken);
3552 p.println(" mCurIntent=" + mCurIntent);
3553 method = mCurMethod;
3554 p.println(" mCurMethod=" + mCurMethod);
3555 p.println(" mEnabledSession=" + mEnabledSession);
3556 p.println(" mShowRequested=" + mShowRequested
3557 + " mShowExplicitlyRequested=" + mShowExplicitlyRequested
3558 + " mShowForced=" + mShowForced
3559 + " mInputShown=" + mInputShown);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09003560 p.println(" mCurUserActionNotificationSequenceNumber="
3561 + mCurUserActionNotificationSequenceNumber);
Dianne Hackbornd4e6d462014-05-16 16:32:37 -07003562 p.println(" mSystemReady=" + mSystemReady + " mInteractive=" + mScreenOn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003563 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003564
Jeff Brownb88102f2010-09-08 11:49:43 -07003565 p.println(" ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 if (client != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003567 pw.flush();
3568 try {
3569 client.client.asBinder().dump(fd, args);
3570 } catch (RemoteException e) {
3571 p.println("Input method client dead: " + e);
3572 }
Jeff Brownb88102f2010-09-08 11:49:43 -07003573 } else {
3574 p.println("No input method client.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003575 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003576
Jeff Brownb88102f2010-09-08 11:49:43 -07003577 p.println(" ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 if (method != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 pw.flush();
3580 try {
3581 method.asBinder().dump(fd, args);
3582 } catch (RemoteException e) {
3583 p.println("Input method service dead: " + e);
3584 }
Jeff Brownb88102f2010-09-08 11:49:43 -07003585 } else {
3586 p.println("No input method service.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 }
3588 }
3589}