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