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 | |
Yohei Yukawa | 603f4d0 | 2018-09-11 15:04:58 -0700 | [diff] [blame] | 16 | package com.android.server.inputmethod; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 18 | import static android.view.Display.DEFAULT_DISPLAY; |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 19 | import static android.view.Display.INVALID_DISPLAY; |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 20 | import static android.view.inputmethod.InputMethodSystemProperty.PER_PROFILE_IME_ENABLED; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 21 | |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 22 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 23 | |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 24 | import android.Manifest; |
Phil Weaver | 03a65b0 | 2018-07-19 16:07:57 -0700 | [diff] [blame] | 25 | import android.accessibilityservice.AccessibilityService; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 26 | import android.annotation.AnyThread; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 27 | import android.annotation.BinderThread; |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 28 | import android.annotation.ColorInt; |
Yohei Yukawa | 41b094f | 2018-09-09 23:58:45 -0700 | [diff] [blame] | 29 | import android.annotation.DrawableRes; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 30 | import android.annotation.IntDef; |
Yohei Yukawa | 930328c | 2017-10-18 20:19:53 -0700 | [diff] [blame] | 31 | import android.annotation.MainThread; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 32 | import android.annotation.NonNull; |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 33 | import android.annotation.Nullable; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 34 | import android.annotation.RequiresPermission; |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 35 | import android.annotation.UserIdInt; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 36 | import android.app.ActivityManager; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 37 | import android.app.ActivityManagerInternal; |
Andrew Sapperstein | 8a3b4cb | 2017-04-28 14:35:31 -0700 | [diff] [blame] | 38 | import android.app.ActivityThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | import android.app.AlertDialog; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 40 | import android.app.AppGlobals; |
Yohei Yukawa | e63b5fa | 2014-09-19 13:14:55 +0900 | [diff] [blame] | 41 | import android.app.AppOpsManager; |
satok | f90a33e | 2011-07-19 11:55:52 +0900 | [diff] [blame] | 42 | import android.app.KeyguardManager; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 43 | import android.app.Notification; |
| 44 | import android.app.NotificationManager; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 45 | import android.app.PendingIntent; |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 46 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.content.ComponentName; |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 48 | import android.content.ContentProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.content.ContentResolver; |
| 50 | import android.content.Context; |
| 51 | import android.content.DialogInterface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.content.DialogInterface.OnCancelListener; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 53 | import android.content.DialogInterface.OnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | import android.content.Intent; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 55 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.content.ServiceConnection; |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 57 | import android.content.pm.ApplicationInfo; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 58 | import android.content.pm.IPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.content.pm.PackageManager; |
| 60 | import android.content.pm.ResolveInfo; |
| 61 | import android.content.pm.ServiceInfo; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 62 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | import android.content.res.Resources; |
| 64 | import android.content.res.TypedArray; |
| 65 | import android.database.ContentObserver; |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 66 | import android.graphics.drawable.Drawable; |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 67 | import android.hardware.display.DisplayManagerInternal; |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 68 | import android.inputmethodservice.InputMethodService; |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 69 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | import android.os.Binder; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 71 | import android.os.Bundle; |
Seigo Nonaka | e27dc2b | 2015-08-14 18:21:27 -0700 | [diff] [blame] | 72 | import android.os.Debug; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | import android.os.Handler; |
| 74 | import android.os.IBinder; |
| 75 | import android.os.IInterface; |
Yohei Yukawa | 23cbe85 | 2016-05-17 16:42:58 -0700 | [diff] [blame] | 76 | import android.os.LocaleList; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 77 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import android.os.Parcel; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 79 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | import android.os.RemoteException; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 81 | import android.os.ResultReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | import android.os.ServiceManager; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 83 | import android.os.ShellCallback; |
| 84 | import android.os.ShellCommand; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | import android.os.SystemClock; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 86 | import android.os.SystemProperties; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 87 | import android.os.UserHandle; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 88 | import android.os.UserManager; |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 89 | import android.os.UserManagerInternal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | import android.provider.Settings; |
| 91 | import android.text.TextUtils; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 92 | import android.text.style.SuggestionSpan; |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 93 | import android.util.ArrayMap; |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 94 | import android.util.ArraySet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import android.util.EventLog; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 96 | import android.util.LruCache; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 97 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | import android.util.PrintWriterPrinter; |
| 99 | import android.util.Printer; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 100 | import android.util.Slog; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 101 | import android.view.ContextThemeWrapper; |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 102 | import android.view.Display; |
| 103 | import android.view.DisplayInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | import android.view.IWindowManager; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 105 | import android.view.InputChannel; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 106 | import android.view.LayoutInflater; |
| 107 | import android.view.View; |
| 108 | import android.view.ViewGroup; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 109 | import android.view.Window; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 110 | import android.view.WindowManager.LayoutParams; |
Yohei Yukawa | b0c2645 | 2018-10-21 10:42:52 -0700 | [diff] [blame] | 111 | import android.view.WindowManager.LayoutParams.SoftInputModeFlags; |
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; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 114 | import android.view.inputmethod.InputConnection; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 115 | import android.view.inputmethod.InputConnectionInspector; |
Yohei Yukawa | 432cf60 | 2018-10-21 10:41:37 -0700 | [diff] [blame] | 116 | import android.view.inputmethod.InputConnectionInspector.MissingMethodFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | import android.view.inputmethod.InputMethod; |
| 118 | import android.view.inputmethod.InputMethodInfo; |
| 119 | import android.view.inputmethod.InputMethodManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 120 | import android.view.inputmethod.InputMethodSubtype; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 121 | import android.widget.ArrayAdapter; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 122 | import android.widget.CompoundButton; |
| 123 | import android.widget.CompoundButton.OnCheckedChangeListener; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 124 | import android.widget.RadioButton; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 125 | import android.widget.Switch; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 126 | import android.widget.TextView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 128 | import com.android.internal.annotations.GuardedBy; |
| 129 | import com.android.internal.content.PackageMonitor; |
| 130 | import com.android.internal.inputmethod.IInputContentUriToken; |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 131 | import com.android.internal.inputmethod.IInputMethodPrivilegedOperations; |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 132 | import com.android.internal.inputmethod.InputMethodDebug; |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 133 | import com.android.internal.inputmethod.StartInputFlags; |
Yohei Yukawa | c6632df | 2018-10-21 11:47:16 -0700 | [diff] [blame] | 134 | import com.android.internal.inputmethod.StartInputReason; |
Yohei Yukawa | 499e3f7 | 2018-10-21 20:15:11 -0700 | [diff] [blame] | 135 | import com.android.internal.inputmethod.UnbindReason; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 136 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 137 | import com.android.internal.notification.SystemNotificationChannels; |
| 138 | import com.android.internal.os.HandlerCaller; |
| 139 | import com.android.internal.os.SomeArgs; |
| 140 | import com.android.internal.os.TransferPipe; |
| 141 | import com.android.internal.util.DumpUtils; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 142 | import com.android.internal.util.IndentingPrintWriter; |
| 143 | import com.android.internal.view.IInputContext; |
| 144 | import com.android.internal.view.IInputMethod; |
| 145 | import com.android.internal.view.IInputMethodClient; |
| 146 | import com.android.internal.view.IInputMethodManager; |
| 147 | import com.android.internal.view.IInputMethodSession; |
| 148 | import com.android.internal.view.IInputSessionCallback; |
| 149 | import com.android.internal.view.InputBindResult; |
Yohei Yukawa | 603f4d0 | 2018-09-11 15:04:58 -0700 | [diff] [blame] | 150 | import com.android.server.EventLogTags; |
| 151 | import com.android.server.LocalServices; |
| 152 | import com.android.server.SystemService; |
Yohei Yukawa | e6b6e0e | 2018-09-12 16:42:48 -0700 | [diff] [blame] | 153 | import com.android.server.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem; |
| 154 | import com.android.server.inputmethod.InputMethodUtils.InputMethodSettings; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 155 | import com.android.server.statusbar.StatusBarManagerService; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 156 | import com.android.server.wm.WindowManagerInternal; |
| 157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | import java.io.FileDescriptor; |
| 159 | import java.io.IOException; |
| 160 | import java.io.PrintWriter; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 161 | import java.lang.annotation.Retention; |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 162 | import java.security.InvalidParameterException; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 163 | import java.text.SimpleDateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | import java.util.ArrayList; |
Yohei Yukawa | b8d240f | 2018-12-26 10:03:11 -0800 | [diff] [blame] | 165 | import java.util.Arrays; |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 166 | import java.util.Collections; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 167 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | import java.util.List; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 169 | import java.util.Locale; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 170 | import java.util.WeakHashMap; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 171 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | |
| 173 | /** |
| 174 | * This class provides a system service that manages input methods. |
| 175 | */ |
| 176 | public class InputMethodManagerService extends IInputMethodManager.Stub |
| 177 | implements ServiceConnection, Handler.Callback { |
| 178 | static final boolean DEBUG = false; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 179 | static final String TAG = "InputMethodManagerService"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 181 | @Retention(SOURCE) |
| 182 | @IntDef({ShellCommandResult.SUCCESS, ShellCommandResult.FAILURE}) |
| 183 | private @interface ShellCommandResult { |
| 184 | int SUCCESS = 0; |
| 185 | int FAILURE = -1; |
| 186 | } |
| 187 | |
Seigo Nonaka | d4474cb | 2015-05-04 16:53:24 -0700 | [diff] [blame] | 188 | static final int MSG_SHOW_IM_SUBTYPE_PICKER = 1; |
| 189 | static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 2; |
| 190 | static final int MSG_SHOW_IM_CONFIG = 3; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 191 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | static final int MSG_UNBIND_INPUT = 1000; |
| 193 | static final int MSG_BIND_INPUT = 1010; |
| 194 | static final int MSG_SHOW_SOFT_INPUT = 1020; |
| 195 | static final int MSG_HIDE_SOFT_INPUT = 1030; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 196 | static final int MSG_HIDE_CURRENT_INPUT_METHOD = 1035; |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 197 | static final int MSG_INITIALIZE_IME = 1040; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | static final int MSG_CREATE_SESSION = 1050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 199 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | static final int MSG_START_INPUT = 2000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 201 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 202 | static final int MSG_UNBIND_CLIENT = 3000; |
| 203 | static final int MSG_BIND_CLIENT = 3010; |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 204 | static final int MSG_SET_ACTIVE = 3020; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 205 | static final int MSG_SET_INTERACTIVE = 3030; |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 206 | static final int MSG_REPORT_FULLSCREEN_MODE = 3045; |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 207 | static final int MSG_REPORT_PRE_RENDERED = 3060; |
| 208 | static final int MSG_APPLY_IME_VISIBILITY = 3070; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 209 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 210 | static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000; |
| 211 | |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 212 | static final int MSG_SYSTEM_UNLOCK_USER = 5000; |
| 213 | |
Satoshi Kataoka | bcacc32 | 2013-10-21 17:57:27 -0700 | [diff] [blame] | 214 | static final long TIME_TO_RECONNECT = 3 * 1000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 215 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 216 | static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20; |
| 217 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 218 | private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID; |
satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 219 | private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher"; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 220 | |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 221 | /** |
| 222 | * Binding flags for establishing connection to the {@link InputMethodService}. |
| 223 | */ |
| 224 | private static final int IME_CONNECTION_BIND_FLAGS = |
| 225 | Context.BIND_AUTO_CREATE |
| 226 | | Context.BIND_NOT_VISIBLE |
| 227 | | Context.BIND_NOT_FOREGROUND |
Yohei Yukawa | ad78a61 | 2017-08-04 01:57:27 -0700 | [diff] [blame] | 228 | | Context.BIND_IMPORTANT_BACKGROUND; |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 229 | |
| 230 | /** |
| 231 | * Binding flags used only while the {@link InputMethodService} is showing window. |
| 232 | */ |
| 233 | private static final int IME_VISIBLE_BIND_FLAGS = |
| 234 | Context.BIND_AUTO_CREATE |
| 235 | | Context.BIND_TREAT_LIKE_ACTIVITY |
Yohei Yukawa | ad78a61 | 2017-08-04 01:57:27 -0700 | [diff] [blame] | 236 | | Context.BIND_FOREGROUND_SERVICE |
| 237 | | Context.BIND_SHOWING_UI; |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 238 | |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 239 | @Retention(SOURCE) |
| 240 | @IntDef({HardKeyboardBehavior.WIRELESS_AFFORDANCE, HardKeyboardBehavior.WIRED_AFFORDANCE}) |
| 241 | private @interface HardKeyboardBehavior { |
| 242 | int WIRELESS_AFFORDANCE = 0; |
| 243 | int WIRED_AFFORDANCE = 1; |
| 244 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 245 | |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 246 | /** |
| 247 | * A protected broadcast intent action for internal use for {@link PendingIntent} in |
| 248 | * the notification. |
| 249 | */ |
| 250 | private static final String ACTION_SHOW_INPUT_METHOD_PICKER = |
Yohei Yukawa | 603f4d0 | 2018-09-11 15:04:58 -0700 | [diff] [blame] | 251 | "com.android.server.inputmethod.InputMethodManagerService.SHOW_INPUT_METHOD_PICKER"; |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 252 | |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 253 | /** |
| 254 | * Debug flag for overriding runtime {@link SystemProperties}. |
| 255 | */ |
| 256 | @AnyThread |
| 257 | private static final class DebugFlag { |
| 258 | private static final Object LOCK = new Object(); |
| 259 | private final String mKey; |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 260 | private final boolean mDefaultValue; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 261 | @GuardedBy("LOCK") |
| 262 | private boolean mValue; |
| 263 | |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 264 | public DebugFlag(String key, boolean defaultValue) { |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 265 | mKey = key; |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 266 | mDefaultValue = defaultValue; |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 267 | mValue = SystemProperties.getBoolean(key, defaultValue); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void refresh() { |
| 271 | synchronized (LOCK) { |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 272 | mValue = SystemProperties.getBoolean(mKey, mDefaultValue); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | |
| 276 | boolean value() { |
| 277 | synchronized (LOCK) { |
| 278 | return mValue; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Debug flags that can be overridden using "adb shell setprop <key>" |
| 285 | * Note: These flags are cached. To refresh, run "adb shell ime refresh_debug_properties". |
| 286 | */ |
| 287 | private static final class DebugFlags { |
| 288 | static final DebugFlag FLAG_OPTIMIZE_START_INPUT = |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 289 | new DebugFlag("debug.optimize_startinput", false); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 290 | static final DebugFlag FLAG_PRE_RENDER_IME_VIEWS = |
| 291 | new DebugFlag("persist.pre_render_ime_views", false); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 294 | @UserIdInt |
| 295 | private int mLastSwitchUserId; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | final Context mContext; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 298 | final Resources mRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | final Handler mHandler; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 300 | final InputMethodSettings mSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | final SettingsObserver mSettingsObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | final IWindowManager mIWindowManager; |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 303 | final WindowManagerInternal mWindowManagerInternal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | final HandlerCaller mCaller; |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 305 | final boolean mHasFeature; |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 306 | private final ArrayMap<String, List<InputMethodSubtype>> mAdditionalSubtypeMap = |
| 307 | new ArrayMap<>(); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 308 | private final boolean mIsLowRam; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 309 | private final HardKeyboardListener mHardKeyboardListener; |
Yohei Yukawa | e63b5fa | 2014-09-19 13:14:55 +0900 | [diff] [blame] | 310 | private final AppOpsManager mAppOpsManager; |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 311 | private final UserManager mUserManager; |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 312 | private final UserManagerInternal mUserManagerInternal; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 313 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | // All known input methods. mMethodMap also serves as the global |
| 315 | // lock for this class. |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 316 | final ArrayList<InputMethodInfo> mMethodList = new ArrayList<>(); |
Yohei Yukawa | 1dd7de6 | 2018-11-20 19:25:29 -0800 | [diff] [blame] | 317 | final ArrayMap<String, InputMethodInfo> mMethodMap = new ArrayMap<>(); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 318 | private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans = |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 319 | new LruCache<>(SECURE_SUGGESTION_SPANS_MAX_SIZE); |
Satoshi Kataoka | d787f69 | 2013-10-26 04:44:21 +0900 | [diff] [blame] | 320 | private final InputMethodSubtypeSwitchingController mSwitchingController; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 321 | |
Yohei Yukawa | e073306 | 2017-02-09 22:49:35 -0800 | [diff] [blame] | 322 | /** |
| 323 | * Tracks how many times {@link #mMethodMap} was updated. |
| 324 | */ |
| 325 | @GuardedBy("mMethodMap") |
| 326 | private int mMethodMapUpdateCount = 0; |
| 327 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 328 | // Used to bring IME service up to visible adjustment while it is being shown. |
| 329 | final ServiceConnection mVisibleConnection = new ServiceConnection() { |
Yohei Yukawa | d3ef842 | 2018-06-07 16:28:07 -0700 | [diff] [blame] | 330 | @Override public void onBindingDied(ComponentName name) { |
| 331 | synchronized (mMethodMap) { |
| 332 | if (mVisibleBound) { |
| 333 | mContext.unbindService(mVisibleConnection); |
| 334 | mVisibleBound = false; |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 339 | @Override public void onServiceConnected(ComponentName name, IBinder service) { |
| 340 | } |
| 341 | |
| 342 | @Override public void onServiceDisconnected(ComponentName name) { |
| 343 | } |
| 344 | }; |
| 345 | boolean mVisibleBound = false; |
| 346 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 347 | // Ongoing notification |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 348 | private NotificationManager mNotificationManager; |
| 349 | private KeyguardManager mKeyguardManager; |
Griff Hazen | 6090c26 | 2016-03-25 08:11:24 -0700 | [diff] [blame] | 350 | private @Nullable StatusBarManagerService mStatusBar; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 351 | private Notification.Builder mImeSwitcherNotification; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 352 | private PendingIntent mImeSwitchPendingIntent; |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 353 | private boolean mShowOngoingImeSwitcherForPhones; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 354 | private boolean mNotificationShown; |
| 355 | |
Tadashi G. Takaoka | 8c6d477 | 2014-08-05 15:29:17 +0900 | [diff] [blame] | 356 | static class SessionState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 357 | final ClientState client; |
| 358 | final IInputMethod method; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 359 | |
| 360 | IInputMethodSession session; |
| 361 | InputChannel channel; |
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 | @Override |
| 364 | public String toString() { |
| 365 | return "SessionState{uid " + client.uid + " pid " + client.pid |
| 366 | + " method " + Integer.toHexString( |
| 367 | System.identityHashCode(method)) |
| 368 | + " session " + Integer.toHexString( |
| 369 | System.identityHashCode(session)) |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 370 | + " channel " + channel |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | + "}"; |
| 372 | } |
| 373 | |
| 374 | SessionState(ClientState _client, IInputMethod _method, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 375 | IInputMethodSession _session, InputChannel _channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | client = _client; |
| 377 | method = _method; |
| 378 | session = _session; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 379 | channel = _channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | } |
| 381 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 382 | |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 383 | private static final class ClientDeathRecipient implements IBinder.DeathRecipient { |
| 384 | private final InputMethodManagerService mImms; |
| 385 | private final IInputMethodClient mClient; |
| 386 | |
| 387 | ClientDeathRecipient(InputMethodManagerService imms, IInputMethodClient client) { |
| 388 | mImms = imms; |
| 389 | mClient = client; |
| 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public void binderDied() { |
| 394 | mImms.removeClient(mClient); |
| 395 | } |
| 396 | } |
| 397 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 398 | static final class ClientState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | final IInputMethodClient client; |
| 400 | final IInputContext inputContext; |
| 401 | final int uid; |
| 402 | final int pid; |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 403 | final int selfReportedDisplayId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | final InputBinding binding; |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 405 | final ClientDeathRecipient clientDeathRecipient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 406 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | boolean sessionRequested; |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 408 | // Determines if IMEs should be pre-rendered. |
| 409 | // DebugFlag can be flipped anytime. This flag is kept per-client to maintain behavior |
| 410 | // through the life of the current client. |
| 411 | boolean shouldPreRenderIme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | SessionState curSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | @Override |
| 415 | public String toString() { |
| 416 | return "ClientState{" + Integer.toHexString( |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 417 | System.identityHashCode(this)) + " uid=" + uid |
| 418 | + " pid=" + pid + " displayId=" + selfReportedDisplayId + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | ClientState(IInputMethodClient _client, IInputContext _inputContext, |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 422 | int _uid, int _pid, int _selfReportedDisplayId, |
| 423 | ClientDeathRecipient _clientDeathRecipient) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | client = _client; |
| 425 | inputContext = _inputContext; |
| 426 | uid = _uid; |
| 427 | pid = _pid; |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 428 | selfReportedDisplayId = _selfReportedDisplayId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | binding = new InputBinding(null, inputContext.asBinder(), uid, pid); |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 430 | clientDeathRecipient = _clientDeathRecipient; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | } |
| 432 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 433 | |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 434 | final ArrayMap<IBinder, ClientState> mClients = new ArrayMap<>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | /** |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 437 | * Set once the system is ready to run third party code. |
| 438 | */ |
| 439 | boolean mSystemReady; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 440 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 441 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 442 | * Id obtained with {@link InputMethodInfo#getId()} for the currently selected input method. |
| 443 | * method. This is to be synchronized with the secure settings keyed with |
| 444 | * {@link Settings.Secure#DEFAULT_INPUT_METHOD}. |
| 445 | * |
| 446 | * <p>This can be transiently {@code null} when the system is re-initializing input method |
| 447 | * settings, e.g., the system locale is just changed.</p> |
| 448 | * |
| 449 | * <p>Note that {@link #mCurId} is used to track which IME is being connected to |
| 450 | * {@link InputMethodManagerService}.</p> |
| 451 | * |
| 452 | * @see #mCurId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 454 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | String mCurMethodId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | /** |
| 458 | * The current binding sequence number, incremented every time there is |
| 459 | * a new bind performed. |
| 460 | */ |
| 461 | int mCurSeq; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | /** |
| 464 | * The client that is currently bound to an input method. |
| 465 | */ |
| 466 | ClientState mCurClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 467 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | /** |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 469 | * The last window token that we confirmed to be focused. This is always updated upon reports |
| 470 | * from the input method client. If the window state is already changed before the report is |
| 471 | * handled, this field just keeps the last value. |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 472 | */ |
| 473 | IBinder mCurFocusedWindow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 474 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 475 | /** |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 476 | * The last window token that we confirmed that IME started talking to. This is always updated |
| 477 | * upon reports from the input method. If the window state is already changed before the report |
| 478 | * is handled, this field just keeps the last value. |
| 479 | */ |
| 480 | IBinder mLastImeTargetWindow; |
| 481 | |
| 482 | /** |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 483 | * {@link LayoutParams#softInputMode} of {@link #mCurFocusedWindow}. |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 484 | * |
| 485 | * @see #mCurFocusedWindow |
| 486 | */ |
Yohei Yukawa | b0c2645 | 2018-10-21 10:42:52 -0700 | [diff] [blame] | 487 | @SoftInputModeFlags |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 488 | int mCurFocusedWindowSoftInputMode; |
| 489 | |
| 490 | /** |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 491 | * The client by which {@link #mCurFocusedWindow} was reported. |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 492 | */ |
| 493 | ClientState mCurFocusedWindowClient; |
| 494 | |
| 495 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | * The input context last provided by the current client. |
| 497 | */ |
| 498 | IInputContext mCurInputContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 499 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | /** |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 501 | * The missing method flags for the input context last provided by the current client. |
| 502 | * |
| 503 | * @see android.view.inputmethod.InputConnectionInspector.MissingMethodFlags |
| 504 | */ |
Yohei Yukawa | 432cf60 | 2018-10-21 10:41:37 -0700 | [diff] [blame] | 505 | @MissingMethodFlags |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 506 | int mCurInputContextMissingMethods; |
| 507 | |
| 508 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | * The attributes last provided by the current client. |
| 510 | */ |
| 511 | EditorInfo mCurAttribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 512 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 514 | * 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] | 515 | * connected to or in the process of connecting to. |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 516 | * |
| 517 | * <p>This can be {@code null} when no input method is connected.</p> |
| 518 | * |
| 519 | * @see #mCurMethodId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 521 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | String mCurId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 523 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | /** |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 525 | * The current subtype of the current input method. |
| 526 | */ |
| 527 | private InputMethodSubtype mCurrentSubtype; |
| 528 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 529 | // Was the keyguard locked when this client became current? |
| 530 | private boolean mCurClientInKeyguard; |
| 531 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 532 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | * Set to true if our ServiceConnection is currently actively bound to |
| 534 | * a service (whether or not we have gotten its IBinder back yet). |
| 535 | */ |
| 536 | boolean mHaveConnection; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 537 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 538 | /** |
| 539 | * Set if the client has asked for the input method to be shown. |
| 540 | */ |
| 541 | boolean mShowRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 542 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | /** |
| 544 | * Set if we were explicitly told to show the input method. |
| 545 | */ |
| 546 | boolean mShowExplicitlyRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | /** |
| 549 | * Set if we were forced to be shown. |
| 550 | */ |
| 551 | boolean mShowForced; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 552 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | /** |
| 554 | * Set if we last told the input method to show itself. |
| 555 | */ |
| 556 | boolean mInputShown; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 557 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | /** |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 559 | * {@code true} if the current input method is in fullscreen mode. |
| 560 | */ |
| 561 | boolean mInFullscreenMode; |
| 562 | |
| 563 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | * The Intent used to connect to the current input method. |
| 565 | */ |
| 566 | Intent mCurIntent; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | /** |
| 569 | * The token we have made for the currently active input method, to |
| 570 | * identify it in the future. |
| 571 | */ |
| 572 | IBinder mCurToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 573 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | /** |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 575 | * The displayId of current active input method. |
| 576 | */ |
| 577 | int mCurTokenDisplayId = INVALID_DISPLAY; |
| 578 | |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 579 | final ImeDisplayValidator mImeDisplayValidator; |
| 580 | |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 581 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | * If non-null, this is the input method service we are currently connected |
| 583 | * to. |
| 584 | */ |
| 585 | IInputMethod mCurMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 586 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | /** |
| 588 | * Time that we last initiated a bind to the input method, to determine |
| 589 | * if we should try to disconnect and reconnect to it. |
| 590 | */ |
| 591 | long mLastBindTime; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | /** |
| 594 | * Have we called mCurMethod.bindInput()? |
| 595 | */ |
| 596 | boolean mBoundToMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | /** |
| 599 | * Currently enabled session. Only touched by service thread, not |
| 600 | * protected by a lock. |
| 601 | */ |
| 602 | SessionState mEnabledSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | /** |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 605 | * 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] | 606 | */ |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 607 | boolean mIsInteractive = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 608 | |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 609 | int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 610 | |
| 611 | /** |
| 612 | * A set of status bits regarding the active IME. |
| 613 | * |
| 614 | * <p>This value is a combination of following two bits:</p> |
| 615 | * <dl> |
| 616 | * <dt>{@link InputMethodService#IME_ACTIVE}</dt> |
| 617 | * <dd> |
| 618 | * If this bit is ON, connected IME is ready to accept touch/key events. |
| 619 | * </dd> |
| 620 | * <dt>{@link InputMethodService#IME_VISIBLE}</dt> |
| 621 | * <dd> |
| 622 | * If this bit is ON, some of IME view, e.g. software input, candidate view, is visible. |
| 623 | * </dd> |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 624 | * dt>{@link InputMethodService#IME_INVISIBLE}</dt> |
| 625 | * <dd> If this bit is ON, IME is ready with views from last EditorInfo but is |
| 626 | * currently invisible. |
| 627 | * </dd> |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 628 | * </dl> |
| 629 | * <em>Do not update this value outside of setImeWindowStatus.</em> |
| 630 | */ |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 631 | int mImeWindowVis; |
| 632 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 633 | private AlertDialog.Builder mDialogBuilder; |
| 634 | private AlertDialog mSwitchingDialog; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 635 | private IBinder mSwitchingDialogToken = new Binder(); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 636 | private View mSwitchingDialogTitleView; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 637 | private InputMethodInfo[] mIms; |
| 638 | private int[] mSubtypeIds; |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 639 | private LocaleList mLastSystemLocales; |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 640 | private boolean mShowImeWithHardKeyboard; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 641 | private boolean mAccessibilityRequestingNoSoftKeyboard; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 642 | private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor(); |
| 643 | private final IPackageManager mIPackageManager; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 644 | private final String mSlotIme; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 645 | @HardKeyboardBehavior |
| 646 | private final int mHardKeyboardBehavior; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 647 | |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 648 | /** |
| 649 | * Internal state snapshot when {@link #MSG_START_INPUT} message is about to be posted to the |
| 650 | * internal message queue. Any subsequent state change inside {@link InputMethodManagerService} |
| 651 | * will not affect those tasks that are already posted. |
| 652 | * |
| 653 | * <p>Posting {@link #MSG_START_INPUT} message basically means that |
| 654 | * {@link InputMethodService#doStartInput(InputConnection, EditorInfo, boolean)} will be called |
| 655 | * back in the current IME process shortly, which will also affect what the current IME starts |
| 656 | * receiving from {@link InputMethodService#getCurrentInputConnection()}. In other words, this |
| 657 | * snapshot will be taken every time when {@link InputMethodManagerService} is initiating a new |
| 658 | * logical input session between the client application and the current IME.</p> |
| 659 | * |
| 660 | * <p>Be careful to not keep strong references to this object forever, which can prevent |
| 661 | * {@link StartInputInfo#mImeToken} and {@link StartInputInfo#mTargetWindow} from being GC-ed. |
| 662 | * </p> |
| 663 | */ |
| 664 | private static class StartInputInfo { |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 665 | private static final AtomicInteger sSequenceNumber = new AtomicInteger(0); |
| 666 | |
| 667 | final int mSequenceNumber; |
| 668 | final long mTimestamp; |
| 669 | final long mWallTime; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 670 | @UserIdInt |
| 671 | final int mImeUserId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 672 | @NonNull |
| 673 | final IBinder mImeToken; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 674 | final int mImeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 675 | @NonNull |
| 676 | final String mImeId; |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 677 | @StartInputReason |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 678 | final int mStartInputReason; |
| 679 | final boolean mRestarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 680 | @UserIdInt |
| 681 | final int mTargetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 682 | final int mTargetDisplayId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 683 | @Nullable |
| 684 | final IBinder mTargetWindow; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 685 | @NonNull |
| 686 | final EditorInfo mEditorInfo; |
Yohei Yukawa | b0c2645 | 2018-10-21 10:42:52 -0700 | [diff] [blame] | 687 | @SoftInputModeFlags |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 688 | final int mTargetWindowSoftInputMode; |
| 689 | final int mClientBindSequenceNumber; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 690 | |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 691 | StartInputInfo(@UserIdInt int imeUserId, @NonNull IBinder imeToken, int imeDisplayId, |
| 692 | @NonNull String imeId, @StartInputReason int startInputReason, boolean restarting, |
| 693 | @UserIdInt int targetUserId, int targetDisplayId, @Nullable IBinder targetWindow, |
| 694 | @NonNull EditorInfo editorInfo, @SoftInputModeFlags int targetWindowSoftInputMode, |
| 695 | int clientBindSequenceNumber) { |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 696 | mSequenceNumber = sSequenceNumber.getAndIncrement(); |
| 697 | mTimestamp = SystemClock.uptimeMillis(); |
| 698 | mWallTime = System.currentTimeMillis(); |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 699 | mImeUserId = imeUserId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 700 | mImeToken = imeToken; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 701 | mImeDisplayId = imeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 702 | mImeId = imeId; |
| 703 | mStartInputReason = startInputReason; |
| 704 | mRestarting = restarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 705 | mTargetUserId = targetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 706 | mTargetDisplayId = targetDisplayId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 707 | mTargetWindow = targetWindow; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 708 | mEditorInfo = editorInfo; |
| 709 | mTargetWindowSoftInputMode = targetWindowSoftInputMode; |
| 710 | mClientBindSequenceNumber = clientBindSequenceNumber; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | |
Yohei Yukawa | b37d8bd | 2017-02-13 18:29:05 -0800 | [diff] [blame] | 714 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 715 | private final WeakHashMap<IBinder, IBinder> mImeTargetWindowMap = new WeakHashMap<>(); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 716 | |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 717 | /** |
| 718 | * A ring buffer to store the history of {@link StartInputInfo}. |
| 719 | */ |
| 720 | private static final class StartInputHistory { |
| 721 | /** |
| 722 | * Entry size for non low-RAM devices. |
| 723 | * |
| 724 | * <p>TODO: Consider to follow what other system services have been doing to manage |
| 725 | * constants (e.g. {@link android.provider.Settings.Global#ACTIVITY_MANAGER_CONSTANTS}).</p> |
| 726 | */ |
| 727 | private final static int ENTRY_SIZE_FOR_HIGH_RAM_DEVICE = 16; |
| 728 | |
| 729 | /** |
| 730 | * Entry size for non low-RAM devices. |
| 731 | * |
| 732 | * <p>TODO: Consider to follow what other system services have been doing to manage |
| 733 | * constants (e.g. {@link android.provider.Settings.Global#ACTIVITY_MANAGER_CONSTANTS}).</p> |
| 734 | */ |
| 735 | private final static int ENTRY_SIZE_FOR_LOW_RAM_DEVICE = 5; |
| 736 | |
| 737 | private static int getEntrySize() { |
| 738 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 739 | return ENTRY_SIZE_FOR_LOW_RAM_DEVICE; |
| 740 | } else { |
| 741 | return ENTRY_SIZE_FOR_HIGH_RAM_DEVICE; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Backing store for the ring bugger. |
| 747 | */ |
| 748 | private final Entry[] mEntries = new Entry[getEntrySize()]; |
| 749 | |
| 750 | /** |
| 751 | * An index of {@link #mEntries}, to which next {@link #addEntry(StartInputInfo)} should |
| 752 | * write. |
| 753 | */ |
| 754 | private int mNextIndex = 0; |
| 755 | |
| 756 | /** |
| 757 | * Recyclable entry to store the information in {@link StartInputInfo}. |
| 758 | */ |
| 759 | private static final class Entry { |
| 760 | int mSequenceNumber; |
| 761 | long mTimestamp; |
| 762 | long mWallTime; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 763 | @UserIdInt |
| 764 | int mImeUserId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 765 | @NonNull |
| 766 | String mImeTokenString; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 767 | int mImeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 768 | @NonNull |
| 769 | String mImeId; |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 770 | @StartInputReason |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 771 | int mStartInputReason; |
| 772 | boolean mRestarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 773 | @UserIdInt |
| 774 | int mTargetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 775 | int mTargetDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 776 | @NonNull |
| 777 | String mTargetWindowString; |
| 778 | @NonNull |
| 779 | EditorInfo mEditorInfo; |
Yohei Yukawa | b0c2645 | 2018-10-21 10:42:52 -0700 | [diff] [blame] | 780 | @SoftInputModeFlags |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 781 | int mTargetWindowSoftInputMode; |
| 782 | int mClientBindSequenceNumber; |
| 783 | |
| 784 | Entry(@NonNull StartInputInfo original) { |
| 785 | set(original); |
| 786 | } |
| 787 | |
| 788 | void set(@NonNull StartInputInfo original) { |
| 789 | mSequenceNumber = original.mSequenceNumber; |
| 790 | mTimestamp = original.mTimestamp; |
| 791 | mWallTime = original.mWallTime; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 792 | mImeUserId = original.mImeUserId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 793 | // Intentionally convert to String so as not to keep a strong reference to a Binder |
| 794 | // object. |
| 795 | mImeTokenString = String.valueOf(original.mImeToken); |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 796 | mImeDisplayId = original.mImeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 797 | mImeId = original.mImeId; |
| 798 | mStartInputReason = original.mStartInputReason; |
| 799 | mRestarting = original.mRestarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 800 | mTargetUserId = original.mTargetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 801 | mTargetDisplayId = original.mTargetDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 802 | // Intentionally convert to String so as not to keep a strong reference to a Binder |
| 803 | // object. |
| 804 | mTargetWindowString = String.valueOf(original.mTargetWindow); |
| 805 | mEditorInfo = original.mEditorInfo; |
| 806 | mTargetWindowSoftInputMode = original.mTargetWindowSoftInputMode; |
| 807 | mClientBindSequenceNumber = original.mClientBindSequenceNumber; |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | /** |
| 812 | * Add a new entry and discard the oldest entry as needed. |
| 813 | * @param info {@lin StartInputInfo} to be added. |
| 814 | */ |
| 815 | void addEntry(@NonNull StartInputInfo info) { |
| 816 | final int index = mNextIndex; |
| 817 | if (mEntries[index] == null) { |
| 818 | mEntries[index] = new Entry(info); |
| 819 | } else { |
| 820 | mEntries[index].set(info); |
| 821 | } |
| 822 | mNextIndex = (mNextIndex + 1) % mEntries.length; |
| 823 | } |
| 824 | |
| 825 | void dump(@NonNull PrintWriter pw, @NonNull String prefix) { |
| 826 | final SimpleDateFormat dataFormat = |
| 827 | new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US); |
| 828 | |
| 829 | for (int i = 0; i < mEntries.length; ++i) { |
| 830 | final Entry entry = mEntries[(i + mNextIndex) % mEntries.length]; |
| 831 | if (entry == null) { |
| 832 | continue; |
| 833 | } |
| 834 | pw.print(prefix); |
| 835 | pw.println("StartInput #" + entry.mSequenceNumber + ":"); |
| 836 | |
| 837 | pw.print(prefix); |
| 838 | pw.println(" time=" + dataFormat.format(new Date(entry.mWallTime)) |
| 839 | + " (timestamp=" + entry.mTimestamp + ")" |
| 840 | + " reason=" |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 841 | + InputMethodDebug.startInputReasonToString(entry.mStartInputReason) |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 842 | + " restarting=" + entry.mRestarting); |
| 843 | |
| 844 | pw.print(prefix); |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 845 | pw.print(" imeToken=" + entry.mImeTokenString + " [" + entry.mImeId + "]"); |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 846 | pw.print(" imeUserId=" + entry.mImeUserId); |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 847 | pw.println(" imeDisplayId=" + entry.mImeDisplayId); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 848 | |
| 849 | pw.print(prefix); |
| 850 | pw.println(" targetWin=" + entry.mTargetWindowString |
| 851 | + " [" + entry.mEditorInfo.packageName + "]" |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 852 | + " targetUserId=" + entry.mTargetUserId |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 853 | + " targetDisplayId=" + entry.mTargetDisplayId |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 854 | + " clientBindSeq=" + entry.mClientBindSequenceNumber); |
| 855 | |
| 856 | pw.print(prefix); |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 857 | pw.println(" softInputMode=" + InputMethodDebug.softInputModeToString( |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 858 | entry.mTargetWindowSoftInputMode)); |
| 859 | |
| 860 | pw.print(prefix); |
| 861 | pw.println(" inputType=0x" + Integer.toHexString(entry.mEditorInfo.inputType) |
| 862 | + " imeOptions=0x" + Integer.toHexString(entry.mEditorInfo.imeOptions) |
| 863 | + " fieldId=0x" + Integer.toHexString(entry.mEditorInfo.fieldId) |
| 864 | + " fieldName=" + entry.mEditorInfo.fieldName |
| 865 | + " actionId=" + entry.mEditorInfo.actionId |
| 866 | + " actionLabel=" + entry.mEditorInfo.actionLabel); |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | @GuardedBy("mMethodMap") |
| 872 | @NonNull |
| 873 | private final StartInputHistory mStartInputHistory = new StartInputHistory(); |
| 874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 875 | class SettingsObserver extends ContentObserver { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 876 | int mUserId; |
| 877 | boolean mRegistered = false; |
Yohei Yukawa | 7b574cb | 2016-03-16 17:22:22 -0700 | [diff] [blame] | 878 | @NonNull |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 879 | String mLastEnabled = ""; |
| 880 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 881 | /** |
| 882 | * <em>This constructor must be called within the lock.</em> |
| 883 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | SettingsObserver(Handler handler) { |
| 885 | super(handler); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 888 | public void registerContentObserverLocked(@UserIdInt int userId) { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 889 | if (mRegistered && mUserId == userId) { |
| 890 | return; |
| 891 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 892 | ContentResolver resolver = mContext.getContentResolver(); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 893 | if (mRegistered) { |
| 894 | mContext.getContentResolver().unregisterContentObserver(this); |
| 895 | mRegistered = false; |
| 896 | } |
| 897 | if (mUserId != userId) { |
| 898 | mLastEnabled = ""; |
| 899 | mUserId = userId; |
| 900 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 902 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, userId); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 903 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 904 | Settings.Secure.ENABLED_INPUT_METHODS), false, this, userId); |
satok | b6109bb | 2011-02-03 22:24:54 +0900 | [diff] [blame] | 905 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 906 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this, userId); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 907 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 908 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD), false, this, userId); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 909 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 910 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE), false, this, userId); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 911 | mRegistered = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 913 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 914 | @Override public void onChange(boolean selfChange, Uri uri) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 915 | final Uri showImeUri = Settings.Secure.getUriFor( |
| 916 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD); |
| 917 | final Uri accessibilityRequestingNoImeUri = Settings.Secure.getUriFor( |
| 918 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | synchronized (mMethodMap) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 920 | if (showImeUri.equals(uri)) { |
| 921 | updateKeyboardFromSettingsLocked(); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 922 | } else if (accessibilityRequestingNoImeUri.equals(uri)) { |
Phil Weaver | 03a65b0 | 2018-07-19 16:07:57 -0700 | [diff] [blame] | 923 | final int accessibilitySoftKeyboardSetting = Settings.Secure.getIntForUser( |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 924 | mContext.getContentResolver(), |
Phil Weaver | 03a65b0 | 2018-07-19 16:07:57 -0700 | [diff] [blame] | 925 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE, 0, mUserId); |
| 926 | mAccessibilityRequestingNoSoftKeyboard = |
| 927 | (accessibilitySoftKeyboardSetting & AccessibilityService.SHOW_MODE_MASK) |
| 928 | == AccessibilityService.SHOW_MODE_HIDDEN; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 929 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 930 | final boolean showRequested = mShowRequested; |
| 931 | hideCurrentInputLocked(0, null); |
| 932 | mShowRequested = showRequested; |
| 933 | } else if (mShowRequested) { |
| 934 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| 935 | } |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 936 | } else { |
| 937 | boolean enabledChanged = false; |
| 938 | String newEnabled = mSettings.getEnabledInputMethodsStr(); |
| 939 | if (!mLastEnabled.equals(newEnabled)) { |
| 940 | mLastEnabled = newEnabled; |
| 941 | enabledChanged = true; |
| 942 | } |
| 943 | updateInputMethodsFromSettingsLocked(enabledChanged); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 944 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 945 | } |
| 946 | } |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 947 | |
| 948 | @Override |
| 949 | public String toString() { |
| 950 | return "SettingsObserver{mUserId=" + mUserId + " mRegistered=" + mRegistered |
| 951 | + " mLastEnabled=" + mLastEnabled + "}"; |
| 952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 954 | |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 955 | class ImmsBroadcastReceiver extends BroadcastReceiver { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 956 | @Override |
| 957 | public void onReceive(Context context, Intent intent) { |
| 958 | final String action = intent.getAction(); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 959 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 960 | hideInputMethodMenu(); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 961 | // No need to update mIsInteractive |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 962 | return; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 963 | } else if (Intent.ACTION_USER_ADDED.equals(action) |
| 964 | || Intent.ACTION_USER_REMOVED.equals(action)) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 965 | updateCurrentProfileIds(); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 966 | return; |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 967 | } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) { |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 968 | onActionLocaleChanged(); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 969 | } else if (ACTION_SHOW_INPUT_METHOD_PICKER.equals(action)) { |
| 970 | // ACTION_SHOW_INPUT_METHOD_PICKER action is a protected-broadcast and it is |
| 971 | // guaranteed to be send only from the system, so that there is no need for extra |
| 972 | // security check such as |
| 973 | // {@link #canShowInputMethodPickerLocked(IInputMethodClient)}. |
| 974 | mHandler.obtainMessage( |
| 975 | MSG_SHOW_IM_SUBTYPE_PICKER, |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 976 | // TODO(b/120076400): Design and implement IME switcher for heterogeneous |
| 977 | // navbar configuration. |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 978 | InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES, |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 979 | DEFAULT_DISPLAY).sendToTarget(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 980 | } else { |
| 981 | Slog.w(TAG, "Unexpected intent " + intent); |
| 982 | } |
| 983 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 985 | |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 986 | /** |
| 987 | * Handles {@link Intent#ACTION_LOCALE_CHANGED}. |
| 988 | * |
| 989 | * <p>Note: For historical reasons, {@link Intent#ACTION_LOCALE_CHANGED} has been sent to all |
| 990 | * the users. We should ignore this event if this is about any background user's locale.</p> |
| 991 | * |
| 992 | * <p>Caution: This method must not be called when system is not ready.</p> |
| 993 | */ |
| 994 | void onActionLocaleChanged() { |
| 995 | synchronized (mMethodMap) { |
| 996 | final LocaleList possibleNewLocale = mRes.getConfiguration().getLocales(); |
| 997 | if (possibleNewLocale != null && possibleNewLocale.equals(mLastSystemLocales)) { |
| 998 | return; |
| 999 | } |
| 1000 | buildInputMethodListLocked(true); |
| 1001 | // If the locale is changed, needs to reset the default ime |
| 1002 | resetDefaultImeLocked(mContext); |
| 1003 | updateFromSettingsLocked(true); |
| 1004 | mLastSystemLocales = possibleNewLocale; |
| 1005 | } |
| 1006 | } |
| 1007 | |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1008 | final class MyPackageMonitor extends PackageMonitor { |
| 1009 | /** |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1010 | * Package names that are known to contain {@link InputMethodService}. |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1011 | * |
| 1012 | * <p>No need to include packages because of direct-boot unaware IMEs since we always rescan |
| 1013 | * all the packages when the user is unlocked, and direct-boot awareness will not be changed |
| 1014 | * dynamically unless the entire package is updated, which also always triggers package |
| 1015 | * rescanning.</p> |
| 1016 | */ |
| 1017 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1018 | final private ArraySet<String> mKnownImePackageNames = new ArraySet<>(); |
| 1019 | |
| 1020 | /** |
| 1021 | * Packages that are appeared, disappeared, or modified for whatever reason. |
| 1022 | * |
| 1023 | * <p>Note: For now we intentionally use {@link ArrayList} instead of {@link ArraySet} |
| 1024 | * because 1) the number of elements is almost always 1 or so, and 2) we do not care |
| 1025 | * duplicate elements for our use case.</p> |
| 1026 | * |
| 1027 | * <p>This object must be accessed only from callback methods in {@link PackageMonitor}, |
| 1028 | * which should be bound to {@link #getRegisteredHandler()}.</p> |
| 1029 | */ |
| 1030 | private final ArrayList<String> mChangedPackages = new ArrayList<>(); |
| 1031 | |
| 1032 | /** |
| 1033 | * {@code true} if one or more packages that contain {@link InputMethodService} appeared. |
| 1034 | * |
| 1035 | * <p>This field must be accessed only from callback methods in {@link PackageMonitor}, |
| 1036 | * which should be bound to {@link #getRegisteredHandler()}.</p> |
| 1037 | */ |
| 1038 | private boolean mImePackageAppeared = false; |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1039 | |
| 1040 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1041 | void clearKnownImePackageNamesLocked() { |
| 1042 | mKnownImePackageNames.clear(); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1046 | final void addKnownImePackageNameLocked(@NonNull String packageName) { |
| 1047 | mKnownImePackageNames.add(packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1048 | } |
| 1049 | |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1050 | @GuardedBy("mMethodMap") |
| 1051 | private boolean isChangingPackagesOfCurrentUserLocked() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1052 | final int userId = getChangingUserId(); |
| 1053 | final boolean retval = userId == mSettings.getCurrentUserId(); |
| 1054 | if (DEBUG) { |
satok | 81f8b7c | 2012-12-04 20:42:56 +0900 | [diff] [blame] | 1055 | if (!retval) { |
| 1056 | Slog.d(TAG, "--- ignore this call back from a background user: " + userId); |
| 1057 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1058 | } |
| 1059 | return retval; |
| 1060 | } |
| 1061 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1063 | public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1064 | synchronized (mMethodMap) { |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1065 | if (!isChangingPackagesOfCurrentUserLocked()) { |
| 1066 | return false; |
| 1067 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1068 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | final int N = mMethodList.size(); |
| 1070 | if (curInputMethodId != null) { |
| 1071 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1072 | InputMethodInfo imi = mMethodList.get(i); |
| 1073 | if (imi.getId().equals(curInputMethodId)) { |
| 1074 | for (String pkg : packages) { |
| 1075 | if (imi.getPackageName().equals(pkg)) { |
| 1076 | if (!doit) { |
| 1077 | return true; |
| 1078 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1079 | resetSelectedInputMethodAndSubtypeLocked(""); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1080 | chooseNewDefaultIMELocked(); |
| 1081 | return true; |
| 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | } |
| 1086 | } |
| 1087 | } |
| 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | @Override |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1092 | public void onBeginPackageChanges() { |
| 1093 | clearPackageChangeState(); |
| 1094 | } |
| 1095 | |
| 1096 | @Override |
| 1097 | public void onPackageAppeared(String packageName, int reason) { |
| 1098 | if (!mImePackageAppeared) { |
| 1099 | final PackageManager pm = mContext.getPackageManager(); |
| 1100 | final List<ResolveInfo> services = pm.queryIntentServicesAsUser( |
| 1101 | new Intent(InputMethod.SERVICE_INTERFACE).setPackage(packageName), |
Yohei Yukawa | 5ec1fce | 2018-12-17 07:56:14 -0800 | [diff] [blame] | 1102 | PackageManager.MATCH_DISABLED_COMPONENTS, getChangingUserId()); |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1103 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1104 | if (!services.isEmpty()) { |
| 1105 | mImePackageAppeared = true; |
| 1106 | } |
| 1107 | } |
| 1108 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1109 | mChangedPackages.add(packageName); |
| 1110 | } |
| 1111 | |
| 1112 | @Override |
| 1113 | public void onPackageDisappeared(String packageName, int reason) { |
| 1114 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1115 | mChangedPackages.add(packageName); |
| 1116 | } |
| 1117 | |
| 1118 | @Override |
| 1119 | public void onPackageModified(String packageName) { |
| 1120 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1121 | mChangedPackages.add(packageName); |
| 1122 | } |
| 1123 | |
| 1124 | @Override |
| 1125 | public void onPackagesSuspended(String[] packages) { |
| 1126 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1127 | for (String packageName : packages) { |
| 1128 | mChangedPackages.add(packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | @Override |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1133 | public void onPackagesUnsuspended(String[] packages) { |
| 1134 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1135 | for (String packageName : packages) { |
| 1136 | mChangedPackages.add(packageName); |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | @Override |
| 1141 | public void onFinishPackageChanges() { |
| 1142 | onFinishPackageChangesInternal(); |
| 1143 | clearPackageChangeState(); |
| 1144 | } |
| 1145 | |
| 1146 | private void clearPackageChangeState() { |
| 1147 | // No need to lock them because we access these fields only on getRegisteredHandler(). |
| 1148 | mChangedPackages.clear(); |
| 1149 | mImePackageAppeared = false; |
| 1150 | } |
| 1151 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1152 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1153 | private boolean shouldRebuildInputMethodListLocked() { |
| 1154 | // This method is guaranteed to be called only by getRegisteredHandler(). |
| 1155 | |
| 1156 | // If there is any new package that contains at least one IME, then rebuilt the list |
| 1157 | // of IMEs. |
| 1158 | if (mImePackageAppeared) { |
| 1159 | return true; |
| 1160 | } |
| 1161 | |
| 1162 | // Otherwise, check if mKnownImePackageNames and mChangedPackages have any intersection. |
| 1163 | // TODO: Consider to create a utility method to do the following test. List.retainAll() |
| 1164 | // is an option, but it may still do some extra operations that we do not need here. |
| 1165 | final int N = mChangedPackages.size(); |
| 1166 | for (int i = 0; i < N; ++i) { |
| 1167 | final String packageName = mChangedPackages.get(i); |
| 1168 | if (mKnownImePackageNames.contains(packageName)) { |
| 1169 | return true; |
| 1170 | } |
| 1171 | } |
| 1172 | return false; |
| 1173 | } |
| 1174 | |
| 1175 | private void onFinishPackageChangesInternal() { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1176 | synchronized (mMethodMap) { |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1177 | if (!isChangingPackagesOfCurrentUserLocked()) { |
| 1178 | return; |
| 1179 | } |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1180 | if (!shouldRebuildInputMethodListLocked()) { |
| 1181 | return; |
| 1182 | } |
| 1183 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1184 | InputMethodInfo curIm = null; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1185 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1186 | final int N = mMethodList.size(); |
| 1187 | if (curInputMethodId != null) { |
| 1188 | for (int i=0; i<N; i++) { |
| 1189 | InputMethodInfo imi = mMethodList.get(i); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1190 | final String imiId = imi.getId(); |
| 1191 | if (imiId.equals(curInputMethodId)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1192 | curIm = imi; |
| 1193 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1194 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1195 | int change = isPackageDisappearing(imi.getPackageName()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1196 | if (isPackageModified(imi.getPackageName())) { |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 1197 | mAdditionalSubtypeMap.remove(imi.getId()); |
| 1198 | AdditionalSubtypeUtils.save(mAdditionalSubtypeMap, mMethodMap, |
| 1199 | mSettings.getCurrentUserId()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1200 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1201 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 1202 | || change == PACKAGE_PERMANENT_CHANGE) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1203 | Slog.i(TAG, "Input method uninstalled, disabling: " |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1204 | + imi.getComponent()); |
| 1205 | setInputMethodEnabledLocked(imi.getId(), false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1209 | |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 1210 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1211 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1213 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1214 | if (curIm != null) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1215 | int change = isPackageDisappearing(curIm.getPackageName()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1216 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 1217 | || change == PACKAGE_PERMANENT_CHANGE) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1218 | ServiceInfo si = null; |
| 1219 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1220 | si = mIPackageManager.getServiceInfo( |
| 1221 | curIm.getComponent(), 0, mSettings.getCurrentUserId()); |
| 1222 | } catch (RemoteException ex) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1223 | } |
| 1224 | if (si == null) { |
| 1225 | // Uh oh, current input method is no longer around! |
| 1226 | // Pick another one... |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1227 | Slog.i(TAG, "Current input method removed: " + curInputMethodId); |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 1228 | updateSystemUiLocked(0 /* vis */, mBackDisposition); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1229 | if (!chooseNewDefaultIMELocked()) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1230 | changed = true; |
| 1231 | curIm = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1232 | Slog.i(TAG, "Unsetting current input method"); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1233 | resetSelectedInputMethodAndSubtypeLocked(""); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1234 | } |
| 1235 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1236 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1237 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1238 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1239 | if (curIm == null) { |
| 1240 | // We currently don't have a default input method... is |
| 1241 | // one now available? |
| 1242 | changed = chooseNewDefaultIMELocked(); |
Yohei Yukawa | 54d512c | 2015-05-19 22:15:02 -0700 | [diff] [blame] | 1243 | } else if (!changed && isPackageModified(curIm.getPackageName())) { |
| 1244 | // Even if the current input method is still available, mCurrentSubtype could |
| 1245 | // be obsolete when the package is modified in practice. |
| 1246 | changed = true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1247 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1248 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1249 | if (changed) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1250 | updateFromSettingsLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | } |
| 1254 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1255 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1256 | private static final class MethodCallback extends IInputSessionCallback.Stub { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 1257 | private final InputMethodManagerService mParentIMMS; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1258 | private final IInputMethod mMethod; |
| 1259 | private final InputChannel mChannel; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1260 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1261 | MethodCallback(InputMethodManagerService imms, IInputMethod method, |
| 1262 | InputChannel channel) { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 1263 | mParentIMMS = imms; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1264 | mMethod = method; |
| 1265 | mChannel = channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1267 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1268 | @Override |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1269 | public void sessionCreated(IInputMethodSession session) { |
Dianne Hackborn | 6b6b3fd | 2014-03-24 11:27:18 -0700 | [diff] [blame] | 1270 | long ident = Binder.clearCallingIdentity(); |
| 1271 | try { |
| 1272 | mParentIMMS.onSessionCreated(mMethod, session, mChannel); |
| 1273 | } finally { |
| 1274 | Binder.restoreCallingIdentity(ident); |
| 1275 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | } |
| 1277 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1278 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1279 | private class HardKeyboardListener |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1280 | implements WindowManagerInternal.OnHardKeyboardStatusChangeListener { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1281 | @Override |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1282 | public void onHardKeyboardStatusChange(boolean available) { |
| 1283 | mHandler.sendMessage(mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED, |
| 1284 | available ? 1 : 0)); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1285 | } |
| 1286 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1287 | public void handleHardKeyboardStatusChange(boolean available) { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1288 | if (DEBUG) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1289 | Slog.w(TAG, "HardKeyboardStatusChanged: available=" + available); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1290 | } |
| 1291 | synchronized(mMethodMap) { |
| 1292 | if (mSwitchingDialog != null && mSwitchingDialogTitleView != null |
| 1293 | && mSwitchingDialog.isShowing()) { |
| 1294 | mSwitchingDialogTitleView.findViewById( |
| 1295 | com.android.internal.R.id.hard_keyboard_section).setVisibility( |
| 1296 | available ? View.VISIBLE : View.GONE); |
| 1297 | } |
| 1298 | } |
| 1299 | } |
| 1300 | } |
| 1301 | |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1302 | public static final class Lifecycle extends SystemService { |
| 1303 | private InputMethodManagerService mService; |
| 1304 | |
| 1305 | public Lifecycle(Context context) { |
| 1306 | super(context); |
| 1307 | mService = new InputMethodManagerService(context); |
| 1308 | } |
| 1309 | |
| 1310 | @Override |
| 1311 | public void onStart() { |
| 1312 | LocalServices.addService(InputMethodManagerInternal.class, |
Yohei Yukawa | fffc0e5 | 2018-09-04 13:24:00 -0700 | [diff] [blame] | 1313 | new LocalServiceImpl(mService)); |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1314 | publishBinderService(Context.INPUT_METHOD_SERVICE, mService); |
| 1315 | } |
| 1316 | |
| 1317 | @Override |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1318 | public void onSwitchUser(@UserIdInt int userHandle) { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1319 | // Called on ActivityManager thread. |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1320 | // TODO: Dispatch this to a worker thread as needed. |
| 1321 | mService.onSwitchUser(userHandle); |
| 1322 | } |
| 1323 | |
| 1324 | @Override |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1325 | public void onBootPhase(int phase) { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1326 | // Called on ActivityManager thread. |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1327 | // TODO: Dispatch this to a worker thread as needed. |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1328 | if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) { |
| 1329 | StatusBarManagerService statusBarService = (StatusBarManagerService) ServiceManager |
| 1330 | .getService(Context.STATUS_BAR_SERVICE); |
| 1331 | mService.systemRunning(statusBarService); |
| 1332 | } |
| 1333 | } |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1334 | |
| 1335 | @Override |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1336 | public void onUnlockUser(final @UserIdInt int userHandle) { |
| 1337 | // Called on ActivityManager thread. |
| 1338 | mService.mHandler.sendMessage(mService.mHandler.obtainMessage(MSG_SYSTEM_UNLOCK_USER, |
Fyodor Kupolov | 0f57cce | 2016-09-09 10:36:30 -0700 | [diff] [blame] | 1339 | userHandle /* arg1 */, 0 /* arg2 */)); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1343 | void onUnlockUser(@UserIdInt int userId) { |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1344 | synchronized(mMethodMap) { |
| 1345 | final int currentUserId = mSettings.getCurrentUserId(); |
| 1346 | if (DEBUG) { |
| 1347 | Slog.d(TAG, "onUnlockUser: userId=" + userId + " curUserId=" + currentUserId); |
| 1348 | } |
| 1349 | if (userId != currentUserId) { |
| 1350 | return; |
| 1351 | } |
| 1352 | mSettings.switchCurrentUser(currentUserId, !mSystemReady); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1353 | if (mSystemReady) { |
| 1354 | // We need to rebuild IMEs. |
| 1355 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
| 1356 | updateInputMethodsFromSettingsLocked(true /* enabledChanged */); |
| 1357 | } |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1358 | } |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1359 | } |
| 1360 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1361 | void onSwitchUser(@UserIdInt int userId) { |
| 1362 | synchronized (mMethodMap) { |
| 1363 | switchUserLocked(userId); |
| 1364 | } |
| 1365 | } |
| 1366 | |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1367 | public InputMethodManagerService(Context context) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1368 | mIPackageManager = AppGlobals.getPackageManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | mContext = context; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1370 | mRes = context.getResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1371 | mHandler = new Handler(this); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1372 | // Note: SettingsObserver doesn't register observers in its constructor. |
| 1373 | mSettingsObserver = new SettingsObserver(mHandler); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1374 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 1375 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1376 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 1377 | final DisplayManagerInternal displayManagerInternal = LocalServices.getService( |
| 1378 | DisplayManagerInternal.class); |
| 1379 | mImeDisplayValidator = (displayId) -> { |
| 1380 | final DisplayInfo displayInfo = displayManagerInternal.getDisplayInfo(displayId); |
| 1381 | return displayInfo != null |
| 1382 | && (displayInfo.flags & Display.FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0; |
| 1383 | }; |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 1384 | mCaller = new HandlerCaller(context, null, new HandlerCaller.Callback() { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1385 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | public void executeMessage(Message msg) { |
| 1387 | handleMessage(msg); |
| 1388 | } |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 1389 | }, true /*asyncHandler*/); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 1390 | mAppOpsManager = mContext.getSystemService(AppOpsManager.class); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1391 | mUserManager = mContext.getSystemService(UserManager.class); |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 1392 | mUserManagerInternal = LocalServices.getService(UserManagerInternal.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1393 | mHardKeyboardListener = new HardKeyboardListener(); |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 1394 | mHasFeature = context.getPackageManager().hasSystemFeature( |
| 1395 | PackageManager.FEATURE_INPUT_METHODS); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 1396 | mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime); |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 1397 | mHardKeyboardBehavior = mContext.getResources().getInteger( |
| 1398 | com.android.internal.R.integer.config_externalHardKeyboardBehavior); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 1399 | mIsLowRam = ActivityManager.isLowRamDeviceStatic(); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1400 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1401 | Bundle extras = new Bundle(); |
| 1402 | extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1403 | @ColorInt final int accentColor = mContext.getColor( |
| 1404 | com.android.internal.R.color.system_notification_accent_color); |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 1405 | mImeSwitcherNotification = |
| 1406 | new Notification.Builder(mContext, SystemNotificationChannels.VIRTUAL_KEYBOARD) |
| 1407 | .setSmallIcon(com.android.internal.R.drawable.ic_notification_ime_default) |
| 1408 | .setWhen(0) |
| 1409 | .setOngoing(true) |
| 1410 | .addExtras(extras) |
| 1411 | .setCategory(Notification.CATEGORY_SYSTEM) |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1412 | .setColor(accentColor); |
Daniel Sandler | 590d515 | 2012-06-14 16:10:13 -0400 | [diff] [blame] | 1413 | |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1414 | Intent intent = new Intent(ACTION_SHOW_INPUT_METHOD_PICKER) |
| 1415 | .setPackage(mContext.getPackageName()); |
satok | 683e238 | 2011-07-12 08:28:52 +0900 | [diff] [blame] | 1416 | mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 1417 | |
| 1418 | mShowOngoingImeSwitcherForPhones = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1419 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1420 | mNotificationShown = false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1421 | int userId = 0; |
| 1422 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1423 | userId = ActivityManager.getService().getCurrentUser().id; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1424 | } catch (RemoteException e) { |
| 1425 | Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e); |
| 1426 | } |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1427 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 1428 | mLastSwitchUserId = userId; |
| 1429 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1430 | // mSettings should be created before buildInputMethodListLocked |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 1431 | mSettings = new InputMethodSettings( |
Yohei Yukawa | f927753 | 2019-01-25 02:47:32 -0800 | [diff] [blame] | 1432 | mRes, context.getContentResolver(), mMethodMap, userId, !mSystemReady); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 1433 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1434 | updateCurrentProfileIds(); |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 1435 | AdditionalSubtypeUtils.load(mAdditionalSubtypeMap, userId); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1436 | mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked( |
| 1437 | mSettings, context); |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1438 | } |
| 1439 | |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1440 | private void resetDefaultImeLocked(Context context) { |
| 1441 | // Do not reset the default (current) IME when it is a 3rd-party IME |
Yohei Yukawa | fd70fe8 | 2018-04-08 12:19:56 -0700 | [diff] [blame] | 1442 | if (mCurMethodId != null && !mMethodMap.get(mCurMethodId).isSystem()) { |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1443 | return; |
| 1444 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1445 | final List<InputMethodInfo> suitableImes = InputMethodUtils.getDefaultEnabledImes( |
Yohei Yukawa | af5cee8 | 2017-01-23 16:17:11 -0800 | [diff] [blame] | 1446 | context, mSettings.getEnabledInputMethodListLocked()); |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1447 | if (suitableImes.isEmpty()) { |
| 1448 | Slog.i(TAG, "No default found"); |
| 1449 | return; |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1450 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1451 | final InputMethodInfo defIm = suitableImes.get(0); |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1452 | if (DEBUG) { |
| 1453 | Slog.i(TAG, "Default found, using " + defIm.getId()); |
| 1454 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1455 | setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false); |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1456 | } |
| 1457 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1458 | @GuardedBy("mMethodMap") |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 1459 | private void switchUserLocked(int newUserId) { |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1460 | if (DEBUG) Slog.d(TAG, "Switching user stage 1/3. newUserId=" + newUserId |
| 1461 | + " currentUserId=" + mSettings.getCurrentUserId()); |
| 1462 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1463 | // ContentObserver should be registered again when the user is changed |
| 1464 | mSettingsObserver.registerContentObserverLocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1465 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1466 | // If the system is not ready or the device is not yed unlocked by the user, then we use |
| 1467 | // copy-on-write settings. |
| 1468 | final boolean useCopyOnWriteSettings = |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 1469 | !mSystemReady || !mUserManagerInternal.isUserUnlockingOrUnlocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1470 | mSettings.switchCurrentUser(newUserId, useCopyOnWriteSettings); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1471 | updateCurrentProfileIds(); |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 1472 | // Additional subtypes should be reset when the user is changed |
| 1473 | AdditionalSubtypeUtils.load(mAdditionalSubtypeMap, newUserId); |
Satoshi Kataoka | 7f7535f | 2013-02-18 12:54:16 +0900 | [diff] [blame] | 1474 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1475 | |
| 1476 | if (DEBUG) Slog.d(TAG, "Switching user stage 2/3. newUserId=" + newUserId |
| 1477 | + " defaultImiId=" + defaultImiId); |
| 1478 | |
Satoshi Kataoka | 7c4a2a1 | 2013-02-25 15:25:43 +0900 | [diff] [blame] | 1479 | // For secondary users, the list of enabled IMEs may not have been updated since the |
| 1480 | // callbacks to PackageMonitor are ignored for the secondary user. Here, defaultImiId may |
| 1481 | // not be empty even if the IME has been uninstalled by the primary user. |
| 1482 | // Even in such cases, IMMS works fine because it will find the most applicable |
| 1483 | // IME for that user. |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1484 | final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId); |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1485 | mLastSystemLocales = mRes.getConfiguration().getLocales(); |
| 1486 | |
| 1487 | // TODO: Is it really possible that switchUserLocked() happens before system ready? |
| 1488 | if (mSystemReady) { |
| 1489 | hideCurrentInputLocked(0, null); |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 1490 | resetCurrentMethodAndClient(UnbindReason.SWITCH_USER); |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1491 | buildInputMethodListLocked(initialUserSwitch); |
| 1492 | if (TextUtils.isEmpty(mSettings.getSelectedInputMethod())) { |
| 1493 | // This is the first time of the user switch and |
| 1494 | // set the current ime to the proper one. |
| 1495 | resetDefaultImeLocked(mContext); |
| 1496 | } |
| 1497 | updateFromSettingsLocked(true); |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1498 | } |
| 1499 | |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1500 | if (initialUserSwitch) { |
Yohei Yukawa | 094c71f | 2015-06-20 00:41:31 -0700 | [diff] [blame] | 1501 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1502 | mSettings.getEnabledInputMethodListLocked(), newUserId, |
| 1503 | mContext.getBasePackageName()); |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1504 | } |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1505 | |
| 1506 | if (DEBUG) Slog.d(TAG, "Switching user stage 3/3. newUserId=" + newUserId |
| 1507 | + " selectedIme=" + mSettings.getSelectedInputMethod()); |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 1508 | |
| 1509 | mLastSwitchUserId = newUserId; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1510 | } |
| 1511 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1512 | void updateCurrentProfileIds() { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 1513 | mSettings.setCurrentProfileIds( |
| 1514 | mUserManager.getProfileIdsWithDisabled(mSettings.getCurrentUserId())); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 1515 | } |
| 1516 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | @Override |
| 1518 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1519 | throws RemoteException { |
| 1520 | try { |
| 1521 | return super.onTransact(code, data, reply, flags); |
| 1522 | } catch (RuntimeException e) { |
| 1523 | // The input method manager only throws security exceptions, so let's |
| 1524 | // log all others. |
| 1525 | if (!(e instanceof SecurityException)) { |
Dianne Hackborn | 164371f | 2013-10-01 19:10:13 -0700 | [diff] [blame] | 1526 | Slog.wtf(TAG, "Input Method Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1527 | } |
| 1528 | throw e; |
| 1529 | } |
| 1530 | } |
| 1531 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 1532 | public void systemRunning(StatusBarManagerService statusBar) { |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1533 | synchronized (mMethodMap) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1534 | if (DEBUG) { |
| 1535 | Slog.d(TAG, "--- systemReady"); |
| 1536 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1537 | if (!mSystemReady) { |
| 1538 | mSystemReady = true; |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1539 | mLastSystemLocales = mRes.getConfiguration().getLocales(); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1540 | final int currentUserId = mSettings.getCurrentUserId(); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1541 | mSettings.switchCurrentUser(currentUserId, |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 1542 | !mUserManagerInternal.isUserUnlockingOrUnlocked(currentUserId)); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 1543 | mKeyguardManager = mContext.getSystemService(KeyguardManager.class); |
| 1544 | mNotificationManager = mContext.getSystemService(NotificationManager.class); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1545 | mStatusBar = statusBar; |
Griff Hazen | 6090c26 | 2016-03-25 08:11:24 -0700 | [diff] [blame] | 1546 | if (mStatusBar != null) { |
| 1547 | mStatusBar.setIconVisibility(mSlotIme, false); |
| 1548 | } |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 1549 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 1550 | mShowOngoingImeSwitcherForPhones = mRes.getBoolean( |
| 1551 | com.android.internal.R.bool.show_ongoing_ime_switcher); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1552 | if (mShowOngoingImeSwitcherForPhones) { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1553 | mWindowManagerInternal.setOnHardKeyboardStatusChangeListener( |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1554 | mHardKeyboardListener); |
| 1555 | } |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1556 | |
| 1557 | mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true); |
| 1558 | mSettingsObserver.registerContentObserverLocked(currentUserId); |
| 1559 | |
| 1560 | final IntentFilter broadcastFilter = new IntentFilter(); |
| 1561 | broadcastFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 1562 | broadcastFilter.addAction(Intent.ACTION_USER_ADDED); |
| 1563 | broadcastFilter.addAction(Intent.ACTION_USER_REMOVED); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1564 | broadcastFilter.addAction(Intent.ACTION_LOCALE_CHANGED); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1565 | broadcastFilter.addAction(ACTION_SHOW_INPUT_METHOD_PICKER); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1566 | mContext.registerReceiver(new ImmsBroadcastReceiver(), broadcastFilter); |
| 1567 | |
Yohei Yukawa | 1f9a3cb | 2017-10-26 15:00:59 -0700 | [diff] [blame] | 1568 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
| 1569 | final boolean imeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId); |
| 1570 | buildInputMethodListLocked(!imeSelectedOnBoot /* resetDefaultEnabledIme */); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1571 | updateFromSettingsLocked(true); |
| 1572 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1573 | mSettings.getEnabledInputMethodListLocked(), currentUserId, |
| 1574 | mContext.getBasePackageName()); |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1575 | } |
| 1576 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1577 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1578 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1579 | // --------------------------------------------------------------------------------------- |
| 1580 | // Check whether or not this is a valid IPC. Assumes an IPC is valid when either |
| 1581 | // 1) it comes from the system process |
| 1582 | // 2) the calling process' user id is identical to the current user id IMMS thinks. |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 1583 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 1584 | private boolean calledFromValidUserLocked() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1585 | final int uid = Binder.getCallingUid(); |
| 1586 | final int userId = UserHandle.getUserId(uid); |
| 1587 | if (DEBUG) { |
| 1588 | Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? " |
| 1589 | + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID |
| 1590 | + " calling userId = " + userId + ", foreground user id = " |
Satoshi Kataoka | 87c2914 | 2013-07-31 23:11:54 +0900 | [diff] [blame] | 1591 | + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid() |
| 1592 | + InputMethodUtils.getApiCallStack()); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1593 | } |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 1594 | if (uid == Process.SYSTEM_UID) { |
| 1595 | return true; |
| 1596 | } |
| 1597 | if (userId == mSettings.getCurrentUserId()) { |
| 1598 | return true; |
| 1599 | } |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 1600 | if (!PER_PROFILE_IME_ENABLED && mSettings.isCurrentProfile(userId)) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1601 | return true; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1602 | } |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1603 | |
| 1604 | // Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the |
| 1605 | // foreground user, not for the user of that process. Accordingly InputMethodManagerService |
| 1606 | // must not manage background users' states in any functions. |
| 1607 | // Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded |
| 1608 | // by a token. |
| 1609 | if (mContext.checkCallingOrSelfPermission( |
| 1610 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
| 1611 | == PackageManager.PERMISSION_GRANTED) { |
| 1612 | if (DEBUG) { |
| 1613 | Slog.d(TAG, "--- Access granted because the calling process has " |
| 1614 | + "the INTERACT_ACROSS_USERS_FULL permission"); |
| 1615 | } |
| 1616 | return true; |
| 1617 | } |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1618 | // TODO(b/34886274): The semantics of this verification is actually not well-defined. |
Seigo Nonaka | e27dc2b | 2015-08-14 18:21:27 -0700 | [diff] [blame] | 1619 | Slog.w(TAG, "--- IPC called from background users. Ignore. callers=" |
| 1620 | + Debug.getCallers(10)); |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1621 | return false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1622 | } |
| 1623 | |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 1624 | |
| 1625 | /** |
| 1626 | * Returns true iff the caller is identified to be the current input method with the token. |
| 1627 | * @param token The window token given to the input method when it was started. |
| 1628 | * @return true if and only if non-null valid token is specified. |
| 1629 | */ |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 1630 | @GuardedBy("mMethodMap") |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 1631 | private boolean calledWithValidTokenLocked(@NonNull IBinder token) { |
| 1632 | if (token == null) { |
| 1633 | throw new InvalidParameterException("token must not be null."); |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1634 | } |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 1635 | if (token != mCurToken) { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1636 | Slog.e(TAG, "Ignoring " + Debug.getCaller() + " due to an invalid token." |
| 1637 | + " uid:" + Binder.getCallingUid() + " token:" + token); |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 1638 | return false; |
| 1639 | } |
| 1640 | return true; |
| 1641 | } |
| 1642 | |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 1643 | @GuardedBy("mMethodMap") |
| 1644 | private boolean bindCurrentInputMethodServiceLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1645 | Intent service, ServiceConnection conn, int flags) { |
| 1646 | if (service == null || conn == null) { |
| 1647 | Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn); |
| 1648 | return false; |
| 1649 | } |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 1650 | return mContext.bindServiceAsUser(service, conn, flags, |
| 1651 | new UserHandle(mSettings.getCurrentUserId())); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1652 | } |
| 1653 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1654 | @Override |
Yohei Yukawa | d20eef8 | 2019-02-05 10:45:32 -0800 | [diff] [blame] | 1655 | public List<InputMethodInfo> getInputMethodList(@UserIdInt int userId) { |
| 1656 | if (UserHandle.getCallingUserId() != userId) { |
| 1657 | mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); |
| 1658 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1659 | synchronized (mMethodMap) { |
Yohei Yukawa | d20eef8 | 2019-02-05 10:45:32 -0800 | [diff] [blame] | 1660 | final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId, |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1661 | mSettings.getCurrentUserId(), null); |
| 1662 | if (resolvedUserIds.length != 1) { |
| 1663 | return Collections.emptyList(); |
| 1664 | } |
| 1665 | final long ident = Binder.clearCallingIdentity(); |
| 1666 | try { |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 1667 | return getInputMethodListLocked(resolvedUserIds[0]); |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1668 | } finally { |
| 1669 | Binder.restoreCallingIdentity(ident); |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 1670 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1671 | } |
| 1672 | } |
| 1673 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1674 | @Override |
Yohei Yukawa | 1fb13c5 | 2019-02-05 07:55:28 -0800 | [diff] [blame] | 1675 | public List<InputMethodInfo> getEnabledInputMethodList(@UserIdInt int userId) { |
| 1676 | if (UserHandle.getCallingUserId() != userId) { |
| 1677 | mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); |
| 1678 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | synchronized (mMethodMap) { |
Yohei Yukawa | 1fb13c5 | 2019-02-05 07:55:28 -0800 | [diff] [blame] | 1680 | final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId, |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1681 | mSettings.getCurrentUserId(), null); |
| 1682 | if (resolvedUserIds.length != 1) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 1683 | return Collections.emptyList(); |
| 1684 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1685 | final long ident = Binder.clearCallingIdentity(); |
| 1686 | try { |
| 1687 | return getEnabledInputMethodListLocked(resolvedUserIds[0]); |
| 1688 | } finally { |
| 1689 | Binder.restoreCallingIdentity(ident); |
| 1690 | } |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 1695 | private List<InputMethodInfo> getInputMethodListLocked(@UserIdInt int userId) { |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1696 | final ArrayList<InputMethodInfo> methodList; |
| 1697 | if (userId == mSettings.getCurrentUserId()) { |
| 1698 | // Create a copy. |
| 1699 | methodList = new ArrayList<>(mMethodList); |
| 1700 | } else { |
| 1701 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 1702 | methodList = new ArrayList<>(); |
| 1703 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 1704 | new ArrayMap<>(); |
| 1705 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 1706 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap, |
| 1707 | methodList); |
| 1708 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1709 | return methodList; |
| 1710 | } |
| 1711 | |
| 1712 | @GuardedBy("mMethodMap") |
| 1713 | private List<InputMethodInfo> getEnabledInputMethodListLocked(@UserIdInt int userId) { |
| 1714 | if (userId == mSettings.getCurrentUserId()) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1715 | return mSettings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1717 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 1718 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 1719 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 1720 | new ArrayMap<>(); |
| 1721 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 1722 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap, |
| 1723 | methodList); |
| 1724 | final InputMethodSettings settings = new InputMethodSettings(mContext.getResources(), |
Yohei Yukawa | f927753 | 2019-01-25 02:47:32 -0800 | [diff] [blame] | 1725 | mContext.getContentResolver(), methodMap, userId, true); |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1726 | return settings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1727 | } |
| 1728 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1729 | /** |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1730 | * @param imiId if null, returns enabled subtypes for the current imi |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1731 | * @return enabled subtypes of the specified imi |
| 1732 | */ |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1733 | @Override |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1734 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId, |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 1735 | boolean allowsImplicitlySelectedSubtypes) { |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1736 | final int callingUserId = UserHandle.getCallingUserId(); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1737 | synchronized (mMethodMap) { |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1738 | final int[] resolvedUserIds = InputMethodUtils.resolveUserId(callingUserId, |
| 1739 | mSettings.getCurrentUserId(), null); |
| 1740 | if (resolvedUserIds.length != 1) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 1741 | return Collections.emptyList(); |
| 1742 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1743 | final long ident = Binder.clearCallingIdentity(); |
| 1744 | try { |
| 1745 | return getEnabledInputMethodSubtypeListLocked(imiId, |
| 1746 | allowsImplicitlySelectedSubtypes, resolvedUserIds[0]); |
| 1747 | } finally { |
| 1748 | Binder.restoreCallingIdentity(ident); |
| 1749 | } |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | @GuardedBy("mMethodMap") |
| 1754 | private List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(String imiId, |
| 1755 | boolean allowsImplicitlySelectedSubtypes, @UserIdInt int userId) { |
| 1756 | if (userId == mSettings.getCurrentUserId()) { |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1757 | final InputMethodInfo imi; |
| 1758 | if (imiId == null && mCurMethodId != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1759 | imi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1760 | } else { |
| 1761 | imi = mMethodMap.get(imiId); |
| 1762 | } |
| 1763 | if (imi == null) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 1764 | return Collections.emptyList(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1765 | } |
| 1766 | return mSettings.getEnabledInputMethodSubtypeListLocked( |
| 1767 | mContext, imi, allowsImplicitlySelectedSubtypes); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1768 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1769 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 1770 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 1771 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 1772 | new ArrayMap<>(); |
| 1773 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 1774 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap, |
| 1775 | methodList); |
| 1776 | final InputMethodInfo imi = methodMap.get(imiId); |
| 1777 | if (imi == null) { |
| 1778 | return Collections.emptyList(); |
| 1779 | } |
| 1780 | final InputMethodSettings settings = new InputMethodSettings(mContext.getResources(), |
Yohei Yukawa | f927753 | 2019-01-25 02:47:32 -0800 | [diff] [blame] | 1781 | mContext.getContentResolver(), methodMap, userId, true); |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1782 | return settings.getEnabledInputMethodSubtypeListLocked( |
| 1783 | mContext, imi, allowsImplicitlySelectedSubtypes); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1784 | } |
| 1785 | |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1786 | /** |
| 1787 | * Called by each application process as a preparation to start interacting with |
| 1788 | * {@link InputMethodManagerService}. |
| 1789 | * |
| 1790 | * <p>As a general principle, IPCs from the application process that take |
Yohei Yukawa | 499e3f7 | 2018-10-21 20:15:11 -0700 | [diff] [blame] | 1791 | * {@link IInputMethodClient} will be rejected without this step.</p> |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1792 | * |
| 1793 | * @param client {@link android.os.Binder} proxy that is associated with the singleton instance |
| 1794 | * of {@link android.view.inputmethod.InputMethodManager} that runs on the client |
| 1795 | * process |
| 1796 | * @param inputContext communication channel for the dummy |
| 1797 | * {@link android.view.inputmethod.InputConnection} |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1798 | * @param selfReportedDisplayId self-reported display ID to which the client is associated. |
| 1799 | * Whether the client is still allowed to access to this display |
| 1800 | * or not needs to be evaluated every time the client interacts |
| 1801 | * with the display |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1802 | */ |
| 1803 | @Override |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1804 | public void addClient(IInputMethodClient client, IInputContext inputContext, |
| 1805 | int selfReportedDisplayId) { |
Yohei Yukawa | cb768bc | 2018-10-24 16:05:09 -0700 | [diff] [blame] | 1806 | // Here there are two scenarios where this method is called: |
| 1807 | // A. IMM is being instantiated in a different process and this is an IPC from that process |
| 1808 | // B. IMM is being instantiated in the same process but Binder.clearCallingIdentity() is |
| 1809 | // called in the caller side if necessary. |
| 1810 | // In either case the following UID/PID should be the ones where InputMethodManager is |
| 1811 | // actually running. |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1812 | final int callerUid = Binder.getCallingUid(); |
| 1813 | final int callerPid = Binder.getCallingPid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1814 | synchronized (mMethodMap) { |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1815 | // TODO: Optimize this linear search. |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 1816 | final int numClients = mClients.size(); |
| 1817 | for (int i = 0; i < numClients; ++i) { |
| 1818 | final ClientState state = mClients.valueAt(i); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1819 | if (state.uid == callerUid && state.pid == callerPid |
| 1820 | && state.selfReportedDisplayId == selfReportedDisplayId) { |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1821 | throw new SecurityException("uid=" + callerUid + "/pid=" + callerPid |
Yohei Yukawa | cb768bc | 2018-10-24 16:05:09 -0700 | [diff] [blame] | 1822 | + "/displayId=" + selfReportedDisplayId + " is already registered."); |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1823 | } |
| 1824 | } |
| 1825 | final ClientDeathRecipient deathRecipient = new ClientDeathRecipient(this, client); |
| 1826 | try { |
| 1827 | client.asBinder().linkToDeath(deathRecipient, 0); |
| 1828 | } catch (RemoteException e) { |
| 1829 | throw new IllegalStateException(e); |
| 1830 | } |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1831 | // We cannot fully avoid race conditions where the client UID already lost the access to |
| 1832 | // the given self-reported display ID, even if the client is not maliciously reporting |
| 1833 | // a fake display ID. Unconditionally returning SecurityException just because the |
| 1834 | // client doesn't pass display ID verification can cause many test failures hence not an |
| 1835 | // option right now. At the same time |
| 1836 | // context.getSystemService(InputMethodManager.class) |
| 1837 | // is expected to return a valid non-null instance at any time if we do not choose to |
| 1838 | // have the client crash. Thus we do not verify the display ID at all here. Instead we |
| 1839 | // later check the display ID every time the client needs to interact with the specified |
| 1840 | // display. |
| 1841 | mClients.put(client.asBinder(), new ClientState(client, inputContext, callerUid, |
| 1842 | callerPid, selfReportedDisplayId, deathRecipient)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1843 | } |
| 1844 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1845 | |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 1846 | void removeClient(IInputMethodClient client) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1847 | synchronized (mMethodMap) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1848 | ClientState cs = mClients.remove(client.asBinder()); |
| 1849 | if (cs != null) { |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1850 | client.asBinder().unlinkToDeath(cs.clientDeathRecipient, 0); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1851 | clearClientSessionLocked(cs); |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 1852 | if (mCurClient == cs) { |
Tarandeep Singh | 93c00cea | 2018-02-16 14:31:17 -0800 | [diff] [blame] | 1853 | if (mBoundToMethod) { |
| 1854 | mBoundToMethod = false; |
| 1855 | if (mCurMethod != null) { |
| 1856 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 1857 | MSG_UNBIND_INPUT, mCurMethod)); |
| 1858 | } |
| 1859 | } |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 1860 | mCurClient = null; |
| 1861 | } |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 1862 | if (mCurFocusedWindowClient == cs) { |
| 1863 | mCurFocusedWindowClient = null; |
| 1864 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1865 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1866 | } |
| 1867 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1868 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1869 | void executeOrSendMessage(IInterface target, Message msg) { |
| 1870 | if (target.asBinder() instanceof Binder) { |
| 1871 | mCaller.sendMessage(msg); |
| 1872 | } else { |
| 1873 | handleMessage(msg); |
| 1874 | msg.recycle(); |
| 1875 | } |
| 1876 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1877 | |
Yohei Yukawa | 4afd933 | 2018-10-21 10:43:53 -0700 | [diff] [blame] | 1878 | void unbindCurrentClientLocked(@UnbindReason int unbindClientReason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | if (mCurClient != null) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1880 | if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1881 | + mCurClient.client.asBinder()); |
| 1882 | if (mBoundToMethod) { |
| 1883 | mBoundToMethod = false; |
| 1884 | if (mCurMethod != null) { |
| 1885 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 1886 | MSG_UNBIND_INPUT, mCurMethod)); |
| 1887 | } |
| 1888 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 1889 | |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 1890 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 1891 | MSG_SET_ACTIVE, 0, 0, mCurClient)); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 1892 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 1893 | MSG_UNBIND_CLIENT, mCurSeq, unbindClientReason, mCurClient.client)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1894 | mCurClient.sessionRequested = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1895 | mCurClient = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1896 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1897 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1898 | } |
| 1899 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1900 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1901 | private int getImeShowFlags() { |
| 1902 | int flags = 0; |
| 1903 | if (mShowForced) { |
| 1904 | flags |= InputMethod.SHOW_FORCED |
| 1905 | | InputMethod.SHOW_EXPLICIT; |
| 1906 | } else if (mShowExplicitlyRequested) { |
| 1907 | flags |= InputMethod.SHOW_EXPLICIT; |
| 1908 | } |
| 1909 | return flags; |
| 1910 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | private int getAppShowFlags() { |
| 1913 | int flags = 0; |
| 1914 | if (mShowForced) { |
| 1915 | flags |= InputMethodManager.SHOW_FORCED; |
| 1916 | } else if (!mShowExplicitlyRequested) { |
| 1917 | flags |= InputMethodManager.SHOW_IMPLICIT; |
| 1918 | } |
| 1919 | return flags; |
| 1920 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1921 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1922 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1923 | @NonNull |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 1924 | InputBindResult attachNewInputLocked(@StartInputReason int startInputReason, boolean initial) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1925 | if (!mBoundToMethod) { |
| 1926 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 1927 | MSG_BIND_INPUT, mCurMethod, mCurClient.binding)); |
| 1928 | mBoundToMethod = true; |
| 1929 | } |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1930 | |
| 1931 | final Binder startInputToken = new Binder(); |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 1932 | final StartInputInfo info = new StartInputInfo(mSettings.getCurrentUserId(), mCurToken, |
| 1933 | mCurTokenDisplayId, mCurId, startInputReason, !initial, |
| 1934 | UserHandle.getUserId(mCurClient.uid), mCurClient.selfReportedDisplayId, |
| 1935 | mCurFocusedWindow, mCurAttribute, mCurFocusedWindowSoftInputMode, mCurSeq); |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 1936 | mImeTargetWindowMap.put(startInputToken, mCurFocusedWindow); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 1937 | mStartInputHistory.addEntry(info); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1939 | final SessionState session = mCurClient.curSession; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1940 | executeOrSendMessage(session.method, mCaller.obtainMessageIIOOOO( |
Yohei Yukawa | f7526b5 | 2017-02-11 20:57:10 -0800 | [diff] [blame] | 1941 | MSG_START_INPUT, mCurInputContextMissingMethods, initial ? 0 : 1 /* restarting */, |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 1942 | startInputToken, session, mCurInputContext, mCurAttribute)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1943 | if (mShowRequested) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1944 | 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] | 1945 | showCurrentInputLocked(getAppShowFlags(), null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1946 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1947 | return new InputBindResult(InputBindResult.ResultCode.SUCCESS_WITH_IME_SESSION, |
| 1948 | session.session, (session.channel != null ? session.channel.dup() : null), |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 1949 | mCurId, mCurSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1950 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1951 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1952 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1953 | @NonNull |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1954 | InputBindResult startInputUncheckedLocked(@NonNull ClientState cs, IInputContext inputContext, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1955 | @MissingMethodFlags int missingMethods, @NonNull EditorInfo attribute, |
| 1956 | @StartInputFlags int startInputFlags, @StartInputReason int startInputReason) { |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1957 | // If no method is currently selected, do nothing. |
| 1958 | if (mCurMethodId == null) { |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1959 | return InputBindResult.NO_IME; |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1960 | } |
| 1961 | |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 1962 | if (!mSystemReady) { |
| 1963 | // If the system is not yet ready, we shouldn't be running third |
| 1964 | // party code. |
| 1965 | return new InputBindResult( |
| 1966 | InputBindResult.ResultCode.ERROR_SYSTEM_NOT_READY, |
| 1967 | null, null, mCurMethodId, mCurSeq); |
| 1968 | } |
| 1969 | |
Yohei Yukawa | d57ba67 | 2015-06-08 16:39:46 -0700 | [diff] [blame] | 1970 | if (!InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, cs.uid, |
| 1971 | attribute.packageName)) { |
| 1972 | Slog.e(TAG, "Rejecting this client as it reported an invalid package name." |
| 1973 | + " uid=" + cs.uid + " package=" + attribute.packageName); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1974 | return InputBindResult.INVALID_PACKAGE_NAME; |
Yohei Yukaw | a0f3ad1 | 2015-04-06 16:48:24 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 1977 | if (!mWindowManagerInternal.isUidAllowedOnDisplay(cs.selfReportedDisplayId, cs.uid)) { |
| 1978 | // Wait, the client no longer has access to the display. |
| 1979 | return InputBindResult.INVALID_DISPLAY_ID; |
| 1980 | } |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 1981 | // Compute the final shown display ID with validated cs.selfReportedDisplayId for this |
| 1982 | // session & other conditions. |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 1983 | final int displayIdToShowIme = computeImeDisplayIdForTarget(cs.selfReportedDisplayId, |
| 1984 | mImeDisplayValidator); |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 1985 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | if (mCurClient != cs) { |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 1987 | // Was the keyguard locked when switching over to the new client? |
| 1988 | mCurClientInKeyguard = isKeyguardLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1989 | // If the client is changing, we need to switch over to the new |
| 1990 | // one. |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 1991 | unbindCurrentClientLocked(UnbindReason.SWITCH_CLIENT); |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1992 | if (DEBUG) Slog.v(TAG, "switching to client: client=" |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 1993 | + cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1994 | |
| 1995 | // If the screen is on, inform the new client it is active |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 1996 | if (mIsInteractive) { |
tiansiming [田思明] | e102c97 | 2018-04-17 18:15:33 +0800 | [diff] [blame] | 1997 | executeOrSendMessage(cs.client, mCaller.obtainMessageIO(MSG_SET_ACTIVE, 1, cs)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1998 | } |
| 1999 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | // Bump up the sequence for this client and attach it. |
| 2002 | mCurSeq++; |
| 2003 | if (mCurSeq <= 0) mCurSeq = 1; |
| 2004 | mCurClient = cs; |
| 2005 | mCurInputContext = inputContext; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2006 | mCurInputContextMissingMethods = missingMethods; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2007 | mCurAttribute = attribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2008 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2009 | // Check if the input method is changing. |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2010 | // We expect the caller has already verified that the client is allowed to access this |
| 2011 | // display ID. |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2012 | if (mCurId != null && mCurId.equals(mCurMethodId) |
| 2013 | && displayIdToShowIme == mCurTokenDisplayId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2014 | if (cs.curSession != null) { |
| 2015 | // Fast case: if we are already connected to the input method, |
| 2016 | // then just return it. |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2017 | return attachNewInputLocked(startInputReason, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 2018 | (startInputFlags & StartInputFlags.INITIAL_CONNECTION) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2019 | } |
| 2020 | if (mHaveConnection) { |
| 2021 | if (mCurMethod != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2022 | // Return to client, and we will get back with it when |
| 2023 | // we have had a session made for it. |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2024 | requestClientSessionLocked(cs); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2025 | return new InputBindResult( |
| 2026 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_SESSION, |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 2027 | null, null, mCurId, mCurSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2028 | } else if (SystemClock.uptimeMillis() |
| 2029 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 2030 | // In this case we have connected to the service, but |
| 2031 | // don't yet have its interface. If it hasn't been too |
| 2032 | // long since we did the connection, we'll return to |
| 2033 | // the client and wait to get the service interface so |
| 2034 | // we can report back. If it has been too long, we want |
| 2035 | // to fall through so we can try a disconnect/reconnect |
| 2036 | // to see if we can get back in touch with the service. |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2037 | return new InputBindResult( |
| 2038 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING, |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 2039 | null, null, mCurId, mCurSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2040 | } else { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2041 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, |
| 2042 | mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2043 | } |
| 2044 | } |
| 2045 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2047 | InputMethodInfo info = mMethodMap.get(mCurMethodId); |
| 2048 | if (info == null) { |
| 2049 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 2050 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2051 | |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2052 | unbindCurrentMethodLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2053 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2054 | mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE); |
| 2055 | mCurIntent.setComponent(info.getComponent()); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2056 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 2057 | com.android.internal.R.string.input_method_binding_label); |
| 2058 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 2059 | mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0)); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2060 | |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 2061 | if (bindCurrentInputMethodServiceLocked(mCurIntent, this, IME_CONNECTION_BIND_FLAGS)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2062 | mLastBindTime = SystemClock.uptimeMillis(); |
| 2063 | mHaveConnection = true; |
| 2064 | mCurId = info.getId(); |
| 2065 | mCurToken = new Binder(); |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2066 | mCurTokenDisplayId = displayIdToShowIme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2067 | try { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2068 | if (DEBUG) { |
| 2069 | Slog.v(TAG, "Adding window token: " + mCurToken + " for display: " |
| 2070 | + mCurTokenDisplayId); |
| 2071 | } |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 2072 | mIWindowManager.addWindowToken(mCurToken, LayoutParams.TYPE_INPUT_METHOD, |
| 2073 | mCurTokenDisplayId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | } catch (RemoteException e) { |
| 2075 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2076 | return new InputBindResult( |
| 2077 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING, |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 2078 | null, null, mCurId, mCurSeq); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2079 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2080 | mCurIntent = null; |
| 2081 | Slog.w(TAG, "Failure connecting to input method service: " + mCurIntent); |
| 2082 | return InputBindResult.IME_NOT_CONNECTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2084 | |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2085 | @FunctionalInterface |
| 2086 | interface ImeDisplayValidator { |
| 2087 | boolean displayCanShowIme(int displayId); |
| 2088 | } |
| 2089 | |
| 2090 | /** |
| 2091 | * Find the display where the IME should be shown. |
| 2092 | * |
| 2093 | * @param displayId the ID of the display where the IME client target is. |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2094 | * @param checker instance of {@link ImeDisplayValidator} which is used for |
| 2095 | * checking display config to adjust the final target display. |
| 2096 | * @return The ID of the display where the IME should be shown. |
| 2097 | */ |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 2098 | static int computeImeDisplayIdForTarget(int displayId, @NonNull ImeDisplayValidator checker) { |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2099 | if (displayId == DEFAULT_DISPLAY || displayId == INVALID_DISPLAY) { |
| 2100 | // We always assume that the default display id suitable to show the IME window. |
| 2101 | return DEFAULT_DISPLAY; |
| 2102 | } |
| 2103 | // Show IME in default display when the display with IME target doesn't support system |
| 2104 | // decorations. |
| 2105 | return checker.displayCanShowIme(displayId) ? displayId : DEFAULT_DISPLAY; |
| 2106 | } |
| 2107 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2108 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 2110 | synchronized (mMethodMap) { |
| 2111 | if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { |
| 2112 | mCurMethod = IInputMethod.Stub.asInterface(service); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2113 | if (mCurToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2114 | Slog.w(TAG, "Service connected without a token!"); |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2115 | unbindCurrentMethodLocked(); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2116 | return; |
| 2117 | } |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2118 | if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2119 | // Dispatch display id for InputMethodService to update context display. |
| 2120 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 2121 | MSG_INITIALIZE_IME, mCurTokenDisplayId, mCurMethod, mCurToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2122 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2123 | clearClientSessionLocked(mCurClient); |
| 2124 | requestClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2125 | } |
| 2126 | } |
| 2127 | } |
| 2128 | } |
| 2129 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2130 | void onSessionCreated(IInputMethod method, IInputMethodSession session, |
| 2131 | InputChannel channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2132 | synchronized (mMethodMap) { |
| 2133 | if (mCurMethod != null && method != null |
| 2134 | && mCurMethod.asBinder() == method.asBinder()) { |
| 2135 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2136 | clearClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2137 | mCurClient.curSession = new SessionState(mCurClient, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2138 | method, session, channel); |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2139 | InputBindResult res = attachNewInputLocked( |
Yohei Yukawa | 4219422 | 2018-10-21 20:14:40 -0700 | [diff] [blame] | 2140 | StartInputReason.SESSION_CREATED_BY_IME, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2141 | if (res.method != null) { |
| 2142 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2143 | MSG_BIND_CLIENT, mCurClient.client, res)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2144 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2145 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2146 | } |
| 2147 | } |
| 2148 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2149 | |
| 2150 | // Session abandoned. Close its associated input channel. |
| 2151 | channel.dispose(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2152 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2153 | |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2154 | void unbindCurrentMethodLocked() { |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2155 | if (mVisibleBound) { |
| 2156 | mContext.unbindService(mVisibleConnection); |
| 2157 | mVisibleBound = false; |
| 2158 | } |
| 2159 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2160 | if (mHaveConnection) { |
| 2161 | mContext.unbindService(this); |
| 2162 | mHaveConnection = false; |
| 2163 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2164 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2165 | if (mCurToken != null) { |
| 2166 | try { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2167 | if (DEBUG) { |
| 2168 | Slog.v(TAG, "Removing window token: " + mCurToken + " for display: " |
| 2169 | + mCurTokenDisplayId); |
| 2170 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2171 | mIWindowManager.removeWindowToken(mCurToken, mCurTokenDisplayId); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2172 | } catch (RemoteException e) { |
| 2173 | } |
| 2174 | mCurToken = null; |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2175 | mCurTokenDisplayId = INVALID_DISPLAY; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2176 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2177 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2178 | mCurId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2179 | clearCurMethodLocked(); |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 2180 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2181 | |
Yohei Yukawa | 4afd933 | 2018-10-21 10:43:53 -0700 | [diff] [blame] | 2182 | void resetCurrentMethodAndClient(@UnbindReason int unbindClientReason) { |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 2183 | mCurMethodId = null; |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2184 | unbindCurrentMethodLocked(); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2185 | unbindCurrentClientLocked(unbindClientReason); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2186 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2187 | |
| 2188 | void requestClientSessionLocked(ClientState cs) { |
| 2189 | if (!cs.sessionRequested) { |
| 2190 | if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs); |
| 2191 | InputChannel[] channels = InputChannel.openInputChannelPair(cs.toString()); |
| 2192 | cs.sessionRequested = true; |
| 2193 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOOO( |
| 2194 | MSG_CREATE_SESSION, mCurMethod, channels[1], |
| 2195 | new MethodCallback(this, mCurMethod, channels[0]))); |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | void clearClientSessionLocked(ClientState cs) { |
| 2200 | finishSessionLocked(cs.curSession); |
| 2201 | cs.curSession = null; |
| 2202 | cs.sessionRequested = false; |
| 2203 | } |
| 2204 | |
| 2205 | private void finishSessionLocked(SessionState sessionState) { |
| 2206 | if (sessionState != null) { |
| 2207 | if (sessionState.session != null) { |
| 2208 | try { |
| 2209 | sessionState.session.finishSession(); |
| 2210 | } catch (RemoteException e) { |
| 2211 | Slog.w(TAG, "Session failed to close due to remote exception", e); |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2212 | updateSystemUiLocked(0 /* vis */, mBackDisposition); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2213 | } |
| 2214 | sessionState.session = null; |
| 2215 | } |
| 2216 | if (sessionState.channel != null) { |
| 2217 | sessionState.channel.dispose(); |
| 2218 | sessionState.channel = null; |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2219 | } |
| 2220 | } |
| 2221 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2222 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2223 | void clearCurMethodLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2224 | if (mCurMethod != null) { |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 2225 | final int numClients = mClients.size(); |
| 2226 | for (int i = 0; i < numClients; ++i) { |
| 2227 | clearClientSessionLocked(mClients.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2228 | } |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2229 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2230 | finishSessionLocked(mEnabledSession); |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2231 | mEnabledSession = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2232 | mCurMethod = null; |
| 2233 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2234 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2235 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2236 | } |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 2237 | mInFullscreenMode = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2238 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2239 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2240 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2241 | public void onServiceDisconnected(ComponentName name) { |
Yohei Yukawa | 817d5f7 | 2017-01-04 20:15:02 -0800 | [diff] [blame] | 2242 | // Note that mContext.unbindService(this) does not trigger this. Hence if we are here the |
| 2243 | // disconnection is not intended by IMMS (e.g. triggered because the current IMS crashed), |
| 2244 | // which is irregular but can eventually happen for everyone just by continuing using the |
| 2245 | // device. Thus it is important to make sure that all the internal states are properly |
| 2246 | // refreshed when this method is called back. Running |
| 2247 | // adb install -r <APK that implements the current IME> |
| 2248 | // would be a good way to trigger such a situation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2249 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2250 | if (DEBUG) Slog.v(TAG, "Service disconnected: " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2251 | + " mCurIntent=" + mCurIntent); |
| 2252 | if (mCurMethod != null && mCurIntent != null |
| 2253 | && name.equals(mCurIntent.getComponent())) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2254 | clearCurMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2255 | // We consider this to be a new bind attempt, since the system |
| 2256 | // should now try to restart the service for us. |
| 2257 | mLastBindTime = SystemClock.uptimeMillis(); |
| 2258 | mShowRequested = mInputShown; |
| 2259 | mInputShown = false; |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 2260 | unbindCurrentClientLocked(UnbindReason.DISCONNECT_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2261 | } |
| 2262 | } |
| 2263 | } |
| 2264 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 2265 | @BinderThread |
Yohei Yukawa | 41b094f | 2018-09-09 23:58:45 -0700 | [diff] [blame] | 2266 | private void updateStatusIcon(@NonNull IBinder token, String packageName, |
| 2267 | @DrawableRes int iconId) { |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2268 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 2269 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2270 | return; |
| 2271 | } |
| 2272 | final long ident = Binder.clearCallingIdentity(); |
| 2273 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2274 | if (iconId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2275 | 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] | 2276 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2277 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2278 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2279 | } else if (packageName != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2280 | 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] | 2281 | CharSequence contentDescription = null; |
| 2282 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2283 | // Use PackageManager to load label |
| 2284 | final PackageManager packageManager = mContext.getPackageManager(); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 2285 | contentDescription = packageManager.getApplicationLabel( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2286 | mIPackageManager.getApplicationInfo(packageName, 0, |
| 2287 | mSettings.getCurrentUserId())); |
| 2288 | } catch (RemoteException e) { |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 2289 | /* ignore */ |
| 2290 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2291 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2292 | mStatusBar.setIcon(mSlotIme, packageName, iconId, 0, |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2293 | contentDescription != null |
| 2294 | ? contentDescription.toString() : null); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2295 | mStatusBar.setIconVisibility(mSlotIme, true); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2296 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2297 | } |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2298 | } finally { |
| 2299 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2300 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2301 | } |
| 2302 | } |
| 2303 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2304 | private boolean shouldShowImeSwitcherLocked(int visibility) { |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2305 | if (!mShowOngoingImeSwitcherForPhones) return false; |
Jason Monk | 807ef76 | 2014-05-08 15:47:46 -0400 | [diff] [blame] | 2306 | if (mSwitchingDialog != null) return false; |
Yohei Yukawa | d2bc309 | 2017-07-31 15:37:14 -0700 | [diff] [blame] | 2307 | if (mWindowManagerInternal.isKeyguardShowingAndNotOccluded() |
| 2308 | && mKeyguardManager != null && mKeyguardManager.isKeyguardSecure()) return false; |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 2309 | if ((visibility & InputMethodService.IME_ACTIVE) == 0 |
| 2310 | || (visibility & InputMethodService.IME_INVISIBLE) != 0) { |
| 2311 | return false; |
| 2312 | } |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2313 | if (mWindowManagerInternal.isHardKeyboardAvailable()) { |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 2314 | if (mHardKeyboardBehavior == HardKeyboardBehavior.WIRELESS_AFFORDANCE) { |
| 2315 | // When physical keyboard is attached, we show the ime switcher (or notification if |
| 2316 | // NavBar is not available) because SHOW_IME_WITH_HARD_KEYBOARD settings currently |
| 2317 | // exists in the IME switcher dialog. Might be OK to remove this condition once |
| 2318 | // SHOW_IME_WITH_HARD_KEYBOARD settings finds a good place to live. |
| 2319 | return true; |
| 2320 | } |
Yohei Yukawa | 8939838 | 2016-03-29 11:37:04 -0700 | [diff] [blame] | 2321 | } else if ((visibility & InputMethodService.IME_VISIBLE) == 0) { |
| 2322 | return false; |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2323 | } |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2324 | |
| 2325 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 2326 | final int N = imis.size(); |
| 2327 | if (N > 2) return true; |
| 2328 | if (N < 1) return false; |
| 2329 | int nonAuxCount = 0; |
| 2330 | int auxCount = 0; |
| 2331 | InputMethodSubtype nonAuxSubtype = null; |
| 2332 | InputMethodSubtype auxSubtype = null; |
| 2333 | for(int i = 0; i < N; ++i) { |
| 2334 | final InputMethodInfo imi = imis.get(i); |
| 2335 | final List<InputMethodSubtype> subtypes = |
| 2336 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
| 2337 | final int subtypeCount = subtypes.size(); |
| 2338 | if (subtypeCount == 0) { |
| 2339 | ++nonAuxCount; |
| 2340 | } else { |
| 2341 | for (int j = 0; j < subtypeCount; ++j) { |
| 2342 | final InputMethodSubtype subtype = subtypes.get(j); |
| 2343 | if (!subtype.isAuxiliary()) { |
| 2344 | ++nonAuxCount; |
| 2345 | nonAuxSubtype = subtype; |
| 2346 | } else { |
| 2347 | ++auxCount; |
| 2348 | auxSubtype = subtype; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2349 | } |
| 2350 | } |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2351 | } |
| 2352 | } |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2353 | if (nonAuxCount > 1 || auxCount > 1) { |
| 2354 | return true; |
| 2355 | } else if (nonAuxCount == 1 && auxCount == 1) { |
| 2356 | if (nonAuxSubtype != null && auxSubtype != null |
| 2357 | && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale()) |
| 2358 | || auxSubtype.overridesImplicitlyEnabledSubtype() |
| 2359 | || nonAuxSubtype.overridesImplicitlyEnabledSubtype()) |
| 2360 | && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) { |
| 2361 | return false; |
| 2362 | } |
| 2363 | return true; |
| 2364 | } |
| 2365 | return false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2366 | } |
| 2367 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 2368 | private boolean isKeyguardLocked() { |
| 2369 | return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked(); |
| 2370 | } |
| 2371 | |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2372 | @BinderThread |
satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 2373 | @SuppressWarnings("deprecation") |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 2374 | private void setImeWindowStatus(@NonNull IBinder token, int vis, int backDisposition) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2375 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 2376 | if (!calledWithValidTokenLocked(token)) { |
| 2377 | return; |
| 2378 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2379 | mImeWindowVis = vis; |
| 2380 | mBackDisposition = backDisposition; |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2381 | updateSystemUiLocked(vis, backDisposition); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2382 | } |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2383 | |
| 2384 | final boolean dismissImeOnBackKeyPressed; |
| 2385 | switch (backDisposition) { |
| 2386 | case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: |
| 2387 | dismissImeOnBackKeyPressed = true; |
| 2388 | break; |
| 2389 | case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: |
| 2390 | dismissImeOnBackKeyPressed = false; |
| 2391 | break; |
| 2392 | default: |
| 2393 | case InputMethodService.BACK_DISPOSITION_DEFAULT: |
| 2394 | dismissImeOnBackKeyPressed = ((vis & InputMethodService.IME_VISIBLE) != 0); |
| 2395 | break; |
| 2396 | } |
Yohei Yukawa | ee2a7ed | 2017-02-15 21:38:57 -0800 | [diff] [blame] | 2397 | mWindowManagerInternal.updateInputMethodWindowStatus(token, |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2398 | (vis & InputMethodService.IME_VISIBLE) != 0, dismissImeOnBackKeyPressed); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2399 | } |
| 2400 | |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2401 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 2402 | private void reportStartInput(@NonNull IBinder token, IBinder startInputToken) { |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2403 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 2404 | if (!calledWithValidTokenLocked(token)) { |
| 2405 | return; |
| 2406 | } |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2407 | final IBinder targetWindow = mImeTargetWindowMap.get(startInputToken); |
| 2408 | if (targetWindow != null && mLastImeTargetWindow != targetWindow) { |
| 2409 | mWindowManagerInternal.updateInputMethodTargetWindow(token, targetWindow); |
| 2410 | } |
| 2411 | mLastImeTargetWindow = targetWindow; |
| 2412 | } |
| 2413 | } |
| 2414 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2415 | // Caution! This method is called in this class. Handle multi-user carefully |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2416 | private void updateSystemUiLocked(int vis, int backDisposition) { |
| 2417 | if (mCurToken == null) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2418 | return; |
| 2419 | } |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 2420 | if (DEBUG) { |
| 2421 | Slog.d(TAG, "IME window vis: " + vis |
| 2422 | + " active: " + (vis & InputMethodService.IME_ACTIVE) |
| 2423 | + " inv: " + (vis & InputMethodService.IME_INVISIBLE)); |
| 2424 | } |
| 2425 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2426 | // TODO: Move this clearing calling identity block to setImeWindowStatus after making sure |
| 2427 | // all updateSystemUi happens on system previlege. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2428 | final long ident = Binder.clearCallingIdentity(); |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2429 | try { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2430 | // apply policy for binder calls |
| 2431 | if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) { |
| 2432 | vis = 0; |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2433 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2434 | // mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked(). |
| 2435 | final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis); |
| 2436 | if (mStatusBar != null) { |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2437 | mStatusBar.setImeWindowStatus(mCurToken, vis, backDisposition, |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2438 | needsToShowImeSwitcher); |
| 2439 | } |
| 2440 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 2441 | if (imi != null && needsToShowImeSwitcher) { |
| 2442 | // Used to load label |
| 2443 | final CharSequence title = mRes.getText( |
| 2444 | com.android.internal.R.string.select_input_method); |
| 2445 | final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName( |
| 2446 | mContext, imi, mCurrentSubtype); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2447 | mImeSwitcherNotification.setContentTitle(title) |
| 2448 | .setContentText(summary) |
| 2449 | .setContentIntent(mImeSwitchPendingIntent); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2450 | try { |
Charles Chen | ea6e7f0 | 2018-11-19 21:37:45 +0800 | [diff] [blame] | 2451 | // TODO(b/120076400): Figure out what is the best behavior |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2452 | if ((mNotificationManager != null) |
Charles Chen | ea6e7f0 | 2018-11-19 21:37:45 +0800 | [diff] [blame] | 2453 | && !mIWindowManager.hasNavigationBar(DEFAULT_DISPLAY)) { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2454 | if (DEBUG) { |
| 2455 | Slog.d(TAG, "--- show notification: label = " + summary); |
| 2456 | } |
| 2457 | mNotificationManager.notifyAsUser(null, |
Chris Wren | 282cfef | 2017-03-27 15:01:44 -0400 | [diff] [blame] | 2458 | SystemMessage.NOTE_SELECT_INPUT_METHOD, |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2459 | mImeSwitcherNotification.build(), UserHandle.ALL); |
| 2460 | mNotificationShown = true; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2461 | } |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2462 | } catch (RemoteException e) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2463 | } |
| 2464 | } else { |
| 2465 | if (mNotificationShown && mNotificationManager != null) { |
| 2466 | if (DEBUG) { |
| 2467 | Slog.d(TAG, "--- hide notification"); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2468 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2469 | mNotificationManager.cancelAsUser(null, |
Chris Wren | 282cfef | 2017-03-27 15:01:44 -0400 | [diff] [blame] | 2470 | SystemMessage.NOTE_SELECT_INPUT_METHOD, UserHandle.ALL); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2471 | mNotificationShown = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2472 | } |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2473 | } |
| 2474 | } finally { |
| 2475 | Binder.restoreCallingIdentity(ident); |
| 2476 | } |
| 2477 | } |
| 2478 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2479 | void updateFromSettingsLocked(boolean enabledMayChange) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 2480 | updateInputMethodsFromSettingsLocked(enabledMayChange); |
| 2481 | updateKeyboardFromSettingsLocked(); |
| 2482 | } |
| 2483 | |
| 2484 | void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2485 | if (enabledMayChange) { |
| 2486 | List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 2487 | for (int i=0; i<enabled.size(); i++) { |
| 2488 | // We allow the user to select "disabled until used" apps, so if they |
| 2489 | // are enabling one of those here we now need to make it enabled. |
| 2490 | InputMethodInfo imm = enabled.get(i); |
| 2491 | try { |
| 2492 | ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(), |
| 2493 | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, |
| 2494 | mSettings.getCurrentUserId()); |
Satoshi Kataoka | 7987a31 | 2013-04-17 18:59:33 +0900 | [diff] [blame] | 2495 | if (ai != null && ai.enabledSetting |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2496 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 2497 | if (DEBUG) { |
| 2498 | Slog.d(TAG, "Update state(" + imm.getId() |
| 2499 | + "): DISABLED_UNTIL_USED -> DEFAULT"); |
| 2500 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2501 | mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(), |
| 2502 | PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 2503 | PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(), |
| 2504 | mContext.getBasePackageName()); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2505 | } |
| 2506 | } catch (RemoteException e) { |
| 2507 | } |
| 2508 | } |
| 2509 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2510 | // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and |
| 2511 | // ENABLED_INPUT_METHODS is taking care of keeping them correctly in |
| 2512 | // sync, so we will never have a DEFAULT_INPUT_METHOD that is not |
| 2513 | // enabled. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2514 | String id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2515 | // There is no input method selected, try to choose new applicable input method. |
| 2516 | if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2517 | id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2518 | } |
| 2519 | if (!TextUtils.isEmpty(id)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2520 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2521 | setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2522 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2523 | Slog.w(TAG, "Unknown input method from prefs: " + id, e); |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 2524 | resetCurrentMethodAndClient(UnbindReason.SWITCH_IME_FAILED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2526 | } else { |
| 2527 | // There is no longer an input method set, so stop any current one. |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 2528 | resetCurrentMethodAndClient(UnbindReason.NO_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2529 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 2530 | // Here is not the perfect place to reset the switching controller. Ideally |
| 2531 | // mSwitchingController and mSettings should be able to share the same state. |
| 2532 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 2533 | // the same enabled IMEs list. |
| 2534 | mSwitchingController.resetCircularListLocked(mContext); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 2535 | |
| 2536 | } |
| 2537 | |
| 2538 | public void updateKeyboardFromSettingsLocked() { |
| 2539 | mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled(); |
| 2540 | if (mSwitchingDialog != null |
| 2541 | && mSwitchingDialogTitleView != null |
| 2542 | && mSwitchingDialog.isShowing()) { |
| 2543 | final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById( |
| 2544 | com.android.internal.R.id.hard_keyboard_switch); |
| 2545 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
| 2546 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2547 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2548 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2549 | /* package */ void setInputMethodLocked(String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | InputMethodInfo info = mMethodMap.get(id); |
| 2551 | if (info == null) { |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 2552 | throw new IllegalArgumentException("Unknown id: " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2553 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2554 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2555 | // 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] | 2556 | if (id.equals(mCurMethodId)) { |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2557 | final int subtypeCount = info.getSubtypeCount(); |
| 2558 | if (subtypeCount <= 0) { |
| 2559 | return; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2560 | } |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2561 | final InputMethodSubtype oldSubtype = mCurrentSubtype; |
| 2562 | final InputMethodSubtype newSubtype; |
| 2563 | if (subtypeId >= 0 && subtypeId < subtypeCount) { |
| 2564 | newSubtype = info.getSubtypeAt(subtypeId); |
| 2565 | } else { |
| 2566 | // If subtype is null, try to find the most applicable one from |
| 2567 | // getCurrentInputMethodSubtype. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2568 | newSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2569 | } |
| 2570 | if (newSubtype == null || oldSubtype == null) { |
| 2571 | Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype |
| 2572 | + ", new subtype = " + newSubtype); |
| 2573 | return; |
| 2574 | } |
| 2575 | if (newSubtype != oldSubtype) { |
| 2576 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true); |
| 2577 | if (mCurMethod != null) { |
| 2578 | try { |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2579 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2580 | mCurMethod.changeInputMethodSubtype(newSubtype); |
| 2581 | } catch (RemoteException e) { |
| 2582 | Slog.w(TAG, "Failed to call changeInputMethodSubtype"); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2583 | } |
| 2584 | } |
| 2585 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2586 | return; |
| 2587 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2588 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2589 | // Changing to a different IME. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2590 | final long ident = Binder.clearCallingIdentity(); |
| 2591 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2592 | // Set a subtype to this input method. |
| 2593 | // subtypeId the name of a subtype which will be set. |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2594 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false); |
| 2595 | // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked() |
| 2596 | // because mCurMethodId is stored as a history in |
| 2597 | // setSelectedInputMethodAndSubtypeLocked(). |
| 2598 | mCurMethodId = id; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2599 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 2600 | if (LocalServices.getService(ActivityManagerInternal.class).isSystemReady()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2601 | Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 2602 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2603 | intent.putExtra("input_method_id", id); |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 2604 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2605 | } |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 2606 | unbindCurrentClientLocked(UnbindReason.SWITCH_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2607 | } finally { |
| 2608 | Binder.restoreCallingIdentity(ident); |
| 2609 | } |
| 2610 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2611 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2612 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2613 | public boolean showSoftInput(IInputMethodClient client, int flags, |
| 2614 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2615 | int uid = Binder.getCallingUid(); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2616 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 2617 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2618 | return false; |
| 2619 | } |
| 2620 | final long ident = Binder.clearCallingIdentity(); |
| 2621 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | if (mCurClient == null || client == null |
| 2623 | || mCurClient.client.asBinder() != client.asBinder()) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 2624 | // We need to check if this is the current client with |
| 2625 | // focus in the window manager, to allow this call to |
| 2626 | // be made before input is started in it. |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 2627 | final ClientState cs = mClients.get(client.asBinder()); |
| 2628 | if (cs == null) { |
| 2629 | throw new IllegalArgumentException("unknown client " + client.asBinder()); |
| 2630 | } |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2631 | if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid, |
| 2632 | cs.selfReportedDisplayId)) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 2633 | Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2634 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | } |
| 2636 | } |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2637 | 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] | 2638 | return showCurrentInputLocked(flags, resultReceiver); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2639 | } finally { |
| 2640 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2641 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2642 | } |
| 2643 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2644 | |
Andreas Gampe | d6d4206 | 2018-07-20 13:08:21 -0700 | [diff] [blame] | 2645 | @GuardedBy("mMethodMap") |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2646 | boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2647 | mShowRequested = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2648 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 2649 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2650 | } |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2652 | if ((flags&InputMethodManager.SHOW_FORCED) != 0) { |
| 2653 | mShowExplicitlyRequested = true; |
| 2654 | mShowForced = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2655 | } else if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) { |
| 2656 | mShowExplicitlyRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2657 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2658 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2659 | if (!mSystemReady) { |
| 2660 | return false; |
| 2661 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2662 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2663 | boolean res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2664 | if (mCurMethod != null) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2665 | if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2666 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 2667 | MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod, |
| 2668 | resultReceiver)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2669 | mInputShown = true; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2670 | if (mHaveConnection && !mVisibleBound) { |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 2671 | bindCurrentInputMethodServiceLocked( |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 2672 | mCurIntent, mVisibleConnection, IME_VISIBLE_BIND_FLAGS); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2673 | mVisibleBound = true; |
| 2674 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2675 | res = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2676 | } else if (mHaveConnection && SystemClock.uptimeMillis() |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 2677 | >= (mLastBindTime+TIME_TO_RECONNECT)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2678 | // The client has asked to have the input method shown, but |
| 2679 | // we have been sitting here too long with a connection to the |
| 2680 | // service and no interface received, so let's disconnect/connect |
| 2681 | // to try to prod things along. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2682 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2683 | SystemClock.uptimeMillis()-mLastBindTime,1); |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 2684 | 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] | 2685 | mContext.unbindService(this); |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 2686 | bindCurrentInputMethodServiceLocked(mCurIntent, this, IME_CONNECTION_BIND_FLAGS); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2687 | } else { |
| 2688 | if (DEBUG) { |
| 2689 | Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = " |
| 2690 | + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis())); |
| 2691 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2692 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2693 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2694 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2695 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2696 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2697 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2698 | public boolean hideSoftInput(IInputMethodClient client, int flags, |
| 2699 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2700 | int uid = Binder.getCallingUid(); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2701 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 2702 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2703 | return false; |
| 2704 | } |
| 2705 | final long ident = Binder.clearCallingIdentity(); |
| 2706 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2707 | if (mCurClient == null || client == null |
| 2708 | || mCurClient.client.asBinder() != client.asBinder()) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 2709 | // We need to check if this is the current client with |
| 2710 | // focus in the window manager, to allow this call to |
| 2711 | // be made before input is started in it. |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 2712 | final ClientState cs = mClients.get(client.asBinder()); |
| 2713 | if (cs == null) { |
| 2714 | throw new IllegalArgumentException("unknown client " + client.asBinder()); |
| 2715 | } |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2716 | if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid, |
| 2717 | cs.selfReportedDisplayId)) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 2718 | if (DEBUG) { |
| 2719 | Slog.w(TAG, "Ignoring hideSoftInput of uid " + uid + ": " + client); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2721 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2722 | } |
| 2723 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2724 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2725 | 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] | 2726 | return hideCurrentInputLocked(flags, resultReceiver); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2727 | } finally { |
| 2728 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2729 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2730 | } |
| 2731 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2732 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2733 | boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2734 | if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0 |
| 2735 | && (mShowExplicitlyRequested || mShowForced)) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2736 | 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] | 2737 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2738 | } |
| 2739 | if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2740 | 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] | 2741 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2742 | } |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 2743 | |
| 2744 | // There is a chance that IMM#hideSoftInput() is called in a transient state where |
| 2745 | // IMMS#InputShown is already updated to be true whereas IMMS#mImeWindowVis is still waiting |
| 2746 | // to be updated with the new value sent from IME process. Even in such a transient state |
| 2747 | // historically we have accepted an incoming call of IMM#hideSoftInput() from the |
| 2748 | // application process as a valid request, and have even promised such a behavior with CTS |
| 2749 | // since Android Eclair. That's why we need to accept IMM#hideSoftInput() even when only |
| 2750 | // IMMS#InputShown indicates that the software keyboard is shown. |
| 2751 | // TODO: Clean up, IMMS#mInputShown, IMMS#mImeWindowVis and mShowRequested. |
| 2752 | final boolean shouldHideSoftInput = (mCurMethod != null) && (mInputShown || |
| 2753 | (mImeWindowVis & InputMethodService.IME_ACTIVE) != 0); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2754 | boolean res; |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 2755 | if (shouldHideSoftInput) { |
| 2756 | // The IME will report its visible state again after the following message finally |
| 2757 | // delivered to the IME process as an IPC. Hence the inconsistency between |
| 2758 | // IMMS#mInputShown and IMMS#mImeWindowVis should be resolved spontaneously in |
| 2759 | // the final state. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2760 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 2761 | MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver)); |
| 2762 | res = true; |
| 2763 | } else { |
| 2764 | res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2765 | } |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2766 | if (mHaveConnection && mVisibleBound) { |
| 2767 | mContext.unbindService(mVisibleConnection); |
| 2768 | mVisibleBound = false; |
| 2769 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2770 | mInputShown = false; |
| 2771 | mShowRequested = false; |
| 2772 | mShowExplicitlyRequested = false; |
| 2773 | mShowForced = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2774 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2775 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2776 | |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2777 | @NonNull |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2778 | @Override |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2779 | public InputBindResult startInputOrWindowGainedFocus( |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 2780 | @StartInputReason int startInputReason, IInputMethodClient client, IBinder windowToken, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 2781 | @StartInputFlags int startInputFlags, @SoftInputModeFlags int softInputMode, |
| 2782 | int windowFlags, @Nullable EditorInfo attribute, IInputContext inputContext, |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 2783 | @MissingMethodFlags int missingMethods, int unverifiedTargetSdkVersion) { |
Yohei Yukawa | 80498d5 | 2018-06-21 16:24:36 -0700 | [diff] [blame] | 2784 | if (windowToken == null) { |
| 2785 | Slog.e(TAG, "windowToken cannot be null."); |
| 2786 | return InputBindResult.NULL; |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2787 | } |
Yohei Yukawa | 0f5eade | 2019-01-18 08:48:07 -0800 | [diff] [blame] | 2788 | final int callingUserId = UserHandle.getCallingUserId(); |
| 2789 | final int userId; |
Yohei Yukawa | 716897c | 2019-01-22 00:00:53 -0800 | [diff] [blame] | 2790 | if (attribute != null && attribute.targetInputMethodUser != null |
Yohei Yukawa | 0f5eade | 2019-01-18 08:48:07 -0800 | [diff] [blame] | 2791 | && attribute.targetInputMethodUser.getIdentifier() != callingUserId) { |
| 2792 | mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
Yohei Yukawa | 670abea | 2019-01-28 00:00:50 -0800 | [diff] [blame] | 2793 | "Using EditorInfo.targetInputMethodUser requires INTERACT_ACROSS_USERS_FULL."); |
Yohei Yukawa | 0f5eade | 2019-01-18 08:48:07 -0800 | [diff] [blame] | 2794 | userId = attribute.targetInputMethodUser.getIdentifier(); |
| 2795 | if (!mUserManagerInternal.isUserRunning(userId)) { |
| 2796 | // There is a chance that we hit here because of race condition. Let's just return |
| 2797 | // an error code instead of crashing the caller process, which at least has |
| 2798 | // INTERACT_ACROSS_USERS_FULL permission thus is likely to be an important process. |
| 2799 | Slog.e(TAG, "User #" + userId + " is not running."); |
| 2800 | return InputBindResult.INVALID_USER; |
| 2801 | } |
| 2802 | } else { |
| 2803 | userId = callingUserId; |
| 2804 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2805 | final InputBindResult result; |
| 2806 | synchronized (mMethodMap) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2807 | final long ident = Binder.clearCallingIdentity(); |
| 2808 | try { |
| 2809 | result = startInputOrWindowGainedFocusInternalLocked(startInputReason, client, |
| 2810 | windowToken, startInputFlags, softInputMode, windowFlags, attribute, |
| 2811 | inputContext, missingMethods, unverifiedTargetSdkVersion, userId); |
| 2812 | } finally { |
| 2813 | Binder.restoreCallingIdentity(ident); |
| 2814 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2815 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2816 | if (result == null) { |
| 2817 | // This must never happen, but just in case. |
| 2818 | Slog.wtf(TAG, "InputBindResult is @NonNull. startInputReason=" |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 2819 | + InputMethodDebug.startInputReasonToString(startInputReason) |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2820 | + " windowFlags=#" + Integer.toHexString(windowFlags) |
| 2821 | + " editorInfo=" + attribute); |
| 2822 | return InputBindResult.NULL; |
| 2823 | } |
| 2824 | return result; |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2825 | } |
| 2826 | |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2827 | @NonNull |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2828 | private InputBindResult startInputOrWindowGainedFocusInternalLocked( |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 2829 | @StartInputReason int startInputReason, IInputMethodClient client, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 2830 | @NonNull IBinder windowToken, @StartInputFlags int startInputFlags, |
| 2831 | @SoftInputModeFlags int softInputMode, int windowFlags, EditorInfo attribute, |
| 2832 | IInputContext inputContext, @MissingMethodFlags int missingMethods, |
Yohei Yukawa | 4391c20 | 2019-01-28 00:49:10 -0800 | [diff] [blame] | 2833 | int unverifiedTargetSdkVersion, @UserIdInt int userId) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 2834 | if (DEBUG) { |
| 2835 | Slog.v(TAG, "startInputOrWindowGainedFocusInternalLocked: reason=" |
| 2836 | + InputMethodDebug.startInputReasonToString(startInputReason) |
| 2837 | + " client=" + client.asBinder() |
| 2838 | + " inputContext=" + inputContext |
| 2839 | + " missingMethods=" |
| 2840 | + InputConnectionInspector.getMissingMethodFlagsAsString(missingMethods) |
| 2841 | + " attribute=" + attribute |
| 2842 | + " startInputFlags=" |
| 2843 | + InputMethodDebug.startInputFlagsToString(startInputFlags) |
| 2844 | + " softInputMode=" + InputMethodDebug.softInputModeToString(softInputMode) |
| 2845 | + " windowFlags=#" + Integer.toHexString(windowFlags) |
| 2846 | + " unverifiedTargetSdkVersion=" + unverifiedTargetSdkVersion); |
| 2847 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2848 | |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 2849 | final int windowDisplayId = mWindowManagerInternal.getDisplayIdForWindow(windowToken); |
| 2850 | |
| 2851 | final ClientState cs = mClients.get(client.asBinder()); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2852 | if (cs == null) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 2853 | throw new IllegalArgumentException("unknown client " + client.asBinder()); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2854 | } |
| 2855 | if (cs.selfReportedDisplayId != windowDisplayId) { |
| 2856 | Slog.e(TAG, "startInputOrWindowGainedFocusInternal: display ID mismatch." |
| 2857 | + " from client:" + cs.selfReportedDisplayId |
| 2858 | + " from window:" + windowDisplayId); |
| 2859 | return InputBindResult.DISPLAY_ID_MISMATCH; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2860 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2861 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2862 | if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid, |
| 2863 | cs.selfReportedDisplayId)) { |
| 2864 | // Check with the window manager to make sure this client actually |
| 2865 | // has a window with focus. If not, reject. This is thread safe |
| 2866 | // because if the focus changes some time before or after, the |
| 2867 | // next client receiving focus that has any interest in input will |
| 2868 | // be calling through here after that change happens. |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2869 | if (DEBUG) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2870 | Slog.w(TAG, "Focus gain on non-focused client " + cs.client |
| 2871 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2872 | } |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2873 | return InputBindResult.NOT_IME_TARGET_WINDOW; |
| 2874 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2875 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2876 | // cross-profile access is always allowed here to allow profile-switching. |
| 2877 | if (!mSettings.isCurrentProfile(userId)) { |
| 2878 | Slog.w(TAG, "A background user is requesting window. Hiding IME."); |
| 2879 | Slog.w(TAG, "If you need to impersonate a foreground user/profile from" |
| 2880 | + " a background user, use EditorInfo.targetInputMethodUser with" |
| 2881 | + " INTERACT_ACROSS_USERS_FULL permission."); |
| 2882 | hideCurrentInputLocked(0, null); |
| 2883 | return InputBindResult.INVALID_USER; |
| 2884 | } |
| 2885 | |
| 2886 | if (PER_PROFILE_IME_ENABLED && userId != mSettings.getCurrentUserId()) { |
| 2887 | switchUserLocked(userId); |
| 2888 | } |
| 2889 | // Master feature flag that overrides other conditions and forces IME preRendering. |
| 2890 | if (DEBUG) { |
| 2891 | Slog.v(TAG, "IME PreRendering MASTER flag: " |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 2892 | + DebugFlags.FLAG_PRE_RENDER_IME_VIEWS.value() + ", LowRam: " + mIsLowRam); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2893 | } |
| 2894 | // pre-rendering not supported on low-ram devices. |
| 2895 | cs.shouldPreRenderIme = DebugFlags.FLAG_PRE_RENDER_IME_VIEWS.value() && !mIsLowRam; |
| 2896 | |
| 2897 | if (mCurFocusedWindow == windowToken) { |
| 2898 | if (DEBUG) { |
| 2899 | Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client |
| 2900 | + " attribute=" + attribute + ", token = " + windowToken); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2901 | } |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2902 | if (attribute != null) { |
| 2903 | return startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 2904 | attribute, startInputFlags, startInputReason); |
| 2905 | } |
| 2906 | return new InputBindResult( |
| 2907 | InputBindResult.ResultCode.SUCCESS_REPORT_WINDOW_FOCUS_ONLY, |
| 2908 | null, null, null, -1); |
| 2909 | } |
| 2910 | mCurFocusedWindow = windowToken; |
| 2911 | mCurFocusedWindowSoftInputMode = softInputMode; |
| 2912 | mCurFocusedWindowClient = cs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2913 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2914 | // Should we auto-show the IME even if the caller has not |
| 2915 | // specified what should be done with it? |
| 2916 | // We only do this automatically if the window can resize |
| 2917 | // to accommodate the IME (so what the user sees will give |
| 2918 | // them good context without input information being obscured |
| 2919 | // by the IME) or if running on a large screen where there |
| 2920 | // is more room for the target window + IME. |
| 2921 | final boolean doAutoShow = |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 2922 | (softInputMode & LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 2923 | == LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2924 | || mRes.getConfiguration().isLayoutSizeAtLeast( |
| 2925 | Configuration.SCREENLAYOUT_SIZE_LARGE); |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 2926 | final boolean isTextEditor = (startInputFlags & StartInputFlags.IS_TEXT_EDITOR) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2927 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2928 | // We want to start input before showing the IME, but after closing |
| 2929 | // it. We want to do this after closing it to help the IME disappear |
| 2930 | // more quickly (not get stuck behind it initializing itself for the |
| 2931 | // new focused input, even if its window wants to hide the IME). |
| 2932 | boolean didStart = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2933 | |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 2934 | InputBindResult res = null; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 2935 | switch (softInputMode & LayoutParams.SOFT_INPUT_MASK_STATE) { |
| 2936 | case LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2937 | if (!isTextEditor || !doAutoShow) { |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 2938 | if (LayoutParams.mayUseInputMethod(windowFlags)) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2939 | // There is no focus view, and this window will |
| 2940 | // be behind any soft input window, so hide the |
| 2941 | // soft input window if it is shown. |
| 2942 | if (DEBUG) Slog.v(TAG, "Unspecified window will hide input"); |
| 2943 | hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2944 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2945 | // If focused display changed, we should unbind current method |
| 2946 | // to make app window in previous display relayout after Ime |
| 2947 | // window token removed. |
| 2948 | // Note that we can trust client's display ID as long as it matches |
| 2949 | // to the display ID obtained from the window. |
| 2950 | if (cs.selfReportedDisplayId != mCurTokenDisplayId) { |
| 2951 | unbindCurrentMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2952 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2953 | } |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 2954 | } else if (isTextEditor && doAutoShow |
| 2955 | && (softInputMode & LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2956 | // There is a focus view, and we are navigating forward |
| 2957 | // into the window, so show the input window for the user. |
| 2958 | // We only do this automatically if the window can resize |
| 2959 | // to accommodate the IME (so what the user sees will give |
| 2960 | // them good context without input information being obscured |
| 2961 | // by the IME) or if running on a large screen where there |
| 2962 | // is more room for the target window + IME. |
| 2963 | if (DEBUG) Slog.v(TAG, "Unspecified window will show input"); |
| 2964 | if (attribute != null) { |
| 2965 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 2966 | attribute, startInputFlags, startInputReason); |
| 2967 | didStart = true; |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2968 | } |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2969 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| 2970 | } |
| 2971 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 2972 | case LayoutParams.SOFT_INPUT_STATE_UNCHANGED: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2973 | // Do nothing. |
| 2974 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 2975 | case LayoutParams.SOFT_INPUT_STATE_HIDDEN: |
| 2976 | if ((softInputMode & LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2977 | if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward"); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2978 | hideCurrentInputLocked(0, null); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2979 | } |
| 2980 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 2981 | case LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2982 | if (DEBUG) Slog.v(TAG, "Window asks to hide input"); |
| 2983 | hideCurrentInputLocked(0, null); |
| 2984 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 2985 | case LayoutParams.SOFT_INPUT_STATE_VISIBLE: |
| 2986 | if ((softInputMode & LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2987 | if (DEBUG) Slog.v(TAG, "Window asks to show input going forward"); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2988 | if (InputMethodUtils.isSoftInputModeStateVisibleAllowed( |
| 2989 | unverifiedTargetSdkVersion, startInputFlags)) { |
| 2990 | if (attribute != null) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 2991 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 2992 | attribute, startInputFlags, startInputReason); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2993 | didStart = true; |
| 2994 | } |
| 2995 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| 2996 | } else { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 2997 | Slog.e(TAG, "SOFT_INPUT_STATE_VISIBLE is ignored because" |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 2998 | + " there is no focused view that also returns true from" |
| 2999 | + " View#onCheckIsTextEditor()"); |
| 3000 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3001 | } |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3002 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3003 | case LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3004 | if (DEBUG) Slog.v(TAG, "Window asks to always show input"); |
| 3005 | if (InputMethodUtils.isSoftInputModeStateVisibleAllowed( |
| 3006 | unverifiedTargetSdkVersion, startInputFlags)) { |
| 3007 | if (attribute != null) { |
| 3008 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 3009 | attribute, startInputFlags, startInputReason); |
| 3010 | didStart = true; |
| 3011 | } |
| 3012 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
| 3013 | } else { |
| 3014 | Slog.e(TAG, "SOFT_INPUT_STATE_ALWAYS_VISIBLE is ignored because" |
| 3015 | + " there is no focused view that also returns true from" |
| 3016 | + " View#onCheckIsTextEditor()"); |
| 3017 | } |
| 3018 | break; |
| 3019 | } |
| 3020 | |
| 3021 | if (!didStart) { |
| 3022 | if (attribute != null) { |
| 3023 | if (!DebugFlags.FLAG_OPTIMIZE_START_INPUT.value() |
| 3024 | || (startInputFlags & StartInputFlags.IS_TEXT_EDITOR) != 0) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3025 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, attribute, |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3026 | startInputFlags, startInputReason); |
| 3027 | } else { |
| 3028 | res = InputBindResult.NO_EDITOR; |
| 3029 | } |
| 3030 | } else { |
| 3031 | res = InputBindResult.NULL_EDITOR_INFO; |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3032 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3033 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 3034 | return res; |
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 | |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3037 | private boolean canShowInputMethodPickerLocked(IInputMethodClient client) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 3038 | // TODO(yukawa): multi-display support. |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3039 | final int uid = Binder.getCallingUid(); |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3040 | if (mCurFocusedWindowClient != null && client != null |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 3041 | && mCurFocusedWindowClient.client.asBinder() == client.asBinder()) { |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3042 | return true; |
| 3043 | } else if (mCurIntent != null && InputMethodUtils.checkIfPackageBelongsToUid( |
| 3044 | mAppOpsManager, |
| 3045 | uid, |
| 3046 | mCurIntent.getComponent().getPackageName())) { |
| 3047 | return true; |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3048 | } |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3049 | return false; |
| 3050 | } |
| 3051 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3052 | @Override |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3053 | public void showInputMethodPickerFromClient( |
| 3054 | IInputMethodClient client, int auxiliarySubtypeMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3055 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3056 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3057 | return; |
| 3058 | } |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3059 | if(!canShowInputMethodPickerLocked(client)) { |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3060 | Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid " |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 3061 | + Binder.getCallingUid() + ": " + client); |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3062 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3063 | } |
| 3064 | |
satok | 440aab5 | 2010-11-25 09:43:11 +0900 | [diff] [blame] | 3065 | // Always call subtype picker, because subtype picker is a superset of input method |
| 3066 | // picker. |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3067 | mHandler.sendMessage(mCaller.obtainMessageII( |
| 3068 | MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, |
| 3069 | (mCurClient != null) ? mCurClient.selfReportedDisplayId : DEFAULT_DISPLAY)); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3070 | } |
| 3071 | } |
| 3072 | |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3073 | @Override |
| 3074 | public void showInputMethodPickerFromSystem(IInputMethodClient client, int auxiliarySubtypeMode, |
| 3075 | int displayId) { |
| 3076 | if (mContext.checkCallingPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 3077 | != PackageManager.PERMISSION_GRANTED) { |
| 3078 | throw new SecurityException( |
| 3079 | "showInputMethodPickerFromSystem requires WRITE_SECURE_SETTINGS permission"); |
| 3080 | } |
| 3081 | // Always call subtype picker, because subtype picker is a superset of input method |
| 3082 | // picker. |
| 3083 | mHandler.sendMessage(mCaller.obtainMessageII( |
| 3084 | MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, displayId)); |
| 3085 | } |
| 3086 | |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 3087 | public boolean isInputMethodPickerShownForTest() { |
| 3088 | synchronized(mMethodMap) { |
| 3089 | if (mSwitchingDialog == null) { |
| 3090 | return false; |
| 3091 | } |
| 3092 | return mSwitchingDialog.isShowing(); |
| 3093 | } |
| 3094 | } |
| 3095 | |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 3096 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3097 | private void setInputMethod(@NonNull IBinder token, String id) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3098 | synchronized (mMethodMap) { |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 3099 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3100 | return; |
| 3101 | } |
| 3102 | setInputMethodWithSubtypeIdLocked(token, id, NOT_A_SUBTYPE_ID); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3103 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3104 | } |
| 3105 | |
Yohei Yukawa | 4773ee1 | 2018-12-24 21:13:53 -0800 | [diff] [blame] | 3106 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3107 | private void setInputMethodAndSubtype(@NonNull IBinder token, String id, |
| 3108 | InputMethodSubtype subtype) { |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3109 | synchronized (mMethodMap) { |
Yohei Yukawa | 4773ee1 | 2018-12-24 21:13:53 -0800 | [diff] [blame] | 3110 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3111 | return; |
| 3112 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3113 | if (subtype != null) { |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3114 | setInputMethodWithSubtypeIdLocked(token, id, |
| 3115 | InputMethodUtils.getSubtypeIdFromHashCode(mMethodMap.get(id), |
| 3116 | subtype.hashCode())); |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3117 | } else { |
| 3118 | setInputMethod(token, id); |
| 3119 | } |
| 3120 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3121 | } |
| 3122 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3123 | @Override |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3124 | public void showInputMethodAndSubtypeEnablerFromClient( |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3125 | IInputMethodClient client, String inputMethodId) { |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3126 | synchronized (mMethodMap) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3127 | // TODO(yukawa): Should we verify the display ID? |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3128 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3129 | return; |
| 3130 | } |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3131 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 3132 | MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId)); |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3133 | } |
| 3134 | } |
| 3135 | |
Yohei Yukawa | 0c49908 | 2018-12-09 18:52:02 -0800 | [diff] [blame] | 3136 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3137 | private boolean switchToPreviousInputMethod(@NonNull IBinder token) { |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3138 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3139 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 0c49908 | 2018-12-09 18:52:02 -0800 | [diff] [blame] | 3140 | return false; |
| 3141 | } |
satok | c445bcd | 2011-01-25 18:57:24 +0900 | [diff] [blame] | 3142 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3143 | final InputMethodInfo lastImi; |
satok | 208d563 | 2011-05-20 22:13:38 +0900 | [diff] [blame] | 3144 | if (lastIme != null) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3145 | lastImi = mMethodMap.get(lastIme.first); |
| 3146 | } else { |
| 3147 | lastImi = null; |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3148 | } |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3149 | String targetLastImiId = null; |
| 3150 | int subtypeId = NOT_A_SUBTYPE_ID; |
| 3151 | if (lastIme != null && lastImi != null) { |
| 3152 | final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId); |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3153 | final int lastSubtypeHash = Integer.parseInt(lastIme.second); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3154 | final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID |
| 3155 | : mCurrentSubtype.hashCode(); |
| 3156 | // If the last IME is the same as the current IME and the last subtype is not |
| 3157 | // defined, there is no need to switch to the last IME. |
| 3158 | if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) { |
| 3159 | targetLastImiId = lastIme.first; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3160 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3161 | } |
| 3162 | } |
| 3163 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3164 | if (TextUtils.isEmpty(targetLastImiId) |
| 3165 | && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3166 | // This is a safety net. If the currentSubtype can't be added to the history |
| 3167 | // and the framework couldn't find the last ime, we will make the last ime be |
| 3168 | // the most applicable enabled keyboard subtype of the system imes. |
| 3169 | final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 3170 | if (enabled != null) { |
| 3171 | final int N = enabled.size(); |
| 3172 | final String locale = mCurrentSubtype == null |
| 3173 | ? mRes.getConfiguration().locale.toString() |
| 3174 | : mCurrentSubtype.getLocale(); |
| 3175 | for (int i = 0; i < N; ++i) { |
| 3176 | final InputMethodInfo imi = enabled.get(i); |
Yohei Yukawa | fd70fe8 | 2018-04-08 12:19:56 -0700 | [diff] [blame] | 3177 | if (imi.getSubtypeCount() > 0 && imi.isSystem()) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3178 | InputMethodSubtype keyboardSubtype = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3179 | InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, |
| 3180 | InputMethodUtils.getSubtypes(imi), |
| 3181 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3182 | if (keyboardSubtype != null) { |
| 3183 | targetLastImiId = imi.getId(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3184 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3185 | imi, keyboardSubtype.hashCode()); |
| 3186 | if(keyboardSubtype.getLocale().equals(locale)) { |
| 3187 | break; |
| 3188 | } |
| 3189 | } |
| 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | } |
| 3194 | |
| 3195 | if (!TextUtils.isEmpty(targetLastImiId)) { |
| 3196 | if (DEBUG) { |
| 3197 | Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second |
| 3198 | + ", from: " + mCurMethodId + ", " + subtypeId); |
| 3199 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3200 | setInputMethodWithSubtypeIdLocked(token, targetLastImiId, subtypeId); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3201 | return true; |
| 3202 | } else { |
| 3203 | return false; |
| 3204 | } |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3205 | } |
| 3206 | } |
| 3207 | |
Yohei Yukawa | 70f17e7 | 2018-12-09 18:51:38 -0800 | [diff] [blame] | 3208 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3209 | private boolean switchToNextInputMethod(@NonNull IBinder token, boolean onlyCurrentIme) { |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3210 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3211 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 3212 | return false; |
| 3213 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3214 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | 136b6ce | 2018-05-02 10:55:35 -0700 | [diff] [blame] | 3215 | onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3216 | if (nextSubtype == null) { |
| 3217 | return false; |
| 3218 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3219 | setInputMethodWithSubtypeIdLocked(token, nextSubtype.mImi.getId(), |
| 3220 | nextSubtype.mSubtypeId); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3221 | return true; |
| 3222 | } |
| 3223 | } |
| 3224 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 3225 | @BinderThread |
| 3226 | private boolean shouldOfferSwitchingToNextInputMethod(@NonNull IBinder token) { |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 3227 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3228 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 3229 | return false; |
| 3230 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3231 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | 136b6ce | 2018-05-02 10:55:35 -0700 | [diff] [blame] | 3232 | false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype); |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 3233 | if (nextSubtype == null) { |
| 3234 | return false; |
| 3235 | } |
| 3236 | return true; |
| 3237 | } |
| 3238 | } |
| 3239 | |
| 3240 | @Override |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3241 | public InputMethodSubtype getLastInputMethodSubtype() { |
| 3242 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3243 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3244 | return null; |
| 3245 | } |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3246 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
| 3247 | // TODO: Handle the case of the last IME with no subtypes |
| 3248 | if (lastIme == null || TextUtils.isEmpty(lastIme.first) |
| 3249 | || TextUtils.isEmpty(lastIme.second)) return null; |
| 3250 | final InputMethodInfo lastImi = mMethodMap.get(lastIme.first); |
| 3251 | if (lastImi == null) return null; |
| 3252 | try { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3253 | final int lastSubtypeHash = Integer.parseInt(lastIme.second); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3254 | final int lastSubtypeId = |
| 3255 | InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 0e7d7d6 | 2011-07-05 13:28:06 +0900 | [diff] [blame] | 3256 | if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) { |
| 3257 | return null; |
| 3258 | } |
| 3259 | return lastImi.getSubtypeAt(lastSubtypeId); |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3260 | } catch (NumberFormatException e) { |
| 3261 | return null; |
| 3262 | } |
| 3263 | } |
| 3264 | } |
| 3265 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3266 | @Override |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3267 | public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) { |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3268 | // By this IPC call, only a process which shares the same uid with the IME can add |
| 3269 | // additional input method subtypes to the IME. |
Yohei Yukawa | 70f5c48 | 2016-01-04 19:42:36 -0800 | [diff] [blame] | 3270 | if (TextUtils.isEmpty(imiId) || subtypes == null) return; |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3271 | final ArrayList<InputMethodSubtype> toBeAdded = new ArrayList<>(); |
| 3272 | for (InputMethodSubtype subtype : subtypes) { |
| 3273 | if (!toBeAdded.contains(subtype)) { |
| 3274 | toBeAdded.add(subtype); |
| 3275 | } else { |
| 3276 | Slog.w(TAG, "Duplicated subtype definition found: " |
| 3277 | + subtype.getLocale() + ", " + subtype.getMode()); |
| 3278 | } |
| 3279 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3280 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3281 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3282 | return; |
| 3283 | } |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 3284 | if (!mSystemReady) { |
| 3285 | return; |
| 3286 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3287 | final InputMethodInfo imi = mMethodMap.get(imiId); |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3288 | if (imi == null) return; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3289 | final String[] packageInfos; |
| 3290 | try { |
| 3291 | packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 3292 | } catch (RemoteException e) { |
| 3293 | Slog.e(TAG, "Failed to get package infos"); |
| 3294 | return; |
| 3295 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3296 | if (packageInfos != null) { |
| 3297 | final int packageNum = packageInfos.length; |
| 3298 | for (int i = 0; i < packageNum; ++i) { |
| 3299 | if (packageInfos[i].equals(imi.getPackageName())) { |
Yohei Yukawa | 7b1c8d7 | 2018-12-19 11:21:04 -0800 | [diff] [blame] | 3300 | if (subtypes.length > 0) { |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3301 | mAdditionalSubtypeMap.put(imi.getId(), toBeAdded); |
Yohei Yukawa | 7b1c8d7 | 2018-12-19 11:21:04 -0800 | [diff] [blame] | 3302 | } else { |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3303 | mAdditionalSubtypeMap.remove(imi.getId()); |
Yohei Yukawa | 7b1c8d7 | 2018-12-19 11:21:04 -0800 | [diff] [blame] | 3304 | } |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3305 | AdditionalSubtypeUtils.save(mAdditionalSubtypeMap, mMethodMap, |
| 3306 | mSettings.getCurrentUserId()); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 3307 | final long ident = Binder.clearCallingIdentity(); |
| 3308 | try { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3309 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 3310 | } finally { |
| 3311 | Binder.restoreCallingIdentity(ident); |
| 3312 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3313 | return; |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3314 | } |
| 3315 | } |
| 3316 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3317 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3318 | return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3319 | } |
| 3320 | |
Yohei Yukawa | b985e6e | 2018-09-05 17:07:52 -0700 | [diff] [blame] | 3321 | /** |
| 3322 | * This is kept due to {@link android.annotation.UnsupportedAppUsage} in |
| 3323 | * {@link InputMethodManager#getInputMethodWindowVisibleHeight()} and a dependency in |
| 3324 | * {@link InputMethodService#onCreate()}. |
| 3325 | * |
| 3326 | * <p>TODO(Bug 113914148): Check if we can remove this.</p> |
| 3327 | * @return {@link WindowManagerInternal#getInputMethodWindowVisibleHeight()} |
| 3328 | */ |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 3329 | @Override |
| 3330 | public int getInputMethodWindowVisibleHeight() { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 3331 | // TODO(yukawa): Should we verify the display ID? |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3332 | return mWindowManagerInternal.getInputMethodWindowVisibleHeight(mCurTokenDisplayId); |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 3333 | } |
| 3334 | |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 3335 | @BinderThread |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3336 | private void notifyUserAction(@NonNull IBinder token) { |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3337 | if (DEBUG) { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3338 | Slog.d(TAG, "Got the notification of a user action."); |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3339 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3340 | synchronized (mMethodMap) { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3341 | if (mCurToken != token) { |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3342 | if (DEBUG) { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3343 | Slog.d(TAG, "Ignoring the user action notification from IMEs that are no longer" |
| 3344 | + " active."); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3345 | } |
| 3346 | return; |
| 3347 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3348 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 3349 | if (imi != null) { |
Yohei Yukawa | 0297051 | 2014-06-05 16:16:18 +0900 | [diff] [blame] | 3350 | mSwitchingController.onUserActionLocked(imi, mCurrentSubtype); |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3351 | } |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3352 | } |
| 3353 | } |
| 3354 | |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 3355 | @BinderThread |
| 3356 | private void reportPreRendered(IBinder token, EditorInfo info) { |
| 3357 | synchronized (mMethodMap) { |
| 3358 | if (!calledWithValidTokenLocked(token)) { |
| 3359 | return; |
| 3360 | } |
| 3361 | if (mCurClient != null && mCurClient.client != null) { |
| 3362 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
| 3363 | MSG_REPORT_PRE_RENDERED, info, mCurClient)); |
| 3364 | } |
| 3365 | } |
| 3366 | } |
| 3367 | |
| 3368 | @BinderThread |
| 3369 | private void applyImeVisibility(IBinder token, boolean setVisible) { |
| 3370 | synchronized (mMethodMap) { |
| 3371 | if (!calledWithValidTokenLocked(token)) { |
| 3372 | return; |
| 3373 | } |
| 3374 | if (mCurClient != null && mCurClient.client != null) { |
| 3375 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 3376 | MSG_APPLY_IME_VISIBILITY, setVisible ? 1 : 0, mCurClient)); |
| 3377 | } |
| 3378 | } |
| 3379 | } |
| 3380 | |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3381 | private void setInputMethodWithSubtypeIdLocked(IBinder token, String id, int subtypeId) { |
| 3382 | if (token == null) { |
| 3383 | if (mContext.checkCallingOrSelfPermission( |
| 3384 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 3385 | != PackageManager.PERMISSION_GRANTED) { |
| 3386 | throw new SecurityException( |
| 3387 | "Using null token requires permission " |
| 3388 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3389 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3390 | } else if (mCurToken != token) { |
| 3391 | Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid() |
| 3392 | + " token: " + token); |
| 3393 | return; |
| 3394 | } |
| 3395 | |
| 3396 | final long ident = Binder.clearCallingIdentity(); |
| 3397 | try { |
| 3398 | setInputMethodLocked(id, subtypeId); |
| 3399 | } finally { |
| 3400 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3401 | } |
| 3402 | } |
| 3403 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 3404 | @BinderThread |
| 3405 | private void hideMySoftInput(@NonNull IBinder token, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3406 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3407 | if (!calledWithValidTokenLocked(token)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3408 | return; |
| 3409 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3410 | long ident = Binder.clearCallingIdentity(); |
| 3411 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3412 | hideCurrentInputLocked(flags, null); |
| 3413 | } finally { |
| 3414 | Binder.restoreCallingIdentity(ident); |
| 3415 | } |
| 3416 | } |
| 3417 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3418 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 3419 | @BinderThread |
| 3420 | private void showMySoftInput(@NonNull IBinder token, int flags) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3421 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3422 | if (!calledWithValidTokenLocked(token)) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3423 | return; |
| 3424 | } |
| 3425 | long ident = Binder.clearCallingIdentity(); |
| 3426 | try { |
| 3427 | showCurrentInputLocked(flags, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3428 | } finally { |
| 3429 | Binder.restoreCallingIdentity(ident); |
| 3430 | } |
| 3431 | } |
| 3432 | } |
| 3433 | |
| 3434 | void setEnabledSessionInMainThread(SessionState session) { |
| 3435 | if (mEnabledSession != session) { |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3436 | if (mEnabledSession != null && mEnabledSession.session != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3437 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3438 | if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession); |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3439 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3440 | } catch (RemoteException e) { |
| 3441 | } |
| 3442 | } |
| 3443 | mEnabledSession = session; |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3444 | if (mEnabledSession != null && mEnabledSession.session != null) { |
| 3445 | try { |
| 3446 | if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession); |
| 3447 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, true); |
| 3448 | } catch (RemoteException e) { |
| 3449 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3450 | } |
| 3451 | } |
| 3452 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3453 | |
Yohei Yukawa | 930328c | 2017-10-18 20:19:53 -0700 | [diff] [blame] | 3454 | @MainThread |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3455 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3456 | public boolean handleMessage(Message msg) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3457 | SomeArgs args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3458 | switch (msg.what) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3459 | case MSG_SHOW_IM_SUBTYPE_PICKER: |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3460 | final boolean showAuxSubtypes; |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3461 | final int displayId = msg.arg2; |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3462 | switch (msg.arg1) { |
| 3463 | case InputMethodManager.SHOW_IM_PICKER_MODE_AUTO: |
| 3464 | // This is undocumented so far, but IMM#showInputMethodPicker() has been |
| 3465 | // implemented so that auxiliary subtypes will be excluded when the soft |
| 3466 | // keyboard is invisible. |
| 3467 | showAuxSubtypes = mInputShown; |
| 3468 | break; |
| 3469 | case InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES: |
| 3470 | showAuxSubtypes = true; |
| 3471 | break; |
| 3472 | case InputMethodManager.SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES: |
| 3473 | showAuxSubtypes = false; |
| 3474 | break; |
| 3475 | default: |
| 3476 | Slog.e(TAG, "Unknown subtype picker mode = " + msg.arg1); |
| 3477 | return false; |
| 3478 | } |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3479 | showInputMethodMenu(showAuxSubtypes, displayId); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3480 | return true; |
| 3481 | |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3482 | case MSG_SHOW_IM_SUBTYPE_ENABLER: |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 3483 | showInputMethodAndSubtypeEnabler((String)msg.obj); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3484 | return true; |
| 3485 | |
| 3486 | case MSG_SHOW_IM_CONFIG: |
| 3487 | showConfigureInputMethods(); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3488 | return true; |
| 3489 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3490 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3492 | case MSG_UNBIND_INPUT: |
| 3493 | try { |
| 3494 | ((IInputMethod)msg.obj).unbindInput(); |
| 3495 | } catch (RemoteException e) { |
| 3496 | // There is nothing interesting about the method dying. |
| 3497 | } |
| 3498 | return true; |
| 3499 | case MSG_BIND_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3500 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3501 | try { |
| 3502 | ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2); |
| 3503 | } catch (RemoteException e) { |
| 3504 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3505 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3506 | return true; |
| 3507 | case MSG_SHOW_SOFT_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3508 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3509 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3510 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput(" |
Craig Mautner | 6efb4c7 | 2013-03-13 10:17:41 -0700 | [diff] [blame] | 3511 | + msg.arg1 + ", " + args.arg2 + ")"); |
Craig Mautner | ca0ac71 | 2013-03-14 09:43:02 -0700 | [diff] [blame] | 3512 | ((IInputMethod)args.arg1).showSoftInput(msg.arg1, (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3513 | } catch (RemoteException e) { |
| 3514 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3515 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3516 | return true; |
| 3517 | case MSG_HIDE_SOFT_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3518 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3519 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3520 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, " |
Craig Mautner | 6efb4c7 | 2013-03-13 10:17:41 -0700 | [diff] [blame] | 3521 | + args.arg2 + ")"); |
Craig Mautner | ca0ac71 | 2013-03-14 09:43:02 -0700 | [diff] [blame] | 3522 | ((IInputMethod)args.arg1).hideSoftInput(0, (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3523 | } catch (RemoteException e) { |
| 3524 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3525 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3526 | return true; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 3527 | case MSG_HIDE_CURRENT_INPUT_METHOD: |
| 3528 | synchronized (mMethodMap) { |
| 3529 | hideCurrentInputLocked(0, null); |
| 3530 | } |
| 3531 | return true; |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 3532 | case MSG_INITIALIZE_IME: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3533 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3534 | try { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3535 | if (DEBUG) { |
| 3536 | Slog.v(TAG, "Sending attach of token: " + args.arg2 + " for display: " |
| 3537 | + msg.arg1); |
| 3538 | } |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 3539 | final IBinder token = (IBinder) args.arg2; |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3540 | ((IInputMethod) args.arg1).initializeInternal(token, msg.arg1, |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 3541 | new InputMethodPrivilegedOperationsImpl(this, token)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3542 | } catch (RemoteException e) { |
| 3543 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3544 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3545 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3546 | case MSG_CREATE_SESSION: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3547 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3548 | IInputMethod method = (IInputMethod)args.arg1; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3549 | InputChannel channel = (InputChannel)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3550 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3551 | method.createSession(channel, (IInputSessionCallback)args.arg3); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3552 | } catch (RemoteException e) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3553 | } finally { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3554 | // Dispose the channel if the input method is not local to this process |
| 3555 | // because the remote proxy will get its own copy when unparceled. |
| 3556 | if (channel != null && Binder.isProxy(method)) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3557 | channel.dispose(); |
| 3558 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3559 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3560 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3561 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3562 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3563 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3564 | |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3565 | case MSG_START_INPUT: { |
Yohei Yukawa | f7526b5 | 2017-02-11 20:57:10 -0800 | [diff] [blame] | 3566 | final int missingMethods = msg.arg1; |
| 3567 | final boolean restarting = msg.arg2 != 0; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3568 | args = (SomeArgs) msg.obj; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 3569 | final IBinder startInputToken = (IBinder) args.arg1; |
| 3570 | final SessionState session = (SessionState) args.arg2; |
| 3571 | final IInputContext inputContext = (IInputContext) args.arg3; |
| 3572 | final EditorInfo editorInfo = (EditorInfo) args.arg4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3573 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3574 | setEnabledSessionInMainThread(session); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 3575 | session.method.startInput(startInputToken, inputContext, missingMethods, |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 3576 | editorInfo, restarting, session.client.shouldPreRenderIme); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3577 | } catch (RemoteException e) { |
| 3578 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3579 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3580 | return true; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3581 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3583 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3584 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3585 | case MSG_UNBIND_CLIENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3586 | try { |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3587 | ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1, msg.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3588 | } catch (RemoteException e) { |
| 3589 | // There is nothing interesting about the last client dying. |
| 3590 | } |
| 3591 | return true; |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3592 | case MSG_BIND_CLIENT: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3593 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3594 | IInputMethodClient client = (IInputMethodClient)args.arg1; |
| 3595 | InputBindResult res = (InputBindResult)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3596 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3597 | client.onBindMethod(res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3598 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3599 | Slog.w(TAG, "Client died receiving input method " + args.arg2); |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3600 | } finally { |
| 3601 | // Dispose the channel if the input method is not local to this process |
| 3602 | // because the remote proxy will get its own copy when unparceled. |
| 3603 | if (res.channel != null && Binder.isProxy(client)) { |
| 3604 | res.channel.dispose(); |
| 3605 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3606 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3607 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3608 | return true; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3609 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 3610 | case MSG_SET_ACTIVE: |
| 3611 | try { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3612 | ((ClientState)msg.obj).client.setActive(msg.arg1 != 0, msg.arg2 != 0); |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 3613 | } catch (RemoteException e) { |
| 3614 | Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid " |
| 3615 | + ((ClientState)msg.obj).pid + " uid " |
| 3616 | + ((ClientState)msg.obj).uid); |
| 3617 | } |
| 3618 | return true; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3619 | case MSG_SET_INTERACTIVE: |
| 3620 | handleSetInteractive(msg.arg1 != 0); |
| 3621 | return true; |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3622 | case MSG_REPORT_FULLSCREEN_MODE: { |
| 3623 | final boolean fullscreen = msg.arg1 != 0; |
| 3624 | final ClientState clientState = (ClientState)msg.obj; |
| 3625 | try { |
| 3626 | clientState.client.reportFullscreenMode(fullscreen); |
| 3627 | } catch (RemoteException e) { |
| 3628 | Slog.w(TAG, "Got RemoteException sending " |
| 3629 | + "reportFullscreen(" + fullscreen + ") notification to pid=" |
| 3630 | + clientState.pid + " uid=" + clientState.uid); |
| 3631 | } |
| 3632 | return true; |
| 3633 | } |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 3634 | case MSG_REPORT_PRE_RENDERED: { |
| 3635 | args = (SomeArgs) msg.obj; |
| 3636 | final EditorInfo info = (EditorInfo) args.arg1; |
| 3637 | final ClientState clientState = (ClientState) args.arg2; |
| 3638 | try { |
| 3639 | clientState.client.reportPreRendered(info); |
| 3640 | } catch (RemoteException e) { |
| 3641 | Slog.w(TAG, "Got RemoteException sending " |
| 3642 | + "reportPreRendered(" + info + ") notification to pid=" |
| 3643 | + clientState.pid + " uid=" + clientState.uid); |
| 3644 | } |
| 3645 | args.recycle(); |
| 3646 | return true; |
| 3647 | } |
| 3648 | case MSG_APPLY_IME_VISIBILITY: { |
| 3649 | final boolean setVisible = msg.arg1 != 0; |
| 3650 | final ClientState clientState = (ClientState) msg.obj; |
| 3651 | try { |
| 3652 | clientState.client.applyImeVisibility(setVisible); |
| 3653 | } catch (RemoteException e) { |
| 3654 | Slog.w(TAG, "Got RemoteException sending " |
| 3655 | + "applyImeVisibility(" + setVisible + ") notification to pid=" |
| 3656 | + clientState.pid + " uid=" + clientState.uid); |
| 3657 | } |
| 3658 | return true; |
| 3659 | } |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3660 | |
| 3661 | // -------------------------------------------------------------- |
| 3662 | case MSG_HARD_KEYBOARD_SWITCH_CHANGED: |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3663 | mHardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3664 | return true; |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 3665 | case MSG_SYSTEM_UNLOCK_USER: |
| 3666 | final int userId = msg.arg1; |
| 3667 | onUnlockUser(userId); |
| 3668 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3669 | } |
| 3670 | return false; |
| 3671 | } |
| 3672 | |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3673 | private void handleSetInteractive(final boolean interactive) { |
| 3674 | synchronized (mMethodMap) { |
| 3675 | mIsInteractive = interactive; |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 3676 | updateSystemUiLocked(interactive ? mImeWindowVis : 0, mBackDisposition); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3677 | |
| 3678 | // Inform the current client of the change in active status |
| 3679 | if (mCurClient != null && mCurClient.client != null) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3680 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 3681 | MSG_SET_ACTIVE, mIsInteractive ? 1 : 0, mInFullscreenMode ? 1 : 0, |
| 3682 | mCurClient)); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3683 | } |
| 3684 | } |
| 3685 | } |
| 3686 | |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 3687 | private boolean chooseNewDefaultIMELocked() { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3688 | final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME( |
| 3689 | mSettings.getEnabledInputMethodListLocked()); |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 3690 | if (imi != null) { |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 3691 | if (DEBUG) { |
| 3692 | Slog.d(TAG, "New default IME was selected: " + imi.getId()); |
| 3693 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3694 | resetSelectedInputMethodAndSubtypeLocked(imi.getId()); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 3695 | return true; |
| 3696 | } |
| 3697 | |
| 3698 | return false; |
| 3699 | } |
| 3700 | |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 3701 | static void queryInputMethodServicesInternal(Context context, |
| 3702 | @UserIdInt int userId, ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap, |
| 3703 | ArrayMap<String, InputMethodInfo> methodMap, ArrayList<InputMethodInfo> methodList) { |
| 3704 | methodList.clear(); |
| 3705 | methodMap.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3706 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 3707 | // Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default |
| 3708 | // behavior of PackageManager is exactly what we want. It by default picks up appropriate |
| 3709 | // services depending on the unlock state for the specified user. |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 3710 | final List<ResolveInfo> services = context.getPackageManager().queryIntentServicesAsUser( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3711 | new Intent(InputMethod.SERVICE_INTERFACE), |
Yohei Yukawa | 5ec1fce | 2018-12-17 07:56:14 -0800 | [diff] [blame] | 3712 | PackageManager.GET_META_DATA | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS, |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 3713 | userId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3714 | |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 3715 | methodList.ensureCapacity(services.size()); |
| 3716 | methodMap.ensureCapacity(services.size()); |
| 3717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3718 | for (int i = 0; i < services.size(); ++i) { |
| 3719 | ResolveInfo ri = services.get(i); |
| 3720 | ServiceInfo si = ri.serviceInfo; |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3721 | final String imeId = InputMethodInfo.computeId(ri); |
| 3722 | if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) { |
| 3723 | Slog.w(TAG, "Skipping input method " + imeId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3724 | + ": it does not require the permission " |
| 3725 | + android.Manifest.permission.BIND_INPUT_METHOD); |
| 3726 | continue; |
| 3727 | } |
| 3728 | |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3729 | if (DEBUG) Slog.d(TAG, "Checking " + imeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3730 | |
| 3731 | try { |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 3732 | final InputMethodInfo imi = new InputMethodInfo(context, ri, |
| 3733 | additionalSubtypeMap.get(imeId)); |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 3734 | if (imi.isVrOnly()) { |
| 3735 | continue; // Skip VR-only IME, which isn't supported for now. |
| 3736 | } |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 3737 | methodList.add(imi); |
| 3738 | methodMap.put(imi.getId(), imi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3739 | if (DEBUG) { |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 3740 | Slog.d(TAG, "Found an input method " + imi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3741 | } |
Tadashi G. Takaoka | 3c23d5b | 2016-09-16 11:41:07 +0900 | [diff] [blame] | 3742 | } catch (Exception e) { |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 3743 | Slog.wtf(TAG, "Unable to load input method " + imeId, e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3744 | } |
| 3745 | } |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | @GuardedBy("mMethodMap") |
| 3749 | void buildInputMethodListLocked(boolean resetDefaultEnabledIme) { |
| 3750 | if (DEBUG) { |
| 3751 | Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme |
| 3752 | + " \n ------ caller=" + Debug.getCallers(10)); |
| 3753 | } |
| 3754 | if (!mSystemReady) { |
| 3755 | Slog.e(TAG, "buildInputMethodListLocked is not allowed until system is ready"); |
| 3756 | return; |
| 3757 | } |
| 3758 | mMethodMapUpdateCount++; |
| 3759 | mMyPackageMonitor.clearKnownImePackageNamesLocked(); |
| 3760 | |
| 3761 | queryInputMethodServicesInternal(mContext, mSettings.getCurrentUserId(), |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3762 | mAdditionalSubtypeMap, mMethodMap, mMethodList); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 3763 | |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 3764 | // Construct the set of possible IME packages for onPackageChanged() to avoid false |
| 3765 | // negatives when the package state remains to be the same but only the component state is |
| 3766 | // changed. |
| 3767 | { |
| 3768 | // Here we intentionally use PackageManager.MATCH_DISABLED_COMPONENTS since the purpose |
| 3769 | // of this query is to avoid false negatives. PackageManager.MATCH_ALL could be more |
| 3770 | // conservative, but it seems we cannot use it for now (Issue 35176630). |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 3771 | final List<ResolveInfo> allInputMethodServices = |
| 3772 | mContext.getPackageManager().queryIntentServicesAsUser( |
| 3773 | new Intent(InputMethod.SERVICE_INTERFACE), |
| 3774 | PackageManager.MATCH_DISABLED_COMPONENTS, mSettings.getCurrentUserId()); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 3775 | final int N = allInputMethodServices.size(); |
| 3776 | for (int i = 0; i < N; ++i) { |
| 3777 | final ServiceInfo si = allInputMethodServices.get(i).serviceInfo; |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 3778 | if (android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) { |
| 3779 | mMyPackageMonitor.addKnownImePackageNameLocked(si.packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 3780 | } |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 3781 | } |
| 3782 | } |
| 3783 | |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3784 | boolean reenableMinimumNonAuxSystemImes = false; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3785 | // TODO: The following code should find better place to live. |
| 3786 | if (!resetDefaultEnabledIme) { |
| 3787 | boolean enabledImeFound = false; |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3788 | boolean enabledNonAuxImeFound = false; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3789 | final List<InputMethodInfo> enabledImes = mSettings.getEnabledInputMethodListLocked(); |
| 3790 | final int N = enabledImes.size(); |
| 3791 | for (int i = 0; i < N; ++i) { |
| 3792 | final InputMethodInfo imi = enabledImes.get(i); |
| 3793 | if (mMethodList.contains(imi)) { |
| 3794 | enabledImeFound = true; |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3795 | if (!imi.isAuxiliaryIme()) { |
| 3796 | enabledNonAuxImeFound = true; |
| 3797 | break; |
| 3798 | } |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3799 | } |
| 3800 | } |
| 3801 | if (!enabledImeFound) { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 3802 | if (DEBUG) { |
| 3803 | Slog.i(TAG, "All the enabled IMEs are gone. Reset default enabled IMEs."); |
| 3804 | } |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3805 | resetDefaultEnabledIme = true; |
| 3806 | resetSelectedInputMethodAndSubtypeLocked(""); |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3807 | } else if (!enabledNonAuxImeFound) { |
| 3808 | if (DEBUG) { |
| 3809 | Slog.i(TAG, "All the enabled non-Aux IMEs are gone. Do partial reset."); |
| 3810 | } |
| 3811 | reenableMinimumNonAuxSystemImes = true; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 3812 | } |
| 3813 | } |
| 3814 | |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3815 | if (resetDefaultEnabledIme || reenableMinimumNonAuxSystemImes) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3816 | final ArrayList<InputMethodInfo> defaultEnabledIme = |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 3817 | InputMethodUtils.getDefaultEnabledImes(mContext, mMethodList, |
| 3818 | reenableMinimumNonAuxSystemImes); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 3819 | final int N = defaultEnabledIme.size(); |
| 3820 | for (int i = 0; i < N; ++i) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 3821 | final InputMethodInfo imi = defaultEnabledIme.get(i); |
| 3822 | if (DEBUG) { |
| 3823 | Slog.d(TAG, "--- enable ime = " + imi); |
| 3824 | } |
| 3825 | setInputMethodEnabledLocked(imi.getId(), true); |
| 3826 | } |
| 3827 | } |
| 3828 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3829 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3830 | if (!TextUtils.isEmpty(defaultImiId)) { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3831 | if (!mMethodMap.containsKey(defaultImiId)) { |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3832 | Slog.w(TAG, "Default IME is uninstalled. Choose new default IME."); |
| 3833 | if (chooseNewDefaultIMELocked()) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3834 | updateInputMethodsFromSettingsLocked(true); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 3835 | } |
| 3836 | } else { |
| 3837 | // Double check that the default IME is certainly enabled. |
| 3838 | setInputMethodEnabledLocked(defaultImiId, true); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 3839 | } |
| 3840 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 3841 | // Here is not the perfect place to reset the switching controller. Ideally |
| 3842 | // mSwitchingController and mSettings should be able to share the same state. |
| 3843 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 3844 | // the same enabled IMEs list. |
Yohei Yukawa | c834a25 | 2014-05-21 22:42:32 +0900 | [diff] [blame] | 3845 | mSwitchingController.resetCircularListLocked(mContext); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3846 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3848 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3849 | |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3850 | private void showInputMethodAndSubtypeEnabler(String inputMethodId) { |
Tadashi G. Takaoka | f49688f | 2011-01-20 17:56:13 +0900 | [diff] [blame] | 3851 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3852 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
satok | 86417ea | 2010-10-27 14:11:03 +0900 | [diff] [blame] | 3853 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 3854 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3855 | if (!TextUtils.isEmpty(inputMethodId)) { |
Tadashi G. Takaoka | 2548020 | 2011-01-20 23:13:02 +0900 | [diff] [blame] | 3856 | intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3857 | } |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 3858 | final int userId; |
| 3859 | synchronized (mMethodMap) { |
| 3860 | userId = mSettings.getCurrentUserId(); |
| 3861 | } |
| 3862 | mContext.startActivityAsUser(intent, null, UserHandle.of(userId)); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | private void showConfigureInputMethods() { |
| 3866 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS); |
| 3867 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 3868 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 3869 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Satoshi Kataoka | 3ba439d | 2012-10-05 18:30:13 +0900 | [diff] [blame] | 3870 | mContext.startActivityAsUser(intent, null, UserHandle.CURRENT); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3871 | } |
| 3872 | |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 3873 | private boolean isScreenLocked() { |
| 3874 | return mKeyguardManager != null |
| 3875 | && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure(); |
| 3876 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3877 | |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3878 | private void showInputMethodMenu(boolean showAuxSubtypes, int displayId) { |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3879 | 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] | 3880 | |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 3881 | final boolean isScreenLocked = isScreenLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3882 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3883 | final String lastInputMethodId = mSettings.getSelectedInputMethod(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3884 | int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3885 | if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3886 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3887 | synchronized (mMethodMap) { |
Yohei Yukawa | cf3bbff | 2018-11-20 17:24:20 -0800 | [diff] [blame] | 3888 | final List<ImeSubtypeListItem> imList = |
| 3889 | mSwitchingController.getSortedInputMethodAndSubtypeListLocked( |
| 3890 | showAuxSubtypes, isScreenLocked); |
| 3891 | if (imList.isEmpty()) { |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 3892 | return; |
| 3893 | } |
| 3894 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3895 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3896 | |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3897 | if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3898 | final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3899 | if (currentSubtype != null) { |
| 3900 | final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3901 | lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
| 3902 | currentImi, currentSubtype.hashCode()); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 3903 | } |
| 3904 | } |
| 3905 | |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 3906 | final int N = imList.size(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3907 | mIms = new InputMethodInfo[N]; |
| 3908 | mSubtypeIds = new int[N]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3909 | int checkedItem = 0; |
| 3910 | for (int i = 0; i < N; ++i) { |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 3911 | final ImeSubtypeListItem item = imList.get(i); |
| 3912 | mIms[i] = item.mImi; |
| 3913 | mSubtypeIds[i] = item.mSubtypeId; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3914 | if (mIms[i].getId().equals(lastInputMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3915 | int subtypeId = mSubtypeIds[i]; |
| 3916 | if ((subtypeId == NOT_A_SUBTYPE_ID) |
| 3917 | || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) |
| 3918 | || (subtypeId == lastInputMethodSubtypeId)) { |
| 3919 | checkedItem = i; |
| 3920 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 3921 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3922 | } |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3923 | |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3924 | final ActivityThread currentThread = ActivityThread.currentActivityThread(); |
Andrew Sapperstein | 8a3b4cb | 2017-04-28 14:35:31 -0700 | [diff] [blame] | 3925 | final Context settingsContext = new ContextThemeWrapper( |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3926 | displayId == DEFAULT_DISPLAY ? currentThread.getSystemUiContext() |
| 3927 | : currentThread.createSystemUiContext(displayId), |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3928 | com.android.internal.R.style.Theme_DeviceDefault_Settings); |
| 3929 | |
| 3930 | mDialogBuilder = new AlertDialog.Builder(settingsContext); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3931 | mDialogBuilder.setOnCancelListener(new OnCancelListener() { |
| 3932 | @Override |
| 3933 | public void onCancel(DialogInterface dialog) { |
| 3934 | hideInputMethodMenu(); |
| 3935 | } |
| 3936 | }); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3937 | |
| 3938 | final Context dialogContext = mDialogBuilder.getContext(); |
| 3939 | final TypedArray a = dialogContext.obtainStyledAttributes(null, |
| 3940 | com.android.internal.R.styleable.DialogPreference, |
| 3941 | com.android.internal.R.attr.alertDialogStyle, 0); |
| 3942 | final Drawable dialogIcon = a.getDrawable( |
| 3943 | com.android.internal.R.styleable.DialogPreference_dialogIcon); |
| 3944 | a.recycle(); |
| 3945 | |
| 3946 | mDialogBuilder.setIcon(dialogIcon); |
| 3947 | |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 3948 | final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3949 | final View tv = inflater.inflate( |
| 3950 | com.android.internal.R.layout.input_method_switch_dialog_title, null); |
| 3951 | mDialogBuilder.setCustomTitle(tv); |
| 3952 | |
| 3953 | // Setup layout for a toggle switch of the hardware keyboard |
| 3954 | mSwitchingDialogTitleView = tv; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3955 | mSwitchingDialogTitleView |
| 3956 | .findViewById(com.android.internal.R.id.hard_keyboard_section) |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 3957 | .setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3958 | ? View.VISIBLE : View.GONE); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3959 | final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById( |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3960 | com.android.internal.R.id.hard_keyboard_switch); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3961 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3962 | hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
| 3963 | @Override |
| 3964 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3965 | mSettings.setShowImeWithHardKeyboard(isChecked); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3966 | // Ensure that the input method dialog is dismissed when changing |
| 3967 | // the hardware keyboard state. |
| 3968 | hideInputMethodMenu(); |
| 3969 | } |
| 3970 | }); |
| 3971 | |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 3972 | final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3973 | com.android.internal.R.layout.input_method_switch_item, imList, checkedItem); |
| 3974 | final OnClickListener choiceListener = new OnClickListener() { |
| 3975 | @Override |
| 3976 | public void onClick(final DialogInterface dialog, final int which) { |
| 3977 | synchronized (mMethodMap) { |
| 3978 | if (mIms == null || mIms.length <= which || mSubtypeIds == null |
| 3979 | || mSubtypeIds.length <= which) { |
| 3980 | return; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3981 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3982 | final InputMethodInfo im = mIms[which]; |
| 3983 | int subtypeId = mSubtypeIds[which]; |
| 3984 | adapter.mCheckedItem = which; |
| 3985 | adapter.notifyDataSetChanged(); |
| 3986 | hideInputMethodMenu(); |
| 3987 | if (im != null) { |
| 3988 | if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) { |
| 3989 | subtypeId = NOT_A_SUBTYPE_ID; |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 3990 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3991 | setInputMethodLocked(im.getId(), subtypeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3992 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 3993 | } |
| 3994 | } |
| 3995 | }; |
| 3996 | mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3997 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3998 | mSwitchingDialog = mDialogBuilder.create(); |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 3999 | mSwitchingDialog.setCanceledOnTouchOutside(true); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4000 | final Window w = mSwitchingDialog.getWindow(); |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 4001 | final LayoutParams attrs = w.getAttributes(); |
| 4002 | w.setType(LayoutParams.TYPE_INPUT_METHOD_DIALOG); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4003 | // Use an alternate token for the dialog for that window manager can group the token |
| 4004 | // with other IME windows based on type vs. grouping based on whichever token happens |
| 4005 | // to get selected by the system later on. |
| 4006 | attrs.token = mSwitchingDialogToken; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 4007 | attrs.privateFlags |= LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4008 | attrs.setTitle("Select input method"); |
| 4009 | w.setAttributes(attrs); |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 4010 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4011 | mSwitchingDialog.show(); |
| 4012 | } |
| 4013 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4014 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4015 | private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> { |
| 4016 | private final LayoutInflater mInflater; |
| 4017 | private final int mTextViewResourceId; |
| 4018 | private final List<ImeSubtypeListItem> mItemsList; |
Satoshi Kataoka | d214296 | 2012-11-12 18:43:06 +0900 | [diff] [blame] | 4019 | public int mCheckedItem; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4020 | public ImeSubtypeListAdapter(Context context, int textViewResourceId, |
| 4021 | List<ImeSubtypeListItem> itemsList, int checkedItem) { |
| 4022 | super(context, textViewResourceId, itemsList); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4023 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4024 | mTextViewResourceId = textViewResourceId; |
| 4025 | mItemsList = itemsList; |
| 4026 | mCheckedItem = checkedItem; |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 4027 | mInflater = context.getSystemService(LayoutInflater.class); |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4028 | } |
| 4029 | |
| 4030 | @Override |
| 4031 | public View getView(int position, View convertView, ViewGroup parent) { |
| 4032 | final View view = convertView != null ? convertView |
| 4033 | : mInflater.inflate(mTextViewResourceId, null); |
| 4034 | if (position < 0 || position >= mItemsList.size()) return view; |
| 4035 | final ImeSubtypeListItem item = mItemsList.get(position); |
| 4036 | final CharSequence imeName = item.mImeName; |
| 4037 | final CharSequence subtypeName = item.mSubtypeName; |
| 4038 | final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1); |
| 4039 | final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2); |
| 4040 | if (TextUtils.isEmpty(subtypeName)) { |
| 4041 | firstTextView.setText(imeName); |
| 4042 | secondTextView.setVisibility(View.GONE); |
| 4043 | } else { |
| 4044 | firstTextView.setText(subtypeName); |
| 4045 | secondTextView.setText(imeName); |
| 4046 | secondTextView.setVisibility(View.VISIBLE); |
| 4047 | } |
| 4048 | final RadioButton radioButton = |
| 4049 | (RadioButton)view.findViewById(com.android.internal.R.id.radio); |
| 4050 | radioButton.setChecked(position == mCheckedItem); |
| 4051 | return view; |
| 4052 | } |
| 4053 | } |
| 4054 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4055 | void hideInputMethodMenu() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4056 | synchronized (mMethodMap) { |
| 4057 | hideInputMethodMenuLocked(); |
| 4058 | } |
| 4059 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4060 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4061 | void hideInputMethodMenuLocked() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4062 | if (DEBUG) Slog.v(TAG, "Hide switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4063 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4064 | if (mSwitchingDialog != null) { |
| 4065 | mSwitchingDialog.dismiss(); |
| 4066 | mSwitchingDialog = null; |
Yohei Yukawa | 1fc7a1d | 2018-04-18 17:31:27 -0700 | [diff] [blame] | 4067 | mSwitchingDialogTitleView = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4068 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4069 | |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 4070 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4071 | mDialogBuilder = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4072 | mIms = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4073 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4075 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4076 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4077 | boolean setInputMethodEnabledLocked(String id, boolean enabled) { |
| 4078 | // Make sure this is a valid input method. |
| 4079 | InputMethodInfo imm = mMethodMap.get(id); |
| 4080 | if (imm == null) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4081 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4082 | } |
| 4083 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4084 | List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings |
| 4085 | .getEnabledInputMethodsAndSubtypeListLocked(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4086 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4087 | if (enabled) { |
| 4088 | for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) { |
| 4089 | if (pair.first.equals(id)) { |
| 4090 | // We are enabling this input method, but it is already enabled. |
| 4091 | // Nothing to do. The previous state was enabled. |
| 4092 | return true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4093 | } |
| 4094 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4095 | mSettings.appendAndPutEnabledInputMethodLocked(id, false); |
| 4096 | // Previous state was disabled. |
| 4097 | return false; |
| 4098 | } else { |
| 4099 | StringBuilder builder = new StringBuilder(); |
| 4100 | if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 4101 | builder, enabledInputMethodsList, id)) { |
| 4102 | // Disabled input method is currently selected, switch to another one. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4103 | final String selId = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 4104 | if (id.equals(selId) && !chooseNewDefaultIMELocked()) { |
| 4105 | Slog.i(TAG, "Can't find new IME, unsetting the current input method."); |
| 4106 | resetSelectedInputMethodAndSubtypeLocked(""); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4107 | } |
| 4108 | // Previous state was enabled. |
| 4109 | return true; |
| 4110 | } else { |
| 4111 | // We are disabling the input method but it is already disabled. |
| 4112 | // Nothing to do. The previous state was disabled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4113 | return false; |
| 4114 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4115 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4116 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 4117 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4118 | private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId, |
| 4119 | boolean setSubtypeOnly) { |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 4120 | mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype); |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 4121 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4122 | // Set Subtype here |
| 4123 | if (imi == null || subtypeId < 0) { |
| 4124 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
Tadashi G. Takaoka | 0ba75bb | 2010-11-09 12:19:32 -0800 | [diff] [blame] | 4125 | mCurrentSubtype = null; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4126 | } else { |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 4127 | if (subtypeId < imi.getSubtypeCount()) { |
| 4128 | InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId); |
| 4129 | mSettings.putSelectedSubtype(subtype.hashCode()); |
| 4130 | mCurrentSubtype = subtype; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4131 | } else { |
| 4132 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 4133 | // If the subtype is not specified, choose the most applicable one |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4134 | mCurrentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4135 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4136 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4137 | |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 4138 | if (!setSubtypeOnly) { |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4139 | // Set InputMethod here |
| 4140 | mSettings.putSelectedInputMethod(imi != null ? imi.getId() : ""); |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) { |
| 4145 | InputMethodInfo imi = mMethodMap.get(newDefaultIme); |
| 4146 | int lastSubtypeId = NOT_A_SUBTYPE_ID; |
| 4147 | // newDefaultIme is empty when there is no candidate for the selected IME. |
| 4148 | if (imi != null && !TextUtils.isEmpty(newDefaultIme)) { |
| 4149 | String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme); |
| 4150 | if (subtypeHashCode != null) { |
| 4151 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4152 | lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 4153 | imi, Integer.parseInt(subtypeHashCode)); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4154 | } catch (NumberFormatException e) { |
| 4155 | Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e); |
| 4156 | } |
| 4157 | } |
| 4158 | } |
| 4159 | setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4160 | } |
| 4161 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4162 | /** |
| 4163 | * @return Return the current subtype of this input method. |
| 4164 | */ |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 4165 | @Override |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4166 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4167 | synchronized (mMethodMap) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 4168 | // TODO: Make this work even for non-current users? |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 4169 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 4170 | return null; |
| 4171 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4172 | return getCurrentInputMethodSubtypeLocked(); |
| 4173 | } |
| 4174 | } |
| 4175 | |
| 4176 | private InputMethodSubtype getCurrentInputMethodSubtypeLocked() { |
satok | fdf419e | 2012-05-08 16:52:08 +0900 | [diff] [blame] | 4177 | if (mCurMethodId == null) { |
| 4178 | return null; |
| 4179 | } |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4180 | final boolean subtypeIsSelected = mSettings.isSubtypeSelected(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4181 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 4182 | if (imi == null || imi.getSubtypeCount() == 0) { |
| 4183 | return null; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4184 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4185 | if (!subtypeIsSelected || mCurrentSubtype == null |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4186 | || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) { |
| 4187 | int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4188 | if (subtypeId == NOT_A_SUBTYPE_ID) { |
| 4189 | // If there are no selected subtypes, the framework will try to find |
| 4190 | // the most applicable subtype from explicitly or implicitly enabled |
| 4191 | // subtypes. |
| 4192 | List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4193 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4194 | // If there is only one explicitly or implicitly enabled subtype, |
| 4195 | // just returns it. |
| 4196 | if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) { |
| 4197 | mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0); |
| 4198 | } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4199 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4200 | mRes, explicitlyOrImplicitlyEnabledSubtypes, |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4201 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4202 | if (mCurrentSubtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4203 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4204 | mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, |
| 4205 | true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4206 | } |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 4207 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4208 | } else { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4209 | mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId); |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 4210 | } |
| 4211 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4212 | return mCurrentSubtype; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4213 | } |
| 4214 | |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 4215 | private List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId) { |
| 4216 | synchronized (mMethodMap) { |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 4217 | return getInputMethodListLocked(userId); |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 4218 | } |
| 4219 | } |
| 4220 | |
| 4221 | private List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId) { |
| 4222 | synchronized (mMethodMap) { |
| 4223 | return getEnabledInputMethodListLocked(userId); |
| 4224 | } |
| 4225 | } |
| 4226 | |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 4227 | private static final class LocalServiceImpl extends InputMethodManagerInternal { |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4228 | @NonNull |
Yohei Yukawa | fffc0e5 | 2018-09-04 13:24:00 -0700 | [diff] [blame] | 4229 | private final InputMethodManagerService mService; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4230 | |
Yohei Yukawa | fffc0e5 | 2018-09-04 13:24:00 -0700 | [diff] [blame] | 4231 | LocalServiceImpl(@NonNull InputMethodManagerService service) { |
| 4232 | mService = service; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | @Override |
| 4236 | public void setInteractive(boolean interactive) { |
| 4237 | // Do everything in handler so as not to block the caller. |
Yohei Yukawa | f16abb7 | 2018-09-05 11:28:42 -0700 | [diff] [blame] | 4238 | mService.mHandler.obtainMessage(MSG_SET_INTERACTIVE, interactive ? 1 : 0, 0) |
| 4239 | .sendToTarget(); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4240 | } |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 4241 | |
| 4242 | @Override |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 4243 | public void hideCurrentInputMethod() { |
Yohei Yukawa | f16abb7 | 2018-09-05 11:28:42 -0700 | [diff] [blame] | 4244 | mService.mHandler.removeMessages(MSG_HIDE_CURRENT_INPUT_METHOD); |
| 4245 | mService.mHandler.sendEmptyMessage(MSG_HIDE_CURRENT_INPUT_METHOD); |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 4246 | } |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 4247 | |
| 4248 | @Override |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 4249 | public List<InputMethodInfo> getInputMethodListAsUser(int userId) { |
| 4250 | return mService.getInputMethodListAsUser(userId); |
| 4251 | } |
| 4252 | |
| 4253 | @Override |
| 4254 | public List<InputMethodInfo> getEnabledInputMethodListAsUser(int userId) { |
| 4255 | return mService.getEnabledInputMethodListAsUser(userId); |
| 4256 | } |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4257 | } |
| 4258 | |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4259 | @BinderThread |
| 4260 | private IInputContentUriToken createInputContentUriToken(@Nullable IBinder token, |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4261 | @Nullable Uri contentUri, @Nullable String packageName) { |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4262 | if (token == null) { |
| 4263 | throw new NullPointerException("token"); |
| 4264 | } |
| 4265 | if (packageName == null) { |
| 4266 | throw new NullPointerException("packageName"); |
| 4267 | } |
| 4268 | if (contentUri == null) { |
| 4269 | throw new NullPointerException("contentUri"); |
| 4270 | } |
| 4271 | final String contentUriScheme = contentUri.getScheme(); |
| 4272 | if (!"content".equals(contentUriScheme)) { |
| 4273 | throw new InvalidParameterException("contentUri must have content scheme"); |
| 4274 | } |
| 4275 | |
| 4276 | synchronized (mMethodMap) { |
| 4277 | final int uid = Binder.getCallingUid(); |
| 4278 | if (mCurMethodId == null) { |
| 4279 | return null; |
| 4280 | } |
| 4281 | if (mCurToken != token) { |
| 4282 | Slog.e(TAG, "Ignoring createInputContentUriToken mCurToken=" + mCurToken |
| 4283 | + " token=" + token); |
| 4284 | return null; |
| 4285 | } |
| 4286 | // We cannot simply distinguish a bad IME that reports an arbitrary package name from |
| 4287 | // an unfortunate IME whose internal state is already obsolete due to the asynchronous |
| 4288 | // nature of our system. Let's compare it with our internal record. |
| 4289 | if (!TextUtils.equals(mCurAttribute.packageName, packageName)) { |
| 4290 | Slog.e(TAG, "Ignoring createInputContentUriToken mCurAttribute.packageName=" |
| 4291 | + mCurAttribute.packageName + " packageName=" + packageName); |
| 4292 | return null; |
| 4293 | } |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4294 | // This user ID can never bee spoofed. |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4295 | final int imeUserId = UserHandle.getUserId(uid); |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4296 | // This user ID can never bee spoofed. |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4297 | final int appUserId = UserHandle.getUserId(mCurClient.uid); |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4298 | // This user ID may be invalid if "contentUri" embedded an invalid user ID. |
| 4299 | final int contentUriOwnerUserId = ContentProvider.getUserIdFromUri(contentUri, |
| 4300 | imeUserId); |
| 4301 | final Uri contentUriWithoutUserId = ContentProvider.getUriWithoutUserId(contentUri); |
| 4302 | // Note: InputContentUriTokenHandler.take() checks whether the IME (specified by "uid") |
| 4303 | // actually has the right to grant a read permission for "contentUriWithoutUserId" that |
| 4304 | // is claimed to belong to "contentUriOwnerUserId". For example, specifying random |
| 4305 | // content URI and/or contentUriOwnerUserId just results in a SecurityException thrown |
| 4306 | // from InputContentUriTokenHandler.take() and can never be allowed beyond what is |
| 4307 | // actually allowed to "uid", which is guaranteed to be the IME's one. |
| 4308 | return new InputContentUriTokenHandler(contentUriWithoutUserId, uid, |
| 4309 | packageName, contentUriOwnerUserId, appUserId); |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4310 | } |
| 4311 | } |
| 4312 | |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4313 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 4314 | private void reportFullscreenMode(@NonNull IBinder token, boolean fullscreen) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4315 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 4316 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4317 | return; |
| 4318 | } |
| 4319 | if (mCurClient != null && mCurClient.client != null) { |
| 4320 | mInFullscreenMode = fullscreen; |
| 4321 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 4322 | MSG_REPORT_FULLSCREEN_MODE, fullscreen ? 1 : 0, mCurClient)); |
| 4323 | } |
| 4324 | } |
| 4325 | } |
| 4326 | |
| 4327 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4328 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 4329 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4330 | |
| 4331 | IInputMethod method; |
| 4332 | ClientState client; |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4333 | ClientState focusedWindowClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4335 | final Printer p = new PrintWriterPrinter(pw); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4336 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4337 | synchronized (mMethodMap) { |
| 4338 | p.println("Current Input Method Manager state:"); |
| 4339 | int N = mMethodList.size(); |
Yohei Yukawa | 5ec1fce | 2018-12-17 07:56:14 -0800 | [diff] [blame] | 4340 | p.println(" Input Methods: mMethodMapUpdateCount=" + mMethodMapUpdateCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4341 | for (int i=0; i<N; i++) { |
| 4342 | InputMethodInfo info = mMethodList.get(i); |
| 4343 | p.println(" InputMethod #" + i + ":"); |
| 4344 | info.dump(p, " "); |
| 4345 | } |
| 4346 | p.println(" Clients:"); |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 4347 | final int numClients = mClients.size(); |
| 4348 | for (int i = 0; i < numClients; ++i) { |
| 4349 | final ClientState ci = mClients.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4350 | p.println(" Client " + ci + ":"); |
| 4351 | p.println(" client=" + ci.client); |
| 4352 | p.println(" inputContext=" + ci.inputContext); |
| 4353 | p.println(" sessionRequested=" + ci.sessionRequested); |
| 4354 | p.println(" curSession=" + ci.curSession); |
| 4355 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4356 | p.println(" mCurMethodId=" + mCurMethodId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4357 | client = mCurClient; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 4358 | p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq); |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 4359 | p.println(" mCurFocusedWindow=" + mCurFocusedWindow |
| 4360 | + " softInputMode=" + |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 4361 | InputMethodDebug.softInputModeToString(mCurFocusedWindowSoftInputMode) |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 4362 | + " client=" + mCurFocusedWindowClient); |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4363 | focusedWindowClient = mCurFocusedWindowClient; |
Yohei Yukawa | d3ef842 | 2018-06-07 16:28:07 -0700 | [diff] [blame] | 4364 | p.println(" mCurId=" + mCurId + " mHaveConnection=" + mHaveConnection |
| 4365 | + " mBoundToMethod=" + mBoundToMethod + " mVisibleBound=" + mVisibleBound); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4366 | p.println(" mCurToken=" + mCurToken); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 4367 | p.println(" mCurTokenDisplayId=" + mCurTokenDisplayId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4368 | p.println(" mCurIntent=" + mCurIntent); |
| 4369 | method = mCurMethod; |
| 4370 | p.println(" mCurMethod=" + mCurMethod); |
| 4371 | p.println(" mEnabledSession=" + mEnabledSession); |
| 4372 | p.println(" mShowRequested=" + mShowRequested |
| 4373 | + " mShowExplicitlyRequested=" + mShowExplicitlyRequested |
| 4374 | + " mShowForced=" + mShowForced |
| 4375 | + " mInputShown=" + mInputShown); |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4376 | p.println(" mInFullscreenMode=" + mInFullscreenMode); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4377 | p.println(" mSystemReady=" + mSystemReady + " mInteractive=" + mIsInteractive); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 4378 | p.println(" mSettingsObserver=" + mSettingsObserver); |
Yohei Yukawa | d724886 | 2015-06-03 23:56:12 -0700 | [diff] [blame] | 4379 | p.println(" mSwitchingController:"); |
| 4380 | mSwitchingController.dump(p); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 4381 | p.println(" mSettings:"); |
| 4382 | mSettings.dumpLocked(p, " "); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 4383 | |
| 4384 | p.println(" mStartInputHistory:"); |
| 4385 | mStartInputHistory.dump(pw, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4386 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4387 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4388 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4389 | if (client != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4390 | pw.flush(); |
| 4391 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4392 | TransferPipe.dumpAsync(client.client.asBinder(), fd, args); |
| 4393 | } catch (IOException | RemoteException e) { |
| 4394 | p.println("Failed to dump input method client: " + e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4395 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4396 | } else { |
| 4397 | p.println("No input method client."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4398 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4399 | |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4400 | if (focusedWindowClient != null && client != focusedWindowClient) { |
| 4401 | p.println(" "); |
| 4402 | p.println("Warning: Current input method client doesn't match the last focused. " |
| 4403 | + "window."); |
| 4404 | p.println("Dumping input method client in the last focused window just in case."); |
| 4405 | p.println(" "); |
| 4406 | pw.flush(); |
| 4407 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4408 | TransferPipe.dumpAsync(focusedWindowClient.client.asBinder(), fd, args); |
| 4409 | } catch (IOException | RemoteException e) { |
| 4410 | p.println("Failed to dump input method client in focused window: " + e); |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4411 | } |
| 4412 | } |
| 4413 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4414 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4415 | if (method != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4416 | pw.flush(); |
| 4417 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4418 | TransferPipe.dumpAsync(method.asBinder(), fd, args); |
| 4419 | } catch (IOException | RemoteException e) { |
| 4420 | p.println("Failed to dump input method service: " + e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4421 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4422 | } else { |
| 4423 | p.println("No input method service."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4424 | } |
| 4425 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4426 | |
| 4427 | @BinderThread |
| 4428 | @Override |
| 4429 | public void onShellCommand(@Nullable FileDescriptor in, @Nullable FileDescriptor out, |
| 4430 | @Nullable FileDescriptor err, |
| 4431 | @NonNull String[] args, @Nullable ShellCallback callback, |
| 4432 | @NonNull ResultReceiver resultReceiver) throws RemoteException { |
Yohei Yukawa | b8d240f | 2018-12-26 10:03:11 -0800 | [diff] [blame] | 4433 | final int callingUid = Binder.getCallingUid(); |
| 4434 | // Reject any incoming calls from non-shell users, including ones from the system user. |
| 4435 | if (callingUid != Process.ROOT_UID && callingUid != Process.SHELL_UID) { |
| 4436 | // Note that Binder#onTransact() will automatically close "in", "out", and "err" when |
| 4437 | // returned from this method, hence there is no need to close those FDs. |
| 4438 | // "resultReceiver" is the only thing that needs to be taken care of here. |
| 4439 | if (resultReceiver != null) { |
| 4440 | resultReceiver.send(ShellCommandResult.FAILURE, null); |
| 4441 | } |
| 4442 | final String errorMsg = "InputMethodManagerService does not support shell commands from" |
| 4443 | + " non-shell users. callingUid=" + callingUid |
| 4444 | + " args=" + Arrays.toString(args); |
| 4445 | if (Process.isCoreUid(callingUid)) { |
| 4446 | // Let's not crash the calling process if the caller is one of core components. |
| 4447 | Slog.e(TAG, errorMsg); |
| 4448 | return; |
| 4449 | } |
| 4450 | throw new SecurityException(errorMsg); |
| 4451 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4452 | new ShellCommandImpl(this).exec( |
| 4453 | this, in, out, err, args, callback, resultReceiver); |
| 4454 | } |
| 4455 | |
| 4456 | private static final class ShellCommandImpl extends ShellCommand { |
| 4457 | @NonNull |
| 4458 | final InputMethodManagerService mService; |
| 4459 | |
| 4460 | ShellCommandImpl(InputMethodManagerService service) { |
| 4461 | mService = service; |
| 4462 | } |
| 4463 | |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 4464 | @RequiresPermission(allOf = { |
Yohei Yukawa | 8a2b96b | 2018-12-28 17:23:29 -0800 | [diff] [blame] | 4465 | Manifest.permission.DUMP, |
| 4466 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 4467 | Manifest.permission.WRITE_SECURE_SETTINGS, |
Yohei Yukawa | 8a2b96b | 2018-12-28 17:23:29 -0800 | [diff] [blame] | 4468 | }) |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4469 | @BinderThread |
| 4470 | @ShellCommandResult |
| 4471 | @Override |
| 4472 | public int onCommand(@Nullable String cmd) { |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 4473 | // For shell command, require all the permissions here in favor of code simplicity. |
Yohei Yukawa | 8a2b96b | 2018-12-28 17:23:29 -0800 | [diff] [blame] | 4474 | Arrays.asList( |
| 4475 | Manifest.permission.DUMP, |
| 4476 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 4477 | Manifest.permission.WRITE_SECURE_SETTINGS |
| 4478 | ).forEach(permission -> mService.mContext.enforceCallingPermission(permission, null)); |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 4479 | |
| 4480 | final long identity = Binder.clearCallingIdentity(); |
| 4481 | try { |
| 4482 | return onCommandWithSystemIdentity(cmd); |
| 4483 | } finally { |
| 4484 | Binder.restoreCallingIdentity(identity); |
| 4485 | } |
| 4486 | } |
| 4487 | |
| 4488 | @BinderThread |
| 4489 | @ShellCommandResult |
| 4490 | private int onCommandWithSystemIdentity(@Nullable String cmd) { |
Yohei Yukawa | dfdab73 | 2018-02-21 07:16:30 +0900 | [diff] [blame] | 4491 | if ("refresh_debug_properties".equals(cmd)) { |
| 4492 | return refreshDebugProperties(); |
| 4493 | } |
| 4494 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 4495 | if ("get-last-switch-user-id".equals(cmd)) { |
| 4496 | return mService.getLastSwitchUserId(this); |
| 4497 | } |
| 4498 | |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4499 | // For existing "adb shell ime <command>". |
| 4500 | if ("ime".equals(cmd)) { |
| 4501 | final String imeCommand = getNextArg(); |
| 4502 | if (imeCommand == null || "help".equals(imeCommand) || "-h".equals(imeCommand)) { |
| 4503 | onImeCommandHelp(); |
| 4504 | return ShellCommandResult.SUCCESS; |
| 4505 | } |
| 4506 | switch (imeCommand) { |
| 4507 | case "list": |
| 4508 | return mService.handleShellCommandListInputMethods(this); |
| 4509 | case "enable": |
| 4510 | return mService.handleShellCommandEnableDisableInputMethod(this, true); |
| 4511 | case "disable": |
| 4512 | return mService.handleShellCommandEnableDisableInputMethod(this, false); |
| 4513 | case "set": |
| 4514 | return mService.handleShellCommandSetInputMethod(this); |
| 4515 | case "reset": |
| 4516 | return mService.handleShellCommandResetInputMethod(this); |
| 4517 | default: |
| 4518 | getOutPrintWriter().println("Unknown command: " + imeCommand); |
| 4519 | return ShellCommandResult.FAILURE; |
| 4520 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4521 | } |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4522 | |
| 4523 | return handleDefaultCommands(cmd); |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | @BinderThread |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 4527 | @ShellCommandResult |
| 4528 | private int refreshDebugProperties() { |
| 4529 | DebugFlags.FLAG_OPTIMIZE_START_INPUT.refresh(); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 4530 | DebugFlags.FLAG_PRE_RENDER_IME_VIEWS.refresh(); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 4531 | return ShellCommandResult.SUCCESS; |
| 4532 | } |
| 4533 | |
| 4534 | @BinderThread |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4535 | @Override |
| 4536 | public void onHelp() { |
| 4537 | try (PrintWriter pw = getOutPrintWriter()) { |
| 4538 | pw.println("InputMethodManagerService commands:"); |
| 4539 | pw.println(" help"); |
| 4540 | pw.println(" Prints this help text."); |
| 4541 | pw.println(" dump [options]"); |
| 4542 | pw.println(" Synonym of dumpsys."); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4543 | pw.println(" ime <command> [options]"); |
| 4544 | pw.println(" Manipulate IMEs. Run \"ime help\" for details."); |
| 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | private void onImeCommandHelp() { |
| 4549 | try (IndentingPrintWriter pw = |
| 4550 | new IndentingPrintWriter(getOutPrintWriter(), " ", 100)) { |
| 4551 | pw.println("ime <command>:"); |
| 4552 | pw.increaseIndent(); |
| 4553 | |
| 4554 | pw.println("list [-a] [-s]"); |
| 4555 | pw.increaseIndent(); |
| 4556 | pw.println("prints all enabled input methods."); |
| 4557 | pw.increaseIndent(); |
| 4558 | pw.println("-a: see all input methods"); |
| 4559 | pw.println("-s: only a single summary line of each"); |
| 4560 | pw.decreaseIndent(); |
| 4561 | pw.decreaseIndent(); |
| 4562 | |
| 4563 | pw.println("enable <ID>"); |
| 4564 | pw.increaseIndent(); |
| 4565 | pw.println("allows the given input method ID to be used."); |
| 4566 | pw.decreaseIndent(); |
| 4567 | |
| 4568 | pw.println("disable <ID>"); |
| 4569 | pw.increaseIndent(); |
| 4570 | pw.println("disallows the given input method ID to be used."); |
| 4571 | pw.decreaseIndent(); |
| 4572 | |
| 4573 | pw.println("set <ID>"); |
| 4574 | pw.increaseIndent(); |
| 4575 | pw.println("switches to the given input method ID."); |
| 4576 | pw.decreaseIndent(); |
| 4577 | |
| 4578 | pw.println("reset"); |
| 4579 | pw.increaseIndent(); |
| 4580 | pw.println("reset currently selected/enabled IMEs to the default ones as if " |
| 4581 | + "the device is initially booted with the current locale."); |
| 4582 | pw.decreaseIndent(); |
| 4583 | |
| 4584 | pw.decreaseIndent(); |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4585 | } |
| 4586 | } |
| 4587 | } |
| 4588 | |
| 4589 | // ---------------------------------------------------------------------- |
| 4590 | // Shell command handlers: |
| 4591 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 4592 | @BinderThread |
| 4593 | @ShellCommandResult |
| 4594 | private int getLastSwitchUserId(@NonNull ShellCommand shellCommand) { |
| 4595 | synchronized (mMethodMap) { |
| 4596 | shellCommand.getOutPrintWriter().println(mLastSwitchUserId); |
| 4597 | return ShellCommandResult.SUCCESS; |
| 4598 | } |
| 4599 | } |
| 4600 | |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4601 | /** |
| 4602 | * Handles {@code adb shell ime list}. |
| 4603 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 4604 | * @return Exit code of the command. |
| 4605 | */ |
| 4606 | @BinderThread |
| 4607 | @ShellCommandResult |
| 4608 | private int handleShellCommandListInputMethods(@NonNull ShellCommand shellCommand) { |
| 4609 | boolean all = false; |
| 4610 | boolean brief = false; |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 4611 | int userIdToBeResolved = UserHandle.USER_CURRENT; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4612 | while (true) { |
| 4613 | final String nextOption = shellCommand.getNextOption(); |
| 4614 | if (nextOption == null) { |
| 4615 | break; |
| 4616 | } |
| 4617 | switch (nextOption) { |
| 4618 | case "-a": |
| 4619 | all = true; |
| 4620 | break; |
| 4621 | case "-s": |
| 4622 | brief = true; |
| 4623 | break; |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 4624 | case "-u": |
| 4625 | case "--user": |
| 4626 | userIdToBeResolved = UserHandle.parseUserArg(shellCommand.getNextArgRequired()); |
| 4627 | break; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4628 | } |
| 4629 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 4630 | synchronized (mMethodMap) { |
| 4631 | final PrintWriter pr = shellCommand.getOutPrintWriter(); |
| 4632 | final int[] userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, |
| 4633 | mSettings.getCurrentUserId(), shellCommand.getErrPrintWriter()); |
| 4634 | for (int userId : userIds) { |
| 4635 | final List<InputMethodInfo> methods = all |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 4636 | ? getInputMethodListLocked(userId) |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 4637 | : getEnabledInputMethodListLocked(userId); |
| 4638 | if (userIds.length > 1) { |
| 4639 | pr.print("User #"); |
| 4640 | pr.print(userId); |
| 4641 | pr.println(":"); |
| 4642 | } |
| 4643 | for (InputMethodInfo info : methods) { |
| 4644 | if (brief) { |
| 4645 | pr.println(info.getId()); |
| 4646 | } else { |
| 4647 | pr.print(info.getId()); |
| 4648 | pr.println(":"); |
| 4649 | info.dump(pr::println, " "); |
| 4650 | } |
| 4651 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4652 | } |
| 4653 | } |
| 4654 | return ShellCommandResult.SUCCESS; |
| 4655 | } |
| 4656 | |
| 4657 | /** |
| 4658 | * Handles {@code adb shell ime enable} and {@code adb shell ime disable}. |
| 4659 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 4660 | * @param enabled {@code true} if the command was {@code adb shell ime enable}. |
| 4661 | * @return Exit code of the command. |
| 4662 | */ |
| 4663 | @BinderThread |
| 4664 | @ShellCommandResult |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4665 | private int handleShellCommandEnableDisableInputMethod( |
| 4666 | @NonNull ShellCommand shellCommand, boolean enabled) { |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4667 | final String id = shellCommand.getNextArgRequired(); |
| 4668 | |
| 4669 | final boolean previouslyEnabled; |
| 4670 | synchronized (mMethodMap) { |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 4671 | previouslyEnabled = setInputMethodEnabledLocked(id, enabled); |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4672 | } |
| 4673 | final PrintWriter pr = shellCommand.getOutPrintWriter(); |
| 4674 | pr.print("Input method "); |
| 4675 | pr.print(id); |
| 4676 | pr.print(": "); |
| 4677 | pr.print((enabled == previouslyEnabled) ? "already " : "now "); |
| 4678 | pr.println(enabled ? "enabled" : "disabled"); |
| 4679 | return ShellCommandResult.SUCCESS; |
| 4680 | } |
| 4681 | |
| 4682 | /** |
| 4683 | * Handles {@code adb shell ime set}. |
| 4684 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 4685 | * @return Exit code of the command. |
| 4686 | */ |
| 4687 | @BinderThread |
| 4688 | @ShellCommandResult |
| 4689 | private int handleShellCommandSetInputMethod(@NonNull ShellCommand shellCommand) { |
| 4690 | final String id = shellCommand.getNextArgRequired(); |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 4691 | synchronized (mMethodMap) { |
| 4692 | setInputMethodLocked(id, NOT_A_SUBTYPE_ID); |
| 4693 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4694 | final PrintWriter pr = shellCommand.getOutPrintWriter(); |
| 4695 | pr.print("Input method "); |
| 4696 | pr.print(id); |
| 4697 | pr.println(" selected"); |
| 4698 | return ShellCommandResult.SUCCESS; |
| 4699 | } |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 4700 | |
| 4701 | /** |
| 4702 | * Handles {@code adb shell ime reset-ime}. |
| 4703 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 4704 | * @return Exit code of the command. |
| 4705 | */ |
| 4706 | @BinderThread |
| 4707 | @ShellCommandResult |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 4708 | private int handleShellCommandResetInputMethod(@NonNull ShellCommand shellCommand) { |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 4709 | synchronized (mMethodMap) { |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 4710 | final String nextIme; |
| 4711 | final List<InputMethodInfo> nextEnabledImes; |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 4712 | hideCurrentInputLocked(0, null); |
| 4713 | unbindCurrentMethodLocked(); |
| 4714 | // Reset the current IME |
| 4715 | resetSelectedInputMethodAndSubtypeLocked(null); |
| 4716 | // Also reset the settings of the current IME |
| 4717 | mSettings.putSelectedInputMethod(null); |
| 4718 | // Disable all enabled IMEs. |
| 4719 | mSettings.getEnabledInputMethodListLocked().forEach( |
| 4720 | imi -> setInputMethodEnabledLocked(imi.getId(), false)); |
| 4721 | // Re-enable with default enabled IMEs. |
| 4722 | InputMethodUtils.getDefaultEnabledImes(mContext, mMethodList).forEach( |
| 4723 | imi -> setInputMethodEnabledLocked(imi.getId(), true)); |
| 4724 | updateInputMethodsFromSettingsLocked(true /* enabledMayChange */); |
| 4725 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 4726 | mSettings.getEnabledInputMethodListLocked(), |
| 4727 | mSettings.getCurrentUserId(), |
| 4728 | mContext.getBasePackageName()); |
| 4729 | nextIme = mSettings.getSelectedInputMethod(); |
Yohei Yukawa | 9cd0c8a | 2019-02-04 22:25:24 -0800 | [diff] [blame] | 4730 | nextEnabledImes = mSettings.getEnabledInputMethodListLocked(); |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 4731 | final PrintWriter pr = shellCommand.getOutPrintWriter(); |
| 4732 | pr.println("Reset current and enabled IMEs"); |
| 4733 | pr.println("Newly selected IME:"); |
| 4734 | pr.print(" "); pr.println(nextIme); |
| 4735 | pr.println("Newly enabled IMEs:"); |
| 4736 | { |
| 4737 | final int N = nextEnabledImes.size(); |
| 4738 | for (int i = 0; i < N; ++i) { |
| 4739 | pr.print(" "); |
| 4740 | pr.println(nextEnabledImes.get(i).getId()); |
| 4741 | } |
| 4742 | } |
| 4743 | return ShellCommandResult.SUCCESS; |
| 4744 | } |
| 4745 | } |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4746 | |
| 4747 | private static final class InputMethodPrivilegedOperationsImpl |
| 4748 | extends IInputMethodPrivilegedOperations.Stub { |
| 4749 | private final InputMethodManagerService mImms; |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 4750 | @NonNull |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4751 | private final IBinder mToken; |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 4752 | InputMethodPrivilegedOperationsImpl(InputMethodManagerService imms, |
| 4753 | @NonNull IBinder token) { |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4754 | mImms = imms; |
| 4755 | mToken = token; |
| 4756 | } |
| 4757 | |
| 4758 | @BinderThread |
| 4759 | @Override |
| 4760 | public void setImeWindowStatus(int vis, int backDisposition) { |
| 4761 | mImms.setImeWindowStatus(mToken, vis, backDisposition); |
| 4762 | } |
| 4763 | |
| 4764 | @BinderThread |
| 4765 | @Override |
| 4766 | public void reportStartInput(IBinder startInputToken) { |
| 4767 | mImms.reportStartInput(mToken, startInputToken); |
| 4768 | } |
| 4769 | |
| 4770 | @BinderThread |
| 4771 | @Override |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4772 | public IInputContentUriToken createInputContentUriToken(Uri contentUri, |
| 4773 | String packageName) { |
| 4774 | return mImms.createInputContentUriToken(mToken, contentUri, packageName); |
| 4775 | } |
| 4776 | |
| 4777 | @BinderThread |
| 4778 | @Override |
| 4779 | public void reportFullscreenMode(boolean fullscreen) { |
| 4780 | mImms.reportFullscreenMode(mToken, fullscreen); |
| 4781 | } |
Yohei Yukawa | c7ca368 | 2018-09-09 20:48:38 -0700 | [diff] [blame] | 4782 | |
| 4783 | @BinderThread |
| 4784 | @Override |
| 4785 | public void setInputMethod(String id) { |
| 4786 | mImms.setInputMethod(mToken, id); |
| 4787 | } |
| 4788 | |
| 4789 | @BinderThread |
| 4790 | @Override |
| 4791 | public void setInputMethodAndSubtype(String id, InputMethodSubtype subtype) { |
| 4792 | mImms.setInputMethodAndSubtype(mToken, id, subtype); |
| 4793 | } |
| 4794 | |
| 4795 | @BinderThread |
| 4796 | @Override |
| 4797 | public void hideMySoftInput(int flags) { |
| 4798 | mImms.hideMySoftInput(mToken, flags); |
| 4799 | } |
| 4800 | |
| 4801 | @BinderThread |
| 4802 | @Override |
| 4803 | public void showMySoftInput(int flags) { |
| 4804 | mImms.showMySoftInput(mToken, flags); |
| 4805 | } |
| 4806 | |
| 4807 | @BinderThread |
| 4808 | @Override |
Yohei Yukawa | 41b094f | 2018-09-09 23:58:45 -0700 | [diff] [blame] | 4809 | public void updateStatusIcon(String packageName, @DrawableRes int iconId) { |
Yohei Yukawa | c7ca368 | 2018-09-09 20:48:38 -0700 | [diff] [blame] | 4810 | mImms.updateStatusIcon(mToken, packageName, iconId); |
| 4811 | } |
| 4812 | |
| 4813 | @BinderThread |
| 4814 | @Override |
| 4815 | public boolean switchToPreviousInputMethod() { |
| 4816 | return mImms.switchToPreviousInputMethod(mToken); |
| 4817 | } |
| 4818 | |
| 4819 | @BinderThread |
| 4820 | @Override |
| 4821 | public boolean switchToNextInputMethod(boolean onlyCurrentIme) { |
| 4822 | return mImms.switchToNextInputMethod(mToken, onlyCurrentIme); |
| 4823 | } |
| 4824 | |
| 4825 | @BinderThread |
| 4826 | @Override |
| 4827 | public boolean shouldOfferSwitchingToNextInputMethod() { |
| 4828 | return mImms.shouldOfferSwitchingToNextInputMethod(mToken); |
| 4829 | } |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 4830 | |
| 4831 | @BinderThread |
| 4832 | @Override |
Yohei Yukawa | 9b60ba0 | 2019-01-21 00:06:27 -0800 | [diff] [blame] | 4833 | public void notifyUserAction() { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 4834 | mImms.notifyUserAction(mToken); |
| 4835 | } |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 4836 | |
| 4837 | @BinderThread |
| 4838 | @Override |
| 4839 | public void reportPreRendered(EditorInfo info) { |
| 4840 | mImms.reportPreRendered(mToken, info); |
| 4841 | } |
| 4842 | |
| 4843 | @BinderThread |
| 4844 | @Override |
| 4845 | public void applyImeVisibility(boolean setVisible) { |
| 4846 | mImms.applyImeVisibility(mToken, setVisible); |
| 4847 | } |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4848 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4849 | } |