The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3 | * 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 Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 6 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 8 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 9 | * 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 | |
| 16 | package com.android.server; |
| 17 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 18 | import com.android.internal.content.PackageMonitor; |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 19 | import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController; |
Satoshi Kataoka | d787f69 | 2013-10-26 04:44:21 +0900 | [diff] [blame] | 20 | import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 21 | import com.android.internal.inputmethod.InputMethodUtils; |
| 22 | import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import com.android.internal.os.HandlerCaller; |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 24 | import com.android.internal.os.SomeArgs; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 25 | import com.android.internal.util.FastXmlSerializer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import com.android.internal.view.IInputContext; |
| 27 | import com.android.internal.view.IInputMethod; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import com.android.internal.view.IInputMethodClient; |
| 29 | import com.android.internal.view.IInputMethodManager; |
| 30 | import com.android.internal.view.IInputMethodSession; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 31 | import com.android.internal.view.IInputSessionCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import com.android.internal.view.InputBindResult; |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 33 | import com.android.internal.view.InputMethodClient; |
Adam Lesinski | ef2ea1f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 34 | import com.android.server.statusbar.StatusBarManagerService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 36 | import org.xmlpull.v1.XmlPullParser; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import org.xmlpull.v1.XmlPullParserException; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 38 | import org.xmlpull.v1.XmlSerializer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 40 | import android.annotation.NonNull; |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 41 | import android.annotation.Nullable; |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 42 | import android.annotation.UserIdInt; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | import android.app.ActivityManagerNative; |
| 44 | import android.app.AlertDialog; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 45 | import android.app.AppGlobals; |
Yohei Yukawa | e63b5fa | 2014-09-19 13:14:55 +0900 | [diff] [blame] | 46 | import android.app.AppOpsManager; |
satok | f90a33e | 2011-07-19 11:55:52 +0900 | [diff] [blame] | 47 | import android.app.KeyguardManager; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 48 | import android.app.Notification; |
| 49 | import android.app.NotificationManager; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 50 | import android.app.PendingIntent; |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 51 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.content.ComponentName; |
| 53 | import android.content.ContentResolver; |
| 54 | import android.content.Context; |
| 55 | import android.content.DialogInterface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.content.DialogInterface.OnCancelListener; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 57 | import android.content.DialogInterface.OnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.content.Intent; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 59 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.content.ServiceConnection; |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 61 | import android.content.pm.ApplicationInfo; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 62 | import android.content.pm.IPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.content.pm.PackageManager; |
| 64 | import android.content.pm.ResolveInfo; |
| 65 | import android.content.pm.ServiceInfo; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 66 | import android.content.pm.UserInfo; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 67 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | import android.content.res.Resources; |
| 69 | import android.content.res.TypedArray; |
| 70 | import android.database.ContentObserver; |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 71 | import android.graphics.drawable.Drawable; |
Yohei Yukawa | b097b82 | 2015-12-01 10:43:08 -0800 | [diff] [blame] | 72 | import android.hardware.input.InputManagerInternal; |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 73 | import android.inputmethodservice.InputMethodService; |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 74 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | import android.os.Binder; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 76 | import android.os.Bundle; |
Seigo Nonaka | e27dc2b | 2015-08-14 18:21:27 -0700 | [diff] [blame] | 77 | import android.os.Debug; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 78 | import android.os.Environment; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import android.os.Handler; |
| 80 | import android.os.IBinder; |
| 81 | import android.os.IInterface; |
| 82 | import android.os.Message; |
| 83 | import android.os.Parcel; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 84 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import android.os.RemoteException; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 86 | import android.os.ResultReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | import android.os.ServiceManager; |
| 88 | import android.os.SystemClock; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 89 | import android.os.UserHandle; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 90 | import android.os.UserManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import android.provider.Settings; |
| 92 | import android.text.TextUtils; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 93 | import android.text.style.SuggestionSpan; |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 94 | import android.util.ArrayMap; |
| 95 | import android.util.ArraySet; |
Dianne Hackborn | 39606a0 | 2012-07-31 17:54:35 -0700 | [diff] [blame] | 96 | import android.util.AtomicFile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | import android.util.EventLog; |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 98 | import android.util.LocaleList; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 99 | import android.util.LruCache; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 100 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | import android.util.PrintWriterPrinter; |
| 102 | import android.util.Printer; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 103 | import android.util.Slog; |
| 104 | import android.util.Xml; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 105 | import android.view.ContextThemeWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | import android.view.IWindowManager; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 107 | import android.view.InputChannel; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 108 | import android.view.LayoutInflater; |
| 109 | import android.view.View; |
| 110 | import android.view.ViewGroup; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | import android.view.WindowManager; |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 112 | import android.view.WindowManagerInternal; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 113 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | import android.view.inputmethod.InputBinding; |
| 115 | import android.view.inputmethod.InputMethod; |
| 116 | import android.view.inputmethod.InputMethodInfo; |
| 117 | import android.view.inputmethod.InputMethodManager; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 118 | import android.view.inputmethod.InputMethodManagerInternal; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 119 | import android.view.inputmethod.InputMethodSubtype; |
Yohei Yukawa | 443c2ba | 2014-09-10 14:10:30 +0900 | [diff] [blame] | 120 | import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 121 | import android.widget.ArrayAdapter; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 122 | import android.widget.CompoundButton; |
| 123 | import android.widget.CompoundButton.OnCheckedChangeListener; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 124 | import android.widget.RadioButton; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 125 | import android.widget.Switch; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 126 | import android.widget.TextView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 128 | import java.io.File; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | import java.io.FileDescriptor; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 130 | import java.io.FileInputStream; |
| 131 | import java.io.FileOutputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | import java.io.IOException; |
| 133 | import java.io.PrintWriter; |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 134 | import java.nio.charset.StandardCharsets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | import java.util.ArrayList; |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 136 | import java.util.Collections; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | import java.util.HashMap; |
| 138 | import java.util.List; |
| 139 | |
| 140 | /** |
| 141 | * This class provides a system service that manages input methods. |
| 142 | */ |
| 143 | public class InputMethodManagerService extends IInputMethodManager.Stub |
| 144 | implements ServiceConnection, Handler.Callback { |
| 145 | static final boolean DEBUG = false; |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 146 | static final boolean DEBUG_RESTORE = DEBUG || false; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 147 | static final String TAG = "InputMethodManagerService"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | |
Seigo Nonaka | d4474cb | 2015-05-04 16:53:24 -0700 | [diff] [blame] | 149 | static final int MSG_SHOW_IM_SUBTYPE_PICKER = 1; |
| 150 | static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 2; |
| 151 | static final int MSG_SHOW_IM_CONFIG = 3; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 152 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | static final int MSG_UNBIND_INPUT = 1000; |
| 154 | static final int MSG_BIND_INPUT = 1010; |
| 155 | static final int MSG_SHOW_SOFT_INPUT = 1020; |
| 156 | static final int MSG_HIDE_SOFT_INPUT = 1030; |
| 157 | static final int MSG_ATTACH_TOKEN = 1040; |
| 158 | static final int MSG_CREATE_SESSION = 1050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | static final int MSG_START_INPUT = 2000; |
| 161 | static final int MSG_RESTART_INPUT = 2010; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 162 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 163 | static final int MSG_UNBIND_CLIENT = 3000; |
| 164 | static final int MSG_BIND_CLIENT = 3010; |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 165 | static final int MSG_SET_ACTIVE = 3020; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 166 | static final int MSG_SET_INTERACTIVE = 3030; |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 167 | static final int MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER = 3040; |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 168 | static final int MSG_SWITCH_IME = 3050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 169 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 170 | static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000; |
| 171 | |
Satoshi Kataoka | bcacc32 | 2013-10-21 17:57:27 -0700 | [diff] [blame] | 172 | static final long TIME_TO_RECONNECT = 3 * 1000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 173 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 174 | static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20; |
| 175 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 176 | private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID; |
satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 177 | private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher"; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 178 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 179 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | final Context mContext; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 181 | final Resources mRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | final Handler mHandler; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 183 | final InputMethodSettings mSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | final SettingsObserver mSettingsObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | final IWindowManager mIWindowManager; |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 186 | final WindowManagerInternal mWindowManagerInternal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | final HandlerCaller mCaller; |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 188 | final boolean mHasFeature; |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 189 | private InputMethodFileManager mFileManager; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 190 | private final HardKeyboardListener mHardKeyboardListener; |
Yohei Yukawa | e63b5fa | 2014-09-19 13:14:55 +0900 | [diff] [blame] | 191 | private final AppOpsManager mAppOpsManager; |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 192 | private final UserManager mUserManager; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 193 | |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 194 | final InputBindResult mNoBinding = new InputBindResult(null, null, null, -1, -1); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | // All known input methods. mMethodMap also serves as the global |
| 197 | // lock for this class. |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 198 | final ArrayList<InputMethodInfo> mMethodList = new ArrayList<>(); |
| 199 | final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<>(); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 200 | private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans = |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 201 | new LruCache<>(SECURE_SUGGESTION_SPANS_MAX_SIZE); |
Satoshi Kataoka | d787f69 | 2013-10-26 04:44:21 +0900 | [diff] [blame] | 202 | private final InputMethodSubtypeSwitchingController mSwitchingController; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 203 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 204 | // Used to bring IME service up to visible adjustment while it is being shown. |
| 205 | final ServiceConnection mVisibleConnection = new ServiceConnection() { |
| 206 | @Override public void onServiceConnected(ComponentName name, IBinder service) { |
| 207 | } |
| 208 | |
| 209 | @Override public void onServiceDisconnected(ComponentName name) { |
| 210 | } |
| 211 | }; |
| 212 | boolean mVisibleBound = false; |
| 213 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 214 | // Ongoing notification |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 215 | private NotificationManager mNotificationManager; |
| 216 | private KeyguardManager mKeyguardManager; |
| 217 | private StatusBarManagerService mStatusBar; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 218 | private Notification.Builder mImeSwitcherNotification; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 219 | private PendingIntent mImeSwitchPendingIntent; |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 220 | private boolean mShowOngoingImeSwitcherForPhones; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 221 | private boolean mNotificationShown; |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 222 | private final boolean mImeSelectedOnBoot; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 223 | |
Tadashi G. Takaoka | 8c6d477 | 2014-08-05 15:29:17 +0900 | [diff] [blame] | 224 | static class SessionState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | final ClientState client; |
| 226 | final IInputMethod method; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 227 | |
| 228 | IInputMethodSession session; |
| 229 | InputChannel channel; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | @Override |
| 232 | public String toString() { |
| 233 | return "SessionState{uid " + client.uid + " pid " + client.pid |
| 234 | + " method " + Integer.toHexString( |
| 235 | System.identityHashCode(method)) |
| 236 | + " session " + Integer.toHexString( |
| 237 | System.identityHashCode(session)) |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 238 | + " channel " + channel |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | + "}"; |
| 240 | } |
| 241 | |
| 242 | SessionState(ClientState _client, IInputMethod _method, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 243 | IInputMethodSession _session, InputChannel _channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | client = _client; |
| 245 | method = _method; |
| 246 | session = _session; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 247 | channel = _channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | } |
| 249 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 250 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 251 | static final class ClientState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | final IInputMethodClient client; |
| 253 | final IInputContext inputContext; |
| 254 | final int uid; |
| 255 | final int pid; |
| 256 | final InputBinding binding; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | boolean sessionRequested; |
| 259 | SessionState curSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | @Override |
| 262 | public String toString() { |
| 263 | return "ClientState{" + Integer.toHexString( |
| 264 | System.identityHashCode(this)) + " uid " + uid |
| 265 | + " pid " + pid + "}"; |
| 266 | } |
| 267 | |
| 268 | ClientState(IInputMethodClient _client, IInputContext _inputContext, |
| 269 | int _uid, int _pid) { |
| 270 | client = _client; |
| 271 | inputContext = _inputContext; |
| 272 | uid = _uid; |
| 273 | pid = _pid; |
| 274 | binding = new InputBinding(null, inputContext.asBinder(), uid, pid); |
| 275 | } |
| 276 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 277 | |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 278 | final HashMap<IBinder, ClientState> mClients = new HashMap<>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | /** |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 281 | * Set once the system is ready to run third party code. |
| 282 | */ |
| 283 | boolean mSystemReady; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 284 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 285 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 286 | * Id obtained with {@link InputMethodInfo#getId()} for the currently selected input method. |
| 287 | * method. This is to be synchronized with the secure settings keyed with |
| 288 | * {@link Settings.Secure#DEFAULT_INPUT_METHOD}. |
| 289 | * |
| 290 | * <p>This can be transiently {@code null} when the system is re-initializing input method |
| 291 | * settings, e.g., the system locale is just changed.</p> |
| 292 | * |
| 293 | * <p>Note that {@link #mCurId} is used to track which IME is being connected to |
| 294 | * {@link InputMethodManagerService}.</p> |
| 295 | * |
| 296 | * @see #mCurId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 298 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | String mCurMethodId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | /** |
| 302 | * The current binding sequence number, incremented every time there is |
| 303 | * a new bind performed. |
| 304 | */ |
| 305 | int mCurSeq; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | /** |
| 308 | * The client that is currently bound to an input method. |
| 309 | */ |
| 310 | ClientState mCurClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 311 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | /** |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 313 | * The last window token that we confirmed to be focused. This is always updated upon reports |
| 314 | * from the input method client. If the window state is already changed before the report is |
| 315 | * handled, this field just keeps the last value. |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 316 | */ |
| 317 | IBinder mCurFocusedWindow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 318 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 319 | /** |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 320 | * The client by which {@link #mCurFocusedWindow} was reported. Used only for debugging. |
| 321 | */ |
| 322 | ClientState mCurFocusedWindowClient; |
| 323 | |
| 324 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | * The input context last provided by the current client. |
| 326 | */ |
| 327 | IInputContext mCurInputContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | /** |
| 330 | * The attributes last provided by the current client. |
| 331 | */ |
| 332 | EditorInfo mCurAttribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 333 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 335 | * Id obtained with {@link InputMethodInfo#getId()} for the input method that we are currently |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | * connected to or in the process of connecting to. |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 337 | * |
| 338 | * <p>This can be {@code null} when no input method is connected.</p> |
| 339 | * |
| 340 | * @see #mCurMethodId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 342 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | String mCurId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 344 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | /** |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 346 | * The current subtype of the current input method. |
| 347 | */ |
| 348 | private InputMethodSubtype mCurrentSubtype; |
| 349 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 350 | // This list contains the pairs of InputMethodInfo and InputMethodSubtype. |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 351 | private final HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>> |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 352 | mShortcutInputMethodsAndSubtypes = new HashMap<>(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 353 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 354 | // Was the keyguard locked when this client became current? |
| 355 | private boolean mCurClientInKeyguard; |
| 356 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 357 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | * Set to true if our ServiceConnection is currently actively bound to |
| 359 | * a service (whether or not we have gotten its IBinder back yet). |
| 360 | */ |
| 361 | boolean mHaveConnection; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 362 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | /** |
| 364 | * Set if the client has asked for the input method to be shown. |
| 365 | */ |
| 366 | boolean mShowRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | /** |
| 369 | * Set if we were explicitly told to show the input method. |
| 370 | */ |
| 371 | boolean mShowExplicitlyRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 372 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 373 | /** |
| 374 | * Set if we were forced to be shown. |
| 375 | */ |
| 376 | boolean mShowForced; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 377 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | /** |
| 379 | * Set if we last told the input method to show itself. |
| 380 | */ |
| 381 | boolean mInputShown; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | /** |
| 384 | * The Intent used to connect to the current input method. |
| 385 | */ |
| 386 | Intent mCurIntent; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 387 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | /** |
| 389 | * The token we have made for the currently active input method, to |
| 390 | * identify it in the future. |
| 391 | */ |
| 392 | IBinder mCurToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | /** |
| 395 | * If non-null, this is the input method service we are currently connected |
| 396 | * to. |
| 397 | */ |
| 398 | IInputMethod mCurMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 399 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | /** |
| 401 | * Time that we last initiated a bind to the input method, to determine |
| 402 | * if we should try to disconnect and reconnect to it. |
| 403 | */ |
| 404 | long mLastBindTime; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 405 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 406 | /** |
| 407 | * Have we called mCurMethod.bindInput()? |
| 408 | */ |
| 409 | boolean mBoundToMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | /** |
| 412 | * Currently enabled session. Only touched by service thread, not |
| 413 | * protected by a lock. |
| 414 | */ |
| 415 | SessionState mEnabledSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | /** |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 418 | * True if the device is currently interactive with user. The value is true initially. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | */ |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 420 | boolean mIsInteractive = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 421 | |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 422 | int mCurUserActionNotificationSequenceNumber = 0; |
| 423 | |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 424 | int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 425 | |
| 426 | /** |
| 427 | * A set of status bits regarding the active IME. |
| 428 | * |
| 429 | * <p>This value is a combination of following two bits:</p> |
| 430 | * <dl> |
| 431 | * <dt>{@link InputMethodService#IME_ACTIVE}</dt> |
| 432 | * <dd> |
| 433 | * If this bit is ON, connected IME is ready to accept touch/key events. |
| 434 | * </dd> |
| 435 | * <dt>{@link InputMethodService#IME_VISIBLE}</dt> |
| 436 | * <dd> |
| 437 | * If this bit is ON, some of IME view, e.g. software input, candidate view, is visible. |
| 438 | * </dd> |
| 439 | * </dl> |
| 440 | * <em>Do not update this value outside of setImeWindowStatus.</em> |
| 441 | */ |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 442 | int mImeWindowVis; |
| 443 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 444 | private AlertDialog.Builder mDialogBuilder; |
| 445 | private AlertDialog mSwitchingDialog; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 446 | private View mSwitchingDialogTitleView; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 447 | private InputMethodInfo[] mIms; |
| 448 | private int[] mSubtypeIds; |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 449 | private LocaleList mLastSystemLocales; |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 450 | private boolean mShowImeWithHardKeyboard; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 451 | private boolean mAccessibilityRequestingNoSoftKeyboard; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 452 | private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor(); |
| 453 | private final IPackageManager mIPackageManager; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 454 | private final String mSlotIme; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | class SettingsObserver extends ContentObserver { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 457 | int mUserId; |
| 458 | boolean mRegistered = false; |
Yohei Yukawa | 7b574cb | 2016-03-16 17:22:22 -0700 | [diff] [blame^] | 459 | @NonNull |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 460 | String mLastEnabled = ""; |
| 461 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 462 | /** |
| 463 | * <em>This constructor must be called within the lock.</em> |
| 464 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | SettingsObserver(Handler handler) { |
| 466 | super(handler); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 469 | public void registerContentObserverLocked(@UserIdInt int userId) { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 470 | if (mRegistered && mUserId == userId) { |
| 471 | return; |
| 472 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | ContentResolver resolver = mContext.getContentResolver(); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 474 | if (mRegistered) { |
| 475 | mContext.getContentResolver().unregisterContentObserver(this); |
| 476 | mRegistered = false; |
| 477 | } |
| 478 | if (mUserId != userId) { |
| 479 | mLastEnabled = ""; |
| 480 | mUserId = userId; |
| 481 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 483 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, userId); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 484 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 485 | Settings.Secure.ENABLED_INPUT_METHODS), false, this, userId); |
satok | b6109bb | 2011-02-03 22:24:54 +0900 | [diff] [blame] | 486 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 487 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this, userId); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 488 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 489 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD), false, this, userId); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 490 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 491 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE), false, this, userId); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 492 | mRegistered = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 494 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 495 | @Override public void onChange(boolean selfChange, Uri uri) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 496 | final Uri showImeUri = Settings.Secure.getUriFor( |
| 497 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD); |
| 498 | final Uri accessibilityRequestingNoImeUri = Settings.Secure.getUriFor( |
| 499 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | synchronized (mMethodMap) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 501 | if (showImeUri.equals(uri)) { |
| 502 | updateKeyboardFromSettingsLocked(); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 503 | } else if (accessibilityRequestingNoImeUri.equals(uri)) { |
| 504 | mAccessibilityRequestingNoSoftKeyboard = Settings.Secure.getIntForUser( |
| 505 | mContext.getContentResolver(), |
| 506 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE, |
| 507 | 0, mUserId) == 1; |
| 508 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 509 | final boolean showRequested = mShowRequested; |
| 510 | hideCurrentInputLocked(0, null); |
| 511 | mShowRequested = showRequested; |
| 512 | } else if (mShowRequested) { |
| 513 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| 514 | } |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 515 | } else { |
| 516 | boolean enabledChanged = false; |
| 517 | String newEnabled = mSettings.getEnabledInputMethodsStr(); |
| 518 | if (!mLastEnabled.equals(newEnabled)) { |
| 519 | mLastEnabled = newEnabled; |
| 520 | enabledChanged = true; |
| 521 | } |
| 522 | updateInputMethodsFromSettingsLocked(enabledChanged); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 523 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | } |
| 525 | } |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 526 | |
| 527 | @Override |
| 528 | public String toString() { |
| 529 | return "SettingsObserver{mUserId=" + mUserId + " mRegistered=" + mRegistered |
| 530 | + " mLastEnabled=" + mLastEnabled + "}"; |
| 531 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 533 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 534 | class ImmsBroadcastReceiver extends android.content.BroadcastReceiver { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 535 | @Override |
| 536 | public void onReceive(Context context, Intent intent) { |
| 537 | final String action = intent.getAction(); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 538 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 539 | hideInputMethodMenu(); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 540 | // No need to update mIsInteractive |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 541 | return; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 542 | } else if (Intent.ACTION_USER_ADDED.equals(action) |
| 543 | || Intent.ACTION_USER_REMOVED.equals(action)) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 544 | updateCurrentProfileIds(); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 545 | return; |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 546 | } else if (Intent.ACTION_SETTING_RESTORED.equals(action)) { |
| 547 | final String name = intent.getStringExtra(Intent.EXTRA_SETTING_NAME); |
| 548 | if (Settings.Secure.ENABLED_INPUT_METHODS.equals(name)) { |
| 549 | final String prevValue = intent.getStringExtra( |
| 550 | Intent.EXTRA_SETTING_PREVIOUS_VALUE); |
| 551 | final String newValue = intent.getStringExtra( |
| 552 | Intent.EXTRA_SETTING_NEW_VALUE); |
| 553 | restoreEnabledInputMethods(mContext, prevValue, newValue); |
| 554 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 555 | } else { |
| 556 | Slog.w(TAG, "Unexpected intent " + intent); |
| 557 | } |
| 558 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 560 | |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 561 | // Apply the results of a restore operation to the set of enabled IMEs. Note that this |
| 562 | // does not attempt to validate on the fly with any installed device policy, so must only |
| 563 | // be run in the context of initial device setup. |
| 564 | // |
| 565 | // TODO: Move this method to InputMethodUtils with adding unit tests. |
| 566 | static void restoreEnabledInputMethods(Context context, String prevValue, String newValue) { |
| 567 | if (DEBUG_RESTORE) { |
| 568 | Slog.i(TAG, "Restoring enabled input methods:"); |
| 569 | Slog.i(TAG, "prev=" + prevValue); |
| 570 | Slog.i(TAG, " new=" + newValue); |
| 571 | } |
| 572 | // 'new' is the just-restored state, 'prev' is what was in settings prior to the restore |
Seigo Nonaka | 2028dda | 2015-07-06 17:41:24 +0900 | [diff] [blame] | 573 | ArrayMap<String, ArraySet<String>> prevMap = |
| 574 | InputMethodUtils.parseInputMethodsAndSubtypesString(prevValue); |
| 575 | ArrayMap<String, ArraySet<String>> newMap = |
| 576 | InputMethodUtils.parseInputMethodsAndSubtypesString(newValue); |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 577 | |
| 578 | // Merge the restored ime+subtype enabled states into the live state |
| 579 | for (ArrayMap.Entry<String, ArraySet<String>> entry : newMap.entrySet()) { |
| 580 | final String imeId = entry.getKey(); |
| 581 | ArraySet<String> prevSubtypes = prevMap.get(imeId); |
| 582 | if (prevSubtypes == null) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 583 | prevSubtypes = new ArraySet<>(2); |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 584 | prevMap.put(imeId, prevSubtypes); |
| 585 | } |
| 586 | prevSubtypes.addAll(entry.getValue()); |
| 587 | } |
| 588 | |
Seigo Nonaka | 2a099bc | 2015-08-14 19:29:45 -0700 | [diff] [blame] | 589 | final String mergedImesAndSubtypesString = |
| 590 | InputMethodUtils.buildInputMethodsAndSubtypesString(prevMap); |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 591 | if (DEBUG_RESTORE) { |
| 592 | Slog.i(TAG, "Merged IME string:"); |
| 593 | Slog.i(TAG, " " + mergedImesAndSubtypesString); |
| 594 | } |
| 595 | Settings.Secure.putString(context.getContentResolver(), |
| 596 | Settings.Secure.ENABLED_INPUT_METHODS, mergedImesAndSubtypesString); |
| 597 | } |
| 598 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 599 | class MyPackageMonitor extends PackageMonitor { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 600 | private boolean isChangingPackagesOfCurrentUser() { |
| 601 | final int userId = getChangingUserId(); |
| 602 | final boolean retval = userId == mSettings.getCurrentUserId(); |
| 603 | if (DEBUG) { |
satok | 81f8b7c | 2012-12-04 20:42:56 +0900 | [diff] [blame] | 604 | if (!retval) { |
| 605 | Slog.d(TAG, "--- ignore this call back from a background user: " + userId); |
| 606 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 607 | } |
| 608 | return retval; |
| 609 | } |
| 610 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 611 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 612 | public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 613 | if (!isChangingPackagesOfCurrentUser()) { |
| 614 | return false; |
| 615 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | synchronized (mMethodMap) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 617 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | final int N = mMethodList.size(); |
| 619 | if (curInputMethodId != null) { |
| 620 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 621 | InputMethodInfo imi = mMethodList.get(i); |
| 622 | if (imi.getId().equals(curInputMethodId)) { |
| 623 | for (String pkg : packages) { |
| 624 | if (imi.getPackageName().equals(pkg)) { |
| 625 | if (!doit) { |
| 626 | return true; |
| 627 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 628 | resetSelectedInputMethodAndSubtypeLocked(""); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 629 | chooseNewDefaultIMELocked(); |
| 630 | return true; |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | return false; |
| 638 | } |
| 639 | |
| 640 | @Override |
| 641 | public void onSomePackagesChanged() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 642 | if (!isChangingPackagesOfCurrentUser()) { |
| 643 | return; |
| 644 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 645 | synchronized (mMethodMap) { |
| 646 | InputMethodInfo curIm = null; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 647 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 648 | final int N = mMethodList.size(); |
| 649 | if (curInputMethodId != null) { |
| 650 | for (int i=0; i<N; i++) { |
| 651 | InputMethodInfo imi = mMethodList.get(i); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 652 | final String imiId = imi.getId(); |
| 653 | if (imiId.equals(curInputMethodId)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 654 | curIm = imi; |
| 655 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 656 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 657 | int change = isPackageDisappearing(imi.getPackageName()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 658 | if (isPackageModified(imi.getPackageName())) { |
| 659 | mFileManager.deleteAllInputMethodSubtypes(imiId); |
| 660 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 661 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 662 | || change == PACKAGE_PERMANENT_CHANGE) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 663 | Slog.i(TAG, "Input method uninstalled, disabling: " |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 664 | + imi.getComponent()); |
| 665 | setInputMethodEnabledLocked(imi.getId(), false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 669 | |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 670 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 673 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 674 | if (curIm != null) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 675 | int change = isPackageDisappearing(curIm.getPackageName()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 676 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 677 | || change == PACKAGE_PERMANENT_CHANGE) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 678 | ServiceInfo si = null; |
| 679 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 680 | si = mIPackageManager.getServiceInfo( |
| 681 | curIm.getComponent(), 0, mSettings.getCurrentUserId()); |
| 682 | } catch (RemoteException ex) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 683 | } |
| 684 | if (si == null) { |
| 685 | // Uh oh, current input method is no longer around! |
| 686 | // Pick another one... |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 687 | Slog.i(TAG, "Current input method removed: " + curInputMethodId); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 688 | updateSystemUiLocked(mCurToken, 0 /* vis */, mBackDisposition); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 689 | if (!chooseNewDefaultIMELocked()) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 690 | changed = true; |
| 691 | curIm = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 692 | Slog.i(TAG, "Unsetting current input method"); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 693 | resetSelectedInputMethodAndSubtypeLocked(""); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 694 | } |
| 695 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 696 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 697 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 698 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 699 | if (curIm == null) { |
| 700 | // We currently don't have a default input method... is |
| 701 | // one now available? |
| 702 | changed = chooseNewDefaultIMELocked(); |
Yohei Yukawa | 54d512c | 2015-05-19 22:15:02 -0700 | [diff] [blame] | 703 | } else if (!changed && isPackageModified(curIm.getPackageName())) { |
| 704 | // Even if the current input method is still available, mCurrentSubtype could |
| 705 | // be obsolete when the package is modified in practice. |
| 706 | changed = true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 707 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 708 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 709 | if (changed) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 710 | updateFromSettingsLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | } |
| 714 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 715 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 716 | private static final class MethodCallback extends IInputSessionCallback.Stub { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 717 | private final InputMethodManagerService mParentIMMS; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 718 | private final IInputMethod mMethod; |
| 719 | private final InputChannel mChannel; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 720 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 721 | MethodCallback(InputMethodManagerService imms, IInputMethod method, |
| 722 | InputChannel channel) { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 723 | mParentIMMS = imms; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 724 | mMethod = method; |
| 725 | mChannel = channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 726 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 727 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 728 | @Override |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 729 | public void sessionCreated(IInputMethodSession session) { |
Dianne Hackborn | 6b6b3fd | 2014-03-24 11:27:18 -0700 | [diff] [blame] | 730 | long ident = Binder.clearCallingIdentity(); |
| 731 | try { |
| 732 | mParentIMMS.onSessionCreated(mMethod, session, mChannel); |
| 733 | } finally { |
| 734 | Binder.restoreCallingIdentity(ident); |
| 735 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | } |
| 737 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 738 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 739 | private class HardKeyboardListener |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 740 | implements WindowManagerInternal.OnHardKeyboardStatusChangeListener { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 741 | @Override |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 742 | public void onHardKeyboardStatusChange(boolean available) { |
| 743 | mHandler.sendMessage(mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED, |
| 744 | available ? 1 : 0)); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 745 | } |
| 746 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 747 | public void handleHardKeyboardStatusChange(boolean available) { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 748 | if (DEBUG) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 749 | Slog.w(TAG, "HardKeyboardStatusChanged: available=" + available); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 750 | } |
| 751 | synchronized(mMethodMap) { |
| 752 | if (mSwitchingDialog != null && mSwitchingDialogTitleView != null |
| 753 | && mSwitchingDialog.isShowing()) { |
| 754 | mSwitchingDialogTitleView.findViewById( |
| 755 | com.android.internal.R.id.hard_keyboard_section).setVisibility( |
| 756 | available ? View.VISIBLE : View.GONE); |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 762 | public static final class Lifecycle extends SystemService { |
| 763 | private InputMethodManagerService mService; |
| 764 | |
| 765 | public Lifecycle(Context context) { |
| 766 | super(context); |
| 767 | mService = new InputMethodManagerService(context); |
| 768 | } |
| 769 | |
| 770 | @Override |
| 771 | public void onStart() { |
| 772 | LocalServices.addService(InputMethodManagerInternal.class, |
| 773 | new LocalServiceImpl(mService.mHandler)); |
| 774 | publishBinderService(Context.INPUT_METHOD_SERVICE, mService); |
| 775 | } |
| 776 | |
| 777 | @Override |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 778 | public void onSwitchUser(@UserIdInt int userHandle) { |
| 779 | // Called on the system server's main looper thread. |
| 780 | // TODO: Dispatch this to a worker thread as needed. |
| 781 | mService.onSwitchUser(userHandle); |
| 782 | } |
| 783 | |
| 784 | @Override |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 785 | public void onBootPhase(int phase) { |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 786 | // Called on the system server's main looper thread. |
| 787 | // TODO: Dispatch this to a worker thread as needed. |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 788 | if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) { |
| 789 | StatusBarManagerService statusBarService = (StatusBarManagerService) ServiceManager |
| 790 | .getService(Context.STATUS_BAR_SERVICE); |
| 791 | mService.systemRunning(statusBarService); |
| 792 | } |
| 793 | } |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 794 | |
| 795 | @Override |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 796 | public void onUnlockUser(@UserIdInt int userHandle) { |
| 797 | // Called on the system server's main looper thread. |
| 798 | // TODO: Dispatch this to a worker thread as needed. |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 799 | mService.onUnlockUser(userHandle); |
| 800 | } |
| 801 | } |
| 802 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 803 | void onUnlockUser(@UserIdInt int userId) { |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 804 | synchronized(mMethodMap) { |
| 805 | final int currentUserId = mSettings.getCurrentUserId(); |
| 806 | if (DEBUG) { |
| 807 | Slog.d(TAG, "onUnlockUser: userId=" + userId + " curUserId=" + currentUserId); |
| 808 | } |
| 809 | if (userId != currentUserId) { |
| 810 | return; |
| 811 | } |
| 812 | mSettings.switchCurrentUser(currentUserId, !mSystemReady); |
| 813 | // We need to rebuild IMEs. |
| 814 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
| 815 | updateInputMethodsFromSettingsLocked(true /* enabledChanged */); |
| 816 | } |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 817 | } |
| 818 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 819 | void onSwitchUser(@UserIdInt int userId) { |
| 820 | synchronized (mMethodMap) { |
| 821 | switchUserLocked(userId); |
| 822 | } |
| 823 | } |
| 824 | |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 825 | public InputMethodManagerService(Context context) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 826 | mIPackageManager = AppGlobals.getPackageManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 827 | mContext = context; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 828 | mRes = context.getResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | mHandler = new Handler(this); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 830 | // Note: SettingsObserver doesn't register observers in its constructor. |
| 831 | mSettingsObserver = new SettingsObserver(mHandler); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 833 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 834 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 835 | mCaller = new HandlerCaller(context, null, new HandlerCaller.Callback() { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 836 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | public void executeMessage(Message msg) { |
| 838 | handleMessage(msg); |
| 839 | } |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 840 | }, true /*asyncHandler*/); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 841 | mAppOpsManager = mContext.getSystemService(AppOpsManager.class); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 842 | mUserManager = mContext.getSystemService(UserManager.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 843 | mHardKeyboardListener = new HardKeyboardListener(); |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 844 | mHasFeature = context.getPackageManager().hasSystemFeature( |
| 845 | PackageManager.FEATURE_INPUT_METHODS); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 846 | mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 847 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 848 | Bundle extras = new Bundle(); |
| 849 | extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true); |
| 850 | mImeSwitcherNotification = new Notification.Builder(mContext) |
| 851 | .setSmallIcon(com.android.internal.R.drawable.ic_notification_ime_default) |
| 852 | .setWhen(0) |
| 853 | .setOngoing(true) |
| 854 | .addExtras(extras) |
| 855 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 856 | .setColor(com.android.internal.R.color.system_notification_accent_color); |
Daniel Sandler | 590d515 | 2012-06-14 16:10:13 -0400 | [diff] [blame] | 857 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 858 | Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER); |
satok | 683e238 | 2011-07-12 08:28:52 +0900 | [diff] [blame] | 859 | mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 860 | |
| 861 | mShowOngoingImeSwitcherForPhones = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 862 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 863 | final IntentFilter broadcastFilter = new IntentFilter(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 864 | broadcastFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 865 | broadcastFilter.addAction(Intent.ACTION_USER_ADDED); |
| 866 | broadcastFilter.addAction(Intent.ACTION_USER_REMOVED); |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 867 | broadcastFilter.addAction(Intent.ACTION_SETTING_RESTORED); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 868 | mContext.registerReceiver(new ImmsBroadcastReceiver(), broadcastFilter); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 869 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 870 | mNotificationShown = false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 871 | int userId = 0; |
| 872 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 873 | userId = ActivityManagerNative.getDefault().getCurrentUser().id; |
| 874 | } catch (RemoteException e) { |
| 875 | Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e); |
| 876 | } |
satok | 81f8b7c | 2012-12-04 20:42:56 +0900 | [diff] [blame] | 877 | mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 878 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 879 | // mSettings should be created before buildInputMethodListLocked |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 880 | mSettings = new InputMethodSettings( |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 881 | mRes, context.getContentResolver(), mMethodMap, mMethodList, userId, !mSystemReady); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 882 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 883 | updateCurrentProfileIds(); |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 884 | mFileManager = new InputMethodFileManager(mMethodMap, userId); |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 885 | synchronized (mMethodMap) { |
| 886 | mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked( |
| 887 | mSettings, context); |
| 888 | } |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 889 | |
| 890 | // Just checking if defaultImiId is empty or not |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 891 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 892 | if (DEBUG) { |
| 893 | Slog.d(TAG, "Initial default ime = " + defaultImiId); |
| 894 | } |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 895 | mImeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId); |
| 896 | |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 897 | synchronized (mMethodMap) { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 898 | buildInputMethodListLocked(!mImeSelectedOnBoot /* resetDefaultEnabledIme */); |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 899 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 900 | mSettings.enableAllIMEsIfThereIsNoEnabledIME(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 902 | if (!mImeSelectedOnBoot) { |
| 903 | Slog.w(TAG, "No IME selected. Choose the most applicable IME."); |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 904 | synchronized (mMethodMap) { |
| 905 | resetDefaultImeLocked(context); |
| 906 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 908 | |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 909 | synchronized (mMethodMap) { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 910 | mSettingsObserver.registerContentObserverLocked(userId); |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 911 | updateFromSettingsLocked(true); |
| 912 | } |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 913 | |
| 914 | // IMMS wants to receive Intent.ACTION_LOCALE_CHANGED in order to update the current IME |
| 915 | // according to the new system locale. |
| 916 | final IntentFilter filter = new IntentFilter(); |
| 917 | filter.addAction(Intent.ACTION_LOCALE_CHANGED); |
| 918 | mContext.registerReceiver( |
| 919 | new BroadcastReceiver() { |
| 920 | @Override |
| 921 | public void onReceive(Context context, Intent intent) { |
| 922 | synchronized(mMethodMap) { |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 923 | resetStateIfCurrentLocaleChangedLocked(); |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 924 | } |
| 925 | } |
| 926 | }, filter); |
| 927 | } |
| 928 | |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 929 | private void resetDefaultImeLocked(Context context) { |
| 930 | // Do not reset the default (current) IME when it is a 3rd-party IME |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 931 | if (mCurMethodId != null && !InputMethodUtils.isSystemIme(mMethodMap.get(mCurMethodId))) { |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 932 | return; |
| 933 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 934 | final List<InputMethodInfo> suitableImes = InputMethodUtils.getDefaultEnabledImes( |
| 935 | context, mSystemReady, mSettings.getEnabledInputMethodListLocked()); |
| 936 | if (suitableImes.isEmpty()) { |
| 937 | Slog.i(TAG, "No default found"); |
| 938 | return; |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 939 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 940 | final InputMethodInfo defIm = suitableImes.get(0); |
| 941 | Slog.i(TAG, "Default found, using " + defIm.getId()); |
| 942 | setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false); |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 943 | } |
| 944 | |
Satoshi Kataoka | 7f7535f | 2013-02-18 12:54:16 +0900 | [diff] [blame] | 945 | private void resetAllInternalStateLocked(final boolean updateOnlyWhenLocaleChanged, |
| 946 | final boolean resetDefaultEnabledIme) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 947 | if (!mSystemReady) { |
| 948 | // not system ready |
| 949 | return; |
| 950 | } |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 951 | final LocaleList newLocales = mRes.getConfiguration().getLocales(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 952 | if (!updateOnlyWhenLocaleChanged |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 953 | || (newLocales != null && !newLocales.equals(mLastSystemLocales))) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 954 | if (!updateOnlyWhenLocaleChanged) { |
| 955 | hideCurrentInputLocked(0, null); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 956 | resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_RESET_IME); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 957 | } |
| 958 | if (DEBUG) { |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 959 | Slog.i(TAG, "LocaleList has been changed to " + newLocales); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 960 | } |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 961 | buildInputMethodListLocked(resetDefaultEnabledIme); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 962 | if (!updateOnlyWhenLocaleChanged) { |
| 963 | final String selectedImiId = mSettings.getSelectedInputMethod(); |
| 964 | if (TextUtils.isEmpty(selectedImiId)) { |
| 965 | // This is the first time of the user switch and |
| 966 | // set the current ime to the proper one. |
| 967 | resetDefaultImeLocked(mContext); |
| 968 | } |
Satoshi Kataoka | d08a923 | 2012-09-28 15:59:58 +0900 | [diff] [blame] | 969 | } else { |
| 970 | // If the locale is changed, needs to reset the default ime |
| 971 | resetDefaultImeLocked(mContext); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 972 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 973 | updateFromSettingsLocked(true); |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 974 | mLastSystemLocales = newLocales; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 975 | if (!updateOnlyWhenLocaleChanged) { |
| 976 | try { |
| 977 | startInputInnerLocked(); |
| 978 | } catch (RuntimeException e) { |
| 979 | Slog.w(TAG, "Unexpected exception", e); |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | } |
| 984 | |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 985 | private void resetStateIfCurrentLocaleChangedLocked() { |
Satoshi Kataoka | 7f7535f | 2013-02-18 12:54:16 +0900 | [diff] [blame] | 986 | resetAllInternalStateLocked(true /* updateOnlyWhenLocaleChanged */, |
| 987 | true /* resetDefaultImeLocked */); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 988 | } |
| 989 | |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 990 | private void switchUserLocked(int newUserId) { |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 991 | if (DEBUG) Slog.d(TAG, "Switching user stage 1/3. newUserId=" + newUserId |
| 992 | + " currentUserId=" + mSettings.getCurrentUserId()); |
| 993 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 994 | // ContentObserver should be registered again when the user is changed |
| 995 | mSettingsObserver.registerContentObserverLocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 996 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 997 | // If the system is not ready or the device is not yed unlocked by the user, then we use |
| 998 | // copy-on-write settings. |
| 999 | final boolean useCopyOnWriteSettings = |
| 1000 | !mSystemReady || !mUserManager.isUserUnlocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1001 | mSettings.switchCurrentUser(newUserId, useCopyOnWriteSettings); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1002 | updateCurrentProfileIds(); |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 1003 | // InputMethodFileManager should be reset when the user is changed |
| 1004 | mFileManager = new InputMethodFileManager(mMethodMap, newUserId); |
Satoshi Kataoka | 7f7535f | 2013-02-18 12:54:16 +0900 | [diff] [blame] | 1005 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1006 | |
| 1007 | if (DEBUG) Slog.d(TAG, "Switching user stage 2/3. newUserId=" + newUserId |
| 1008 | + " defaultImiId=" + defaultImiId); |
| 1009 | |
Satoshi Kataoka | 7c4a2a1 | 2013-02-25 15:25:43 +0900 | [diff] [blame] | 1010 | // For secondary users, the list of enabled IMEs may not have been updated since the |
| 1011 | // callbacks to PackageMonitor are ignored for the secondary user. Here, defaultImiId may |
| 1012 | // not be empty even if the IME has been uninstalled by the primary user. |
| 1013 | // Even in such cases, IMMS works fine because it will find the most applicable |
| 1014 | // IME for that user. |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1015 | final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId); |
Satoshi Kataoka | 7f7535f | 2013-02-18 12:54:16 +0900 | [diff] [blame] | 1016 | resetAllInternalStateLocked(false /* updateOnlyWhenLocaleChanged */, |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1017 | initialUserSwitch /* needsToResetDefaultIme */); |
| 1018 | if (initialUserSwitch) { |
Yohei Yukawa | 094c71f | 2015-06-20 00:41:31 -0700 | [diff] [blame] | 1019 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1020 | mSettings.getEnabledInputMethodListLocked(), newUserId, |
| 1021 | mContext.getBasePackageName()); |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1022 | } |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1023 | |
| 1024 | if (DEBUG) Slog.d(TAG, "Switching user stage 3/3. newUserId=" + newUserId |
| 1025 | + " selectedIme=" + mSettings.getSelectedInputMethod()); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1026 | } |
| 1027 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1028 | void updateCurrentProfileIds() { |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1029 | List<UserInfo> profiles = mUserManager.getProfiles(mSettings.getCurrentUserId()); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1030 | int[] currentProfileIds = new int[profiles.size()]; // profiles will not be null |
| 1031 | for (int i = 0; i < currentProfileIds.length; i++) { |
| 1032 | currentProfileIds[i] = profiles.get(i).id; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 1033 | } |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1034 | mSettings.setCurrentProfileIds(currentProfileIds); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 1035 | } |
| 1036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | @Override |
| 1038 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1039 | throws RemoteException { |
| 1040 | try { |
| 1041 | return super.onTransact(code, data, reply, flags); |
| 1042 | } catch (RuntimeException e) { |
| 1043 | // The input method manager only throws security exceptions, so let's |
| 1044 | // log all others. |
| 1045 | if (!(e instanceof SecurityException)) { |
Dianne Hackborn | 164371f | 2013-10-01 19:10:13 -0700 | [diff] [blame] | 1046 | Slog.wtf(TAG, "Input Method Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | } |
| 1048 | throw e; |
| 1049 | } |
| 1050 | } |
| 1051 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 1052 | public void systemRunning(StatusBarManagerService statusBar) { |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1053 | synchronized (mMethodMap) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1054 | if (DEBUG) { |
| 1055 | Slog.d(TAG, "--- systemReady"); |
| 1056 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1057 | if (!mSystemReady) { |
| 1058 | mSystemReady = true; |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1059 | final int currentUserId = mSettings.getCurrentUserId(); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1060 | mSettings.switchCurrentUser(currentUserId, |
| 1061 | !mUserManager.isUserUnlocked(currentUserId)); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 1062 | mKeyguardManager = mContext.getSystemService(KeyguardManager.class); |
| 1063 | mNotificationManager = mContext.getSystemService(NotificationManager.class); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1064 | mStatusBar = statusBar; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 1065 | statusBar.setIconVisibility(mSlotIme, false); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1066 | updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 1067 | mShowOngoingImeSwitcherForPhones = mRes.getBoolean( |
| 1068 | com.android.internal.R.bool.show_ongoing_ime_switcher); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1069 | if (mShowOngoingImeSwitcherForPhones) { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1070 | mWindowManagerInternal.setOnHardKeyboardStatusChangeListener( |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1071 | mHardKeyboardListener); |
| 1072 | } |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 1073 | buildInputMethodListLocked(!mImeSelectedOnBoot /* resetDefaultEnabledIme */); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 1074 | if (!mImeSelectedOnBoot) { |
| 1075 | Slog.w(TAG, "Reset the default IME as \"Resource\" is ready here."); |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1076 | resetStateIfCurrentLocaleChangedLocked(); |
Yohei Yukawa | 094c71f | 2015-06-20 00:41:31 -0700 | [diff] [blame] | 1077 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1078 | mSettings.getEnabledInputMethodListLocked(), |
| 1079 | mSettings.getCurrentUserId(), mContext.getBasePackageName()); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 1080 | } |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 1081 | mLastSystemLocales = mRes.getConfiguration().getLocales(); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1082 | try { |
| 1083 | startInputInnerLocked(); |
| 1084 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1085 | Slog.w(TAG, "Unexpected exception", e); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1086 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1087 | } |
| 1088 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1089 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1090 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1091 | // --------------------------------------------------------------------------------------- |
| 1092 | // Check whether or not this is a valid IPC. Assumes an IPC is valid when either |
| 1093 | // 1) it comes from the system process |
| 1094 | // 2) the calling process' user id is identical to the current user id IMMS thinks. |
| 1095 | private boolean calledFromValidUser() { |
| 1096 | final int uid = Binder.getCallingUid(); |
| 1097 | final int userId = UserHandle.getUserId(uid); |
| 1098 | if (DEBUG) { |
| 1099 | Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? " |
| 1100 | + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID |
| 1101 | + " calling userId = " + userId + ", foreground user id = " |
Satoshi Kataoka | 87c2914 | 2013-07-31 23:11:54 +0900 | [diff] [blame] | 1102 | + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid() |
| 1103 | + InputMethodUtils.getApiCallStack()); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1104 | } |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1105 | if (uid == Process.SYSTEM_UID || mSettings.isCurrentProfile(userId)) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1106 | return true; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1107 | } |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1108 | |
| 1109 | // Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the |
| 1110 | // foreground user, not for the user of that process. Accordingly InputMethodManagerService |
| 1111 | // must not manage background users' states in any functions. |
| 1112 | // Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded |
| 1113 | // by a token. |
| 1114 | if (mContext.checkCallingOrSelfPermission( |
| 1115 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
| 1116 | == PackageManager.PERMISSION_GRANTED) { |
| 1117 | if (DEBUG) { |
| 1118 | Slog.d(TAG, "--- Access granted because the calling process has " |
| 1119 | + "the INTERACT_ACROSS_USERS_FULL permission"); |
| 1120 | } |
| 1121 | return true; |
| 1122 | } |
Seigo Nonaka | e27dc2b | 2015-08-14 18:21:27 -0700 | [diff] [blame] | 1123 | Slog.w(TAG, "--- IPC called from background users. Ignore. callers=" |
| 1124 | + Debug.getCallers(10)); |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1125 | return false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1126 | } |
| 1127 | |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 1128 | |
| 1129 | /** |
| 1130 | * Returns true iff the caller is identified to be the current input method with the token. |
| 1131 | * @param token The window token given to the input method when it was started. |
| 1132 | * @return true if and only if non-null valid token is specified. |
| 1133 | */ |
| 1134 | private boolean calledWithValidToken(IBinder token) { |
| 1135 | if (token == null || mCurToken != token) { |
| 1136 | return false; |
| 1137 | } |
| 1138 | return true; |
| 1139 | } |
| 1140 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1141 | private boolean bindCurrentInputMethodService( |
| 1142 | Intent service, ServiceConnection conn, int flags) { |
| 1143 | if (service == null || conn == null) { |
| 1144 | Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn); |
| 1145 | return false; |
| 1146 | } |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 1147 | return mContext.bindServiceAsUser(service, conn, flags, |
| 1148 | new UserHandle(mSettings.getCurrentUserId())); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1149 | } |
| 1150 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1151 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | public List<InputMethodInfo> getInputMethodList() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1153 | // TODO: Make this work even for non-current users? |
| 1154 | if (!calledFromValidUser()) { |
| 1155 | return Collections.emptyList(); |
| 1156 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | synchronized (mMethodMap) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 1158 | return new ArrayList<>(mMethodList); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | } |
| 1160 | } |
| 1161 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1162 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | public List<InputMethodInfo> getEnabledInputMethodList() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1164 | // TODO: Make this work even for non-current users? |
| 1165 | if (!calledFromValidUser()) { |
| 1166 | return Collections.emptyList(); |
| 1167 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | synchronized (mMethodMap) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1169 | return mSettings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1173 | /** |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1174 | * @param imiId if null, returns enabled subtypes for the current imi |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1175 | * @return enabled subtypes of the specified imi |
| 1176 | */ |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1177 | @Override |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1178 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId, |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 1179 | boolean allowsImplicitlySelectedSubtypes) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1180 | // TODO: Make this work even for non-current users? |
| 1181 | if (!calledFromValidUser()) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 1182 | return Collections.emptyList(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1183 | } |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1184 | synchronized (mMethodMap) { |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1185 | final InputMethodInfo imi; |
| 1186 | if (imiId == null && mCurMethodId != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1187 | imi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1188 | } else { |
| 1189 | imi = mMethodMap.get(imiId); |
| 1190 | } |
| 1191 | if (imi == null) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 1192 | return Collections.emptyList(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1193 | } |
| 1194 | return mSettings.getEnabledInputMethodSubtypeListLocked( |
| 1195 | mContext, imi, allowsImplicitlySelectedSubtypes); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1199 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1200 | public void addClient(IInputMethodClient client, |
| 1201 | IInputContext inputContext, int uid, int pid) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1202 | if (!calledFromValidUser()) { |
| 1203 | return; |
| 1204 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1205 | synchronized (mMethodMap) { |
| 1206 | mClients.put(client.asBinder(), new ClientState(client, |
| 1207 | inputContext, uid, pid)); |
| 1208 | } |
| 1209 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1210 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1211 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | public void removeClient(IInputMethodClient client) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1213 | if (!calledFromValidUser()) { |
| 1214 | return; |
| 1215 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1216 | synchronized (mMethodMap) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1217 | ClientState cs = mClients.remove(client.asBinder()); |
| 1218 | if (cs != null) { |
| 1219 | clearClientSessionLocked(cs); |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 1220 | if (mCurClient == cs) { |
| 1221 | mCurClient = null; |
| 1222 | } |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 1223 | if (mCurFocusedWindowClient == cs) { |
| 1224 | mCurFocusedWindowClient = null; |
| 1225 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1226 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | } |
| 1228 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | void executeOrSendMessage(IInterface target, Message msg) { |
| 1231 | if (target.asBinder() instanceof Binder) { |
| 1232 | mCaller.sendMessage(msg); |
| 1233 | } else { |
| 1234 | handleMessage(msg); |
| 1235 | msg.recycle(); |
| 1236 | } |
| 1237 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1238 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1239 | void unbindCurrentClientLocked( |
| 1240 | /* @InputMethodClient.UnbindReason */ final int unbindClientReason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1241 | if (mCurClient != null) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1242 | if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | + mCurClient.client.asBinder()); |
| 1244 | if (mBoundToMethod) { |
| 1245 | mBoundToMethod = false; |
| 1246 | if (mCurMethod != null) { |
| 1247 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 1248 | MSG_UNBIND_INPUT, mCurMethod)); |
| 1249 | } |
| 1250 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 1251 | |
| 1252 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 1253 | MSG_SET_ACTIVE, 0, mCurClient)); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1254 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 1255 | MSG_UNBIND_CLIENT, mCurSeq, unbindClientReason, mCurClient.client)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | mCurClient.sessionRequested = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | mCurClient = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1258 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1259 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1260 | } |
| 1261 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1262 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1263 | private int getImeShowFlags() { |
| 1264 | int flags = 0; |
| 1265 | if (mShowForced) { |
| 1266 | flags |= InputMethod.SHOW_FORCED |
| 1267 | | InputMethod.SHOW_EXPLICIT; |
| 1268 | } else if (mShowExplicitlyRequested) { |
| 1269 | flags |= InputMethod.SHOW_EXPLICIT; |
| 1270 | } |
| 1271 | return flags; |
| 1272 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1274 | private int getAppShowFlags() { |
| 1275 | int flags = 0; |
| 1276 | if (mShowForced) { |
| 1277 | flags |= InputMethodManager.SHOW_FORCED; |
| 1278 | } else if (!mShowExplicitlyRequested) { |
| 1279 | flags |= InputMethodManager.SHOW_IMPLICIT; |
| 1280 | } |
| 1281 | return flags; |
| 1282 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1283 | |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1284 | InputBindResult attachNewInputLocked(boolean initial) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1285 | if (!mBoundToMethod) { |
| 1286 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 1287 | MSG_BIND_INPUT, mCurMethod, mCurClient.binding)); |
| 1288 | mBoundToMethod = true; |
| 1289 | } |
| 1290 | final SessionState session = mCurClient.curSession; |
| 1291 | if (initial) { |
| 1292 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 1293 | MSG_START_INPUT, session, mCurInputContext, mCurAttribute)); |
| 1294 | } else { |
| 1295 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 1296 | MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute)); |
| 1297 | } |
| 1298 | if (mShowRequested) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1299 | if (DEBUG) Slog.v(TAG, "Attach new input asks to show input"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1300 | showCurrentInputLocked(getAppShowFlags(), null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | } |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 1302 | return new InputBindResult(session.session, |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1303 | (session.channel != null ? session.channel.dup() : null), |
| 1304 | mCurId, mCurSeq, mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1305 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1306 | |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1307 | InputBindResult startInputLocked( |
| 1308 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
| 1309 | IInputMethodClient client, IInputContext inputContext, EditorInfo attribute, |
| 1310 | int controlFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1311 | // If no method is currently selected, do nothing. |
| 1312 | if (mCurMethodId == null) { |
| 1313 | return mNoBinding; |
| 1314 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1315 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | ClientState cs = mClients.get(client.asBinder()); |
| 1317 | if (cs == null) { |
| 1318 | throw new IllegalArgumentException("unknown client " |
| 1319 | + client.asBinder()); |
| 1320 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | try { |
| 1323 | if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) { |
| 1324 | // Check with the window manager to make sure this client actually |
| 1325 | // has a window with focus. If not, reject. This is thread safe |
| 1326 | // because if the focus changes some time before or after, the |
| 1327 | // next client receiving focus that has any interest in input will |
| 1328 | // be calling through here after that change happens. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1329 | Slog.w(TAG, "Starting input on non-focused client " + cs.client |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
| 1331 | return null; |
| 1332 | } |
| 1333 | } catch (RemoteException e) { |
| 1334 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1335 | |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1336 | return startInputUncheckedLocked(cs, inputContext, attribute, controlFlags); |
| 1337 | } |
| 1338 | |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1339 | InputBindResult startInputUncheckedLocked(@NonNull ClientState cs, IInputContext inputContext, |
| 1340 | @NonNull EditorInfo attribute, int controlFlags) { |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1341 | // If no method is currently selected, do nothing. |
| 1342 | if (mCurMethodId == null) { |
| 1343 | return mNoBinding; |
| 1344 | } |
| 1345 | |
Yohei Yukawa | d57ba67 | 2015-06-08 16:39:46 -0700 | [diff] [blame] | 1346 | if (!InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, cs.uid, |
| 1347 | attribute.packageName)) { |
| 1348 | Slog.e(TAG, "Rejecting this client as it reported an invalid package name." |
| 1349 | + " uid=" + cs.uid + " package=" + attribute.packageName); |
| 1350 | return mNoBinding; |
Yohei Yukaw | a0f3ad1 | 2015-04-06 16:48:24 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1353 | if (mCurClient != cs) { |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 1354 | // Was the keyguard locked when switching over to the new client? |
| 1355 | mCurClientInKeyguard = isKeyguardLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1356 | // If the client is changing, we need to switch over to the new |
| 1357 | // one. |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1358 | unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_SWITCH_CLIENT); |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1359 | if (DEBUG) Slog.v(TAG, "switching to client: client=" |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 1360 | + cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1361 | |
| 1362 | // If the screen is on, inform the new client it is active |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 1363 | if (mIsInteractive) { |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 1364 | executeOrSendMessage(cs.client, mCaller.obtainMessageIO( |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 1365 | MSG_SET_ACTIVE, mIsInteractive ? 1 : 0, cs)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1366 | } |
| 1367 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | // Bump up the sequence for this client and attach it. |
| 1370 | mCurSeq++; |
| 1371 | if (mCurSeq <= 0) mCurSeq = 1; |
| 1372 | mCurClient = cs; |
| 1373 | mCurInputContext = inputContext; |
| 1374 | mCurAttribute = attribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1375 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | // Check if the input method is changing. |
| 1377 | if (mCurId != null && mCurId.equals(mCurMethodId)) { |
| 1378 | if (cs.curSession != null) { |
| 1379 | // Fast case: if we are already connected to the input method, |
| 1380 | // then just return it. |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1381 | return attachNewInputLocked( |
| 1382 | (controlFlags&InputMethodManager.CONTROL_START_INITIAL) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1383 | } |
| 1384 | if (mHaveConnection) { |
| 1385 | if (mCurMethod != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | // Return to client, and we will get back with it when |
| 1387 | // we have had a session made for it. |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1388 | requestClientSessionLocked(cs); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1389 | return new InputBindResult(null, null, mCurId, mCurSeq, |
| 1390 | mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1391 | } else if (SystemClock.uptimeMillis() |
| 1392 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 1393 | // In this case we have connected to the service, but |
| 1394 | // don't yet have its interface. If it hasn't been too |
| 1395 | // long since we did the connection, we'll return to |
| 1396 | // the client and wait to get the service interface so |
| 1397 | // we can report back. If it has been too long, we want |
| 1398 | // to fall through so we can try a disconnect/reconnect |
| 1399 | // to see if we can get back in touch with the service. |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1400 | return new InputBindResult(null, null, mCurId, mCurSeq, |
| 1401 | mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | } else { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1403 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, |
| 1404 | mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1408 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1409 | return startInputInnerLocked(); |
| 1410 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1411 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1412 | InputBindResult startInputInnerLocked() { |
| 1413 | if (mCurMethodId == null) { |
| 1414 | return mNoBinding; |
| 1415 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1416 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1417 | if (!mSystemReady) { |
| 1418 | // If the system is not yet ready, we shouldn't be running third |
| 1419 | // party code. |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1420 | return new InputBindResult(null, null, mCurMethodId, mCurSeq, |
| 1421 | mCurUserActionNotificationSequenceNumber); |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1422 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1424 | InputMethodInfo info = mMethodMap.get(mCurMethodId); |
| 1425 | if (info == null) { |
| 1426 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 1427 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1428 | |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 1429 | unbindCurrentMethodLocked(true); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1430 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1431 | mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE); |
| 1432 | mCurIntent.setComponent(info.getComponent()); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1433 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 1434 | com.android.internal.R.string.input_method_binding_label); |
| 1435 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 1436 | mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0)); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1437 | if (bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE |
Dianne Hackborn | f0f94d1 | 2014-03-17 16:04:21 -0700 | [diff] [blame] | 1438 | | Context.BIND_NOT_VISIBLE | Context.BIND_NOT_FOREGROUND |
| 1439 | | Context.BIND_SHOWING_UI)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1440 | mLastBindTime = SystemClock.uptimeMillis(); |
| 1441 | mHaveConnection = true; |
| 1442 | mCurId = info.getId(); |
| 1443 | mCurToken = new Binder(); |
| 1444 | try { |
Craig Mautner | ca0ac71 | 2013-03-14 09:43:02 -0700 | [diff] [blame] | 1445 | if (true || DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | mIWindowManager.addWindowToken(mCurToken, |
| 1447 | WindowManager.LayoutParams.TYPE_INPUT_METHOD); |
| 1448 | } catch (RemoteException e) { |
| 1449 | } |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 1450 | return new InputBindResult(null, null, mCurId, mCurSeq, |
| 1451 | mCurUserActionNotificationSequenceNumber); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | } else { |
| 1453 | mCurIntent = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1454 | Slog.w(TAG, "Failure connecting to input method service: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1455 | + mCurIntent); |
| 1456 | } |
| 1457 | return null; |
| 1458 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1459 | |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 1460 | private InputBindResult startInput( |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1461 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
| 1462 | IInputMethodClient client, IInputContext inputContext, EditorInfo attribute, |
| 1463 | int controlFlags) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1464 | if (!calledFromValidUser()) { |
| 1465 | return null; |
| 1466 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | synchronized (mMethodMap) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1468 | if (DEBUG) { |
| 1469 | Slog.v(TAG, "startInput: reason=" |
| 1470 | + InputMethodClient.getStartInputReason(startInputReason) |
| 1471 | + " client = " + client.asBinder() |
| 1472 | + " inputContext=" + inputContext |
| 1473 | + " attribute=" + attribute |
| 1474 | + " controlFlags=#" + Integer.toHexString(controlFlags)); |
| 1475 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1476 | final long ident = Binder.clearCallingIdentity(); |
| 1477 | try { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1478 | return startInputLocked(startInputReason, client, inputContext, attribute, |
| 1479 | controlFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1480 | } finally { |
| 1481 | Binder.restoreCallingIdentity(ident); |
| 1482 | } |
| 1483 | } |
| 1484 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1485 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1486 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1487 | public void finishInput(IInputMethodClient client) { |
| 1488 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1489 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1490 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1491 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 1492 | synchronized (mMethodMap) { |
| 1493 | if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { |
| 1494 | mCurMethod = IInputMethod.Stub.asInterface(service); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1495 | if (mCurToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1496 | Slog.w(TAG, "Service connected without a token!"); |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 1497 | unbindCurrentMethodLocked(false); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1498 | return; |
| 1499 | } |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 1500 | if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1501 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 1502 | MSG_ATTACH_TOKEN, mCurMethod, mCurToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1504 | clearClientSessionLocked(mCurClient); |
| 1505 | requestClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | } |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1511 | void onSessionCreated(IInputMethod method, IInputMethodSession session, |
| 1512 | InputChannel channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1513 | synchronized (mMethodMap) { |
| 1514 | if (mCurMethod != null && method != null |
| 1515 | && mCurMethod.asBinder() == method.asBinder()) { |
| 1516 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1517 | clearClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1518 | mCurClient.curSession = new SessionState(mCurClient, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1519 | method, session, channel); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1520 | InputBindResult res = attachNewInputLocked(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1521 | if (res.method != null) { |
| 1522 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1523 | MSG_BIND_CLIENT, mCurClient.client, res)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1524 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1525 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1526 | } |
| 1527 | } |
| 1528 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1529 | |
| 1530 | // Session abandoned. Close its associated input channel. |
| 1531 | channel.dispose(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1532 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1533 | |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 1534 | void unbindCurrentMethodLocked(boolean savePosition) { |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 1535 | if (mVisibleBound) { |
| 1536 | mContext.unbindService(mVisibleConnection); |
| 1537 | mVisibleBound = false; |
| 1538 | } |
| 1539 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1540 | if (mHaveConnection) { |
| 1541 | mContext.unbindService(this); |
| 1542 | mHaveConnection = false; |
| 1543 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1544 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1545 | if (mCurToken != null) { |
| 1546 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1547 | if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 1548 | if ((mImeWindowVis & InputMethodService.IME_ACTIVE) != 0 && savePosition) { |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 1549 | // The current IME is shown. Hence an IME switch (transition) is happening. |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1550 | mWindowManagerInternal.saveLastInputMethodWindowForTransition(); |
satok | e0a9941 | 2012-05-10 02:22:58 +0900 | [diff] [blame] | 1551 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1552 | mIWindowManager.removeWindowToken(mCurToken); |
| 1553 | } catch (RemoteException e) { |
| 1554 | } |
| 1555 | mCurToken = null; |
| 1556 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1557 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1558 | mCurId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1559 | clearCurMethodLocked(); |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 1560 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1561 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1562 | void resetCurrentMethodAndClient( |
| 1563 | /* @InputMethodClient.UnbindReason */ final int unbindClientReason) { |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 1564 | mCurMethodId = null; |
| 1565 | unbindCurrentMethodLocked(false); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1566 | unbindCurrentClientLocked(unbindClientReason); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1567 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1568 | |
| 1569 | void requestClientSessionLocked(ClientState cs) { |
| 1570 | if (!cs.sessionRequested) { |
| 1571 | if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs); |
| 1572 | InputChannel[] channels = InputChannel.openInputChannelPair(cs.toString()); |
| 1573 | cs.sessionRequested = true; |
| 1574 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOOO( |
| 1575 | MSG_CREATE_SESSION, mCurMethod, channels[1], |
| 1576 | new MethodCallback(this, mCurMethod, channels[0]))); |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | void clearClientSessionLocked(ClientState cs) { |
| 1581 | finishSessionLocked(cs.curSession); |
| 1582 | cs.curSession = null; |
| 1583 | cs.sessionRequested = false; |
| 1584 | } |
| 1585 | |
| 1586 | private void finishSessionLocked(SessionState sessionState) { |
| 1587 | if (sessionState != null) { |
| 1588 | if (sessionState.session != null) { |
| 1589 | try { |
| 1590 | sessionState.session.finishSession(); |
| 1591 | } catch (RemoteException e) { |
| 1592 | Slog.w(TAG, "Session failed to close due to remote exception", e); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1593 | updateSystemUiLocked(mCurToken, 0 /* vis */, mBackDisposition); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1594 | } |
| 1595 | sessionState.session = null; |
| 1596 | } |
| 1597 | if (sessionState.channel != null) { |
| 1598 | sessionState.channel.dispose(); |
| 1599 | sessionState.channel = null; |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 1600 | } |
| 1601 | } |
| 1602 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1603 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1604 | void clearCurMethodLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | if (mCurMethod != null) { |
| 1606 | for (ClientState cs : mClients.values()) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1607 | clearClientSessionLocked(cs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1608 | } |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 1609 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1610 | finishSessionLocked(mEnabledSession); |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 1611 | mEnabledSession = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1612 | mCurMethod = null; |
| 1613 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1614 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 1615 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1616 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1617 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1618 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1619 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1620 | public void onServiceDisconnected(ComponentName name) { |
| 1621 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1622 | if (DEBUG) Slog.v(TAG, "Service disconnected: " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | + " mCurIntent=" + mCurIntent); |
| 1624 | if (mCurMethod != null && mCurIntent != null |
| 1625 | && name.equals(mCurIntent.getComponent())) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1626 | clearCurMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1627 | // We consider this to be a new bind attempt, since the system |
| 1628 | // should now try to restart the service for us. |
| 1629 | mLastBindTime = SystemClock.uptimeMillis(); |
| 1630 | mShowRequested = mInputShown; |
| 1631 | mInputShown = false; |
| 1632 | if (mCurClient != null) { |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1633 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 1634 | MSG_UNBIND_CLIENT, InputMethodClient.UNBIND_REASON_DISCONNECT_IME, |
| 1635 | mCurSeq, mCurClient.client)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1636 | } |
| 1637 | } |
| 1638 | } |
| 1639 | } |
| 1640 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1641 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1642 | public void updateStatusIcon(IBinder token, String packageName, int iconId) { |
| 1643 | long ident = Binder.clearCallingIdentity(); |
| 1644 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1645 | synchronized (mMethodMap) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 1646 | if (!calledWithValidToken(token)) { |
| 1647 | final int uid = Binder.getCallingUid(); |
| 1648 | Slog.e(TAG, "Ignoring updateStatusIcon due to an invalid token. uid:" + uid |
| 1649 | + " token:" + token); |
| 1650 | return; |
| 1651 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | if (iconId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1653 | if (DEBUG) Slog.d(TAG, "hide the small icon for the input method"); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1654 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 1655 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | } else if (packageName != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1658 | if (DEBUG) Slog.d(TAG, "show a small icon for the input method"); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 1659 | CharSequence contentDescription = null; |
| 1660 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1661 | // Use PackageManager to load label |
| 1662 | final PackageManager packageManager = mContext.getPackageManager(); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 1663 | contentDescription = packageManager.getApplicationLabel( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1664 | mIPackageManager.getApplicationInfo(packageName, 0, |
| 1665 | mSettings.getCurrentUserId())); |
| 1666 | } catch (RemoteException e) { |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 1667 | /* ignore */ |
| 1668 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1669 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 1670 | mStatusBar.setIcon(mSlotIme, packageName, iconId, 0, |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1671 | contentDescription != null |
| 1672 | ? contentDescription.toString() : null); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 1673 | mStatusBar.setIconVisibility(mSlotIme, true); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1674 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | } finally { |
| 1678 | Binder.restoreCallingIdentity(ident); |
| 1679 | } |
| 1680 | } |
| 1681 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1682 | private boolean shouldShowImeSwitcherLocked(int visibility) { |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1683 | if (!mShowOngoingImeSwitcherForPhones) return false; |
Jason Monk | 807ef76 | 2014-05-08 15:47:46 -0400 | [diff] [blame] | 1684 | if (mSwitchingDialog != null) return false; |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 1685 | if (isScreenLocked()) return false; |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1686 | if ((visibility & InputMethodService.IME_ACTIVE) == 0) return false; |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1687 | if (mWindowManagerInternal.isHardKeyboardAvailable()) { |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 1688 | // When physical keyboard is attached, we show the ime switcher (or notification if |
| 1689 | // NavBar is not available) because SHOW_IME_WITH_HARD_KEYBOARD settings currently |
| 1690 | // exists in the IME switcher dialog. Might be OK to remove this condition once |
| 1691 | // SHOW_IME_WITH_HARD_KEYBOARD settings finds a good place to live. |
| 1692 | return true; |
| 1693 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1694 | if ((visibility & InputMethodService.IME_VISIBLE) == 0) return false; |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 1695 | |
| 1696 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 1697 | final int N = imis.size(); |
| 1698 | if (N > 2) return true; |
| 1699 | if (N < 1) return false; |
| 1700 | int nonAuxCount = 0; |
| 1701 | int auxCount = 0; |
| 1702 | InputMethodSubtype nonAuxSubtype = null; |
| 1703 | InputMethodSubtype auxSubtype = null; |
| 1704 | for(int i = 0; i < N; ++i) { |
| 1705 | final InputMethodInfo imi = imis.get(i); |
| 1706 | final List<InputMethodSubtype> subtypes = |
| 1707 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
| 1708 | final int subtypeCount = subtypes.size(); |
| 1709 | if (subtypeCount == 0) { |
| 1710 | ++nonAuxCount; |
| 1711 | } else { |
| 1712 | for (int j = 0; j < subtypeCount; ++j) { |
| 1713 | final InputMethodSubtype subtype = subtypes.get(j); |
| 1714 | if (!subtype.isAuxiliary()) { |
| 1715 | ++nonAuxCount; |
| 1716 | nonAuxSubtype = subtype; |
| 1717 | } else { |
| 1718 | ++auxCount; |
| 1719 | auxSubtype = subtype; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1720 | } |
| 1721 | } |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1722 | } |
| 1723 | } |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 1724 | if (nonAuxCount > 1 || auxCount > 1) { |
| 1725 | return true; |
| 1726 | } else if (nonAuxCount == 1 && auxCount == 1) { |
| 1727 | if (nonAuxSubtype != null && auxSubtype != null |
| 1728 | && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale()) |
| 1729 | || auxSubtype.overridesImplicitlyEnabledSubtype() |
| 1730 | || nonAuxSubtype.overridesImplicitlyEnabledSubtype()) |
| 1731 | && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) { |
| 1732 | return false; |
| 1733 | } |
| 1734 | return true; |
| 1735 | } |
| 1736 | return false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1737 | } |
| 1738 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 1739 | private boolean isKeyguardLocked() { |
| 1740 | return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked(); |
| 1741 | } |
| 1742 | |
satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 1743 | @SuppressWarnings("deprecation") |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1744 | @Override |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 1745 | public void setImeWindowStatus(IBinder token, int vis, int backDisposition) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1746 | if (!calledWithValidToken(token)) { |
| 1747 | final int uid = Binder.getCallingUid(); |
| 1748 | Slog.e(TAG, "Ignoring setImeWindowStatus due to an invalid token. uid:" + uid |
| 1749 | + " token:" + token); |
| 1750 | return; |
| 1751 | } |
| 1752 | |
| 1753 | synchronized (mMethodMap) { |
| 1754 | mImeWindowVis = vis; |
| 1755 | mBackDisposition = backDisposition; |
| 1756 | updateSystemUiLocked(token, vis, backDisposition); |
| 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | private void updateSystemUi(IBinder token, int vis, int backDisposition) { |
| 1761 | synchronized (mMethodMap) { |
| 1762 | updateSystemUiLocked(token, vis, backDisposition); |
| 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | // Caution! This method is called in this class. Handle multi-user carefully |
| 1767 | private void updateSystemUiLocked(IBinder token, int vis, int backDisposition) { |
| 1768 | if (!calledWithValidToken(token)) { |
| 1769 | final int uid = Binder.getCallingUid(); |
| 1770 | Slog.e(TAG, "Ignoring updateSystemUiLocked due to an invalid token. uid:" + uid |
| 1771 | + " token:" + token); |
| 1772 | return; |
| 1773 | } |
| 1774 | |
| 1775 | // TODO: Move this clearing calling identity block to setImeWindowStatus after making sure |
| 1776 | // all updateSystemUi happens on system previlege. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1777 | final long ident = Binder.clearCallingIdentity(); |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 1778 | try { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1779 | // apply policy for binder calls |
| 1780 | if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) { |
| 1781 | vis = 0; |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 1782 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1783 | // mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked(). |
| 1784 | final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis); |
| 1785 | if (mStatusBar != null) { |
| 1786 | mStatusBar.setImeWindowStatus(token, vis, backDisposition, |
| 1787 | needsToShowImeSwitcher); |
| 1788 | } |
| 1789 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 1790 | if (imi != null && needsToShowImeSwitcher) { |
| 1791 | // Used to load label |
| 1792 | final CharSequence title = mRes.getText( |
| 1793 | com.android.internal.R.string.select_input_method); |
| 1794 | final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName( |
| 1795 | mContext, imi, mCurrentSubtype); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1796 | mImeSwitcherNotification.setContentTitle(title) |
| 1797 | .setContentText(summary) |
| 1798 | .setContentIntent(mImeSwitchPendingIntent); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1799 | try { |
| 1800 | if ((mNotificationManager != null) |
| 1801 | && !mIWindowManager.hasNavigationBar()) { |
| 1802 | if (DEBUG) { |
| 1803 | Slog.d(TAG, "--- show notification: label = " + summary); |
| 1804 | } |
| 1805 | mNotificationManager.notifyAsUser(null, |
| 1806 | com.android.internal.R.string.select_input_method, |
| 1807 | mImeSwitcherNotification.build(), UserHandle.ALL); |
| 1808 | mNotificationShown = true; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1809 | } |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1810 | } catch (RemoteException e) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1811 | } |
| 1812 | } else { |
| 1813 | if (mNotificationShown && mNotificationManager != null) { |
| 1814 | if (DEBUG) { |
| 1815 | Slog.d(TAG, "--- hide notification"); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1816 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1817 | mNotificationManager.cancelAsUser(null, |
| 1818 | com.android.internal.R.string.select_input_method, UserHandle.ALL); |
| 1819 | mNotificationShown = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1820 | } |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 1821 | } |
| 1822 | } finally { |
| 1823 | Binder.restoreCallingIdentity(ident); |
| 1824 | } |
| 1825 | } |
| 1826 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1827 | @Override |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1828 | public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1829 | if (!calledFromValidUser()) { |
| 1830 | return; |
| 1831 | } |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1832 | synchronized (mMethodMap) { |
| 1833 | final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId); |
| 1834 | for (int i = 0; i < spans.length; ++i) { |
| 1835 | SuggestionSpan ss = spans[i]; |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1836 | if (!TextUtils.isEmpty(ss.getNotificationTargetClassName())) { |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1837 | mSecureSuggestionSpans.put(ss, currentImi); |
| 1838 | } |
| 1839 | } |
| 1840 | } |
| 1841 | } |
| 1842 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1843 | @Override |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1844 | public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1845 | if (!calledFromValidUser()) { |
| 1846 | return false; |
| 1847 | } |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1848 | synchronized (mMethodMap) { |
| 1849 | final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span); |
| 1850 | // TODO: Do not send the intent if the process of the targetImi is already dead. |
| 1851 | if (targetImi != null) { |
| 1852 | final String[] suggestions = span.getSuggestions(); |
| 1853 | if (index < 0 || index >= suggestions.length) return false; |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1854 | final String className = span.getNotificationTargetClassName(); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1855 | final Intent intent = new Intent(); |
| 1856 | // Ensures that only a class in the original IME package will receive the |
| 1857 | // notification. |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 1858 | intent.setClassName(targetImi.getPackageName(), className); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1859 | intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED); |
| 1860 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString); |
| 1861 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]); |
| 1862 | intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode()); |
Amith Yamasani | f043de9 | 2012-10-24 06:42:40 -0700 | [diff] [blame] | 1863 | final long ident = Binder.clearCallingIdentity(); |
| 1864 | try { |
| 1865 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
| 1866 | } finally { |
| 1867 | Binder.restoreCallingIdentity(ident); |
| 1868 | } |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1869 | return true; |
| 1870 | } |
| 1871 | } |
| 1872 | return false; |
| 1873 | } |
| 1874 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1875 | void updateFromSettingsLocked(boolean enabledMayChange) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1876 | updateInputMethodsFromSettingsLocked(enabledMayChange); |
| 1877 | updateKeyboardFromSettingsLocked(); |
| 1878 | } |
| 1879 | |
| 1880 | void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1881 | if (enabledMayChange) { |
| 1882 | List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 1883 | for (int i=0; i<enabled.size(); i++) { |
| 1884 | // We allow the user to select "disabled until used" apps, so if they |
| 1885 | // are enabling one of those here we now need to make it enabled. |
| 1886 | InputMethodInfo imm = enabled.get(i); |
| 1887 | try { |
| 1888 | ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(), |
| 1889 | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, |
| 1890 | mSettings.getCurrentUserId()); |
Satoshi Kataoka | 7987a31 | 2013-04-17 18:59:33 +0900 | [diff] [blame] | 1891 | if (ai != null && ai.enabledSetting |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1892 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1893 | if (DEBUG) { |
| 1894 | Slog.d(TAG, "Update state(" + imm.getId() |
| 1895 | + "): DISABLED_UNTIL_USED -> DEFAULT"); |
| 1896 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1897 | mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(), |
| 1898 | PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 1899 | PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(), |
| 1900 | mContext.getBasePackageName()); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1901 | } |
| 1902 | } catch (RemoteException e) { |
| 1903 | } |
| 1904 | } |
| 1905 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1906 | // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and |
| 1907 | // ENABLED_INPUT_METHODS is taking care of keeping them correctly in |
| 1908 | // sync, so we will never have a DEFAULT_INPUT_METHOD that is not |
| 1909 | // enabled. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1910 | String id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 1911 | // There is no input method selected, try to choose new applicable input method. |
| 1912 | if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1913 | id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 1914 | } |
| 1915 | if (!TextUtils.isEmpty(id)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1916 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1917 | setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1918 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1919 | Slog.w(TAG, "Unknown input method from prefs: " + id, e); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1920 | resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_SWITCH_IME_FAILED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 1922 | mShortcutInputMethodsAndSubtypes.clear(); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1923 | } else { |
| 1924 | // There is no longer an input method set, so stop any current one. |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1925 | resetCurrentMethodAndClient(InputMethodClient.UNBIND_REASON_NO_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1926 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 1927 | // Here is not the perfect place to reset the switching controller. Ideally |
| 1928 | // mSwitchingController and mSettings should be able to share the same state. |
| 1929 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 1930 | // the same enabled IMEs list. |
| 1931 | mSwitchingController.resetCircularListLocked(mContext); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1932 | |
| 1933 | } |
| 1934 | |
| 1935 | public void updateKeyboardFromSettingsLocked() { |
| 1936 | mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled(); |
| 1937 | if (mSwitchingDialog != null |
| 1938 | && mSwitchingDialogTitleView != null |
| 1939 | && mSwitchingDialog.isShowing()) { |
| 1940 | final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById( |
| 1941 | com.android.internal.R.id.hard_keyboard_switch); |
| 1942 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
| 1943 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1944 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1945 | |
Yohei Yukawa | b097b82 | 2015-12-01 10:43:08 -0800 | [diff] [blame] | 1946 | private void notifyInputMethodSubtypeChanged(final int userId, |
| 1947 | @Nullable final InputMethodInfo inputMethodInfo, |
| 1948 | @Nullable final InputMethodSubtype subtype) { |
| 1949 | final InputManagerInternal inputManagerInternal = |
| 1950 | LocalServices.getService(InputManagerInternal.class); |
| 1951 | if (inputManagerInternal != null) { |
| 1952 | inputManagerInternal.onInputMethodSubtypeChanged(userId, inputMethodInfo, subtype); |
| 1953 | } |
| 1954 | } |
| 1955 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1956 | /* package */ void setInputMethodLocked(String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1957 | InputMethodInfo info = mMethodMap.get(id); |
| 1958 | if (info == null) { |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1959 | throw new IllegalArgumentException("Unknown id: " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1960 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1961 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 1962 | // See if we need to notify a subtype change within the same IME. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1963 | if (id.equals(mCurMethodId)) { |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 1964 | final int subtypeCount = info.getSubtypeCount(); |
| 1965 | if (subtypeCount <= 0) { |
| 1966 | return; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 1967 | } |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 1968 | final InputMethodSubtype oldSubtype = mCurrentSubtype; |
| 1969 | final InputMethodSubtype newSubtype; |
| 1970 | if (subtypeId >= 0 && subtypeId < subtypeCount) { |
| 1971 | newSubtype = info.getSubtypeAt(subtypeId); |
| 1972 | } else { |
| 1973 | // If subtype is null, try to find the most applicable one from |
| 1974 | // getCurrentInputMethodSubtype. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1975 | newSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 1976 | } |
| 1977 | if (newSubtype == null || oldSubtype == null) { |
| 1978 | Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype |
| 1979 | + ", new subtype = " + newSubtype); |
| 1980 | return; |
| 1981 | } |
| 1982 | if (newSubtype != oldSubtype) { |
| 1983 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true); |
| 1984 | if (mCurMethod != null) { |
| 1985 | try { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 1986 | updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 1987 | mCurMethod.changeInputMethodSubtype(newSubtype); |
| 1988 | } catch (RemoteException e) { |
| 1989 | Slog.w(TAG, "Failed to call changeInputMethodSubtype"); |
Yohei Yukawa | b097b82 | 2015-12-01 10:43:08 -0800 | [diff] [blame] | 1990 | return; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1991 | } |
| 1992 | } |
Yohei Yukawa | b097b82 | 2015-12-01 10:43:08 -0800 | [diff] [blame] | 1993 | notifyInputMethodSubtypeChanged(mSettings.getCurrentUserId(), info, newSubtype); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1994 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1995 | return; |
| 1996 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1997 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 1998 | // Changing to a different IME. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1999 | final long ident = Binder.clearCallingIdentity(); |
| 2000 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2001 | // Set a subtype to this input method. |
| 2002 | // subtypeId the name of a subtype which will be set. |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2003 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false); |
| 2004 | // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked() |
| 2005 | // because mCurMethodId is stored as a history in |
| 2006 | // setSelectedInputMethodAndSubtypeLocked(). |
| 2007 | mCurMethodId = id; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2008 | |
| 2009 | if (ActivityManagerNative.isSystemReady()) { |
| 2010 | Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 2011 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2012 | intent.putExtra("input_method_id", id); |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 2013 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2014 | } |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2015 | unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_SWITCH_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2016 | } finally { |
| 2017 | Binder.restoreCallingIdentity(ident); |
| 2018 | } |
Yohei Yukawa | b097b82 | 2015-12-01 10:43:08 -0800 | [diff] [blame] | 2019 | |
| 2020 | notifyInputMethodSubtypeChanged(mSettings.getCurrentUserId(), info, |
| 2021 | getCurrentInputMethodSubtypeLocked()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2022 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2023 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2024 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2025 | public boolean showSoftInput(IInputMethodClient client, int flags, |
| 2026 | ResultReceiver resultReceiver) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2027 | if (!calledFromValidUser()) { |
| 2028 | return false; |
| 2029 | } |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2030 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2031 | long ident = Binder.clearCallingIdentity(); |
| 2032 | try { |
| 2033 | synchronized (mMethodMap) { |
| 2034 | if (mCurClient == null || client == null |
| 2035 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 2036 | try { |
| 2037 | // We need to check if this is the current client with |
| 2038 | // focus in the window manager, to allow this call to |
| 2039 | // be made before input is started in it. |
| 2040 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2041 | Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2042 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2043 | } |
| 2044 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2045 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2046 | } |
| 2047 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2048 | |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2049 | if (DEBUG) Slog.v(TAG, "Client requesting input be shown"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2050 | return showCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2051 | } |
| 2052 | } finally { |
| 2053 | Binder.restoreCallingIdentity(ident); |
| 2054 | } |
| 2055 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2056 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2057 | boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2058 | mShowRequested = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2059 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 2060 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2061 | } |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2062 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | if ((flags&InputMethodManager.SHOW_FORCED) != 0) { |
| 2064 | mShowExplicitlyRequested = true; |
| 2065 | mShowForced = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2066 | } else if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) { |
| 2067 | mShowExplicitlyRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2068 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2069 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2070 | if (!mSystemReady) { |
| 2071 | return false; |
| 2072 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2073 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2074 | boolean res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2075 | if (mCurMethod != null) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2076 | if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2077 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 2078 | MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod, |
| 2079 | resultReceiver)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2080 | mInputShown = true; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2081 | if (mHaveConnection && !mVisibleBound) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2082 | bindCurrentInputMethodService( |
Dianne Hackborn | f0f94d1 | 2014-03-17 16:04:21 -0700 | [diff] [blame] | 2083 | mCurIntent, mVisibleConnection, Context.BIND_AUTO_CREATE |
Dianne Hackborn | d69e4c1 | 2015-04-24 09:54:54 -0700 | [diff] [blame] | 2084 | | Context.BIND_TREAT_LIKE_ACTIVITY |
| 2085 | | Context.BIND_FOREGROUND_SERVICE); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2086 | mVisibleBound = true; |
| 2087 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2088 | res = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2089 | } else if (mHaveConnection && SystemClock.uptimeMillis() |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 2090 | >= (mLastBindTime+TIME_TO_RECONNECT)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | // The client has asked to have the input method shown, but |
| 2092 | // we have been sitting here too long with a connection to the |
| 2093 | // service and no interface received, so let's disconnect/connect |
| 2094 | // to try to prod things along. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2095 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2096 | SystemClock.uptimeMillis()-mLastBindTime,1); |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 2097 | Slog.w(TAG, "Force disconnect/connect to the IME in showCurrentInputLocked()"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2098 | mContext.unbindService(this); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2099 | bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2100 | | Context.BIND_NOT_VISIBLE); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2101 | } else { |
| 2102 | if (DEBUG) { |
| 2103 | Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = " |
| 2104 | + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis())); |
| 2105 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2106 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2107 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2108 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2110 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2111 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2112 | public boolean hideSoftInput(IInputMethodClient client, int flags, |
| 2113 | ResultReceiver resultReceiver) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2114 | if (!calledFromValidUser()) { |
| 2115 | return false; |
| 2116 | } |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2117 | int uid = Binder.getCallingUid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2118 | long ident = Binder.clearCallingIdentity(); |
| 2119 | try { |
| 2120 | synchronized (mMethodMap) { |
| 2121 | if (mCurClient == null || client == null |
| 2122 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 2123 | try { |
| 2124 | // We need to check if this is the current client with |
| 2125 | // focus in the window manager, to allow this call to |
| 2126 | // be made before input is started in it. |
| 2127 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2128 | if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid " |
| 2129 | + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2130 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2131 | } |
| 2132 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2133 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2134 | } |
| 2135 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2136 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2137 | if (DEBUG) Slog.v(TAG, "Client requesting input be hidden"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2138 | return hideCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2139 | } |
| 2140 | } finally { |
| 2141 | Binder.restoreCallingIdentity(ident); |
| 2142 | } |
| 2143 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2144 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2145 | boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0 |
| 2147 | && (mShowExplicitlyRequested || mShowForced)) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2148 | if (DEBUG) Slog.v(TAG, "Not hiding: explicit show not cancelled by non-explicit hide"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2149 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2150 | } |
| 2151 | if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2152 | if (DEBUG) Slog.v(TAG, "Not hiding: forced show not cancelled by not-always hide"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2153 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | } |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 2155 | |
| 2156 | // There is a chance that IMM#hideSoftInput() is called in a transient state where |
| 2157 | // IMMS#InputShown is already updated to be true whereas IMMS#mImeWindowVis is still waiting |
| 2158 | // to be updated with the new value sent from IME process. Even in such a transient state |
| 2159 | // historically we have accepted an incoming call of IMM#hideSoftInput() from the |
| 2160 | // application process as a valid request, and have even promised such a behavior with CTS |
| 2161 | // since Android Eclair. That's why we need to accept IMM#hideSoftInput() even when only |
| 2162 | // IMMS#InputShown indicates that the software keyboard is shown. |
| 2163 | // TODO: Clean up, IMMS#mInputShown, IMMS#mImeWindowVis and mShowRequested. |
| 2164 | final boolean shouldHideSoftInput = (mCurMethod != null) && (mInputShown || |
| 2165 | (mImeWindowVis & InputMethodService.IME_ACTIVE) != 0); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2166 | boolean res; |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 2167 | if (shouldHideSoftInput) { |
| 2168 | // The IME will report its visible state again after the following message finally |
| 2169 | // delivered to the IME process as an IPC. Hence the inconsistency between |
| 2170 | // IMMS#mInputShown and IMMS#mImeWindowVis should be resolved spontaneously in |
| 2171 | // the final state. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2172 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 2173 | MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver)); |
| 2174 | res = true; |
| 2175 | } else { |
| 2176 | res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | } |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2178 | if (mHaveConnection && mVisibleBound) { |
| 2179 | mContext.unbindService(mVisibleConnection); |
| 2180 | mVisibleBound = false; |
| 2181 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2182 | mInputShown = false; |
| 2183 | mShowRequested = false; |
| 2184 | mShowExplicitlyRequested = false; |
| 2185 | mShowForced = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2186 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2187 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2188 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2189 | @Override |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2190 | public InputBindResult startInputOrWindowGainedFocus( |
| 2191 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
| 2192 | IInputMethodClient client, IBinder windowToken, int controlFlags, int softInputMode, |
| 2193 | int windowFlags, EditorInfo attribute, IInputContext inputContext) { |
| 2194 | if (windowToken != null) { |
| 2195 | return windowGainedFocus(startInputReason, client, windowToken, controlFlags, |
| 2196 | softInputMode, windowFlags, attribute, inputContext); |
| 2197 | } else { |
| 2198 | return startInput(startInputReason, client, inputContext, attribute, controlFlags); |
| 2199 | } |
| 2200 | } |
| 2201 | |
| 2202 | private InputBindResult windowGainedFocus( |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2203 | /* @InputMethodClient.StartInputReason */ final int startInputReason, |
| 2204 | IInputMethodClient client, IBinder windowToken, int controlFlags, int softInputMode, |
| 2205 | int windowFlags, EditorInfo attribute, IInputContext inputContext) { |
Satoshi Kataoka | 8d03305 | 2012-11-19 17:30:40 +0900 | [diff] [blame] | 2206 | // Needs to check the validity before clearing calling identity |
| 2207 | final boolean calledFromValidUser = calledFromValidUser(); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2208 | InputBindResult res = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2209 | long ident = Binder.clearCallingIdentity(); |
| 2210 | try { |
| 2211 | synchronized (mMethodMap) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2212 | if (DEBUG) Slog.v(TAG, "windowGainedFocus: reason=" |
| 2213 | + InputMethodClient.getStartInputReason(startInputReason) |
| 2214 | + " client=" + client.asBinder() |
| 2215 | + " inputContext=" + inputContext |
| 2216 | + " attribute=" + attribute |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2217 | + " controlFlags=#" + Integer.toHexString(controlFlags) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | + " softInputMode=#" + Integer.toHexString(softInputMode) |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2219 | + " windowFlags=#" + Integer.toHexString(windowFlags)); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2220 | |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2221 | ClientState cs = mClients.get(client.asBinder()); |
| 2222 | if (cs == null) { |
| 2223 | throw new IllegalArgumentException("unknown client " |
| 2224 | + client.asBinder()); |
| 2225 | } |
| 2226 | |
| 2227 | try { |
| 2228 | if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) { |
| 2229 | // Check with the window manager to make sure this client actually |
| 2230 | // has a window with focus. If not, reject. This is thread safe |
| 2231 | // because if the focus changes some time before or after, the |
| 2232 | // next client receiving focus that has any interest in input will |
| 2233 | // be calling through here after that change happens. |
| 2234 | Slog.w(TAG, "Focus gain on non-focused client " + cs.client |
| 2235 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
| 2236 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2237 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2238 | } catch (RemoteException e) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2239 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2240 | |
Satoshi Kataoka | 8d03305 | 2012-11-19 17:30:40 +0900 | [diff] [blame] | 2241 | if (!calledFromValidUser) { |
| 2242 | Slog.w(TAG, "A background user is requesting window. Hiding IME."); |
| 2243 | Slog.w(TAG, "If you want to interect with IME, you need " |
| 2244 | + "android.permission.INTERACT_ACROSS_USERS_FULL"); |
| 2245 | hideCurrentInputLocked(0, null); |
| 2246 | return null; |
| 2247 | } |
| 2248 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2249 | if (mCurFocusedWindow == windowToken) { |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 2250 | Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client |
Satoshi Kataoka | 3573950 | 2012-10-02 19:00:26 +0900 | [diff] [blame] | 2251 | + " attribute=" + attribute + ", token = " + windowToken); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2252 | if (attribute != null) { |
| 2253 | return startInputUncheckedLocked(cs, inputContext, attribute, |
| 2254 | controlFlags); |
| 2255 | } |
| 2256 | return null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2257 | } |
| 2258 | mCurFocusedWindow = windowToken; |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 2259 | mCurFocusedWindowClient = cs; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2260 | |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2261 | // Should we auto-show the IME even if the caller has not |
| 2262 | // specified what should be done with it? |
| 2263 | // We only do this automatically if the window can resize |
| 2264 | // to accommodate the IME (so what the user sees will give |
| 2265 | // them good context without input information being obscured |
| 2266 | // by the IME) or if running on a large screen where there |
| 2267 | // is more room for the target window + IME. |
| 2268 | final boolean doAutoShow = |
| 2269 | (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 2270 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
| 2271 | || mRes.getConfiguration().isLayoutSizeAtLeast( |
| 2272 | Configuration.SCREENLAYOUT_SIZE_LARGE); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2273 | final boolean isTextEditor = |
| 2274 | (controlFlags&InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0; |
| 2275 | |
| 2276 | // We want to start input before showing the IME, but after closing |
| 2277 | // it. We want to do this after closing it to help the IME disappear |
| 2278 | // more quickly (not get stuck behind it initializing itself for the |
| 2279 | // new focused input, even if its window wants to hide the IME). |
| 2280 | boolean didStart = false; |
Yohei Yukaw | a0f3ad1 | 2015-04-06 16:48:24 -0700 | [diff] [blame] | 2281 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2282 | switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) { |
| 2283 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2284 | if (!isTextEditor || !doAutoShow) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) { |
| 2286 | // There is no focus view, and this window will |
| 2287 | // be behind any soft input window, so hide the |
| 2288 | // soft input window if it is shown. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2289 | if (DEBUG) Slog.v(TAG, "Unspecified window will hide input"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2290 | hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2291 | } |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2292 | } else if (isTextEditor && doAutoShow && (softInputMode & |
| 2293 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | // There is a focus view, and we are navigating forward |
| 2295 | // into the window, so show the input window for the user. |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2296 | // We only do this automatically if the window can resize |
| 2297 | // to accommodate the IME (so what the user sees will give |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 2298 | // them good context without input information being obscured |
| 2299 | // by the IME) or if running on a large screen where there |
| 2300 | // is more room for the target window + IME. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2301 | if (DEBUG) Slog.v(TAG, "Unspecified window will show input"); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2302 | if (attribute != null) { |
| 2303 | res = startInputUncheckedLocked(cs, inputContext, attribute, |
| 2304 | controlFlags); |
| 2305 | didStart = true; |
| 2306 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2307 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2308 | } |
| 2309 | break; |
| 2310 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED: |
| 2311 | // Do nothing. |
| 2312 | break; |
| 2313 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN: |
| 2314 | if ((softInputMode & |
| 2315 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2316 | if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2317 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2318 | } |
| 2319 | break; |
| 2320 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2321 | if (DEBUG) Slog.v(TAG, "Window asks to hide input"); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2322 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2323 | break; |
| 2324 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE: |
| 2325 | if ((softInputMode & |
| 2326 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2327 | if (DEBUG) Slog.v(TAG, "Window asks to show input going forward"); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2328 | if (attribute != null) { |
| 2329 | res = startInputUncheckedLocked(cs, inputContext, attribute, |
| 2330 | controlFlags); |
| 2331 | didStart = true; |
| 2332 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2333 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2334 | } |
| 2335 | break; |
| 2336 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2337 | if (DEBUG) Slog.v(TAG, "Window asks to always show input"); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2338 | if (attribute != null) { |
| 2339 | res = startInputUncheckedLocked(cs, inputContext, attribute, |
| 2340 | controlFlags); |
| 2341 | didStart = true; |
| 2342 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2343 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2344 | break; |
| 2345 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2346 | |
| 2347 | if (!didStart && attribute != null) { |
| 2348 | res = startInputUncheckedLocked(cs, inputContext, attribute, |
| 2349 | controlFlags); |
| 2350 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2351 | } |
| 2352 | } finally { |
| 2353 | Binder.restoreCallingIdentity(ident); |
| 2354 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2355 | |
| 2356 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2357 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2358 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2359 | @Override |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2360 | public void showInputMethodPickerFromClient( |
| 2361 | IInputMethodClient client, int auxiliarySubtypeMode) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2362 | if (!calledFromValidUser()) { |
| 2363 | return; |
| 2364 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2365 | synchronized (mMethodMap) { |
| 2366 | if (mCurClient == null || client == null |
| 2367 | || mCurClient.client.asBinder() != client.asBinder()) { |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 2368 | Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid " |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2369 | + Binder.getCallingUid() + ": " + client); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2370 | } |
| 2371 | |
satok | 440aab5 | 2010-11-25 09:43:11 +0900 | [diff] [blame] | 2372 | // Always call subtype picker, because subtype picker is a superset of input method |
| 2373 | // picker. |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2374 | mHandler.sendMessage(mCaller.obtainMessageI( |
| 2375 | MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode)); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2376 | } |
| 2377 | } |
| 2378 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2379 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2380 | public void setInputMethod(IBinder token, String id) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2381 | if (!calledFromValidUser()) { |
| 2382 | return; |
| 2383 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2384 | setInputMethodWithSubtypeId(token, id, NOT_A_SUBTYPE_ID); |
| 2385 | } |
| 2386 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2387 | @Override |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2388 | public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2389 | if (!calledFromValidUser()) { |
| 2390 | return; |
| 2391 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2392 | synchronized (mMethodMap) { |
| 2393 | if (subtype != null) { |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 2394 | setInputMethodWithSubtypeIdLocked(token, id, |
| 2395 | InputMethodUtils.getSubtypeIdFromHashCode(mMethodMap.get(id), |
| 2396 | subtype.hashCode())); |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2397 | } else { |
| 2398 | setInputMethod(token, id); |
| 2399 | } |
| 2400 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2401 | } |
| 2402 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2403 | @Override |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 2404 | public void showInputMethodAndSubtypeEnablerFromClient( |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 2405 | IInputMethodClient client, String inputMethodId) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2406 | if (!calledFromValidUser()) { |
| 2407 | return; |
| 2408 | } |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 2409 | synchronized (mMethodMap) { |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 2410 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 2411 | MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId)); |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 2412 | } |
| 2413 | } |
| 2414 | |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2415 | @Override |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 2416 | public boolean switchToLastInputMethod(IBinder token) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2417 | if (!calledFromValidUser()) { |
| 2418 | return false; |
| 2419 | } |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 2420 | synchronized (mMethodMap) { |
satok | c445bcd | 2011-01-25 18:57:24 +0900 | [diff] [blame] | 2421 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2422 | final InputMethodInfo lastImi; |
satok | 208d563 | 2011-05-20 22:13:38 +0900 | [diff] [blame] | 2423 | if (lastIme != null) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2424 | lastImi = mMethodMap.get(lastIme.first); |
| 2425 | } else { |
| 2426 | lastImi = null; |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 2427 | } |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2428 | String targetLastImiId = null; |
| 2429 | int subtypeId = NOT_A_SUBTYPE_ID; |
| 2430 | if (lastIme != null && lastImi != null) { |
| 2431 | final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId); |
| 2432 | final int lastSubtypeHash = Integer.valueOf(lastIme.second); |
| 2433 | final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID |
| 2434 | : mCurrentSubtype.hashCode(); |
| 2435 | // If the last IME is the same as the current IME and the last subtype is not |
| 2436 | // defined, there is no need to switch to the last IME. |
| 2437 | if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) { |
| 2438 | targetLastImiId = lastIme.first; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2439 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2440 | } |
| 2441 | } |
| 2442 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2443 | if (TextUtils.isEmpty(targetLastImiId) |
| 2444 | && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2445 | // This is a safety net. If the currentSubtype can't be added to the history |
| 2446 | // and the framework couldn't find the last ime, we will make the last ime be |
| 2447 | // the most applicable enabled keyboard subtype of the system imes. |
| 2448 | final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 2449 | if (enabled != null) { |
| 2450 | final int N = enabled.size(); |
| 2451 | final String locale = mCurrentSubtype == null |
| 2452 | ? mRes.getConfiguration().locale.toString() |
| 2453 | : mCurrentSubtype.getLocale(); |
| 2454 | for (int i = 0; i < N; ++i) { |
| 2455 | final InputMethodInfo imi = enabled.get(i); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2456 | if (imi.getSubtypeCount() > 0 && InputMethodUtils.isSystemIme(imi)) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2457 | InputMethodSubtype keyboardSubtype = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2458 | InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, |
| 2459 | InputMethodUtils.getSubtypes(imi), |
| 2460 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2461 | if (keyboardSubtype != null) { |
| 2462 | targetLastImiId = imi.getId(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2463 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2464 | imi, keyboardSubtype.hashCode()); |
| 2465 | if(keyboardSubtype.getLocale().equals(locale)) { |
| 2466 | break; |
| 2467 | } |
| 2468 | } |
| 2469 | } |
| 2470 | } |
| 2471 | } |
| 2472 | } |
| 2473 | |
| 2474 | if (!TextUtils.isEmpty(targetLastImiId)) { |
| 2475 | if (DEBUG) { |
| 2476 | Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second |
| 2477 | + ", from: " + mCurMethodId + ", " + subtypeId); |
| 2478 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 2479 | setInputMethodWithSubtypeIdLocked(token, targetLastImiId, subtypeId); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 2480 | return true; |
| 2481 | } else { |
| 2482 | return false; |
| 2483 | } |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 2484 | } |
| 2485 | } |
| 2486 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2487 | @Override |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2488 | public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2489 | if (!calledFromValidUser()) { |
| 2490 | return false; |
| 2491 | } |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2492 | synchronized (mMethodMap) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 2493 | if (!calledWithValidToken(token)) { |
| 2494 | final int uid = Binder.getCallingUid(); |
| 2495 | Slog.e(TAG, "Ignoring switchToNextInputMethod due to an invalid token. uid:" + uid |
| 2496 | + " token:" + token); |
| 2497 | return false; |
| 2498 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 2499 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2500 | onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype); |
| 2501 | if (nextSubtype == null) { |
| 2502 | return false; |
| 2503 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 2504 | setInputMethodWithSubtypeIdLocked(token, nextSubtype.mImi.getId(), |
| 2505 | nextSubtype.mSubtypeId); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2506 | return true; |
| 2507 | } |
| 2508 | } |
| 2509 | |
| 2510 | @Override |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 2511 | public boolean shouldOfferSwitchingToNextInputMethod(IBinder token) { |
| 2512 | if (!calledFromValidUser()) { |
| 2513 | return false; |
| 2514 | } |
| 2515 | synchronized (mMethodMap) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 2516 | if (!calledWithValidToken(token)) { |
| 2517 | final int uid = Binder.getCallingUid(); |
| 2518 | Slog.e(TAG, "Ignoring shouldOfferSwitchingToNextInputMethod due to an invalid " |
| 2519 | + "token. uid:" + uid + " token:" + token); |
| 2520 | return false; |
| 2521 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 2522 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 2523 | false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype); |
| 2524 | if (nextSubtype == null) { |
| 2525 | return false; |
| 2526 | } |
| 2527 | return true; |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | @Override |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 2532 | public InputMethodSubtype getLastInputMethodSubtype() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2533 | if (!calledFromValidUser()) { |
| 2534 | return null; |
| 2535 | } |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 2536 | synchronized (mMethodMap) { |
| 2537 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
| 2538 | // TODO: Handle the case of the last IME with no subtypes |
| 2539 | if (lastIme == null || TextUtils.isEmpty(lastIme.first) |
| 2540 | || TextUtils.isEmpty(lastIme.second)) return null; |
| 2541 | final InputMethodInfo lastImi = mMethodMap.get(lastIme.first); |
| 2542 | if (lastImi == null) return null; |
| 2543 | try { |
| 2544 | final int lastSubtypeHash = Integer.valueOf(lastIme.second); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2545 | final int lastSubtypeId = |
| 2546 | InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 0e7d7d6 | 2011-07-05 13:28:06 +0900 | [diff] [blame] | 2547 | if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) { |
| 2548 | return null; |
| 2549 | } |
| 2550 | return lastImi.getSubtypeAt(lastSubtypeId); |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 2551 | } catch (NumberFormatException e) { |
| 2552 | return null; |
| 2553 | } |
| 2554 | } |
| 2555 | } |
| 2556 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2557 | @Override |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 2558 | public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2559 | if (!calledFromValidUser()) { |
| 2560 | return; |
| 2561 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 2562 | // By this IPC call, only a process which shares the same uid with the IME can add |
| 2563 | // additional input method subtypes to the IME. |
Yohei Yukawa | 70f5c48 | 2016-01-04 19:42:36 -0800 | [diff] [blame] | 2564 | if (TextUtils.isEmpty(imiId) || subtypes == null) return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2565 | synchronized (mMethodMap) { |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 2566 | final InputMethodInfo imi = mMethodMap.get(imiId); |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 2567 | if (imi == null) return; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2568 | final String[] packageInfos; |
| 2569 | try { |
| 2570 | packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 2571 | } catch (RemoteException e) { |
| 2572 | Slog.e(TAG, "Failed to get package infos"); |
| 2573 | return; |
| 2574 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 2575 | if (packageInfos != null) { |
| 2576 | final int packageNum = packageInfos.length; |
| 2577 | for (int i = 0; i < packageNum; ++i) { |
| 2578 | if (packageInfos[i].equals(imi.getPackageName())) { |
| 2579 | mFileManager.addInputMethodSubtypes(imi, subtypes); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 2580 | final long ident = Binder.clearCallingIdentity(); |
| 2581 | try { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 2582 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 2583 | } finally { |
| 2584 | Binder.restoreCallingIdentity(ident); |
| 2585 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 2586 | return; |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 2587 | } |
| 2588 | } |
| 2589 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2590 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 2591 | return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2592 | } |
| 2593 | |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 2594 | @Override |
| 2595 | public int getInputMethodWindowVisibleHeight() { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2596 | return mWindowManagerInternal.getInputMethodWindowVisibleHeight(); |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 2597 | } |
| 2598 | |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 2599 | @Override |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 2600 | public void notifyUserAction(int sequenceNumber) { |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 2601 | if (DEBUG) { |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 2602 | Slog.d(TAG, "Got the notification of a user action. sequenceNumber:" + sequenceNumber); |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 2603 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 2604 | synchronized (mMethodMap) { |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 2605 | if (mCurUserActionNotificationSequenceNumber != sequenceNumber) { |
| 2606 | if (DEBUG) { |
| 2607 | Slog.d(TAG, "Ignoring the user action notification due to the sequence number " |
| 2608 | + "mismatch. expected:" + mCurUserActionNotificationSequenceNumber |
| 2609 | + " actual: " + sequenceNumber); |
| 2610 | } |
| 2611 | return; |
| 2612 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 2613 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 2614 | if (imi != null) { |
Yohei Yukawa | 0297051 | 2014-06-05 16:16:18 +0900 | [diff] [blame] | 2615 | mSwitchingController.onUserActionLocked(imi, mCurrentSubtype); |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 2616 | } |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 2617 | } |
| 2618 | } |
| 2619 | |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2620 | private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2621 | synchronized (mMethodMap) { |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 2622 | setInputMethodWithSubtypeIdLocked(token, id, subtypeId); |
| 2623 | } |
| 2624 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 2626 | private void setInputMethodWithSubtypeIdLocked(IBinder token, String id, int subtypeId) { |
| 2627 | if (token == null) { |
| 2628 | if (mContext.checkCallingOrSelfPermission( |
| 2629 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 2630 | != PackageManager.PERMISSION_GRANTED) { |
| 2631 | throw new SecurityException( |
| 2632 | "Using null token requires permission " |
| 2633 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2634 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 2635 | } else if (mCurToken != token) { |
| 2636 | Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid() |
| 2637 | + " token: " + token); |
| 2638 | return; |
| 2639 | } |
| 2640 | |
| 2641 | final long ident = Binder.clearCallingIdentity(); |
| 2642 | try { |
| 2643 | setInputMethodLocked(id, subtypeId); |
| 2644 | } finally { |
| 2645 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2646 | } |
| 2647 | } |
| 2648 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2649 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2650 | public void hideMySoftInput(IBinder token, int flags) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2651 | if (!calledFromValidUser()) { |
| 2652 | return; |
| 2653 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2654 | synchronized (mMethodMap) { |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 2655 | if (!calledWithValidToken(token)) { |
| 2656 | final int uid = Binder.getCallingUid(); |
| 2657 | Slog.e(TAG, "Ignoring hideInputMethod due to an invalid token. uid:" |
| 2658 | + uid + " token:" + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | return; |
| 2660 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | long ident = Binder.clearCallingIdentity(); |
| 2662 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2663 | hideCurrentInputLocked(flags, null); |
| 2664 | } finally { |
| 2665 | Binder.restoreCallingIdentity(ident); |
| 2666 | } |
| 2667 | } |
| 2668 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2669 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2670 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2671 | public void showMySoftInput(IBinder token, int flags) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2672 | if (!calledFromValidUser()) { |
| 2673 | return; |
| 2674 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2675 | synchronized (mMethodMap) { |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 2676 | if (!calledWithValidToken(token)) { |
| 2677 | final int uid = Binder.getCallingUid(); |
| 2678 | Slog.e(TAG, "Ignoring showMySoftInput due to an invalid token. uid:" |
| 2679 | + uid + " token:" + token); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2680 | return; |
| 2681 | } |
| 2682 | long ident = Binder.clearCallingIdentity(); |
| 2683 | try { |
| 2684 | showCurrentInputLocked(flags, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2685 | } finally { |
| 2686 | Binder.restoreCallingIdentity(ident); |
| 2687 | } |
| 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | void setEnabledSessionInMainThread(SessionState session) { |
| 2692 | if (mEnabledSession != session) { |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 2693 | if (mEnabledSession != null && mEnabledSession.session != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2694 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2695 | if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession); |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 2696 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2697 | } catch (RemoteException e) { |
| 2698 | } |
| 2699 | } |
| 2700 | mEnabledSession = session; |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 2701 | if (mEnabledSession != null && mEnabledSession.session != null) { |
| 2702 | try { |
| 2703 | if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession); |
| 2704 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, true); |
| 2705 | } catch (RemoteException e) { |
| 2706 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2707 | } |
| 2708 | } |
| 2709 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2710 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2711 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2712 | public boolean handleMessage(Message msg) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2713 | SomeArgs args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2714 | switch (msg.what) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2715 | case MSG_SHOW_IM_SUBTYPE_PICKER: |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2716 | final boolean showAuxSubtypes; |
| 2717 | switch (msg.arg1) { |
| 2718 | case InputMethodManager.SHOW_IM_PICKER_MODE_AUTO: |
| 2719 | // This is undocumented so far, but IMM#showInputMethodPicker() has been |
| 2720 | // implemented so that auxiliary subtypes will be excluded when the soft |
| 2721 | // keyboard is invisible. |
| 2722 | showAuxSubtypes = mInputShown; |
| 2723 | break; |
| 2724 | case InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES: |
| 2725 | showAuxSubtypes = true; |
| 2726 | break; |
| 2727 | case InputMethodManager.SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES: |
| 2728 | showAuxSubtypes = false; |
| 2729 | break; |
| 2730 | default: |
| 2731 | Slog.e(TAG, "Unknown subtype picker mode = " + msg.arg1); |
| 2732 | return false; |
| 2733 | } |
| 2734 | showInputMethodMenu(showAuxSubtypes); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2735 | return true; |
| 2736 | |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 2737 | case MSG_SHOW_IM_SUBTYPE_ENABLER: |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 2738 | showInputMethodAndSubtypeEnabler((String)msg.obj); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 2739 | return true; |
| 2740 | |
| 2741 | case MSG_SHOW_IM_CONFIG: |
| 2742 | showConfigureInputMethods(); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 2743 | return true; |
| 2744 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2745 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2746 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2747 | case MSG_UNBIND_INPUT: |
| 2748 | try { |
| 2749 | ((IInputMethod)msg.obj).unbindInput(); |
| 2750 | } catch (RemoteException e) { |
| 2751 | // There is nothing interesting about the method dying. |
| 2752 | } |
| 2753 | return true; |
| 2754 | case MSG_BIND_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2755 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2756 | try { |
| 2757 | ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2); |
| 2758 | } catch (RemoteException e) { |
| 2759 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2760 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2761 | return true; |
| 2762 | case MSG_SHOW_SOFT_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2763 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2764 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2765 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput(" |
Craig Mautner | 6efb4c7 | 2013-03-13 10:17:41 -0700 | [diff] [blame] | 2766 | + msg.arg1 + ", " + args.arg2 + ")"); |
Craig Mautner | ca0ac71 | 2013-03-14 09:43:02 -0700 | [diff] [blame] | 2767 | ((IInputMethod)args.arg1).showSoftInput(msg.arg1, (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2768 | } catch (RemoteException e) { |
| 2769 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2770 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2771 | return true; |
| 2772 | case MSG_HIDE_SOFT_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2773 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2774 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2775 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, " |
Craig Mautner | 6efb4c7 | 2013-03-13 10:17:41 -0700 | [diff] [blame] | 2776 | + args.arg2 + ")"); |
Craig Mautner | ca0ac71 | 2013-03-14 09:43:02 -0700 | [diff] [blame] | 2777 | ((IInputMethod)args.arg1).hideSoftInput(0, (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2778 | } catch (RemoteException e) { |
| 2779 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2780 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2781 | return true; |
| 2782 | case MSG_ATTACH_TOKEN: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2783 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2784 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2785 | if (DEBUG) Slog.v(TAG, "Sending attach of token: " + args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2786 | ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2); |
| 2787 | } catch (RemoteException e) { |
| 2788 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2789 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2790 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2791 | case MSG_CREATE_SESSION: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2792 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 2793 | IInputMethod method = (IInputMethod)args.arg1; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2794 | InputChannel channel = (InputChannel)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2795 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 2796 | method.createSession(channel, (IInputSessionCallback)args.arg3); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2797 | } catch (RemoteException e) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2798 | } finally { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 2799 | // Dispose the channel if the input method is not local to this process |
| 2800 | // because the remote proxy will get its own copy when unparceled. |
| 2801 | if (channel != null && Binder.isProxy(method)) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2802 | channel.dispose(); |
| 2803 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2804 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2805 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2806 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2807 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2808 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2809 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2810 | case MSG_START_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2811 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2812 | try { |
| 2813 | SessionState session = (SessionState)args.arg1; |
| 2814 | setEnabledSessionInMainThread(session); |
| 2815 | session.method.startInput((IInputContext)args.arg2, |
| 2816 | (EditorInfo)args.arg3); |
| 2817 | } catch (RemoteException e) { |
| 2818 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2819 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2820 | return true; |
| 2821 | case MSG_RESTART_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2822 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | try { |
| 2824 | SessionState session = (SessionState)args.arg1; |
| 2825 | setEnabledSessionInMainThread(session); |
| 2826 | session.method.restartInput((IInputContext)args.arg2, |
| 2827 | (EditorInfo)args.arg3); |
| 2828 | } catch (RemoteException e) { |
| 2829 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2830 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2831 | return true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2832 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2833 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2834 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2835 | case MSG_UNBIND_CLIENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2836 | try { |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2837 | ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1, msg.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2838 | } catch (RemoteException e) { |
| 2839 | // There is nothing interesting about the last client dying. |
| 2840 | } |
| 2841 | return true; |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2842 | case MSG_BIND_CLIENT: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2843 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 2844 | IInputMethodClient client = (IInputMethodClient)args.arg1; |
| 2845 | InputBindResult res = (InputBindResult)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2846 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 2847 | client.onBindMethod(res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2849 | Slog.w(TAG, "Client died receiving input method " + args.arg2); |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 2850 | } finally { |
| 2851 | // Dispose the channel if the input method is not local to this process |
| 2852 | // because the remote proxy will get its own copy when unparceled. |
| 2853 | if (res.channel != null && Binder.isProxy(client)) { |
| 2854 | res.channel.dispose(); |
| 2855 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2856 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 2857 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2858 | return true; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 2859 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 2860 | case MSG_SET_ACTIVE: |
| 2861 | try { |
| 2862 | ((ClientState)msg.obj).client.setActive(msg.arg1 != 0); |
| 2863 | } catch (RemoteException e) { |
| 2864 | Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid " |
| 2865 | + ((ClientState)msg.obj).pid + " uid " |
| 2866 | + ((ClientState)msg.obj).uid); |
| 2867 | } |
| 2868 | return true; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 2869 | case MSG_SET_INTERACTIVE: |
| 2870 | handleSetInteractive(msg.arg1 != 0); |
| 2871 | return true; |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 2872 | case MSG_SWITCH_IME: |
| 2873 | handleSwitchInputMethod(msg.arg1 != 0); |
| 2874 | return true; |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 2875 | case MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER: { |
| 2876 | final int sequenceNumber = msg.arg1; |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 2877 | final ClientState clientState = (ClientState)msg.obj; |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 2878 | try { |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 2879 | clientState.client.setUserActionNotificationSequenceNumber(sequenceNumber); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 2880 | } catch (RemoteException e) { |
| 2881 | Slog.w(TAG, "Got RemoteException sending " |
| 2882 | + "setUserActionNotificationSequenceNumber(" |
| 2883 | + sequenceNumber + ") notification to pid " |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 2884 | + clientState.pid + " uid " |
| 2885 | + clientState.uid); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 2886 | } |
| 2887 | return true; |
| 2888 | } |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 2889 | |
| 2890 | // -------------------------------------------------------------- |
| 2891 | case MSG_HARD_KEYBOARD_SWITCH_CHANGED: |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 2892 | mHardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 2893 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2894 | } |
| 2895 | return false; |
| 2896 | } |
| 2897 | |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 2898 | private void handleSetInteractive(final boolean interactive) { |
| 2899 | synchronized (mMethodMap) { |
| 2900 | mIsInteractive = interactive; |
| 2901 | updateSystemUiLocked(mCurToken, interactive ? mImeWindowVis : 0, mBackDisposition); |
| 2902 | |
| 2903 | // Inform the current client of the change in active status |
| 2904 | if (mCurClient != null && mCurClient.client != null) { |
| 2905 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 2906 | MSG_SET_ACTIVE, mIsInteractive ? 1 : 0, mCurClient)); |
| 2907 | } |
| 2908 | } |
| 2909 | } |
| 2910 | |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 2911 | private void handleSwitchInputMethod(final boolean forwardDirection) { |
| 2912 | synchronized (mMethodMap) { |
| 2913 | // TODO: Support forwardDirection. |
| 2914 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
| 2915 | false, mMethodMap.get(mCurMethodId), mCurrentSubtype); |
| 2916 | if (nextSubtype == null) { |
| 2917 | return; |
| 2918 | } |
| 2919 | setInputMethodLocked(nextSubtype.mImi.getId(), nextSubtype.mSubtypeId); |
| 2920 | } |
| 2921 | } |
| 2922 | |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 2923 | private boolean chooseNewDefaultIMELocked() { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2924 | final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME( |
| 2925 | mSettings.getEnabledInputMethodListLocked()); |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 2926 | if (imi != null) { |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2927 | if (DEBUG) { |
| 2928 | Slog.d(TAG, "New default IME was selected: " + imi.getId()); |
| 2929 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2930 | resetSelectedInputMethodAndSubtypeLocked(imi.getId()); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 2931 | return true; |
| 2932 | } |
| 2933 | |
| 2934 | return false; |
| 2935 | } |
| 2936 | |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 2937 | void buildInputMethodListLocked(boolean resetDefaultEnabledIme) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2938 | if (DEBUG) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 2939 | Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme |
Seigo Nonaka | e27dc2b | 2015-08-14 18:21:27 -0700 | [diff] [blame] | 2940 | + " \n ------ caller=" + Debug.getCallers(10)); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2941 | } |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 2942 | mMethodList.clear(); |
| 2943 | mMethodMap.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2944 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2945 | // Use for queryIntentServicesAsUser |
| 2946 | final PackageManager pm = mContext.getPackageManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2947 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 2948 | // Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default |
| 2949 | // behavior of PackageManager is exactly what we want. It by default picks up appropriate |
| 2950 | // services depending on the unlock state for the specified user. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2951 | final List<ResolveInfo> services = pm.queryIntentServicesAsUser( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2952 | new Intent(InputMethod.SERVICE_INTERFACE), |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2953 | PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, |
| 2954 | mSettings.getCurrentUserId()); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2955 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2956 | final HashMap<String, List<InputMethodSubtype>> additionalSubtypes = |
| 2957 | mFileManager.getAllAdditionalInputMethodSubtypes(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2958 | for (int i = 0; i < services.size(); ++i) { |
| 2959 | ResolveInfo ri = services.get(i); |
| 2960 | ServiceInfo si = ri.serviceInfo; |
| 2961 | ComponentName compName = new ComponentName(si.packageName, si.name); |
| 2962 | if (!android.Manifest.permission.BIND_INPUT_METHOD.equals( |
| 2963 | si.permission)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2964 | Slog.w(TAG, "Skipping input method " + compName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2965 | + ": it does not require the permission " |
| 2966 | + android.Manifest.permission.BIND_INPUT_METHOD); |
| 2967 | continue; |
| 2968 | } |
| 2969 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2970 | if (DEBUG) Slog.d(TAG, "Checking " + compName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | |
| 2972 | try { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2973 | InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes); |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 2974 | mMethodList.add(p); |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 2975 | final String id = p.getId(); |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 2976 | mMethodMap.put(id, p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2977 | |
| 2978 | if (DEBUG) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 2979 | Slog.d(TAG, "Found an input method " + p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2980 | } |
Yohei Yukawa | 5894b43 | 2015-08-11 13:29:24 -0700 | [diff] [blame] | 2981 | } catch (XmlPullParserException | IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2982 | Slog.w(TAG, "Unable to load input method " + compName, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2983 | } |
| 2984 | } |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 2985 | |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 2986 | // TODO: The following code should find better place to live. |
| 2987 | if (!resetDefaultEnabledIme) { |
| 2988 | boolean enabledImeFound = false; |
| 2989 | final List<InputMethodInfo> enabledImes = mSettings.getEnabledInputMethodListLocked(); |
| 2990 | final int N = enabledImes.size(); |
| 2991 | for (int i = 0; i < N; ++i) { |
| 2992 | final InputMethodInfo imi = enabledImes.get(i); |
| 2993 | if (mMethodList.contains(imi)) { |
| 2994 | enabledImeFound = true; |
| 2995 | break; |
| 2996 | } |
| 2997 | } |
| 2998 | if (!enabledImeFound) { |
| 2999 | Slog.i(TAG, "All the enabled IMEs are gone. Reset default enabled IMEs."); |
| 3000 | resetDefaultEnabledIme = true; |
| 3001 | resetSelectedInputMethodAndSubtypeLocked(""); |
| 3002 | } |
| 3003 | } |
| 3004 | |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3005 | if (resetDefaultEnabledIme) { |
| 3006 | final ArrayList<InputMethodInfo> defaultEnabledIme = |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3007 | InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, mMethodList); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 3008 | final int N = defaultEnabledIme.size(); |
| 3009 | for (int i = 0; i < N; ++i) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3010 | final InputMethodInfo imi = defaultEnabledIme.get(i); |
| 3011 | if (DEBUG) { |
| 3012 | Slog.d(TAG, "--- enable ime = " + imi); |
| 3013 | } |
| 3014 | setInputMethodEnabledLocked(imi.getId(), true); |
| 3015 | } |
| 3016 | } |
| 3017 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3018 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3019 | if (!TextUtils.isEmpty(defaultImiId)) { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3020 | if (!mMethodMap.containsKey(defaultImiId)) { |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3021 | Slog.w(TAG, "Default IME is uninstalled. Choose new default IME."); |
| 3022 | if (chooseNewDefaultIMELocked()) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3023 | updateInputMethodsFromSettingsLocked(true); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3024 | } |
| 3025 | } else { |
| 3026 | // Double check that the default IME is certainly enabled. |
| 3027 | setInputMethodEnabledLocked(defaultImiId, true); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 3028 | } |
| 3029 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 3030 | // Here is not the perfect place to reset the switching controller. Ideally |
| 3031 | // mSwitchingController and mSettings should be able to share the same state. |
| 3032 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 3033 | // the same enabled IMEs list. |
Yohei Yukawa | c834a25 | 2014-05-21 22:42:32 +0900 | [diff] [blame] | 3034 | mSwitchingController.resetCircularListLocked(mContext); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3035 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3036 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3037 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3038 | |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3039 | private void showInputMethodAndSubtypeEnabler(String inputMethodId) { |
Tadashi G. Takaoka | f49688f | 2011-01-20 17:56:13 +0900 | [diff] [blame] | 3040 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3041 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
satok | 86417ea | 2010-10-27 14:11:03 +0900 | [diff] [blame] | 3042 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 3043 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3044 | if (!TextUtils.isEmpty(inputMethodId)) { |
Tadashi G. Takaoka | 2548020 | 2011-01-20 23:13:02 +0900 | [diff] [blame] | 3045 | intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3046 | } |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 3047 | final int userId; |
| 3048 | synchronized (mMethodMap) { |
| 3049 | userId = mSettings.getCurrentUserId(); |
| 3050 | } |
| 3051 | mContext.startActivityAsUser(intent, null, UserHandle.of(userId)); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | private void showConfigureInputMethods() { |
| 3055 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS); |
| 3056 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 3057 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 3058 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Satoshi Kataoka | 3ba439d | 2012-10-05 18:30:13 +0900 | [diff] [blame] | 3059 | mContext.startActivityAsUser(intent, null, UserHandle.CURRENT); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3060 | } |
| 3061 | |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 3062 | private boolean isScreenLocked() { |
| 3063 | return mKeyguardManager != null |
| 3064 | && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure(); |
| 3065 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3066 | |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3067 | private void showInputMethodMenu(boolean showAuxSubtypes) { |
| 3068 | if (DEBUG) Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3069 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3070 | final Context context = mContext; |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 3071 | final boolean isScreenLocked = isScreenLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3072 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3073 | final String lastInputMethodId = mSettings.getSelectedInputMethod(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3074 | int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3075 | if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3076 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3077 | synchronized (mMethodMap) { |
satok | bb4aa06 | 2011-01-19 21:40:27 +0900 | [diff] [blame] | 3078 | final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = |
Satoshi Kataoka | d787f69 | 2013-10-26 04:44:21 +0900 | [diff] [blame] | 3079 | mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked( |
| 3080 | mContext); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 3081 | if (immis == null || immis.size() == 0) { |
| 3082 | return; |
| 3083 | } |
| 3084 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3085 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3086 | |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3087 | final List<ImeSubtypeListItem> imList = |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3088 | mSwitchingController.getSortedInputMethodAndSubtypeListLocked( |
Yohei Yukawa | 5f8e731 | 2015-12-10 00:58:55 -0800 | [diff] [blame] | 3089 | showAuxSubtypes, isScreenLocked); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 3090 | |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3091 | if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3092 | final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3093 | if (currentSubtype != null) { |
| 3094 | final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3095 | lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
| 3096 | currentImi, currentSubtype.hashCode()); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 3100 | final int N = imList.size(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3101 | mIms = new InputMethodInfo[N]; |
| 3102 | mSubtypeIds = new int[N]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3103 | int checkedItem = 0; |
| 3104 | for (int i = 0; i < N; ++i) { |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3105 | final ImeSubtypeListItem item = imList.get(i); |
| 3106 | mIms[i] = item.mImi; |
| 3107 | mSubtypeIds[i] = item.mSubtypeId; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3108 | if (mIms[i].getId().equals(lastInputMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3109 | int subtypeId = mSubtypeIds[i]; |
| 3110 | if ((subtypeId == NOT_A_SUBTYPE_ID) |
| 3111 | || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) |
| 3112 | || (subtypeId == lastInputMethodSubtypeId)) { |
| 3113 | checkedItem = i; |
| 3114 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3115 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3116 | } |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3117 | |
| 3118 | final Context settingsContext = new ContextThemeWrapper(context, |
| 3119 | com.android.internal.R.style.Theme_DeviceDefault_Settings); |
| 3120 | |
| 3121 | mDialogBuilder = new AlertDialog.Builder(settingsContext); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3122 | mDialogBuilder.setOnCancelListener(new OnCancelListener() { |
| 3123 | @Override |
| 3124 | public void onCancel(DialogInterface dialog) { |
| 3125 | hideInputMethodMenu(); |
| 3126 | } |
| 3127 | }); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3128 | |
| 3129 | final Context dialogContext = mDialogBuilder.getContext(); |
| 3130 | final TypedArray a = dialogContext.obtainStyledAttributes(null, |
| 3131 | com.android.internal.R.styleable.DialogPreference, |
| 3132 | com.android.internal.R.attr.alertDialogStyle, 0); |
| 3133 | final Drawable dialogIcon = a.getDrawable( |
| 3134 | com.android.internal.R.styleable.DialogPreference_dialogIcon); |
| 3135 | a.recycle(); |
| 3136 | |
| 3137 | mDialogBuilder.setIcon(dialogIcon); |
| 3138 | |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 3139 | final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3140 | final View tv = inflater.inflate( |
| 3141 | com.android.internal.R.layout.input_method_switch_dialog_title, null); |
| 3142 | mDialogBuilder.setCustomTitle(tv); |
| 3143 | |
| 3144 | // Setup layout for a toggle switch of the hardware keyboard |
| 3145 | mSwitchingDialogTitleView = tv; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3146 | mSwitchingDialogTitleView |
| 3147 | .findViewById(com.android.internal.R.id.hard_keyboard_section) |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 3148 | .setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3149 | ? View.VISIBLE : View.GONE); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3150 | final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById( |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3151 | com.android.internal.R.id.hard_keyboard_switch); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3152 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3153 | hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
| 3154 | @Override |
| 3155 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3156 | mSettings.setShowImeWithHardKeyboard(isChecked); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3157 | // Ensure that the input method dialog is dismissed when changing |
| 3158 | // the hardware keyboard state. |
| 3159 | hideInputMethodMenu(); |
| 3160 | } |
| 3161 | }); |
| 3162 | |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3163 | final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3164 | com.android.internal.R.layout.input_method_switch_item, imList, checkedItem); |
| 3165 | final OnClickListener choiceListener = new OnClickListener() { |
| 3166 | @Override |
| 3167 | public void onClick(final DialogInterface dialog, final int which) { |
| 3168 | synchronized (mMethodMap) { |
| 3169 | if (mIms == null || mIms.length <= which || mSubtypeIds == null |
| 3170 | || mSubtypeIds.length <= which) { |
| 3171 | return; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3172 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3173 | final InputMethodInfo im = mIms[which]; |
| 3174 | int subtypeId = mSubtypeIds[which]; |
| 3175 | adapter.mCheckedItem = which; |
| 3176 | adapter.notifyDataSetChanged(); |
| 3177 | hideInputMethodMenu(); |
| 3178 | if (im != null) { |
| 3179 | if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) { |
| 3180 | subtypeId = NOT_A_SUBTYPE_ID; |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 3181 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3182 | setInputMethodLocked(im.getId(), subtypeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3183 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3184 | } |
| 3185 | } |
| 3186 | }; |
| 3187 | mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3188 | |
Seigo Nonaka | d4474cb | 2015-05-04 16:53:24 -0700 | [diff] [blame] | 3189 | if (!isScreenLocked) { |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3190 | final OnClickListener positiveListener = new OnClickListener() { |
| 3191 | @Override |
| 3192 | public void onClick(DialogInterface dialog, int whichButton) { |
| 3193 | showConfigureInputMethods(); |
| 3194 | } |
| 3195 | }; |
satok | 82beadf | 2010-12-27 19:03:06 +0900 | [diff] [blame] | 3196 | mDialogBuilder.setPositiveButton( |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3197 | com.android.internal.R.string.configure_input_methods, positiveListener); |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 3198 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3199 | mSwitchingDialog = mDialogBuilder.create(); |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 3200 | mSwitchingDialog.setCanceledOnTouchOutside(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3201 | mSwitchingDialog.getWindow().setType( |
| 3202 | WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG); |
Satoshi Kataoka | c86884c | 2012-10-09 15:20:29 +0900 | [diff] [blame] | 3203 | mSwitchingDialog.getWindow().getAttributes().privateFlags |= |
| 3204 | WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 3205 | mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method"); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 3206 | updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3207 | mSwitchingDialog.show(); |
| 3208 | } |
| 3209 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3210 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3211 | private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> { |
| 3212 | private final LayoutInflater mInflater; |
| 3213 | private final int mTextViewResourceId; |
| 3214 | private final List<ImeSubtypeListItem> mItemsList; |
Satoshi Kataoka | d214296 | 2012-11-12 18:43:06 +0900 | [diff] [blame] | 3215 | public int mCheckedItem; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3216 | public ImeSubtypeListAdapter(Context context, int textViewResourceId, |
| 3217 | List<ImeSubtypeListItem> itemsList, int checkedItem) { |
| 3218 | super(context, textViewResourceId, itemsList); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3219 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3220 | mTextViewResourceId = textViewResourceId; |
| 3221 | mItemsList = itemsList; |
| 3222 | mCheckedItem = checkedItem; |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 3223 | mInflater = context.getSystemService(LayoutInflater.class); |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | @Override |
| 3227 | public View getView(int position, View convertView, ViewGroup parent) { |
| 3228 | final View view = convertView != null ? convertView |
| 3229 | : mInflater.inflate(mTextViewResourceId, null); |
| 3230 | if (position < 0 || position >= mItemsList.size()) return view; |
| 3231 | final ImeSubtypeListItem item = mItemsList.get(position); |
| 3232 | final CharSequence imeName = item.mImeName; |
| 3233 | final CharSequence subtypeName = item.mSubtypeName; |
| 3234 | final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1); |
| 3235 | final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2); |
| 3236 | if (TextUtils.isEmpty(subtypeName)) { |
| 3237 | firstTextView.setText(imeName); |
| 3238 | secondTextView.setVisibility(View.GONE); |
| 3239 | } else { |
| 3240 | firstTextView.setText(subtypeName); |
| 3241 | secondTextView.setText(imeName); |
| 3242 | secondTextView.setVisibility(View.VISIBLE); |
| 3243 | } |
| 3244 | final RadioButton radioButton = |
| 3245 | (RadioButton)view.findViewById(com.android.internal.R.id.radio); |
| 3246 | radioButton.setChecked(position == mCheckedItem); |
| 3247 | return view; |
| 3248 | } |
| 3249 | } |
| 3250 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3251 | void hideInputMethodMenu() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3252 | synchronized (mMethodMap) { |
| 3253 | hideInputMethodMenuLocked(); |
| 3254 | } |
| 3255 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3256 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3257 | void hideInputMethodMenuLocked() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3258 | if (DEBUG) Slog.v(TAG, "Hide switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3259 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3260 | if (mSwitchingDialog != null) { |
| 3261 | mSwitchingDialog.dismiss(); |
| 3262 | mSwitchingDialog = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3263 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3264 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 3265 | updateSystemUiLocked(mCurToken, mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3266 | mDialogBuilder = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3267 | mIms = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3268 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3269 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3270 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3271 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3272 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3273 | public boolean setInputMethodEnabled(String id, boolean enabled) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3274 | // TODO: Make this work even for non-current users? |
| 3275 | if (!calledFromValidUser()) { |
| 3276 | return false; |
| 3277 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3278 | synchronized (mMethodMap) { |
| 3279 | if (mContext.checkCallingOrSelfPermission( |
| 3280 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 3281 | != PackageManager.PERMISSION_GRANTED) { |
| 3282 | throw new SecurityException( |
| 3283 | "Requires permission " |
| 3284 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 3285 | } |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 3286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3287 | long ident = Binder.clearCallingIdentity(); |
| 3288 | try { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3289 | return setInputMethodEnabledLocked(id, enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3290 | } finally { |
| 3291 | Binder.restoreCallingIdentity(ident); |
| 3292 | } |
| 3293 | } |
| 3294 | } |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3295 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3296 | boolean setInputMethodEnabledLocked(String id, boolean enabled) { |
| 3297 | // Make sure this is a valid input method. |
| 3298 | InputMethodInfo imm = mMethodMap.get(id); |
| 3299 | if (imm == null) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3300 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3301 | } |
| 3302 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3303 | List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings |
| 3304 | .getEnabledInputMethodsAndSubtypeListLocked(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3305 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3306 | if (enabled) { |
| 3307 | for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) { |
| 3308 | if (pair.first.equals(id)) { |
| 3309 | // We are enabling this input method, but it is already enabled. |
| 3310 | // Nothing to do. The previous state was enabled. |
| 3311 | return true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3312 | } |
| 3313 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3314 | mSettings.appendAndPutEnabledInputMethodLocked(id, false); |
| 3315 | // Previous state was disabled. |
| 3316 | return false; |
| 3317 | } else { |
| 3318 | StringBuilder builder = new StringBuilder(); |
| 3319 | if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 3320 | builder, enabledInputMethodsList, id)) { |
| 3321 | // Disabled input method is currently selected, switch to another one. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3322 | final String selId = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 3323 | if (id.equals(selId) && !chooseNewDefaultIMELocked()) { |
| 3324 | Slog.i(TAG, "Can't find new IME, unsetting the current input method."); |
| 3325 | resetSelectedInputMethodAndSubtypeLocked(""); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 3326 | } |
| 3327 | // Previous state was enabled. |
| 3328 | return true; |
| 3329 | } else { |
| 3330 | // We are disabling the input method but it is already disabled. |
| 3331 | // Nothing to do. The previous state was disabled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3332 | return false; |
| 3333 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3334 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 3335 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3336 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3337 | private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId, |
| 3338 | boolean setSubtypeOnly) { |
| 3339 | // Update the history of InputMethod and Subtype |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3340 | mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3341 | |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3342 | mCurUserActionNotificationSequenceNumber = |
| 3343 | Math.max(mCurUserActionNotificationSequenceNumber + 1, 1); |
| 3344 | if (DEBUG) { |
| 3345 | Slog.d(TAG, "Bump mCurUserActionNotificationSequenceNumber:" |
| 3346 | + mCurUserActionNotificationSequenceNumber); |
| 3347 | } |
| 3348 | |
| 3349 | if (mCurClient != null && mCurClient.client != null) { |
| 3350 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 3351 | MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER, |
Yohei Yukawa | 080fa34 | 2014-08-31 16:10:05 -0700 | [diff] [blame] | 3352 | mCurUserActionNotificationSequenceNumber, mCurClient)); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3353 | } |
| 3354 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3355 | // Set Subtype here |
| 3356 | if (imi == null || subtypeId < 0) { |
| 3357 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
Tadashi G. Takaoka | 0ba75bb | 2010-11-09 12:19:32 -0800 | [diff] [blame] | 3358 | mCurrentSubtype = null; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3359 | } else { |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 3360 | if (subtypeId < imi.getSubtypeCount()) { |
| 3361 | InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId); |
| 3362 | mSettings.putSelectedSubtype(subtype.hashCode()); |
| 3363 | mCurrentSubtype = subtype; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3364 | } else { |
| 3365 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 3366 | // If the subtype is not specified, choose the most applicable one |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3367 | mCurrentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3368 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3369 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3370 | |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 3371 | if (!setSubtypeOnly) { |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3372 | // Set InputMethod here |
| 3373 | mSettings.putSelectedInputMethod(imi != null ? imi.getId() : ""); |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) { |
| 3378 | InputMethodInfo imi = mMethodMap.get(newDefaultIme); |
| 3379 | int lastSubtypeId = NOT_A_SUBTYPE_ID; |
| 3380 | // newDefaultIme is empty when there is no candidate for the selected IME. |
| 3381 | if (imi != null && !TextUtils.isEmpty(newDefaultIme)) { |
| 3382 | String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme); |
| 3383 | if (subtypeHashCode != null) { |
| 3384 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3385 | lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3386 | imi, Integer.valueOf(subtypeHashCode)); |
| 3387 | } catch (NumberFormatException e) { |
| 3388 | Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e); |
| 3389 | } |
| 3390 | } |
| 3391 | } |
| 3392 | setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3393 | } |
| 3394 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3395 | // If there are no selected shortcuts, tries finding the most applicable ones. |
| 3396 | private Pair<InputMethodInfo, InputMethodSubtype> |
| 3397 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) { |
| 3398 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 3399 | InputMethodInfo mostApplicableIMI = null; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3400 | InputMethodSubtype mostApplicableSubtype = null; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3401 | boolean foundInSystemIME = false; |
| 3402 | |
| 3403 | // Search applicable subtype for each InputMethodInfo |
| 3404 | for (InputMethodInfo imi: imis) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3405 | final String imiId = imi.getId(); |
| 3406 | if (foundInSystemIME && !imiId.equals(mCurMethodId)) { |
| 3407 | continue; |
| 3408 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3409 | InputMethodSubtype subtype = null; |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3410 | final List<InputMethodSubtype> enabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3411 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3412 | // 1. Search by the current subtype's locale from enabledSubtypes. |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3413 | if (mCurrentSubtype != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3414 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3415 | mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3416 | } |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3417 | // 2. Search by the system locale from enabledSubtypes. |
| 3418 | // 3. Search the first enabled subtype matched with mode from enabledSubtypes. |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3419 | if (subtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3420 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 3421 | mRes, enabledSubtypes, mode, null, true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3422 | } |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 3423 | final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3424 | InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode); |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 3425 | final ArrayList<InputMethodSubtype> subtypesForSearch = |
| 3426 | overridingImplicitlyEnabledSubtypes.isEmpty() |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3427 | ? InputMethodUtils.getSubtypes(imi) |
| 3428 | : overridingImplicitlyEnabledSubtypes; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3429 | // 4. Search by the current subtype's locale from all subtypes. |
| 3430 | if (subtype == null && mCurrentSubtype != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3431 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 3432 | mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3433 | } |
| 3434 | // 5. Search by the system locale from all subtypes. |
| 3435 | // 6. Search the first enabled subtype matched with mode from all subtypes. |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3436 | if (subtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3437 | subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
satok | a86f5e4 | 2011-09-02 17:12:42 +0900 | [diff] [blame] | 3438 | mRes, subtypesForSearch, mode, null, true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3439 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3440 | if (subtype != null) { |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3441 | if (imiId.equals(mCurMethodId)) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3442 | // The current input method is the most applicable IME. |
| 3443 | mostApplicableIMI = imi; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3444 | mostApplicableSubtype = subtype; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3445 | break; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3446 | } else if (!foundInSystemIME) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3447 | // The system input method is 2nd applicable IME. |
| 3448 | mostApplicableIMI = imi; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3449 | mostApplicableSubtype = subtype; |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3450 | if ((imi.getServiceInfo().applicationInfo.flags |
| 3451 | & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 3452 | foundInSystemIME = true; |
| 3453 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3454 | } |
| 3455 | } |
| 3456 | } |
| 3457 | if (DEBUG) { |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3458 | if (mostApplicableIMI != null) { |
| 3459 | Slog.w(TAG, "Most applicable shortcut input method was:" |
| 3460 | + mostApplicableIMI.getId()); |
| 3461 | if (mostApplicableSubtype != null) { |
| 3462 | Slog.w(TAG, "Most applicable shortcut input method subtype was:" |
| 3463 | + "," + mostApplicableSubtype.getMode() + "," |
| 3464 | + mostApplicableSubtype.getLocale()); |
| 3465 | } |
| 3466 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3467 | } |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 3468 | if (mostApplicableIMI != null) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 3469 | return new Pair<> (mostApplicableIMI, mostApplicableSubtype); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3470 | } else { |
| 3471 | return null; |
| 3472 | } |
| 3473 | } |
| 3474 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3475 | /** |
| 3476 | * @return Return the current subtype of this input method. |
| 3477 | */ |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3478 | @Override |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3479 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3480 | // TODO: Make this work even for non-current users? |
| 3481 | if (!calledFromValidUser()) { |
| 3482 | return null; |
| 3483 | } |
| 3484 | synchronized (mMethodMap) { |
| 3485 | return getCurrentInputMethodSubtypeLocked(); |
| 3486 | } |
| 3487 | } |
| 3488 | |
| 3489 | private InputMethodSubtype getCurrentInputMethodSubtypeLocked() { |
satok | fdf419e | 2012-05-08 16:52:08 +0900 | [diff] [blame] | 3490 | if (mCurMethodId == null) { |
| 3491 | return null; |
| 3492 | } |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3493 | final boolean subtypeIsSelected = mSettings.isSubtypeSelected(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3494 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 3495 | if (imi == null || imi.getSubtypeCount() == 0) { |
| 3496 | return null; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3497 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3498 | if (!subtypeIsSelected || mCurrentSubtype == null |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3499 | || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) { |
| 3500 | int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3501 | if (subtypeId == NOT_A_SUBTYPE_ID) { |
| 3502 | // If there are no selected subtypes, the framework will try to find |
| 3503 | // the most applicable subtype from explicitly or implicitly enabled |
| 3504 | // subtypes. |
| 3505 | List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3506 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3507 | // If there is only one explicitly or implicitly enabled subtype, |
| 3508 | // just returns it. |
| 3509 | if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) { |
| 3510 | mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0); |
| 3511 | } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3512 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3513 | mRes, explicitlyOrImplicitlyEnabledSubtypes, |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3514 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3515 | if (mCurrentSubtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3516 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3517 | mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, |
| 3518 | true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3519 | } |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 3520 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3521 | } else { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3522 | mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId); |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 3523 | } |
| 3524 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3525 | return mCurrentSubtype; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3526 | } |
| 3527 | |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3528 | // TODO: We should change the return type from List to List<Parcelable> |
satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 3529 | @SuppressWarnings("rawtypes") |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3530 | @Override |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3531 | public List getShortcutInputMethodsAndSubtypes() { |
| 3532 | synchronized (mMethodMap) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 3533 | ArrayList<Object> ret = new ArrayList<>(); |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 3534 | if (mShortcutInputMethodsAndSubtypes.size() == 0) { |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3535 | // If there are no selected shortcut subtypes, the framework will try to find |
| 3536 | // the most applicable subtype from all subtypes whose mode is |
| 3537 | // SUBTYPE_MODE_VOICE. This is an exceptional case, so we will hardcode the mode. |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 3538 | Pair<InputMethodInfo, InputMethodSubtype> info = |
| 3539 | findLastResortApplicableShortcutInputMethodAndSubtypeLocked( |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3540 | InputMethodUtils.SUBTYPE_MODE_VOICE); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3541 | if (info != null) { |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 3542 | ret.add(info.first); |
| 3543 | ret.add(info.second); |
satok | 7599a7f | 2010-12-22 13:45:23 +0900 | [diff] [blame] | 3544 | } |
satok | 3da9223 | 2011-01-11 22:46:30 +0900 | [diff] [blame] | 3545 | return ret; |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 3546 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 3547 | for (InputMethodInfo imi: mShortcutInputMethodsAndSubtypes.keySet()) { |
| 3548 | ret.add(imi); |
| 3549 | for (InputMethodSubtype subtype: mShortcutInputMethodsAndSubtypes.get(imi)) { |
| 3550 | ret.add(subtype); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3551 | } |
| 3552 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 3553 | return ret; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 3554 | } |
| 3555 | } |
| 3556 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3557 | @Override |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 3558 | public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3559 | // TODO: Make this work even for non-current users? |
| 3560 | if (!calledFromValidUser()) { |
| 3561 | return false; |
| 3562 | } |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 3563 | synchronized (mMethodMap) { |
| 3564 | if (subtype != null && mCurMethodId != null) { |
| 3565 | InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3566 | int subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode()); |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 3567 | if (subtypeId != NOT_A_SUBTYPE_ID) { |
| 3568 | setInputMethodLocked(mCurMethodId, subtypeId); |
| 3569 | return true; |
| 3570 | } |
| 3571 | } |
| 3572 | return false; |
| 3573 | } |
| 3574 | } |
| 3575 | |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 3576 | // TODO: Cache the state for each user and reset when the cached user is removed. |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3577 | private static class InputMethodFileManager { |
| 3578 | private static final String SYSTEM_PATH = "system"; |
| 3579 | private static final String INPUT_METHOD_PATH = "inputmethod"; |
| 3580 | private static final String ADDITIONAL_SUBTYPES_FILE_NAME = "subtypes.xml"; |
| 3581 | private static final String NODE_SUBTYPES = "subtypes"; |
| 3582 | private static final String NODE_SUBTYPE = "subtype"; |
| 3583 | private static final String NODE_IMI = "imi"; |
| 3584 | private static final String ATTR_ID = "id"; |
| 3585 | private static final String ATTR_LABEL = "label"; |
| 3586 | private static final String ATTR_ICON = "icon"; |
| 3587 | private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale"; |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 3588 | private static final String ATTR_IME_SUBTYPE_LANGUAGE_TAG = "languageTag"; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3589 | private static final String ATTR_IME_SUBTYPE_MODE = "imeSubtypeMode"; |
| 3590 | private static final String ATTR_IME_SUBTYPE_EXTRA_VALUE = "imeSubtypeExtraValue"; |
| 3591 | private static final String ATTR_IS_AUXILIARY = "isAuxiliary"; |
Yohei Yukawa | 1e1a447 | 2016-03-10 23:46:07 -0800 | [diff] [blame] | 3592 | private static final String ATTR_IS_ASCII_CAPABLE = "isAsciiCapable"; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3593 | private final AtomicFile mAdditionalInputMethodSubtypeFile; |
| 3594 | private final HashMap<String, InputMethodInfo> mMethodMap; |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 3595 | private final HashMap<String, List<InputMethodSubtype>> mAdditionalSubtypesMap = |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 3596 | new HashMap<>(); |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 3597 | public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap, int userId) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3598 | if (methodMap == null) { |
| 3599 | throw new NullPointerException("methodMap is null"); |
| 3600 | } |
| 3601 | mMethodMap = methodMap; |
Xiaohui Chen | 7c69636 | 2015-09-16 09:56:14 -0700 | [diff] [blame] | 3602 | final File systemDir = userId == UserHandle.USER_SYSTEM |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 3603 | ? new File(Environment.getDataDirectory(), SYSTEM_PATH) |
| 3604 | : Environment.getUserSystemDirectory(userId); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3605 | final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH); |
Yohei Yukawa | df5af48 | 2015-08-04 22:11:11 -0700 | [diff] [blame] | 3606 | if (!inputMethodDir.exists() && !inputMethodDir.mkdirs()) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3607 | Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath()); |
| 3608 | } |
| 3609 | final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME); |
| 3610 | mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile); |
| 3611 | if (!subtypeFile.exists()) { |
| 3612 | // If "subtypes.xml" doesn't exist, create a blank file. |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 3613 | writeAdditionalInputMethodSubtypes( |
| 3614 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, methodMap); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3615 | } else { |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 3616 | readAdditionalInputMethodSubtypes( |
| 3617 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3618 | } |
| 3619 | } |
| 3620 | |
| 3621 | private void deleteAllInputMethodSubtypes(String imiId) { |
| 3622 | synchronized (mMethodMap) { |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 3623 | mAdditionalSubtypesMap.remove(imiId); |
| 3624 | writeAdditionalInputMethodSubtypes( |
| 3625 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | public void addInputMethodSubtypes( |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 3630 | InputMethodInfo imi, InputMethodSubtype[] additionalSubtypes) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3631 | synchronized (mMethodMap) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 3632 | final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>(); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3633 | final int N = additionalSubtypes.length; |
| 3634 | for (int i = 0; i < N; ++i) { |
| 3635 | final InputMethodSubtype subtype = additionalSubtypes[i]; |
satok | ed2b24e | 2011-08-31 18:03:21 +0900 | [diff] [blame] | 3636 | if (!subtypes.contains(subtype)) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3637 | subtypes.add(subtype); |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 3638 | } else { |
| 3639 | Slog.w(TAG, "Duplicated subtype definition found: " |
| 3640 | + subtype.getLocale() + ", " + subtype.getMode()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3641 | } |
| 3642 | } |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 3643 | mAdditionalSubtypesMap.put(imi.getId(), subtypes); |
| 3644 | writeAdditionalInputMethodSubtypes( |
| 3645 | mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | public HashMap<String, List<InputMethodSubtype>> getAllAdditionalInputMethodSubtypes() { |
| 3650 | synchronized (mMethodMap) { |
Satoshi Kataoka | e62e6d8 | 2012-07-02 18:45:43 +0900 | [diff] [blame] | 3651 | return mAdditionalSubtypesMap; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | private static void writeAdditionalInputMethodSubtypes( |
| 3656 | HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile, |
| 3657 | HashMap<String, InputMethodInfo> methodMap) { |
| 3658 | // Safety net for the case that this function is called before methodMap is set. |
| 3659 | final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0; |
| 3660 | FileOutputStream fos = null; |
| 3661 | try { |
| 3662 | fos = subtypesFile.startWrite(); |
| 3663 | final XmlSerializer out = new FastXmlSerializer(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 3664 | out.setOutput(fos, StandardCharsets.UTF_8.name()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3665 | out.startDocument(null, true); |
| 3666 | out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); |
| 3667 | out.startTag(null, NODE_SUBTYPES); |
| 3668 | for (String imiId : allSubtypes.keySet()) { |
| 3669 | if (isSetMethodMap && !methodMap.containsKey(imiId)) { |
| 3670 | Slog.w(TAG, "IME uninstalled or not valid.: " + imiId); |
| 3671 | continue; |
| 3672 | } |
| 3673 | out.startTag(null, NODE_IMI); |
| 3674 | out.attribute(null, ATTR_ID, imiId); |
| 3675 | final List<InputMethodSubtype> subtypesList = allSubtypes.get(imiId); |
| 3676 | final int N = subtypesList.size(); |
| 3677 | for (int i = 0; i < N; ++i) { |
| 3678 | final InputMethodSubtype subtype = subtypesList.get(i); |
| 3679 | out.startTag(null, NODE_SUBTYPE); |
| 3680 | out.attribute(null, ATTR_ICON, String.valueOf(subtype.getIconResId())); |
| 3681 | out.attribute(null, ATTR_LABEL, String.valueOf(subtype.getNameResId())); |
| 3682 | out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale()); |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 3683 | out.attribute(null, ATTR_IME_SUBTYPE_LANGUAGE_TAG, |
| 3684 | subtype.getLanguageTag()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3685 | out.attribute(null, ATTR_IME_SUBTYPE_MODE, subtype.getMode()); |
| 3686 | out.attribute(null, ATTR_IME_SUBTYPE_EXTRA_VALUE, subtype.getExtraValue()); |
| 3687 | out.attribute(null, ATTR_IS_AUXILIARY, |
| 3688 | String.valueOf(subtype.isAuxiliary() ? 1 : 0)); |
Yohei Yukawa | 1e1a447 | 2016-03-10 23:46:07 -0800 | [diff] [blame] | 3689 | out.attribute(null, ATTR_IS_ASCII_CAPABLE, |
| 3690 | String.valueOf(subtype.isAsciiCapable() ? 1 : 0)); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3691 | out.endTag(null, NODE_SUBTYPE); |
| 3692 | } |
| 3693 | out.endTag(null, NODE_IMI); |
| 3694 | } |
| 3695 | out.endTag(null, NODE_SUBTYPES); |
| 3696 | out.endDocument(); |
| 3697 | subtypesFile.finishWrite(fos); |
| 3698 | } catch (java.io.IOException e) { |
| 3699 | Slog.w(TAG, "Error writing subtypes", e); |
| 3700 | if (fos != null) { |
| 3701 | subtypesFile.failWrite(fos); |
| 3702 | } |
| 3703 | } |
| 3704 | } |
| 3705 | |
| 3706 | private static void readAdditionalInputMethodSubtypes( |
| 3707 | HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) { |
| 3708 | if (allSubtypes == null || subtypesFile == null) return; |
| 3709 | allSubtypes.clear(); |
Yohei Yukawa | 5894b43 | 2015-08-11 13:29:24 -0700 | [diff] [blame] | 3710 | try (final FileInputStream fis = subtypesFile.openRead()) { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3711 | final XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 3712 | parser.setInput(fis, StandardCharsets.UTF_8.name()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3713 | int type = parser.getEventType(); |
| 3714 | // Skip parsing until START_TAG |
| 3715 | while ((type = parser.next()) != XmlPullParser.START_TAG |
| 3716 | && type != XmlPullParser.END_DOCUMENT) {} |
| 3717 | String firstNodeName = parser.getName(); |
| 3718 | if (!NODE_SUBTYPES.equals(firstNodeName)) { |
| 3719 | throw new XmlPullParserException("Xml doesn't start with subtypes"); |
| 3720 | } |
| 3721 | final int depth =parser.getDepth(); |
| 3722 | String currentImiId = null; |
| 3723 | ArrayList<InputMethodSubtype> tempSubtypesArray = null; |
| 3724 | while (((type = parser.next()) != XmlPullParser.END_TAG |
| 3725 | || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { |
| 3726 | if (type != XmlPullParser.START_TAG) |
| 3727 | continue; |
| 3728 | final String nodeName = parser.getName(); |
| 3729 | if (NODE_IMI.equals(nodeName)) { |
| 3730 | currentImiId = parser.getAttributeValue(null, ATTR_ID); |
| 3731 | if (TextUtils.isEmpty(currentImiId)) { |
| 3732 | Slog.w(TAG, "Invalid imi id found in subtypes.xml"); |
| 3733 | continue; |
| 3734 | } |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 3735 | tempSubtypesArray = new ArrayList<>(); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3736 | allSubtypes.put(currentImiId, tempSubtypesArray); |
| 3737 | } else if (NODE_SUBTYPE.equals(nodeName)) { |
| 3738 | if (TextUtils.isEmpty(currentImiId) || tempSubtypesArray == null) { |
| 3739 | Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId); |
| 3740 | continue; |
| 3741 | } |
| 3742 | final int icon = Integer.valueOf( |
| 3743 | parser.getAttributeValue(null, ATTR_ICON)); |
| 3744 | final int label = Integer.valueOf( |
| 3745 | parser.getAttributeValue(null, ATTR_LABEL)); |
| 3746 | final String imeSubtypeLocale = |
| 3747 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE); |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 3748 | final String languageTag = |
| 3749 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LANGUAGE_TAG); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3750 | final String imeSubtypeMode = |
| 3751 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_MODE); |
| 3752 | final String imeSubtypeExtraValue = |
| 3753 | parser.getAttributeValue(null, ATTR_IME_SUBTYPE_EXTRA_VALUE); |
satok | 4a28bde | 2011-06-29 21:03:40 +0900 | [diff] [blame] | 3754 | final boolean isAuxiliary = "1".equals(String.valueOf( |
| 3755 | parser.getAttributeValue(null, ATTR_IS_AUXILIARY))); |
Yohei Yukawa | 1e1a447 | 2016-03-10 23:46:07 -0800 | [diff] [blame] | 3756 | final boolean isAsciiCapable = "1".equals(String.valueOf( |
| 3757 | parser.getAttributeValue(null, ATTR_IS_ASCII_CAPABLE))); |
Yohei Yukawa | 443c2ba | 2014-09-10 14:10:30 +0900 | [diff] [blame] | 3758 | final InputMethodSubtype subtype = new InputMethodSubtypeBuilder() |
| 3759 | .setSubtypeNameResId(label) |
| 3760 | .setSubtypeIconResId(icon) |
| 3761 | .setSubtypeLocale(imeSubtypeLocale) |
Yohei Yukawa | 868d19b | 2015-12-07 15:58:57 -0800 | [diff] [blame] | 3762 | .setLanguageTag(languageTag) |
Yohei Yukawa | 443c2ba | 2014-09-10 14:10:30 +0900 | [diff] [blame] | 3763 | .setSubtypeMode(imeSubtypeMode) |
| 3764 | .setSubtypeExtraValue(imeSubtypeExtraValue) |
| 3765 | .setIsAuxiliary(isAuxiliary) |
Yohei Yukawa | 1e1a447 | 2016-03-10 23:46:07 -0800 | [diff] [blame] | 3766 | .setIsAsciiCapable(isAsciiCapable) |
Yohei Yukawa | 443c2ba | 2014-09-10 14:10:30 +0900 | [diff] [blame] | 3767 | .build(); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3768 | tempSubtypesArray.add(subtype); |
| 3769 | } |
| 3770 | } |
Yohei Yukawa | 5894b43 | 2015-08-11 13:29:24 -0700 | [diff] [blame] | 3771 | } catch (XmlPullParserException | IOException | NumberFormatException e) { |
| 3772 | Slog.w(TAG, "Error reading subtypes", e); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3773 | return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3774 | } |
| 3775 | } |
| 3776 | } |
| 3777 | |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3778 | private static final class LocalServiceImpl implements InputMethodManagerInternal { |
| 3779 | @NonNull |
| 3780 | private final Handler mHandler; |
| 3781 | |
| 3782 | LocalServiceImpl(@NonNull final Handler handler) { |
| 3783 | mHandler = handler; |
| 3784 | } |
| 3785 | |
| 3786 | @Override |
| 3787 | public void setInteractive(boolean interactive) { |
| 3788 | // Do everything in handler so as not to block the caller. |
| 3789 | mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_INTERACTIVE, |
| 3790 | interactive ? 1 : 0, 0)); |
| 3791 | } |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 3792 | |
| 3793 | @Override |
| 3794 | public void switchInputMethod(boolean forwardDirection) { |
| 3795 | // Do everything in handler so as not to block the caller. |
| 3796 | mHandler.sendMessage(mHandler.obtainMessage(MSG_SWITCH_IME, |
| 3797 | forwardDirection ? 1 : 0, 0)); |
| 3798 | } |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3801 | @Override |
| 3802 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 3803 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 3804 | != PackageManager.PERMISSION_GRANTED) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3805 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3806 | pw.println("Permission Denial: can't dump InputMethodManager from from pid=" |
| 3807 | + Binder.getCallingPid() |
| 3808 | + ", uid=" + Binder.getCallingUid()); |
| 3809 | return; |
| 3810 | } |
| 3811 | |
| 3812 | IInputMethod method; |
| 3813 | ClientState client; |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 3814 | ClientState focusedWindowClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3815 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3816 | final Printer p = new PrintWriterPrinter(pw); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3817 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3818 | synchronized (mMethodMap) { |
| 3819 | p.println("Current Input Method Manager state:"); |
| 3820 | int N = mMethodList.size(); |
| 3821 | p.println(" Input Methods:"); |
| 3822 | for (int i=0; i<N; i++) { |
| 3823 | InputMethodInfo info = mMethodList.get(i); |
| 3824 | p.println(" InputMethod #" + i + ":"); |
| 3825 | info.dump(p, " "); |
| 3826 | } |
| 3827 | p.println(" Clients:"); |
| 3828 | for (ClientState ci : mClients.values()) { |
| 3829 | p.println(" Client " + ci + ":"); |
| 3830 | p.println(" client=" + ci.client); |
| 3831 | p.println(" inputContext=" + ci.inputContext); |
| 3832 | p.println(" sessionRequested=" + ci.sessionRequested); |
| 3833 | p.println(" curSession=" + ci.curSession); |
| 3834 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 3835 | p.println(" mCurMethodId=" + mCurMethodId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3836 | client = mCurClient; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 3837 | p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq); |
| 3838 | p.println(" mCurFocusedWindow=" + mCurFocusedWindow); |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 3839 | focusedWindowClient = mCurFocusedWindowClient; |
| 3840 | p.println(" mCurFocusedWindowClient=" + focusedWindowClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3841 | p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection |
| 3842 | + " mBoundToMethod=" + mBoundToMethod); |
| 3843 | p.println(" mCurToken=" + mCurToken); |
| 3844 | p.println(" mCurIntent=" + mCurIntent); |
| 3845 | method = mCurMethod; |
| 3846 | p.println(" mCurMethod=" + mCurMethod); |
| 3847 | p.println(" mEnabledSession=" + mEnabledSession); |
| 3848 | p.println(" mShowRequested=" + mShowRequested |
| 3849 | + " mShowExplicitlyRequested=" + mShowExplicitlyRequested |
| 3850 | + " mShowForced=" + mShowForced |
| 3851 | + " mInputShown=" + mInputShown); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3852 | p.println(" mCurUserActionNotificationSequenceNumber=" |
| 3853 | + mCurUserActionNotificationSequenceNumber); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3854 | p.println(" mSystemReady=" + mSystemReady + " mInteractive=" + mIsInteractive); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 3855 | p.println(" mSettingsObserver=" + mSettingsObserver); |
Yohei Yukawa | d724886 | 2015-06-03 23:56:12 -0700 | [diff] [blame] | 3856 | p.println(" mSwitchingController:"); |
| 3857 | mSwitchingController.dump(p); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 3858 | p.println(" mSettings:"); |
| 3859 | mSettings.dumpLocked(p, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3860 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3861 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3862 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3863 | if (client != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3864 | pw.flush(); |
| 3865 | try { |
| 3866 | client.client.asBinder().dump(fd, args); |
| 3867 | } catch (RemoteException e) { |
| 3868 | p.println("Input method client dead: " + e); |
| 3869 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3870 | } else { |
| 3871 | p.println("No input method client."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3872 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3873 | |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 3874 | if (focusedWindowClient != null && client != focusedWindowClient) { |
| 3875 | p.println(" "); |
| 3876 | p.println("Warning: Current input method client doesn't match the last focused. " |
| 3877 | + "window."); |
| 3878 | p.println("Dumping input method client in the last focused window just in case."); |
| 3879 | p.println(" "); |
| 3880 | pw.flush(); |
| 3881 | try { |
| 3882 | focusedWindowClient.client.asBinder().dump(fd, args); |
| 3883 | } catch (RemoteException e) { |
| 3884 | p.println("Input method client in focused window dead: " + e); |
| 3885 | } |
| 3886 | } |
| 3887 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3888 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3889 | if (method != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3890 | pw.flush(); |
| 3891 | try { |
| 3892 | method.asBinder().dump(fd, args); |
| 3893 | } catch (RemoteException e) { |
| 3894 | p.println("Input method service dead: " + e); |
| 3895 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 3896 | } else { |
| 3897 | p.println("No input method service."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3898 | } |
| 3899 | } |
| 3900 | } |