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