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