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