blob: b2b8f8508be558b6a675f582e9c9c6960c9dd8f9 [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
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070018import static android.view.Display.DEFAULT_DISPLAY;
Wale Ogunwale3a931692016-11-02 16:49:48 -070019import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Wale Ogunwaleac2561e2016-11-01 15:43:46 -070020import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
Wale Ogunwale3a931692016-11-02 16:49:48 -070021import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
Yohei Yukawafa0e47e2016-04-05 09:55:56 -070022import static java.lang.annotation.RetentionPolicy.SOURCE;
23
Yohei Yukawac4e44912017-02-09 19:30:22 -080024import com.android.internal.annotations.GuardedBy;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080025import com.android.internal.content.PackageMonitor;
Yohei Yukawa25e08132016-06-22 16:31:41 -070026import com.android.internal.inputmethod.IInputContentUriToken;
Satoshi Kataokad7443c82013-10-15 17:45:43 +090027import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController;
Satoshi Kataokad787f692013-10-26 04:44:21 +090028import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +090029import com.android.internal.inputmethod.InputMethodUtils;
30import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import com.android.internal.os.HandlerCaller;
Svetoslav Ganov758143e2012-08-06 16:40:27 -070032import com.android.internal.os.SomeArgs;
Jeff Sharkey850c83e2016-11-09 12:25:44 -070033import com.android.internal.os.TransferPipe;
satoke7c6998e2011-06-03 17:57:59 +090034import com.android.internal.util.FastXmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035import com.android.internal.view.IInputContext;
36import com.android.internal.view.IInputMethod;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import com.android.internal.view.IInputMethodClient;
38import com.android.internal.view.IInputMethodManager;
39import com.android.internal.view.IInputMethodSession;
Yohei Yukawa6ab1a822015-08-25 14:01:28 -070040import com.android.internal.view.IInputSessionCallback;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import com.android.internal.view.InputBindResult;
Yohei Yukawa33e81792015-11-17 21:14:42 -080042import com.android.internal.view.InputMethodClient;
Adam Lesinskief2ea1f2013-12-05 16:48:06 -080043import com.android.server.statusbar.StatusBarManagerService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
satoke7c6998e2011-06-03 17:57:59 +090045import org.xmlpull.v1.XmlPullParser;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import org.xmlpull.v1.XmlPullParserException;
satoke7c6998e2011-06-03 17:57:59 +090047import org.xmlpull.v1.XmlSerializer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048
Yohei Yukawafa0e47e2016-04-05 09:55:56 -070049import android.annotation.IntDef;
Yohei Yukawa6ab1a822015-08-25 14:01:28 -070050import android.annotation.NonNull;
Yohei Yukawae13a20fa2015-09-30 19:11:32 -070051import android.annotation.Nullable;
Yohei Yukawa7b18aec2016-03-07 13:04:32 -080052import android.annotation.UserIdInt;
Sudheer Shankadc589ac2016-11-10 15:30:17 -080053import android.app.ActivityManager;
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070054import android.app.ActivityManagerInternal;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.app.AlertDialog;
Yohei Yukawa6ab1a822015-08-25 14:01:28 -070056import android.app.AppGlobals;
Yohei Yukawae63b5fa2014-09-19 13:14:55 +090057import android.app.AppOpsManager;
satokf90a33e2011-07-19 11:55:52 +090058import android.app.KeyguardManager;
satok7cfc0ed2011-06-20 21:29:36 +090059import android.app.Notification;
60import android.app.NotificationManager;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -070061import android.app.PendingIntent;
satok5b927c432012-05-01 20:09:34 +090062import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.content.ComponentName;
Yohei Yukawa3933a6e2016-11-10 00:47:48 -080064import android.content.ContentProvider;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.content.ContentResolver;
66import android.content.Context;
67import android.content.DialogInterface;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.content.DialogInterface.OnCancelListener;
Tadashi G. Takaokad130b802014-08-01 14:05:47 +090069import android.content.DialogInterface.OnClickListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070import android.content.Intent;
satoke7c6998e2011-06-03 17:57:59 +090071import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072import android.content.ServiceConnection;
Brandon Ballinger6da35a02009-10-21 00:38:13 -070073import android.content.pm.ApplicationInfo;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +090074import android.content.pm.IPackageManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075import android.content.pm.PackageManager;
76import android.content.pm.ResolveInfo;
77import android.content.pm.ServiceInfo;
Amith Yamasanie861ec12010-03-24 21:39:27 -070078import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079import android.content.res.Resources;
80import android.content.res.TypedArray;
81import android.database.ContentObserver;
Alan Viverette505e3ab2014-11-24 15:22:11 -080082import android.graphics.drawable.Drawable;
Yohei Yukawab097b822015-12-01 10:43:08 -080083import android.hardware.input.InputManagerInternal;
Joe Onorato857fd9b2011-01-27 15:08:35 -080084import android.inputmethodservice.InputMethodService;
Michael Wright7b5a96b2014-08-09 19:28:42 -070085import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086import android.os.Binder;
Chris Wren1ce4b6d2015-06-11 10:19:43 -040087import android.os.Bundle;
Seigo Nonakae27dc2b2015-08-14 18:21:27 -070088import android.os.Debug;
satoke7c6998e2011-06-03 17:57:59 +090089import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090import android.os.Handler;
91import android.os.IBinder;
92import android.os.IInterface;
93import android.os.Message;
Yohei Yukawa23cbe852016-05-17 16:42:58 -070094import android.os.LocaleList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095import android.os.Parcel;
Yohei Yukawa6ab1a822015-08-25 14:01:28 -070096import android.os.Process;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097import android.os.RemoteException;
The Android Open Source Project4df24232009-03-05 14:34:35 -080098import android.os.ResultReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099import android.os.ServiceManager;
100import android.os.SystemClock;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900101import android.os.UserHandle;
Amith Yamasani734983f2014-03-04 16:48:05 -0800102import android.os.UserManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103import android.provider.Settings;
104import android.text.TextUtils;
satokf9f01002011-05-19 21:31:50 +0900105import android.text.style.SuggestionSpan;
Christopher Tate7b9a28c2015-03-18 13:06:16 -0700106import android.util.ArrayMap;
107import android.util.ArraySet;
Dianne Hackborn39606a02012-07-31 17:54:35 -0700108import android.util.AtomicFile;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109import android.util.EventLog;
satokf9f01002011-05-19 21:31:50 +0900110import android.util.LruCache;
satokab751aa2010-09-14 19:17:36 +0900111import android.util.Pair;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112import android.util.PrintWriterPrinter;
113import android.util.Printer;
satoke7c6998e2011-06-03 17:57:59 +0900114import android.util.Slog;
115import android.util.Xml;
Tadashi G. Takaokad130b802014-08-01 14:05:47 +0900116import android.view.ContextThemeWrapper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117import android.view.IWindowManager;
Jeff Brownc28867a2013-03-26 15:42:39 -0700118import android.view.InputChannel;
Ken Wakasa05dbb652011-08-22 15:22:43 +0900119import android.view.LayoutInflater;
120import android.view.View;
121import android.view.ViewGroup;
Wale Ogunwale3a931692016-11-02 16:49:48 -0700122import android.view.Window;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123import android.view.WindowManager;
Seigo Nonaka7309b122015-08-17 18:34:13 -0700124import android.view.WindowManagerInternal;
satokab751aa2010-09-14 19:17:36 +0900125import android.view.inputmethod.EditorInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126import android.view.inputmethod.InputBinding;
Yohei Yukawa19a80a12016-03-14 22:57:37 -0700127import android.view.inputmethod.InputConnectionInspector;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128import android.view.inputmethod.InputMethod;
129import android.view.inputmethod.InputMethodInfo;
130import android.view.inputmethod.InputMethodManager;
Yohei Yukawafa6e0a82015-07-23 15:08:59 -0700131import android.view.inputmethod.InputMethodManagerInternal;
satokab751aa2010-09-14 19:17:36 +0900132import android.view.inputmethod.InputMethodSubtype;
Yohei Yukawa443c2ba2014-09-10 14:10:30 +0900133import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
Ken Wakasa05dbb652011-08-22 15:22:43 +0900134import android.widget.ArrayAdapter;
satok01038492012-04-09 21:08:27 +0900135import android.widget.CompoundButton;
136import android.widget.CompoundButton.OnCheckedChangeListener;
Ken Wakasa05dbb652011-08-22 15:22:43 +0900137import android.widget.RadioButton;
satok01038492012-04-09 21:08:27 +0900138import android.widget.Switch;
Ken Wakasa05dbb652011-08-22 15:22:43 +0900139import android.widget.TextView;
Yohei Yukawaebda7d72016-04-02 17:39:23 -0700140import android.widget.Toast;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141
satoke7c6998e2011-06-03 17:57:59 +0900142import java.io.File;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143import java.io.FileDescriptor;
satoke7c6998e2011-06-03 17:57:59 +0900144import java.io.FileInputStream;
145import java.io.FileOutputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146import java.io.IOException;
147import java.io.PrintWriter;
Yohei Yukawafa0e47e2016-04-05 09:55:56 -0700148import java.lang.annotation.Retention;
Wojciech Staszkiewicz9e9e2e72015-05-08 14:58:46 +0100149import java.nio.charset.StandardCharsets;
Yohei Yukawa25e08132016-06-22 16:31:41 -0700150import java.security.InvalidParameterException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151import java.util.ArrayList;
satok688bd472012-02-09 20:09:17 +0900152import java.util.Collections;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153import java.util.HashMap;
154import java.util.List;
155
156/**
157 * This class provides a system service that manages input methods.
158 */
159public class InputMethodManagerService extends IInputMethodManager.Stub
160 implements ServiceConnection, Handler.Callback {
161 static final boolean DEBUG = false;
Christopher Tate7b9a28c2015-03-18 13:06:16 -0700162 static final boolean DEBUG_RESTORE = DEBUG || false;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700163 static final String TAG = "InputMethodManagerService";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164
Seigo Nonakad4474cb2015-05-04 16:53:24 -0700165 static final int MSG_SHOW_IM_SUBTYPE_PICKER = 1;
166 static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 2;
167 static final int MSG_SHOW_IM_CONFIG = 3;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 static final int MSG_UNBIND_INPUT = 1000;
170 static final int MSG_BIND_INPUT = 1010;
171 static final int MSG_SHOW_SOFT_INPUT = 1020;
172 static final int MSG_HIDE_SOFT_INPUT = 1030;
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -0700173 static final int MSG_HIDE_CURRENT_INPUT_METHOD = 1035;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 static final int MSG_ATTACH_TOKEN = 1040;
175 static final int MSG_CREATE_SESSION = 1050;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 static final int MSG_START_INPUT = 2000;
Yohei Yukawa3eaf8672017-02-11 23:40:07 +0000178 static final int MSG_RESTART_INPUT = 2010;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800179
Yohei Yukawa33e81792015-11-17 21:14:42 -0800180 static final int MSG_UNBIND_CLIENT = 3000;
181 static final int MSG_BIND_CLIENT = 3010;
Dianne Hackborna6e41342012-05-22 16:30:34 -0700182 static final int MSG_SET_ACTIVE = 3020;
Yohei Yukawafa6e0a82015-07-23 15:08:59 -0700183 static final int MSG_SET_INTERACTIVE = 3030;
Yohei Yukawa3d1e8122014-06-06 19:12:47 +0900184 static final int MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER = 3040;
Yohei Yukawa2bc66172017-02-08 11:13:25 -0800185 static final int MSG_REPORT_FULLSCREEN_MODE = 3045;
Yohei Yukawaae61f712015-12-09 13:00:10 -0800186 static final int MSG_SWITCH_IME = 3050;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800187
satok01038492012-04-09 21:08:27 +0900188 static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000;
189
Fyodor Kupolov7877b8a2016-06-29 14:39:19 -0700190 static final int MSG_SYSTEM_UNLOCK_USER = 5000;
191
Satoshi Kataokabcacc322013-10-21 17:57:27 -0700192 static final long TIME_TO_RECONNECT = 3 * 1000;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800193
satokf9f01002011-05-19 21:31:50 +0900194 static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20;
195
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +0900196 private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
satokb6359412011-06-28 17:47:41 +0900197 private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher";
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +0900198
Yohei Yukawafa0e47e2016-04-05 09:55:56 -0700199 @Retention(SOURCE)
200 @IntDef({HardKeyboardBehavior.WIRELESS_AFFORDANCE, HardKeyboardBehavior.WIRED_AFFORDANCE})
201 private @interface HardKeyboardBehavior {
202 int WIRELESS_AFFORDANCE = 0;
203 int WIRED_AFFORDANCE = 1;
204 }
satok4e4569d2010-11-19 18:45:53 +0900205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 final Context mContext;
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -0800207 final Resources mRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 final Handler mHandler;
satokd87c2592010-09-29 11:52:06 +0900209 final InputMethodSettings mSettings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 final SettingsObserver mSettingsObserver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 final IWindowManager mIWindowManager;
Seigo Nonaka7309b122015-08-17 18:34:13 -0700212 final WindowManagerInternal mWindowManagerInternal;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 final HandlerCaller mCaller;
Dianne Hackborn119bbc32013-03-22 17:27:25 -0700214 final boolean mHasFeature;
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +0900215 private InputMethodFileManager mFileManager;
satok01038492012-04-09 21:08:27 +0900216 private final HardKeyboardListener mHardKeyboardListener;
Yohei Yukawae63b5fa2014-09-19 13:14:55 +0900217 private final AppOpsManager mAppOpsManager;
Yohei Yukawaed4952a2016-02-17 07:57:25 -0800218 private final UserManager mUserManager;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800219
Yohei Yukawa3d1e8122014-06-06 19:12:47 +0900220 final InputBindResult mNoBinding = new InputBindResult(null, null, null, -1, -1);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 // All known input methods. mMethodMap also serves as the global
223 // lock for this class.
Yohei Yukawab0377bb2015-08-10 21:06:30 -0700224 final ArrayList<InputMethodInfo> mMethodList = new ArrayList<>();
225 final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<>();
satokf9f01002011-05-19 21:31:50 +0900226 private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans =
Yohei Yukawab0377bb2015-08-10 21:06:30 -0700227 new LruCache<>(SECURE_SUGGESTION_SPANS_MAX_SIZE);
Satoshi Kataokad787f692013-10-26 04:44:21 +0900228 private final InputMethodSubtypeSwitchingController mSwitchingController;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800229
Yohei Yukawae0733062017-02-09 22:49:35 -0800230 /**
231 * Tracks how many times {@link #mMethodMap} was updated.
232 */
233 @GuardedBy("mMethodMap")
234 private int mMethodMapUpdateCount = 0;
235
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700236 // Used to bring IME service up to visible adjustment while it is being shown.
237 final ServiceConnection mVisibleConnection = new ServiceConnection() {
238 @Override public void onServiceConnected(ComponentName name, IBinder service) {
239 }
240
241 @Override public void onServiceDisconnected(ComponentName name) {
242 }
243 };
244 boolean mVisibleBound = false;
245
satok7cfc0ed2011-06-20 21:29:36 +0900246 // Ongoing notification
Dianne Hackborn661cd522011-08-22 00:26:20 -0700247 private NotificationManager mNotificationManager;
248 private KeyguardManager mKeyguardManager;
Griff Hazen6090c262016-03-25 08:11:24 -0700249 private @Nullable StatusBarManagerService mStatusBar;
Chris Wren1ce4b6d2015-06-11 10:19:43 -0400250 private Notification.Builder mImeSwitcherNotification;
Dianne Hackborn661cd522011-08-22 00:26:20 -0700251 private PendingIntent mImeSwitchPendingIntent;
satokb858c732011-07-22 19:54:34 +0900252 private boolean mShowOngoingImeSwitcherForPhones;
satok7cfc0ed2011-06-20 21:29:36 +0900253 private boolean mNotificationShown;
254
Tadashi G. Takaoka8c6d4772014-08-05 15:29:17 +0900255 static class SessionState {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 final ClientState client;
257 final IInputMethod method;
Jeff Brownc28867a2013-03-26 15:42:39 -0700258
259 IInputMethodSession session;
260 InputChannel channel;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800261
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 @Override
263 public String toString() {
264 return "SessionState{uid " + client.uid + " pid " + client.pid
265 + " method " + Integer.toHexString(
266 System.identityHashCode(method))
267 + " session " + Integer.toHexString(
268 System.identityHashCode(session))
Jeff Brownc28867a2013-03-26 15:42:39 -0700269 + " channel " + channel
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 + "}";
271 }
272
273 SessionState(ClientState _client, IInputMethod _method,
Jeff Brownc28867a2013-03-26 15:42:39 -0700274 IInputMethodSession _session, InputChannel _channel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 client = _client;
276 method = _method;
277 session = _session;
Jeff Brownc28867a2013-03-26 15:42:39 -0700278 channel = _channel;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 }
280 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800281
Jeff Brownc28867a2013-03-26 15:42:39 -0700282 static final class ClientState {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 final IInputMethodClient client;
284 final IInputContext inputContext;
285 final int uid;
286 final int pid;
287 final InputBinding binding;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 boolean sessionRequested;
290 SessionState curSession;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 @Override
293 public String toString() {
294 return "ClientState{" + Integer.toHexString(
295 System.identityHashCode(this)) + " uid " + uid
296 + " pid " + pid + "}";
297 }
298
299 ClientState(IInputMethodClient _client, IInputContext _inputContext,
300 int _uid, int _pid) {
301 client = _client;
302 inputContext = _inputContext;
303 uid = _uid;
304 pid = _pid;
305 binding = new InputBinding(null, inputContext.asBinder(), uid, pid);
306 }
307 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800308
Yohei Yukawab0377bb2015-08-10 21:06:30 -0700309 final HashMap<IBinder, ClientState> mClients = new HashMap<>();
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 /**
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700312 * Set once the system is ready to run third party code.
313 */
314 boolean mSystemReady;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800315
Dianne Hackborna34f1ad2009-09-02 13:26:28 -0700316 /**
Yohei Yukawae13a20fa2015-09-30 19:11:32 -0700317 * Id obtained with {@link InputMethodInfo#getId()} for the currently selected input method.
318 * method. This is to be synchronized with the secure settings keyed with
319 * {@link Settings.Secure#DEFAULT_INPUT_METHOD}.
320 *
321 * <p>This can be transiently {@code null} when the system is re-initializing input method
322 * settings, e.g., the system locale is just changed.</p>
323 *
324 * <p>Note that {@link #mCurId} is used to track which IME is being connected to
325 * {@link InputMethodManagerService}.</p>
326 *
327 * @see #mCurId
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 */
Yohei Yukawae13a20fa2015-09-30 19:11:32 -0700329 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 String mCurMethodId;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 /**
333 * The current binding sequence number, incremented every time there is
334 * a new bind performed.
335 */
336 int mCurSeq;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800337
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 /**
339 * The client that is currently bound to an input method.
340 */
341 ClientState mCurClient;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 /**
Yohei Yukawae39d4ed2015-11-19 03:38:49 -0800344 * The last window token that we confirmed to be focused. This is always updated upon reports
345 * from the input method client. If the window state is already changed before the report is
346 * handled, this field just keeps the last value.
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700347 */
348 IBinder mCurFocusedWindow;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800349
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700350 /**
Yohei Yukawa22a89232017-02-12 16:38:59 -0800351 * {@link WindowManager.LayoutParams#softInputMode} of {@link #mCurFocusedWindow}.
352 *
353 * @see #mCurFocusedWindow
354 */
355 int mCurFocusedWindowSoftInputMode;
356
357 /**
Yohei Yukawae39d4ed2015-11-19 03:38:49 -0800358 * The client by which {@link #mCurFocusedWindow} was reported. Used only for debugging.
359 */
360 ClientState mCurFocusedWindowClient;
361
362 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 * The input context last provided by the current client.
364 */
365 IInputContext mCurInputContext;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 /**
Yohei Yukawa19a80a12016-03-14 22:57:37 -0700368 * The missing method flags for the input context last provided by the current client.
369 *
370 * @see android.view.inputmethod.InputConnectionInspector.MissingMethodFlags
371 */
372 int mCurInputContextMissingMethods;
373
374 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 * The attributes last provided by the current client.
376 */
377 EditorInfo mCurAttribute;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 /**
Yohei Yukawae13a20fa2015-09-30 19:11:32 -0700380 * Id obtained with {@link InputMethodInfo#getId()} for the input method that we are currently
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 * connected to or in the process of connecting to.
Yohei Yukawae13a20fa2015-09-30 19:11:32 -0700382 *
383 * <p>This can be {@code null} when no input method is connected.</p>
384 *
385 * @see #mCurMethodId
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 */
Yohei Yukawae13a20fa2015-09-30 19:11:32 -0700387 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 String mCurId;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 /**
satokab751aa2010-09-14 19:17:36 +0900391 * The current subtype of the current input method.
392 */
393 private InputMethodSubtype mCurrentSubtype;
394
satok4e4569d2010-11-19 18:45:53 +0900395 // This list contains the pairs of InputMethodInfo and InputMethodSubtype.
satokf3db1af2010-11-23 13:34:33 +0900396 private final HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>>
Yohei Yukawab0377bb2015-08-10 21:06:30 -0700397 mShortcutInputMethodsAndSubtypes = new HashMap<>();
satokab751aa2010-09-14 19:17:36 +0900398
John Spurlocke0980502013-10-25 11:59:29 -0400399 // Was the keyguard locked when this client became current?
400 private boolean mCurClientInKeyguard;
401
satokab751aa2010-09-14 19:17:36 +0900402 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403 * Set to true if our ServiceConnection is currently actively bound to
404 * a service (whether or not we have gotten its IBinder back yet).
405 */
406 boolean mHaveConnection;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800407
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 /**
409 * Set if the client has asked for the input method to be shown.
410 */
411 boolean mShowRequested;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 /**
414 * Set if we were explicitly told to show the input method.
415 */
416 boolean mShowExplicitlyRequested;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800417
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 /**
419 * Set if we were forced to be shown.
420 */
421 boolean mShowForced;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 /**
424 * Set if we last told the input method to show itself.
425 */
426 boolean mInputShown;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 /**
Yohei Yukawa2bc66172017-02-08 11:13:25 -0800429 * {@code true} if the current input method is in fullscreen mode.
430 */
431 boolean mInFullscreenMode;
432
433 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 * The Intent used to connect to the current input method.
435 */
436 Intent mCurIntent;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 /**
439 * The token we have made for the currently active input method, to
440 * identify it in the future.
441 */
442 IBinder mCurToken;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 /**
445 * If non-null, this is the input method service we are currently connected
446 * to.
447 */
448 IInputMethod mCurMethod;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 /**
451 * Time that we last initiated a bind to the input method, to determine
452 * if we should try to disconnect and reconnect to it.
453 */
454 long mLastBindTime;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800455
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 /**
457 * Have we called mCurMethod.bindInput()?
458 */
459 boolean mBoundToMethod;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 /**
462 * Currently enabled session. Only touched by service thread, not
463 * protected by a lock.
464 */
465 SessionState mEnabledSession;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800466
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 /**
Yohei Yukawafa6e0a82015-07-23 15:08:59 -0700468 * True if the device is currently interactive with user. The value is true initially.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 */
Yohei Yukawafa6e0a82015-07-23 15:08:59 -0700470 boolean mIsInteractive = true;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800471
Yohei Yukawa3d1e8122014-06-06 19:12:47 +0900472 int mCurUserActionNotificationSequenceNumber = 0;
473
Joe Onorato857fd9b2011-01-27 15:08:35 -0800474 int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT;
Seigo Nonakad9eb9112015-05-26 20:54:43 +0900475
476 /**
477 * A set of status bits regarding the active IME.
478 *
479 * <p>This value is a combination of following two bits:</p>
480 * <dl>
481 * <dt>{@link InputMethodService#IME_ACTIVE}</dt>
482 * <dd>
483 * If this bit is ON, connected IME is ready to accept touch/key events.
484 * </dd>
485 * <dt>{@link InputMethodService#IME_VISIBLE}</dt>
486 * <dd>
487 * If this bit is ON, some of IME view, e.g. software input, candidate view, is visible.
488 * </dd>
489 * </dl>
490 * <em>Do not update this value outside of setImeWindowStatus.</em>
491 */
Joe Onorato857fd9b2011-01-27 15:08:35 -0800492 int mImeWindowVis;
493
Ken Wakasa05dbb652011-08-22 15:22:43 +0900494 private AlertDialog.Builder mDialogBuilder;
495 private AlertDialog mSwitchingDialog;
Wale Ogunwale3a931692016-11-02 16:49:48 -0700496 private IBinder mSwitchingDialogToken = new Binder();
satok01038492012-04-09 21:08:27 +0900497 private View mSwitchingDialogTitleView;
Yohei Yukawaebda7d72016-04-02 17:39:23 -0700498 private Toast mSubtypeSwitchedByShortCutToast;
Ken Wakasa05dbb652011-08-22 15:22:43 +0900499 private InputMethodInfo[] mIms;
500 private int[] mSubtypeIds;
Yohei Yukawae985c242016-02-24 18:27:04 -0800501 private LocaleList mLastSystemLocales;
Michael Wright7b5a96b2014-08-09 19:28:42 -0700502 private boolean mShowImeWithHardKeyboard;
Anna Galusza9b278112016-01-04 11:37:37 -0800503 private boolean mAccessibilityRequestingNoSoftKeyboard;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900504 private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor();
505 private final IPackageManager mIPackageManager;
Jason Monk3e189872016-01-12 09:10:34 -0500506 private final String mSlotIme;
Yohei Yukawafa0e47e2016-04-05 09:55:56 -0700507 @HardKeyboardBehavior
508 private final int mHardKeyboardBehavior;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 class SettingsObserver extends ContentObserver {
Yohei Yukawa81482972015-06-04 00:58:59 -0700511 int mUserId;
512 boolean mRegistered = false;
Yohei Yukawa7b574cb2016-03-16 17:22:22 -0700513 @NonNull
Dianne Hackbornfd7aded2013-01-22 17:10:23 -0800514 String mLastEnabled = "";
515
Yohei Yukawa81482972015-06-04 00:58:59 -0700516 /**
517 * <em>This constructor must be called within the lock.</em>
518 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 SettingsObserver(Handler handler) {
520 super(handler);
Yohei Yukawa81482972015-06-04 00:58:59 -0700521 }
522
Yohei Yukawa7b18aec2016-03-07 13:04:32 -0800523 public void registerContentObserverLocked(@UserIdInt int userId) {
Yohei Yukawa81482972015-06-04 00:58:59 -0700524 if (mRegistered && mUserId == userId) {
525 return;
526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 ContentResolver resolver = mContext.getContentResolver();
Yohei Yukawa81482972015-06-04 00:58:59 -0700528 if (mRegistered) {
529 mContext.getContentResolver().unregisterContentObserver(this);
530 mRegistered = false;
531 }
532 if (mUserId != userId) {
533 mLastEnabled = "";
534 mUserId = userId;
535 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 resolver.registerContentObserver(Settings.Secure.getUriFor(
Yohei Yukawa81482972015-06-04 00:58:59 -0700537 Settings.Secure.DEFAULT_INPUT_METHOD), false, this, userId);
satokab751aa2010-09-14 19:17:36 +0900538 resolver.registerContentObserver(Settings.Secure.getUriFor(
Yohei Yukawa81482972015-06-04 00:58:59 -0700539 Settings.Secure.ENABLED_INPUT_METHODS), false, this, userId);
satokb6109bb2011-02-03 22:24:54 +0900540 resolver.registerContentObserver(Settings.Secure.getUriFor(
Yohei Yukawa81482972015-06-04 00:58:59 -0700541 Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this, userId);
Michael Wright7b5a96b2014-08-09 19:28:42 -0700542 resolver.registerContentObserver(Settings.Secure.getUriFor(
Yohei Yukawa81482972015-06-04 00:58:59 -0700543 Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD), false, this, userId);
Anna Galusza9b278112016-01-04 11:37:37 -0800544 resolver.registerContentObserver(Settings.Secure.getUriFor(
545 Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE), false, this, userId);
Yohei Yukawa81482972015-06-04 00:58:59 -0700546 mRegistered = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800548
Michael Wright7b5a96b2014-08-09 19:28:42 -0700549 @Override public void onChange(boolean selfChange, Uri uri) {
Anna Galusza9b278112016-01-04 11:37:37 -0800550 final Uri showImeUri = Settings.Secure.getUriFor(
551 Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD);
552 final Uri accessibilityRequestingNoImeUri = Settings.Secure.getUriFor(
553 Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 synchronized (mMethodMap) {
Michael Wright7b5a96b2014-08-09 19:28:42 -0700555 if (showImeUri.equals(uri)) {
556 updateKeyboardFromSettingsLocked();
Anna Galusza9b278112016-01-04 11:37:37 -0800557 } else if (accessibilityRequestingNoImeUri.equals(uri)) {
558 mAccessibilityRequestingNoSoftKeyboard = Settings.Secure.getIntForUser(
559 mContext.getContentResolver(),
560 Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE,
561 0, mUserId) == 1;
562 if (mAccessibilityRequestingNoSoftKeyboard) {
563 final boolean showRequested = mShowRequested;
564 hideCurrentInputLocked(0, null);
565 mShowRequested = showRequested;
566 } else if (mShowRequested) {
567 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
568 }
Michael Wright7b5a96b2014-08-09 19:28:42 -0700569 } else {
570 boolean enabledChanged = false;
571 String newEnabled = mSettings.getEnabledInputMethodsStr();
572 if (!mLastEnabled.equals(newEnabled)) {
573 mLastEnabled = newEnabled;
574 enabledChanged = true;
575 }
576 updateInputMethodsFromSettingsLocked(enabledChanged);
Dianne Hackbornfd7aded2013-01-22 17:10:23 -0800577 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 }
579 }
Yohei Yukawa81482972015-06-04 00:58:59 -0700580
581 @Override
582 public String toString() {
583 return "SettingsObserver{mUserId=" + mUserId + " mRegistered=" + mRegistered
584 + " mLastEnabled=" + mLastEnabled + "}";
585 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800587
Yohei Yukawa79247822017-01-23 15:26:15 -0800588 class ImmsBroadcastReceiver extends BroadcastReceiver {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900589 @Override
590 public void onReceive(Context context, Intent intent) {
591 final String action = intent.getAction();
Yohei Yukawafa6e0a82015-07-23 15:08:59 -0700592 if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900593 hideInputMethodMenu();
Yohei Yukawafa6e0a82015-07-23 15:08:59 -0700594 // No need to update mIsInteractive
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900595 return;
Amith Yamasani734983f2014-03-04 16:48:05 -0800596 } else if (Intent.ACTION_USER_ADDED.equals(action)
597 || Intent.ACTION_USER_REMOVED.equals(action)) {
Kenny Guy2a764942014-04-02 13:29:20 +0100598 updateCurrentProfileIds();
Amith Yamasani734983f2014-03-04 16:48:05 -0800599 return;
Christopher Tate7b9a28c2015-03-18 13:06:16 -0700600 } else if (Intent.ACTION_SETTING_RESTORED.equals(action)) {
601 final String name = intent.getStringExtra(Intent.EXTRA_SETTING_NAME);
602 if (Settings.Secure.ENABLED_INPUT_METHODS.equals(name)) {
603 final String prevValue = intent.getStringExtra(
604 Intent.EXTRA_SETTING_PREVIOUS_VALUE);
605 final String newValue = intent.getStringExtra(
606 Intent.EXTRA_SETTING_NEW_VALUE);
607 restoreEnabledInputMethods(mContext, prevValue, newValue);
608 }
Yohei Yukawa79247822017-01-23 15:26:15 -0800609 } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
Yohei Yukawa0d7aff82017-02-10 00:40:51 -0800610 onActionLocaleChanged();
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900611 } else {
612 Slog.w(TAG, "Unexpected intent " + intent);
613 }
614 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800615 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800616
Yohei Yukawa0d7aff82017-02-10 00:40:51 -0800617 /**
618 * Handles {@link Intent#ACTION_LOCALE_CHANGED}.
619 *
620 * <p>Note: For historical reasons, {@link Intent#ACTION_LOCALE_CHANGED} has been sent to all
621 * the users. We should ignore this event if this is about any background user's locale.</p>
622 *
623 * <p>Caution: This method must not be called when system is not ready.</p>
624 */
625 void onActionLocaleChanged() {
626 synchronized (mMethodMap) {
627 final LocaleList possibleNewLocale = mRes.getConfiguration().getLocales();
628 if (possibleNewLocale != null && possibleNewLocale.equals(mLastSystemLocales)) {
629 return;
630 }
631 buildInputMethodListLocked(true);
632 // If the locale is changed, needs to reset the default ime
633 resetDefaultImeLocked(mContext);
634 updateFromSettingsLocked(true);
635 mLastSystemLocales = possibleNewLocale;
636 }
637 }
638
Christopher Tate7b9a28c2015-03-18 13:06:16 -0700639 // Apply the results of a restore operation to the set of enabled IMEs. Note that this
640 // does not attempt to validate on the fly with any installed device policy, so must only
641 // be run in the context of initial device setup.
642 //
643 // TODO: Move this method to InputMethodUtils with adding unit tests.
644 static void restoreEnabledInputMethods(Context context, String prevValue, String newValue) {
645 if (DEBUG_RESTORE) {
646 Slog.i(TAG, "Restoring enabled input methods:");
647 Slog.i(TAG, "prev=" + prevValue);
648 Slog.i(TAG, " new=" + newValue);
649 }
650 // 'new' is the just-restored state, 'prev' is what was in settings prior to the restore
Seigo Nonaka2028dda2015-07-06 17:41:24 +0900651 ArrayMap<String, ArraySet<String>> prevMap =
652 InputMethodUtils.parseInputMethodsAndSubtypesString(prevValue);
653 ArrayMap<String, ArraySet<String>> newMap =
654 InputMethodUtils.parseInputMethodsAndSubtypesString(newValue);
Christopher Tate7b9a28c2015-03-18 13:06:16 -0700655
656 // Merge the restored ime+subtype enabled states into the live state
657 for (ArrayMap.Entry<String, ArraySet<String>> entry : newMap.entrySet()) {
658 final String imeId = entry.getKey();
659 ArraySet<String> prevSubtypes = prevMap.get(imeId);
660 if (prevSubtypes == null) {
Yohei Yukawab0377bb2015-08-10 21:06:30 -0700661 prevSubtypes = new ArraySet<>(2);
Christopher Tate7b9a28c2015-03-18 13:06:16 -0700662 prevMap.put(imeId, prevSubtypes);
663 }
664 prevSubtypes.addAll(entry.getValue());
665 }
666
Seigo Nonaka2a099bc2015-08-14 19:29:45 -0700667 final String mergedImesAndSubtypesString =
668 InputMethodUtils.buildInputMethodsAndSubtypesString(prevMap);
Christopher Tate7b9a28c2015-03-18 13:06:16 -0700669 if (DEBUG_RESTORE) {
670 Slog.i(TAG, "Merged IME string:");
671 Slog.i(TAG, " " + mergedImesAndSubtypesString);
672 }
673 Settings.Secure.putString(context.getContentResolver(),
674 Settings.Secure.ENABLED_INPUT_METHODS, mergedImesAndSubtypesString);
675 }
676
Yohei Yukawac4e44912017-02-09 19:30:22 -0800677 final class MyPackageMonitor extends PackageMonitor {
678 /**
679 * Set of packages to be monitored.
680 *
681 * <p>No need to include packages because of direct-boot unaware IMEs since we always rescan
682 * all the packages when the user is unlocked, and direct-boot awareness will not be changed
683 * dynamically unless the entire package is updated, which also always triggers package
684 * rescanning.</p>
685 */
686 @GuardedBy("mMethodMap")
687 private ArraySet<String> mPackagesToMonitorComponentChange = new ArraySet<>();
688
689 @GuardedBy("mMethodMap")
690 void clearPackagesToMonitorComponentChangeLocked() {
691 mPackagesToMonitorComponentChange.clear();
692 }
693
694 @GuardedBy("mMethodMap")
695 final void addPackageToMonitorComponentChangeLocked(@NonNull String packageName) {
696 mPackagesToMonitorComponentChange.add(packageName);
697 }
698
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900699 private boolean isChangingPackagesOfCurrentUser() {
700 final int userId = getChangingUserId();
701 final boolean retval = userId == mSettings.getCurrentUserId();
702 if (DEBUG) {
satok81f8b7c2012-12-04 20:42:56 +0900703 if (!retval) {
704 Slog.d(TAG, "--- ignore this call back from a background user: " + userId);
705 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900706 }
707 return retval;
708 }
709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 @Override
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800711 public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900712 if (!isChangingPackagesOfCurrentUser()) {
713 return false;
714 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 synchronized (mMethodMap) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900716 String curInputMethodId = mSettings.getSelectedInputMethod();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 final int N = mMethodList.size();
718 if (curInputMethodId != null) {
719 for (int i=0; i<N; i++) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800720 InputMethodInfo imi = mMethodList.get(i);
721 if (imi.getId().equals(curInputMethodId)) {
722 for (String pkg : packages) {
723 if (imi.getPackageName().equals(pkg)) {
724 if (!doit) {
725 return true;
726 }
satok723a27e2010-11-11 14:58:11 +0900727 resetSelectedInputMethodAndSubtypeLocked("");
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800728 chooseNewDefaultIMELocked();
729 return true;
730 }
731 }
732 }
733 }
734 }
735 }
736 return false;
737 }
738
739 @Override
Yohei Yukawac4e44912017-02-09 19:30:22 -0800740 public boolean onPackageChanged(String packageName, int uid, String[] components) {
741 // If this package is in the watch list, we want to check it.
742 synchronized (mMethodMap) {
743 return mPackagesToMonitorComponentChange.contains(packageName);
744 }
745 }
746
747 @Override
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800748 public void onSomePackagesChanged() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900749 if (!isChangingPackagesOfCurrentUser()) {
750 return;
751 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800752 synchronized (mMethodMap) {
753 InputMethodInfo curIm = null;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900754 String curInputMethodId = mSettings.getSelectedInputMethod();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800755 final int N = mMethodList.size();
756 if (curInputMethodId != null) {
757 for (int i=0; i<N; i++) {
758 InputMethodInfo imi = mMethodList.get(i);
satoke7c6998e2011-06-03 17:57:59 +0900759 final String imiId = imi.getId();
760 if (imiId.equals(curInputMethodId)) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800761 curIm = imi;
762 }
satoke7c6998e2011-06-03 17:57:59 +0900763
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800764 int change = isPackageDisappearing(imi.getPackageName());
satoke7c6998e2011-06-03 17:57:59 +0900765 if (isPackageModified(imi.getPackageName())) {
766 mFileManager.deleteAllInputMethodSubtypes(imiId);
767 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800768 if (change == PACKAGE_TEMPORARY_CHANGE
769 || change == PACKAGE_PERMANENT_CHANGE) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800770 Slog.i(TAG, "Input method uninstalled, disabling: "
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800771 + imi.getComponent());
772 setInputMethodEnabledLocked(imi.getId(), false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 }
774 }
775 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800776
Yohei Yukawa94e33302016-02-12 19:37:03 -0800777 buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 boolean changed = false;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800780
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800781 if (curIm != null) {
Anna Galusza9b278112016-01-04 11:37:37 -0800782 int change = isPackageDisappearing(curIm.getPackageName());
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800783 if (change == PACKAGE_TEMPORARY_CHANGE
784 || change == PACKAGE_PERMANENT_CHANGE) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800785 ServiceInfo si = null;
786 try {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900787 si = mIPackageManager.getServiceInfo(
788 curIm.getComponent(), 0, mSettings.getCurrentUserId());
789 } catch (RemoteException ex) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800790 }
791 if (si == null) {
792 // Uh oh, current input method is no longer around!
793 // Pick another one...
Joe Onorato8a9b2202010-02-26 18:56:32 -0800794 Slog.i(TAG, "Current input method removed: " + curInputMethodId);
Seigo Nonakad9eb9112015-05-26 20:54:43 +0900795 updateSystemUiLocked(mCurToken, 0 /* vis */, mBackDisposition);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800796 if (!chooseNewDefaultIMELocked()) {
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800797 changed = true;
798 curIm = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800799 Slog.i(TAG, "Unsetting current input method");
satok723a27e2010-11-11 14:58:11 +0900800 resetSelectedInputMethodAndSubtypeLocked("");
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800801 }
802 }
Suchi Amalapurapu08675a32010-01-28 09:57:30 -0800803 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800804 }
satokab751aa2010-09-14 19:17:36 +0900805
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800806 if (curIm == null) {
807 // We currently don't have a default input method... is
808 // one now available?
809 changed = chooseNewDefaultIMELocked();
Yohei Yukawa54d512c2015-05-19 22:15:02 -0700810 } else if (!changed && isPackageModified(curIm.getPackageName())) {
811 // Even if the current input method is still available, mCurrentSubtype could
812 // be obsolete when the package is modified in practice.
813 changed = true;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800814 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800815
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800816 if (changed) {
Dianne Hackbornfd7aded2013-01-22 17:10:23 -0800817 updateFromSettingsLocked(false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 }
819 }
820 }
821 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800822
Jeff Brownc28867a2013-03-26 15:42:39 -0700823 private static final class MethodCallback extends IInputSessionCallback.Stub {
Jean Chalarde0d32a62011-10-20 20:36:07 +0900824 private final InputMethodManagerService mParentIMMS;
Jeff Brownc28867a2013-03-26 15:42:39 -0700825 private final IInputMethod mMethod;
826 private final InputChannel mChannel;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800827
Jeff Brownc28867a2013-03-26 15:42:39 -0700828 MethodCallback(InputMethodManagerService imms, IInputMethod method,
829 InputChannel channel) {
Jean Chalarde0d32a62011-10-20 20:36:07 +0900830 mParentIMMS = imms;
Jeff Brownc28867a2013-03-26 15:42:39 -0700831 mMethod = method;
832 mChannel = channel;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800834
satoke7c6998e2011-06-03 17:57:59 +0900835 @Override
Jeff Brownc28867a2013-03-26 15:42:39 -0700836 public void sessionCreated(IInputMethodSession session) {
Dianne Hackborn6b6b3fd2014-03-24 11:27:18 -0700837 long ident = Binder.clearCallingIdentity();
838 try {
839 mParentIMMS.onSessionCreated(mMethod, session, mChannel);
840 } finally {
841 Binder.restoreCallingIdentity(ident);
842 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 }
844 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800845
satok01038492012-04-09 21:08:27 +0900846 private class HardKeyboardListener
Seigo Nonaka7309b122015-08-17 18:34:13 -0700847 implements WindowManagerInternal.OnHardKeyboardStatusChangeListener {
satok01038492012-04-09 21:08:27 +0900848 @Override
Michael Wright7b5a96b2014-08-09 19:28:42 -0700849 public void onHardKeyboardStatusChange(boolean available) {
850 mHandler.sendMessage(mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED,
851 available ? 1 : 0));
satok01038492012-04-09 21:08:27 +0900852 }
853
Michael Wright7b5a96b2014-08-09 19:28:42 -0700854 public void handleHardKeyboardStatusChange(boolean available) {
satok01038492012-04-09 21:08:27 +0900855 if (DEBUG) {
Michael Wright7b5a96b2014-08-09 19:28:42 -0700856 Slog.w(TAG, "HardKeyboardStatusChanged: available=" + available);
satok01038492012-04-09 21:08:27 +0900857 }
858 synchronized(mMethodMap) {
859 if (mSwitchingDialog != null && mSwitchingDialogTitleView != null
860 && mSwitchingDialog.isShowing()) {
861 mSwitchingDialogTitleView.findViewById(
862 com.android.internal.R.id.hard_keyboard_section).setVisibility(
863 available ? View.VISIBLE : View.GONE);
864 }
865 }
866 }
867 }
868
Fyodor Kupolov1e33dc82016-01-21 12:02:58 -0800869 public static final class Lifecycle extends SystemService {
870 private InputMethodManagerService mService;
871
872 public Lifecycle(Context context) {
873 super(context);
874 mService = new InputMethodManagerService(context);
875 }
876
877 @Override
878 public void onStart() {
879 LocalServices.addService(InputMethodManagerInternal.class,
880 new LocalServiceImpl(mService.mHandler));
881 publishBinderService(Context.INPUT_METHOD_SERVICE, mService);
882 }
883
884 @Override
Yohei Yukawa7b18aec2016-03-07 13:04:32 -0800885 public void onSwitchUser(@UserIdInt int userHandle) {
Fyodor Kupolov7877b8a2016-06-29 14:39:19 -0700886 // Called on ActivityManager thread.
Yohei Yukawa7b18aec2016-03-07 13:04:32 -0800887 // TODO: Dispatch this to a worker thread as needed.
888 mService.onSwitchUser(userHandle);
889 }
890
891 @Override
Fyodor Kupolov1e33dc82016-01-21 12:02:58 -0800892 public void onBootPhase(int phase) {
Fyodor Kupolov7877b8a2016-06-29 14:39:19 -0700893 // Called on ActivityManager thread.
Yohei Yukawa7b18aec2016-03-07 13:04:32 -0800894 // TODO: Dispatch this to a worker thread as needed.
Fyodor Kupolov1e33dc82016-01-21 12:02:58 -0800895 if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) {
896 StatusBarManagerService statusBarService = (StatusBarManagerService) ServiceManager
897 .getService(Context.STATUS_BAR_SERVICE);
898 mService.systemRunning(statusBarService);
899 }
900 }
Yohei Yukawaed4952a2016-02-17 07:57:25 -0800901
902 @Override
Fyodor Kupolov7877b8a2016-06-29 14:39:19 -0700903 public void onUnlockUser(final @UserIdInt int userHandle) {
904 // Called on ActivityManager thread.
905 mService.mHandler.sendMessage(mService.mHandler.obtainMessage(MSG_SYSTEM_UNLOCK_USER,
Fyodor Kupolov0f57cce2016-09-09 10:36:30 -0700906 userHandle /* arg1 */, 0 /* arg2 */));
Yohei Yukawaed4952a2016-02-17 07:57:25 -0800907 }
908 }
909
Yohei Yukawa7b18aec2016-03-07 13:04:32 -0800910 void onUnlockUser(@UserIdInt int userId) {
Yohei Yukawaed4952a2016-02-17 07:57:25 -0800911 synchronized(mMethodMap) {
912 final int currentUserId = mSettings.getCurrentUserId();
913 if (DEBUG) {
914 Slog.d(TAG, "onUnlockUser: userId=" + userId + " curUserId=" + currentUserId);
915 }
916 if (userId != currentUserId) {
917 return;
918 }
919 mSettings.switchCurrentUser(currentUserId, !mSystemReady);
Yohei Yukawa79247822017-01-23 15:26:15 -0800920 if (mSystemReady) {
921 // We need to rebuild IMEs.
922 buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
923 updateInputMethodsFromSettingsLocked(true /* enabledChanged */);
924 }
Yohei Yukawaed4952a2016-02-17 07:57:25 -0800925 }
Fyodor Kupolov1e33dc82016-01-21 12:02:58 -0800926 }
927
Yohei Yukawa7b18aec2016-03-07 13:04:32 -0800928 void onSwitchUser(@UserIdInt int userId) {
929 synchronized (mMethodMap) {
930 switchUserLocked(userId);
931 }
932 }
933
Seigo Nonaka7309b122015-08-17 18:34:13 -0700934 public InputMethodManagerService(Context context) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900935 mIPackageManager = AppGlobals.getPackageManager();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 mContext = context;
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -0800937 mRes = context.getResources();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 mHandler = new Handler(this);
Yohei Yukawa81482972015-06-04 00:58:59 -0700939 // Note: SettingsObserver doesn't register observers in its constructor.
940 mSettingsObserver = new SettingsObserver(mHandler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 mIWindowManager = IWindowManager.Stub.asInterface(
942 ServiceManager.getService(Context.WINDOW_SERVICE));
Seigo Nonaka7309b122015-08-17 18:34:13 -0700943 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Mita Yuned218c72012-12-06 17:18:25 -0800944 mCaller = new HandlerCaller(context, null, new HandlerCaller.Callback() {
satoke7c6998e2011-06-03 17:57:59 +0900945 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800946 public void executeMessage(Message msg) {
947 handleMessage(msg);
948 }
Mita Yuned218c72012-12-06 17:18:25 -0800949 }, true /*asyncHandler*/);
Yohei Yukawad34e1482016-02-11 08:03:52 -0800950 mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
Yohei Yukawaed4952a2016-02-17 07:57:25 -0800951 mUserManager = mContext.getSystemService(UserManager.class);
satok01038492012-04-09 21:08:27 +0900952 mHardKeyboardListener = new HardKeyboardListener();
Dianne Hackborn119bbc32013-03-22 17:27:25 -0700953 mHasFeature = context.getPackageManager().hasSystemFeature(
954 PackageManager.FEATURE_INPUT_METHODS);
Jason Monk3e189872016-01-12 09:10:34 -0500955 mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime);
Yohei Yukawafa0e47e2016-04-05 09:55:56 -0700956 mHardKeyboardBehavior = mContext.getResources().getInteger(
957 com.android.internal.R.integer.config_externalHardKeyboardBehavior);
satok7cfc0ed2011-06-20 21:29:36 +0900958
Chris Wren1ce4b6d2015-06-11 10:19:43 -0400959 Bundle extras = new Bundle();
960 extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true);
961 mImeSwitcherNotification = new Notification.Builder(mContext)
962 .setSmallIcon(com.android.internal.R.drawable.ic_notification_ime_default)
963 .setWhen(0)
964 .setOngoing(true)
965 .addExtras(extras)
966 .setCategory(Notification.CATEGORY_SYSTEM)
967 .setColor(com.android.internal.R.color.system_notification_accent_color);
Daniel Sandler590d5152012-06-14 16:10:13 -0400968
satok7cfc0ed2011-06-20 21:29:36 +0900969 Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER);
satok683e2382011-07-12 08:28:52 +0900970 mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
satokb858c732011-07-22 19:54:34 +0900971
972 mShowOngoingImeSwitcherForPhones = false;
satok7cfc0ed2011-06-20 21:29:36 +0900973
satok7cfc0ed2011-06-20 21:29:36 +0900974 mNotificationShown = false;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900975 int userId = 0;
976 try {
Sudheer Shankadc589ac2016-11-10 15:30:17 -0800977 userId = ActivityManager.getService().getCurrentUser().id;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +0900978 } catch (RemoteException e) {
979 Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e);
980 }
satok913a8922010-08-26 21:53:41 +0900981
satokd87c2592010-09-29 11:52:06 +0900982 // mSettings should be created before buildInputMethodListLocked
satokdf31ae62011-01-15 06:19:44 +0900983 mSettings = new InputMethodSettings(
Yohei Yukawa68645a62016-02-17 07:54:20 -0800984 mRes, context.getContentResolver(), mMethodMap, mMethodList, userId, !mSystemReady);
Svet Ganovadc1cf42015-06-15 16:36:24 -0700985
Kenny Guy2a764942014-04-02 13:29:20 +0100986 updateCurrentProfileIds();
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +0900987 mFileManager = new InputMethodFileManager(mMethodMap, userId);
Yohei Yukawa79247822017-01-23 15:26:15 -0800988 mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked(
989 mSettings, context);
satok5b927c432012-05-01 20:09:34 +0900990 }
991
satok5b927c432012-05-01 20:09:34 +0900992 private void resetDefaultImeLocked(Context context) {
993 // Do not reset the default (current) IME when it is a 3rd-party IME
Yohei Yukawac2393ac2016-02-18 00:30:45 -0800994 if (mCurMethodId != null && !InputMethodUtils.isSystemIme(mMethodMap.get(mCurMethodId))) {
satok5b927c432012-05-01 20:09:34 +0900995 return;
996 }
Yohei Yukawac2393ac2016-02-18 00:30:45 -0800997 final List<InputMethodInfo> suitableImes = InputMethodUtils.getDefaultEnabledImes(
Yohei Yukawaaf5cee82017-01-23 16:17:11 -0800998 context, mSettings.getEnabledInputMethodListLocked());
Yohei Yukawac2393ac2016-02-18 00:30:45 -0800999 if (suitableImes.isEmpty()) {
1000 Slog.i(TAG, "No default found");
1001 return;
satok5b927c432012-05-01 20:09:34 +09001002 }
Yohei Yukawac2393ac2016-02-18 00:30:45 -08001003 final InputMethodInfo defIm = suitableImes.get(0);
Yohei Yukawad0332832017-02-01 13:59:43 -08001004 if (DEBUG) {
1005 Slog.i(TAG, "Default found, using " + defIm.getId());
1006 }
Yohei Yukawac2393ac2016-02-18 00:30:45 -08001007 setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false);
satok5b927c432012-05-01 20:09:34 +09001008 }
1009
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +09001010 private void switchUserLocked(int newUserId) {
Yohei Yukawa90bf7082015-06-03 23:50:27 -07001011 if (DEBUG) Slog.d(TAG, "Switching user stage 1/3. newUserId=" + newUserId
1012 + " currentUserId=" + mSettings.getCurrentUserId());
1013
Yohei Yukawa81482972015-06-04 00:58:59 -07001014 // ContentObserver should be registered again when the user is changed
1015 mSettingsObserver.registerContentObserverLocked(newUserId);
Yohei Yukawa68645a62016-02-17 07:54:20 -08001016
Yohei Yukawaed4952a2016-02-17 07:57:25 -08001017 // If the system is not ready or the device is not yed unlocked by the user, then we use
1018 // copy-on-write settings.
1019 final boolean useCopyOnWriteSettings =
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001020 !mSystemReady || !mUserManager.isUserUnlockingOrUnlocked(newUserId);
Yohei Yukawa68645a62016-02-17 07:54:20 -08001021 mSettings.switchCurrentUser(newUserId, useCopyOnWriteSettings);
Kenny Guy2a764942014-04-02 13:29:20 +01001022 updateCurrentProfileIds();
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +09001023 // InputMethodFileManager should be reset when the user is changed
1024 mFileManager = new InputMethodFileManager(mMethodMap, newUserId);
Satoshi Kataoka7f7535f2013-02-18 12:54:16 +09001025 final String defaultImiId = mSettings.getSelectedInputMethod();
Yohei Yukawa90bf7082015-06-03 23:50:27 -07001026
1027 if (DEBUG) Slog.d(TAG, "Switching user stage 2/3. newUserId=" + newUserId
1028 + " defaultImiId=" + defaultImiId);
1029
Satoshi Kataoka7c4a2a12013-02-25 15:25:43 +09001030 // For secondary users, the list of enabled IMEs may not have been updated since the
1031 // callbacks to PackageMonitor are ignored for the secondary user. Here, defaultImiId may
1032 // not be empty even if the IME has been uninstalled by the primary user.
1033 // Even in such cases, IMMS works fine because it will find the most applicable
1034 // IME for that user.
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +09001035 final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId);
Yohei Yukawa0d7aff82017-02-10 00:40:51 -08001036 mLastSystemLocales = mRes.getConfiguration().getLocales();
1037
1038 // TODO: Is it really possible that switchUserLocked() happens before system ready?
1039 if (mSystemReady) {
1040 hideCurrentInputLocked(0, null);
1041 resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_SWITCH_USER);
1042 buildInputMethodListLocked(initialUserSwitch);
1043 if (TextUtils.isEmpty(mSettings.getSelectedInputMethod())) {
1044 // This is the first time of the user switch and
1045 // set the current ime to the proper one.
1046 resetDefaultImeLocked(mContext);
1047 }
1048 updateFromSettingsLocked(true);
1049 try {
1050 startInputInnerLocked();
1051 } catch (RuntimeException e) {
1052 Slog.w(TAG, "Unexpected exception", e);
1053 }
1054 }
1055
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +09001056 if (initialUserSwitch) {
Yohei Yukawa094c71f2015-06-20 00:41:31 -07001057 InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager,
1058 mSettings.getEnabledInputMethodListLocked(), newUserId,
1059 mContext.getBasePackageName());
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +09001060 }
Yohei Yukawa90bf7082015-06-03 23:50:27 -07001061
1062 if (DEBUG) Slog.d(TAG, "Switching user stage 3/3. newUserId=" + newUserId
1063 + " selectedIme=" + mSettings.getSelectedInputMethod());
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001064 }
1065
Kenny Guy2a764942014-04-02 13:29:20 +01001066 void updateCurrentProfileIds() {
Fyodor Kupolov7f98aa42016-04-07 14:56:25 -07001067 mSettings.setCurrentProfileIds(
1068 mUserManager.getProfileIdsWithDisabled(mSettings.getCurrentUserId()));
Amith Yamasani734983f2014-03-04 16:48:05 -08001069 }
1070
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001071 @Override
1072 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
1073 throws RemoteException {
1074 try {
1075 return super.onTransact(code, data, reply, flags);
1076 } catch (RuntimeException e) {
1077 // The input method manager only throws security exceptions, so let's
1078 // log all others.
1079 if (!(e instanceof SecurityException)) {
Dianne Hackborn164371f2013-10-01 19:10:13 -07001080 Slog.wtf(TAG, "Input Method Manager Crash", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081 }
1082 throw e;
1083 }
1084 }
1085
Svetoslav Ganova0027152013-06-25 14:59:53 -07001086 public void systemRunning(StatusBarManagerService statusBar) {
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001087 synchronized (mMethodMap) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001088 if (DEBUG) {
1089 Slog.d(TAG, "--- systemReady");
1090 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001091 if (!mSystemReady) {
1092 mSystemReady = true;
Yohei Yukawa79247822017-01-23 15:26:15 -08001093 mLastSystemLocales = mRes.getConfiguration().getLocales();
Yohei Yukawa68645a62016-02-17 07:54:20 -08001094 final int currentUserId = mSettings.getCurrentUserId();
Yohei Yukawaed4952a2016-02-17 07:57:25 -08001095 mSettings.switchCurrentUser(currentUserId,
Jeff Sharkeyce18c812016-04-27 16:00:41 -06001096 !mUserManager.isUserUnlockingOrUnlocked(currentUserId));
Yohei Yukawad34e1482016-02-11 08:03:52 -08001097 mKeyguardManager = mContext.getSystemService(KeyguardManager.class);
1098 mNotificationManager = mContext.getSystemService(NotificationManager.class);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001099 mStatusBar = statusBar;
Griff Hazen6090c262016-03-25 08:11:24 -07001100 if (mStatusBar != null) {
1101 mStatusBar.setIconVisibility(mSlotIme, false);
1102 }
Seigo Nonakad9eb9112015-05-26 20:54:43 +09001103 updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition);
satokb858c732011-07-22 19:54:34 +09001104 mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
1105 com.android.internal.R.bool.show_ongoing_ime_switcher);
satok01038492012-04-09 21:08:27 +09001106 if (mShowOngoingImeSwitcherForPhones) {
Seigo Nonaka7309b122015-08-17 18:34:13 -07001107 mWindowManagerInternal.setOnHardKeyboardStatusChangeListener(
satok01038492012-04-09 21:08:27 +09001108 mHardKeyboardListener);
1109 }
Yohei Yukawa79247822017-01-23 15:26:15 -08001110
1111 mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true);
1112 mSettingsObserver.registerContentObserverLocked(currentUserId);
1113
1114 final IntentFilter broadcastFilter = new IntentFilter();
1115 broadcastFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
1116 broadcastFilter.addAction(Intent.ACTION_USER_ADDED);
1117 broadcastFilter.addAction(Intent.ACTION_USER_REMOVED);
1118 broadcastFilter.addAction(Intent.ACTION_SETTING_RESTORED);
1119 broadcastFilter.addAction(Intent.ACTION_LOCALE_CHANGED);
1120 mContext.registerReceiver(new ImmsBroadcastReceiver(), broadcastFilter);
1121
1122 buildInputMethodListLocked(true /* resetDefaultEnabledIme */);
1123 resetDefaultImeLocked(mContext);
1124 updateFromSettingsLocked(true);
1125 InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager,
1126 mSettings.getEnabledInputMethodListLocked(), currentUserId,
1127 mContext.getBasePackageName());
1128
Dianne Hackborncc278702009-09-02 23:07:23 -07001129 try {
1130 startInputInnerLocked();
1131 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001132 Slog.w(TAG, "Unexpected exception", e);
Dianne Hackborncc278702009-09-02 23:07:23 -07001133 }
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001134 }
1135 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001137
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001138 // ---------------------------------------------------------------------------------------
1139 // Check whether or not this is a valid IPC. Assumes an IPC is valid when either
1140 // 1) it comes from the system process
1141 // 2) the calling process' user id is identical to the current user id IMMS thinks.
1142 private boolean calledFromValidUser() {
1143 final int uid = Binder.getCallingUid();
1144 final int userId = UserHandle.getUserId(uid);
1145 if (DEBUG) {
1146 Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? "
1147 + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID
1148 + " calling userId = " + userId + ", foreground user id = "
Satoshi Kataoka87c29142013-07-31 23:11:54 +09001149 + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid()
1150 + InputMethodUtils.getApiCallStack());
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001151 }
Kenny Guy2a764942014-04-02 13:29:20 +01001152 if (uid == Process.SYSTEM_UID || mSettings.isCurrentProfile(userId)) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001153 return true;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001154 }
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +09001155
1156 // Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the
1157 // foreground user, not for the user of that process. Accordingly InputMethodManagerService
1158 // must not manage background users' states in any functions.
1159 // Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded
1160 // by a token.
1161 if (mContext.checkCallingOrSelfPermission(
1162 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1163 == PackageManager.PERMISSION_GRANTED) {
1164 if (DEBUG) {
1165 Slog.d(TAG, "--- Access granted because the calling process has "
1166 + "the INTERACT_ACROSS_USERS_FULL permission");
1167 }
1168 return true;
1169 }
Yohei Yukawad0332832017-02-01 13:59:43 -08001170 // TODO(b/34886274): The semantics of this verification is actually not well-defined.
Seigo Nonakae27dc2b2015-08-14 18:21:27 -07001171 Slog.w(TAG, "--- IPC called from background users. Ignore. callers="
1172 + Debug.getCallers(10));
Satoshi Kataoka135e5fb2012-09-28 18:25:06 +09001173 return false;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001174 }
1175
Yohei Yukawa22c97be2014-06-04 19:43:36 +09001176
1177 /**
1178 * Returns true iff the caller is identified to be the current input method with the token.
1179 * @param token The window token given to the input method when it was started.
1180 * @return true if and only if non-null valid token is specified.
1181 */
Yohei Yukawad0332832017-02-01 13:59:43 -08001182 private boolean calledWithValidToken(@Nullable IBinder token) {
1183 if (token == null && Binder.getCallingPid() == Process.myPid()) {
1184 if (DEBUG) {
1185 // TODO(b/34851776): Basically it's the caller's fault if we reach here.
1186 Slog.d(TAG, "Bug 34851776 is detected callers=" + Debug.getCallers(10));
1187 }
1188 return false;
1189 }
1190 if (token == null || token != mCurToken) {
1191 // TODO(b/34886274): The semantics of this verification is actually not well-defined.
1192 Slog.e(TAG, "Ignoring " + Debug.getCaller() + " due to an invalid token."
1193 + " uid:" + Binder.getCallingUid() + " token:" + token);
Yohei Yukawa22c97be2014-06-04 19:43:36 +09001194 return false;
1195 }
1196 return true;
1197 }
1198
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001199 private boolean bindCurrentInputMethodService(
1200 Intent service, ServiceConnection conn, int flags) {
1201 if (service == null || conn == null) {
1202 Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn);
1203 return false;
1204 }
Amith Yamasani27b89e62013-01-16 12:30:11 -08001205 return mContext.bindServiceAsUser(service, conn, flags,
1206 new UserHandle(mSettings.getCurrentUserId()));
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001207 }
1208
satoke7c6998e2011-06-03 17:57:59 +09001209 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 public List<InputMethodInfo> getInputMethodList() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001211 // TODO: Make this work even for non-current users?
1212 if (!calledFromValidUser()) {
1213 return Collections.emptyList();
1214 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 synchronized (mMethodMap) {
Yohei Yukawab0377bb2015-08-10 21:06:30 -07001216 return new ArrayList<>(mMethodList);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 }
1218 }
1219
satoke7c6998e2011-06-03 17:57:59 +09001220 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001221 public List<InputMethodInfo> getEnabledInputMethodList() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001222 // TODO: Make this work even for non-current users?
1223 if (!calledFromValidUser()) {
1224 return Collections.emptyList();
1225 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 synchronized (mMethodMap) {
satokd87c2592010-09-29 11:52:06 +09001227 return mSettings.getEnabledInputMethodListLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001228 }
1229 }
1230
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001231 /**
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001232 * @param imiId if null, returns enabled subtypes for the current imi
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001233 * @return enabled subtypes of the specified imi
1234 */
satoke7c6998e2011-06-03 17:57:59 +09001235 @Override
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001236 public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId,
satok16331c82010-12-20 23:48:46 +09001237 boolean allowsImplicitlySelectedSubtypes) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001238 // TODO: Make this work even for non-current users?
1239 if (!calledFromValidUser()) {
Yohei Yukawab0377bb2015-08-10 21:06:30 -07001240 return Collections.emptyList();
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001241 }
satok67ddf9c2010-11-17 09:45:54 +09001242 synchronized (mMethodMap) {
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001243 final InputMethodInfo imi;
1244 if (imiId == null && mCurMethodId != null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001245 imi = mMethodMap.get(mCurMethodId);
Satoshi Kataokab3c21ac2013-08-07 15:43:29 +09001246 } else {
1247 imi = mMethodMap.get(imiId);
1248 }
1249 if (imi == null) {
Yohei Yukawab0377bb2015-08-10 21:06:30 -07001250 return Collections.emptyList();
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001251 }
1252 return mSettings.getEnabledInputMethodSubtypeListLocked(
1253 mContext, imi, allowsImplicitlySelectedSubtypes);
satok67ddf9c2010-11-17 09:45:54 +09001254 }
1255 }
1256
satoke7c6998e2011-06-03 17:57:59 +09001257 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 public void addClient(IInputMethodClient client,
1259 IInputContext inputContext, int uid, int pid) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001260 if (!calledFromValidUser()) {
1261 return;
1262 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 synchronized (mMethodMap) {
1264 mClients.put(client.asBinder(), new ClientState(client,
1265 inputContext, uid, pid));
1266 }
1267 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001268
satoke7c6998e2011-06-03 17:57:59 +09001269 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 public void removeClient(IInputMethodClient client) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001271 if (!calledFromValidUser()) {
1272 return;
1273 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 synchronized (mMethodMap) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001275 ClientState cs = mClients.remove(client.asBinder());
1276 if (cs != null) {
1277 clearClientSessionLocked(cs);
Yohei Yukawa072b1b52015-11-18 15:54:34 -08001278 if (mCurClient == cs) {
1279 mCurClient = null;
1280 }
Yohei Yukawae39d4ed2015-11-19 03:38:49 -08001281 if (mCurFocusedWindowClient == cs) {
1282 mCurFocusedWindowClient = null;
1283 }
Jeff Brownc28867a2013-03-26 15:42:39 -07001284 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285 }
1286 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001287
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 void executeOrSendMessage(IInterface target, Message msg) {
1289 if (target.asBinder() instanceof Binder) {
1290 mCaller.sendMessage(msg);
1291 } else {
1292 handleMessage(msg);
1293 msg.recycle();
1294 }
1295 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001296
Yohei Yukawa33e81792015-11-17 21:14:42 -08001297 void unbindCurrentClientLocked(
1298 /* @InputMethodClient.UnbindReason */ final int unbindClientReason) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001299 if (mCurClient != null) {
Yohei Yukawa35d3f372015-11-25 11:07:19 -08001300 if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client="
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 + mCurClient.client.asBinder());
1302 if (mBoundToMethod) {
1303 mBoundToMethod = false;
1304 if (mCurMethod != null) {
1305 executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
1306 MSG_UNBIND_INPUT, mCurMethod));
1307 }
1308 }
Dianne Hackborna6e41342012-05-22 16:30:34 -07001309
Yohei Yukawa2bc66172017-02-08 11:13:25 -08001310 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO(
1311 MSG_SET_ACTIVE, 0, 0, mCurClient));
Yohei Yukawa33e81792015-11-17 21:14:42 -08001312 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO(
1313 MSG_UNBIND_CLIENT, mCurSeq, unbindClientReason, mCurClient.client));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 mCurClient.sessionRequested = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001315 mCurClient = null;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001316
The Android Open Source Project10592532009-03-18 17:39:46 -07001317 hideInputMethodMenuLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 }
1319 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 private int getImeShowFlags() {
1322 int flags = 0;
1323 if (mShowForced) {
1324 flags |= InputMethod.SHOW_FORCED
1325 | InputMethod.SHOW_EXPLICIT;
1326 } else if (mShowExplicitlyRequested) {
1327 flags |= InputMethod.SHOW_EXPLICIT;
1328 }
1329 return flags;
1330 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001331
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001332 private int getAppShowFlags() {
1333 int flags = 0;
1334 if (mShowForced) {
1335 flags |= InputMethodManager.SHOW_FORCED;
1336 } else if (!mShowExplicitlyRequested) {
1337 flags |= InputMethodManager.SHOW_IMPLICIT;
1338 }
1339 return flags;
1340 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001341
Yohei Yukawa87ca8402017-02-07 00:13:14 -08001342 InputBindResult attachNewInputLocked(
1343 /* @InputMethodClient.StartInputReason */ final int startInputReason, boolean initial) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001344 if (!mBoundToMethod) {
1345 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
1346 MSG_BIND_INPUT, mCurMethod, mCurClient.binding));
1347 mBoundToMethod = true;
1348 }
1349 final SessionState session = mCurClient.curSession;
Yohei Yukawa3eaf8672017-02-11 23:40:07 +00001350 if (initial) {
1351 executeOrSendMessage(session.method, mCaller.obtainMessageIOOO(
1352 MSG_START_INPUT, mCurInputContextMissingMethods, session, mCurInputContext,
1353 mCurAttribute));
1354 } else {
1355 executeOrSendMessage(session.method, mCaller.obtainMessageIOOO(
1356 MSG_RESTART_INPUT, mCurInputContextMissingMethods, session, mCurInputContext,
1357 mCurAttribute));
1358 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 if (mShowRequested) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001360 if (DEBUG) Slog.v(TAG, "Attach new input asks to show input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08001361 showCurrentInputLocked(getAppShowFlags(), null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 }
Jeff Brown1951ce82013-04-04 22:45:12 -07001363 return new InputBindResult(session.session,
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001364 (session.channel != null ? session.channel.dup() : null),
1365 mCurId, mCurSeq, mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001367
Yohei Yukawa35d3f372015-11-25 11:07:19 -08001368 InputBindResult startInputLocked(
1369 /* @InputMethodClient.StartInputReason */ final int startInputReason,
Yohei Yukawa19a80a12016-03-14 22:57:37 -07001370 IInputMethodClient client, IInputContext inputContext,
1371 /* @InputConnectionInspector.missingMethods */ final int missingMethods,
Yohei Yukawa74750f22016-03-22 12:54:22 -07001372 @Nullable EditorInfo attribute, int controlFlags) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001373 // If no method is currently selected, do nothing.
1374 if (mCurMethodId == null) {
1375 return mNoBinding;
1376 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001378 ClientState cs = mClients.get(client.asBinder());
1379 if (cs == null) {
1380 throw new IllegalArgumentException("unknown client "
1381 + client.asBinder());
1382 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001383
Yohei Yukawa74750f22016-03-22 12:54:22 -07001384 if (attribute == null) {
1385 Slog.w(TAG, "Ignoring startInput with null EditorInfo."
1386 + " uid=" + cs.uid + " pid=" + cs.pid);
1387 return null;
1388 }
1389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 try {
1391 if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
1392 // Check with the window manager to make sure this client actually
1393 // has a window with focus. If not, reject. This is thread safe
1394 // because if the focus changes some time before or after, the
1395 // next client receiving focus that has any interest in input will
1396 // be calling through here after that change happens.
Yohei Yukawad0332832017-02-01 13:59:43 -08001397 if (DEBUG) {
1398 Slog.w(TAG, "Starting input on non-focused client " + cs.client
1399 + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
1400 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 return null;
1402 }
1403 } catch (RemoteException e) {
1404 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001405
Yohei Yukawa19a80a12016-03-14 22:57:37 -07001406 return startInputUncheckedLocked(cs, inputContext, missingMethods, attribute,
Yohei Yukawa87ca8402017-02-07 00:13:14 -08001407 controlFlags, startInputReason);
Dianne Hackborn7663d802012-02-24 13:08:49 -08001408 }
1409
Yohei Yukawa35d3f372015-11-25 11:07:19 -08001410 InputBindResult startInputUncheckedLocked(@NonNull ClientState cs, IInputContext inputContext,
Yohei Yukawa19a80a12016-03-14 22:57:37 -07001411 /* @InputConnectionInspector.missingMethods */ final int missingMethods,
Yohei Yukawa87ca8402017-02-07 00:13:14 -08001412 @NonNull EditorInfo attribute, int controlFlags,
1413 /* @InputMethodClient.StartInputReason */ final int startInputReason) {
Dianne Hackborn7663d802012-02-24 13:08:49 -08001414 // If no method is currently selected, do nothing.
1415 if (mCurMethodId == null) {
1416 return mNoBinding;
1417 }
1418
Yohei Yukawad57ba672015-06-08 16:39:46 -07001419 if (!InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, cs.uid,
1420 attribute.packageName)) {
1421 Slog.e(TAG, "Rejecting this client as it reported an invalid package name."
1422 + " uid=" + cs.uid + " package=" + attribute.packageName);
1423 return mNoBinding;
Yohei Yukawa0f3ad12015-04-06 16:48:24 -07001424 }
1425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001426 if (mCurClient != cs) {
John Spurlocke0980502013-10-25 11:59:29 -04001427 // Was the keyguard locked when switching over to the new client?
1428 mCurClientInKeyguard = isKeyguardLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429 // If the client is changing, we need to switch over to the new
1430 // one.
Yohei Yukawa33e81792015-11-17 21:14:42 -08001431 unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_SWITCH_CLIENT);
Yohei Yukawa35d3f372015-11-25 11:07:19 -08001432 if (DEBUG) Slog.v(TAG, "switching to client: client="
John Spurlocke0980502013-10-25 11:59:29 -04001433 + cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434
1435 // If the screen is on, inform the new client it is active
Yohei Yukawafa6e0a82015-07-23 15:08:59 -07001436 if (mIsInteractive) {
Dianne Hackborna6e41342012-05-22 16:30:34 -07001437 executeOrSendMessage(cs.client, mCaller.obtainMessageIO(
Yohei Yukawafa6e0a82015-07-23 15:08:59 -07001438 MSG_SET_ACTIVE, mIsInteractive ? 1 : 0, cs));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 }
1440 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001441
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 // Bump up the sequence for this client and attach it.
1443 mCurSeq++;
1444 if (mCurSeq <= 0) mCurSeq = 1;
1445 mCurClient = cs;
1446 mCurInputContext = inputContext;
Yohei Yukawa19a80a12016-03-14 22:57:37 -07001447 mCurInputContextMissingMethods = missingMethods;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001448 mCurAttribute = attribute;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 // Check if the input method is changing.
1451 if (mCurId != null && mCurId.equals(mCurMethodId)) {
1452 if (cs.curSession != null) {
1453 // Fast case: if we are already connected to the input method,
1454 // then just return it.
Yohei Yukawa87ca8402017-02-07 00:13:14 -08001455 return attachNewInputLocked(startInputReason,
Dianne Hackborn7663d802012-02-24 13:08:49 -08001456 (controlFlags&InputMethodManager.CONTROL_START_INITIAL) != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 }
1458 if (mHaveConnection) {
1459 if (mCurMethod != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001460 // Return to client, and we will get back with it when
1461 // we have had a session made for it.
Jeff Brownc28867a2013-03-26 15:42:39 -07001462 requestClientSessionLocked(cs);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001463 return new InputBindResult(null, null, mCurId, mCurSeq,
1464 mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465 } else if (SystemClock.uptimeMillis()
1466 < (mLastBindTime+TIME_TO_RECONNECT)) {
1467 // In this case we have connected to the service, but
1468 // don't yet have its interface. If it hasn't been too
1469 // long since we did the connection, we'll return to
1470 // the client and wait to get the service interface so
1471 // we can report back. If it has been too long, we want
1472 // to fall through so we can try a disconnect/reconnect
1473 // to see if we can get back in touch with the service.
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001474 return new InputBindResult(null, null, mCurId, mCurSeq,
1475 mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 } else {
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001477 EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME,
1478 mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 }
1480 }
1481 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001482
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001483 return startInputInnerLocked();
1484 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001485
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001486 InputBindResult startInputInnerLocked() {
1487 if (mCurMethodId == null) {
1488 return mNoBinding;
1489 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001490
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001491 if (!mSystemReady) {
1492 // If the system is not yet ready, we shouldn't be running third
1493 // party code.
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001494 return new InputBindResult(null, null, mCurMethodId, mCurSeq,
1495 mCurUserActionNotificationSequenceNumber);
Dianne Hackborna34f1ad2009-09-02 13:26:28 -07001496 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001497
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 InputMethodInfo info = mMethodMap.get(mCurMethodId);
1499 if (info == null) {
1500 throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
1501 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001502
Yohei Yukawabc7b5262015-11-17 17:38:41 -08001503 unbindCurrentMethodLocked(true);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE);
1506 mCurIntent.setComponent(info.getComponent());
Dianne Hackborndd9b82c2009-09-03 00:18:47 -07001507 mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
1508 com.android.internal.R.string.input_method_binding_label);
1509 mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
1510 mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0));
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001511 if (bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
Dianne Hackbornf0f94d12014-03-17 16:04:21 -07001512 | Context.BIND_NOT_VISIBLE | Context.BIND_NOT_FOREGROUND
1513 | Context.BIND_SHOWING_UI)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 mLastBindTime = SystemClock.uptimeMillis();
1515 mHaveConnection = true;
1516 mCurId = info.getId();
1517 mCurToken = new Binder();
1518 try {
Yohei Yukawad0332832017-02-01 13:59:43 -08001519 if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken);
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001520 mIWindowManager.addWindowToken(mCurToken, TYPE_INPUT_METHOD, DEFAULT_DISPLAY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521 } catch (RemoteException e) {
1522 }
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09001523 return new InputBindResult(null, null, mCurId, mCurSeq,
1524 mCurUserActionNotificationSequenceNumber);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 } else {
1526 mCurIntent = null;
Joe Onorato8a9b2202010-02-26 18:56:32 -08001527 Slog.w(TAG, "Failure connecting to input method service: "
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 + mCurIntent);
1529 }
1530 return null;
1531 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001532
Yohei Yukawa05c25f82016-02-22 12:41:17 -08001533 private InputBindResult startInput(
Yohei Yukawa35d3f372015-11-25 11:07:19 -08001534 /* @InputMethodClient.StartInputReason */ final int startInputReason,
Yohei Yukawa19a80a12016-03-14 22:57:37 -07001535 IInputMethodClient client, IInputContext inputContext,
1536 /* @InputConnectionInspector.missingMethods */ final int missingMethods,
Yohei Yukawa74750f22016-03-22 12:54:22 -07001537 @Nullable EditorInfo attribute, int controlFlags) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001538 if (!calledFromValidUser()) {
1539 return null;
1540 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541 synchronized (mMethodMap) {
Yohei Yukawa35d3f372015-11-25 11:07:19 -08001542 if (DEBUG) {
1543 Slog.v(TAG, "startInput: reason="
1544 + InputMethodClient.getStartInputReason(startInputReason)
1545 + " client = " + client.asBinder()
1546 + " inputContext=" + inputContext
Yohei Yukawa19a80a12016-03-14 22:57:37 -07001547 + " missingMethods="
1548 + InputConnectionInspector.getMissingMethodFlagsAsString(missingMethods)
Yohei Yukawa35d3f372015-11-25 11:07:19 -08001549 + " attribute=" + attribute
1550 + " controlFlags=#" + Integer.toHexString(controlFlags));
1551 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552 final long ident = Binder.clearCallingIdentity();
1553 try {
Yohei Yukawa19a80a12016-03-14 22:57:37 -07001554 return startInputLocked(startInputReason, client, inputContext, missingMethods,
1555 attribute, controlFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001556 } finally {
1557 Binder.restoreCallingIdentity(ident);
1558 }
1559 }
1560 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001561
satoke7c6998e2011-06-03 17:57:59 +09001562 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 public void finishInput(IInputMethodClient client) {
1564 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001565
satoke7c6998e2011-06-03 17:57:59 +09001566 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 public void onServiceConnected(ComponentName name, IBinder service) {
1568 synchronized (mMethodMap) {
1569 if (mCurIntent != null && name.equals(mCurIntent.getComponent())) {
1570 mCurMethod = IInputMethod.Stub.asInterface(service);
Dianne Hackborncc278702009-09-02 23:07:23 -07001571 if (mCurToken == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001572 Slog.w(TAG, "Service connected without a token!");
Yohei Yukawabc7b5262015-11-17 17:38:41 -08001573 unbindCurrentMethodLocked(false);
Dianne Hackborncc278702009-09-02 23:07:23 -07001574 return;
1575 }
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07001576 if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken);
Dianne Hackborncc278702009-09-02 23:07:23 -07001577 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
1578 MSG_ATTACH_TOKEN, mCurMethod, mCurToken));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 if (mCurClient != null) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001580 clearClientSessionLocked(mCurClient);
1581 requestClientSessionLocked(mCurClient);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 }
1583 }
1584 }
1585 }
1586
Jeff Brownc28867a2013-03-26 15:42:39 -07001587 void onSessionCreated(IInputMethod method, IInputMethodSession session,
1588 InputChannel channel) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 synchronized (mMethodMap) {
1590 if (mCurMethod != null && method != null
1591 && mCurMethod.asBinder() == method.asBinder()) {
1592 if (mCurClient != null) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001593 clearClientSessionLocked(mCurClient);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 mCurClient.curSession = new SessionState(mCurClient,
Jeff Brownc28867a2013-03-26 15:42:39 -07001595 method, session, channel);
Yohei Yukawa87ca8402017-02-07 00:13:14 -08001596 InputBindResult res = attachNewInputLocked(
1597 InputMethodClient.START_INPUT_REASON_SESSION_CREATED_BY_IME, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 if (res.method != null) {
1599 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO(
Yohei Yukawa33e81792015-11-17 21:14:42 -08001600 MSG_BIND_CLIENT, mCurClient.client, res));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 }
Jeff Brownc28867a2013-03-26 15:42:39 -07001602 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603 }
1604 }
1605 }
Jeff Brownc28867a2013-03-26 15:42:39 -07001606
1607 // Session abandoned. Close its associated input channel.
1608 channel.dispose();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001610
Yohei Yukawabc7b5262015-11-17 17:38:41 -08001611 void unbindCurrentMethodLocked(boolean savePosition) {
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07001612 if (mVisibleBound) {
1613 mContext.unbindService(mVisibleConnection);
1614 mVisibleBound = false;
1615 }
1616
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001617 if (mHaveConnection) {
1618 mContext.unbindService(this);
1619 mHaveConnection = false;
1620 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001621
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001622 if (mCurToken != null) {
1623 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001624 if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07001625 if ((mImeWindowVis & InputMethodService.IME_ACTIVE) != 0 && savePosition) {
satoke0a99412012-05-10 02:22:58 +09001626 // The current IME is shown. Hence an IME switch (transition) is happening.
Seigo Nonaka7309b122015-08-17 18:34:13 -07001627 mWindowManagerInternal.saveLastInputMethodWindowForTransition();
satoke0a99412012-05-10 02:22:58 +09001628 }
Wale Ogunwaleac2561e2016-11-01 15:43:46 -07001629 mIWindowManager.removeWindowToken(mCurToken, DEFAULT_DISPLAY);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001630 } catch (RemoteException e) {
1631 }
1632 mCurToken = null;
1633 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001634
The Android Open Source Project10592532009-03-18 17:39:46 -07001635 mCurId = null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001636 clearCurMethodLocked();
Yohei Yukawabc7b5262015-11-17 17:38:41 -08001637 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001638
Yohei Yukawa33e81792015-11-17 21:14:42 -08001639 void resetCurrentMethodAndClient(
1640 /* @InputMethodClient.UnbindReason */ final int unbindClientReason) {
Yohei Yukawabc7b5262015-11-17 17:38:41 -08001641 mCurMethodId = null;
1642 unbindCurrentMethodLocked(false);
Yohei Yukawa33e81792015-11-17 21:14:42 -08001643 unbindCurrentClientLocked(unbindClientReason);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001644 }
Jeff Brownc28867a2013-03-26 15:42:39 -07001645
1646 void requestClientSessionLocked(ClientState cs) {
1647 if (!cs.sessionRequested) {
1648 if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs);
1649 InputChannel[] channels = InputChannel.openInputChannelPair(cs.toString());
1650 cs.sessionRequested = true;
1651 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOOO(
1652 MSG_CREATE_SESSION, mCurMethod, channels[1],
1653 new MethodCallback(this, mCurMethod, channels[0])));
1654 }
1655 }
1656
1657 void clearClientSessionLocked(ClientState cs) {
1658 finishSessionLocked(cs.curSession);
1659 cs.curSession = null;
1660 cs.sessionRequested = false;
1661 }
1662
1663 private void finishSessionLocked(SessionState sessionState) {
1664 if (sessionState != null) {
1665 if (sessionState.session != null) {
1666 try {
1667 sessionState.session.finishSession();
1668 } catch (RemoteException e) {
1669 Slog.w(TAG, "Session failed to close due to remote exception", e);
Seigo Nonakad9eb9112015-05-26 20:54:43 +09001670 updateSystemUiLocked(mCurToken, 0 /* vis */, mBackDisposition);
Jeff Brownc28867a2013-03-26 15:42:39 -07001671 }
1672 sessionState.session = null;
1673 }
1674 if (sessionState.channel != null) {
1675 sessionState.channel.dispose();
1676 sessionState.channel = null;
Devin Taylor0c33ed22010-02-23 13:26:46 -06001677 }
1678 }
1679 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001680
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001681 void clearCurMethodLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 if (mCurMethod != null) {
1683 for (ClientState cs : mClients.values()) {
Jeff Brownc28867a2013-03-26 15:42:39 -07001684 clearClientSessionLocked(cs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001685 }
Devin Taylor0c33ed22010-02-23 13:26:46 -06001686
Jeff Brownc28867a2013-03-26 15:42:39 -07001687 finishSessionLocked(mEnabledSession);
Devin Taylor0c33ed22010-02-23 13:26:46 -06001688 mEnabledSession = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001689 mCurMethod = null;
1690 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07001691 if (mStatusBar != null) {
Jason Monk3e189872016-01-12 09:10:34 -05001692 mStatusBar.setIconVisibility(mSlotIme, false);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001693 }
Yohei Yukawa2bc66172017-02-08 11:13:25 -08001694 mInFullscreenMode = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08001696
satoke7c6998e2011-06-03 17:57:59 +09001697 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001698 public void onServiceDisconnected(ComponentName name) {
Yohei Yukawa817d5f72017-01-04 20:15:02 -08001699 // Note that mContext.unbindService(this) does not trigger this. Hence if we are here the
1700 // disconnection is not intended by IMMS (e.g. triggered because the current IMS crashed),
1701 // which is irregular but can eventually happen for everyone just by continuing using the
1702 // device. Thus it is important to make sure that all the internal states are properly
1703 // refreshed when this method is called back. Running
1704 // adb install -r <APK that implements the current IME>
1705 // would be a good way to trigger such a situation.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 synchronized (mMethodMap) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001707 if (DEBUG) Slog.v(TAG, "Service disconnected: " + name
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 + " mCurIntent=" + mCurIntent);
1709 if (mCurMethod != null && mCurIntent != null
1710 && name.equals(mCurIntent.getComponent())) {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001711 clearCurMethodLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001712 // We consider this to be a new bind attempt, since the system
1713 // should now try to restart the service for us.
1714 mLastBindTime = SystemClock.uptimeMillis();
1715 mShowRequested = mInputShown;
1716 mInputShown = false;
Yohei Yukawa817d5f72017-01-04 20:15:02 -08001717 unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_DISCONNECT_IME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001718 }
1719 }
1720 }
1721
satokf9f01002011-05-19 21:31:50 +09001722 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001723 public void updateStatusIcon(IBinder token, String packageName, int iconId) {
Yohei Yukawa59377ca2017-01-31 21:32:26 -08001724 synchronized (mMethodMap) {
1725 if (!calledWithValidToken(token)) {
Yohei Yukawa59377ca2017-01-31 21:32:26 -08001726 return;
1727 }
1728 final long ident = Binder.clearCallingIdentity();
1729 try {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 if (iconId == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001731 if (DEBUG) Slog.d(TAG, "hide the small icon for the input method");
Dianne Hackborn661cd522011-08-22 00:26:20 -07001732 if (mStatusBar != null) {
Jason Monk3e189872016-01-12 09:10:34 -05001733 mStatusBar.setIconVisibility(mSlotIme, false);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001734 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 } else if (packageName != null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001736 if (DEBUG) Slog.d(TAG, "show a small icon for the input method");
Svetoslav Ganov6179ea32011-06-28 01:12:41 -07001737 CharSequence contentDescription = null;
1738 try {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001739 // Use PackageManager to load label
1740 final PackageManager packageManager = mContext.getPackageManager();
Svetoslav Ganov6179ea32011-06-28 01:12:41 -07001741 contentDescription = packageManager.getApplicationLabel(
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001742 mIPackageManager.getApplicationInfo(packageName, 0,
1743 mSettings.getCurrentUserId()));
1744 } catch (RemoteException e) {
Svetoslav Ganov6179ea32011-06-28 01:12:41 -07001745 /* ignore */
1746 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07001747 if (mStatusBar != null) {
Jason Monk3e189872016-01-12 09:10:34 -05001748 mStatusBar.setIcon(mSlotIme, packageName, iconId, 0,
Dianne Hackborn661cd522011-08-22 00:26:20 -07001749 contentDescription != null
1750 ? contentDescription.toString() : null);
Jason Monk3e189872016-01-12 09:10:34 -05001751 mStatusBar.setIconVisibility(mSlotIme, true);
Dianne Hackborn661cd522011-08-22 00:26:20 -07001752 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001753 }
Yohei Yukawa59377ca2017-01-31 21:32:26 -08001754 } finally {
1755 Binder.restoreCallingIdentity(ident);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001757 }
1758 }
1759
Seigo Nonakad9eb9112015-05-26 20:54:43 +09001760 private boolean shouldShowImeSwitcherLocked(int visibility) {
satok7cfc0ed2011-06-20 21:29:36 +09001761 if (!mShowOngoingImeSwitcherForPhones) return false;
Jason Monk807ef762014-05-08 15:47:46 -04001762 if (mSwitchingDialog != null) return false;
satok2c93efc2012-04-02 19:33:47 +09001763 if (isScreenLocked()) return false;
Seigo Nonakad9eb9112015-05-26 20:54:43 +09001764 if ((visibility & InputMethodService.IME_ACTIVE) == 0) return false;
Seigo Nonaka7309b122015-08-17 18:34:13 -07001765 if (mWindowManagerInternal.isHardKeyboardAvailable()) {
Yohei Yukawafa0e47e2016-04-05 09:55:56 -07001766 if (mHardKeyboardBehavior == HardKeyboardBehavior.WIRELESS_AFFORDANCE) {
1767 // When physical keyboard is attached, we show the ime switcher (or notification if
1768 // NavBar is not available) because SHOW_IME_WITH_HARD_KEYBOARD settings currently
1769 // exists in the IME switcher dialog. Might be OK to remove this condition once
1770 // SHOW_IME_WITH_HARD_KEYBOARD settings finds a good place to live.
1771 return true;
1772 }
Yohei Yukawa89398382016-03-29 11:37:04 -07001773 } else if ((visibility & InputMethodService.IME_VISIBLE) == 0) {
1774 return false;
Yohei Yukawac6c7cd22015-05-12 15:00:33 -07001775 }
Yohei Yukawac6c7cd22015-05-12 15:00:33 -07001776
1777 List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
1778 final int N = imis.size();
1779 if (N > 2) return true;
1780 if (N < 1) return false;
1781 int nonAuxCount = 0;
1782 int auxCount = 0;
1783 InputMethodSubtype nonAuxSubtype = null;
1784 InputMethodSubtype auxSubtype = null;
1785 for(int i = 0; i < N; ++i) {
1786 final InputMethodInfo imi = imis.get(i);
1787 final List<InputMethodSubtype> subtypes =
1788 mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
1789 final int subtypeCount = subtypes.size();
1790 if (subtypeCount == 0) {
1791 ++nonAuxCount;
1792 } else {
1793 for (int j = 0; j < subtypeCount; ++j) {
1794 final InputMethodSubtype subtype = subtypes.get(j);
1795 if (!subtype.isAuxiliary()) {
1796 ++nonAuxCount;
1797 nonAuxSubtype = subtype;
1798 } else {
1799 ++auxCount;
1800 auxSubtype = subtype;
satok7cfc0ed2011-06-20 21:29:36 +09001801 }
1802 }
satok7cfc0ed2011-06-20 21:29:36 +09001803 }
1804 }
Yohei Yukawac6c7cd22015-05-12 15:00:33 -07001805 if (nonAuxCount > 1 || auxCount > 1) {
1806 return true;
1807 } else if (nonAuxCount == 1 && auxCount == 1) {
1808 if (nonAuxSubtype != null && auxSubtype != null
1809 && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale())
1810 || auxSubtype.overridesImplicitlyEnabledSubtype()
1811 || nonAuxSubtype.overridesImplicitlyEnabledSubtype())
1812 && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) {
1813 return false;
1814 }
1815 return true;
1816 }
1817 return false;
satok7cfc0ed2011-06-20 21:29:36 +09001818 }
1819
John Spurlocke0980502013-10-25 11:59:29 -04001820 private boolean isKeyguardLocked() {
1821 return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked();
1822 }
1823
satokdbf29502011-08-25 15:28:23 +09001824 @SuppressWarnings("deprecation")
satokf9f01002011-05-19 21:31:50 +09001825 @Override
Joe Onorato857fd9b2011-01-27 15:08:35 -08001826 public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
Seigo Nonakad9eb9112015-05-26 20:54:43 +09001827 if (!calledWithValidToken(token)) {
Seigo Nonakad9eb9112015-05-26 20:54:43 +09001828 return;
1829 }
1830
1831 synchronized (mMethodMap) {
1832 mImeWindowVis = vis;
1833 mBackDisposition = backDisposition;
1834 updateSystemUiLocked(token, vis, backDisposition);
1835 }
1836 }
1837
1838 private void updateSystemUi(IBinder token, int vis, int backDisposition) {
1839 synchronized (mMethodMap) {
1840 updateSystemUiLocked(token, vis, backDisposition);
1841 }
1842 }
1843
1844 // Caution! This method is called in this class. Handle multi-user carefully
1845 private void updateSystemUiLocked(IBinder token, int vis, int backDisposition) {
1846 if (!calledWithValidToken(token)) {
Seigo Nonakad9eb9112015-05-26 20:54:43 +09001847 return;
1848 }
1849
1850 // TODO: Move this clearing calling identity block to setImeWindowStatus after making sure
1851 // all updateSystemUi happens on system previlege.
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001852 final long ident = Binder.clearCallingIdentity();
satok06487a52010-10-29 11:37:18 +09001853 try {
Seigo Nonakad9eb9112015-05-26 20:54:43 +09001854 // apply policy for binder calls
1855 if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) {
1856 vis = 0;
satok06487a52010-10-29 11:37:18 +09001857 }
Seigo Nonakad9eb9112015-05-26 20:54:43 +09001858 // mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked().
1859 final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis);
1860 if (mStatusBar != null) {
1861 mStatusBar.setImeWindowStatus(token, vis, backDisposition,
1862 needsToShowImeSwitcher);
1863 }
1864 final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
1865 if (imi != null && needsToShowImeSwitcher) {
1866 // Used to load label
1867 final CharSequence title = mRes.getText(
1868 com.android.internal.R.string.select_input_method);
1869 final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName(
1870 mContext, imi, mCurrentSubtype);
Chris Wren1ce4b6d2015-06-11 10:19:43 -04001871 mImeSwitcherNotification.setContentTitle(title)
1872 .setContentText(summary)
1873 .setContentIntent(mImeSwitchPendingIntent);
Seigo Nonaka7309b122015-08-17 18:34:13 -07001874 try {
1875 if ((mNotificationManager != null)
1876 && !mIWindowManager.hasNavigationBar()) {
1877 if (DEBUG) {
1878 Slog.d(TAG, "--- show notification: label = " + summary);
1879 }
1880 mNotificationManager.notifyAsUser(null,
1881 com.android.internal.R.string.select_input_method,
1882 mImeSwitcherNotification.build(), UserHandle.ALL);
1883 mNotificationShown = true;
Dianne Hackborn661cd522011-08-22 00:26:20 -07001884 }
Seigo Nonaka7309b122015-08-17 18:34:13 -07001885 } catch (RemoteException e) {
Seigo Nonakad9eb9112015-05-26 20:54:43 +09001886 }
1887 } else {
1888 if (mNotificationShown && mNotificationManager != null) {
1889 if (DEBUG) {
1890 Slog.d(TAG, "--- hide notification");
satok7cfc0ed2011-06-20 21:29:36 +09001891 }
Seigo Nonakad9eb9112015-05-26 20:54:43 +09001892 mNotificationManager.cancelAsUser(null,
1893 com.android.internal.R.string.select_input_method, UserHandle.ALL);
1894 mNotificationShown = false;
satok7cfc0ed2011-06-20 21:29:36 +09001895 }
satok06487a52010-10-29 11:37:18 +09001896 }
1897 } finally {
1898 Binder.restoreCallingIdentity(ident);
1899 }
1900 }
1901
satoke7c6998e2011-06-03 17:57:59 +09001902 @Override
satokf9f01002011-05-19 21:31:50 +09001903 public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001904 if (!calledFromValidUser()) {
1905 return;
1906 }
satokf9f01002011-05-19 21:31:50 +09001907 synchronized (mMethodMap) {
1908 final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
1909 for (int i = 0; i < spans.length; ++i) {
1910 SuggestionSpan ss = spans[i];
satok42c5a162011-05-26 16:46:14 +09001911 if (!TextUtils.isEmpty(ss.getNotificationTargetClassName())) {
satokf9f01002011-05-19 21:31:50 +09001912 mSecureSuggestionSpans.put(ss, currentImi);
1913 }
1914 }
1915 }
1916 }
1917
satoke7c6998e2011-06-03 17:57:59 +09001918 @Override
satokf9f01002011-05-19 21:31:50 +09001919 public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001920 if (!calledFromValidUser()) {
1921 return false;
1922 }
satokf9f01002011-05-19 21:31:50 +09001923 synchronized (mMethodMap) {
1924 final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span);
1925 // TODO: Do not send the intent if the process of the targetImi is already dead.
1926 if (targetImi != null) {
1927 final String[] suggestions = span.getSuggestions();
1928 if (index < 0 || index >= suggestions.length) return false;
satok42c5a162011-05-26 16:46:14 +09001929 final String className = span.getNotificationTargetClassName();
satokf9f01002011-05-19 21:31:50 +09001930 final Intent intent = new Intent();
1931 // Ensures that only a class in the original IME package will receive the
1932 // notification.
satok42c5a162011-05-26 16:46:14 +09001933 intent.setClassName(targetImi.getPackageName(), className);
satokf9f01002011-05-19 21:31:50 +09001934 intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED);
1935 intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString);
1936 intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]);
1937 intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode());
Amith Yamasanif043de92012-10-24 06:42:40 -07001938 final long ident = Binder.clearCallingIdentity();
1939 try {
1940 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
1941 } finally {
1942 Binder.restoreCallingIdentity(ident);
1943 }
satokf9f01002011-05-19 21:31:50 +09001944 return true;
1945 }
1946 }
1947 return false;
1948 }
1949
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001950 void updateFromSettingsLocked(boolean enabledMayChange) {
Michael Wright7b5a96b2014-08-09 19:28:42 -07001951 updateInputMethodsFromSettingsLocked(enabledMayChange);
1952 updateKeyboardFromSettingsLocked();
1953 }
1954
1955 void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) {
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001956 if (enabledMayChange) {
1957 List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
1958 for (int i=0; i<enabled.size(); i++) {
1959 // We allow the user to select "disabled until used" apps, so if they
1960 // are enabling one of those here we now need to make it enabled.
1961 InputMethodInfo imm = enabled.get(i);
1962 try {
1963 ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(),
1964 PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
1965 mSettings.getCurrentUserId());
Satoshi Kataoka7987a312013-04-17 18:59:33 +09001966 if (ai != null && ai.enabledSetting
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001967 == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
Satoshi Kataokaed1cdb22013-04-17 16:41:58 +09001968 if (DEBUG) {
1969 Slog.d(TAG, "Update state(" + imm.getId()
1970 + "): DISABLED_UNTIL_USED -> DEFAULT");
1971 }
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001972 mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(),
1973 PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
Dianne Hackborn3fa3c28a2013-03-26 16:15:41 -07001974 PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(),
1975 mContext.getBasePackageName());
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08001976 }
1977 } catch (RemoteException e) {
1978 }
1979 }
1980 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001981 // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and
1982 // ENABLED_INPUT_METHODS is taking care of keeping them correctly in
1983 // sync, so we will never have a DEFAULT_INPUT_METHOD that is not
1984 // enabled.
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001985 String id = mSettings.getSelectedInputMethod();
satok03eb319a2010-11-11 18:17:42 +09001986 // There is no input method selected, try to choose new applicable input method.
1987 if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09001988 id = mSettings.getSelectedInputMethod();
satok03eb319a2010-11-11 18:17:42 +09001989 }
1990 if (!TextUtils.isEmpty(id)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001991 try {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09001992 setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 } catch (IllegalArgumentException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001994 Slog.w(TAG, "Unknown input method from prefs: " + id, e);
Yohei Yukawa33e81792015-11-17 21:14:42 -08001995 resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_SWITCH_IME_FAILED);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 }
satokf3db1af2010-11-23 13:34:33 +09001997 mShortcutInputMethodsAndSubtypes.clear();
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001998 } else {
1999 // There is no longer an input method set, so stop any current one.
Yohei Yukawa33e81792015-11-17 21:14:42 -08002000 resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_NO_IME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 }
Yohei Yukawa3d46bab2014-05-30 18:10:18 +09002002 // Here is not the perfect place to reset the switching controller. Ideally
2003 // mSwitchingController and mSettings should be able to share the same state.
2004 // TODO: Make sure that mSwitchingController and mSettings are sharing the
2005 // the same enabled IMEs list.
2006 mSwitchingController.resetCircularListLocked(mContext);
Michael Wright7b5a96b2014-08-09 19:28:42 -07002007
2008 }
2009
2010 public void updateKeyboardFromSettingsLocked() {
2011 mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled();
2012 if (mSwitchingDialog != null
2013 && mSwitchingDialogTitleView != null
2014 && mSwitchingDialog.isShowing()) {
2015 final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById(
2016 com.android.internal.R.id.hard_keyboard_switch);
2017 hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
2018 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002019 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002020
Yohei Yukawab097b822015-12-01 10:43:08 -08002021 private void notifyInputMethodSubtypeChanged(final int userId,
2022 @Nullable final InputMethodInfo inputMethodInfo,
2023 @Nullable final InputMethodSubtype subtype) {
2024 final InputManagerInternal inputManagerInternal =
2025 LocalServices.getService(InputManagerInternal.class);
2026 if (inputManagerInternal != null) {
2027 inputManagerInternal.onInputMethodSubtypeChanged(userId, inputMethodInfo, subtype);
2028 }
2029 }
2030
satokab751aa2010-09-14 19:17:36 +09002031 /* package */ void setInputMethodLocked(String id, int subtypeId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032 InputMethodInfo info = mMethodMap.get(id);
2033 if (info == null) {
satok913a8922010-08-26 21:53:41 +09002034 throw new IllegalArgumentException("Unknown id: " + id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002035 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002036
satokd81e9502012-05-21 12:58:45 +09002037 // See if we need to notify a subtype change within the same IME.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 if (id.equals(mCurMethodId)) {
satokd81e9502012-05-21 12:58:45 +09002039 final int subtypeCount = info.getSubtypeCount();
2040 if (subtypeCount <= 0) {
2041 return;
satokcd7cd292010-11-20 15:46:23 +09002042 }
satokd81e9502012-05-21 12:58:45 +09002043 final InputMethodSubtype oldSubtype = mCurrentSubtype;
2044 final InputMethodSubtype newSubtype;
2045 if (subtypeId >= 0 && subtypeId < subtypeCount) {
2046 newSubtype = info.getSubtypeAt(subtypeId);
2047 } else {
2048 // If subtype is null, try to find the most applicable one from
2049 // getCurrentInputMethodSubtype.
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002050 newSubtype = getCurrentInputMethodSubtypeLocked();
satokd81e9502012-05-21 12:58:45 +09002051 }
2052 if (newSubtype == null || oldSubtype == null) {
2053 Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype
2054 + ", new subtype = " + newSubtype);
2055 return;
2056 }
2057 if (newSubtype != oldSubtype) {
2058 setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true);
2059 if (mCurMethod != null) {
2060 try {
Seigo Nonakad9eb9112015-05-26 20:54:43 +09002061 updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition);
satokd81e9502012-05-21 12:58:45 +09002062 mCurMethod.changeInputMethodSubtype(newSubtype);
2063 } catch (RemoteException e) {
2064 Slog.w(TAG, "Failed to call changeInputMethodSubtype");
Yohei Yukawab097b822015-12-01 10:43:08 -08002065 return;
satokab751aa2010-09-14 19:17:36 +09002066 }
2067 }
Yohei Yukawab097b822015-12-01 10:43:08 -08002068 notifyInputMethodSubtypeChanged(mSettings.getCurrentUserId(), info, newSubtype);
satokab751aa2010-09-14 19:17:36 +09002069 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002070 return;
2071 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002072
satokd81e9502012-05-21 12:58:45 +09002073 // Changing to a different IME.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 final long ident = Binder.clearCallingIdentity();
2075 try {
satokab751aa2010-09-14 19:17:36 +09002076 // Set a subtype to this input method.
2077 // subtypeId the name of a subtype which will be set.
satok723a27e2010-11-11 14:58:11 +09002078 setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false);
2079 // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked()
2080 // because mCurMethodId is stored as a history in
2081 // setSelectedInputMethodAndSubtypeLocked().
2082 mCurMethodId = id;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002083
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07002084 if (LocalServices.getService(ActivityManagerInternal.class).isSystemReady()) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002085 Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED);
Dianne Hackborn1c633fc2009-12-08 19:45:14 -08002086 intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087 intent.putExtra("input_method_id", id);
Amith Yamasanicd757062012-10-19 18:23:52 -07002088 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002089 }
Yohei Yukawa33e81792015-11-17 21:14:42 -08002090 unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_SWITCH_IME);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 } finally {
2092 Binder.restoreCallingIdentity(ident);
2093 }
Yohei Yukawab097b822015-12-01 10:43:08 -08002094
2095 notifyInputMethodSubtypeChanged(mSettings.getCurrentUserId(), info,
2096 getCurrentInputMethodSubtypeLocked());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002097 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002098
satok42c5a162011-05-26 16:46:14 +09002099 @Override
The Android Open Source Project4df24232009-03-05 14:34:35 -08002100 public boolean showSoftInput(IInputMethodClient client, int flags,
2101 ResultReceiver resultReceiver) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002102 if (!calledFromValidUser()) {
2103 return false;
2104 }
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002105 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002106 long ident = Binder.clearCallingIdentity();
2107 try {
2108 synchronized (mMethodMap) {
2109 if (mCurClient == null || client == null
2110 || mCurClient.client.asBinder() != client.asBinder()) {
2111 try {
2112 // We need to check if this is the current client with
2113 // focus in the window manager, to allow this call to
2114 // be made before input is started in it.
2115 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002116 Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client);
The Android Open Source Project4df24232009-03-05 14:34:35 -08002117 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002118 }
2119 } catch (RemoteException e) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08002120 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002121 }
2122 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002123
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002124 if (DEBUG) Slog.v(TAG, "Client requesting input be shown");
The Android Open Source Project4df24232009-03-05 14:34:35 -08002125 return showCurrentInputLocked(flags, resultReceiver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 }
2127 } finally {
2128 Binder.restoreCallingIdentity(ident);
2129 }
2130 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002131
The Android Open Source Project4df24232009-03-05 14:34:35 -08002132 boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 mShowRequested = true;
Anna Galusza9b278112016-01-04 11:37:37 -08002134 if (mAccessibilityRequestingNoSoftKeyboard) {
2135 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002136 }
Anna Galusza9b278112016-01-04 11:37:37 -08002137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 if ((flags&InputMethodManager.SHOW_FORCED) != 0) {
2139 mShowExplicitlyRequested = true;
2140 mShowForced = true;
Anna Galusza9b278112016-01-04 11:37:37 -08002141 } else if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) {
2142 mShowExplicitlyRequested = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002143 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002144
Dianne Hackborncc278702009-09-02 23:07:23 -07002145 if (!mSystemReady) {
2146 return false;
2147 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002148
The Android Open Source Project4df24232009-03-05 14:34:35 -08002149 boolean res = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002150 if (mCurMethod != null) {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002151 if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken);
The Android Open Source Project4df24232009-03-05 14:34:35 -08002152 executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO(
2153 MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod,
2154 resultReceiver));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002155 mInputShown = true;
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07002156 if (mHaveConnection && !mVisibleBound) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002157 bindCurrentInputMethodService(
Dianne Hackbornf0f94d12014-03-17 16:04:21 -07002158 mCurIntent, mVisibleConnection, Context.BIND_AUTO_CREATE
Dianne Hackbornd69e4c12015-04-24 09:54:54 -07002159 | Context.BIND_TREAT_LIKE_ACTIVITY
2160 | Context.BIND_FOREGROUND_SERVICE);
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07002161 mVisibleBound = true;
2162 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002163 res = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002164 } else if (mHaveConnection && SystemClock.uptimeMillis()
satok59b424c2011-09-30 17:21:46 +09002165 >= (mLastBindTime+TIME_TO_RECONNECT)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002166 // The client has asked to have the input method shown, but
2167 // we have been sitting here too long with a connection to the
2168 // service and no interface received, so let's disconnect/connect
2169 // to try to prod things along.
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002170 EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 SystemClock.uptimeMillis()-mLastBindTime,1);
satok59b424c2011-09-30 17:21:46 +09002172 Slog.w(TAG, "Force disconnect/connect to the IME in showCurrentInputLocked()");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 mContext.unbindService(this);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002174 bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07002175 | Context.BIND_NOT_VISIBLE);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002176 } else {
2177 if (DEBUG) {
2178 Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = "
2179 + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis()));
2180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002182
The Android Open Source Project4df24232009-03-05 14:34:35 -08002183 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002185
satok42c5a162011-05-26 16:46:14 +09002186 @Override
The Android Open Source Project4df24232009-03-05 14:34:35 -08002187 public boolean hideSoftInput(IInputMethodClient client, int flags,
2188 ResultReceiver resultReceiver) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002189 if (!calledFromValidUser()) {
2190 return false;
2191 }
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002192 int uid = Binder.getCallingUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002193 long ident = Binder.clearCallingIdentity();
2194 try {
2195 synchronized (mMethodMap) {
2196 if (mCurClient == null || client == null
2197 || mCurClient.client.asBinder() != client.asBinder()) {
2198 try {
2199 // We need to check if this is the current client with
2200 // focus in the window manager, to allow this call to
2201 // be made before input is started in it.
2202 if (!mIWindowManager.inputMethodClientHasFocus(client)) {
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002203 if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid "
2204 + uid + ": " + client);
The Android Open Source Project4df24232009-03-05 14:34:35 -08002205 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206 }
2207 } catch (RemoteException e) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08002208 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002209 }
2210 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002211
Joe Onorato8a9b2202010-02-26 18:56:32 -08002212 if (DEBUG) Slog.v(TAG, "Client requesting input be hidden");
The Android Open Source Project4df24232009-03-05 14:34:35 -08002213 return hideCurrentInputLocked(flags, resultReceiver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 }
2215 } finally {
2216 Binder.restoreCallingIdentity(ident);
2217 }
2218 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002219
The Android Open Source Project4df24232009-03-05 14:34:35 -08002220 boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002221 if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0
2222 && (mShowExplicitlyRequested || mShowForced)) {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002223 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 -08002224 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002225 }
2226 if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002227 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 -08002228 return false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002229 }
Seigo Nonakaec928652015-06-10 15:31:20 +09002230
2231 // There is a chance that IMM#hideSoftInput() is called in a transient state where
2232 // IMMS#InputShown is already updated to be true whereas IMMS#mImeWindowVis is still waiting
2233 // to be updated with the new value sent from IME process. Even in such a transient state
2234 // historically we have accepted an incoming call of IMM#hideSoftInput() from the
2235 // application process as a valid request, and have even promised such a behavior with CTS
2236 // since Android Eclair. That's why we need to accept IMM#hideSoftInput() even when only
2237 // IMMS#InputShown indicates that the software keyboard is shown.
2238 // TODO: Clean up, IMMS#mInputShown, IMMS#mImeWindowVis and mShowRequested.
2239 final boolean shouldHideSoftInput = (mCurMethod != null) && (mInputShown ||
2240 (mImeWindowVis & InputMethodService.IME_ACTIVE) != 0);
The Android Open Source Project4df24232009-03-05 14:34:35 -08002241 boolean res;
Seigo Nonakaec928652015-06-10 15:31:20 +09002242 if (shouldHideSoftInput) {
2243 // The IME will report its visible state again after the following message finally
2244 // delivered to the IME process as an IPC. Hence the inconsistency between
2245 // IMMS#mInputShown and IMMS#mImeWindowVis should be resolved spontaneously in
2246 // the final state.
The Android Open Source Project4df24232009-03-05 14:34:35 -08002247 executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
2248 MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver));
2249 res = true;
2250 } else {
2251 res = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002252 }
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -07002253 if (mHaveConnection && mVisibleBound) {
2254 mContext.unbindService(mVisibleConnection);
2255 mVisibleBound = false;
2256 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 mInputShown = false;
2258 mShowRequested = false;
2259 mShowExplicitlyRequested = false;
2260 mShowForced = false;
The Android Open Source Project4df24232009-03-05 14:34:35 -08002261 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002263
satok42c5a162011-05-26 16:46:14 +09002264 @Override
Yohei Yukawa05c25f82016-02-22 12:41:17 -08002265 public InputBindResult startInputOrWindowGainedFocus(
2266 /* @InputMethodClient.StartInputReason */ final int startInputReason,
2267 IInputMethodClient client, IBinder windowToken, int controlFlags, int softInputMode,
Yohei Yukawa74750f22016-03-22 12:54:22 -07002268 int windowFlags, @Nullable EditorInfo attribute, IInputContext inputContext,
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002269 /* @InputConnectionInspector.missingMethods */ final int missingMethods) {
Yohei Yukawa05c25f82016-02-22 12:41:17 -08002270 if (windowToken != null) {
2271 return windowGainedFocus(startInputReason, client, windowToken, controlFlags,
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002272 softInputMode, windowFlags, attribute, inputContext, missingMethods);
Yohei Yukawa05c25f82016-02-22 12:41:17 -08002273 } else {
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002274 return startInput(startInputReason, client, inputContext, missingMethods, attribute,
2275 controlFlags);
Yohei Yukawa05c25f82016-02-22 12:41:17 -08002276 }
2277 }
2278
2279 private InputBindResult windowGainedFocus(
Yohei Yukawa35d3f372015-11-25 11:07:19 -08002280 /* @InputMethodClient.StartInputReason */ final int startInputReason,
2281 IInputMethodClient client, IBinder windowToken, int controlFlags, int softInputMode,
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002282 int windowFlags, EditorInfo attribute, IInputContext inputContext,
2283 /* @InputConnectionInspector.missingMethods */ final int missingMethods) {
Satoshi Kataoka8d033052012-11-19 17:30:40 +09002284 // Needs to check the validity before clearing calling identity
2285 final boolean calledFromValidUser = calledFromValidUser();
Dianne Hackborn7663d802012-02-24 13:08:49 -08002286 InputBindResult res = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 long ident = Binder.clearCallingIdentity();
2288 try {
2289 synchronized (mMethodMap) {
Yohei Yukawa35d3f372015-11-25 11:07:19 -08002290 if (DEBUG) Slog.v(TAG, "windowGainedFocus: reason="
2291 + InputMethodClient.getStartInputReason(startInputReason)
2292 + " client=" + client.asBinder()
2293 + " inputContext=" + inputContext
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002294 + " missingMethods="
2295 + InputConnectionInspector.getMissingMethodFlagsAsString(missingMethods)
Yohei Yukawa35d3f372015-11-25 11:07:19 -08002296 + " attribute=" + attribute
Dianne Hackborn7663d802012-02-24 13:08:49 -08002297 + " controlFlags=#" + Integer.toHexString(controlFlags)
Yohei Yukawa22a89232017-02-12 16:38:59 -08002298 + " softInputMode=" + InputMethodClient.softInputModeToString(softInputMode)
Dianne Hackborn7663d802012-02-24 13:08:49 -08002299 + " windowFlags=#" + Integer.toHexString(windowFlags));
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002300
Dianne Hackborn7663d802012-02-24 13:08:49 -08002301 ClientState cs = mClients.get(client.asBinder());
2302 if (cs == null) {
2303 throw new IllegalArgumentException("unknown client "
2304 + client.asBinder());
2305 }
2306
2307 try {
2308 if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
2309 // Check with the window manager to make sure this client actually
2310 // has a window with focus. If not, reject. This is thread safe
2311 // because if the focus changes some time before or after, the
2312 // next client receiving focus that has any interest in input will
2313 // be calling through here after that change happens.
Yohei Yukawad0332832017-02-01 13:59:43 -08002314 if (DEBUG) {
2315 Slog.w(TAG, "Focus gain on non-focused client " + cs.client
2316 + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
2317 }
Dianne Hackborn7663d802012-02-24 13:08:49 -08002318 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002319 }
Dianne Hackborn7663d802012-02-24 13:08:49 -08002320 } catch (RemoteException e) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002322
Satoshi Kataoka8d033052012-11-19 17:30:40 +09002323 if (!calledFromValidUser) {
2324 Slog.w(TAG, "A background user is requesting window. Hiding IME.");
2325 Slog.w(TAG, "If you want to interect with IME, you need "
2326 + "android.permission.INTERACT_ACROSS_USERS_FULL");
2327 hideCurrentInputLocked(0, null);
2328 return null;
2329 }
2330
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07002331 if (mCurFocusedWindow == windowToken) {
Yohei Yukawad0332832017-02-01 13:59:43 -08002332 if (DEBUG) {
2333 Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client
2334 + " attribute=" + attribute + ", token = " + windowToken);
2335 }
Dianne Hackborn7663d802012-02-24 13:08:49 -08002336 if (attribute != null) {
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002337 return startInputUncheckedLocked(cs, inputContext, missingMethods,
Yohei Yukawa87ca8402017-02-07 00:13:14 -08002338 attribute, controlFlags, startInputReason);
Dianne Hackborn7663d802012-02-24 13:08:49 -08002339 }
2340 return null;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07002341 }
2342 mCurFocusedWindow = windowToken;
Yohei Yukawa22a89232017-02-12 16:38:59 -08002343 mCurFocusedWindowSoftInputMode = softInputMode;
Yohei Yukawae39d4ed2015-11-19 03:38:49 -08002344 mCurFocusedWindowClient = cs;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002345
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002346 // Should we auto-show the IME even if the caller has not
2347 // specified what should be done with it?
2348 // We only do this automatically if the window can resize
2349 // to accommodate the IME (so what the user sees will give
2350 // them good context without input information being obscured
2351 // by the IME) or if running on a large screen where there
2352 // is more room for the target window + IME.
2353 final boolean doAutoShow =
2354 (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
2355 == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
2356 || mRes.getConfiguration().isLayoutSizeAtLeast(
2357 Configuration.SCREENLAYOUT_SIZE_LARGE);
Dianne Hackborn7663d802012-02-24 13:08:49 -08002358 final boolean isTextEditor =
2359 (controlFlags&InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0;
2360
2361 // We want to start input before showing the IME, but after closing
2362 // it. We want to do this after closing it to help the IME disappear
2363 // more quickly (not get stuck behind it initializing itself for the
2364 // new focused input, even if its window wants to hide the IME).
2365 boolean didStart = false;
Yohei Yukawa0f3ad12015-04-06 16:48:24 -07002366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) {
2368 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002369 if (!isTextEditor || !doAutoShow) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002370 if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) {
2371 // There is no focus view, and this window will
2372 // be behind any soft input window, so hide the
2373 // soft input window if it is shown.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002374 if (DEBUG) Slog.v(TAG, "Unspecified window will hide input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08002375 hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376 }
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002377 } else if (isTextEditor && doAutoShow && (softInputMode &
2378 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002379 // There is a focus view, and we are navigating forward
2380 // into the window, so show the input window for the user.
Dianne Hackborn7663d802012-02-24 13:08:49 -08002381 // We only do this automatically if the window can resize
2382 // to accommodate the IME (so what the user sees will give
Dianne Hackborn7d3a5bc2010-11-29 22:52:12 -08002383 // them good context without input information being obscured
2384 // by the IME) or if running on a large screen where there
2385 // is more room for the target window + IME.
Joe Onorato8a9b2202010-02-26 18:56:32 -08002386 if (DEBUG) Slog.v(TAG, "Unspecified window will show input");
Dianne Hackborn7663d802012-02-24 13:08:49 -08002387 if (attribute != null) {
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002388 res = startInputUncheckedLocked(cs, inputContext,
Yohei Yukawa87ca8402017-02-07 00:13:14 -08002389 missingMethods, attribute, controlFlags, startInputReason);
Dianne Hackborn7663d802012-02-24 13:08:49 -08002390 didStart = true;
2391 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002392 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 }
2394 break;
2395 case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
2396 // Do nothing.
2397 break;
2398 case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN:
2399 if ((softInputMode &
2400 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002401 if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward");
The Android Open Source Project4df24232009-03-05 14:34:35 -08002402 hideCurrentInputLocked(0, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 }
2404 break;
2405 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
Joe Onorato8a9b2202010-02-26 18:56:32 -08002406 if (DEBUG) Slog.v(TAG, "Window asks to hide input");
The Android Open Source Project4df24232009-03-05 14:34:35 -08002407 hideCurrentInputLocked(0, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 break;
2409 case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
2410 if ((softInputMode &
2411 WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002412 if (DEBUG) Slog.v(TAG, "Window asks to show input going forward");
Dianne Hackborn7663d802012-02-24 13:08:49 -08002413 if (attribute != null) {
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002414 res = startInputUncheckedLocked(cs, inputContext,
Yohei Yukawa87ca8402017-02-07 00:13:14 -08002415 missingMethods, attribute, controlFlags, startInputReason);
Dianne Hackborn7663d802012-02-24 13:08:49 -08002416 didStart = true;
2417 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002418 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002419 }
2420 break;
2421 case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
Joe Onorato8a9b2202010-02-26 18:56:32 -08002422 if (DEBUG) Slog.v(TAG, "Window asks to always show input");
Dianne Hackborn7663d802012-02-24 13:08:49 -08002423 if (attribute != null) {
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002424 res = startInputUncheckedLocked(cs, inputContext, missingMethods,
Yohei Yukawa87ca8402017-02-07 00:13:14 -08002425 attribute, controlFlags, startInputReason);
Dianne Hackborn7663d802012-02-24 13:08:49 -08002426 didStart = true;
2427 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002428 showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002429 break;
2430 }
Dianne Hackborn7663d802012-02-24 13:08:49 -08002431
2432 if (!didStart && attribute != null) {
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002433 res = startInputUncheckedLocked(cs, inputContext, missingMethods, attribute,
Yohei Yukawa87ca8402017-02-07 00:13:14 -08002434 controlFlags, startInputReason);
Dianne Hackborn7663d802012-02-24 13:08:49 -08002435 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002436 }
2437 } finally {
2438 Binder.restoreCallingIdentity(ident);
2439 }
Dianne Hackborn7663d802012-02-24 13:08:49 -08002440
2441 return res;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002442 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002443
satok42c5a162011-05-26 16:46:14 +09002444 @Override
Seigo Nonaka14e13912015-05-06 21:04:13 -07002445 public void showInputMethodPickerFromClient(
2446 IInputMethodClient client, int auxiliarySubtypeMode) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002447 if (!calledFromValidUser()) {
2448 return;
2449 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002450 synchronized (mMethodMap) {
2451 if (mCurClient == null || client == null
2452 || mCurClient.client.asBinder() != client.asBinder()) {
satok47a44912010-10-06 16:03:58 +09002453 Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid "
Dianne Hackborncef65ee2010-09-30 18:27:22 -07002454 + Binder.getCallingUid() + ": " + client);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 }
2456
satok440aab52010-11-25 09:43:11 +09002457 // Always call subtype picker, because subtype picker is a superset of input method
2458 // picker.
Seigo Nonaka14e13912015-05-06 21:04:13 -07002459 mHandler.sendMessage(mCaller.obtainMessageI(
2460 MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode));
satokab751aa2010-09-14 19:17:36 +09002461 }
2462 }
2463
satok42c5a162011-05-26 16:46:14 +09002464 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 public void setInputMethod(IBinder token, String id) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002466 if (!calledFromValidUser()) {
2467 return;
2468 }
satok28203512010-11-24 11:06:49 +09002469 setInputMethodWithSubtypeId(token, id, NOT_A_SUBTYPE_ID);
2470 }
2471
satok42c5a162011-05-26 16:46:14 +09002472 @Override
satok28203512010-11-24 11:06:49 +09002473 public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002474 if (!calledFromValidUser()) {
2475 return;
2476 }
satok28203512010-11-24 11:06:49 +09002477 synchronized (mMethodMap) {
2478 if (subtype != null) {
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002479 setInputMethodWithSubtypeIdLocked(token, id,
2480 InputMethodUtils.getSubtypeIdFromHashCode(mMethodMap.get(id),
2481 subtype.hashCode()));
satok28203512010-11-24 11:06:49 +09002482 } else {
2483 setInputMethod(token, id);
2484 }
2485 }
satokab751aa2010-09-14 19:17:36 +09002486 }
2487
satok42c5a162011-05-26 16:46:14 +09002488 @Override
satokb416a712010-11-25 20:42:14 +09002489 public void showInputMethodAndSubtypeEnablerFromClient(
satok217f5482010-12-15 05:19:19 +09002490 IInputMethodClient client, String inputMethodId) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002491 if (!calledFromValidUser()) {
2492 return;
2493 }
satokb416a712010-11-25 20:42:14 +09002494 synchronized (mMethodMap) {
satok7fee71f2010-12-17 18:54:26 +09002495 executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
2496 MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId));
satokb416a712010-11-25 20:42:14 +09002497 }
2498 }
2499
satok4fc87d62011-05-20 16:13:43 +09002500 @Override
satok735cf382010-11-11 20:40:09 +09002501 public boolean switchToLastInputMethod(IBinder token) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002502 if (!calledFromValidUser()) {
2503 return false;
2504 }
satok735cf382010-11-11 20:40:09 +09002505 synchronized (mMethodMap) {
satokc445bcd2011-01-25 18:57:24 +09002506 final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
satok4fc87d62011-05-20 16:13:43 +09002507 final InputMethodInfo lastImi;
satok208d5632011-05-20 22:13:38 +09002508 if (lastIme != null) {
satok4fc87d62011-05-20 16:13:43 +09002509 lastImi = mMethodMap.get(lastIme.first);
2510 } else {
2511 lastImi = null;
satok735cf382010-11-11 20:40:09 +09002512 }
satok4fc87d62011-05-20 16:13:43 +09002513 String targetLastImiId = null;
2514 int subtypeId = NOT_A_SUBTYPE_ID;
2515 if (lastIme != null && lastImi != null) {
2516 final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId);
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002517 final int lastSubtypeHash = Integer.parseInt(lastIme.second);
satok4fc87d62011-05-20 16:13:43 +09002518 final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID
2519 : mCurrentSubtype.hashCode();
2520 // If the last IME is the same as the current IME and the last subtype is not
2521 // defined, there is no need to switch to the last IME.
2522 if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) {
2523 targetLastImiId = lastIme.first;
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002524 subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
satok4fc87d62011-05-20 16:13:43 +09002525 }
2526 }
2527
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002528 if (TextUtils.isEmpty(targetLastImiId)
2529 && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) {
satok4fc87d62011-05-20 16:13:43 +09002530 // This is a safety net. If the currentSubtype can't be added to the history
2531 // and the framework couldn't find the last ime, we will make the last ime be
2532 // the most applicable enabled keyboard subtype of the system imes.
2533 final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
2534 if (enabled != null) {
2535 final int N = enabled.size();
2536 final String locale = mCurrentSubtype == null
2537 ? mRes.getConfiguration().locale.toString()
2538 : mCurrentSubtype.getLocale();
2539 for (int i = 0; i < N; ++i) {
2540 final InputMethodInfo imi = enabled.get(i);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002541 if (imi.getSubtypeCount() > 0 && InputMethodUtils.isSystemIme(imi)) {
satok4fc87d62011-05-20 16:13:43 +09002542 InputMethodSubtype keyboardSubtype =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002543 InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes,
2544 InputMethodUtils.getSubtypes(imi),
2545 InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true);
satok4fc87d62011-05-20 16:13:43 +09002546 if (keyboardSubtype != null) {
2547 targetLastImiId = imi.getId();
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002548 subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
satok4fc87d62011-05-20 16:13:43 +09002549 imi, keyboardSubtype.hashCode());
2550 if(keyboardSubtype.getLocale().equals(locale)) {
2551 break;
2552 }
2553 }
2554 }
2555 }
2556 }
2557 }
2558
2559 if (!TextUtils.isEmpty(targetLastImiId)) {
2560 if (DEBUG) {
2561 Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second
2562 + ", from: " + mCurMethodId + ", " + subtypeId);
2563 }
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002564 setInputMethodWithSubtypeIdLocked(token, targetLastImiId, subtypeId);
satok4fc87d62011-05-20 16:13:43 +09002565 return true;
2566 } else {
2567 return false;
2568 }
satok735cf382010-11-11 20:40:09 +09002569 }
2570 }
2571
satoke7c6998e2011-06-03 17:57:59 +09002572 @Override
satok688bd472012-02-09 20:09:17 +09002573 public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002574 if (!calledFromValidUser()) {
2575 return false;
2576 }
satok688bd472012-02-09 20:09:17 +09002577 synchronized (mMethodMap) {
Yohei Yukawaa0755742014-06-04 20:28:18 +09002578 if (!calledWithValidToken(token)) {
Yohei Yukawaa0755742014-06-04 20:28:18 +09002579 return false;
2580 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002581 final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
Yohei Yukawad39ae852016-04-10 20:28:40 -07002582 onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype,
2583 true /* forward */);
satok688bd472012-02-09 20:09:17 +09002584 if (nextSubtype == null) {
2585 return false;
2586 }
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002587 setInputMethodWithSubtypeIdLocked(token, nextSubtype.mImi.getId(),
2588 nextSubtype.mSubtypeId);
satok688bd472012-02-09 20:09:17 +09002589 return true;
2590 }
2591 }
2592
2593 @Override
Satoshi Kataoka2b10b522013-08-21 20:39:12 +09002594 public boolean shouldOfferSwitchingToNextInputMethod(IBinder token) {
2595 if (!calledFromValidUser()) {
2596 return false;
2597 }
2598 synchronized (mMethodMap) {
Yohei Yukawaa0755742014-06-04 20:28:18 +09002599 if (!calledWithValidToken(token)) {
Yohei Yukawaa0755742014-06-04 20:28:18 +09002600 return false;
2601 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002602 final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
Yohei Yukawad39ae852016-04-10 20:28:40 -07002603 false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype,
2604 true /* forward */);
Satoshi Kataoka2b10b522013-08-21 20:39:12 +09002605 if (nextSubtype == null) {
2606 return false;
2607 }
2608 return true;
2609 }
2610 }
2611
2612 @Override
satok68f1b782011-04-11 14:26:04 +09002613 public InputMethodSubtype getLastInputMethodSubtype() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002614 if (!calledFromValidUser()) {
2615 return null;
2616 }
satok68f1b782011-04-11 14:26:04 +09002617 synchronized (mMethodMap) {
2618 final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
2619 // TODO: Handle the case of the last IME with no subtypes
2620 if (lastIme == null || TextUtils.isEmpty(lastIme.first)
2621 || TextUtils.isEmpty(lastIme.second)) return null;
2622 final InputMethodInfo lastImi = mMethodMap.get(lastIme.first);
2623 if (lastImi == null) return null;
2624 try {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01002625 final int lastSubtypeHash = Integer.parseInt(lastIme.second);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09002626 final int lastSubtypeId =
2627 InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
satok0e7d7d62011-07-05 13:28:06 +09002628 if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) {
2629 return null;
2630 }
2631 return lastImi.getSubtypeAt(lastSubtypeId);
satok68f1b782011-04-11 14:26:04 +09002632 } catch (NumberFormatException e) {
2633 return null;
2634 }
2635 }
2636 }
2637
satoke7c6998e2011-06-03 17:57:59 +09002638 @Override
satokee5e77c2011-09-02 18:50:15 +09002639 public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002640 if (!calledFromValidUser()) {
2641 return;
2642 }
satok91e88122011-07-18 11:11:42 +09002643 // By this IPC call, only a process which shares the same uid with the IME can add
2644 // additional input method subtypes to the IME.
Yohei Yukawa70f5c482016-01-04 19:42:36 -08002645 if (TextUtils.isEmpty(imiId) || subtypes == null) return;
satoke7c6998e2011-06-03 17:57:59 +09002646 synchronized (mMethodMap) {
Yohei Yukawa79247822017-01-23 15:26:15 -08002647 if (!mSystemReady) {
2648 return;
2649 }
satok91e88122011-07-18 11:11:42 +09002650 final InputMethodInfo imi = mMethodMap.get(imiId);
satokee5e77c2011-09-02 18:50:15 +09002651 if (imi == null) return;
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002652 final String[] packageInfos;
2653 try {
2654 packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid());
2655 } catch (RemoteException e) {
2656 Slog.e(TAG, "Failed to get package infos");
2657 return;
2658 }
satok91e88122011-07-18 11:11:42 +09002659 if (packageInfos != null) {
2660 final int packageNum = packageInfos.length;
2661 for (int i = 0; i < packageNum; ++i) {
2662 if (packageInfos[i].equals(imi.getPackageName())) {
2663 mFileManager.addInputMethodSubtypes(imi, subtypes);
satokc5933802011-08-31 21:26:04 +09002664 final long ident = Binder.clearCallingIdentity();
2665 try {
Yohei Yukawa94e33302016-02-12 19:37:03 -08002666 buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
satokc5933802011-08-31 21:26:04 +09002667 } finally {
2668 Binder.restoreCallingIdentity(ident);
2669 }
satokee5e77c2011-09-02 18:50:15 +09002670 return;
satok91e88122011-07-18 11:11:42 +09002671 }
2672 }
2673 }
satoke7c6998e2011-06-03 17:57:59 +09002674 }
satokee5e77c2011-09-02 18:50:15 +09002675 return;
satoke7c6998e2011-06-03 17:57:59 +09002676 }
2677
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09002678 @Override
2679 public int getInputMethodWindowVisibleHeight() {
Seigo Nonaka7309b122015-08-17 18:34:13 -07002680 return mWindowManagerInternal.getInputMethodWindowVisibleHeight();
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09002681 }
2682
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002683 @Override
Yohei Yukawa833bdce2016-05-15 20:05:56 -07002684 public void clearLastInputMethodWindowForTransition(IBinder token) {
2685 if (!calledFromValidUser()) {
2686 return;
2687 }
Yohei Yukawafa49c002017-01-31 19:15:00 -08002688 synchronized (mMethodMap) {
2689 if (!calledWithValidToken(token)) {
Yohei Yukawafa49c002017-01-31 19:15:00 -08002690 return;
Yohei Yukawa833bdce2016-05-15 20:05:56 -07002691 }
Yohei Yukawa833bdce2016-05-15 20:05:56 -07002692 }
Yohei Yukawafa49c002017-01-31 19:15:00 -08002693 mWindowManagerInternal.clearLastInputMethodWindowForTransition();
Yohei Yukawa833bdce2016-05-15 20:05:56 -07002694 }
2695
2696 @Override
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002697 public void notifyUserAction(int sequenceNumber) {
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002698 if (DEBUG) {
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002699 Slog.d(TAG, "Got the notification of a user action. sequenceNumber:" + sequenceNumber);
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002700 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002701 synchronized (mMethodMap) {
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002702 if (mCurUserActionNotificationSequenceNumber != sequenceNumber) {
2703 if (DEBUG) {
2704 Slog.d(TAG, "Ignoring the user action notification due to the sequence number "
2705 + "mismatch. expected:" + mCurUserActionNotificationSequenceNumber
2706 + " actual: " + sequenceNumber);
2707 }
2708 return;
2709 }
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002710 final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
2711 if (imi != null) {
Yohei Yukawa02970512014-06-05 16:16:18 +09002712 mSwitchingController.onUserActionLocked(imi, mCurrentSubtype);
Yohei Yukawa5a647b692014-05-22 12:49:00 +09002713 }
Satoshi Kataokad7443c82013-10-15 17:45:43 +09002714 }
2715 }
2716
satok28203512010-11-24 11:06:49 +09002717 private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002718 synchronized (mMethodMap) {
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002719 setInputMethodWithSubtypeIdLocked(token, id, subtypeId);
2720 }
2721 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002722
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002723 private void setInputMethodWithSubtypeIdLocked(IBinder token, String id, int subtypeId) {
2724 if (token == null) {
2725 if (mContext.checkCallingOrSelfPermission(
2726 android.Manifest.permission.WRITE_SECURE_SETTINGS)
2727 != PackageManager.PERMISSION_GRANTED) {
2728 throw new SecurityException(
2729 "Using null token requires permission "
2730 + android.Manifest.permission.WRITE_SECURE_SETTINGS);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 }
Yohei Yukawa4e02bc62014-06-04 18:37:20 +09002732 } else if (mCurToken != token) {
2733 Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid()
2734 + " token: " + token);
2735 return;
2736 }
2737
2738 final long ident = Binder.clearCallingIdentity();
2739 try {
2740 setInputMethodLocked(id, subtypeId);
2741 } finally {
2742 Binder.restoreCallingIdentity(ident);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743 }
2744 }
2745
satok42c5a162011-05-26 16:46:14 +09002746 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747 public void hideMySoftInput(IBinder token, int flags) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002748 if (!calledFromValidUser()) {
2749 return;
2750 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 synchronized (mMethodMap) {
Yohei Yukawa22c97be2014-06-04 19:43:36 +09002752 if (!calledWithValidToken(token)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002753 return;
2754 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002755 long ident = Binder.clearCallingIdentity();
2756 try {
The Android Open Source Project4df24232009-03-05 14:34:35 -08002757 hideCurrentInputLocked(flags, null);
2758 } finally {
2759 Binder.restoreCallingIdentity(ident);
2760 }
2761 }
2762 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002763
satok42c5a162011-05-26 16:46:14 +09002764 @Override
The Android Open Source Project4df24232009-03-05 14:34:35 -08002765 public void showMySoftInput(IBinder token, int flags) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09002766 if (!calledFromValidUser()) {
2767 return;
2768 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08002769 synchronized (mMethodMap) {
Yohei Yukawa22c97be2014-06-04 19:43:36 +09002770 if (!calledWithValidToken(token)) {
The Android Open Source Project4df24232009-03-05 14:34:35 -08002771 return;
2772 }
2773 long ident = Binder.clearCallingIdentity();
2774 try {
2775 showCurrentInputLocked(flags, null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 } finally {
2777 Binder.restoreCallingIdentity(ident);
2778 }
2779 }
2780 }
2781
2782 void setEnabledSessionInMainThread(SessionState session) {
2783 if (mEnabledSession != session) {
Yohei Yukawa9d91b432014-05-19 16:03:24 +09002784 if (mEnabledSession != null && mEnabledSession.session != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002785 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002786 if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession);
Yohei Yukawa9d91b432014-05-19 16:03:24 +09002787 mEnabledSession.method.setSessionEnabled(mEnabledSession.session, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788 } catch (RemoteException e) {
2789 }
2790 }
2791 mEnabledSession = session;
Yohei Yukawa9d91b432014-05-19 16:03:24 +09002792 if (mEnabledSession != null && mEnabledSession.session != null) {
2793 try {
2794 if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession);
2795 mEnabledSession.method.setSessionEnabled(mEnabledSession.session, true);
2796 } catch (RemoteException e) {
2797 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 }
2799 }
2800 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002801
satok42c5a162011-05-26 16:46:14 +09002802 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 public boolean handleMessage(Message msg) {
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002804 SomeArgs args;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805 switch (msg.what) {
satokab751aa2010-09-14 19:17:36 +09002806 case MSG_SHOW_IM_SUBTYPE_PICKER:
Seigo Nonaka14e13912015-05-06 21:04:13 -07002807 final boolean showAuxSubtypes;
2808 switch (msg.arg1) {
2809 case InputMethodManager.SHOW_IM_PICKER_MODE_AUTO:
2810 // This is undocumented so far, but IMM#showInputMethodPicker() has been
2811 // implemented so that auxiliary subtypes will be excluded when the soft
2812 // keyboard is invisible.
2813 showAuxSubtypes = mInputShown;
2814 break;
2815 case InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES:
2816 showAuxSubtypes = true;
2817 break;
2818 case InputMethodManager.SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES:
2819 showAuxSubtypes = false;
2820 break;
2821 default:
2822 Slog.e(TAG, "Unknown subtype picker mode = " + msg.arg1);
2823 return false;
2824 }
2825 showInputMethodMenu(showAuxSubtypes);
satokab751aa2010-09-14 19:17:36 +09002826 return true;
2827
satok47a44912010-10-06 16:03:58 +09002828 case MSG_SHOW_IM_SUBTYPE_ENABLER:
Yohei Yukawa41f34272015-12-14 15:41:52 -08002829 showInputMethodAndSubtypeEnabler((String)msg.obj);
satok217f5482010-12-15 05:19:19 +09002830 return true;
2831
2832 case MSG_SHOW_IM_CONFIG:
2833 showConfigureInputMethods();
satok47a44912010-10-06 16:03:58 +09002834 return true;
2835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002837
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002838 case MSG_UNBIND_INPUT:
2839 try {
2840 ((IInputMethod)msg.obj).unbindInput();
2841 } catch (RemoteException e) {
2842 // There is nothing interesting about the method dying.
2843 }
2844 return true;
2845 case MSG_BIND_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002846 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 try {
2848 ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2);
2849 } catch (RemoteException e) {
2850 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002851 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 return true;
2853 case MSG_SHOW_SOFT_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002854 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002855 try {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002856 if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput("
Craig Mautner6efb4c72013-03-13 10:17:41 -07002857 + msg.arg1 + ", " + args.arg2 + ")");
Craig Mautnerca0ac712013-03-14 09:43:02 -07002858 ((IInputMethod)args.arg1).showSoftInput(msg.arg1, (ResultReceiver)args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002859 } catch (RemoteException e) {
2860 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002861 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002862 return true;
2863 case MSG_HIDE_SOFT_INPUT:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002864 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 try {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002866 if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, "
Craig Mautner6efb4c72013-03-13 10:17:41 -07002867 + args.arg2 + ")");
Craig Mautnerca0ac712013-03-14 09:43:02 -07002868 ((IInputMethod)args.arg1).hideSoftInput(0, (ResultReceiver)args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 } catch (RemoteException e) {
2870 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002871 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002872 return true;
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -07002873 case MSG_HIDE_CURRENT_INPUT_METHOD:
2874 synchronized (mMethodMap) {
2875 hideCurrentInputLocked(0, null);
2876 }
2877 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 case MSG_ATTACH_TOKEN:
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002879 args = (SomeArgs)msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 try {
Craig Mautnere4bbb1c2013-03-15 11:38:44 -07002881 if (DEBUG) Slog.v(TAG, "Sending attach of token: " + args.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2);
2883 } catch (RemoteException e) {
2884 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002885 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002886 return true;
Jeff Brownc28867a2013-03-26 15:42:39 -07002887 case MSG_CREATE_SESSION: {
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002888 args = (SomeArgs)msg.obj;
Jeff Brown1951ce82013-04-04 22:45:12 -07002889 IInputMethod method = (IInputMethod)args.arg1;
Jeff Brownc28867a2013-03-26 15:42:39 -07002890 InputChannel channel = (InputChannel)args.arg2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002891 try {
Jeff Brown1951ce82013-04-04 22:45:12 -07002892 method.createSession(channel, (IInputSessionCallback)args.arg3);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002893 } catch (RemoteException e) {
Jeff Brownc28867a2013-03-26 15:42:39 -07002894 } finally {
Jeff Brown1951ce82013-04-04 22:45:12 -07002895 // Dispose the channel if the input method is not local to this process
2896 // because the remote proxy will get its own copy when unparceled.
2897 if (channel != null && Binder.isProxy(method)) {
Jeff Brownc28867a2013-03-26 15:42:39 -07002898 channel.dispose();
2899 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002901 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 return true;
Jeff Brownc28867a2013-03-26 15:42:39 -07002903 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002905
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002906 case MSG_START_INPUT: {
2907 int missingMethods = msg.arg1;
2908 args = (SomeArgs) msg.obj;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 try {
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002910 SessionState session = (SessionState) args.arg1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 setEnabledSessionInMainThread(session);
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002912 session.method.startInput((IInputContext) args.arg2, missingMethods,
Yohei Yukawa3eaf8672017-02-11 23:40:07 +00002913 (EditorInfo) args.arg3);
2914 } catch (RemoteException e) {
2915 }
2916 args.recycle();
2917 return true;
2918 }
2919 case MSG_RESTART_INPUT: {
2920 int missingMethods = msg.arg1;
2921 args = (SomeArgs) msg.obj;
2922 try {
2923 SessionState session = (SessionState) args.arg1;
2924 setEnabledSessionInMainThread(session);
2925 session.method.restartInput((IInputContext) args.arg2, missingMethods,
2926 (EditorInfo) args.arg3);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 } catch (RemoteException e) {
2928 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002929 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 return true;
Yohei Yukawa19a80a12016-03-14 22:57:37 -07002931 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002932
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 // ---------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08002934
Yohei Yukawa33e81792015-11-17 21:14:42 -08002935 case MSG_UNBIND_CLIENT:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002936 try {
Yohei Yukawa33e81792015-11-17 21:14:42 -08002937 ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1, msg.arg2);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 } catch (RemoteException e) {
2939 // There is nothing interesting about the last client dying.
2940 }
2941 return true;
Yohei Yukawa33e81792015-11-17 21:14:42 -08002942 case MSG_BIND_CLIENT: {
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002943 args = (SomeArgs)msg.obj;
Jeff Brown1951ce82013-04-04 22:45:12 -07002944 IInputMethodClient client = (IInputMethodClient)args.arg1;
2945 InputBindResult res = (InputBindResult)args.arg2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002946 try {
Jeff Brown1951ce82013-04-04 22:45:12 -07002947 client.onBindMethod(res);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08002949 Slog.w(TAG, "Client died receiving input method " + args.arg2);
Jeff Brown1951ce82013-04-04 22:45:12 -07002950 } finally {
2951 // Dispose the channel if the input method is not local to this process
2952 // because the remote proxy will get its own copy when unparceled.
2953 if (res.channel != null && Binder.isProxy(client)) {
2954 res.channel.dispose();
2955 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 }
Svetoslav Ganov758143e2012-08-06 16:40:27 -07002957 args.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 return true;
Jeff Brown1951ce82013-04-04 22:45:12 -07002959 }
Dianne Hackborna6e41342012-05-22 16:30:34 -07002960 case MSG_SET_ACTIVE:
2961 try {
Yohei Yukawa2bc66172017-02-08 11:13:25 -08002962 ((ClientState)msg.obj).client.setActive(msg.arg1 != 0, msg.arg2 != 0);
Dianne Hackborna6e41342012-05-22 16:30:34 -07002963 } catch (RemoteException e) {
2964 Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid "
2965 + ((ClientState)msg.obj).pid + " uid "
2966 + ((ClientState)msg.obj).uid);
2967 }
2968 return true;
Yohei Yukawafa6e0a82015-07-23 15:08:59 -07002969 case MSG_SET_INTERACTIVE:
2970 handleSetInteractive(msg.arg1 != 0);
2971 return true;
Yohei Yukawaae61f712015-12-09 13:00:10 -08002972 case MSG_SWITCH_IME:
2973 handleSwitchInputMethod(msg.arg1 != 0);
2974 return true;
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002975 case MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER: {
2976 final int sequenceNumber = msg.arg1;
Yohei Yukawa080fa342014-08-31 16:10:05 -07002977 final ClientState clientState = (ClientState)msg.obj;
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002978 try {
Yohei Yukawa080fa342014-08-31 16:10:05 -07002979 clientState.client.setUserActionNotificationSequenceNumber(sequenceNumber);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002980 } catch (RemoteException e) {
2981 Slog.w(TAG, "Got RemoteException sending "
2982 + "setUserActionNotificationSequenceNumber("
2983 + sequenceNumber + ") notification to pid "
Yohei Yukawa080fa342014-08-31 16:10:05 -07002984 + clientState.pid + " uid "
2985 + clientState.uid);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09002986 }
2987 return true;
2988 }
Yohei Yukawa2bc66172017-02-08 11:13:25 -08002989 case MSG_REPORT_FULLSCREEN_MODE: {
2990 final boolean fullscreen = msg.arg1 != 0;
2991 final ClientState clientState = (ClientState)msg.obj;
2992 try {
2993 clientState.client.reportFullscreenMode(fullscreen);
2994 } catch (RemoteException e) {
2995 Slog.w(TAG, "Got RemoteException sending "
2996 + "reportFullscreen(" + fullscreen + ") notification to pid="
2997 + clientState.pid + " uid=" + clientState.uid);
2998 }
2999 return true;
3000 }
satok01038492012-04-09 21:08:27 +09003001
3002 // --------------------------------------------------------------
3003 case MSG_HARD_KEYBOARD_SWITCH_CHANGED:
Michael Wright7b5a96b2014-08-09 19:28:42 -07003004 mHardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1);
satok01038492012-04-09 21:08:27 +09003005 return true;
Fyodor Kupolov7877b8a2016-06-29 14:39:19 -07003006 case MSG_SYSTEM_UNLOCK_USER:
3007 final int userId = msg.arg1;
3008 onUnlockUser(userId);
3009 return true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 }
3011 return false;
3012 }
3013
Yohei Yukawafa6e0a82015-07-23 15:08:59 -07003014 private void handleSetInteractive(final boolean interactive) {
3015 synchronized (mMethodMap) {
3016 mIsInteractive = interactive;
3017 updateSystemUiLocked(mCurToken, interactive ? mImeWindowVis : 0, mBackDisposition);
3018
3019 // Inform the current client of the change in active status
3020 if (mCurClient != null && mCurClient.client != null) {
Yohei Yukawa2bc66172017-02-08 11:13:25 -08003021 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO(
3022 MSG_SET_ACTIVE, mIsInteractive ? 1 : 0, mInFullscreenMode ? 1 : 0,
3023 mCurClient));
Yohei Yukawafa6e0a82015-07-23 15:08:59 -07003024 }
3025 }
3026 }
3027
Yohei Yukawaae61f712015-12-09 13:00:10 -08003028 private void handleSwitchInputMethod(final boolean forwardDirection) {
3029 synchronized (mMethodMap) {
Yohei Yukawaae61f712015-12-09 13:00:10 -08003030 final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
Yohei Yukawad39ae852016-04-10 20:28:40 -07003031 false, mMethodMap.get(mCurMethodId), mCurrentSubtype, forwardDirection);
Yohei Yukawaae61f712015-12-09 13:00:10 -08003032 if (nextSubtype == null) {
3033 return;
3034 }
3035 setInputMethodLocked(nextSubtype.mImi.getId(), nextSubtype.mSubtypeId);
Yohei Yukawaebda7d72016-04-02 17:39:23 -07003036 final InputMethodInfo newInputMethodInfo = mMethodMap.get(mCurMethodId);
3037 if (newInputMethodInfo == null) {
3038 return;
3039 }
3040 final CharSequence toastText = InputMethodUtils.getImeAndSubtypeDisplayName(mContext,
3041 newInputMethodInfo, mCurrentSubtype);
3042 if (!TextUtils.isEmpty(toastText)) {
Yohei Yukawab2f901a2016-04-12 01:19:31 -07003043 if (mSubtypeSwitchedByShortCutToast == null) {
3044 mSubtypeSwitchedByShortCutToast = Toast.makeText(mContext, toastText,
3045 Toast.LENGTH_SHORT);
3046 } else {
3047 mSubtypeSwitchedByShortCutToast.setText(toastText);
3048 }
Yohei Yukawaebda7d72016-04-02 17:39:23 -07003049 mSubtypeSwitchedByShortCutToast.show();
3050 }
Yohei Yukawaae61f712015-12-09 13:00:10 -08003051 }
3052 }
3053
satokdc9ddae2011-10-06 12:22:36 +09003054 private boolean chooseNewDefaultIMELocked() {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003055 final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME(
3056 mSettings.getEnabledInputMethodListLocked());
satokdc9ddae2011-10-06 12:22:36 +09003057 if (imi != null) {
satok03eb319a2010-11-11 18:17:42 +09003058 if (DEBUG) {
3059 Slog.d(TAG, "New default IME was selected: " + imi.getId());
3060 }
satok723a27e2010-11-11 14:58:11 +09003061 resetSelectedInputMethodAndSubtypeLocked(imi.getId());
Brandon Ballinger6da35a02009-10-21 00:38:13 -07003062 return true;
3063 }
3064
3065 return false;
3066 }
3067
Yohei Yukawa94e33302016-02-12 19:37:03 -08003068 void buildInputMethodListLocked(boolean resetDefaultEnabledIme) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003069 if (DEBUG) {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09003070 Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme
Seigo Nonakae27dc2b2015-08-14 18:21:27 -07003071 + " \n ------ caller=" + Debug.getCallers(10));
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003072 }
Yohei Yukawa79247822017-01-23 15:26:15 -08003073 if (!mSystemReady) {
3074 Slog.e(TAG, "buildInputMethodListLocked is not allowed until system is ready");
3075 return;
3076 }
Yohei Yukawa94e33302016-02-12 19:37:03 -08003077 mMethodList.clear();
3078 mMethodMap.clear();
Yohei Yukawae0733062017-02-09 22:49:35 -08003079 mMethodMapUpdateCount++;
Yohei Yukawac4e44912017-02-09 19:30:22 -08003080 mMyPackageMonitor.clearPackagesToMonitorComponentChangeLocked();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003081
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003082 // Use for queryIntentServicesAsUser
3083 final PackageManager pm = mContext.getPackageManager();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084
Yohei Yukawaed4952a2016-02-17 07:57:25 -08003085 // Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default
3086 // behavior of PackageManager is exactly what we want. It by default picks up appropriate
3087 // services depending on the unlock state for the specified user.
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003088 final List<ResolveInfo> services = pm.queryIntentServicesAsUser(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 new Intent(InputMethod.SERVICE_INTERFACE),
Dianne Hackbornfd7aded2013-01-22 17:10:23 -08003090 PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
3091 mSettings.getCurrentUserId());
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003092
Yohei Yukawaddad4b92017-02-02 01:46:13 -08003093 final HashMap<String, List<InputMethodSubtype>> additionalSubtypeMap =
satoke7c6998e2011-06-03 17:57:59 +09003094 mFileManager.getAllAdditionalInputMethodSubtypes();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003095 for (int i = 0; i < services.size(); ++i) {
3096 ResolveInfo ri = services.get(i);
3097 ServiceInfo si = ri.serviceInfo;
Yohei Yukawaddad4b92017-02-02 01:46:13 -08003098 final String imeId = InputMethodInfo.computeId(ri);
3099 if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) {
3100 Slog.w(TAG, "Skipping input method " + imeId
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101 + ": it does not require the permission "
3102 + android.Manifest.permission.BIND_INPUT_METHOD);
3103 continue;
3104 }
3105
Yohei Yukawaddad4b92017-02-02 01:46:13 -08003106 if (DEBUG) Slog.d(TAG, "Checking " + imeId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003107
Yohei Yukawaddad4b92017-02-02 01:46:13 -08003108 final List<InputMethodSubtype> additionalSubtypes = additionalSubtypeMap.get(imeId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 try {
satoke7c6998e2011-06-03 17:57:59 +09003110 InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
Yohei Yukawa94e33302016-02-12 19:37:03 -08003111 mMethodList.add(p);
Amith Yamasanie861ec12010-03-24 21:39:27 -07003112 final String id = p.getId();
Yohei Yukawa94e33302016-02-12 19:37:03 -08003113 mMethodMap.put(id, p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003114
3115 if (DEBUG) {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09003116 Slog.d(TAG, "Found an input method " + p);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003117 }
Tadashi G. Takaoka3c23d5b2016-09-16 11:41:07 +09003118 } catch (Exception e) {
Yohei Yukawaddad4b92017-02-02 01:46:13 -08003119 Slog.wtf(TAG, "Unable to load input method " + imeId, e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120 }
3121 }
Brandon Ballinger6da35a02009-10-21 00:38:13 -07003122
Yohei Yukawac4e44912017-02-09 19:30:22 -08003123 // Construct the set of possible IME packages for onPackageChanged() to avoid false
3124 // negatives when the package state remains to be the same but only the component state is
3125 // changed.
3126 {
3127 // Here we intentionally use PackageManager.MATCH_DISABLED_COMPONENTS since the purpose
3128 // of this query is to avoid false negatives. PackageManager.MATCH_ALL could be more
3129 // conservative, but it seems we cannot use it for now (Issue 35176630).
3130 final List<ResolveInfo> allInputMethodServices = pm.queryIntentServicesAsUser(
3131 new Intent(InputMethod.SERVICE_INTERFACE),
3132 PackageManager.MATCH_DISABLED_COMPONENTS, mSettings.getCurrentUserId());
3133 final int N = allInputMethodServices.size();
3134 for (int i = 0; i < N; ++i) {
3135 final ServiceInfo si = allInputMethodServices.get(i).serviceInfo;
3136 if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) {
3137 continue;
3138 }
3139 mMyPackageMonitor.addPackageToMonitorComponentChangeLocked(si.packageName);
3140 }
3141 }
3142
Yohei Yukawa859df052016-02-17 07:56:46 -08003143 // TODO: The following code should find better place to live.
3144 if (!resetDefaultEnabledIme) {
3145 boolean enabledImeFound = false;
3146 final List<InputMethodInfo> enabledImes = mSettings.getEnabledInputMethodListLocked();
3147 final int N = enabledImes.size();
3148 for (int i = 0; i < N; ++i) {
3149 final InputMethodInfo imi = enabledImes.get(i);
3150 if (mMethodList.contains(imi)) {
3151 enabledImeFound = true;
3152 break;
3153 }
3154 }
3155 if (!enabledImeFound) {
Yohei Yukawad0332832017-02-01 13:59:43 -08003156 if (DEBUG) {
3157 Slog.i(TAG, "All the enabled IMEs are gone. Reset default enabled IMEs.");
3158 }
Yohei Yukawa859df052016-02-17 07:56:46 -08003159 resetDefaultEnabledIme = true;
3160 resetSelectedInputMethodAndSubtypeLocked("");
3161 }
3162 }
3163
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09003164 if (resetDefaultEnabledIme) {
3165 final ArrayList<InputMethodInfo> defaultEnabledIme =
Yohei Yukawaaf5cee82017-01-23 16:17:11 -08003166 InputMethodUtils.getDefaultEnabledImes(mContext, mMethodList);
Yohei Yukawa68645a62016-02-17 07:54:20 -08003167 final int N = defaultEnabledIme.size();
3168 for (int i = 0; i < N; ++i) {
Satoshi Kataokaf1367b72013-01-25 17:20:12 +09003169 final InputMethodInfo imi = defaultEnabledIme.get(i);
3170 if (DEBUG) {
3171 Slog.d(TAG, "--- enable ime = " + imi);
3172 }
3173 setInputMethodEnabledLocked(imi.getId(), true);
3174 }
3175 }
3176
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003177 final String defaultImiId = mSettings.getSelectedInputMethod();
satok0a1bcf42012-05-16 19:26:31 +09003178 if (!TextUtils.isEmpty(defaultImiId)) {
Yohei Yukawa94e33302016-02-12 19:37:03 -08003179 if (!mMethodMap.containsKey(defaultImiId)) {
satok0a1bcf42012-05-16 19:26:31 +09003180 Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
3181 if (chooseNewDefaultIMELocked()) {
Michael Wright7b5a96b2014-08-09 19:28:42 -07003182 updateInputMethodsFromSettingsLocked(true);
satok0a1bcf42012-05-16 19:26:31 +09003183 }
3184 } else {
3185 // Double check that the default IME is certainly enabled.
3186 setInputMethodEnabledLocked(defaultImiId, true);
Brandon Ballinger6da35a02009-10-21 00:38:13 -07003187 }
3188 }
Yohei Yukawa3d46bab2014-05-30 18:10:18 +09003189 // Here is not the perfect place to reset the switching controller. Ideally
3190 // mSwitchingController and mSettings should be able to share the same state.
3191 // TODO: Make sure that mSwitchingController and mSettings are sharing the
3192 // the same enabled IMEs list.
Yohei Yukawac834a252014-05-21 22:42:32 +09003193 mSwitchingController.resetCircularListLocked(mContext);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003197
satok217f5482010-12-15 05:19:19 +09003198 private void showInputMethodAndSubtypeEnabler(String inputMethodId) {
Tadashi G. Takaokaf49688f2011-01-20 17:56:13 +09003199 Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
satok47a44912010-10-06 16:03:58 +09003200 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
satok86417ea2010-10-27 14:11:03 +09003201 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
3202 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
satok7fee71f2010-12-17 18:54:26 +09003203 if (!TextUtils.isEmpty(inputMethodId)) {
Tadashi G. Takaoka25480202011-01-20 23:13:02 +09003204 intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId);
satok7fee71f2010-12-17 18:54:26 +09003205 }
Yohei Yukawa41f34272015-12-14 15:41:52 -08003206 final int userId;
3207 synchronized (mMethodMap) {
3208 userId = mSettings.getCurrentUserId();
3209 }
3210 mContext.startActivityAsUser(intent, null, UserHandle.of(userId));
satok217f5482010-12-15 05:19:19 +09003211 }
3212
3213 private void showConfigureInputMethods() {
3214 Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
3215 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
3216 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
3217 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
Satoshi Kataoka3ba439d2012-10-05 18:30:13 +09003218 mContext.startActivityAsUser(intent, null, UserHandle.CURRENT);
satok47a44912010-10-06 16:03:58 +09003219 }
3220
satok2c93efc2012-04-02 19:33:47 +09003221 private boolean isScreenLocked() {
3222 return mKeyguardManager != null
3223 && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure();
3224 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09003225
Seigo Nonaka14e13912015-05-06 21:04:13 -07003226 private void showInputMethodMenu(boolean showAuxSubtypes) {
3227 if (DEBUG) Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 final Context context = mContext;
satok2c93efc2012-04-02 19:33:47 +09003230 final boolean isScreenLocked = isScreenLocked();
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003231
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003232 final String lastInputMethodId = mSettings.getSelectedInputMethod();
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003233 int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
Joe Onorato8a9b2202010-02-26 18:56:32 -08003234 if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003235
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07003236 synchronized (mMethodMap) {
satokbb4aa062011-01-19 21:40:27 +09003237 final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis =
Satoshi Kataokad787f692013-10-26 04:44:21 +09003238 mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(
3239 mContext);
satok7f35c8c2010-10-07 21:13:11 +09003240 if (immis == null || immis.size() == 0) {
3241 return;
3242 }
3243
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07003244 hideInputMethodMenuLocked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245
satok688bd472012-02-09 20:09:17 +09003246 final List<ImeSubtypeListItem> imList =
Yohei Yukawa5a647b692014-05-22 12:49:00 +09003247 mSwitchingController.getSortedInputMethodAndSubtypeListLocked(
Yohei Yukawa5f8e7312015-12-10 00:58:55 -08003248 showAuxSubtypes, isScreenLocked);
satok913a8922010-08-26 21:53:41 +09003249
satokc3690562012-01-10 20:14:43 +09003250 if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003251 final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
satokc3690562012-01-10 20:14:43 +09003252 if (currentSubtype != null) {
3253 final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003254 lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
3255 currentImi, currentSubtype.hashCode());
satokc3690562012-01-10 20:14:43 +09003256 }
3257 }
3258
Ken Wakasa761eb372011-03-04 19:06:18 +09003259 final int N = imList.size();
satokab751aa2010-09-14 19:17:36 +09003260 mIms = new InputMethodInfo[N];
3261 mSubtypeIds = new int[N];
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07003262 int checkedItem = 0;
3263 for (int i = 0; i < N; ++i) {
Ken Wakasa05dbb652011-08-22 15:22:43 +09003264 final ImeSubtypeListItem item = imList.get(i);
3265 mIms[i] = item.mImi;
3266 mSubtypeIds[i] = item.mSubtypeId;
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07003267 if (mIms[i].getId().equals(lastInputMethodId)) {
satokab751aa2010-09-14 19:17:36 +09003268 int subtypeId = mSubtypeIds[i];
3269 if ((subtypeId == NOT_A_SUBTYPE_ID)
3270 || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0)
3271 || (subtypeId == lastInputMethodSubtypeId)) {
3272 checkedItem = i;
3273 }
Dianne Hackborn8cf1bcd2010-03-16 13:06:10 -07003274 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003275 }
Alan Viverette505e3ab2014-11-24 15:22:11 -08003276
3277 final Context settingsContext = new ContextThemeWrapper(context,
3278 com.android.internal.R.style.Theme_DeviceDefault_Settings);
3279
3280 mDialogBuilder = new AlertDialog.Builder(settingsContext);
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09003281 mDialogBuilder.setOnCancelListener(new OnCancelListener() {
3282 @Override
3283 public void onCancel(DialogInterface dialog) {
3284 hideInputMethodMenu();
3285 }
3286 });
Alan Viverette505e3ab2014-11-24 15:22:11 -08003287
3288 final Context dialogContext = mDialogBuilder.getContext();
3289 final TypedArray a = dialogContext.obtainStyledAttributes(null,
3290 com.android.internal.R.styleable.DialogPreference,
3291 com.android.internal.R.attr.alertDialogStyle, 0);
3292 final Drawable dialogIcon = a.getDrawable(
3293 com.android.internal.R.styleable.DialogPreference_dialogIcon);
3294 a.recycle();
3295
3296 mDialogBuilder.setIcon(dialogIcon);
3297
Yohei Yukawad34e1482016-02-11 08:03:52 -08003298 final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class);
satok01038492012-04-09 21:08:27 +09003299 final View tv = inflater.inflate(
3300 com.android.internal.R.layout.input_method_switch_dialog_title, null);
3301 mDialogBuilder.setCustomTitle(tv);
3302
3303 // Setup layout for a toggle switch of the hardware keyboard
3304 mSwitchingDialogTitleView = tv;
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09003305 mSwitchingDialogTitleView
3306 .findViewById(com.android.internal.R.id.hard_keyboard_section)
Seigo Nonaka7309b122015-08-17 18:34:13 -07003307 .setVisibility(mWindowManagerInternal.isHardKeyboardAvailable()
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09003308 ? View.VISIBLE : View.GONE);
Alan Viverette505e3ab2014-11-24 15:22:11 -08003309 final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById(
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09003310 com.android.internal.R.id.hard_keyboard_switch);
Michael Wright7b5a96b2014-08-09 19:28:42 -07003311 hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09003312 hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
3313 @Override
3314 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Michael Wright7b5a96b2014-08-09 19:28:42 -07003315 mSettings.setShowImeWithHardKeyboard(isChecked);
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09003316 // Ensure that the input method dialog is dismissed when changing
3317 // the hardware keyboard state.
3318 hideInputMethodMenu();
3319 }
3320 });
3321
Alan Viverette505e3ab2014-11-24 15:22:11 -08003322 final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext,
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09003323 com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
3324 final OnClickListener choiceListener = new OnClickListener() {
3325 @Override
3326 public void onClick(final DialogInterface dialog, final int which) {
3327 synchronized (mMethodMap) {
3328 if (mIms == null || mIms.length <= which || mSubtypeIds == null
3329 || mSubtypeIds.length <= which) {
3330 return;
satok01038492012-04-09 21:08:27 +09003331 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09003332 final InputMethodInfo im = mIms[which];
3333 int subtypeId = mSubtypeIds[which];
3334 adapter.mCheckedItem = which;
3335 adapter.notifyDataSetChanged();
3336 hideInputMethodMenu();
3337 if (im != null) {
3338 if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) {
3339 subtypeId = NOT_A_SUBTYPE_ID;
Dianne Hackborn20cb56e2010-03-04 00:58:29 -08003340 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09003341 setInputMethodLocked(im.getId(), subtypeId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 }
Tadashi G. Takaokad130b802014-08-01 14:05:47 +09003343 }
3344 }
3345 };
3346 mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 mSwitchingDialog = mDialogBuilder.create();
Dianne Hackborne3a7f622011-03-03 21:48:24 -08003349 mSwitchingDialog.setCanceledOnTouchOutside(true);
Wale Ogunwale3a931692016-11-02 16:49:48 -07003350 final Window w = mSwitchingDialog.getWindow();
3351 final WindowManager.LayoutParams attrs = w.getAttributes();
3352 w.setType(TYPE_INPUT_METHOD_DIALOG);
3353 // Use an alternate token for the dialog for that window manager can group the token
3354 // with other IME windows based on type vs. grouping based on whichever token happens
3355 // to get selected by the system later on.
3356 attrs.token = mSwitchingDialogToken;
3357 attrs.privateFlags |= PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
3358 attrs.setTitle("Select input method");
3359 w.setAttributes(attrs);
Seigo Nonakad9eb9112015-05-26 20:54:43 +09003360 updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003361 mSwitchingDialog.show();
3362 }
3363 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003364
Ken Wakasa05dbb652011-08-22 15:22:43 +09003365 private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> {
3366 private final LayoutInflater mInflater;
3367 private final int mTextViewResourceId;
3368 private final List<ImeSubtypeListItem> mItemsList;
Satoshi Kataokad2142962012-11-12 18:43:06 +09003369 public int mCheckedItem;
Ken Wakasa05dbb652011-08-22 15:22:43 +09003370 public ImeSubtypeListAdapter(Context context, int textViewResourceId,
3371 List<ImeSubtypeListItem> itemsList, int checkedItem) {
3372 super(context, textViewResourceId, itemsList);
Alan Viverette505e3ab2014-11-24 15:22:11 -08003373
Ken Wakasa05dbb652011-08-22 15:22:43 +09003374 mTextViewResourceId = textViewResourceId;
3375 mItemsList = itemsList;
3376 mCheckedItem = checkedItem;
Yohei Yukawad34e1482016-02-11 08:03:52 -08003377 mInflater = context.getSystemService(LayoutInflater.class);
Ken Wakasa05dbb652011-08-22 15:22:43 +09003378 }
3379
3380 @Override
3381 public View getView(int position, View convertView, ViewGroup parent) {
3382 final View view = convertView != null ? convertView
3383 : mInflater.inflate(mTextViewResourceId, null);
3384 if (position < 0 || position >= mItemsList.size()) return view;
3385 final ImeSubtypeListItem item = mItemsList.get(position);
3386 final CharSequence imeName = item.mImeName;
3387 final CharSequence subtypeName = item.mSubtypeName;
3388 final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1);
3389 final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2);
3390 if (TextUtils.isEmpty(subtypeName)) {
3391 firstTextView.setText(imeName);
3392 secondTextView.setVisibility(View.GONE);
3393 } else {
3394 firstTextView.setText(subtypeName);
3395 secondTextView.setText(imeName);
3396 secondTextView.setVisibility(View.VISIBLE);
3397 }
3398 final RadioButton radioButton =
3399 (RadioButton)view.findViewById(com.android.internal.R.id.radio);
3400 radioButton.setChecked(position == mCheckedItem);
3401 return view;
3402 }
3403 }
3404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003405 void hideInputMethodMenu() {
The Android Open Source Project10592532009-03-18 17:39:46 -07003406 synchronized (mMethodMap) {
3407 hideInputMethodMenuLocked();
3408 }
3409 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003410
The Android Open Source Project10592532009-03-18 17:39:46 -07003411 void hideInputMethodMenuLocked() {
Joe Onorato8a9b2202010-02-26 18:56:32 -08003412 if (DEBUG) Slog.v(TAG, "Hide switching menu");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003413
The Android Open Source Project10592532009-03-18 17:39:46 -07003414 if (mSwitchingDialog != null) {
3415 mSwitchingDialog.dismiss();
3416 mSwitchingDialog = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003417 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003418
Seigo Nonakad9eb9112015-05-26 20:54:43 +09003419 updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition);
The Android Open Source Project10592532009-03-18 17:39:46 -07003420 mDialogBuilder = null;
The Android Open Source Project10592532009-03-18 17:39:46 -07003421 mIms = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003424 // ----------------------------------------------------------------------
Doug Zongkerab5c49c2009-12-04 10:31:43 -08003425
satok42c5a162011-05-26 16:46:14 +09003426 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003427 public boolean setInputMethodEnabled(String id, boolean enabled) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003428 // TODO: Make this work even for non-current users?
3429 if (!calledFromValidUser()) {
3430 return false;
3431 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003432 synchronized (mMethodMap) {
3433 if (mContext.checkCallingOrSelfPermission(
3434 android.Manifest.permission.WRITE_SECURE_SETTINGS)
3435 != PackageManager.PERMISSION_GRANTED) {
3436 throw new SecurityException(
3437 "Requires permission "
3438 + android.Manifest.permission.WRITE_SECURE_SETTINGS);
3439 }
Anna Galusza9b278112016-01-04 11:37:37 -08003440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003441 long ident = Binder.clearCallingIdentity();
3442 try {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003443 return setInputMethodEnabledLocked(id, enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003444 } finally {
3445 Binder.restoreCallingIdentity(ident);
3446 }
3447 }
3448 }
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003449
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003450 boolean setInputMethodEnabledLocked(String id, boolean enabled) {
3451 // Make sure this is a valid input method.
3452 InputMethodInfo imm = mMethodMap.get(id);
3453 if (imm == null) {
satokd87c2592010-09-29 11:52:06 +09003454 throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003455 }
3456
satokd87c2592010-09-29 11:52:06 +09003457 List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings
3458 .getEnabledInputMethodsAndSubtypeListLocked();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003459
satokd87c2592010-09-29 11:52:06 +09003460 if (enabled) {
3461 for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) {
3462 if (pair.first.equals(id)) {
3463 // We are enabling this input method, but it is already enabled.
3464 // Nothing to do. The previous state was enabled.
3465 return true;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003466 }
3467 }
satokd87c2592010-09-29 11:52:06 +09003468 mSettings.appendAndPutEnabledInputMethodLocked(id, false);
3469 // Previous state was disabled.
3470 return false;
3471 } else {
3472 StringBuilder builder = new StringBuilder();
3473 if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked(
3474 builder, enabledInputMethodsList, id)) {
3475 // Disabled input method is currently selected, switch to another one.
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003476 final String selId = mSettings.getSelectedInputMethod();
satok03eb319a2010-11-11 18:17:42 +09003477 if (id.equals(selId) && !chooseNewDefaultIMELocked()) {
3478 Slog.i(TAG, "Can't find new IME, unsetting the current input method.");
3479 resetSelectedInputMethodAndSubtypeLocked("");
satokd87c2592010-09-29 11:52:06 +09003480 }
3481 // Previous state was enabled.
3482 return true;
3483 } else {
3484 // We are disabling the input method but it is already disabled.
3485 // Nothing to do. The previous state was disabled.
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003486 return false;
3487 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003488 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -08003489 }
The Android Open Source Project4df24232009-03-05 14:34:35 -08003490
satok723a27e2010-11-11 14:58:11 +09003491 private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId,
3492 boolean setSubtypeOnly) {
3493 // Update the history of InputMethod and Subtype
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003494 mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype);
satok723a27e2010-11-11 14:58:11 +09003495
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09003496 mCurUserActionNotificationSequenceNumber =
3497 Math.max(mCurUserActionNotificationSequenceNumber + 1, 1);
3498 if (DEBUG) {
3499 Slog.d(TAG, "Bump mCurUserActionNotificationSequenceNumber:"
3500 + mCurUserActionNotificationSequenceNumber);
3501 }
3502
3503 if (mCurClient != null && mCurClient.client != null) {
3504 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
3505 MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER,
Yohei Yukawa080fa342014-08-31 16:10:05 -07003506 mCurUserActionNotificationSequenceNumber, mCurClient));
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09003507 }
3508
satok723a27e2010-11-11 14:58:11 +09003509 // Set Subtype here
3510 if (imi == null || subtypeId < 0) {
3511 mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
Tadashi G. Takaoka0ba75bb2010-11-09 12:19:32 -08003512 mCurrentSubtype = null;
satok723a27e2010-11-11 14:58:11 +09003513 } else {
Ken Wakasa586f0512011-01-20 22:31:01 +09003514 if (subtypeId < imi.getSubtypeCount()) {
3515 InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId);
3516 mSettings.putSelectedSubtype(subtype.hashCode());
3517 mCurrentSubtype = subtype;
satok723a27e2010-11-11 14:58:11 +09003518 } else {
3519 mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
satokd81e9502012-05-21 12:58:45 +09003520 // If the subtype is not specified, choose the most applicable one
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003521 mCurrentSubtype = getCurrentInputMethodSubtypeLocked();
satok723a27e2010-11-11 14:58:11 +09003522 }
satokab751aa2010-09-14 19:17:36 +09003523 }
satok723a27e2010-11-11 14:58:11 +09003524
Yohei Yukawa68645a62016-02-17 07:54:20 -08003525 if (!setSubtypeOnly) {
satok723a27e2010-11-11 14:58:11 +09003526 // Set InputMethod here
3527 mSettings.putSelectedInputMethod(imi != null ? imi.getId() : "");
3528 }
3529 }
3530
3531 private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) {
3532 InputMethodInfo imi = mMethodMap.get(newDefaultIme);
3533 int lastSubtypeId = NOT_A_SUBTYPE_ID;
3534 // newDefaultIme is empty when there is no candidate for the selected IME.
3535 if (imi != null && !TextUtils.isEmpty(newDefaultIme)) {
3536 String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme);
3537 if (subtypeHashCode != null) {
3538 try {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003539 lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
Narayan Kamatha09b4d22016-04-15 18:32:45 +01003540 imi, Integer.parseInt(subtypeHashCode));
satok723a27e2010-11-11 14:58:11 +09003541 } catch (NumberFormatException e) {
3542 Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e);
3543 }
3544 }
3545 }
3546 setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false);
satokab751aa2010-09-14 19:17:36 +09003547 }
3548
satok4e4569d2010-11-19 18:45:53 +09003549 // If there are no selected shortcuts, tries finding the most applicable ones.
3550 private Pair<InputMethodInfo, InputMethodSubtype>
3551 findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) {
3552 List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
3553 InputMethodInfo mostApplicableIMI = null;
satokcd7cd292010-11-20 15:46:23 +09003554 InputMethodSubtype mostApplicableSubtype = null;
satok4e4569d2010-11-19 18:45:53 +09003555 boolean foundInSystemIME = false;
3556
3557 // Search applicable subtype for each InputMethodInfo
3558 for (InputMethodInfo imi: imis) {
satok7599a7f2010-12-22 13:45:23 +09003559 final String imiId = imi.getId();
3560 if (foundInSystemIME && !imiId.equals(mCurMethodId)) {
3561 continue;
3562 }
satokcd7cd292010-11-20 15:46:23 +09003563 InputMethodSubtype subtype = null;
satokdf31ae62011-01-15 06:19:44 +09003564 final List<InputMethodSubtype> enabledSubtypes =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003565 mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
satokdf31ae62011-01-15 06:19:44 +09003566 // 1. Search by the current subtype's locale from enabledSubtypes.
satok4e4569d2010-11-19 18:45:53 +09003567 if (mCurrentSubtype != null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003568 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satokdf31ae62011-01-15 06:19:44 +09003569 mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false);
satok4e4569d2010-11-19 18:45:53 +09003570 }
satokdf31ae62011-01-15 06:19:44 +09003571 // 2. Search by the system locale from enabledSubtypes.
3572 // 3. Search the first enabled subtype matched with mode from enabledSubtypes.
satokcd7cd292010-11-20 15:46:23 +09003573 if (subtype == null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003574 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satokdf31ae62011-01-15 06:19:44 +09003575 mRes, enabledSubtypes, mode, null, true);
satok4e4569d2010-11-19 18:45:53 +09003576 }
satoka86f5e42011-09-02 17:12:42 +09003577 final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003578 InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode);
satoka86f5e42011-09-02 17:12:42 +09003579 final ArrayList<InputMethodSubtype> subtypesForSearch =
3580 overridingImplicitlyEnabledSubtypes.isEmpty()
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003581 ? InputMethodUtils.getSubtypes(imi)
3582 : overridingImplicitlyEnabledSubtypes;
satok7599a7f2010-12-22 13:45:23 +09003583 // 4. Search by the current subtype's locale from all subtypes.
3584 if (subtype == null && mCurrentSubtype != null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003585 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satoka86f5e42011-09-02 17:12:42 +09003586 mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false);
satok7599a7f2010-12-22 13:45:23 +09003587 }
3588 // 5. Search by the system locale from all subtypes.
3589 // 6. Search the first enabled subtype matched with mode from all subtypes.
satokcd7cd292010-11-20 15:46:23 +09003590 if (subtype == null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003591 subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
satoka86f5e42011-09-02 17:12:42 +09003592 mRes, subtypesForSearch, mode, null, true);
satok4e4569d2010-11-19 18:45:53 +09003593 }
satokcd7cd292010-11-20 15:46:23 +09003594 if (subtype != null) {
satok7599a7f2010-12-22 13:45:23 +09003595 if (imiId.equals(mCurMethodId)) {
satok4e4569d2010-11-19 18:45:53 +09003596 // The current input method is the most applicable IME.
3597 mostApplicableIMI = imi;
satokcd7cd292010-11-20 15:46:23 +09003598 mostApplicableSubtype = subtype;
satok4e4569d2010-11-19 18:45:53 +09003599 break;
satok7599a7f2010-12-22 13:45:23 +09003600 } else if (!foundInSystemIME) {
satok4e4569d2010-11-19 18:45:53 +09003601 // The system input method is 2nd applicable IME.
3602 mostApplicableIMI = imi;
satokcd7cd292010-11-20 15:46:23 +09003603 mostApplicableSubtype = subtype;
satok7599a7f2010-12-22 13:45:23 +09003604 if ((imi.getServiceInfo().applicationInfo.flags
3605 & ApplicationInfo.FLAG_SYSTEM) != 0) {
3606 foundInSystemIME = true;
3607 }
satok4e4569d2010-11-19 18:45:53 +09003608 }
3609 }
3610 }
3611 if (DEBUG) {
satokcd7cd292010-11-20 15:46:23 +09003612 if (mostApplicableIMI != null) {
3613 Slog.w(TAG, "Most applicable shortcut input method was:"
3614 + mostApplicableIMI.getId());
3615 if (mostApplicableSubtype != null) {
3616 Slog.w(TAG, "Most applicable shortcut input method subtype was:"
3617 + "," + mostApplicableSubtype.getMode() + ","
3618 + mostApplicableSubtype.getLocale());
3619 }
3620 }
satok4e4569d2010-11-19 18:45:53 +09003621 }
satokcd7cd292010-11-20 15:46:23 +09003622 if (mostApplicableIMI != null) {
Yohei Yukawab0377bb2015-08-10 21:06:30 -07003623 return new Pair<> (mostApplicableIMI, mostApplicableSubtype);
satok4e4569d2010-11-19 18:45:53 +09003624 } else {
3625 return null;
3626 }
3627 }
3628
satokab751aa2010-09-14 19:17:36 +09003629 /**
3630 * @return Return the current subtype of this input method.
3631 */
satok42c5a162011-05-26 16:46:14 +09003632 @Override
satokab751aa2010-09-14 19:17:36 +09003633 public InputMethodSubtype getCurrentInputMethodSubtype() {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003634 // TODO: Make this work even for non-current users?
3635 if (!calledFromValidUser()) {
3636 return null;
3637 }
3638 synchronized (mMethodMap) {
3639 return getCurrentInputMethodSubtypeLocked();
3640 }
3641 }
3642
3643 private InputMethodSubtype getCurrentInputMethodSubtypeLocked() {
satokfdf419e2012-05-08 16:52:08 +09003644 if (mCurMethodId == null) {
3645 return null;
3646 }
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003647 final boolean subtypeIsSelected = mSettings.isSubtypeSelected();
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003648 final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
3649 if (imi == null || imi.getSubtypeCount() == 0) {
3650 return null;
satok4e4569d2010-11-19 18:45:53 +09003651 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003652 if (!subtypeIsSelected || mCurrentSubtype == null
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003653 || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) {
3654 int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003655 if (subtypeId == NOT_A_SUBTYPE_ID) {
3656 // If there are no selected subtypes, the framework will try to find
3657 // the most applicable subtype from explicitly or implicitly enabled
3658 // subtypes.
3659 List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes =
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003660 mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003661 // If there is only one explicitly or implicitly enabled subtype,
3662 // just returns it.
3663 if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) {
3664 mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0);
3665 } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003666 mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003667 mRes, explicitlyOrImplicitlyEnabledSubtypes,
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003668 InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true);
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003669 if (mCurrentSubtype == null) {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003670 mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003671 mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null,
3672 true);
satok4e4569d2010-11-19 18:45:53 +09003673 }
satok3ef8b292010-11-23 06:06:29 +09003674 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003675 } else {
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003676 mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId);
satok8fbb1e82010-11-02 23:15:58 +09003677 }
3678 }
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003679 return mCurrentSubtype;
satokab751aa2010-09-14 19:17:36 +09003680 }
3681
satok4e4569d2010-11-19 18:45:53 +09003682 // TODO: We should change the return type from List to List<Parcelable>
satokdbf29502011-08-25 15:28:23 +09003683 @SuppressWarnings("rawtypes")
satoke7c6998e2011-06-03 17:57:59 +09003684 @Override
satok4e4569d2010-11-19 18:45:53 +09003685 public List getShortcutInputMethodsAndSubtypes() {
3686 synchronized (mMethodMap) {
Yohei Yukawab0377bb2015-08-10 21:06:30 -07003687 ArrayList<Object> ret = new ArrayList<>();
satokf3db1af2010-11-23 13:34:33 +09003688 if (mShortcutInputMethodsAndSubtypes.size() == 0) {
satok4e4569d2010-11-19 18:45:53 +09003689 // If there are no selected shortcut subtypes, the framework will try to find
3690 // the most applicable subtype from all subtypes whose mode is
3691 // SUBTYPE_MODE_VOICE. This is an exceptional case, so we will hardcode the mode.
satokf3db1af2010-11-23 13:34:33 +09003692 Pair<InputMethodInfo, InputMethodSubtype> info =
3693 findLastResortApplicableShortcutInputMethodAndSubtypeLocked(
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003694 InputMethodUtils.SUBTYPE_MODE_VOICE);
satok7599a7f2010-12-22 13:45:23 +09003695 if (info != null) {
satok3da92232011-01-11 22:46:30 +09003696 ret.add(info.first);
3697 ret.add(info.second);
satok7599a7f2010-12-22 13:45:23 +09003698 }
satok3da92232011-01-11 22:46:30 +09003699 return ret;
satokf3db1af2010-11-23 13:34:33 +09003700 }
satokf3db1af2010-11-23 13:34:33 +09003701 for (InputMethodInfo imi: mShortcutInputMethodsAndSubtypes.keySet()) {
3702 ret.add(imi);
3703 for (InputMethodSubtype subtype: mShortcutInputMethodsAndSubtypes.get(imi)) {
3704 ret.add(subtype);
satok4e4569d2010-11-19 18:45:53 +09003705 }
3706 }
satokf3db1af2010-11-23 13:34:33 +09003707 return ret;
satok4e4569d2010-11-19 18:45:53 +09003708 }
3709 }
3710
satok42c5a162011-05-26 16:46:14 +09003711 @Override
satokb66d2872010-11-10 01:04:04 +09003712 public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) {
Satoshi Kataoka4e1ab152012-09-13 21:34:20 +09003713 // TODO: Make this work even for non-current users?
3714 if (!calledFromValidUser()) {
3715 return false;
3716 }
satokb66d2872010-11-10 01:04:04 +09003717 synchronized (mMethodMap) {
3718 if (subtype != null && mCurMethodId != null) {
3719 InputMethodInfo imi = mMethodMap.get(mCurMethodId);
Satoshi Kataoka8e303cc2013-01-11 15:55:28 +09003720 int subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode());
satokb66d2872010-11-10 01:04:04 +09003721 if (subtypeId != NOT_A_SUBTYPE_ID) {
3722 setInputMethodLocked(mCurMethodId, subtypeId);
3723 return true;
3724 }
3725 }
3726 return false;
3727 }
3728 }
3729
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +09003730 // TODO: Cache the state for each user and reset when the cached user is removed.
satoke7c6998e2011-06-03 17:57:59 +09003731 private static class InputMethodFileManager {
3732 private static final String SYSTEM_PATH = "system";
3733 private static final String INPUT_METHOD_PATH = "inputmethod";
3734 private static final String ADDITIONAL_SUBTYPES_FILE_NAME = "subtypes.xml";
3735 private static final String NODE_SUBTYPES = "subtypes";
3736 private static final String NODE_SUBTYPE = "subtype";
3737 private static final String NODE_IMI = "imi";
3738 private static final String ATTR_ID = "id";
3739 private static final String ATTR_LABEL = "label";
3740 private static final String ATTR_ICON = "icon";
Yohei Yukawa66baf692016-04-11 02:29:35 -07003741 private static final String ATTR_IME_SUBTYPE_ID = "subtypeId";
satoke7c6998e2011-06-03 17:57:59 +09003742 private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale";
Yohei Yukawa868d19b2015-12-07 15:58:57 -08003743 private static final String ATTR_IME_SUBTYPE_LANGUAGE_TAG = "languageTag";
satoke7c6998e2011-06-03 17:57:59 +09003744 private static final String ATTR_IME_SUBTYPE_MODE = "imeSubtypeMode";
3745 private static final String ATTR_IME_SUBTYPE_EXTRA_VALUE = "imeSubtypeExtraValue";
3746 private static final String ATTR_IS_AUXILIARY = "isAuxiliary";
Yohei Yukawa1e1a4472016-03-10 23:46:07 -08003747 private static final String ATTR_IS_ASCII_CAPABLE = "isAsciiCapable";
satoke7c6998e2011-06-03 17:57:59 +09003748 private final AtomicFile mAdditionalInputMethodSubtypeFile;
3749 private final HashMap<String, InputMethodInfo> mMethodMap;
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003750 private final HashMap<String, List<InputMethodSubtype>> mAdditionalSubtypesMap =
Yohei Yukawab0377bb2015-08-10 21:06:30 -07003751 new HashMap<>();
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +09003752 public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap, int userId) {
satoke7c6998e2011-06-03 17:57:59 +09003753 if (methodMap == null) {
3754 throw new NullPointerException("methodMap is null");
3755 }
3756 mMethodMap = methodMap;
Xiaohui Chen7c696362015-09-16 09:56:14 -07003757 final File systemDir = userId == UserHandle.USER_SYSTEM
Satoshi Kataoka5ade83b2012-09-26 22:59:41 +09003758 ? new File(Environment.getDataDirectory(), SYSTEM_PATH)
3759 : Environment.getUserSystemDirectory(userId);
satoke7c6998e2011-06-03 17:57:59 +09003760 final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH);
Yohei Yukawadf5af482015-08-04 22:11:11 -07003761 if (!inputMethodDir.exists() && !inputMethodDir.mkdirs()) {
satoke7c6998e2011-06-03 17:57:59 +09003762 Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath());
3763 }
3764 final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME);
3765 mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile);
3766 if (!subtypeFile.exists()) {
3767 // If "subtypes.xml" doesn't exist, create a blank file.
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003768 writeAdditionalInputMethodSubtypes(
3769 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, methodMap);
satoke7c6998e2011-06-03 17:57:59 +09003770 } else {
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003771 readAdditionalInputMethodSubtypes(
3772 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile);
satoke7c6998e2011-06-03 17:57:59 +09003773 }
3774 }
3775
3776 private void deleteAllInputMethodSubtypes(String imiId) {
3777 synchronized (mMethodMap) {
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003778 mAdditionalSubtypesMap.remove(imiId);
3779 writeAdditionalInputMethodSubtypes(
3780 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap);
satoke7c6998e2011-06-03 17:57:59 +09003781 }
3782 }
3783
3784 public void addInputMethodSubtypes(
satok4a28bde2011-06-29 21:03:40 +09003785 InputMethodInfo imi, InputMethodSubtype[] additionalSubtypes) {
satoke7c6998e2011-06-03 17:57:59 +09003786 synchronized (mMethodMap) {
Yohei Yukawab0377bb2015-08-10 21:06:30 -07003787 final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
satoke7c6998e2011-06-03 17:57:59 +09003788 final int N = additionalSubtypes.length;
3789 for (int i = 0; i < N; ++i) {
3790 final InputMethodSubtype subtype = additionalSubtypes[i];
satoked2b24e2011-08-31 18:03:21 +09003791 if (!subtypes.contains(subtype)) {
satoke7c6998e2011-06-03 17:57:59 +09003792 subtypes.add(subtype);
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003793 } else {
3794 Slog.w(TAG, "Duplicated subtype definition found: "
3795 + subtype.getLocale() + ", " + subtype.getMode());
satoke7c6998e2011-06-03 17:57:59 +09003796 }
3797 }
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003798 mAdditionalSubtypesMap.put(imi.getId(), subtypes);
3799 writeAdditionalInputMethodSubtypes(
3800 mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap);
satoke7c6998e2011-06-03 17:57:59 +09003801 }
3802 }
3803
3804 public HashMap<String, List<InputMethodSubtype>> getAllAdditionalInputMethodSubtypes() {
3805 synchronized (mMethodMap) {
Satoshi Kataokae62e6d82012-07-02 18:45:43 +09003806 return mAdditionalSubtypesMap;
satoke7c6998e2011-06-03 17:57:59 +09003807 }
3808 }
3809
3810 private static void writeAdditionalInputMethodSubtypes(
3811 HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile,
3812 HashMap<String, InputMethodInfo> methodMap) {
3813 // Safety net for the case that this function is called before methodMap is set.
3814 final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0;
3815 FileOutputStream fos = null;
3816 try {
3817 fos = subtypesFile.startWrite();
3818 final XmlSerializer out = new FastXmlSerializer();
Wojciech Staszkiewicz9e9e2e72015-05-08 14:58:46 +01003819 out.setOutput(fos, StandardCharsets.UTF_8.name());
satoke7c6998e2011-06-03 17:57:59 +09003820 out.startDocument(null, true);
3821 out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
3822 out.startTag(null, NODE_SUBTYPES);
3823 for (String imiId : allSubtypes.keySet()) {
3824 if (isSetMethodMap && !methodMap.containsKey(imiId)) {
3825 Slog.w(TAG, "IME uninstalled or not valid.: " + imiId);
3826 continue;
3827 }
3828 out.startTag(null, NODE_IMI);
3829 out.attribute(null, ATTR_ID, imiId);
3830 final List<InputMethodSubtype> subtypesList = allSubtypes.get(imiId);
3831 final int N = subtypesList.size();
3832 for (int i = 0; i < N; ++i) {
3833 final InputMethodSubtype subtype = subtypesList.get(i);
3834 out.startTag(null, NODE_SUBTYPE);
Yohei Yukawa66baf692016-04-11 02:29:35 -07003835 if (subtype.hasSubtypeId()) {
3836 out.attribute(null, ATTR_IME_SUBTYPE_ID,
3837 String.valueOf(subtype.getSubtypeId()));
3838 }
satoke7c6998e2011-06-03 17:57:59 +09003839 out.attribute(null, ATTR_ICON, String.valueOf(subtype.getIconResId()));
3840 out.attribute(null, ATTR_LABEL, String.valueOf(subtype.getNameResId()));
3841 out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale());
Yohei Yukawa868d19b2015-12-07 15:58:57 -08003842 out.attribute(null, ATTR_IME_SUBTYPE_LANGUAGE_TAG,
3843 subtype.getLanguageTag());
satoke7c6998e2011-06-03 17:57:59 +09003844 out.attribute(null, ATTR_IME_SUBTYPE_MODE, subtype.getMode());
3845 out.attribute(null, ATTR_IME_SUBTYPE_EXTRA_VALUE, subtype.getExtraValue());
3846 out.attribute(null, ATTR_IS_AUXILIARY,
3847 String.valueOf(subtype.isAuxiliary() ? 1 : 0));
Yohei Yukawa1e1a4472016-03-10 23:46:07 -08003848 out.attribute(null, ATTR_IS_ASCII_CAPABLE,
3849 String.valueOf(subtype.isAsciiCapable() ? 1 : 0));
satoke7c6998e2011-06-03 17:57:59 +09003850 out.endTag(null, NODE_SUBTYPE);
3851 }
3852 out.endTag(null, NODE_IMI);
3853 }
3854 out.endTag(null, NODE_SUBTYPES);
3855 out.endDocument();
3856 subtypesFile.finishWrite(fos);
3857 } catch (java.io.IOException e) {
3858 Slog.w(TAG, "Error writing subtypes", e);
3859 if (fos != null) {
3860 subtypesFile.failWrite(fos);
3861 }
3862 }
3863 }
3864
3865 private static void readAdditionalInputMethodSubtypes(
3866 HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) {
3867 if (allSubtypes == null || subtypesFile == null) return;
3868 allSubtypes.clear();
Yohei Yukawa5894b432015-08-11 13:29:24 -07003869 try (final FileInputStream fis = subtypesFile.openRead()) {
satoke7c6998e2011-06-03 17:57:59 +09003870 final XmlPullParser parser = Xml.newPullParser();
Wojciech Staszkiewicz9e9e2e72015-05-08 14:58:46 +01003871 parser.setInput(fis, StandardCharsets.UTF_8.name());
satoke7c6998e2011-06-03 17:57:59 +09003872 int type = parser.getEventType();
3873 // Skip parsing until START_TAG
3874 while ((type = parser.next()) != XmlPullParser.START_TAG
3875 && type != XmlPullParser.END_DOCUMENT) {}
3876 String firstNodeName = parser.getName();
3877 if (!NODE_SUBTYPES.equals(firstNodeName)) {
3878 throw new XmlPullParserException("Xml doesn't start with subtypes");
3879 }
3880 final int depth =parser.getDepth();
3881 String currentImiId = null;
3882 ArrayList<InputMethodSubtype> tempSubtypesArray = null;
3883 while (((type = parser.next()) != XmlPullParser.END_TAG
3884 || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
3885 if (type != XmlPullParser.START_TAG)
3886 continue;
3887 final String nodeName = parser.getName();
3888 if (NODE_IMI.equals(nodeName)) {
3889 currentImiId = parser.getAttributeValue(null, ATTR_ID);
3890 if (TextUtils.isEmpty(currentImiId)) {
3891 Slog.w(TAG, "Invalid imi id found in subtypes.xml");
3892 continue;
3893 }
Yohei Yukawab0377bb2015-08-10 21:06:30 -07003894 tempSubtypesArray = new ArrayList<>();
satoke7c6998e2011-06-03 17:57:59 +09003895 allSubtypes.put(currentImiId, tempSubtypesArray);
3896 } else if (NODE_SUBTYPE.equals(nodeName)) {
3897 if (TextUtils.isEmpty(currentImiId) || tempSubtypesArray == null) {
3898 Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId);
3899 continue;
3900 }
Narayan Kamatha09b4d22016-04-15 18:32:45 +01003901 final int icon = Integer.parseInt(
satoke7c6998e2011-06-03 17:57:59 +09003902 parser.getAttributeValue(null, ATTR_ICON));
Narayan Kamatha09b4d22016-04-15 18:32:45 +01003903 final int label = Integer.parseInt(
satoke7c6998e2011-06-03 17:57:59 +09003904 parser.getAttributeValue(null, ATTR_LABEL));
3905 final String imeSubtypeLocale =
3906 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE);
Yohei Yukawa868d19b2015-12-07 15:58:57 -08003907 final String languageTag =
3908 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LANGUAGE_TAG);
satoke7c6998e2011-06-03 17:57:59 +09003909 final String imeSubtypeMode =
3910 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_MODE);
3911 final String imeSubtypeExtraValue =
3912 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_EXTRA_VALUE);
satok4a28bde2011-06-29 21:03:40 +09003913 final boolean isAuxiliary = "1".equals(String.valueOf(
3914 parser.getAttributeValue(null, ATTR_IS_AUXILIARY)));
Yohei Yukawa1e1a4472016-03-10 23:46:07 -08003915 final boolean isAsciiCapable = "1".equals(String.valueOf(
3916 parser.getAttributeValue(null, ATTR_IS_ASCII_CAPABLE)));
Yohei Yukawa66baf692016-04-11 02:29:35 -07003917 final InputMethodSubtypeBuilder builder = new InputMethodSubtypeBuilder()
Yohei Yukawa443c2ba2014-09-10 14:10:30 +09003918 .setSubtypeNameResId(label)
3919 .setSubtypeIconResId(icon)
3920 .setSubtypeLocale(imeSubtypeLocale)
Yohei Yukawa868d19b2015-12-07 15:58:57 -08003921 .setLanguageTag(languageTag)
Yohei Yukawa443c2ba2014-09-10 14:10:30 +09003922 .setSubtypeMode(imeSubtypeMode)
3923 .setSubtypeExtraValue(imeSubtypeExtraValue)
3924 .setIsAuxiliary(isAuxiliary)
Yohei Yukawa66baf692016-04-11 02:29:35 -07003925 .setIsAsciiCapable(isAsciiCapable);
3926 final String subtypeIdString =
3927 parser.getAttributeValue(null, ATTR_IME_SUBTYPE_ID);
3928 if (subtypeIdString != null) {
Narayan Kamatha09b4d22016-04-15 18:32:45 +01003929 builder.setSubtypeId(Integer.parseInt(subtypeIdString));
Yohei Yukawa66baf692016-04-11 02:29:35 -07003930 }
3931 tempSubtypesArray.add(builder.build());
satoke7c6998e2011-06-03 17:57:59 +09003932 }
3933 }
Yohei Yukawa5894b432015-08-11 13:29:24 -07003934 } catch (XmlPullParserException | IOException | NumberFormatException e) {
3935 Slog.w(TAG, "Error reading subtypes", e);
satoke7c6998e2011-06-03 17:57:59 +09003936 return;
satoke7c6998e2011-06-03 17:57:59 +09003937 }
3938 }
3939 }
3940
Yohei Yukawafa6e0a82015-07-23 15:08:59 -07003941 private static final class LocalServiceImpl implements InputMethodManagerInternal {
3942 @NonNull
3943 private final Handler mHandler;
3944
3945 LocalServiceImpl(@NonNull final Handler handler) {
3946 mHandler = handler;
3947 }
3948
3949 @Override
3950 public void setInteractive(boolean interactive) {
3951 // Do everything in handler so as not to block the caller.
3952 mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_INTERACTIVE,
3953 interactive ? 1 : 0, 0));
3954 }
Yohei Yukawaae61f712015-12-09 13:00:10 -08003955
3956 @Override
3957 public void switchInputMethod(boolean forwardDirection) {
3958 // Do everything in handler so as not to block the caller.
3959 mHandler.sendMessage(mHandler.obtainMessage(MSG_SWITCH_IME,
3960 forwardDirection ? 1 : 0, 0));
3961 }
Jorim Jaggi3c5d0f12016-05-24 19:04:30 -07003962
3963 @Override
3964 public void hideCurrentInputMethod() {
3965 mHandler.removeMessages(MSG_HIDE_CURRENT_INPUT_METHOD);
3966 mHandler.sendEmptyMessage(MSG_HIDE_CURRENT_INPUT_METHOD);
3967 }
Yohei Yukawafa6e0a82015-07-23 15:08:59 -07003968 }
3969
Yohei Yukawaebda7d72016-04-02 17:39:23 -07003970 private static String imeWindowStatusToString(final int imeWindowVis) {
3971 final StringBuilder sb = new StringBuilder();
3972 boolean first = true;
3973 if ((imeWindowVis & InputMethodService.IME_ACTIVE) != 0) {
3974 sb.append("Active");
3975 first = false;
3976 }
3977 if ((imeWindowVis & InputMethodService.IME_VISIBLE) != 0) {
3978 if (!first) {
3979 sb.append("|");
3980 }
3981 sb.append("Visible");
3982 }
3983 return sb.toString();
3984 }
3985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003986 @Override
Yohei Yukawa25e08132016-06-22 16:31:41 -07003987 public IInputContentUriToken createInputContentUriToken(@Nullable IBinder token,
3988 @Nullable Uri contentUri, @Nullable String packageName) {
3989 if (!calledFromValidUser()) {
3990 return null;
3991 }
3992
3993 if (token == null) {
3994 throw new NullPointerException("token");
3995 }
3996 if (packageName == null) {
3997 throw new NullPointerException("packageName");
3998 }
3999 if (contentUri == null) {
4000 throw new NullPointerException("contentUri");
4001 }
4002 final String contentUriScheme = contentUri.getScheme();
4003 if (!"content".equals(contentUriScheme)) {
4004 throw new InvalidParameterException("contentUri must have content scheme");
4005 }
4006
4007 synchronized (mMethodMap) {
4008 final int uid = Binder.getCallingUid();
4009 if (mCurMethodId == null) {
4010 return null;
4011 }
4012 if (mCurToken != token) {
4013 Slog.e(TAG, "Ignoring createInputContentUriToken mCurToken=" + mCurToken
4014 + " token=" + token);
4015 return null;
4016 }
4017 // We cannot simply distinguish a bad IME that reports an arbitrary package name from
4018 // an unfortunate IME whose internal state is already obsolete due to the asynchronous
4019 // nature of our system. Let's compare it with our internal record.
4020 if (!TextUtils.equals(mCurAttribute.packageName, packageName)) {
4021 Slog.e(TAG, "Ignoring createInputContentUriToken mCurAttribute.packageName="
4022 + mCurAttribute.packageName + " packageName=" + packageName);
4023 return null;
4024 }
Yohei Yukawa3933a6e2016-11-10 00:47:48 -08004025 // This user ID can never bee spoofed.
Yohei Yukawa25e08132016-06-22 16:31:41 -07004026 final int imeUserId = UserHandle.getUserId(uid);
Yohei Yukawa3933a6e2016-11-10 00:47:48 -08004027 // This user ID can never bee spoofed.
Yohei Yukawa25e08132016-06-22 16:31:41 -07004028 final int appUserId = UserHandle.getUserId(mCurClient.uid);
Yohei Yukawa3933a6e2016-11-10 00:47:48 -08004029 // This user ID may be invalid if "contentUri" embedded an invalid user ID.
4030 final int contentUriOwnerUserId = ContentProvider.getUserIdFromUri(contentUri,
4031 imeUserId);
4032 final Uri contentUriWithoutUserId = ContentProvider.getUriWithoutUserId(contentUri);
4033 // Note: InputContentUriTokenHandler.take() checks whether the IME (specified by "uid")
4034 // actually has the right to grant a read permission for "contentUriWithoutUserId" that
4035 // is claimed to belong to "contentUriOwnerUserId". For example, specifying random
4036 // content URI and/or contentUriOwnerUserId just results in a SecurityException thrown
4037 // from InputContentUriTokenHandler.take() and can never be allowed beyond what is
4038 // actually allowed to "uid", which is guaranteed to be the IME's one.
4039 return new InputContentUriTokenHandler(contentUriWithoutUserId, uid,
4040 packageName, contentUriOwnerUserId, appUserId);
Yohei Yukawa25e08132016-06-22 16:31:41 -07004041 }
4042 }
4043
4044 @Override
Yohei Yukawa2bc66172017-02-08 11:13:25 -08004045 public void reportFullscreenMode(IBinder token, boolean fullscreen) {
4046 if (!calledFromValidUser()) {
4047 return;
4048 }
4049 synchronized (mMethodMap) {
4050 if (!calledWithValidToken(token)) {
4051 return;
4052 }
4053 if (mCurClient != null && mCurClient.client != null) {
4054 mInFullscreenMode = fullscreen;
4055 executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
4056 MSG_REPORT_FULLSCREEN_MODE, fullscreen ? 1 : 0, mCurClient));
4057 }
4058 }
4059 }
4060
4061 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004062 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
4063 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4064 != PackageManager.PERMISSION_GRANTED) {
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004066 pw.println("Permission Denial: can't dump InputMethodManager from from pid="
4067 + Binder.getCallingPid()
4068 + ", uid=" + Binder.getCallingUid());
4069 return;
4070 }
4071
4072 IInputMethod method;
4073 ClientState client;
Yohei Yukawae39d4ed2015-11-19 03:38:49 -08004074 ClientState focusedWindowClient;
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 final Printer p = new PrintWriterPrinter(pw);
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004078 synchronized (mMethodMap) {
4079 p.println("Current Input Method Manager state:");
4080 int N = mMethodList.size();
Yohei Yukawae0733062017-02-09 22:49:35 -08004081 p.println(" Input Methods: mMethodMapUpdateCount=" + mMethodMapUpdateCount);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004082 for (int i=0; i<N; i++) {
4083 InputMethodInfo info = mMethodList.get(i);
4084 p.println(" InputMethod #" + i + ":");
4085 info.dump(p, " ");
4086 }
4087 p.println(" Clients:");
4088 for (ClientState ci : mClients.values()) {
4089 p.println(" Client " + ci + ":");
4090 p.println(" client=" + ci.client);
4091 p.println(" inputContext=" + ci.inputContext);
4092 p.println(" sessionRequested=" + ci.sessionRequested);
4093 p.println(" curSession=" + ci.curSession);
4094 }
The Android Open Source Project10592532009-03-18 17:39:46 -07004095 p.println(" mCurMethodId=" + mCurMethodId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004096 client = mCurClient;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07004097 p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq);
Yohei Yukawa22a89232017-02-12 16:38:59 -08004098 p.println(" mCurFocusedWindow=" + mCurFocusedWindow
4099 + " softInputMode=" +
4100 InputMethodClient.softInputModeToString(mCurFocusedWindowSoftInputMode)
4101 + " client=" + mCurFocusedWindowClient);
Yohei Yukawae39d4ed2015-11-19 03:38:49 -08004102 focusedWindowClient = mCurFocusedWindowClient;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004103 p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection
4104 + " mBoundToMethod=" + mBoundToMethod);
4105 p.println(" mCurToken=" + mCurToken);
4106 p.println(" mCurIntent=" + mCurIntent);
4107 method = mCurMethod;
4108 p.println(" mCurMethod=" + mCurMethod);
4109 p.println(" mEnabledSession=" + mEnabledSession);
Yohei Yukawaebda7d72016-04-02 17:39:23 -07004110 p.println(" mImeWindowVis=" + imeWindowStatusToString(mImeWindowVis));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004111 p.println(" mShowRequested=" + mShowRequested
4112 + " mShowExplicitlyRequested=" + mShowExplicitlyRequested
4113 + " mShowForced=" + mShowForced
4114 + " mInputShown=" + mInputShown);
Yohei Yukawa2bc66172017-02-08 11:13:25 -08004115 p.println(" mInFullscreenMode=" + mInFullscreenMode);
Yohei Yukawa3d1e8122014-06-06 19:12:47 +09004116 p.println(" mCurUserActionNotificationSequenceNumber="
4117 + mCurUserActionNotificationSequenceNumber);
Yohei Yukawafa6e0a82015-07-23 15:08:59 -07004118 p.println(" mSystemReady=" + mSystemReady + " mInteractive=" + mIsInteractive);
Yohei Yukawa81482972015-06-04 00:58:59 -07004119 p.println(" mSettingsObserver=" + mSettingsObserver);
Yohei Yukawad7248862015-06-03 23:56:12 -07004120 p.println(" mSwitchingController:");
4121 mSwitchingController.dump(p);
Yohei Yukawa68645a62016-02-17 07:54:20 -08004122 p.println(" mSettings:");
4123 mSettings.dumpLocked(p, " ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004124 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004125
Jeff Brownb88102f2010-09-08 11:49:43 -07004126 p.println(" ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 if (client != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004128 pw.flush();
4129 try {
Jeff Sharkey850c83e2016-11-09 12:25:44 -07004130 TransferPipe.dumpAsync(client.client.asBinder(), fd, args);
4131 } catch (IOException | RemoteException e) {
4132 p.println("Failed to dump input method client: " + e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004133 }
Jeff Brownb88102f2010-09-08 11:49:43 -07004134 } else {
4135 p.println("No input method client.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004136 }
Doug Zongkerab5c49c2009-12-04 10:31:43 -08004137
Yohei Yukawae39d4ed2015-11-19 03:38:49 -08004138 if (focusedWindowClient != null && client != focusedWindowClient) {
4139 p.println(" ");
4140 p.println("Warning: Current input method client doesn't match the last focused. "
4141 + "window.");
4142 p.println("Dumping input method client in the last focused window just in case.");
4143 p.println(" ");
4144 pw.flush();
4145 try {
Jeff Sharkey850c83e2016-11-09 12:25:44 -07004146 TransferPipe.dumpAsync(focusedWindowClient.client.asBinder(), fd, args);
4147 } catch (IOException | RemoteException e) {
4148 p.println("Failed to dump input method client in focused window: " + e);
Yohei Yukawae39d4ed2015-11-19 03:38:49 -08004149 }
4150 }
4151
Jeff Brownb88102f2010-09-08 11:49:43 -07004152 p.println(" ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004153 if (method != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004154 pw.flush();
4155 try {
Jeff Sharkey850c83e2016-11-09 12:25:44 -07004156 TransferPipe.dumpAsync(method.asBinder(), fd, args);
4157 } catch (IOException | RemoteException e) {
4158 p.println("Failed to dump input method service: " + e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004159 }
Jeff Brownb88102f2010-09-08 11:49:43 -07004160 } else {
4161 p.println("No input method service.");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004162 }
4163 }
4164}