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