blob: 1623eac6ac9e07cc3a4618764fcc59709f94ba3a [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());
satok5b927c432012-05-01 20:09:34 +0900777 Slog.i(TAG, "No default found, using " + defIm.getId());
778 }
779 if (defIm != null) {
780 setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false);
781 }
782 }
783
Satoshi Kataoka7f7535f2013-02-18 12:54:16 +0900784 private void resetAllInternalStateLocked(final boolean updateOnlyWhenLocaleChanged,
785 final boolean resetDefaultEnabledIme) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900786 if (!mSystemReady) {
787 // not system ready
788 return;
789 }
790 final Locale newLocale = mRes.getConfiguration().locale;
791 if (!updateOnlyWhenLocaleChanged
792 || (newLocale != null && !newLocale.equals(mLastSystemLocale))) {
793 if (!updateOnlyWhenLocaleChanged) {
794 hideCurrentInputLocked(0, null);
795 mCurMethodId = null;
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -0700796 unbindCurrentMethodLocked(true, false);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900797 }
798 if (DEBUG) {
799 Slog.i(TAG, "Locale has been changed to " + newLocale);
800 }
Satoshi Kataoka7f7535f2013-02-18 12:54:16 +0900801 buildInputMethodListLocked(mMethodList, mMethodMap, resetDefaultEnabledIme);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900802 if (!updateOnlyWhenLocaleChanged) {
803 final String selectedImiId = mSettings.getSelectedInputMethod();
804 if (TextUtils.isEmpty(selectedImiId)) {
805 // This is the first time of the user switch and
806 // set the current ime to the proper one.
807 resetDefaultImeLocked(mContext);
808 }
Satoshi Kataokad08a9232012-09-28 15:59:58 +0900809 } else {
810 // If the locale is changed, needs to reset the default ime
811 resetDefaultImeLocked(mContext);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900812 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -0800813 updateFromSettingsLocked(true);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900814 mLastSystemLocale = newLocale;
815 if (!updateOnlyWhenLocaleChanged) {
816 try {
817 startInputInnerLocked();
818 } catch (RuntimeException e) {
819 Slog.w(TAG, "Unexpected exception", e);
820 }
821 }
822 }
823 }
824
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +0900825 private void resetStateIfCurrentLocaleChangedLocked() {
Satoshi Kataoka7f7535f2013-02-18 12:54:16 +0900826 resetAllInternalStateLocked(true /* updateOnlyWhenLocaleChanged */,
827 true /* resetDefaultImeLocked */);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900828 }
829
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +0900830 private void switchUserLocked(int newUserId) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900831 mSettings.setCurrentUserId(newUserId);
Kenny Guy2a764942014-04-02 13:29:20 +0100832 updateCurrentProfileIds();
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +0900833 // InputMethodFileManager should be reset when the user is changed
834 mFileManager = new InputMethodFileManager(mMethodMap, newUserId);
Satoshi Kataoka7f7535f2013-02-18 12:54:16 +0900835 final String defaultImiId = mSettings.getSelectedInputMethod();
Satoshi Kataoka7c4a2a12013-02-25 15:25:43 +0900836 // For secondary users, the list of enabled IMEs may not have been updated since the
837 // callbacks to PackageMonitor are ignored for the secondary user. Here, defaultImiId may
838 // not be empty even if the IME has been uninstalled by the primary user.
839 // Even in such cases, IMMS works fine because it will find the most applicable
840 // IME for that user.
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +0900841 final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId);
Satoshi Kataoka7f7535f2013-02-18 12:54:16 +0900842 if (DEBUG) {
843 Slog.d(TAG, "Switch user: " + newUserId + " current ime = " + defaultImiId);
844 }
845 resetAllInternalStateLocked(false /* updateOnlyWhenLocaleChanged */,
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +0900846 initialUserSwitch /* needsToResetDefaultIme */);
847 if (initialUserSwitch) {
848 InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mContext.getPackageManager(),
849 mSettings.getEnabledInputMethodListLocked());
850 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900851 }
852
Kenny Guy2a764942014-04-02 13:29:20 +0100853 void updateCurrentProfileIds() {
854 List<UserInfo> profiles =
855 UserManager.get(mContext).getProfiles(mSettings.getCurrentUserId());
856 int[] currentProfileIds = new int[profiles.size()]; // profiles will not be null
857 for (int i = 0; i < currentProfileIds.length; i++) {
858 currentProfileIds[i] = profiles.get(i).id;
Amith Yamasani734983f2014-03-04 16:48:05 -0800859 }
Kenny Guy2a764942014-04-02 13:29:20 +0100860 mSettings.setCurrentProfileIds(currentProfileIds);
Amith Yamasani734983f2014-03-04 16:48:05 -0800861 }
862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 @Override
864 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
865 throws RemoteException {
866 try {
867 return super.onTransact(code, data, reply, flags);
868 } catch (RuntimeException e) {
869 // The input method manager only throws security exceptions, so let's
870 // log all others.
871 if (!(e instanceof SecurityException)) {
Dianne Hackborn164371f2013-10-01 19:10:13 -0700872 Slog.wtf(TAG, "Input Method Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 }
874 throw e;
875 }
876 }
877
Svetoslav Ganova0027152013-06-25 14:59:53 -0700878 public void systemRunning(StatusBarManagerService statusBar) {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700879 synchronized (mMethodMap) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900880 if (DEBUG) {
881 Slog.d(TAG, "--- systemReady");
882 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700883 if (!mSystemReady) {
884 mSystemReady = true;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900885 mKeyguardManager =
886 (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700887 mNotificationManager = (NotificationManager)
888 mContext.getSystemService(Context.NOTIFICATION_SERVICE);
889 mStatusBar = statusBar;
890 statusBar.setIconVisibility("ime", false);
891 updateImeWindowStatusLocked();
satokb858c732011-07-22 19:54:34 +0900892 mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
893 com.android.internal.R.bool.show_ongoing_ime_switcher);
satok01038492012-04-09 21:08:27 +0900894 if (mShowOngoingImeSwitcherForPhones) {
895 mWindowManagerService.setOnHardKeyboardStatusChangeListener(
896 mHardKeyboardListener);
897 }
Satoshi Kataokaf1367b72013-01-25 17:20:12 +0900898 buildInputMethodListLocked(mMethodList, mMethodMap,
899 !mImeSelectedOnBoot /* resetDefaultEnabledIme */);
satok0a1bcf42012-05-16 19:26:31 +0900900 if (!mImeSelectedOnBoot) {
901 Slog.w(TAG, "Reset the default IME as \"Resource\" is ready here.");
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +0900902 resetStateIfCurrentLocaleChangedLocked();
903 InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(
904 mContext.getPackageManager(),
905 mSettings.getEnabledInputMethodListLocked());
satok0a1bcf42012-05-16 19:26:31 +0900906 }
907 mLastSystemLocale = mRes.getConfiguration().locale;
Dianne Hackborncc278702009-09-02 23:07:23 -0700908 try {
909 startInputInnerLocked();
910 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800911 Slog.w(TAG, "Unexpected exception", e);
Dianne Hackborncc278702009-09-02 23:07:23 -0700912 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700913 }
914 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800915 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800916
satok15452a42011-10-28 17:58:28 +0900917 private void setImeWindowVisibilityStatusHiddenLocked() {
918 mImeWindowVis = 0;
919 updateImeWindowStatusLocked();
920 }
921
satok3afd6c02011-11-18 08:38:19 +0900922 private void refreshImeWindowVisibilityLocked() {
923 final Configuration conf = mRes.getConfiguration();
924 final boolean haveHardKeyboard = conf.keyboard
925 != Configuration.KEYBOARD_NOKEYS;
926 final boolean hardKeyShown = haveHardKeyboard
927 && conf.hardKeyboardHidden
928 != Configuration.HARDKEYBOARDHIDDEN_YES;
John Spurlocke0980502013-10-25 11:59:29 -0400929
930 final boolean isScreenLocked = isKeyguardLocked();
931 final boolean inputActive = !isScreenLocked && (mInputShown || hardKeyShown);
John Spurlock36439b42013-10-23 16:36:47 -0400932 // We assume the softkeyboard is shown when the input is active as long as the
933 // hard keyboard is not shown.
934 final boolean inputVisible = inputActive && !hardKeyShown;
935 mImeWindowVis = (inputActive ? InputMethodService.IME_ACTIVE : 0)
936 | (inputVisible ? InputMethodService.IME_VISIBLE : 0);
satok3afd6c02011-11-18 08:38:19 +0900937 updateImeWindowStatusLocked();
938 }
939
satok15452a42011-10-28 17:58:28 +0900940 private void updateImeWindowStatusLocked() {
satokdbf29502011-08-25 15:28:23 +0900941 setImeWindowStatus(mCurToken, mImeWindowVis, mBackDisposition);
Dianne Hackborn661cd522011-08-22 00:26:20 -0700942 }
943
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900944 // ---------------------------------------------------------------------------------------
945 // Check whether or not this is a valid IPC. Assumes an IPC is valid when either
946 // 1) it comes from the system process
947 // 2) the calling process' user id is identical to the current user id IMMS thinks.
948 private boolean calledFromValidUser() {
949 final int uid = Binder.getCallingUid();
950 final int userId = UserHandle.getUserId(uid);
951 if (DEBUG) {
952 Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? "
953 + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID
954 + " calling userId = " + userId + ", foreground user id = "
Satoshi Kataoka87c29142013-07-31 23:11:54 +0900955 + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid()
956 + InputMethodUtils.getApiCallStack());
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900957 }
Kenny Guy2a764942014-04-02 13:29:20 +0100958 if (uid == Process.SYSTEM_UID || mSettings.isCurrentProfile(userId)) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900959 return true;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900960 }
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +0900961
962 // Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the
963 // foreground user, not for the user of that process. Accordingly InputMethodManagerService
964 // must not manage background users' states in any functions.
965 // Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded
966 // by a token.
967 if (mContext.checkCallingOrSelfPermission(
968 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
969 == PackageManager.PERMISSION_GRANTED) {
970 if (DEBUG) {
971 Slog.d(TAG, "--- Access granted because the calling process has "
972 + "the INTERACT_ACROSS_USERS_FULL permission");
973 }
974 return true;
975 }
Satoshi Kataoka0766eb02013-07-31 18:30:13 +0900976 Slog.w(TAG, "--- IPC called from background users. Ignore. \n"
977 + InputMethodUtils.getStackTrace());
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +0900978 return false;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900979 }
980
Yohei Yukawa22c97be2014-06-04 19:43:36 +0900981
982 /**
983 * Returns true iff the caller is identified to be the current input method with the token.
984 * @param token The window token given to the input method when it was started.
985 * @return true if and only if non-null valid token is specified.
986 */
987 private boolean calledWithValidToken(IBinder token) {
988 if (token == null || mCurToken != token) {
989 return false;
990 }
991 return true;
992 }
993
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900994 private boolean bindCurrentInputMethodService(
995 Intent service, ServiceConnection conn, int flags) {
996 if (service == null || conn == null) {
997 Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn);
998 return false;
999 }
Amith Yamasani27b89e62013-01-16 12:30:11 -08001000 return mContext.bindServiceAsUser(service, conn, flags,
1001 new UserHandle(mSettings.getCurrentUserId()));
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001002 }
1003
satoke7c6998e2011-06-03 17:57:59 +09001004 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 public List<InputMethodInfo> getInputMethodList() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001006 // TODO: Make this work even for non-current users?
1007 if (!calledFromValidUser()) {
1008 return Collections.emptyList();
1009 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 synchronized (mMethodMap) {
1011 return new ArrayList<InputMethodInfo>(mMethodList);
1012 }
1013 }
1014
satoke7c6998e2011-06-03 17:57:59 +09001015 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 public List<InputMethodInfo> getEnabledInputMethodList() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001017 // TODO: Make this work even for non-current users?
1018 if (!calledFromValidUser()) {
1019 return Collections.emptyList();
1020 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001021 synchronized (mMethodMap) {
satokd87c2592010-09-29 11:52:06 +09001022 return mSettings.getEnabledInputMethodListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 }
1024 }
1025
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001026 /**
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001027 * @param imiId if null, returns enabled subtypes for the current imi
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001028 * @return enabled subtypes of the specified imi
1029 */
satoke7c6998e2011-06-03 17:57:59 +09001030 @Override
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001031 public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId,
satok16331c82010-12-20 23:48:46 +09001032 boolean allowsImplicitlySelectedSubtypes) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001033 // TODO: Make this work even for non-current users?
1034 if (!calledFromValidUser()) {
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001035 return Collections.<InputMethodSubtype>emptyList();
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001036 }
satok67ddf9c2010-11-17 09:45:54 +09001037 synchronized (mMethodMap) {
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001038 final InputMethodInfo imi;
1039 if (imiId == null && mCurMethodId != null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001040 imi = mMethodMap.get(mCurMethodId);
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001041 } else {
1042 imi = mMethodMap.get(imiId);
1043 }
1044 if (imi == null) {
1045 return Collections.<InputMethodSubtype>emptyList();
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001046 }
1047 return mSettings.getEnabledInputMethodSubtypeListLocked(
1048 mContext, imi, allowsImplicitlySelectedSubtypes);
satok67ddf9c2010-11-17 09:45:54 +09001049 }
1050 }
1051
satoke7c6998e2011-06-03 17:57:59 +09001052 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 public void addClient(IInputMethodClient client,
1054 IInputContext inputContext, int uid, int pid) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001055 if (!calledFromValidUser()) {
1056 return;
1057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058 synchronized (mMethodMap) {
1059 mClients.put(client.asBinder(), new ClientState(client,
1060 inputContext, uid, pid));
1061 }
1062 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001063
satoke7c6998e2011-06-03 17:57:59 +09001064 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001065 public void removeClient(IInputMethodClient client) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001066 if (!calledFromValidUser()) {
1067 return;
1068 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 synchronized (mMethodMap) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001070 ClientState cs = mClients.remove(client.asBinder());
1071 if (cs != null) {
1072 clearClientSessionLocked(cs);
1073 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001074 }
1075 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001076
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 void executeOrSendMessage(IInterface target, Message msg) {
1078 if (target.asBinder() instanceof Binder) {
1079 mCaller.sendMessage(msg);
1080 } else {
1081 handleMessage(msg);
1082 msg.recycle();
1083 }
1084 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001085
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001086 void unbindCurrentClientLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 if (mCurClient != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001088 if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 + mCurClient.client.asBinder());
1090 if (mBoundToMethod) {
1091 mBoundToMethod = false;
1092 if (mCurMethod != null) {
1093 executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
1094 MSG_UNBIND_INPUT, mCurMethod));
1095 }
1096 }
Dianne Hackborna6e41342012-05-22 16:30:34 -07001097
1098 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
1099 MSG_SET_ACTIVE, 0, mCurClient));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001100 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
1101 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
1102 mCurClient.sessionRequested = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 mCurClient = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001104
The Android Open Source Project10592532009-03-18 17:39:46 -07001105 hideInputMethodMenuLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 }
1107 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 private int getImeShowFlags() {
1110 int flags = 0;
1111 if (mShowForced) {
1112 flags |= InputMethod.SHOW_FORCED
1113 | InputMethod.SHOW_EXPLICIT;
1114 } else if (mShowExplicitlyRequested) {
1115 flags |= InputMethod.SHOW_EXPLICIT;
1116 }
1117 return flags;
1118 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 private int getAppShowFlags() {
1121 int flags = 0;
1122 if (mShowForced) {
1123 flags |= InputMethodManager.SHOW_FORCED;
1124 } else if (!mShowExplicitlyRequested) {
1125 flags |= InputMethodManager.SHOW_IMPLICIT;
1126 }
1127 return flags;
1128 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001129
Dianne Hackborn7663d802012-02-24 13:08:49 -08001130 InputBindResult attachNewInputLocked(boolean initial) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 if (!mBoundToMethod) {
1132 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
1133 MSG_BIND_INPUT, mCurMethod, mCurClient.binding));
1134 mBoundToMethod = true;
1135 }
1136 final SessionState session = mCurClient.curSession;
1137 if (initial) {
1138 executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
1139 MSG_START_INPUT, session, mCurInputContext, mCurAttribute));
1140 } else {
1141 executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
1142 MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute));
1143 }
1144 if (mShowRequested) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001145 if (DEBUG) Slog.v(TAG, "Attach new input asks to show input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001146 showCurrentInputLocked(getAppShowFlags(), null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001147 }
Jeff Brown1951ce82013-04-04 22:45:12 -07001148 return new InputBindResult(session.session,
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001149 (session.channel != null ? session.channel.dup() : null),
1150 mCurId, mCurSeq, mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001153 InputBindResult startInputLocked(IInputMethodClient client,
Dianne Hackborn7663d802012-02-24 13:08:49 -08001154 IInputContext inputContext, EditorInfo attribute, int controlFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 // If no method is currently selected, do nothing.
1156 if (mCurMethodId == null) {
1157 return mNoBinding;
1158 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 ClientState cs = mClients.get(client.asBinder());
1161 if (cs == null) {
1162 throw new IllegalArgumentException("unknown client "
1163 + client.asBinder());
1164 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 try {
1167 if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
1168 // Check with the window manager to make sure this client actually
1169 // has a window with focus. If not, reject. This is thread safe
1170 // because if the focus changes some time before or after, the
1171 // next client receiving focus that has any interest in input will
1172 // be calling through here after that change happens.
Joe Onorato8a9b2202010-02-26 18:56:32 -08001173 Slog.w(TAG, "Starting input on non-focused client " + cs.client
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
1175 return null;
1176 }
1177 } catch (RemoteException e) {
1178 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001179
Dianne Hackborn7663d802012-02-24 13:08:49 -08001180 return startInputUncheckedLocked(cs, inputContext, attribute, controlFlags);
1181 }
1182
1183 InputBindResult startInputUncheckedLocked(ClientState cs,
1184 IInputContext inputContext, EditorInfo attribute, int controlFlags) {
1185 // If no method is currently selected, do nothing.
1186 if (mCurMethodId == null) {
1187 return mNoBinding;
1188 }
1189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 if (mCurClient != cs) {
John Spurlocke0980502013-10-25 11:59:29 -04001191 // Was the keyguard locked when switching over to the new client?
1192 mCurClientInKeyguard = isKeyguardLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 // If the client is changing, we need to switch over to the new
1194 // one.
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001195 unbindCurrentClientLocked();
Joe Onorato8a9b2202010-02-26 18:56:32 -08001196 if (DEBUG) Slog.v(TAG, "switching to client: client = "
John Spurlocke0980502013-10-25 11:59:29 -04001197 + cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198
1199 // If the screen is on, inform the new client it is active
1200 if (mScreenOn) {
Dianne Hackborna6e41342012-05-22 16:30:34 -07001201 executeOrSendMessage(cs.client, mCaller.obtainMessageIO(
1202 MSG_SET_ACTIVE, mScreenOn ? 1 : 0, cs));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 }
1204 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 // Bump up the sequence for this client and attach it.
1207 mCurSeq++;
1208 if (mCurSeq <= 0) mCurSeq = 1;
1209 mCurClient = cs;
1210 mCurInputContext = inputContext;
1211 mCurAttribute = attribute;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213 // Check if the input method is changing.
1214 if (mCurId != null && mCurId.equals(mCurMethodId)) {
1215 if (cs.curSession != null) {
1216 // Fast case: if we are already connected to the input method,
1217 // then just return it.
Dianne Hackborn7663d802012-02-24 13:08:49 -08001218 return attachNewInputLocked(
1219 (controlFlags&InputMethodManager.CONTROL_START_INITIAL) != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001220 }
1221 if (mHaveConnection) {
1222 if (mCurMethod != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 // Return to client, and we will get back with it when
1224 // we have had a session made for it.
Jeff Brownc28867a2013-03-26 15:42:39 -07001225 requestClientSessionLocked(cs);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001226 return new InputBindResult(null, null, mCurId, mCurSeq,
1227 mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 } else if (SystemClock.uptimeMillis()
1229 < (mLastBindTime+TIME_TO_RECONNECT)) {
1230 // In this case we have connected to the service, but
1231 // don't yet have its interface. If it hasn't been too
1232 // long since we did the connection, we'll return to
1233 // the client and wait to get the service interface so
1234 // we can report back. If it has been too long, we want
1235 // to fall through so we can try a disconnect/reconnect
1236 // to see if we can get back in touch with the service.
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001237 return new InputBindResult(null, null, mCurId, mCurSeq,
1238 mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 } else {
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001240 EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME,
1241 mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 }
1243 }
1244 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001245
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001246 return startInputInnerLocked();
1247 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001248
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001249 InputBindResult startInputInnerLocked() {
1250 if (mCurMethodId == null) {
1251 return mNoBinding;
1252 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001253
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001254 if (!mSystemReady) {
1255 // If the system is not yet ready, we shouldn't be running third
1256 // party code.
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001257 return new InputBindResult(null, null, mCurMethodId, mCurSeq,
1258 mCurUserActionNotificationSequenceNumber);
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001259 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 InputMethodInfo info = mMethodMap.get(mCurMethodId);
1262 if (info == null) {
1263 throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
1264 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001265
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001266 unbindCurrentMethodLocked(false, true);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001268 mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE);
1269 mCurIntent.setComponent(info.getComponent());
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07001270 mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
1271 com.android.internal.R.string.input_method_binding_label);
1272 mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
1273 mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0));
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001274 if (bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
Dianne Hackbornf0f94d12014-03-17 16:04:21 -07001275 | Context.BIND_NOT_VISIBLE | Context.BIND_NOT_FOREGROUND
1276 | Context.BIND_SHOWING_UI)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 mLastBindTime = SystemClock.uptimeMillis();
1278 mHaveConnection = true;
1279 mCurId = info.getId();
1280 mCurToken = new Binder();
1281 try {
Craig Mautnerca0ac712013-03-14 09:43:02 -07001282 if (true || DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 mIWindowManager.addWindowToken(mCurToken,
1284 WindowManager.LayoutParams.TYPE_INPUT_METHOD);
1285 } catch (RemoteException e) {
1286 }
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001287 return new InputBindResult(null, null, mCurId, mCurSeq,
1288 mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289 } else {
1290 mCurIntent = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001291 Slog.w(TAG, "Failure connecting to input method service: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001292 + mCurIntent);
1293 }
1294 return null;
1295 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001296
satoke7c6998e2011-06-03 17:57:59 +09001297 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 public InputBindResult startInput(IInputMethodClient client,
Dianne Hackborn7663d802012-02-24 13:08:49 -08001299 IInputContext inputContext, EditorInfo attribute, int controlFlags) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001300 if (!calledFromValidUser()) {
1301 return null;
1302 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001303 synchronized (mMethodMap) {
1304 final long ident = Binder.clearCallingIdentity();
1305 try {
Dianne Hackborn7663d802012-02-24 13:08:49 -08001306 return startInputLocked(client, inputContext, attribute, controlFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 } finally {
1308 Binder.restoreCallingIdentity(ident);
1309 }
1310 }
1311 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001312
satoke7c6998e2011-06-03 17:57:59 +09001313 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 public void finishInput(IInputMethodClient client) {
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 onServiceConnected(ComponentName name, IBinder service) {
1319 synchronized (mMethodMap) {
1320 if (mCurIntent != null && name.equals(mCurIntent.getComponent())) {
1321 mCurMethod = IInputMethod.Stub.asInterface(service);
Dianne Hackborncc278702009-09-02 23:07:23 -07001322 if (mCurToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001323 Slog.w(TAG, "Service connected without a token!");
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001324 unbindCurrentMethodLocked(false, false);
Dianne Hackborncc278702009-09-02 23:07:23 -07001325 return;
1326 }
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07001327 if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken);
Dianne Hackborncc278702009-09-02 23:07:23 -07001328 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
1329 MSG_ATTACH_TOKEN, mCurMethod, mCurToken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 if (mCurClient != null) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001331 clearClientSessionLocked(mCurClient);
1332 requestClientSessionLocked(mCurClient);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 }
1334 }
1335 }
1336 }
1337
Jeff Brownc28867a2013-03-26 15:42:39 -07001338 void onSessionCreated(IInputMethod method, IInputMethodSession session,
1339 InputChannel channel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340 synchronized (mMethodMap) {
1341 if (mCurMethod != null && method != null
1342 && mCurMethod.asBinder() == method.asBinder()) {
1343 if (mCurClient != null) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001344 clearClientSessionLocked(mCurClient);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 mCurClient.curSession = new SessionState(mCurClient,
Jeff Brownc28867a2013-03-26 15:42:39 -07001346 method, session, channel);
Dianne Hackborn7663d802012-02-24 13:08:49 -08001347 InputBindResult res = attachNewInputLocked(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 if (res.method != null) {
1349 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO(
1350 MSG_BIND_METHOD, mCurClient.client, res));
1351 }
Jeff Brownc28867a2013-03-26 15:42:39 -07001352 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 }
1354 }
1355 }
Jeff Brownc28867a2013-03-26 15:42:39 -07001356
1357 // Session abandoned. Close its associated input channel.
1358 channel.dispose();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001360
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001361 void unbindCurrentMethodLocked(boolean reportToClient, boolean savePosition) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001362 if (mVisibleBound) {
1363 mContext.unbindService(mVisibleConnection);
1364 mVisibleBound = false;
1365 }
1366
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001367 if (mHaveConnection) {
1368 mContext.unbindService(this);
1369 mHaveConnection = false;
1370 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001371
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001372 if (mCurToken != null) {
1373 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001374 if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001375 if ((mImeWindowVis & InputMethodService.IME_ACTIVE) != 0 && savePosition) {
satoke0a99412012-05-10 02:22:58 +09001376 // The current IME is shown. Hence an IME switch (transition) is happening.
1377 mWindowManagerService.saveLastInputMethodWindowForTransition();
1378 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001379 mIWindowManager.removeWindowToken(mCurToken);
1380 } catch (RemoteException e) {
1381 }
1382 mCurToken = null;
1383 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001384
The Android Open Source Project10592532009-03-18 17:39:46 -07001385 mCurId = null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001386 clearCurMethodLocked();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001387
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001388 if (reportToClient && mCurClient != null) {
1389 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
1390 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
1391 }
1392 }
Jeff Brownc28867a2013-03-26 15:42:39 -07001393
1394 void requestClientSessionLocked(ClientState cs) {
1395 if (!cs.sessionRequested) {
1396 if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs);
1397 InputChannel[] channels = InputChannel.openInputChannelPair(cs.toString());
1398 cs.sessionRequested = true;
1399 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOOO(
1400 MSG_CREATE_SESSION, mCurMethod, channels[1],
1401 new MethodCallback(this, mCurMethod, channels[0])));
1402 }
1403 }
1404
1405 void clearClientSessionLocked(ClientState cs) {
1406 finishSessionLocked(cs.curSession);
1407 cs.curSession = null;
1408 cs.sessionRequested = false;
1409 }
1410
1411 private void finishSessionLocked(SessionState sessionState) {
1412 if (sessionState != null) {
1413 if (sessionState.session != null) {
1414 try {
1415 sessionState.session.finishSession();
1416 } catch (RemoteException e) {
1417 Slog.w(TAG, "Session failed to close due to remote exception", e);
1418 setImeWindowVisibilityStatusHiddenLocked();
1419 }
1420 sessionState.session = null;
1421 }
1422 if (sessionState.channel != null) {
1423 sessionState.channel.dispose();
1424 sessionState.channel = null;
Devin Taylor0c33ed22010-02-23 13:26:46 -06001425 }
1426 }
1427 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001428
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001429 void clearCurMethodLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 if (mCurMethod != null) {
1431 for (ClientState cs : mClients.values()) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001432 clearClientSessionLocked(cs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001433 }
Devin Taylor0c33ed22010-02-23 13:26:46 -06001434
Jeff Brownc28867a2013-03-26 15:42:39 -07001435 finishSessionLocked(mEnabledSession);
Devin Taylor0c33ed22010-02-23 13:26:46 -06001436 mEnabledSession = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 mCurMethod = null;
1438 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07001439 if (mStatusBar != null) {
1440 mStatusBar.setIconVisibility("ime", false);
1441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001443
satoke7c6998e2011-06-03 17:57:59 +09001444 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 public void onServiceDisconnected(ComponentName name) {
1446 synchronized (mMethodMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001447 if (DEBUG) Slog.v(TAG, "Service disconnected: " + name
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 + " mCurIntent=" + mCurIntent);
1449 if (mCurMethod != null && mCurIntent != null
1450 && name.equals(mCurIntent.getComponent())) {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001451 clearCurMethodLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001452 // We consider this to be a new bind attempt, since the system
1453 // should now try to restart the service for us.
1454 mLastBindTime = SystemClock.uptimeMillis();
1455 mShowRequested = mInputShown;
1456 mInputShown = false;
1457 if (mCurClient != null) {
1458 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
1459 MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
1460 }
1461 }
1462 }
1463 }
1464
satokf9f01002011-05-19 21:31:50 +09001465 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 public void updateStatusIcon(IBinder token, String packageName, int iconId) {
1467 long ident = Binder.clearCallingIdentity();
1468 try {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 synchronized (mMethodMap) {
Yohei Yukawaa0755742014-06-04 20:28:18 +09001470 if (!calledWithValidToken(token)) {
1471 final int uid = Binder.getCallingUid();
1472 Slog.e(TAG, "Ignoring updateStatusIcon due to an invalid token. uid:" + uid
1473 + " token:" + token);
1474 return;
1475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 if (iconId == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001477 if (DEBUG) Slog.d(TAG, "hide the small icon for the input method");
Dianne Hackborn661cd522011-08-22 00:26:20 -07001478 if (mStatusBar != null) {
1479 mStatusBar.setIconVisibility("ime", false);
1480 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 } else if (packageName != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001482 if (DEBUG) Slog.d(TAG, "show a small icon for the input method");
Svetoslav Ganov6179ea32011-06-28 01:12:41 -07001483 CharSequence contentDescription = null;
1484 try {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001485 // Use PackageManager to load label
1486 final PackageManager packageManager = mContext.getPackageManager();
Svetoslav Ganov6179ea32011-06-28 01:12:41 -07001487 contentDescription = packageManager.getApplicationLabel(
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001488 mIPackageManager.getApplicationInfo(packageName, 0,
1489 mSettings.getCurrentUserId()));
1490 } catch (RemoteException e) {
Svetoslav Ganov6179ea32011-06-28 01:12:41 -07001491 /* ignore */
1492 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07001493 if (mStatusBar != null) {
1494 mStatusBar.setIcon("ime", packageName, iconId, 0,
1495 contentDescription != null
1496 ? contentDescription.toString() : null);
1497 mStatusBar.setIconVisibility("ime", true);
1498 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 }
1500 }
1501 } finally {
1502 Binder.restoreCallingIdentity(ident);
1503 }
1504 }
1505
satok7cfc0ed2011-06-20 21:29:36 +09001506 private boolean needsToShowImeSwitchOngoingNotification() {
1507 if (!mShowOngoingImeSwitcherForPhones) return false;
Jason Monk807ef762014-05-08 15:47:46 -04001508 if (mSwitchingDialog != null) return false;
satok2c93efc2012-04-02 19:33:47 +09001509 if (isScreenLocked()) return false;
satok7cfc0ed2011-06-20 21:29:36 +09001510 synchronized (mMethodMap) {
1511 List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
1512 final int N = imis.size();
satokb6359412011-06-28 17:47:41 +09001513 if (N > 2) return true;
1514 if (N < 1) return false;
1515 int nonAuxCount = 0;
1516 int auxCount = 0;
1517 InputMethodSubtype nonAuxSubtype = null;
1518 InputMethodSubtype auxSubtype = null;
satok7cfc0ed2011-06-20 21:29:36 +09001519 for(int i = 0; i < N; ++i) {
1520 final InputMethodInfo imi = imis.get(i);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001521 final List<InputMethodSubtype> subtypes =
1522 mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
satok7cfc0ed2011-06-20 21:29:36 +09001523 final int subtypeCount = subtypes.size();
1524 if (subtypeCount == 0) {
satokb6359412011-06-28 17:47:41 +09001525 ++nonAuxCount;
satok7cfc0ed2011-06-20 21:29:36 +09001526 } else {
1527 for (int j = 0; j < subtypeCount; ++j) {
satokb6359412011-06-28 17:47:41 +09001528 final InputMethodSubtype subtype = subtypes.get(j);
1529 if (!subtype.isAuxiliary()) {
1530 ++nonAuxCount;
1531 nonAuxSubtype = subtype;
1532 } else {
1533 ++auxCount;
1534 auxSubtype = subtype;
satok7cfc0ed2011-06-20 21:29:36 +09001535 }
1536 }
1537 }
satok7cfc0ed2011-06-20 21:29:36 +09001538 }
satokb6359412011-06-28 17:47:41 +09001539 if (nonAuxCount > 1 || auxCount > 1) {
1540 return true;
1541 } else if (nonAuxCount == 1 && auxCount == 1) {
1542 if (nonAuxSubtype != null && auxSubtype != null
satok9747f892011-09-12 15:56:40 +09001543 && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale())
1544 || auxSubtype.overridesImplicitlyEnabledSubtype()
1545 || nonAuxSubtype.overridesImplicitlyEnabledSubtype())
satokb6359412011-06-28 17:47:41 +09001546 && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) {
1547 return false;
1548 }
1549 return true;
1550 }
1551 return false;
satok7cfc0ed2011-06-20 21:29:36 +09001552 }
satok7cfc0ed2011-06-20 21:29:36 +09001553 }
1554
John Spurlocke0980502013-10-25 11:59:29 -04001555 private boolean isKeyguardLocked() {
1556 return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked();
1557 }
1558
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001559 // Caution! This method is called in this class. Handle multi-user carefully
satokdbf29502011-08-25 15:28:23 +09001560 @SuppressWarnings("deprecation")
satokf9f01002011-05-19 21:31:50 +09001561 @Override
Joe Onorato857fd9b2011-01-27 15:08:35 -08001562 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001563 final long ident = Binder.clearCallingIdentity();
satok06487a52010-10-29 11:37:18 +09001564 try {
Yohei Yukawa22c97be2014-06-04 19:43:36 +09001565 if (!calledWithValidToken(token)) {
1566 final int uid = Binder.getCallingUid();
1567 Slog.e(TAG, "Ignoring setImeWindowStatus due to an invalid token. uid:" + uid
1568 + " token:" + token);
satok06487a52010-10-29 11:37:18 +09001569 return;
1570 }
satok06487a52010-10-29 11:37:18 +09001571 synchronized (mMethodMap) {
John Spurlocke0980502013-10-25 11:59:29 -04001572 // apply policy for binder calls
1573 if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) {
1574 vis = 0;
1575 }
Joe Onorato857fd9b2011-01-27 15:08:35 -08001576 mImeWindowVis = vis;
1577 mBackDisposition = backDisposition;
jungheang.lee217fd292013-02-26 16:53:22 +09001578 final boolean iconVisibility = ((vis & (InputMethodService.IME_ACTIVE)) != 0)
1579 && (mWindowManagerService.isHardKeyboardAvailable()
1580 || (vis & (InputMethodService.IME_VISIBLE)) != 0);
Jason Monkb605fec2014-05-02 17:04:10 -04001581 final boolean needsToShowImeSwitcher = iconVisibility
1582 && needsToShowImeSwitchOngoingNotification();
1583 if (mStatusBar != null) {
1584 mStatusBar.setImeWindowStatus(token, vis, backDisposition,
1585 needsToShowImeSwitcher);
1586 }
satok5bc8e732011-07-22 21:07:23 +09001587 final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
Jason Monkb605fec2014-05-02 17:04:10 -04001588 if (imi != null && needsToShowImeSwitcher) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001589 // Used to load label
satok7cfc0ed2011-06-20 21:29:36 +09001590 final CharSequence title = mRes.getText(
1591 com.android.internal.R.string.select_input_method);
Satoshi Kataokab2827262013-07-04 19:43:14 +09001592 final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName(
1593 mContext, imi, mCurrentSubtype);
satok5bc8e732011-07-22 21:07:23 +09001594
Selim Cinek255dd042014-08-19 22:29:02 +02001595 mImeSwitcherNotification.color = mContext.getResources().getColor(
1596 com.android.internal.R.color.system_notification_accent_color);
satok7cfc0ed2011-06-20 21:29:36 +09001597 mImeSwitcherNotification.setLatestEventInfo(
satok5bc8e732011-07-22 21:07:23 +09001598 mContext, title, summary, mImeSwitchPendingIntent);
Jason Monke463c742014-05-02 12:31:45 -04001599 if ((mNotificationManager != null)
1600 && !mWindowManagerService.hasNavigationBar()) {
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +09001601 if (DEBUG) {
Satoshi Kataokab2827262013-07-04 19:43:14 +09001602 Slog.d(TAG, "--- show notification: label = " + summary);
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +09001603 }
1604 mNotificationManager.notifyAsUser(null,
Dianne Hackborn661cd522011-08-22 00:26:20 -07001605 com.android.internal.R.string.select_input_method,
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +09001606 mImeSwitcherNotification, UserHandle.ALL);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001607 mNotificationShown = true;
1608 }
satok7cfc0ed2011-06-20 21:29:36 +09001609 } else {
Dianne Hackborn661cd522011-08-22 00:26:20 -07001610 if (mNotificationShown && mNotificationManager != null) {
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +09001611 if (DEBUG) {
1612 Slog.d(TAG, "--- hide notification");
1613 }
1614 mNotificationManager.cancelAsUser(null,
1615 com.android.internal.R.string.select_input_method, UserHandle.ALL);
satok7cfc0ed2011-06-20 21:29:36 +09001616 mNotificationShown = false;
1617 }
1618 }
satok06487a52010-10-29 11:37:18 +09001619 }
1620 } finally {
1621 Binder.restoreCallingIdentity(ident);
1622 }
1623 }
1624
satoke7c6998e2011-06-03 17:57:59 +09001625 @Override
satokf9f01002011-05-19 21:31:50 +09001626 public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001627 if (!calledFromValidUser()) {
1628 return;
1629 }
satokf9f01002011-05-19 21:31:50 +09001630 synchronized (mMethodMap) {
1631 final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
1632 for (int i = 0; i < spans.length; ++i) {
1633 SuggestionSpan ss = spans[i];
satok42c5a162011-05-26 16:46:14 +09001634 if (!TextUtils.isEmpty(ss.getNotificationTargetClassName())) {
satokf9f01002011-05-19 21:31:50 +09001635 mSecureSuggestionSpans.put(ss, currentImi);
1636 }
1637 }
1638 }
1639 }
1640
satoke7c6998e2011-06-03 17:57:59 +09001641 @Override
satokf9f01002011-05-19 21:31:50 +09001642 public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001643 if (!calledFromValidUser()) {
1644 return false;
1645 }
satokf9f01002011-05-19 21:31:50 +09001646 synchronized (mMethodMap) {
1647 final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span);
1648 // TODO: Do not send the intent if the process of the targetImi is already dead.
1649 if (targetImi != null) {
1650 final String[] suggestions = span.getSuggestions();
1651 if (index < 0 || index >= suggestions.length) return false;
satok42c5a162011-05-26 16:46:14 +09001652 final String className = span.getNotificationTargetClassName();
satokf9f01002011-05-19 21:31:50 +09001653 final Intent intent = new Intent();
1654 // Ensures that only a class in the original IME package will receive the
1655 // notification.
satok42c5a162011-05-26 16:46:14 +09001656 intent.setClassName(targetImi.getPackageName(), className);
satokf9f01002011-05-19 21:31:50 +09001657 intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED);
1658 intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString);
1659 intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]);
1660 intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode());
Amith Yamasanif043de92012-10-24 06:42:40 -07001661 final long ident = Binder.clearCallingIdentity();
1662 try {
1663 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
1664 } finally {
1665 Binder.restoreCallingIdentity(ident);
1666 }
satokf9f01002011-05-19 21:31:50 +09001667 return true;
1668 }
1669 }
1670 return false;
1671 }
1672
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001673 void updateFromSettingsLocked(boolean enabledMayChange) {
Michael Wright7b5a96b2014-08-09 19:28:42 -07001674 updateInputMethodsFromSettingsLocked(enabledMayChange);
1675 updateKeyboardFromSettingsLocked();
1676 }
1677
1678 void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) {
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001679 if (enabledMayChange) {
1680 List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
1681 for (int i=0; i<enabled.size(); i++) {
1682 // We allow the user to select "disabled until used" apps, so if they
1683 // are enabling one of those here we now need to make it enabled.
1684 InputMethodInfo imm = enabled.get(i);
1685 try {
1686 ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(),
1687 PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
1688 mSettings.getCurrentUserId());
Satoshi Kataoka7987a312013-04-17 18:59:33 +09001689 if (ai != null && ai.enabledSetting
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001690 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +09001691 if (DEBUG) {
1692 Slog.d(TAG, "Update state(" + imm.getId()
1693 + "): DISABLED_UNTIL_USED -> DEFAULT");
1694 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001695 mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(),
1696 PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07001697 PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(),
1698 mContext.getBasePackageName());
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001699 }
1700 } catch (RemoteException e) {
1701 }
1702 }
1703 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001704 // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and
1705 // ENABLED_INPUT_METHODS is taking care of keeping them correctly in
1706 // sync, so we will never have a DEFAULT_INPUT_METHOD that is not
1707 // enabled.
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001708 String id = mSettings.getSelectedInputMethod();
satok03eb319a2010-11-11 18:17:42 +09001709 // There is no input method selected, try to choose new applicable input method.
1710 if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001711 id = mSettings.getSelectedInputMethod();
satok03eb319a2010-11-11 18:17:42 +09001712 }
1713 if (!TextUtils.isEmpty(id)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001714 try {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001715 setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001716 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001717 Slog.w(TAG, "Unknown input method from prefs: " + id, e);
The Android Open Source Project10592532009-03-18 17:39:46 -07001718 mCurMethodId = null;
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001719 unbindCurrentMethodLocked(true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 }
satokf3db1af2010-11-23 13:34:33 +09001721 mShortcutInputMethodsAndSubtypes.clear();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001722 } else {
1723 // There is no longer an input method set, so stop any current one.
The Android Open Source Project10592532009-03-18 17:39:46 -07001724 mCurMethodId = null;
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001725 unbindCurrentMethodLocked(true, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 }
Yohei Yukawa3d46bab2014-05-30 18:10:18 +09001727 // Here is not the perfect place to reset the switching controller. Ideally
1728 // mSwitchingController and mSettings should be able to share the same state.
1729 // TODO: Make sure that mSwitchingController and mSettings are sharing the
1730 // the same enabled IMEs list.
1731 mSwitchingController.resetCircularListLocked(mContext);
Michael Wright7b5a96b2014-08-09 19:28:42 -07001732
1733 }
1734
1735 public void updateKeyboardFromSettingsLocked() {
1736 mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled();
1737 if (mSwitchingDialog != null
1738 && mSwitchingDialogTitleView != null
1739 && mSwitchingDialog.isShowing()) {
1740 final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById(
1741 com.android.internal.R.id.hard_keyboard_switch);
1742 hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
1743 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001744 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001745
satokab751aa2010-09-14 19:17:36 +09001746 /* package */ void setInputMethodLocked(String id, int subtypeId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001747 InputMethodInfo info = mMethodMap.get(id);
1748 if (info == null) {
satok913a8922010-08-26 21:53:41 +09001749 throw new IllegalArgumentException("Unknown id: " + id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001750 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001751
Yohei Yukawae63b5fa2014-09-19 13:14:55 +09001752 if (mCurClient != null && mCurAttribute != null) {
1753 final int uid = mCurClient.uid;
1754 final String packageName = mCurAttribute.packageName;
1755 if (SystemConfig.getInstance().getFixedImeApps().contains(packageName)) {
1756 if (InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, uid, packageName)) {
1757 return;
1758 }
1759 // TODO: Do we need to lock the input method when the application reported an
1760 // incorrect package name?
1761 Slog.e(TAG, "Ignoring FixedImeApps due to the validation failure. uid=" + uid
1762 + " package=" + packageName);
1763 }
1764 }
1765
satokd81e9502012-05-21 12:58:45 +09001766 // See if we need to notify a subtype change within the same IME.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001767 if (id.equals(mCurMethodId)) {
satokd81e9502012-05-21 12:58:45 +09001768 final int subtypeCount = info.getSubtypeCount();
1769 if (subtypeCount <= 0) {
1770 return;
satokcd7cd292010-11-20 15:46:23 +09001771 }
satokd81e9502012-05-21 12:58:45 +09001772 final InputMethodSubtype oldSubtype = mCurrentSubtype;
1773 final InputMethodSubtype newSubtype;
1774 if (subtypeId >= 0 && subtypeId < subtypeCount) {
1775 newSubtype = info.getSubtypeAt(subtypeId);
1776 } else {
1777 // If subtype is null, try to find the most applicable one from
1778 // getCurrentInputMethodSubtype.
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001779 newSubtype = getCurrentInputMethodSubtypeLocked();
satokd81e9502012-05-21 12:58:45 +09001780 }
1781 if (newSubtype == null || oldSubtype == null) {
1782 Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype
1783 + ", new subtype = " + newSubtype);
1784 return;
1785 }
1786 if (newSubtype != oldSubtype) {
1787 setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true);
1788 if (mCurMethod != null) {
1789 try {
1790 refreshImeWindowVisibilityLocked();
1791 mCurMethod.changeInputMethodSubtype(newSubtype);
1792 } catch (RemoteException e) {
1793 Slog.w(TAG, "Failed to call changeInputMethodSubtype");
satokab751aa2010-09-14 19:17:36 +09001794 }
1795 }
1796 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 return;
1798 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001799
satokd81e9502012-05-21 12:58:45 +09001800 // Changing to a different IME.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001801 final long ident = Binder.clearCallingIdentity();
1802 try {
satokab751aa2010-09-14 19:17:36 +09001803 // Set a subtype to this input method.
1804 // subtypeId the name of a subtype which will be set.
satok723a27e2010-11-11 14:58:11 +09001805 setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false);
1806 // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked()
1807 // because mCurMethodId is stored as a history in
1808 // setSelectedInputMethodAndSubtypeLocked().
1809 mCurMethodId = id;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001810
1811 if (ActivityManagerNative.isSystemReady()) {
1812 Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08001813 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001814 intent.putExtra("input_method_id", id);
Amith Yamasanicd757062012-10-19 18:23:52 -07001815 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001816 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001817 unbindCurrentClientLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001818 } finally {
1819 Binder.restoreCallingIdentity(ident);
1820 }
1821 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001822
satok42c5a162011-05-26 16:46:14 +09001823 @Override
The Android Open Source Project4df24232009-03-05 14:34:35 -08001824 public boolean showSoftInput(IInputMethodClient client, int flags,
1825 ResultReceiver resultReceiver) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001826 if (!calledFromValidUser()) {
1827 return false;
1828 }
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001829 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001830 long ident = Binder.clearCallingIdentity();
1831 try {
1832 synchronized (mMethodMap) {
1833 if (mCurClient == null || client == null
1834 || mCurClient.client.asBinder() != client.asBinder()) {
1835 try {
1836 // We need to check if this is the current client with
1837 // focus in the window manager, to allow this call to
1838 // be made before input is started in it.
1839 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001840 Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client);
The Android Open Source Project4df24232009-03-05 14:34:35 -08001841 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001842 }
1843 } catch (RemoteException e) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001844 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 }
1846 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001847
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07001848 if (DEBUG) Slog.v(TAG, "Client requesting input be shown");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001849 return showCurrentInputLocked(flags, resultReceiver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001850 }
1851 } finally {
1852 Binder.restoreCallingIdentity(ident);
1853 }
1854 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001855
The Android Open Source Project4df24232009-03-05 14:34:35 -08001856 boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 mShowRequested = true;
1858 if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) {
1859 mShowExplicitlyRequested = true;
1860 }
1861 if ((flags&InputMethodManager.SHOW_FORCED) != 0) {
1862 mShowExplicitlyRequested = true;
1863 mShowForced = true;
1864 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001865
Dianne Hackborncc278702009-09-02 23:07:23 -07001866 if (!mSystemReady) {
1867 return false;
1868 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001869
The Android Open Source Project4df24232009-03-05 14:34:35 -08001870 boolean res = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001871 if (mCurMethod != null) {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07001872 if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken);
The Android Open Source Project4df24232009-03-05 14:34:35 -08001873 executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO(
1874 MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod,
1875 resultReceiver));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001876 mInputShown = true;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001877 if (mHaveConnection && !mVisibleBound) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001878 bindCurrentInputMethodService(
Dianne Hackbornf0f94d12014-03-17 16:04:21 -07001879 mCurIntent, mVisibleConnection, Context.BIND_AUTO_CREATE
1880 | Context.BIND_TREAT_LIKE_ACTIVITY);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001881 mVisibleBound = true;
1882 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08001883 res = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001884 } else if (mHaveConnection && SystemClock.uptimeMillis()
satok59b424c2011-09-30 17:21:46 +09001885 >= (mLastBindTime+TIME_TO_RECONNECT)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001886 // The client has asked to have the input method shown, but
1887 // we have been sitting here too long with a connection to the
1888 // service and no interface received, so let's disconnect/connect
1889 // to try to prod things along.
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001890 EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001891 SystemClock.uptimeMillis()-mLastBindTime,1);
satok59b424c2011-09-30 17:21:46 +09001892 Slog.w(TAG, "Force disconnect/connect to the IME in showCurrentInputLocked()");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 mContext.unbindService(this);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001894 bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001895 | Context.BIND_NOT_VISIBLE);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001896 } else {
1897 if (DEBUG) {
1898 Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = "
1899 + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis()));
1900 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001901 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001902
The Android Open Source Project4df24232009-03-05 14:34:35 -08001903 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001905
satok42c5a162011-05-26 16:46:14 +09001906 @Override
The Android Open Source Project4df24232009-03-05 14:34:35 -08001907 public boolean hideSoftInput(IInputMethodClient client, int flags,
1908 ResultReceiver resultReceiver) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001909 if (!calledFromValidUser()) {
1910 return false;
1911 }
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001912 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 long ident = Binder.clearCallingIdentity();
1914 try {
1915 synchronized (mMethodMap) {
1916 if (mCurClient == null || client == null
1917 || mCurClient.client.asBinder() != client.asBinder()) {
1918 try {
1919 // We need to check if this is the current client with
1920 // focus in the window manager, to allow this call to
1921 // be made before input is started in it.
1922 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07001923 if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid "
1924 + uid + ": " + client);
satok15452a42011-10-28 17:58:28 +09001925 setImeWindowVisibilityStatusHiddenLocked();
The Android Open Source Project4df24232009-03-05 14:34:35 -08001926 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 }
1928 } catch (RemoteException e) {
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 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001933
Joe Onorato8a9b2202010-02-26 18:56:32 -08001934 if (DEBUG) Slog.v(TAG, "Client requesting input be hidden");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001935 return hideCurrentInputLocked(flags, resultReceiver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001936 }
1937 } finally {
1938 Binder.restoreCallingIdentity(ident);
1939 }
1940 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001941
The Android Open Source Project4df24232009-03-05 14:34:35 -08001942 boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943 if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0
1944 && (mShowExplicitlyRequested || mShowForced)) {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07001945 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 -08001946 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 }
1948 if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07001949 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 -08001950 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08001952 boolean res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001953 if (mInputShown && mCurMethod != null) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08001954 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
1955 MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver));
1956 res = true;
1957 } else {
1958 res = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001960 if (mHaveConnection && mVisibleBound) {
1961 mContext.unbindService(mVisibleConnection);
1962 mVisibleBound = false;
1963 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 mInputShown = false;
1965 mShowRequested = false;
1966 mShowExplicitlyRequested = false;
1967 mShowForced = false;
The Android Open Source Project4df24232009-03-05 14:34:35 -08001968 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001970
satok42c5a162011-05-26 16:46:14 +09001971 @Override
Dianne Hackborn7663d802012-02-24 13:08:49 -08001972 public InputBindResult windowGainedFocus(IInputMethodClient client, IBinder windowToken,
1973 int controlFlags, int softInputMode, int windowFlags,
1974 EditorInfo attribute, IInputContext inputContext) {
Satoshi Kataoka8d033052012-11-19 17:30:40 +09001975 // Needs to check the validity before clearing calling identity
1976 final boolean calledFromValidUser = calledFromValidUser();
1977
Dianne Hackborn7663d802012-02-24 13:08:49 -08001978 InputBindResult res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001979 long ident = Binder.clearCallingIdentity();
1980 try {
1981 synchronized (mMethodMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001982 if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder()
Dianne Hackborn7663d802012-02-24 13:08:49 -08001983 + " controlFlags=#" + Integer.toHexString(controlFlags)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 + " softInputMode=#" + Integer.toHexString(softInputMode)
Dianne Hackborn7663d802012-02-24 13:08:49 -08001985 + " windowFlags=#" + Integer.toHexString(windowFlags));
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001986
Dianne Hackborn7663d802012-02-24 13:08:49 -08001987 ClientState cs = mClients.get(client.asBinder());
1988 if (cs == null) {
1989 throw new IllegalArgumentException("unknown client "
1990 + client.asBinder());
1991 }
1992
1993 try {
1994 if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
1995 // Check with the window manager to make sure this client actually
1996 // has a window with focus. If not, reject. This is thread safe
1997 // because if the focus changes some time before or after, the
1998 // next client receiving focus that has any interest in input will
1999 // be calling through here after that change happens.
2000 Slog.w(TAG, "Focus gain on non-focused client " + cs.client
2001 + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
2002 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002003 }
Dianne Hackborn7663d802012-02-24 13:08:49 -08002004 } catch (RemoteException e) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002005 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002006
Satoshi Kataoka8d033052012-11-19 17:30:40 +09002007 if (!calledFromValidUser) {
2008 Slog.w(TAG, "A background user is requesting window. Hiding IME.");
2009 Slog.w(TAG, "If you want to interect with IME, you need "
2010 + "android.permission.INTERACT_ACROSS_USERS_FULL");
2011 hideCurrentInputLocked(0, null);
2012 return null;
2013 }
2014
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07002015 if (mCurFocusedWindow == windowToken) {
Dianne Hackbornac920872012-05-22 11:49:49 -07002016 Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client
Satoshi Kataoka35739502012-10-02 19:00:26 +09002017 + " attribute=" + attribute + ", token = " + windowToken);
Dianne Hackborn7663d802012-02-24 13:08:49 -08002018 if (attribute != null) {
2019 return startInputUncheckedLocked(cs, inputContext, attribute,
2020 controlFlags);
2021 }
2022 return null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07002023 }
2024 mCurFocusedWindow = windowToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002025
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002026 // Should we auto-show the IME even if the caller has not
2027 // specified what should be done with it?
2028 // We only do this automatically if the window can resize
2029 // to accommodate the IME (so what the user sees will give
2030 // them good context without input information being obscured
2031 // by the IME) or if running on a large screen where there
2032 // is more room for the target window + IME.
2033 final boolean doAutoShow =
2034 (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
2035 == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
2036 || mRes.getConfiguration().isLayoutSizeAtLeast(
2037 Configuration.SCREENLAYOUT_SIZE_LARGE);
Dianne Hackborn7663d802012-02-24 13:08:49 -08002038 final boolean isTextEditor =
2039 (controlFlags&InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0;
2040
2041 // We want to start input before showing the IME, but after closing
2042 // it. We want to do this after closing it to help the IME disappear
2043 // more quickly (not get stuck behind it initializing itself for the
2044 // new focused input, even if its window wants to hide the IME).
2045 boolean didStart = false;
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002047 switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) {
2048 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002049 if (!isTextEditor || !doAutoShow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) {
2051 // There is no focus view, and this window will
2052 // be behind any soft input window, so hide the
2053 // soft input window if it is shown.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002054 if (DEBUG) Slog.v(TAG, "Unspecified window will hide input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08002055 hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 }
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002057 } else if (isTextEditor && doAutoShow && (softInputMode &
2058 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059 // There is a focus view, and we are navigating forward
2060 // into the window, so show the input window for the user.
Dianne Hackborn7663d802012-02-24 13:08:49 -08002061 // We only do this automatically if the window can resize
2062 // to accommodate the IME (so what the user sees will give
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002063 // them good context without input information being obscured
2064 // by the IME) or if running on a large screen where there
2065 // is more room for the target window + IME.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002066 if (DEBUG) Slog.v(TAG, "Unspecified window will show input");
Dianne Hackborn7663d802012-02-24 13:08:49 -08002067 if (attribute != null) {
2068 res = startInputUncheckedLocked(cs, inputContext, attribute,
2069 controlFlags);
2070 didStart = true;
2071 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002072 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 }
2074 break;
2075 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
2076 // Do nothing.
2077 break;
2078 case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN:
2079 if ((softInputMode &
2080 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002081 if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward");
The Android Open Source Project4df24232009-03-05 14:34:35 -08002082 hideCurrentInputLocked(0, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002083 }
2084 break;
2085 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08002086 if (DEBUG) Slog.v(TAG, "Window asks to hide input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08002087 hideCurrentInputLocked(0, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002088 break;
2089 case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
2090 if ((softInputMode &
2091 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002092 if (DEBUG) Slog.v(TAG, "Window asks to show input going forward");
Dianne Hackborn7663d802012-02-24 13:08:49 -08002093 if (attribute != null) {
2094 res = startInputUncheckedLocked(cs, inputContext, attribute,
2095 controlFlags);
2096 didStart = true;
2097 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002098 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002099 }
2100 break;
2101 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
Joe Onorato8a9b2202010-02-26 18:56:32 -08002102 if (DEBUG) Slog.v(TAG, "Window asks to always show input");
Dianne Hackborn7663d802012-02-24 13:08:49 -08002103 if (attribute != null) {
2104 res = startInputUncheckedLocked(cs, inputContext, attribute,
2105 controlFlags);
2106 didStart = true;
2107 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002108 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109 break;
2110 }
Dianne Hackborn7663d802012-02-24 13:08:49 -08002111
2112 if (!didStart && attribute != null) {
2113 res = startInputUncheckedLocked(cs, inputContext, attribute,
2114 controlFlags);
2115 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002116 }
2117 } finally {
2118 Binder.restoreCallingIdentity(ident);
2119 }
Dianne Hackborn7663d802012-02-24 13:08:49 -08002120
2121 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002123
satok42c5a162011-05-26 16:46:14 +09002124 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 public void showInputMethodPickerFromClient(IInputMethodClient client) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002126 if (!calledFromValidUser()) {
2127 return;
2128 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002129 synchronized (mMethodMap) {
2130 if (mCurClient == null || client == null
2131 || mCurClient.client.asBinder() != client.asBinder()) {
satok47a44912010-10-06 16:03:58 +09002132 Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid "
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002133 + Binder.getCallingUid() + ": " + client);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002134 }
2135
satok440aab52010-11-25 09:43:11 +09002136 // Always call subtype picker, because subtype picker is a superset of input method
2137 // picker.
satokab751aa2010-09-14 19:17:36 +09002138 mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER);
2139 }
2140 }
2141
satok42c5a162011-05-26 16:46:14 +09002142 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002143 public void setInputMethod(IBinder token, String id) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002144 if (!calledFromValidUser()) {
2145 return;
2146 }
satok28203512010-11-24 11:06:49 +09002147 setInputMethodWithSubtypeId(token, id, NOT_A_SUBTYPE_ID);
2148 }
2149
satok42c5a162011-05-26 16:46:14 +09002150 @Override
satok28203512010-11-24 11:06:49 +09002151 public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002152 if (!calledFromValidUser()) {
2153 return;
2154 }
satok28203512010-11-24 11:06:49 +09002155 synchronized (mMethodMap) {
2156 if (subtype != null) {
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002157 setInputMethodWithSubtypeIdLocked(token, id,
2158 InputMethodUtils.getSubtypeIdFromHashCode(mMethodMap.get(id),
2159 subtype.hashCode()));
satok28203512010-11-24 11:06:49 +09002160 } else {
2161 setInputMethod(token, id);
2162 }
2163 }
satokab751aa2010-09-14 19:17:36 +09002164 }
2165
satok42c5a162011-05-26 16:46:14 +09002166 @Override
satokb416a712010-11-25 20:42:14 +09002167 public void showInputMethodAndSubtypeEnablerFromClient(
satok217f5482010-12-15 05:19:19 +09002168 IInputMethodClient client, String inputMethodId) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002169 if (!calledFromValidUser()) {
2170 return;
2171 }
satokb416a712010-11-25 20:42:14 +09002172 synchronized (mMethodMap) {
2173 if (mCurClient == null || client == null
2174 || mCurClient.client.asBinder() != client.asBinder()) {
2175 Slog.w(TAG, "Ignoring showInputMethodAndSubtypeEnablerFromClient of: " + client);
2176 }
satok7fee71f2010-12-17 18:54:26 +09002177 executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
2178 MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId));
satokb416a712010-11-25 20:42:14 +09002179 }
2180 }
2181
satok4fc87d62011-05-20 16:13:43 +09002182 @Override
satok735cf382010-11-11 20:40:09 +09002183 public boolean switchToLastInputMethod(IBinder token) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002184 if (!calledFromValidUser()) {
2185 return false;
2186 }
satok735cf382010-11-11 20:40:09 +09002187 synchronized (mMethodMap) {
satokc445bcd2011-01-25 18:57:24 +09002188 final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
satok4fc87d62011-05-20 16:13:43 +09002189 final InputMethodInfo lastImi;
satok208d5632011-05-20 22:13:38 +09002190 if (lastIme != null) {
satok4fc87d62011-05-20 16:13:43 +09002191 lastImi = mMethodMap.get(lastIme.first);
2192 } else {
2193 lastImi = null;
satok735cf382010-11-11 20:40:09 +09002194 }
satok4fc87d62011-05-20 16:13:43 +09002195 String targetLastImiId = null;
2196 int subtypeId = NOT_A_SUBTYPE_ID;
2197 if (lastIme != null && lastImi != null) {
2198 final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId);
2199 final int lastSubtypeHash = Integer.valueOf(lastIme.second);
2200 final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID
2201 : mCurrentSubtype.hashCode();
2202 // If the last IME is the same as the current IME and the last subtype is not
2203 // defined, there is no need to switch to the last IME.
2204 if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) {
2205 targetLastImiId = lastIme.first;
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002206 subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
satok4fc87d62011-05-20 16:13:43 +09002207 }
2208 }
2209
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002210 if (TextUtils.isEmpty(targetLastImiId)
2211 && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) {
satok4fc87d62011-05-20 16:13:43 +09002212 // This is a safety net. If the currentSubtype can't be added to the history
2213 // and the framework couldn't find the last ime, we will make the last ime be
2214 // the most applicable enabled keyboard subtype of the system imes.
2215 final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
2216 if (enabled != null) {
2217 final int N = enabled.size();
2218 final String locale = mCurrentSubtype == null
2219 ? mRes.getConfiguration().locale.toString()
2220 : mCurrentSubtype.getLocale();
2221 for (int i = 0; i < N; ++i) {
2222 final InputMethodInfo imi = enabled.get(i);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002223 if (imi.getSubtypeCount() > 0 && InputMethodUtils.isSystemIme(imi)) {
satok4fc87d62011-05-20 16:13:43 +09002224 InputMethodSubtype keyboardSubtype =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002225 InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes,
2226 InputMethodUtils.getSubtypes(imi),
2227 InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true);
satok4fc87d62011-05-20 16:13:43 +09002228 if (keyboardSubtype != null) {
2229 targetLastImiId = imi.getId();
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002230 subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
satok4fc87d62011-05-20 16:13:43 +09002231 imi, keyboardSubtype.hashCode());
2232 if(keyboardSubtype.getLocale().equals(locale)) {
2233 break;
2234 }
2235 }
2236 }
2237 }
2238 }
2239 }
2240
2241 if (!TextUtils.isEmpty(targetLastImiId)) {
2242 if (DEBUG) {
2243 Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second
2244 + ", from: " + mCurMethodId + ", " + subtypeId);
2245 }
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002246 setInputMethodWithSubtypeIdLocked(token, targetLastImiId, subtypeId);
satok4fc87d62011-05-20 16:13:43 +09002247 return true;
2248 } else {
2249 return false;
2250 }
satok735cf382010-11-11 20:40:09 +09002251 }
2252 }
2253
satoke7c6998e2011-06-03 17:57:59 +09002254 @Override
satok688bd472012-02-09 20:09:17 +09002255 public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002256 if (!calledFromValidUser()) {
2257 return false;
2258 }
satok688bd472012-02-09 20:09:17 +09002259 synchronized (mMethodMap) {
Yohei Yukawaa0755742014-06-04 20:28:18 +09002260 if (!calledWithValidToken(token)) {
2261 final int uid = Binder.getCallingUid();
2262 Slog.e(TAG, "Ignoring switchToNextInputMethod due to an invalid token. uid:" + uid
2263 + " token:" + token);
2264 return false;
2265 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002266 final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
satok688bd472012-02-09 20:09:17 +09002267 onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype);
2268 if (nextSubtype == null) {
2269 return false;
2270 }
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002271 setInputMethodWithSubtypeIdLocked(token, nextSubtype.mImi.getId(),
2272 nextSubtype.mSubtypeId);
satok688bd472012-02-09 20:09:17 +09002273 return true;
2274 }
2275 }
2276
2277 @Override
Satoshi Kataoka2b10b522013-08-21 20:39:12 +09002278 public boolean shouldOfferSwitchingToNextInputMethod(IBinder token) {
2279 if (!calledFromValidUser()) {
2280 return false;
2281 }
2282 synchronized (mMethodMap) {
Yohei Yukawaa0755742014-06-04 20:28:18 +09002283 if (!calledWithValidToken(token)) {
2284 final int uid = Binder.getCallingUid();
2285 Slog.e(TAG, "Ignoring shouldOfferSwitchingToNextInputMethod due to an invalid "
2286 + "token. uid:" + uid + " token:" + token);
2287 return false;
2288 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002289 final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
Satoshi Kataoka2b10b522013-08-21 20:39:12 +09002290 false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype);
2291 if (nextSubtype == null) {
2292 return false;
2293 }
2294 return true;
2295 }
2296 }
2297
2298 @Override
satok68f1b782011-04-11 14:26:04 +09002299 public InputMethodSubtype getLastInputMethodSubtype() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002300 if (!calledFromValidUser()) {
2301 return null;
2302 }
satok68f1b782011-04-11 14:26:04 +09002303 synchronized (mMethodMap) {
2304 final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
2305 // TODO: Handle the case of the last IME with no subtypes
2306 if (lastIme == null || TextUtils.isEmpty(lastIme.first)
2307 || TextUtils.isEmpty(lastIme.second)) return null;
2308 final InputMethodInfo lastImi = mMethodMap.get(lastIme.first);
2309 if (lastImi == null) return null;
2310 try {
2311 final int lastSubtypeHash = Integer.valueOf(lastIme.second);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002312 final int lastSubtypeId =
2313 InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
satok0e7d7d62011-07-05 13:28:06 +09002314 if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) {
2315 return null;
2316 }
2317 return lastImi.getSubtypeAt(lastSubtypeId);
satok68f1b782011-04-11 14:26:04 +09002318 } catch (NumberFormatException e) {
2319 return null;
2320 }
2321 }
2322 }
2323
satoke7c6998e2011-06-03 17:57:59 +09002324 @Override
satokee5e77c2011-09-02 18:50:15 +09002325 public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002326 if (!calledFromValidUser()) {
2327 return;
2328 }
satok91e88122011-07-18 11:11:42 +09002329 // By this IPC call, only a process which shares the same uid with the IME can add
2330 // additional input method subtypes to the IME.
satokee5e77c2011-09-02 18:50:15 +09002331 if (TextUtils.isEmpty(imiId) || subtypes == null || subtypes.length == 0) return;
satoke7c6998e2011-06-03 17:57:59 +09002332 synchronized (mMethodMap) {
satok91e88122011-07-18 11:11:42 +09002333 final InputMethodInfo imi = mMethodMap.get(imiId);
satokee5e77c2011-09-02 18:50:15 +09002334 if (imi == null) return;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002335 final String[] packageInfos;
2336 try {
2337 packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid());
2338 } catch (RemoteException e) {
2339 Slog.e(TAG, "Failed to get package infos");
2340 return;
2341 }
satok91e88122011-07-18 11:11:42 +09002342 if (packageInfos != null) {
2343 final int packageNum = packageInfos.length;
2344 for (int i = 0; i < packageNum; ++i) {
2345 if (packageInfos[i].equals(imi.getPackageName())) {
2346 mFileManager.addInputMethodSubtypes(imi, subtypes);
satokc5933802011-08-31 21:26:04 +09002347 final long ident = Binder.clearCallingIdentity();
2348 try {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09002349 buildInputMethodListLocked(mMethodList, mMethodMap,
2350 false /* resetDefaultEnabledIme */);
satokc5933802011-08-31 21:26:04 +09002351 } finally {
2352 Binder.restoreCallingIdentity(ident);
2353 }
satokee5e77c2011-09-02 18:50:15 +09002354 return;
satok91e88122011-07-18 11:11:42 +09002355 }
2356 }
2357 }
satoke7c6998e2011-06-03 17:57:59 +09002358 }
satokee5e77c2011-09-02 18:50:15 +09002359 return;
satoke7c6998e2011-06-03 17:57:59 +09002360 }
2361
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09002362 @Override
2363 public int getInputMethodWindowVisibleHeight() {
2364 return mWindowManagerService.getInputMethodWindowVisibleHeight();
2365 }
2366
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002367 @Override
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002368 public void notifyUserAction(int sequenceNumber) {
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002369 if (DEBUG) {
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002370 Slog.d(TAG, "Got the notification of a user action. sequenceNumber:" + sequenceNumber);
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002371 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002372 synchronized (mMethodMap) {
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002373 if (mCurUserActionNotificationSequenceNumber != sequenceNumber) {
2374 if (DEBUG) {
2375 Slog.d(TAG, "Ignoring the user action notification due to the sequence number "
2376 + "mismatch. expected:" + mCurUserActionNotificationSequenceNumber
2377 + " actual: " + sequenceNumber);
2378 }
2379 return;
2380 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002381 final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
2382 if (imi != null) {
Yohei Yukawa02970512014-06-05 16:16:18 +09002383 mSwitchingController.onUserActionLocked(imi, mCurrentSubtype);
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002384 }
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002385 }
2386 }
2387
satok28203512010-11-24 11:06:49 +09002388 private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002389 synchronized (mMethodMap) {
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002390 setInputMethodWithSubtypeIdLocked(token, id, subtypeId);
2391 }
2392 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002394 private void setInputMethodWithSubtypeIdLocked(IBinder token, String id, int subtypeId) {
2395 if (token == null) {
2396 if (mContext.checkCallingOrSelfPermission(
2397 android.Manifest.permission.WRITE_SECURE_SETTINGS)
2398 != PackageManager.PERMISSION_GRANTED) {
2399 throw new SecurityException(
2400 "Using null token requires permission "
2401 + android.Manifest.permission.WRITE_SECURE_SETTINGS);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 }
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002403 } else if (mCurToken != token) {
2404 Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid()
2405 + " token: " + token);
2406 return;
2407 }
2408
2409 final long ident = Binder.clearCallingIdentity();
2410 try {
2411 setInputMethodLocked(id, subtypeId);
2412 } finally {
2413 Binder.restoreCallingIdentity(ident);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002414 }
2415 }
2416
satok42c5a162011-05-26 16:46:14 +09002417 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 public void hideMySoftInput(IBinder token, int flags) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002419 if (!calledFromValidUser()) {
2420 return;
2421 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 synchronized (mMethodMap) {
Yohei Yukawa22c97be2014-06-04 19:43:36 +09002423 if (!calledWithValidToken(token)) {
2424 final int uid = Binder.getCallingUid();
2425 Slog.e(TAG, "Ignoring hideInputMethod due to an invalid token. uid:"
2426 + uid + " token:" + token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 return;
2428 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002429 long ident = Binder.clearCallingIdentity();
2430 try {
The Android Open Source Project4df24232009-03-05 14:34:35 -08002431 hideCurrentInputLocked(flags, null);
2432 } finally {
2433 Binder.restoreCallingIdentity(ident);
2434 }
2435 }
2436 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002437
satok42c5a162011-05-26 16:46:14 +09002438 @Override
The Android Open Source Project4df24232009-03-05 14:34:35 -08002439 public void showMySoftInput(IBinder token, int flags) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002440 if (!calledFromValidUser()) {
2441 return;
2442 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002443 synchronized (mMethodMap) {
Yohei Yukawa22c97be2014-06-04 19:43:36 +09002444 if (!calledWithValidToken(token)) {
2445 final int uid = Binder.getCallingUid();
2446 Slog.e(TAG, "Ignoring showMySoftInput due to an invalid token. uid:"
2447 + uid + " token:" + token);
The Android Open Source Project4df24232009-03-05 14:34:35 -08002448 return;
2449 }
2450 long ident = Binder.clearCallingIdentity();
2451 try {
2452 showCurrentInputLocked(flags, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 } finally {
2454 Binder.restoreCallingIdentity(ident);
2455 }
2456 }
2457 }
2458
2459 void setEnabledSessionInMainThread(SessionState session) {
2460 if (mEnabledSession != session) {
Yohei Yukawa9d91b432014-05-19 16:03:24 +09002461 if (mEnabledSession != null && mEnabledSession.session != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002463 if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession);
Yohei Yukawa9d91b432014-05-19 16:03:24 +09002464 mEnabledSession.method.setSessionEnabled(mEnabledSession.session, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 } catch (RemoteException e) {
2466 }
2467 }
2468 mEnabledSession = session;
Yohei Yukawa9d91b432014-05-19 16:03:24 +09002469 if (mEnabledSession != null && mEnabledSession.session != null) {
2470 try {
2471 if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession);
2472 mEnabledSession.method.setSessionEnabled(mEnabledSession.session, true);
2473 } catch (RemoteException e) {
2474 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 }
2476 }
2477 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002478
satok42c5a162011-05-26 16:46:14 +09002479 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 public boolean handleMessage(Message msg) {
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002481 SomeArgs args;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 switch (msg.what) {
2483 case MSG_SHOW_IM_PICKER:
2484 showInputMethodMenu();
2485 return true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002486
satokab751aa2010-09-14 19:17:36 +09002487 case MSG_SHOW_IM_SUBTYPE_PICKER:
2488 showInputMethodSubtypeMenu();
2489 return true;
2490
satok47a44912010-10-06 16:03:58 +09002491 case MSG_SHOW_IM_SUBTYPE_ENABLER:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002492 args = (SomeArgs)msg.obj;
satok7fee71f2010-12-17 18:54:26 +09002493 showInputMethodAndSubtypeEnabler((String)args.arg1);
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002494 args.recycle();
satok217f5482010-12-15 05:19:19 +09002495 return true;
2496
2497 case MSG_SHOW_IM_CONFIG:
2498 showConfigureInputMethods();
satok47a44912010-10-06 16:03:58 +09002499 return true;
2500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 case MSG_UNBIND_INPUT:
2504 try {
2505 ((IInputMethod)msg.obj).unbindInput();
2506 } catch (RemoteException e) {
2507 // There is nothing interesting about the method dying.
2508 }
2509 return true;
2510 case MSG_BIND_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002511 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 try {
2513 ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2);
2514 } catch (RemoteException e) {
2515 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002516 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 return true;
2518 case MSG_SHOW_SOFT_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002519 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002520 try {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002521 if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput("
Craig Mautner6efb4c72013-03-13 10:17:41 -07002522 + msg.arg1 + ", " + args.arg2 + ")");
Craig Mautnerca0ac712013-03-14 09:43:02 -07002523 ((IInputMethod)args.arg1).showSoftInput(msg.arg1, (ResultReceiver)args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 } catch (RemoteException e) {
2525 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002526 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 return true;
2528 case MSG_HIDE_SOFT_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002529 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 try {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002531 if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, "
Craig Mautner6efb4c72013-03-13 10:17:41 -07002532 + args.arg2 + ")");
Craig Mautnerca0ac712013-03-14 09:43:02 -07002533 ((IInputMethod)args.arg1).hideSoftInput(0, (ResultReceiver)args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 } catch (RemoteException e) {
2535 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002536 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 return true;
2538 case MSG_ATTACH_TOKEN:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002539 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 try {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002541 if (DEBUG) Slog.v(TAG, "Sending attach of token: " + args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2);
2543 } catch (RemoteException e) {
2544 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002545 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002546 return true;
Jeff Brownc28867a2013-03-26 15:42:39 -07002547 case MSG_CREATE_SESSION: {
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002548 args = (SomeArgs)msg.obj;
Jeff Brown1951ce82013-04-04 22:45:12 -07002549 IInputMethod method = (IInputMethod)args.arg1;
Jeff Brownc28867a2013-03-26 15:42:39 -07002550 InputChannel channel = (InputChannel)args.arg2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 try {
Jeff Brown1951ce82013-04-04 22:45:12 -07002552 method.createSession(channel, (IInputSessionCallback)args.arg3);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 } catch (RemoteException e) {
Jeff Brownc28867a2013-03-26 15:42:39 -07002554 } finally {
Jeff Brown1951ce82013-04-04 22:45:12 -07002555 // Dispose the channel if the input method is not local to this process
2556 // because the remote proxy will get its own copy when unparceled.
2557 if (channel != null && Binder.isProxy(method)) {
Jeff Brownc28867a2013-03-26 15:42:39 -07002558 channel.dispose();
2559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002561 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 return true;
Jeff Brownc28867a2013-03-26 15:42:39 -07002563 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002566 case MSG_START_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002567 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 try {
2569 SessionState session = (SessionState)args.arg1;
2570 setEnabledSessionInMainThread(session);
2571 session.method.startInput((IInputContext)args.arg2,
2572 (EditorInfo)args.arg3);
2573 } catch (RemoteException e) {
2574 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002575 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 return true;
2577 case MSG_RESTART_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002578 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579 try {
2580 SessionState session = (SessionState)args.arg1;
2581 setEnabledSessionInMainThread(session);
2582 session.method.restartInput((IInputContext)args.arg2,
2583 (EditorInfo)args.arg3);
2584 } catch (RemoteException e) {
2585 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002586 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 return true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002591 case MSG_UNBIND_METHOD:
2592 try {
2593 ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1);
2594 } catch (RemoteException e) {
2595 // There is nothing interesting about the last client dying.
2596 }
2597 return true;
Jeff Brown1951ce82013-04-04 22:45:12 -07002598 case MSG_BIND_METHOD: {
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002599 args = (SomeArgs)msg.obj;
Jeff Brown1951ce82013-04-04 22:45:12 -07002600 IInputMethodClient client = (IInputMethodClient)args.arg1;
2601 InputBindResult res = (InputBindResult)args.arg2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002602 try {
Jeff Brown1951ce82013-04-04 22:45:12 -07002603 client.onBindMethod(res);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002605 Slog.w(TAG, "Client died receiving input method " + args.arg2);
Jeff Brown1951ce82013-04-04 22:45:12 -07002606 } finally {
2607 // Dispose the channel if the input method is not local to this process
2608 // because the remote proxy will get its own copy when unparceled.
2609 if (res.channel != null && Binder.isProxy(client)) {
2610 res.channel.dispose();
2611 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002612 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002613 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 return true;
Jeff Brown1951ce82013-04-04 22:45:12 -07002615 }
Dianne Hackborna6e41342012-05-22 16:30:34 -07002616 case MSG_SET_ACTIVE:
2617 try {
2618 ((ClientState)msg.obj).client.setActive(msg.arg1 != 0);
2619 } catch (RemoteException e) {
2620 Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid "
2621 + ((ClientState)msg.obj).pid + " uid "
2622 + ((ClientState)msg.obj).uid);
2623 }
2624 return true;
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002625 case MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER: {
2626 final int sequenceNumber = msg.arg1;
Yohei Yukawa080fa342014-08-31 16:10:05 -07002627 final ClientState clientState = (ClientState)msg.obj;
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002628 try {
Yohei Yukawa080fa342014-08-31 16:10:05 -07002629 clientState.client.setUserActionNotificationSequenceNumber(sequenceNumber);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002630 } catch (RemoteException e) {
2631 Slog.w(TAG, "Got RemoteException sending "
2632 + "setUserActionNotificationSequenceNumber("
2633 + sequenceNumber + ") notification to pid "
Yohei Yukawa080fa342014-08-31 16:10:05 -07002634 + clientState.pid + " uid "
2635 + clientState.uid);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002636 }
2637 return true;
2638 }
satok01038492012-04-09 21:08:27 +09002639
2640 // --------------------------------------------------------------
2641 case MSG_HARD_KEYBOARD_SWITCH_CHANGED:
Michael Wright7b5a96b2014-08-09 19:28:42 -07002642 mHardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1);
satok01038492012-04-09 21:08:27 +09002643 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644 }
2645 return false;
2646 }
2647
satokdc9ddae2011-10-06 12:22:36 +09002648 private boolean chooseNewDefaultIMELocked() {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002649 final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME(
2650 mSettings.getEnabledInputMethodListLocked());
satokdc9ddae2011-10-06 12:22:36 +09002651 if (imi != null) {
satok03eb319a2010-11-11 18:17:42 +09002652 if (DEBUG) {
2653 Slog.d(TAG, "New default IME was selected: " + imi.getId());
2654 }
satok723a27e2010-11-11 14:58:11 +09002655 resetSelectedInputMethodAndSubtypeLocked(imi.getId());
Brandon Ballinger6da35a02009-10-21 00:38:13 -07002656 return true;
2657 }
2658
2659 return false;
2660 }
2661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002662 void buildInputMethodListLocked(ArrayList<InputMethodInfo> list,
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09002663 HashMap<String, InputMethodInfo> map, boolean resetDefaultEnabledIme) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002664 if (DEBUG) {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09002665 Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme
Satoshi Kataoka0766eb02013-07-31 18:30:13 +09002666 + " \n ------ \n" + InputMethodUtils.getStackTrace());
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002667 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 list.clear();
2669 map.clear();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002670
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002671 // Use for queryIntentServicesAsUser
2672 final PackageManager pm = mContext.getPackageManager();
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002673 String disabledSysImes = mSettings.getDisabledSystemInputMethods();
Amith Yamasanie861ec12010-03-24 21:39:27 -07002674 if (disabledSysImes == null) disabledSysImes = "";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002675
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002676 final List<ResolveInfo> services = pm.queryIntentServicesAsUser(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002677 new Intent(InputMethod.SERVICE_INTERFACE),
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08002678 PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
2679 mSettings.getCurrentUserId());
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002680
satoke7c6998e2011-06-03 17:57:59 +09002681 final HashMap<String, List<InputMethodSubtype>> additionalSubtypes =
2682 mFileManager.getAllAdditionalInputMethodSubtypes();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002683 for (int i = 0; i < services.size(); ++i) {
2684 ResolveInfo ri = services.get(i);
2685 ServiceInfo si = ri.serviceInfo;
2686 ComponentName compName = new ComponentName(si.packageName, si.name);
2687 if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(
2688 si.permission)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002689 Slog.w(TAG, "Skipping input method " + compName
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 + ": it does not require the permission "
2691 + android.Manifest.permission.BIND_INPUT_METHOD);
2692 continue;
2693 }
2694
Joe Onorato8a9b2202010-02-26 18:56:32 -08002695 if (DEBUG) Slog.d(TAG, "Checking " + compName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002696
2697 try {
satoke7c6998e2011-06-03 17:57:59 +09002698 InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002699 list.add(p);
Amith Yamasanie861ec12010-03-24 21:39:27 -07002700 final String id = p.getId();
2701 map.put(id, p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702
2703 if (DEBUG) {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09002704 Slog.d(TAG, "Found an input method " + p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002705 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 } catch (XmlPullParserException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002708 Slog.w(TAG, "Unable to load input method " + compName, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002710 Slog.w(TAG, "Unable to load input method " + compName, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 }
2712 }
Brandon Ballinger6da35a02009-10-21 00:38:13 -07002713
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09002714 if (resetDefaultEnabledIme) {
2715 final ArrayList<InputMethodInfo> defaultEnabledIme =
2716 InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, list);
2717 for (int i = 0; i < defaultEnabledIme.size(); ++i) {
2718 final InputMethodInfo imi = defaultEnabledIme.get(i);
2719 if (DEBUG) {
2720 Slog.d(TAG, "--- enable ime = " + imi);
2721 }
2722 setInputMethodEnabledLocked(imi.getId(), true);
2723 }
2724 }
2725
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002726 final String defaultImiId = mSettings.getSelectedInputMethod();
satok0a1bcf42012-05-16 19:26:31 +09002727 if (!TextUtils.isEmpty(defaultImiId)) {
2728 if (!map.containsKey(defaultImiId)) {
2729 Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
2730 if (chooseNewDefaultIMELocked()) {
Michael Wright7b5a96b2014-08-09 19:28:42 -07002731 updateInputMethodsFromSettingsLocked(true);
satok0a1bcf42012-05-16 19:26:31 +09002732 }
2733 } else {
2734 // Double check that the default IME is certainly enabled.
2735 setInputMethodEnabledLocked(defaultImiId, true);
Brandon Ballinger6da35a02009-10-21 00:38:13 -07002736 }
2737 }
Yohei Yukawa3d46bab2014-05-30 18:10:18 +09002738 // Here is not the perfect place to reset the switching controller. Ideally
2739 // mSwitchingController and mSettings should be able to share the same state.
2740 // TODO: Make sure that mSwitchingController and mSettings are sharing the
2741 // the same enabled IMEs list.
Yohei Yukawac834a252014-05-21 22:42:32 +09002742 mSwitchingController.resetCircularListLocked(mContext);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002745 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002746
satokab751aa2010-09-14 19:17:36 +09002747 private void showInputMethodMenu() {
2748 showInputMethodMenuInternal(false);
2749 }
2750
2751 private void showInputMethodSubtypeMenu() {
2752 showInputMethodMenuInternal(true);
2753 }
2754
satok217f5482010-12-15 05:19:19 +09002755 private void showInputMethodAndSubtypeEnabler(String inputMethodId) {
Tadashi G. Takaokaf49688f2011-01-20 17:56:13 +09002756 Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
satok47a44912010-10-06 16:03:58 +09002757 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
satok86417ea2010-10-27 14:11:03 +09002758 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
2759 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
satok7fee71f2010-12-17 18:54:26 +09002760 if (!TextUtils.isEmpty(inputMethodId)) {
Tadashi G. Takaoka25480202011-01-20 23:13:02 +09002761 intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId);
satok7fee71f2010-12-17 18:54:26 +09002762 }
Satoshi Kataoka3ba439d2012-10-05 18:30:13 +09002763 mContext.startActivityAsUser(intent, null, UserHandle.CURRENT);
satok217f5482010-12-15 05:19:19 +09002764 }
2765
2766 private void showConfigureInputMethods() {
2767 Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
2768 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2769 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
2770 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Satoshi Kataoka3ba439d2012-10-05 18:30:13 +09002771 mContext.startActivityAsUser(intent, null, UserHandle.CURRENT);
satok47a44912010-10-06 16:03:58 +09002772 }
2773
satok2c93efc2012-04-02 19:33:47 +09002774 private boolean isScreenLocked() {
2775 return mKeyguardManager != null
2776 && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure();
2777 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002778
satokab751aa2010-09-14 19:17:36 +09002779 private void showInputMethodMenuInternal(boolean showSubtypes) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002780 if (DEBUG) Slog.v(TAG, "Show switching menu");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002782 final Context context = mContext;
satok2c93efc2012-04-02 19:33:47 +09002783 final boolean isScreenLocked = isScreenLocked();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002784
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002785 final String lastInputMethodId = mSettings.getSelectedInputMethod();
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002786 int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
Joe Onorato8a9b2202010-02-26 18:56:32 -08002787 if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002788
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002789 synchronized (mMethodMap) {
satokbb4aa062011-01-19 21:40:27 +09002790 final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis =
Satoshi Kataokad787f692013-10-26 04:44:21 +09002791 mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(
2792 mContext);
satok7f35c8c2010-10-07 21:13:11 +09002793 if (immis == null || immis.size() == 0) {
2794 return;
2795 }
2796
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002797 hideInputMethodMenuLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798
satok688bd472012-02-09 20:09:17 +09002799 final List<ImeSubtypeListItem> imList =
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002800 mSwitchingController.getSortedInputMethodAndSubtypeListLocked(
satok688bd472012-02-09 20:09:17 +09002801 showSubtypes, mInputShown, isScreenLocked);
satok913a8922010-08-26 21:53:41 +09002802
satokc3690562012-01-10 20:14:43 +09002803 if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002804 final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
satokc3690562012-01-10 20:14:43 +09002805 if (currentSubtype != null) {
2806 final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002807 lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
2808 currentImi, currentSubtype.hashCode());
satokc3690562012-01-10 20:14:43 +09002809 }
2810 }
2811
Ken Wakasa761eb372011-03-04 19:06:18 +09002812 final int N = imList.size();
satokab751aa2010-09-14 19:17:36 +09002813 mIms = new InputMethodInfo[N];
2814 mSubtypeIds = new int[N];
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002815 int checkedItem = 0;
2816 for (int i = 0; i < N; ++i) {
Ken Wakasa05dbb652011-08-22 15:22:43 +09002817 final ImeSubtypeListItem item = imList.get(i);
2818 mIms[i] = item.mImi;
2819 mSubtypeIds[i] = item.mSubtypeId;
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002820 if (mIms[i].getId().equals(lastInputMethodId)) {
satokab751aa2010-09-14 19:17:36 +09002821 int subtypeId = mSubtypeIds[i];
2822 if ((subtypeId == NOT_A_SUBTYPE_ID)
2823 || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0)
2824 || (subtypeId == lastInputMethodSubtypeId)) {
2825 checkedItem = i;
2826 }
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002829 final Context themedContext = new ContextThemeWrapper(context,
2830 android.R.style.Theme_DeviceDefault_Settings);
2831 mDialogBuilder = new AlertDialog.Builder(themedContext);
2832 final TypedArray a = themedContext.obtainStyledAttributes(null,
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002833 com.android.internal.R.styleable.DialogPreference,
2834 com.android.internal.R.attr.alertDialogStyle, 0);
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002835 mDialogBuilder.setIcon(a.getDrawable(
2836 com.android.internal.R.styleable.DialogPreference_dialogIcon));
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07002837 a.recycle();
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002838 mDialogBuilder.setOnCancelListener(new OnCancelListener() {
2839 @Override
2840 public void onCancel(DialogInterface dialog) {
2841 hideInputMethodMenu();
2842 }
2843 });
satok01038492012-04-09 21:08:27 +09002844 final LayoutInflater inflater =
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002845 (LayoutInflater)themedContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
satok01038492012-04-09 21:08:27 +09002846 final View tv = inflater.inflate(
2847 com.android.internal.R.layout.input_method_switch_dialog_title, null);
2848 mDialogBuilder.setCustomTitle(tv);
2849
2850 // Setup layout for a toggle switch of the hardware keyboard
2851 mSwitchingDialogTitleView = tv;
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002852 mSwitchingDialogTitleView
2853 .findViewById(com.android.internal.R.id.hard_keyboard_section)
2854 .setVisibility(mWindowManagerService.isHardKeyboardAvailable()
2855 ? View.VISIBLE : View.GONE);
2856 final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById(
2857 com.android.internal.R.id.hard_keyboard_switch);
Michael Wright7b5a96b2014-08-09 19:28:42 -07002858 hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002859 hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
2860 @Override
2861 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Michael Wright7b5a96b2014-08-09 19:28:42 -07002862 mSettings.setShowImeWithHardKeyboard(isChecked);
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002863 // Ensure that the input method dialog is dismissed when changing
2864 // the hardware keyboard state.
2865 hideInputMethodMenu();
2866 }
2867 });
2868
2869 final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(themedContext,
2870 com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
2871 final OnClickListener choiceListener = new OnClickListener() {
2872 @Override
2873 public void onClick(final DialogInterface dialog, final int which) {
2874 synchronized (mMethodMap) {
2875 if (mIms == null || mIms.length <= which || mSubtypeIds == null
2876 || mSubtypeIds.length <= which) {
2877 return;
satok01038492012-04-09 21:08:27 +09002878 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002879 final InputMethodInfo im = mIms[which];
2880 int subtypeId = mSubtypeIds[which];
2881 adapter.mCheckedItem = which;
2882 adapter.notifyDataSetChanged();
2883 hideInputMethodMenu();
2884 if (im != null) {
2885 if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) {
2886 subtypeId = NOT_A_SUBTYPE_ID;
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08002887 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002888 setInputMethodLocked(im.getId(), subtypeId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002890 }
2891 }
2892 };
2893 mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894
satokbc81b692011-08-26 16:22:22 +09002895 if (showSubtypes && !isScreenLocked) {
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002896 final OnClickListener positiveListener = new OnClickListener() {
2897 @Override
2898 public void onClick(DialogInterface dialog, int whichButton) {
2899 showConfigureInputMethods();
2900 }
2901 };
satok82beadf2010-12-27 19:03:06 +09002902 mDialogBuilder.setPositiveButton(
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09002903 com.android.internal.R.string.configure_input_methods, positiveListener);
satok7f35c8c2010-10-07 21:13:11 +09002904 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002905 mSwitchingDialog = mDialogBuilder.create();
Dianne Hackborne3a7f622011-03-03 21:48:24 -08002906 mSwitchingDialog.setCanceledOnTouchOutside(true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 mSwitchingDialog.getWindow().setType(
2908 WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
Satoshi Kataokac86884c2012-10-09 15:20:29 +09002909 mSwitchingDialog.getWindow().getAttributes().privateFlags |=
2910 WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborne3a7f622011-03-03 21:48:24 -08002911 mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
Jason Monk807ef762014-05-08 15:47:46 -04002912 updateImeWindowStatusLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002913 mSwitchingDialog.show();
2914 }
2915 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002916
Ken Wakasa05dbb652011-08-22 15:22:43 +09002917 private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> {
2918 private final LayoutInflater mInflater;
2919 private final int mTextViewResourceId;
2920 private final List<ImeSubtypeListItem> mItemsList;
Satoshi Kataokad2142962012-11-12 18:43:06 +09002921 public int mCheckedItem;
Ken Wakasa05dbb652011-08-22 15:22:43 +09002922 public ImeSubtypeListAdapter(Context context, int textViewResourceId,
2923 List<ImeSubtypeListItem> itemsList, int checkedItem) {
2924 super(context, textViewResourceId, itemsList);
2925 mTextViewResourceId = textViewResourceId;
2926 mItemsList = itemsList;
2927 mCheckedItem = checkedItem;
2928 mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
2929 }
2930
2931 @Override
2932 public View getView(int position, View convertView, ViewGroup parent) {
2933 final View view = convertView != null ? convertView
2934 : mInflater.inflate(mTextViewResourceId, null);
2935 if (position < 0 || position >= mItemsList.size()) return view;
2936 final ImeSubtypeListItem item = mItemsList.get(position);
2937 final CharSequence imeName = item.mImeName;
2938 final CharSequence subtypeName = item.mSubtypeName;
2939 final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1);
2940 final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2);
2941 if (TextUtils.isEmpty(subtypeName)) {
2942 firstTextView.setText(imeName);
2943 secondTextView.setVisibility(View.GONE);
2944 } else {
2945 firstTextView.setText(subtypeName);
2946 secondTextView.setText(imeName);
2947 secondTextView.setVisibility(View.VISIBLE);
2948 }
2949 final RadioButton radioButton =
2950 (RadioButton)view.findViewById(com.android.internal.R.id.radio);
2951 radioButton.setChecked(position == mCheckedItem);
2952 return view;
2953 }
2954 }
2955
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 void hideInputMethodMenu() {
The Android Open Source Project10592532009-03-18 17:39:46 -07002957 synchronized (mMethodMap) {
2958 hideInputMethodMenuLocked();
2959 }
2960 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002961
The Android Open Source Project10592532009-03-18 17:39:46 -07002962 void hideInputMethodMenuLocked() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002963 if (DEBUG) Slog.v(TAG, "Hide switching menu");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964
The Android Open Source Project10592532009-03-18 17:39:46 -07002965 if (mSwitchingDialog != null) {
2966 mSwitchingDialog.dismiss();
2967 mSwitchingDialog = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002969
Jason Monk807ef762014-05-08 15:47:46 -04002970 updateImeWindowStatusLocked();
The Android Open Source Project10592532009-03-18 17:39:46 -07002971 mDialogBuilder = null;
The Android Open Source Project10592532009-03-18 17:39:46 -07002972 mIms = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002976
satok42c5a162011-05-26 16:46:14 +09002977 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 public boolean setInputMethodEnabled(String id, boolean enabled) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002979 // TODO: Make this work even for non-current users?
2980 if (!calledFromValidUser()) {
2981 return false;
2982 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 synchronized (mMethodMap) {
2984 if (mContext.checkCallingOrSelfPermission(
2985 android.Manifest.permission.WRITE_SECURE_SETTINGS)
2986 != PackageManager.PERMISSION_GRANTED) {
2987 throw new SecurityException(
2988 "Requires permission "
2989 + android.Manifest.permission.WRITE_SECURE_SETTINGS);
2990 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 long ident = Binder.clearCallingIdentity();
2993 try {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08002994 return setInputMethodEnabledLocked(id, enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 } finally {
2996 Binder.restoreCallingIdentity(ident);
2997 }
2998 }
2999 }
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003000
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003001 boolean setInputMethodEnabledLocked(String id, boolean enabled) {
3002 // Make sure this is a valid input method.
3003 InputMethodInfo imm = mMethodMap.get(id);
3004 if (imm == null) {
satokd87c2592010-09-29 11:52:06 +09003005 throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003006 }
3007
satokd87c2592010-09-29 11:52:06 +09003008 List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings
3009 .getEnabledInputMethodsAndSubtypeListLocked();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003010
satokd87c2592010-09-29 11:52:06 +09003011 if (enabled) {
3012 for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) {
3013 if (pair.first.equals(id)) {
3014 // We are enabling this input method, but it is already enabled.
3015 // Nothing to do. The previous state was enabled.
3016 return true;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003017 }
3018 }
satokd87c2592010-09-29 11:52:06 +09003019 mSettings.appendAndPutEnabledInputMethodLocked(id, false);
3020 // Previous state was disabled.
3021 return false;
3022 } else {
3023 StringBuilder builder = new StringBuilder();
3024 if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked(
3025 builder, enabledInputMethodsList, id)) {
3026 // Disabled input method is currently selected, switch to another one.
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003027 final String selId = mSettings.getSelectedInputMethod();
satok03eb319a2010-11-11 18:17:42 +09003028 if (id.equals(selId) && !chooseNewDefaultIMELocked()) {
3029 Slog.i(TAG, "Can't find new IME, unsetting the current input method.");
3030 resetSelectedInputMethodAndSubtypeLocked("");
satokd87c2592010-09-29 11:52:06 +09003031 }
3032 // Previous state was enabled.
3033 return true;
3034 } else {
3035 // We are disabling the input method but it is already disabled.
3036 // Nothing to do. The previous state was disabled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003037 return false;
3038 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003039 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003040 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08003041
satok723a27e2010-11-11 14:58:11 +09003042 private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId,
3043 boolean setSubtypeOnly) {
3044 // Update the history of InputMethod and Subtype
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003045 mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype);
satok723a27e2010-11-11 14:58:11 +09003046
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09003047 mCurUserActionNotificationSequenceNumber =
3048 Math.max(mCurUserActionNotificationSequenceNumber + 1, 1);
3049 if (DEBUG) {
3050 Slog.d(TAG, "Bump mCurUserActionNotificationSequenceNumber:"
3051 + mCurUserActionNotificationSequenceNumber);
3052 }
3053
3054 if (mCurClient != null && mCurClient.client != null) {
3055 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
3056 MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER,
Yohei Yukawa080fa342014-08-31 16:10:05 -07003057 mCurUserActionNotificationSequenceNumber, mCurClient));
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09003058 }
3059
satok723a27e2010-11-11 14:58:11 +09003060 // Set Subtype here
3061 if (imi == null || subtypeId < 0) {
3062 mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
Tadashi G. Takaoka0ba75bb2010-11-09 12:19:32 -08003063 mCurrentSubtype = null;
satok723a27e2010-11-11 14:58:11 +09003064 } else {
Ken Wakasa586f0512011-01-20 22:31:01 +09003065 if (subtypeId < imi.getSubtypeCount()) {
3066 InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId);
3067 mSettings.putSelectedSubtype(subtype.hashCode());
3068 mCurrentSubtype = subtype;
satok723a27e2010-11-11 14:58:11 +09003069 } else {
3070 mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
satokd81e9502012-05-21 12:58:45 +09003071 // If the subtype is not specified, choose the most applicable one
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003072 mCurrentSubtype = getCurrentInputMethodSubtypeLocked();
satok723a27e2010-11-11 14:58:11 +09003073 }
satokab751aa2010-09-14 19:17:36 +09003074 }
satok723a27e2010-11-11 14:58:11 +09003075
satok4c0e7152012-06-20 20:08:44 +09003076 // Workaround.
3077 // ASEC is not ready in the IMMS constructor. Accordingly, forward-locked
3078 // IMEs are not recognized and considered uninstalled.
3079 // Actually, we can't move everything after SystemReady because
3080 // IMMS needs to run in the encryption lock screen. So, we just skip changing
3081 // the default IME here and try cheking the default IME again in systemReady().
3082 // TODO: Do nothing before system ready and implement a separated logic for
3083 // the encryption lock screen.
3084 // TODO: ASEC should be ready before IMMS is instantiated.
3085 if (mSystemReady && !setSubtypeOnly) {
satok723a27e2010-11-11 14:58:11 +09003086 // Set InputMethod here
3087 mSettings.putSelectedInputMethod(imi != null ? imi.getId() : "");
3088 }
3089 }
3090
3091 private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) {
3092 InputMethodInfo imi = mMethodMap.get(newDefaultIme);
3093 int lastSubtypeId = NOT_A_SUBTYPE_ID;
3094 // newDefaultIme is empty when there is no candidate for the selected IME.
3095 if (imi != null && !TextUtils.isEmpty(newDefaultIme)) {
3096 String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme);
3097 if (subtypeHashCode != null) {
3098 try {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003099 lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
satok723a27e2010-11-11 14:58:11 +09003100 imi, Integer.valueOf(subtypeHashCode));
3101 } catch (NumberFormatException e) {
3102 Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e);
3103 }
3104 }
3105 }
3106 setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false);
satokab751aa2010-09-14 19:17:36 +09003107 }
3108
satok4e4569d2010-11-19 18:45:53 +09003109 // If there are no selected shortcuts, tries finding the most applicable ones.
3110 private Pair<InputMethodInfo, InputMethodSubtype>
3111 findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) {
3112 List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
3113 InputMethodInfo mostApplicableIMI = null;
satokcd7cd292010-11-20 15:46:23 +09003114 InputMethodSubtype mostApplicableSubtype = null;
satok4e4569d2010-11-19 18:45:53 +09003115 boolean foundInSystemIME = false;
3116
3117 // Search applicable subtype for each InputMethodInfo
3118 for (InputMethodInfo imi: imis) {
satok7599a7f2010-12-22 13:45:23 +09003119 final String imiId = imi.getId();
3120 if (foundInSystemIME && !imiId.equals(mCurMethodId)) {
3121 continue;
3122 }
satokcd7cd292010-11-20 15:46:23 +09003123 InputMethodSubtype subtype = null;
satokdf31ae62011-01-15 06:19:44 +09003124 final List<InputMethodSubtype> enabledSubtypes =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003125 mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
satokdf31ae62011-01-15 06:19:44 +09003126 // 1. Search by the current subtype's locale from enabledSubtypes.
satok4e4569d2010-11-19 18:45:53 +09003127 if (mCurrentSubtype != null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003128 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satokdf31ae62011-01-15 06:19:44 +09003129 mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false);
satok4e4569d2010-11-19 18:45:53 +09003130 }
satokdf31ae62011-01-15 06:19:44 +09003131 // 2. Search by the system locale from enabledSubtypes.
3132 // 3. Search the first enabled subtype matched with mode from enabledSubtypes.
satokcd7cd292010-11-20 15:46:23 +09003133 if (subtype == null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003134 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satokdf31ae62011-01-15 06:19:44 +09003135 mRes, enabledSubtypes, mode, null, true);
satok4e4569d2010-11-19 18:45:53 +09003136 }
satoka86f5e42011-09-02 17:12:42 +09003137 final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003138 InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode);
satoka86f5e42011-09-02 17:12:42 +09003139 final ArrayList<InputMethodSubtype> subtypesForSearch =
3140 overridingImplicitlyEnabledSubtypes.isEmpty()
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003141 ? InputMethodUtils.getSubtypes(imi)
3142 : overridingImplicitlyEnabledSubtypes;
satok7599a7f2010-12-22 13:45:23 +09003143 // 4. Search by the current subtype's locale from all subtypes.
3144 if (subtype == null && mCurrentSubtype != null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003145 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satoka86f5e42011-09-02 17:12:42 +09003146 mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false);
satok7599a7f2010-12-22 13:45:23 +09003147 }
3148 // 5. Search by the system locale from all subtypes.
3149 // 6. Search the first enabled subtype matched with mode from all subtypes.
satokcd7cd292010-11-20 15:46:23 +09003150 if (subtype == null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003151 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satoka86f5e42011-09-02 17:12:42 +09003152 mRes, subtypesForSearch, mode, null, true);
satok4e4569d2010-11-19 18:45:53 +09003153 }
satokcd7cd292010-11-20 15:46:23 +09003154 if (subtype != null) {
satok7599a7f2010-12-22 13:45:23 +09003155 if (imiId.equals(mCurMethodId)) {
satok4e4569d2010-11-19 18:45:53 +09003156 // The current input method is the most applicable IME.
3157 mostApplicableIMI = imi;
satokcd7cd292010-11-20 15:46:23 +09003158 mostApplicableSubtype = subtype;
satok4e4569d2010-11-19 18:45:53 +09003159 break;
satok7599a7f2010-12-22 13:45:23 +09003160 } else if (!foundInSystemIME) {
satok4e4569d2010-11-19 18:45:53 +09003161 // The system input method is 2nd applicable IME.
3162 mostApplicableIMI = imi;
satokcd7cd292010-11-20 15:46:23 +09003163 mostApplicableSubtype = subtype;
satok7599a7f2010-12-22 13:45:23 +09003164 if ((imi.getServiceInfo().applicationInfo.flags
3165 & ApplicationInfo.FLAG_SYSTEM) != 0) {
3166 foundInSystemIME = true;
3167 }
satok4e4569d2010-11-19 18:45:53 +09003168 }
3169 }
3170 }
3171 if (DEBUG) {
satokcd7cd292010-11-20 15:46:23 +09003172 if (mostApplicableIMI != null) {
3173 Slog.w(TAG, "Most applicable shortcut input method was:"
3174 + mostApplicableIMI.getId());
3175 if (mostApplicableSubtype != null) {
3176 Slog.w(TAG, "Most applicable shortcut input method subtype was:"
3177 + "," + mostApplicableSubtype.getMode() + ","
3178 + mostApplicableSubtype.getLocale());
3179 }
3180 }
satok4e4569d2010-11-19 18:45:53 +09003181 }
satokcd7cd292010-11-20 15:46:23 +09003182 if (mostApplicableIMI != null) {
satok4e4569d2010-11-19 18:45:53 +09003183 return new Pair<InputMethodInfo, InputMethodSubtype> (mostApplicableIMI,
satokcd7cd292010-11-20 15:46:23 +09003184 mostApplicableSubtype);
satok4e4569d2010-11-19 18:45:53 +09003185 } else {
3186 return null;
3187 }
3188 }
3189
satokab751aa2010-09-14 19:17:36 +09003190 /**
3191 * @return Return the current subtype of this input method.
3192 */
satok42c5a162011-05-26 16:46:14 +09003193 @Override
satokab751aa2010-09-14 19:17:36 +09003194 public InputMethodSubtype getCurrentInputMethodSubtype() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003195 // TODO: Make this work even for non-current users?
3196 if (!calledFromValidUser()) {
3197 return null;
3198 }
3199 synchronized (mMethodMap) {
3200 return getCurrentInputMethodSubtypeLocked();
3201 }
3202 }
3203
3204 private InputMethodSubtype getCurrentInputMethodSubtypeLocked() {
satokfdf419e2012-05-08 16:52:08 +09003205 if (mCurMethodId == null) {
3206 return null;
3207 }
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003208 final boolean subtypeIsSelected = mSettings.isSubtypeSelected();
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003209 final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
3210 if (imi == null || imi.getSubtypeCount() == 0) {
3211 return null;
satok4e4569d2010-11-19 18:45:53 +09003212 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003213 if (!subtypeIsSelected || mCurrentSubtype == null
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003214 || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) {
3215 int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003216 if (subtypeId == NOT_A_SUBTYPE_ID) {
3217 // If there are no selected subtypes, the framework will try to find
3218 // the most applicable subtype from explicitly or implicitly enabled
3219 // subtypes.
3220 List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003221 mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003222 // If there is only one explicitly or implicitly enabled subtype,
3223 // just returns it.
3224 if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) {
3225 mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0);
3226 } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003227 mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003228 mRes, explicitlyOrImplicitlyEnabledSubtypes,
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003229 InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003230 if (mCurrentSubtype == null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003231 mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003232 mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null,
3233 true);
satok4e4569d2010-11-19 18:45:53 +09003234 }
satok3ef8b292010-11-23 06:06:29 +09003235 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003236 } else {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003237 mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId);
satok8fbb1e82010-11-02 23:15:58 +09003238 }
3239 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003240 return mCurrentSubtype;
satokab751aa2010-09-14 19:17:36 +09003241 }
3242
satokf3db1af2010-11-23 13:34:33 +09003243 private void addShortcutInputMethodAndSubtypes(InputMethodInfo imi,
3244 InputMethodSubtype subtype) {
3245 if (mShortcutInputMethodsAndSubtypes.containsKey(imi)) {
3246 mShortcutInputMethodsAndSubtypes.get(imi).add(subtype);
3247 } else {
3248 ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
3249 subtypes.add(subtype);
3250 mShortcutInputMethodsAndSubtypes.put(imi, subtypes);
3251 }
3252 }
3253
satok4e4569d2010-11-19 18:45:53 +09003254 // TODO: We should change the return type from List to List<Parcelable>
satokdbf29502011-08-25 15:28:23 +09003255 @SuppressWarnings("rawtypes")
satoke7c6998e2011-06-03 17:57:59 +09003256 @Override
satok4e4569d2010-11-19 18:45:53 +09003257 public List getShortcutInputMethodsAndSubtypes() {
3258 synchronized (mMethodMap) {
satok3da92232011-01-11 22:46:30 +09003259 ArrayList<Object> ret = new ArrayList<Object>();
satokf3db1af2010-11-23 13:34:33 +09003260 if (mShortcutInputMethodsAndSubtypes.size() == 0) {
satok4e4569d2010-11-19 18:45:53 +09003261 // If there are no selected shortcut subtypes, the framework will try to find
3262 // the most applicable subtype from all subtypes whose mode is
3263 // SUBTYPE_MODE_VOICE. This is an exceptional case, so we will hardcode the mode.
satokf3db1af2010-11-23 13:34:33 +09003264 Pair<InputMethodInfo, InputMethodSubtype> info =
3265 findLastResortApplicableShortcutInputMethodAndSubtypeLocked(
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003266 InputMethodUtils.SUBTYPE_MODE_VOICE);
satok7599a7f2010-12-22 13:45:23 +09003267 if (info != null) {
satok3da92232011-01-11 22:46:30 +09003268 ret.add(info.first);
3269 ret.add(info.second);
satok7599a7f2010-12-22 13:45:23 +09003270 }
satok3da92232011-01-11 22:46:30 +09003271 return ret;
satokf3db1af2010-11-23 13:34:33 +09003272 }
satokf3db1af2010-11-23 13:34:33 +09003273 for (InputMethodInfo imi: mShortcutInputMethodsAndSubtypes.keySet()) {
3274 ret.add(imi);
3275 for (InputMethodSubtype subtype: mShortcutInputMethodsAndSubtypes.get(imi)) {
3276 ret.add(subtype);
satok4e4569d2010-11-19 18:45:53 +09003277 }
3278 }
satokf3db1af2010-11-23 13:34:33 +09003279 return ret;
satok4e4569d2010-11-19 18:45:53 +09003280 }
3281 }
3282
satok42c5a162011-05-26 16:46:14 +09003283 @Override
satokb66d2872010-11-10 01:04:04 +09003284 public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003285 // TODO: Make this work even for non-current users?
3286 if (!calledFromValidUser()) {
3287 return false;
3288 }
satokb66d2872010-11-10 01:04:04 +09003289 synchronized (mMethodMap) {
3290 if (subtype != null && mCurMethodId != null) {
3291 InputMethodInfo imi = mMethodMap.get(mCurMethodId);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003292 int subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode());
satokb66d2872010-11-10 01:04:04 +09003293 if (subtypeId != NOT_A_SUBTYPE_ID) {
3294 setInputMethodLocked(mCurMethodId, subtypeId);
3295 return true;
3296 }
3297 }
3298 return false;
3299 }
3300 }
3301
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +09003302 // TODO: Cache the state for each user and reset when the cached user is removed.
satoke7c6998e2011-06-03 17:57:59 +09003303 private static class InputMethodFileManager {
3304 private static final String SYSTEM_PATH = "system";
3305 private static final String INPUT_METHOD_PATH = "inputmethod";
3306 private static final String ADDITIONAL_SUBTYPES_FILE_NAME = "subtypes.xml";
3307 private static final String NODE_SUBTYPES = "subtypes";
3308 private static final String NODE_SUBTYPE = "subtype";
3309 private static final String NODE_IMI = "imi";
3310 private static final String ATTR_ID = "id";
3311 private static final String ATTR_LABEL = "label";
3312 private static final String ATTR_ICON = "icon";
3313 private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale";
3314 private static final String ATTR_IME_SUBTYPE_MODE = "imeSubtypeMode";
3315 private static final String ATTR_IME_SUBTYPE_EXTRA_VALUE = "imeSubtypeExtraValue";
3316 private static final String ATTR_IS_AUXILIARY = "isAuxiliary";
3317 private final AtomicFile mAdditionalInputMethodSubtypeFile;
3318 private final HashMap<String, InputMethodInfo> mMethodMap;
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003319 private final HashMap<String, List<InputMethodSubtype>> mAdditionalSubtypesMap =
satoke7c6998e2011-06-03 17:57:59 +09003320 new HashMap<String, List<InputMethodSubtype>>();
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +09003321 public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap, int userId) {
satoke7c6998e2011-06-03 17:57:59 +09003322 if (methodMap == null) {
3323 throw new NullPointerException("methodMap is null");
3324 }
3325 mMethodMap = methodMap;
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +09003326 final File systemDir = userId == UserHandle.USER_OWNER
3327 ? new File(Environment.getDataDirectory(), SYSTEM_PATH)
3328 : Environment.getUserSystemDirectory(userId);
satoke7c6998e2011-06-03 17:57:59 +09003329 final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH);
3330 if (!inputMethodDir.mkdirs()) {
3331 Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath());
3332 }
3333 final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME);
3334 mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile);
3335 if (!subtypeFile.exists()) {
3336 // If "subtypes.xml" doesn't exist, create a blank file.
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003337 writeAdditionalInputMethodSubtypes(
3338 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, methodMap);
satoke7c6998e2011-06-03 17:57:59 +09003339 } else {
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003340 readAdditionalInputMethodSubtypes(
3341 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile);
satoke7c6998e2011-06-03 17:57:59 +09003342 }
3343 }
3344
3345 private void deleteAllInputMethodSubtypes(String imiId) {
3346 synchronized (mMethodMap) {
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003347 mAdditionalSubtypesMap.remove(imiId);
3348 writeAdditionalInputMethodSubtypes(
3349 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap);
satoke7c6998e2011-06-03 17:57:59 +09003350 }
3351 }
3352
3353 public void addInputMethodSubtypes(
satok4a28bde2011-06-29 21:03:40 +09003354 InputMethodInfo imi, InputMethodSubtype[] additionalSubtypes) {
satoke7c6998e2011-06-03 17:57:59 +09003355 synchronized (mMethodMap) {
3356 final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
3357 final int N = additionalSubtypes.length;
3358 for (int i = 0; i < N; ++i) {
3359 final InputMethodSubtype subtype = additionalSubtypes[i];
satoked2b24e2011-08-31 18:03:21 +09003360 if (!subtypes.contains(subtype)) {
satoke7c6998e2011-06-03 17:57:59 +09003361 subtypes.add(subtype);
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003362 } else {
3363 Slog.w(TAG, "Duplicated subtype definition found: "
3364 + subtype.getLocale() + ", " + subtype.getMode());
satoke7c6998e2011-06-03 17:57:59 +09003365 }
3366 }
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003367 mAdditionalSubtypesMap.put(imi.getId(), subtypes);
3368 writeAdditionalInputMethodSubtypes(
3369 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap);
satoke7c6998e2011-06-03 17:57:59 +09003370 }
3371 }
3372
3373 public HashMap<String, List<InputMethodSubtype>> getAllAdditionalInputMethodSubtypes() {
3374 synchronized (mMethodMap) {
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003375 return mAdditionalSubtypesMap;
satoke7c6998e2011-06-03 17:57:59 +09003376 }
3377 }
3378
3379 private static void writeAdditionalInputMethodSubtypes(
3380 HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile,
3381 HashMap<String, InputMethodInfo> methodMap) {
3382 // Safety net for the case that this function is called before methodMap is set.
3383 final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0;
3384 FileOutputStream fos = null;
3385 try {
3386 fos = subtypesFile.startWrite();
3387 final XmlSerializer out = new FastXmlSerializer();
3388 out.setOutput(fos, "utf-8");
3389 out.startDocument(null, true);
3390 out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
3391 out.startTag(null, NODE_SUBTYPES);
3392 for (String imiId : allSubtypes.keySet()) {
3393 if (isSetMethodMap && !methodMap.containsKey(imiId)) {
3394 Slog.w(TAG, "IME uninstalled or not valid.: " + imiId);
3395 continue;
3396 }
3397 out.startTag(null, NODE_IMI);
3398 out.attribute(null, ATTR_ID, imiId);
3399 final List<InputMethodSubtype> subtypesList = allSubtypes.get(imiId);
3400 final int N = subtypesList.size();
3401 for (int i = 0; i < N; ++i) {
3402 final InputMethodSubtype subtype = subtypesList.get(i);
3403 out.startTag(null, NODE_SUBTYPE);
3404 out.attribute(null, ATTR_ICON, String.valueOf(subtype.getIconResId()));
3405 out.attribute(null, ATTR_LABEL, String.valueOf(subtype.getNameResId()));
3406 out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale());
3407 out.attribute(null, ATTR_IME_SUBTYPE_MODE, subtype.getMode());
3408 out.attribute(null, ATTR_IME_SUBTYPE_EXTRA_VALUE, subtype.getExtraValue());
3409 out.attribute(null, ATTR_IS_AUXILIARY,
3410 String.valueOf(subtype.isAuxiliary() ? 1 : 0));
3411 out.endTag(null, NODE_SUBTYPE);
3412 }
3413 out.endTag(null, NODE_IMI);
3414 }
3415 out.endTag(null, NODE_SUBTYPES);
3416 out.endDocument();
3417 subtypesFile.finishWrite(fos);
3418 } catch (java.io.IOException e) {
3419 Slog.w(TAG, "Error writing subtypes", e);
3420 if (fos != null) {
3421 subtypesFile.failWrite(fos);
3422 }
3423 }
3424 }
3425
3426 private static void readAdditionalInputMethodSubtypes(
3427 HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) {
3428 if (allSubtypes == null || subtypesFile == null) return;
3429 allSubtypes.clear();
3430 FileInputStream fis = null;
3431 try {
3432 fis = subtypesFile.openRead();
3433 final XmlPullParser parser = Xml.newPullParser();
3434 parser.setInput(fis, null);
3435 int type = parser.getEventType();
3436 // Skip parsing until START_TAG
3437 while ((type = parser.next()) != XmlPullParser.START_TAG
3438 && type != XmlPullParser.END_DOCUMENT) {}
3439 String firstNodeName = parser.getName();
3440 if (!NODE_SUBTYPES.equals(firstNodeName)) {
3441 throw new XmlPullParserException("Xml doesn't start with subtypes");
3442 }
3443 final int depth =parser.getDepth();
3444 String currentImiId = null;
3445 ArrayList<InputMethodSubtype> tempSubtypesArray = null;
3446 while (((type = parser.next()) != XmlPullParser.END_TAG
3447 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
3448 if (type != XmlPullParser.START_TAG)
3449 continue;
3450 final String nodeName = parser.getName();
3451 if (NODE_IMI.equals(nodeName)) {
3452 currentImiId = parser.getAttributeValue(null, ATTR_ID);
3453 if (TextUtils.isEmpty(currentImiId)) {
3454 Slog.w(TAG, "Invalid imi id found in subtypes.xml");
3455 continue;
3456 }
3457 tempSubtypesArray = new ArrayList<InputMethodSubtype>();
3458 allSubtypes.put(currentImiId, tempSubtypesArray);
3459 } else if (NODE_SUBTYPE.equals(nodeName)) {
3460 if (TextUtils.isEmpty(currentImiId) || tempSubtypesArray == null) {
3461 Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId);
3462 continue;
3463 }
3464 final int icon = Integer.valueOf(
3465 parser.getAttributeValue(null, ATTR_ICON));
3466 final int label = Integer.valueOf(
3467 parser.getAttributeValue(null, ATTR_LABEL));
3468 final String imeSubtypeLocale =
3469 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE);
3470 final String imeSubtypeMode =
3471 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_MODE);
3472 final String imeSubtypeExtraValue =
3473 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_EXTRA_VALUE);
satok4a28bde2011-06-29 21:03:40 +09003474 final boolean isAuxiliary = "1".equals(String.valueOf(
3475 parser.getAttributeValue(null, ATTR_IS_AUXILIARY)));
Yohei Yukawa443c2ba2014-09-10 14:10:30 +09003476 final InputMethodSubtype subtype = new InputMethodSubtypeBuilder()
3477 .setSubtypeNameResId(label)
3478 .setSubtypeIconResId(icon)
3479 .setSubtypeLocale(imeSubtypeLocale)
3480 .setSubtypeMode(imeSubtypeMode)
3481 .setSubtypeExtraValue(imeSubtypeExtraValue)
3482 .setIsAuxiliary(isAuxiliary)
3483 .build();
satoke7c6998e2011-06-03 17:57:59 +09003484 tempSubtypesArray.add(subtype);
3485 }
3486 }
3487 } catch (XmlPullParserException e) {
3488 Slog.w(TAG, "Error reading subtypes: " + e);
3489 return;
3490 } catch (java.io.IOException e) {
3491 Slog.w(TAG, "Error reading subtypes: " + e);
3492 return;
3493 } catch (NumberFormatException e) {
3494 Slog.w(TAG, "Error reading subtypes: " + e);
3495 return;
3496 } finally {
3497 if (fis != null) {
3498 try {
3499 fis.close();
3500 } catch (java.io.IOException e1) {
3501 Slog.w(TAG, "Failed to close.");
3502 }
3503 }
3504 }
3505 }
3506 }
3507
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508 @Override
3509 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
3510 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3511 != PackageManager.PERMISSION_GRANTED) {
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003512
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003513 pw.println("Permission Denial: can't dump InputMethodManager from from pid="
3514 + Binder.getCallingPid()
3515 + ", uid=" + Binder.getCallingUid());
3516 return;
3517 }
3518
3519 IInputMethod method;
3520 ClientState client;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003522 final Printer p = new PrintWriterPrinter(pw);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003523
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003524 synchronized (mMethodMap) {
3525 p.println("Current Input Method Manager state:");
3526 int N = mMethodList.size();
3527 p.println(" Input Methods:");
3528 for (int i=0; i<N; i++) {
3529 InputMethodInfo info = mMethodList.get(i);
3530 p.println(" InputMethod #" + i + ":");
3531 info.dump(p, " ");
3532 }
3533 p.println(" Clients:");
3534 for (ClientState ci : mClients.values()) {
3535 p.println(" Client " + ci + ":");
3536 p.println(" client=" + ci.client);
3537 p.println(" inputContext=" + ci.inputContext);
3538 p.println(" sessionRequested=" + ci.sessionRequested);
3539 p.println(" curSession=" + ci.curSession);
3540 }
The Android Open Source Project10592532009-03-18 17:39:46 -07003541 p.println(" mCurMethodId=" + mCurMethodId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003542 client = mCurClient;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07003543 p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq);
3544 p.println(" mCurFocusedWindow=" + mCurFocusedWindow);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection
3546 + " mBoundToMethod=" + mBoundToMethod);
3547 p.println(" mCurToken=" + mCurToken);
3548 p.println(" mCurIntent=" + mCurIntent);
3549 method = mCurMethod;
3550 p.println(" mCurMethod=" + mCurMethod);
3551 p.println(" mEnabledSession=" + mEnabledSession);
3552 p.println(" mShowRequested=" + mShowRequested
3553 + " mShowExplicitlyRequested=" + mShowExplicitlyRequested
3554 + " mShowForced=" + mShowForced
3555 + " mInputShown=" + mInputShown);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09003556 p.println(" mCurUserActionNotificationSequenceNumber="
3557 + mCurUserActionNotificationSequenceNumber);
Dianne Hackbornd4e6d462014-05-16 16:32:37 -07003558 p.println(" mSystemReady=" + mSystemReady + " mInteractive=" + mScreenOn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003560
Jeff Brownb88102f2010-09-08 11:49:43 -07003561 p.println(" ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003562 if (client != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003563 pw.flush();
3564 try {
3565 client.client.asBinder().dump(fd, args);
3566 } catch (RemoteException e) {
3567 p.println("Input method client dead: " + e);
3568 }
Jeff Brownb88102f2010-09-08 11:49:43 -07003569 } else {
3570 p.println("No input method client.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003571 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003572
Jeff Brownb88102f2010-09-08 11:49:43 -07003573 p.println(" ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003574 if (method != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003575 pw.flush();
3576 try {
3577 method.asBinder().dump(fd, args);
3578 } catch (RemoteException e) {
3579 p.println("Input method service dead: " + e);
3580 }
Jeff Brownb88102f2010-09-08 11:49:43 -07003581 } else {
3582 p.println("No input method service.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583 }
3584 }
3585}