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