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 | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 20 | |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 21 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 22 | |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 23 | import android.Manifest; |
Phil Weaver | 03a65b0 | 2018-07-19 16:07:57 -0700 | [diff] [blame] | 24 | import android.accessibilityservice.AccessibilityService; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 25 | import android.annotation.AnyThread; |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 26 | import android.annotation.BinderThread; |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 27 | import android.annotation.ColorInt; |
Yohei Yukawa | 41b094f | 2018-09-09 23:58:45 -0700 | [diff] [blame] | 28 | import android.annotation.DrawableRes; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 29 | import android.annotation.IntDef; |
Yohei Yukawa | 930328c | 2017-10-18 20:19:53 -0700 | [diff] [blame] | 30 | import android.annotation.MainThread; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 31 | import android.annotation.NonNull; |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 32 | import android.annotation.Nullable; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 33 | import android.annotation.RequiresPermission; |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 34 | import android.annotation.UserIdInt; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 35 | import android.app.ActivityManager; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 36 | import android.app.ActivityManagerInternal; |
Andrew Sapperstein | 8a3b4cb | 2017-04-28 14:35:31 -0700 | [diff] [blame] | 37 | import android.app.ActivityThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.app.AlertDialog; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 39 | import android.app.AppGlobals; |
Yohei Yukawa | e63b5fa | 2014-09-19 13:14:55 +0900 | [diff] [blame] | 40 | import android.app.AppOpsManager; |
satok | f90a33e | 2011-07-19 11:55:52 +0900 | [diff] [blame] | 41 | import android.app.KeyguardManager; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 42 | import android.app.Notification; |
| 43 | import android.app.NotificationManager; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 44 | import android.app.PendingIntent; |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 45 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.content.ComponentName; |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 47 | import android.content.ContentProvider; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.content.ContentResolver; |
| 49 | import android.content.Context; |
| 50 | import android.content.DialogInterface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.content.DialogInterface.OnCancelListener; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 52 | import android.content.DialogInterface.OnClickListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.content.Intent; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 54 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.content.ServiceConnection; |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 56 | import android.content.pm.ApplicationInfo; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 57 | import android.content.pm.IPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.content.pm.PackageManager; |
| 59 | import android.content.pm.ResolveInfo; |
| 60 | import android.content.pm.ServiceInfo; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 61 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.content.res.Resources; |
| 63 | import android.content.res.TypedArray; |
| 64 | import android.database.ContentObserver; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 65 | import android.graphics.Matrix; |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 66 | import android.graphics.drawable.Drawable; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [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; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 101 | import android.util.SparseArray; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 102 | import android.view.ContextThemeWrapper; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 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; |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 112 | import android.view.autofill.AutofillId; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 113 | import android.view.inputmethod.EditorInfo; |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 114 | import android.view.inputmethod.InlineSuggestionsRequest; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | import android.view.inputmethod.InputBinding; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 116 | import android.view.inputmethod.InputConnection; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 117 | import android.view.inputmethod.InputConnectionInspector; |
Yohei Yukawa | 432cf60 | 2018-10-21 10:41:37 -0700 | [diff] [blame] | 118 | import android.view.inputmethod.InputConnectionInspector.MissingMethodFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | import android.view.inputmethod.InputMethod; |
| 120 | import android.view.inputmethod.InputMethodInfo; |
| 121 | import android.view.inputmethod.InputMethodManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 122 | import android.view.inputmethod.InputMethodSubtype; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 123 | import android.widget.ArrayAdapter; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 124 | import android.widget.CompoundButton; |
| 125 | import android.widget.CompoundButton.OnCheckedChangeListener; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 126 | import android.widget.RadioButton; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 127 | import android.widget.Switch; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 128 | import android.widget.TextView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 130 | import com.android.internal.annotations.GuardedBy; |
| 131 | import com.android.internal.content.PackageMonitor; |
| 132 | import com.android.internal.inputmethod.IInputContentUriToken; |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 133 | import com.android.internal.inputmethod.IInputMethodPrivilegedOperations; |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 134 | import com.android.internal.inputmethod.InputMethodDebug; |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 135 | import com.android.internal.inputmethod.StartInputFlags; |
Yohei Yukawa | c6632df | 2018-10-21 11:47:16 -0700 | [diff] [blame] | 136 | import com.android.internal.inputmethod.StartInputReason; |
Yohei Yukawa | 499e3f7 | 2018-10-21 20:15:11 -0700 | [diff] [blame] | 137 | import com.android.internal.inputmethod.UnbindReason; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 138 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 139 | import com.android.internal.notification.SystemNotificationChannels; |
| 140 | import com.android.internal.os.HandlerCaller; |
| 141 | import com.android.internal.os.SomeArgs; |
| 142 | import com.android.internal.os.TransferPipe; |
| 143 | import com.android.internal.util.DumpUtils; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 144 | import com.android.internal.util.IndentingPrintWriter; |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 145 | import com.android.internal.view.IInlineSuggestionsRequestCallback; |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 146 | import com.android.internal.view.IInlineSuggestionsResponseCallback; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 147 | import com.android.internal.view.IInputContext; |
| 148 | import com.android.internal.view.IInputMethod; |
| 149 | import com.android.internal.view.IInputMethodClient; |
| 150 | import com.android.internal.view.IInputMethodManager; |
| 151 | import com.android.internal.view.IInputMethodSession; |
| 152 | import com.android.internal.view.IInputSessionCallback; |
| 153 | import com.android.internal.view.InputBindResult; |
Yohei Yukawa | 603f4d0 | 2018-09-11 15:04:58 -0700 | [diff] [blame] | 154 | import com.android.server.EventLogTags; |
| 155 | import com.android.server.LocalServices; |
| 156 | import com.android.server.SystemService; |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 157 | import com.android.server.inputmethod.InputMethodManagerInternal.InputMethodListListener; |
Yohei Yukawa | e6b6e0e | 2018-09-12 16:42:48 -0700 | [diff] [blame] | 158 | import com.android.server.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem; |
| 159 | import com.android.server.inputmethod.InputMethodUtils.InputMethodSettings; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 160 | import com.android.server.statusbar.StatusBarManagerService; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 161 | import com.android.server.wm.WindowManagerInternal; |
| 162 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | import java.io.FileDescriptor; |
| 164 | import java.io.IOException; |
| 165 | import java.io.PrintWriter; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 166 | import java.lang.annotation.Retention; |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 167 | import java.security.InvalidParameterException; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 168 | import java.text.SimpleDateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | import java.util.ArrayList; |
Yohei Yukawa | b8d240f | 2018-12-26 10:03:11 -0800 | [diff] [blame] | 170 | import java.util.Arrays; |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 171 | import java.util.Collections; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 172 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | import java.util.List; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 174 | import java.util.Locale; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 175 | import java.util.WeakHashMap; |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 176 | import java.util.concurrent.CopyOnWriteArrayList; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 177 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * This class provides a system service that manages input methods. |
| 181 | */ |
| 182 | public class InputMethodManagerService extends IInputMethodManager.Stub |
| 183 | implements ServiceConnection, Handler.Callback { |
| 184 | static final boolean DEBUG = false; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 185 | static final String TAG = "InputMethodManagerService"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 187 | @Retention(SOURCE) |
| 188 | @IntDef({ShellCommandResult.SUCCESS, ShellCommandResult.FAILURE}) |
| 189 | private @interface ShellCommandResult { |
| 190 | int SUCCESS = 0; |
| 191 | int FAILURE = -1; |
| 192 | } |
| 193 | |
Seigo Nonaka | d4474cb | 2015-05-04 16:53:24 -0700 | [diff] [blame] | 194 | static final int MSG_SHOW_IM_SUBTYPE_PICKER = 1; |
| 195 | static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 2; |
| 196 | static final int MSG_SHOW_IM_CONFIG = 3; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 197 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | static final int MSG_UNBIND_INPUT = 1000; |
| 199 | static final int MSG_BIND_INPUT = 1010; |
| 200 | static final int MSG_SHOW_SOFT_INPUT = 1020; |
| 201 | static final int MSG_HIDE_SOFT_INPUT = 1030; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 202 | static final int MSG_HIDE_CURRENT_INPUT_METHOD = 1035; |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 203 | static final int MSG_INITIALIZE_IME = 1040; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | static final int MSG_CREATE_SESSION = 1050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | static final int MSG_START_INPUT = 2000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 207 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 208 | static final int MSG_UNBIND_CLIENT = 3000; |
| 209 | static final int MSG_BIND_CLIENT = 3010; |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 210 | static final int MSG_SET_ACTIVE = 3020; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 211 | static final int MSG_SET_INTERACTIVE = 3030; |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 212 | static final int MSG_REPORT_FULLSCREEN_MODE = 3045; |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 213 | static final int MSG_REPORT_PRE_RENDERED = 3060; |
| 214 | static final int MSG_APPLY_IME_VISIBILITY = 3070; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 215 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 216 | static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000; |
| 217 | |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 218 | static final int MSG_SYSTEM_UNLOCK_USER = 5000; |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 219 | static final int MSG_DISPATCH_ON_INPUT_METHOD_LIST_UPDATED = 5010; |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 220 | |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 221 | static final int MSG_INLINE_SUGGESTIONS_REQUEST = 6000; |
| 222 | |
Satoshi Kataoka | bcacc32 | 2013-10-21 17:57:27 -0700 | [diff] [blame] | 223 | static final long TIME_TO_RECONNECT = 3 * 1000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 224 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 225 | static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20; |
| 226 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 227 | private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID; |
satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 228 | private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher"; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 229 | |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 230 | /** |
| 231 | * Binding flags for establishing connection to the {@link InputMethodService}. |
| 232 | */ |
| 233 | private static final int IME_CONNECTION_BIND_FLAGS = |
| 234 | Context.BIND_AUTO_CREATE |
| 235 | | Context.BIND_NOT_VISIBLE |
| 236 | | Context.BIND_NOT_FOREGROUND |
Yohei Yukawa | ad78a61 | 2017-08-04 01:57:27 -0700 | [diff] [blame] | 237 | | Context.BIND_IMPORTANT_BACKGROUND; |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 238 | |
| 239 | /** |
| 240 | * Binding flags used only while the {@link InputMethodService} is showing window. |
| 241 | */ |
| 242 | private static final int IME_VISIBLE_BIND_FLAGS = |
| 243 | Context.BIND_AUTO_CREATE |
| 244 | | Context.BIND_TREAT_LIKE_ACTIVITY |
Yohei Yukawa | ad78a61 | 2017-08-04 01:57:27 -0700 | [diff] [blame] | 245 | | Context.BIND_FOREGROUND_SERVICE |
Amith Yamasani | c45a990 | 2019-04-05 16:29:30 -0700 | [diff] [blame] | 246 | | Context.BIND_INCLUDE_CAPABILITIES |
Yohei Yukawa | 5973096 | 2019-03-18 10:47:22 -0700 | [diff] [blame] | 247 | | Context.BIND_SHOWING_UI |
| 248 | | Context.BIND_SCHEDULE_LIKE_TOP_APP; |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 249 | |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 250 | /** |
| 251 | * A protected broadcast intent action for internal use for {@link PendingIntent} in |
| 252 | * the notification. |
| 253 | */ |
| 254 | private static final String ACTION_SHOW_INPUT_METHOD_PICKER = |
Yohei Yukawa | 603f4d0 | 2018-09-11 15:04:58 -0700 | [diff] [blame] | 255 | "com.android.server.inputmethod.InputMethodManagerService.SHOW_INPUT_METHOD_PICKER"; |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 256 | |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 257 | /** |
| 258 | * Debug flag for overriding runtime {@link SystemProperties}. |
| 259 | */ |
| 260 | @AnyThread |
| 261 | private static final class DebugFlag { |
| 262 | private static final Object LOCK = new Object(); |
| 263 | private final String mKey; |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 264 | private final boolean mDefaultValue; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 265 | @GuardedBy("LOCK") |
| 266 | private boolean mValue; |
| 267 | |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 268 | public DebugFlag(String key, boolean defaultValue) { |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 269 | mKey = key; |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 270 | mDefaultValue = defaultValue; |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 271 | mValue = SystemProperties.getBoolean(key, defaultValue); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void refresh() { |
| 275 | synchronized (LOCK) { |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 276 | mValue = SystemProperties.getBoolean(mKey, mDefaultValue); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
| 280 | boolean value() { |
| 281 | synchronized (LOCK) { |
| 282 | return mValue; |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Debug flags that can be overridden using "adb shell setprop <key>" |
| 289 | * Note: These flags are cached. To refresh, run "adb shell ime refresh_debug_properties". |
| 290 | */ |
| 291 | private static final class DebugFlags { |
| 292 | static final DebugFlag FLAG_OPTIMIZE_START_INPUT = |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 293 | new DebugFlag("debug.optimize_startinput", false); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 294 | static final DebugFlag FLAG_PRE_RENDER_IME_VIEWS = |
| 295 | new DebugFlag("persist.pre_render_ime_views", false); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 298 | @UserIdInt |
| 299 | private int mLastSwitchUserId; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | final Context mContext; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 302 | final Resources mRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | final Handler mHandler; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 304 | final InputMethodSettings mSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | final SettingsObserver mSettingsObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | final IWindowManager mIWindowManager; |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 307 | final WindowManagerInternal mWindowManagerInternal; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 308 | private final DisplayManagerInternal mDisplayManagerInternal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | final HandlerCaller mCaller; |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 310 | final boolean mHasFeature; |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 311 | private final ArrayMap<String, List<InputMethodSubtype>> mAdditionalSubtypeMap = |
| 312 | new ArrayMap<>(); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 313 | private final boolean mIsLowRam; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 314 | private final HardKeyboardListener mHardKeyboardListener; |
Yohei Yukawa | e63b5fa | 2014-09-19 13:14:55 +0900 | [diff] [blame] | 315 | private final AppOpsManager mAppOpsManager; |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 316 | private final UserManager mUserManager; |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 317 | private final UserManagerInternal mUserManagerInternal; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | // All known input methods. mMethodMap also serves as the global |
| 320 | // lock for this class. |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 321 | final ArrayList<InputMethodInfo> mMethodList = new ArrayList<>(); |
Yohei Yukawa | 1dd7de6 | 2018-11-20 19:25:29 -0800 | [diff] [blame] | 322 | final ArrayMap<String, InputMethodInfo> mMethodMap = new ArrayMap<>(); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 323 | private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans = |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 324 | new LruCache<>(SECURE_SUGGESTION_SPANS_MAX_SIZE); |
Satoshi Kataoka | d787f69 | 2013-10-26 04:44:21 +0900 | [diff] [blame] | 325 | private final InputMethodSubtypeSwitchingController mSwitchingController; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 326 | |
Yohei Yukawa | e073306 | 2017-02-09 22:49:35 -0800 | [diff] [blame] | 327 | /** |
| 328 | * Tracks how many times {@link #mMethodMap} was updated. |
| 329 | */ |
| 330 | @GuardedBy("mMethodMap") |
| 331 | private int mMethodMapUpdateCount = 0; |
| 332 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 333 | // Used to bring IME service up to visible adjustment while it is being shown. |
| 334 | final ServiceConnection mVisibleConnection = new ServiceConnection() { |
Yohei Yukawa | d3ef842 | 2018-06-07 16:28:07 -0700 | [diff] [blame] | 335 | @Override public void onBindingDied(ComponentName name) { |
| 336 | synchronized (mMethodMap) { |
| 337 | if (mVisibleBound) { |
| 338 | mContext.unbindService(mVisibleConnection); |
| 339 | mVisibleBound = false; |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 344 | @Override public void onServiceConnected(ComponentName name, IBinder service) { |
| 345 | } |
| 346 | |
| 347 | @Override public void onServiceDisconnected(ComponentName name) { |
| 348 | } |
| 349 | }; |
| 350 | boolean mVisibleBound = false; |
| 351 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 352 | // Ongoing notification |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 353 | private NotificationManager mNotificationManager; |
| 354 | private KeyguardManager mKeyguardManager; |
Griff Hazen | 6090c26 | 2016-03-25 08:11:24 -0700 | [diff] [blame] | 355 | private @Nullable StatusBarManagerService mStatusBar; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 356 | private Notification.Builder mImeSwitcherNotification; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 357 | private PendingIntent mImeSwitchPendingIntent; |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 358 | private boolean mShowOngoingImeSwitcherForPhones; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 359 | private boolean mNotificationShown; |
| 360 | |
Tadashi G. Takaoka | 8c6d477 | 2014-08-05 15:29:17 +0900 | [diff] [blame] | 361 | static class SessionState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | final ClientState client; |
| 363 | final IInputMethod method; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 364 | |
| 365 | IInputMethodSession session; |
| 366 | InputChannel channel; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 367 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | @Override |
| 369 | public String toString() { |
| 370 | return "SessionState{uid " + client.uid + " pid " + client.pid |
| 371 | + " method " + Integer.toHexString( |
| 372 | System.identityHashCode(method)) |
| 373 | + " session " + Integer.toHexString( |
| 374 | System.identityHashCode(session)) |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 375 | + " channel " + channel |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 376 | + "}"; |
| 377 | } |
| 378 | |
| 379 | SessionState(ClientState _client, IInputMethod _method, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 380 | IInputMethodSession _session, InputChannel _channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | client = _client; |
| 382 | method = _method; |
| 383 | session = _session; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 384 | channel = _channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | } |
| 386 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 387 | |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 388 | private static final class ClientDeathRecipient implements IBinder.DeathRecipient { |
| 389 | private final InputMethodManagerService mImms; |
| 390 | private final IInputMethodClient mClient; |
| 391 | |
| 392 | ClientDeathRecipient(InputMethodManagerService imms, IInputMethodClient client) { |
| 393 | mImms = imms; |
| 394 | mClient = client; |
| 395 | } |
| 396 | |
| 397 | @Override |
| 398 | public void binderDied() { |
| 399 | mImms.removeClient(mClient); |
| 400 | } |
| 401 | } |
| 402 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 403 | static final class ClientState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | final IInputMethodClient client; |
| 405 | final IInputContext inputContext; |
| 406 | final int uid; |
| 407 | final int pid; |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 408 | final int selfReportedDisplayId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | final InputBinding binding; |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 410 | final ClientDeathRecipient clientDeathRecipient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | boolean sessionRequested; |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 413 | // Determines if IMEs should be pre-rendered. |
| 414 | // DebugFlag can be flipped anytime. This flag is kept per-client to maintain behavior |
| 415 | // through the life of the current client. |
| 416 | boolean shouldPreRenderIme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | SessionState curSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | @Override |
| 420 | public String toString() { |
| 421 | return "ClientState{" + Integer.toHexString( |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 422 | System.identityHashCode(this)) + " uid=" + uid |
| 423 | + " pid=" + pid + " displayId=" + selfReportedDisplayId + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | ClientState(IInputMethodClient _client, IInputContext _inputContext, |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 427 | int _uid, int _pid, int _selfReportedDisplayId, |
| 428 | ClientDeathRecipient _clientDeathRecipient) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | client = _client; |
| 430 | inputContext = _inputContext; |
| 431 | uid = _uid; |
| 432 | pid = _pid; |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 433 | selfReportedDisplayId = _selfReportedDisplayId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | binding = new InputBinding(null, inputContext.asBinder(), uid, pid); |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 435 | clientDeathRecipient = _clientDeathRecipient; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | } |
| 437 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 438 | |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 439 | final ArrayMap<IBinder, ClientState> mClients = new ArrayMap<>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 440 | |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 441 | private static final class ActivityViewInfo { |
| 442 | /** |
| 443 | * {@link ClientState} where {@link android.app.ActivityView} is running. |
| 444 | */ |
| 445 | private final ClientState mParentClient; |
| 446 | /** |
| 447 | * {@link Matrix} to convert screen coordinates in the embedded virtual display to |
| 448 | * screen coordinates where {@link #mParentClient} exists. |
| 449 | */ |
| 450 | private final Matrix mMatrix; |
| 451 | |
| 452 | ActivityViewInfo(ClientState parentClient, Matrix matrix) { |
| 453 | mParentClient = parentClient; |
| 454 | mMatrix = matrix; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * A mapping table from virtual display IDs created for {@link android.app.ActivityView} |
| 460 | * to its parent IME client where {@link android.app.ActivityView} is running. |
| 461 | * |
| 462 | * <p>Note: this can be used only for virtual display IDs created by |
| 463 | * {@link android.app.ActivityView}.</p> |
| 464 | */ |
| 465 | private SparseArray<ActivityViewInfo> mActivityViewDisplayIdToParentMap = new SparseArray<>(); |
| 466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | /** |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 468 | * Set once the system is ready to run third party code. |
| 469 | */ |
| 470 | boolean mSystemReady; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 471 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 472 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 473 | * Id obtained with {@link InputMethodInfo#getId()} for the currently selected input method. |
| 474 | * method. This is to be synchronized with the secure settings keyed with |
| 475 | * {@link Settings.Secure#DEFAULT_INPUT_METHOD}. |
| 476 | * |
| 477 | * <p>This can be transiently {@code null} when the system is re-initializing input method |
| 478 | * settings, e.g., the system locale is just changed.</p> |
| 479 | * |
| 480 | * <p>Note that {@link #mCurId} is used to track which IME is being connected to |
| 481 | * {@link InputMethodManagerService}.</p> |
| 482 | * |
| 483 | * @see #mCurId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 485 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | String mCurMethodId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 487 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | /** |
| 489 | * The current binding sequence number, incremented every time there is |
| 490 | * a new bind performed. |
| 491 | */ |
| 492 | int mCurSeq; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 493 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | /** |
| 495 | * The client that is currently bound to an input method. |
| 496 | */ |
| 497 | ClientState mCurClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | /** |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 500 | * The last window token that we confirmed to be focused. This is always updated upon reports |
| 501 | * from the input method client. If the window state is already changed before the report is |
| 502 | * handled, this field just keeps the last value. |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 503 | */ |
| 504 | IBinder mCurFocusedWindow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 505 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 506 | /** |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 507 | * The last window token that we confirmed that IME started talking to. This is always updated |
| 508 | * upon reports from the input method. If the window state is already changed before the report |
| 509 | * is handled, this field just keeps the last value. |
| 510 | */ |
| 511 | IBinder mLastImeTargetWindow; |
| 512 | |
| 513 | /** |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 514 | * {@link LayoutParams#softInputMode} of {@link #mCurFocusedWindow}. |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 515 | * |
| 516 | * @see #mCurFocusedWindow |
| 517 | */ |
Yohei Yukawa | b0c2645 | 2018-10-21 10:42:52 -0700 | [diff] [blame] | 518 | @SoftInputModeFlags |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 519 | int mCurFocusedWindowSoftInputMode; |
| 520 | |
| 521 | /** |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 522 | * The client by which {@link #mCurFocusedWindow} was reported. |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 523 | */ |
| 524 | ClientState mCurFocusedWindowClient; |
| 525 | |
| 526 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | * The input context last provided by the current client. |
| 528 | */ |
| 529 | IInputContext mCurInputContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 530 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | /** |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 532 | * The missing method flags for the input context last provided by the current client. |
| 533 | * |
| 534 | * @see android.view.inputmethod.InputConnectionInspector.MissingMethodFlags |
| 535 | */ |
Yohei Yukawa | 432cf60 | 2018-10-21 10:41:37 -0700 | [diff] [blame] | 536 | @MissingMethodFlags |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 537 | int mCurInputContextMissingMethods; |
| 538 | |
| 539 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 540 | * The attributes last provided by the current client. |
| 541 | */ |
| 542 | EditorInfo mCurAttribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 543 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | /** |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 545 | * A special {@link Matrix} to convert virtual screen coordinates to the IME target display |
| 546 | * coordinates. |
| 547 | * |
| 548 | * <p>Used only while the IME client is running in a virtual display inside |
| 549 | * {@link android.app.ActivityView}. {@code null} otherwise.</p> |
| 550 | */ |
| 551 | @Nullable |
| 552 | private Matrix mCurActivityViewToScreenMatrix = null; |
| 553 | |
| 554 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 555 | * 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] | 556 | * connected to or in the process of connecting to. |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 557 | * |
| 558 | * <p>This can be {@code null} when no input method is connected.</p> |
| 559 | * |
| 560 | * @see #mCurMethodId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 562 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 563 | String mCurId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 564 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | /** |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 566 | * The current subtype of the current input method. |
| 567 | */ |
| 568 | private InputMethodSubtype mCurrentSubtype; |
| 569 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 570 | // Was the keyguard locked when this client became current? |
| 571 | private boolean mCurClientInKeyguard; |
| 572 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 573 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | * Set to true if our ServiceConnection is currently actively bound to |
| 575 | * a service (whether or not we have gotten its IBinder back yet). |
| 576 | */ |
| 577 | boolean mHaveConnection; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | /** |
| 580 | * Set if the client has asked for the input method to be shown. |
| 581 | */ |
| 582 | boolean mShowRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 583 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | /** |
| 585 | * Set if we were explicitly told to show the input method. |
| 586 | */ |
| 587 | boolean mShowExplicitlyRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | /** |
| 590 | * Set if we were forced to be shown. |
| 591 | */ |
| 592 | boolean mShowForced; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 593 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | /** |
| 595 | * Set if we last told the input method to show itself. |
| 596 | */ |
| 597 | boolean mInputShown; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 599 | /** |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 600 | * {@code true} if the current input method is in fullscreen mode. |
| 601 | */ |
| 602 | boolean mInFullscreenMode; |
| 603 | |
| 604 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | * The Intent used to connect to the current input method. |
| 606 | */ |
| 607 | Intent mCurIntent; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | /** |
| 610 | * The token we have made for the currently active input method, to |
| 611 | * identify it in the future. |
| 612 | */ |
| 613 | IBinder mCurToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 614 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 615 | /** |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 616 | * The displayId of current active input method. |
| 617 | */ |
| 618 | int mCurTokenDisplayId = INVALID_DISPLAY; |
| 619 | |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 620 | /** |
| 621 | * The display ID of the input method indicates the fallback display which returned by |
| 622 | * {@link #computeImeDisplayIdForTarget}. |
| 623 | */ |
| 624 | private static final int FALLBACK_DISPLAY_ID = DEFAULT_DISPLAY; |
| 625 | |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 626 | final ImeDisplayValidator mImeDisplayValidator; |
| 627 | |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 628 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 629 | * If non-null, this is the input method service we are currently connected |
| 630 | * to. |
| 631 | */ |
| 632 | IInputMethod mCurMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 633 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 634 | /** |
| 635 | * Time that we last initiated a bind to the input method, to determine |
| 636 | * if we should try to disconnect and reconnect to it. |
| 637 | */ |
| 638 | long mLastBindTime; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 639 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | /** |
| 641 | * Have we called mCurMethod.bindInput()? |
| 642 | */ |
| 643 | boolean mBoundToMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 644 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | /** |
| 646 | * Currently enabled session. Only touched by service thread, not |
| 647 | * protected by a lock. |
| 648 | */ |
| 649 | SessionState mEnabledSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 651 | /** |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 652 | * 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] | 653 | */ |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 654 | boolean mIsInteractive = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 655 | |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 656 | int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 657 | |
| 658 | /** |
| 659 | * A set of status bits regarding the active IME. |
| 660 | * |
| 661 | * <p>This value is a combination of following two bits:</p> |
| 662 | * <dl> |
| 663 | * <dt>{@link InputMethodService#IME_ACTIVE}</dt> |
| 664 | * <dd> |
| 665 | * If this bit is ON, connected IME is ready to accept touch/key events. |
| 666 | * </dd> |
| 667 | * <dt>{@link InputMethodService#IME_VISIBLE}</dt> |
| 668 | * <dd> |
| 669 | * If this bit is ON, some of IME view, e.g. software input, candidate view, is visible. |
| 670 | * </dd> |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 671 | * dt>{@link InputMethodService#IME_INVISIBLE}</dt> |
| 672 | * <dd> If this bit is ON, IME is ready with views from last EditorInfo but is |
| 673 | * currently invisible. |
| 674 | * </dd> |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 675 | * </dl> |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 676 | * <em>Do not update this value outside of {@link #setImeWindowStatus(IBinder, int, int)} and |
| 677 | * {@link #unbindCurrentMethodLocked()}.</em> |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 678 | */ |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 679 | int mImeWindowVis; |
| 680 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 681 | private AlertDialog.Builder mDialogBuilder; |
| 682 | private AlertDialog mSwitchingDialog; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 683 | private IBinder mSwitchingDialogToken = new Binder(); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 684 | private View mSwitchingDialogTitleView; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 685 | private InputMethodInfo[] mIms; |
| 686 | private int[] mSubtypeIds; |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 687 | private LocaleList mLastSystemLocales; |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 688 | private boolean mShowImeWithHardKeyboard; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 689 | private boolean mAccessibilityRequestingNoSoftKeyboard; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 690 | private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor(); |
| 691 | private final IPackageManager mIPackageManager; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 692 | private final String mSlotIme; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 693 | |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 694 | /** |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 695 | * Registered {@link InputMethodListListeners}. |
| 696 | * This variable can be accessed from both of MainThread and BinderThread. |
| 697 | */ |
| 698 | private final CopyOnWriteArrayList<InputMethodListListener> mInputMethodListListeners = |
| 699 | new CopyOnWriteArrayList<>(); |
| 700 | |
| 701 | /** |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 702 | * Internal state snapshot when {@link #MSG_START_INPUT} message is about to be posted to the |
| 703 | * internal message queue. Any subsequent state change inside {@link InputMethodManagerService} |
| 704 | * will not affect those tasks that are already posted. |
| 705 | * |
| 706 | * <p>Posting {@link #MSG_START_INPUT} message basically means that |
| 707 | * {@link InputMethodService#doStartInput(InputConnection, EditorInfo, boolean)} will be called |
| 708 | * back in the current IME process shortly, which will also affect what the current IME starts |
| 709 | * receiving from {@link InputMethodService#getCurrentInputConnection()}. In other words, this |
| 710 | * snapshot will be taken every time when {@link InputMethodManagerService} is initiating a new |
| 711 | * logical input session between the client application and the current IME.</p> |
| 712 | * |
| 713 | * <p>Be careful to not keep strong references to this object forever, which can prevent |
| 714 | * {@link StartInputInfo#mImeToken} and {@link StartInputInfo#mTargetWindow} from being GC-ed. |
| 715 | * </p> |
| 716 | */ |
| 717 | private static class StartInputInfo { |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 718 | private static final AtomicInteger sSequenceNumber = new AtomicInteger(0); |
| 719 | |
| 720 | final int mSequenceNumber; |
| 721 | final long mTimestamp; |
| 722 | final long mWallTime; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 723 | @UserIdInt |
| 724 | final int mImeUserId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 725 | @NonNull |
| 726 | final IBinder mImeToken; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 727 | final int mImeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 728 | @NonNull |
| 729 | final String mImeId; |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 730 | @StartInputReason |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 731 | final int mStartInputReason; |
| 732 | final boolean mRestarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 733 | @UserIdInt |
| 734 | final int mTargetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 735 | final int mTargetDisplayId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 736 | @Nullable |
| 737 | final IBinder mTargetWindow; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 738 | @NonNull |
| 739 | final EditorInfo mEditorInfo; |
Yohei Yukawa | b0c2645 | 2018-10-21 10:42:52 -0700 | [diff] [blame] | 740 | @SoftInputModeFlags |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 741 | final int mTargetWindowSoftInputMode; |
| 742 | final int mClientBindSequenceNumber; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 743 | |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 744 | StartInputInfo(@UserIdInt int imeUserId, @NonNull IBinder imeToken, int imeDisplayId, |
| 745 | @NonNull String imeId, @StartInputReason int startInputReason, boolean restarting, |
| 746 | @UserIdInt int targetUserId, int targetDisplayId, @Nullable IBinder targetWindow, |
| 747 | @NonNull EditorInfo editorInfo, @SoftInputModeFlags int targetWindowSoftInputMode, |
| 748 | int clientBindSequenceNumber) { |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 749 | mSequenceNumber = sSequenceNumber.getAndIncrement(); |
| 750 | mTimestamp = SystemClock.uptimeMillis(); |
| 751 | mWallTime = System.currentTimeMillis(); |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 752 | mImeUserId = imeUserId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 753 | mImeToken = imeToken; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 754 | mImeDisplayId = imeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 755 | mImeId = imeId; |
| 756 | mStartInputReason = startInputReason; |
| 757 | mRestarting = restarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 758 | mTargetUserId = targetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 759 | mTargetDisplayId = targetDisplayId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 760 | mTargetWindow = targetWindow; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 761 | mEditorInfo = editorInfo; |
| 762 | mTargetWindowSoftInputMode = targetWindowSoftInputMode; |
| 763 | mClientBindSequenceNumber = clientBindSequenceNumber; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
Yohei Yukawa | b37d8bd | 2017-02-13 18:29:05 -0800 | [diff] [blame] | 767 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 768 | private final WeakHashMap<IBinder, IBinder> mImeTargetWindowMap = new WeakHashMap<>(); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 769 | |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 770 | /** |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 771 | * Map of generated token to windowToken that is requesting |
| 772 | * {@link InputMethodManager#showSoftInput(View, int)}. |
| 773 | * This map tracks origin of showSoftInput requests. |
| 774 | */ |
| 775 | @GuardedBy("mMethodMap") |
| 776 | private final WeakHashMap<IBinder, IBinder> mShowRequestWindowMap = new WeakHashMap<>(); |
| 777 | |
| 778 | /** |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 779 | * A ring buffer to store the history of {@link StartInputInfo}. |
| 780 | */ |
| 781 | private static final class StartInputHistory { |
| 782 | /** |
| 783 | * Entry size for non low-RAM devices. |
| 784 | * |
| 785 | * <p>TODO: Consider to follow what other system services have been doing to manage |
| 786 | * constants (e.g. {@link android.provider.Settings.Global#ACTIVITY_MANAGER_CONSTANTS}).</p> |
| 787 | */ |
| 788 | private final static int ENTRY_SIZE_FOR_HIGH_RAM_DEVICE = 16; |
| 789 | |
| 790 | /** |
| 791 | * Entry size for non low-RAM devices. |
| 792 | * |
| 793 | * <p>TODO: Consider to follow what other system services have been doing to manage |
| 794 | * constants (e.g. {@link android.provider.Settings.Global#ACTIVITY_MANAGER_CONSTANTS}).</p> |
| 795 | */ |
| 796 | private final static int ENTRY_SIZE_FOR_LOW_RAM_DEVICE = 5; |
| 797 | |
| 798 | private static int getEntrySize() { |
| 799 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 800 | return ENTRY_SIZE_FOR_LOW_RAM_DEVICE; |
| 801 | } else { |
| 802 | return ENTRY_SIZE_FOR_HIGH_RAM_DEVICE; |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | /** |
| 807 | * Backing store for the ring bugger. |
| 808 | */ |
| 809 | private final Entry[] mEntries = new Entry[getEntrySize()]; |
| 810 | |
| 811 | /** |
| 812 | * An index of {@link #mEntries}, to which next {@link #addEntry(StartInputInfo)} should |
| 813 | * write. |
| 814 | */ |
| 815 | private int mNextIndex = 0; |
| 816 | |
| 817 | /** |
| 818 | * Recyclable entry to store the information in {@link StartInputInfo}. |
| 819 | */ |
| 820 | private static final class Entry { |
| 821 | int mSequenceNumber; |
| 822 | long mTimestamp; |
| 823 | long mWallTime; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 824 | @UserIdInt |
| 825 | int mImeUserId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 826 | @NonNull |
| 827 | String mImeTokenString; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 828 | int mImeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 829 | @NonNull |
| 830 | String mImeId; |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 831 | @StartInputReason |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 832 | int mStartInputReason; |
| 833 | boolean mRestarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 834 | @UserIdInt |
| 835 | int mTargetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 836 | int mTargetDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 837 | @NonNull |
| 838 | String mTargetWindowString; |
| 839 | @NonNull |
| 840 | EditorInfo mEditorInfo; |
Yohei Yukawa | b0c2645 | 2018-10-21 10:42:52 -0700 | [diff] [blame] | 841 | @SoftInputModeFlags |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 842 | int mTargetWindowSoftInputMode; |
| 843 | int mClientBindSequenceNumber; |
| 844 | |
| 845 | Entry(@NonNull StartInputInfo original) { |
| 846 | set(original); |
| 847 | } |
| 848 | |
| 849 | void set(@NonNull StartInputInfo original) { |
| 850 | mSequenceNumber = original.mSequenceNumber; |
| 851 | mTimestamp = original.mTimestamp; |
| 852 | mWallTime = original.mWallTime; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 853 | mImeUserId = original.mImeUserId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 854 | // Intentionally convert to String so as not to keep a strong reference to a Binder |
| 855 | // object. |
| 856 | mImeTokenString = String.valueOf(original.mImeToken); |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 857 | mImeDisplayId = original.mImeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 858 | mImeId = original.mImeId; |
| 859 | mStartInputReason = original.mStartInputReason; |
| 860 | mRestarting = original.mRestarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 861 | mTargetUserId = original.mTargetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 862 | mTargetDisplayId = original.mTargetDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 863 | // Intentionally convert to String so as not to keep a strong reference to a Binder |
| 864 | // object. |
| 865 | mTargetWindowString = String.valueOf(original.mTargetWindow); |
| 866 | mEditorInfo = original.mEditorInfo; |
| 867 | mTargetWindowSoftInputMode = original.mTargetWindowSoftInputMode; |
| 868 | mClientBindSequenceNumber = original.mClientBindSequenceNumber; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | /** |
| 873 | * Add a new entry and discard the oldest entry as needed. |
| 874 | * @param info {@lin StartInputInfo} to be added. |
| 875 | */ |
| 876 | void addEntry(@NonNull StartInputInfo info) { |
| 877 | final int index = mNextIndex; |
| 878 | if (mEntries[index] == null) { |
| 879 | mEntries[index] = new Entry(info); |
| 880 | } else { |
| 881 | mEntries[index].set(info); |
| 882 | } |
| 883 | mNextIndex = (mNextIndex + 1) % mEntries.length; |
| 884 | } |
| 885 | |
| 886 | void dump(@NonNull PrintWriter pw, @NonNull String prefix) { |
| 887 | final SimpleDateFormat dataFormat = |
| 888 | new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US); |
| 889 | |
| 890 | for (int i = 0; i < mEntries.length; ++i) { |
| 891 | final Entry entry = mEntries[(i + mNextIndex) % mEntries.length]; |
| 892 | if (entry == null) { |
| 893 | continue; |
| 894 | } |
| 895 | pw.print(prefix); |
| 896 | pw.println("StartInput #" + entry.mSequenceNumber + ":"); |
| 897 | |
| 898 | pw.print(prefix); |
| 899 | pw.println(" time=" + dataFormat.format(new Date(entry.mWallTime)) |
| 900 | + " (timestamp=" + entry.mTimestamp + ")" |
| 901 | + " reason=" |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 902 | + InputMethodDebug.startInputReasonToString(entry.mStartInputReason) |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 903 | + " restarting=" + entry.mRestarting); |
| 904 | |
| 905 | pw.print(prefix); |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 906 | pw.print(" imeToken=" + entry.mImeTokenString + " [" + entry.mImeId + "]"); |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 907 | pw.print(" imeUserId=" + entry.mImeUserId); |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 908 | pw.println(" imeDisplayId=" + entry.mImeDisplayId); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 909 | |
| 910 | pw.print(prefix); |
| 911 | pw.println(" targetWin=" + entry.mTargetWindowString |
| 912 | + " [" + entry.mEditorInfo.packageName + "]" |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 913 | + " targetUserId=" + entry.mTargetUserId |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 914 | + " targetDisplayId=" + entry.mTargetDisplayId |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 915 | + " clientBindSeq=" + entry.mClientBindSequenceNumber); |
| 916 | |
| 917 | pw.print(prefix); |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 918 | pw.println(" softInputMode=" + InputMethodDebug.softInputModeToString( |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 919 | entry.mTargetWindowSoftInputMode)); |
| 920 | |
| 921 | pw.print(prefix); |
| 922 | pw.println(" inputType=0x" + Integer.toHexString(entry.mEditorInfo.inputType) |
| 923 | + " imeOptions=0x" + Integer.toHexString(entry.mEditorInfo.imeOptions) |
| 924 | + " fieldId=0x" + Integer.toHexString(entry.mEditorInfo.fieldId) |
| 925 | + " fieldName=" + entry.mEditorInfo.fieldName |
| 926 | + " actionId=" + entry.mEditorInfo.actionId |
| 927 | + " actionLabel=" + entry.mEditorInfo.actionLabel); |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | @GuardedBy("mMethodMap") |
| 933 | @NonNull |
| 934 | private final StartInputHistory mStartInputHistory = new StartInputHistory(); |
| 935 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | class SettingsObserver extends ContentObserver { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 937 | int mUserId; |
| 938 | boolean mRegistered = false; |
Yohei Yukawa | 7b574cb | 2016-03-16 17:22:22 -0700 | [diff] [blame] | 939 | @NonNull |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 940 | String mLastEnabled = ""; |
| 941 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 942 | /** |
| 943 | * <em>This constructor must be called within the lock.</em> |
| 944 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 945 | SettingsObserver(Handler handler) { |
| 946 | super(handler); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 949 | public void registerContentObserverLocked(@UserIdInt int userId) { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 950 | if (mRegistered && mUserId == userId) { |
| 951 | return; |
| 952 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | ContentResolver resolver = mContext.getContentResolver(); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 954 | if (mRegistered) { |
| 955 | mContext.getContentResolver().unregisterContentObserver(this); |
| 956 | mRegistered = false; |
| 957 | } |
| 958 | if (mUserId != userId) { |
| 959 | mLastEnabled = ""; |
| 960 | mUserId = userId; |
| 961 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 963 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, userId); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 964 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 965 | Settings.Secure.ENABLED_INPUT_METHODS), false, this, userId); |
satok | b6109bb | 2011-02-03 22:24:54 +0900 | [diff] [blame] | 966 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 967 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this, userId); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 968 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 969 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD), false, this, userId); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 970 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 971 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE), false, this, userId); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 972 | mRegistered = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 973 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 974 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 975 | @Override public void onChange(boolean selfChange, Uri uri) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 976 | final Uri showImeUri = Settings.Secure.getUriFor( |
| 977 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD); |
| 978 | final Uri accessibilityRequestingNoImeUri = Settings.Secure.getUriFor( |
| 979 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 980 | synchronized (mMethodMap) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 981 | if (showImeUri.equals(uri)) { |
| 982 | updateKeyboardFromSettingsLocked(); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 983 | } else if (accessibilityRequestingNoImeUri.equals(uri)) { |
Phil Weaver | 03a65b0 | 2018-07-19 16:07:57 -0700 | [diff] [blame] | 984 | final int accessibilitySoftKeyboardSetting = Settings.Secure.getIntForUser( |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 985 | mContext.getContentResolver(), |
Phil Weaver | 03a65b0 | 2018-07-19 16:07:57 -0700 | [diff] [blame] | 986 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE, 0, mUserId); |
| 987 | mAccessibilityRequestingNoSoftKeyboard = |
| 988 | (accessibilitySoftKeyboardSetting & AccessibilityService.SHOW_MODE_MASK) |
| 989 | == AccessibilityService.SHOW_MODE_HIDDEN; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 990 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 991 | final boolean showRequested = mShowRequested; |
| 992 | hideCurrentInputLocked(0, null); |
| 993 | mShowRequested = showRequested; |
| 994 | } else if (mShowRequested) { |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 995 | showCurrentInputLocked( |
| 996 | mCurFocusedWindow, InputMethodManager.SHOW_IMPLICIT, null); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 997 | } |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 998 | } else { |
| 999 | boolean enabledChanged = false; |
| 1000 | String newEnabled = mSettings.getEnabledInputMethodsStr(); |
| 1001 | if (!mLastEnabled.equals(newEnabled)) { |
| 1002 | mLastEnabled = newEnabled; |
| 1003 | enabledChanged = true; |
| 1004 | } |
| 1005 | updateInputMethodsFromSettingsLocked(enabledChanged); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1006 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | } |
| 1008 | } |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1009 | |
| 1010 | @Override |
| 1011 | public String toString() { |
| 1012 | return "SettingsObserver{mUserId=" + mUserId + " mRegistered=" + mRegistered |
| 1013 | + " mLastEnabled=" + mLastEnabled + "}"; |
| 1014 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1016 | |
Yohei Yukawa | 0ec0800 | 2019-03-08 10:48:26 -0800 | [diff] [blame] | 1017 | /** |
| 1018 | * {@link BroadcastReceiver} that is intended to listen to broadcasts sent to the system user |
| 1019 | * only. |
| 1020 | */ |
| 1021 | private final class ImmsBroadcastReceiverForSystemUser extends BroadcastReceiver { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1022 | @Override |
| 1023 | public void onReceive(Context context, Intent intent) { |
| 1024 | final String action = intent.getAction(); |
Yohei Yukawa | 4225c7d | 2019-03-08 00:06:11 -0800 | [diff] [blame] | 1025 | if (Intent.ACTION_USER_ADDED.equals(action) |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 1026 | || Intent.ACTION_USER_REMOVED.equals(action)) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1027 | updateCurrentProfileIds(); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 1028 | return; |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1029 | } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) { |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1030 | onActionLocaleChanged(); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1031 | } else if (ACTION_SHOW_INPUT_METHOD_PICKER.equals(action)) { |
| 1032 | // ACTION_SHOW_INPUT_METHOD_PICKER action is a protected-broadcast and it is |
| 1033 | // guaranteed to be send only from the system, so that there is no need for extra |
| 1034 | // security check such as |
| 1035 | // {@link #canShowInputMethodPickerLocked(IInputMethodClient)}. |
| 1036 | mHandler.obtainMessage( |
| 1037 | MSG_SHOW_IM_SUBTYPE_PICKER, |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 1038 | // TODO(b/120076400): Design and implement IME switcher for heterogeneous |
| 1039 | // navbar configuration. |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1040 | InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES, |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 1041 | DEFAULT_DISPLAY).sendToTarget(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1042 | } else { |
| 1043 | Slog.w(TAG, "Unexpected intent " + intent); |
| 1044 | } |
| 1045 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1047 | |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1048 | /** |
Yohei Yukawa | 0ec0800 | 2019-03-08 10:48:26 -0800 | [diff] [blame] | 1049 | * {@link BroadcastReceiver} that is intended to listen to broadcasts sent to all the users. |
| 1050 | */ |
| 1051 | private final class ImmsBroadcastReceiverForAllUsers extends BroadcastReceiver { |
| 1052 | @Override |
| 1053 | public void onReceive(Context context, Intent intent) { |
| 1054 | final String action = intent.getAction(); |
| 1055 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { |
| 1056 | final PendingResult pendingResult = getPendingResult(); |
| 1057 | if (pendingResult == null) { |
| 1058 | return; |
| 1059 | } |
| 1060 | // sender userId can be a real user ID or USER_ALL. |
| 1061 | final int senderUserId = pendingResult.getSendingUserId(); |
| 1062 | if (senderUserId != UserHandle.USER_ALL) { |
Tarandeep Singh | cf5ff82 | 2019-07-08 14:06:27 -0700 | [diff] [blame] | 1063 | if (senderUserId != mSettings.getCurrentUserId()) { |
Yohei Yukawa | 0ec0800 | 2019-03-08 10:48:26 -0800 | [diff] [blame] | 1064 | // A background user is trying to hide the dialog. Ignore. |
| 1065 | return; |
| 1066 | } |
| 1067 | } |
| 1068 | hideInputMethodMenu(); |
| 1069 | } else { |
| 1070 | Slog.w(TAG, "Unexpected intent " + intent); |
| 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | /** |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1076 | * Handles {@link Intent#ACTION_LOCALE_CHANGED}. |
| 1077 | * |
| 1078 | * <p>Note: For historical reasons, {@link Intent#ACTION_LOCALE_CHANGED} has been sent to all |
| 1079 | * the users. We should ignore this event if this is about any background user's locale.</p> |
| 1080 | * |
| 1081 | * <p>Caution: This method must not be called when system is not ready.</p> |
| 1082 | */ |
| 1083 | void onActionLocaleChanged() { |
| 1084 | synchronized (mMethodMap) { |
| 1085 | final LocaleList possibleNewLocale = mRes.getConfiguration().getLocales(); |
| 1086 | if (possibleNewLocale != null && possibleNewLocale.equals(mLastSystemLocales)) { |
| 1087 | return; |
| 1088 | } |
| 1089 | buildInputMethodListLocked(true); |
| 1090 | // If the locale is changed, needs to reset the default ime |
| 1091 | resetDefaultImeLocked(mContext); |
| 1092 | updateFromSettingsLocked(true); |
| 1093 | mLastSystemLocales = possibleNewLocale; |
| 1094 | } |
| 1095 | } |
| 1096 | |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1097 | final class MyPackageMonitor extends PackageMonitor { |
| 1098 | /** |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1099 | * Package names that are known to contain {@link InputMethodService}. |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1100 | * |
| 1101 | * <p>No need to include packages because of direct-boot unaware IMEs since we always rescan |
| 1102 | * all the packages when the user is unlocked, and direct-boot awareness will not be changed |
| 1103 | * dynamically unless the entire package is updated, which also always triggers package |
| 1104 | * rescanning.</p> |
| 1105 | */ |
| 1106 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1107 | final private ArraySet<String> mKnownImePackageNames = new ArraySet<>(); |
| 1108 | |
| 1109 | /** |
| 1110 | * Packages that are appeared, disappeared, or modified for whatever reason. |
| 1111 | * |
| 1112 | * <p>Note: For now we intentionally use {@link ArrayList} instead of {@link ArraySet} |
| 1113 | * because 1) the number of elements is almost always 1 or so, and 2) we do not care |
| 1114 | * duplicate elements for our use case.</p> |
| 1115 | * |
| 1116 | * <p>This object must be accessed only from callback methods in {@link PackageMonitor}, |
| 1117 | * which should be bound to {@link #getRegisteredHandler()}.</p> |
| 1118 | */ |
| 1119 | private final ArrayList<String> mChangedPackages = new ArrayList<>(); |
| 1120 | |
| 1121 | /** |
| 1122 | * {@code true} if one or more packages that contain {@link InputMethodService} appeared. |
| 1123 | * |
| 1124 | * <p>This field must be accessed only from callback methods in {@link PackageMonitor}, |
| 1125 | * which should be bound to {@link #getRegisteredHandler()}.</p> |
| 1126 | */ |
| 1127 | private boolean mImePackageAppeared = false; |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1128 | |
| 1129 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1130 | void clearKnownImePackageNamesLocked() { |
| 1131 | mKnownImePackageNames.clear(); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1135 | final void addKnownImePackageNameLocked(@NonNull String packageName) { |
| 1136 | mKnownImePackageNames.add(packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1137 | } |
| 1138 | |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1139 | @GuardedBy("mMethodMap") |
| 1140 | private boolean isChangingPackagesOfCurrentUserLocked() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1141 | final int userId = getChangingUserId(); |
| 1142 | final boolean retval = userId == mSettings.getCurrentUserId(); |
| 1143 | if (DEBUG) { |
satok | 81f8b7c | 2012-12-04 20:42:56 +0900 | [diff] [blame] | 1144 | if (!retval) { |
| 1145 | Slog.d(TAG, "--- ignore this call back from a background user: " + userId); |
| 1146 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1147 | } |
| 1148 | return retval; |
| 1149 | } |
| 1150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1152 | 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] | 1153 | synchronized (mMethodMap) { |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1154 | if (!isChangingPackagesOfCurrentUserLocked()) { |
| 1155 | return false; |
| 1156 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1157 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | final int N = mMethodList.size(); |
| 1159 | if (curInputMethodId != null) { |
| 1160 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1161 | InputMethodInfo imi = mMethodList.get(i); |
| 1162 | if (imi.getId().equals(curInputMethodId)) { |
| 1163 | for (String pkg : packages) { |
| 1164 | if (imi.getPackageName().equals(pkg)) { |
| 1165 | if (!doit) { |
| 1166 | return true; |
| 1167 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1168 | resetSelectedInputMethodAndSubtypeLocked(""); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1169 | chooseNewDefaultIMELocked(); |
| 1170 | return true; |
| 1171 | } |
| 1172 | } |
| 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | return false; |
| 1178 | } |
| 1179 | |
| 1180 | @Override |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1181 | public void onBeginPackageChanges() { |
| 1182 | clearPackageChangeState(); |
| 1183 | } |
| 1184 | |
| 1185 | @Override |
| 1186 | public void onPackageAppeared(String packageName, int reason) { |
| 1187 | if (!mImePackageAppeared) { |
| 1188 | final PackageManager pm = mContext.getPackageManager(); |
| 1189 | final List<ResolveInfo> services = pm.queryIntentServicesAsUser( |
| 1190 | new Intent(InputMethod.SERVICE_INTERFACE).setPackage(packageName), |
Yohei Yukawa | 5ec1fce | 2018-12-17 07:56:14 -0800 | [diff] [blame] | 1191 | PackageManager.MATCH_DISABLED_COMPONENTS, getChangingUserId()); |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1192 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1193 | if (!services.isEmpty()) { |
| 1194 | mImePackageAppeared = true; |
| 1195 | } |
| 1196 | } |
| 1197 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1198 | mChangedPackages.add(packageName); |
| 1199 | } |
| 1200 | |
| 1201 | @Override |
| 1202 | public void onPackageDisappeared(String packageName, int reason) { |
| 1203 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1204 | mChangedPackages.add(packageName); |
| 1205 | } |
| 1206 | |
| 1207 | @Override |
| 1208 | public void onPackageModified(String packageName) { |
| 1209 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1210 | mChangedPackages.add(packageName); |
| 1211 | } |
| 1212 | |
| 1213 | @Override |
| 1214 | public void onPackagesSuspended(String[] packages) { |
| 1215 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1216 | for (String packageName : packages) { |
| 1217 | mChangedPackages.add(packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | @Override |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1222 | public void onPackagesUnsuspended(String[] packages) { |
| 1223 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1224 | for (String packageName : packages) { |
| 1225 | mChangedPackages.add(packageName); |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | @Override |
| 1230 | public void onFinishPackageChanges() { |
| 1231 | onFinishPackageChangesInternal(); |
| 1232 | clearPackageChangeState(); |
| 1233 | } |
| 1234 | |
| 1235 | private void clearPackageChangeState() { |
| 1236 | // No need to lock them because we access these fields only on getRegisteredHandler(). |
| 1237 | mChangedPackages.clear(); |
| 1238 | mImePackageAppeared = false; |
| 1239 | } |
| 1240 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1241 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1242 | private boolean shouldRebuildInputMethodListLocked() { |
| 1243 | // This method is guaranteed to be called only by getRegisteredHandler(). |
| 1244 | |
| 1245 | // If there is any new package that contains at least one IME, then rebuilt the list |
| 1246 | // of IMEs. |
| 1247 | if (mImePackageAppeared) { |
| 1248 | return true; |
| 1249 | } |
| 1250 | |
| 1251 | // Otherwise, check if mKnownImePackageNames and mChangedPackages have any intersection. |
| 1252 | // TODO: Consider to create a utility method to do the following test. List.retainAll() |
| 1253 | // is an option, but it may still do some extra operations that we do not need here. |
| 1254 | final int N = mChangedPackages.size(); |
| 1255 | for (int i = 0; i < N; ++i) { |
| 1256 | final String packageName = mChangedPackages.get(i); |
| 1257 | if (mKnownImePackageNames.contains(packageName)) { |
| 1258 | return true; |
| 1259 | } |
| 1260 | } |
| 1261 | return false; |
| 1262 | } |
| 1263 | |
| 1264 | private void onFinishPackageChangesInternal() { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1265 | synchronized (mMethodMap) { |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1266 | if (!isChangingPackagesOfCurrentUserLocked()) { |
| 1267 | return; |
| 1268 | } |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1269 | if (!shouldRebuildInputMethodListLocked()) { |
| 1270 | return; |
| 1271 | } |
| 1272 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1273 | InputMethodInfo curIm = null; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1274 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1275 | final int N = mMethodList.size(); |
| 1276 | if (curInputMethodId != null) { |
| 1277 | for (int i=0; i<N; i++) { |
| 1278 | InputMethodInfo imi = mMethodList.get(i); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1279 | final String imiId = imi.getId(); |
| 1280 | if (imiId.equals(curInputMethodId)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1281 | curIm = imi; |
| 1282 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1283 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1284 | int change = isPackageDisappearing(imi.getPackageName()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1285 | if (isPackageModified(imi.getPackageName())) { |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 1286 | mAdditionalSubtypeMap.remove(imi.getId()); |
| 1287 | AdditionalSubtypeUtils.save(mAdditionalSubtypeMap, mMethodMap, |
| 1288 | mSettings.getCurrentUserId()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1289 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1290 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 1291 | || change == PACKAGE_PERMANENT_CHANGE) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1292 | Slog.i(TAG, "Input method uninstalled, disabling: " |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1293 | + imi.getComponent()); |
| 1294 | setInputMethodEnabledLocked(imi.getId(), false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1298 | |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 1299 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1300 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1302 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1303 | if (curIm != null) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1304 | int change = isPackageDisappearing(curIm.getPackageName()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1305 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 1306 | || change == PACKAGE_PERMANENT_CHANGE) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1307 | ServiceInfo si = null; |
| 1308 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1309 | si = mIPackageManager.getServiceInfo( |
| 1310 | curIm.getComponent(), 0, mSettings.getCurrentUserId()); |
| 1311 | } catch (RemoteException ex) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1312 | } |
| 1313 | if (si == null) { |
| 1314 | // Uh oh, current input method is no longer around! |
| 1315 | // Pick another one... |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1316 | Slog.i(TAG, "Current input method removed: " + curInputMethodId); |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 1317 | updateSystemUiLocked(0 /* vis */, mBackDisposition); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1318 | if (!chooseNewDefaultIMELocked()) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1319 | changed = true; |
| 1320 | curIm = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1321 | Slog.i(TAG, "Unsetting current input method"); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1322 | resetSelectedInputMethodAndSubtypeLocked(""); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1323 | } |
| 1324 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1325 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1326 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1327 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1328 | if (curIm == null) { |
| 1329 | // We currently don't have a default input method... is |
| 1330 | // one now available? |
| 1331 | changed = chooseNewDefaultIMELocked(); |
Yohei Yukawa | 54d512c | 2015-05-19 22:15:02 -0700 | [diff] [blame] | 1332 | } else if (!changed && isPackageModified(curIm.getPackageName())) { |
| 1333 | // Even if the current input method is still available, mCurrentSubtype could |
| 1334 | // be obsolete when the package is modified in practice. |
| 1335 | changed = true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1336 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1337 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1338 | if (changed) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1339 | updateFromSettingsLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1344 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1345 | private static final class MethodCallback extends IInputSessionCallback.Stub { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 1346 | private final InputMethodManagerService mParentIMMS; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1347 | private final IInputMethod mMethod; |
| 1348 | private final InputChannel mChannel; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1349 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1350 | MethodCallback(InputMethodManagerService imms, IInputMethod method, |
| 1351 | InputChannel channel) { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 1352 | mParentIMMS = imms; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1353 | mMethod = method; |
| 1354 | mChannel = channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1355 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1356 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1357 | @Override |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1358 | public void sessionCreated(IInputMethodSession session) { |
Dianne Hackborn | 6b6b3fd | 2014-03-24 11:27:18 -0700 | [diff] [blame] | 1359 | long ident = Binder.clearCallingIdentity(); |
| 1360 | try { |
| 1361 | mParentIMMS.onSessionCreated(mMethod, session, mChannel); |
| 1362 | } finally { |
| 1363 | Binder.restoreCallingIdentity(ident); |
| 1364 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1365 | } |
| 1366 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1367 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1368 | private class HardKeyboardListener |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1369 | implements WindowManagerInternal.OnHardKeyboardStatusChangeListener { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1370 | @Override |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1371 | public void onHardKeyboardStatusChange(boolean available) { |
| 1372 | mHandler.sendMessage(mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED, |
| 1373 | available ? 1 : 0)); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1374 | } |
| 1375 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1376 | public void handleHardKeyboardStatusChange(boolean available) { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1377 | if (DEBUG) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1378 | Slog.w(TAG, "HardKeyboardStatusChanged: available=" + available); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1379 | } |
| 1380 | synchronized(mMethodMap) { |
| 1381 | if (mSwitchingDialog != null && mSwitchingDialogTitleView != null |
| 1382 | && mSwitchingDialog.isShowing()) { |
| 1383 | mSwitchingDialogTitleView.findViewById( |
| 1384 | com.android.internal.R.id.hard_keyboard_section).setVisibility( |
| 1385 | available ? View.VISIBLE : View.GONE); |
| 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | } |
| 1390 | |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1391 | public static final class Lifecycle extends SystemService { |
| 1392 | private InputMethodManagerService mService; |
| 1393 | |
| 1394 | public Lifecycle(Context context) { |
| 1395 | super(context); |
| 1396 | mService = new InputMethodManagerService(context); |
| 1397 | } |
| 1398 | |
| 1399 | @Override |
| 1400 | public void onStart() { |
| 1401 | LocalServices.addService(InputMethodManagerInternal.class, |
Yohei Yukawa | fffc0e5 | 2018-09-04 13:24:00 -0700 | [diff] [blame] | 1402 | new LocalServiceImpl(mService)); |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1403 | publishBinderService(Context.INPUT_METHOD_SERVICE, mService); |
| 1404 | } |
| 1405 | |
| 1406 | @Override |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1407 | public void onSwitchUser(@UserIdInt int userHandle) { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1408 | // Called on ActivityManager thread. |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1409 | // TODO: Dispatch this to a worker thread as needed. |
| 1410 | mService.onSwitchUser(userHandle); |
| 1411 | } |
| 1412 | |
| 1413 | @Override |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1414 | public void onBootPhase(int phase) { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1415 | // Called on ActivityManager thread. |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1416 | // TODO: Dispatch this to a worker thread as needed. |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1417 | if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) { |
| 1418 | StatusBarManagerService statusBarService = (StatusBarManagerService) ServiceManager |
| 1419 | .getService(Context.STATUS_BAR_SERVICE); |
| 1420 | mService.systemRunning(statusBarService); |
| 1421 | } |
| 1422 | } |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1423 | |
| 1424 | @Override |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1425 | public void onUnlockUser(final @UserIdInt int userHandle) { |
| 1426 | // Called on ActivityManager thread. |
| 1427 | mService.mHandler.sendMessage(mService.mHandler.obtainMessage(MSG_SYSTEM_UNLOCK_USER, |
Fyodor Kupolov | 0f57cce | 2016-09-09 10:36:30 -0700 | [diff] [blame] | 1428 | userHandle /* arg1 */, 0 /* arg2 */)); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1429 | } |
| 1430 | } |
| 1431 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1432 | void onUnlockUser(@UserIdInt int userId) { |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1433 | synchronized(mMethodMap) { |
| 1434 | final int currentUserId = mSettings.getCurrentUserId(); |
| 1435 | if (DEBUG) { |
| 1436 | Slog.d(TAG, "onUnlockUser: userId=" + userId + " curUserId=" + currentUserId); |
| 1437 | } |
| 1438 | if (userId != currentUserId) { |
| 1439 | return; |
| 1440 | } |
| 1441 | mSettings.switchCurrentUser(currentUserId, !mSystemReady); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1442 | if (mSystemReady) { |
| 1443 | // We need to rebuild IMEs. |
| 1444 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
| 1445 | updateInputMethodsFromSettingsLocked(true /* enabledChanged */); |
| 1446 | } |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1447 | } |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1448 | } |
| 1449 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1450 | void onSwitchUser(@UserIdInt int userId) { |
| 1451 | synchronized (mMethodMap) { |
| 1452 | switchUserLocked(userId); |
| 1453 | } |
| 1454 | } |
| 1455 | |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1456 | public InputMethodManagerService(Context context) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1457 | mIPackageManager = AppGlobals.getPackageManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | mContext = context; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1459 | mRes = context.getResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1460 | mHandler = new Handler(this); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1461 | // Note: SettingsObserver doesn't register observers in its constructor. |
| 1462 | mSettingsObserver = new SettingsObserver(mHandler); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1463 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 1464 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1465 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 1466 | mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); |
lumark | 9a72d22 | 2019-03-30 18:31:45 +0800 | [diff] [blame] | 1467 | mImeDisplayValidator = displayId -> mWindowManagerInternal.shouldShowIme(displayId); |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 1468 | mCaller = new HandlerCaller(context, null, new HandlerCaller.Callback() { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1469 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1470 | public void executeMessage(Message msg) { |
| 1471 | handleMessage(msg); |
| 1472 | } |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 1473 | }, true /*asyncHandler*/); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 1474 | mAppOpsManager = mContext.getSystemService(AppOpsManager.class); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1475 | mUserManager = mContext.getSystemService(UserManager.class); |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 1476 | mUserManagerInternal = LocalServices.getService(UserManagerInternal.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1477 | mHardKeyboardListener = new HardKeyboardListener(); |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 1478 | mHasFeature = context.getPackageManager().hasSystemFeature( |
| 1479 | PackageManager.FEATURE_INPUT_METHODS); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 1480 | mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 1481 | mIsLowRam = ActivityManager.isLowRamDeviceStatic(); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1482 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1483 | Bundle extras = new Bundle(); |
| 1484 | extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1485 | @ColorInt final int accentColor = mContext.getColor( |
| 1486 | com.android.internal.R.color.system_notification_accent_color); |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 1487 | mImeSwitcherNotification = |
| 1488 | new Notification.Builder(mContext, SystemNotificationChannels.VIRTUAL_KEYBOARD) |
| 1489 | .setSmallIcon(com.android.internal.R.drawable.ic_notification_ime_default) |
| 1490 | .setWhen(0) |
| 1491 | .setOngoing(true) |
| 1492 | .addExtras(extras) |
| 1493 | .setCategory(Notification.CATEGORY_SYSTEM) |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1494 | .setColor(accentColor); |
Daniel Sandler | 590d515 | 2012-06-14 16:10:13 -0400 | [diff] [blame] | 1495 | |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1496 | Intent intent = new Intent(ACTION_SHOW_INPUT_METHOD_PICKER) |
| 1497 | .setPackage(mContext.getPackageName()); |
satok | 683e238 | 2011-07-12 08:28:52 +0900 | [diff] [blame] | 1498 | mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 1499 | |
| 1500 | mShowOngoingImeSwitcherForPhones = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1501 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1502 | mNotificationShown = false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1503 | int userId = 0; |
| 1504 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1505 | userId = ActivityManager.getService().getCurrentUser().id; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1506 | } catch (RemoteException e) { |
| 1507 | Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e); |
| 1508 | } |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1509 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 1510 | mLastSwitchUserId = userId; |
| 1511 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1512 | // mSettings should be created before buildInputMethodListLocked |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 1513 | mSettings = new InputMethodSettings( |
Yohei Yukawa | f927753 | 2019-01-25 02:47:32 -0800 | [diff] [blame] | 1514 | mRes, context.getContentResolver(), mMethodMap, userId, !mSystemReady); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 1515 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1516 | updateCurrentProfileIds(); |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 1517 | AdditionalSubtypeUtils.load(mAdditionalSubtypeMap, userId); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1518 | mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked( |
| 1519 | mSettings, context); |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1520 | } |
| 1521 | |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1522 | private void resetDefaultImeLocked(Context context) { |
| 1523 | // 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] | 1524 | if (mCurMethodId != null && !mMethodMap.get(mCurMethodId).isSystem()) { |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1525 | return; |
| 1526 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1527 | final List<InputMethodInfo> suitableImes = InputMethodUtils.getDefaultEnabledImes( |
Yohei Yukawa | af5cee8 | 2017-01-23 16:17:11 -0800 | [diff] [blame] | 1528 | context, mSettings.getEnabledInputMethodListLocked()); |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1529 | if (suitableImes.isEmpty()) { |
| 1530 | Slog.i(TAG, "No default found"); |
| 1531 | return; |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1532 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1533 | final InputMethodInfo defIm = suitableImes.get(0); |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1534 | if (DEBUG) { |
| 1535 | Slog.i(TAG, "Default found, using " + defIm.getId()); |
| 1536 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1537 | setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false); |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1538 | } |
| 1539 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1540 | @GuardedBy("mMethodMap") |
Satoshi Kataoka | 5ade83b | 2012-09-26 22:59:41 +0900 | [diff] [blame] | 1541 | private void switchUserLocked(int newUserId) { |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1542 | if (DEBUG) Slog.d(TAG, "Switching user stage 1/3. newUserId=" + newUserId |
| 1543 | + " currentUserId=" + mSettings.getCurrentUserId()); |
| 1544 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1545 | // ContentObserver should be registered again when the user is changed |
| 1546 | mSettingsObserver.registerContentObserverLocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1547 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1548 | // If the system is not ready or the device is not yed unlocked by the user, then we use |
| 1549 | // copy-on-write settings. |
| 1550 | final boolean useCopyOnWriteSettings = |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 1551 | !mSystemReady || !mUserManagerInternal.isUserUnlockingOrUnlocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1552 | mSettings.switchCurrentUser(newUserId, useCopyOnWriteSettings); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1553 | updateCurrentProfileIds(); |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 1554 | // Additional subtypes should be reset when the user is changed |
| 1555 | AdditionalSubtypeUtils.load(mAdditionalSubtypeMap, newUserId); |
Satoshi Kataoka | 7f7535f | 2013-02-18 12:54:16 +0900 | [diff] [blame] | 1556 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1557 | |
| 1558 | if (DEBUG) Slog.d(TAG, "Switching user stage 2/3. newUserId=" + newUserId |
| 1559 | + " defaultImiId=" + defaultImiId); |
| 1560 | |
Satoshi Kataoka | 7c4a2a1 | 2013-02-25 15:25:43 +0900 | [diff] [blame] | 1561 | // For secondary users, the list of enabled IMEs may not have been updated since the |
| 1562 | // callbacks to PackageMonitor are ignored for the secondary user. Here, defaultImiId may |
| 1563 | // not be empty even if the IME has been uninstalled by the primary user. |
| 1564 | // Even in such cases, IMMS works fine because it will find the most applicable |
| 1565 | // IME for that user. |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1566 | final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId); |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1567 | mLastSystemLocales = mRes.getConfiguration().getLocales(); |
| 1568 | |
| 1569 | // TODO: Is it really possible that switchUserLocked() happens before system ready? |
| 1570 | if (mSystemReady) { |
| 1571 | hideCurrentInputLocked(0, null); |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 1572 | resetCurrentMethodAndClient(UnbindReason.SWITCH_USER); |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1573 | buildInputMethodListLocked(initialUserSwitch); |
| 1574 | if (TextUtils.isEmpty(mSettings.getSelectedInputMethod())) { |
| 1575 | // This is the first time of the user switch and |
| 1576 | // set the current ime to the proper one. |
| 1577 | resetDefaultImeLocked(mContext); |
| 1578 | } |
| 1579 | updateFromSettingsLocked(true); |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1580 | } |
| 1581 | |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1582 | if (initialUserSwitch) { |
Yohei Yukawa | 094c71f | 2015-06-20 00:41:31 -0700 | [diff] [blame] | 1583 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1584 | mSettings.getEnabledInputMethodListLocked(), newUserId, |
| 1585 | mContext.getBasePackageName()); |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1586 | } |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1587 | |
| 1588 | if (DEBUG) Slog.d(TAG, "Switching user stage 3/3. newUserId=" + newUserId |
| 1589 | + " selectedIme=" + mSettings.getSelectedInputMethod()); |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 1590 | |
| 1591 | mLastSwitchUserId = newUserId; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1592 | } |
| 1593 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1594 | void updateCurrentProfileIds() { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 1595 | mSettings.setCurrentProfileIds( |
| 1596 | mUserManager.getProfileIdsWithDisabled(mSettings.getCurrentUserId())); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 1597 | } |
| 1598 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | @Override |
| 1600 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1601 | throws RemoteException { |
| 1602 | try { |
| 1603 | return super.onTransact(code, data, reply, flags); |
| 1604 | } catch (RuntimeException e) { |
| 1605 | // The input method manager only throws security exceptions, so let's |
| 1606 | // log all others. |
| 1607 | if (!(e instanceof SecurityException)) { |
Dianne Hackborn | 164371f | 2013-10-01 19:10:13 -0700 | [diff] [blame] | 1608 | Slog.wtf(TAG, "Input Method Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1609 | } |
| 1610 | throw e; |
| 1611 | } |
| 1612 | } |
| 1613 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 1614 | public void systemRunning(StatusBarManagerService statusBar) { |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1615 | synchronized (mMethodMap) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1616 | if (DEBUG) { |
| 1617 | Slog.d(TAG, "--- systemReady"); |
| 1618 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1619 | if (!mSystemReady) { |
| 1620 | mSystemReady = true; |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1621 | mLastSystemLocales = mRes.getConfiguration().getLocales(); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1622 | final int currentUserId = mSettings.getCurrentUserId(); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1623 | mSettings.switchCurrentUser(currentUserId, |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 1624 | !mUserManagerInternal.isUserUnlockingOrUnlocked(currentUserId)); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 1625 | mKeyguardManager = mContext.getSystemService(KeyguardManager.class); |
| 1626 | mNotificationManager = mContext.getSystemService(NotificationManager.class); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1627 | mStatusBar = statusBar; |
Griff Hazen | 6090c26 | 2016-03-25 08:11:24 -0700 | [diff] [blame] | 1628 | if (mStatusBar != null) { |
| 1629 | mStatusBar.setIconVisibility(mSlotIme, false); |
| 1630 | } |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 1631 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 1632 | mShowOngoingImeSwitcherForPhones = mRes.getBoolean( |
| 1633 | com.android.internal.R.bool.show_ongoing_ime_switcher); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1634 | if (mShowOngoingImeSwitcherForPhones) { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1635 | mWindowManagerInternal.setOnHardKeyboardStatusChangeListener( |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1636 | mHardKeyboardListener); |
| 1637 | } |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1638 | |
| 1639 | mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true); |
| 1640 | mSettingsObserver.registerContentObserverLocked(currentUserId); |
| 1641 | |
Yohei Yukawa | 0ec0800 | 2019-03-08 10:48:26 -0800 | [diff] [blame] | 1642 | final IntentFilter broadcastFilterForSystemUser = new IntentFilter(); |
| 1643 | broadcastFilterForSystemUser.addAction(Intent.ACTION_USER_ADDED); |
| 1644 | broadcastFilterForSystemUser.addAction(Intent.ACTION_USER_REMOVED); |
| 1645 | broadcastFilterForSystemUser.addAction(Intent.ACTION_LOCALE_CHANGED); |
| 1646 | broadcastFilterForSystemUser.addAction(ACTION_SHOW_INPUT_METHOD_PICKER); |
| 1647 | mContext.registerReceiver(new ImmsBroadcastReceiverForSystemUser(), |
| 1648 | broadcastFilterForSystemUser); |
| 1649 | |
| 1650 | final IntentFilter broadcastFilterForAllUsers = new IntentFilter(); |
| 1651 | broadcastFilterForAllUsers.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 1652 | mContext.registerReceiverAsUser(new ImmsBroadcastReceiverForAllUsers(), |
| 1653 | UserHandle.ALL, broadcastFilterForAllUsers, null, null); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1654 | |
Yohei Yukawa | 1f9a3cb | 2017-10-26 15:00:59 -0700 | [diff] [blame] | 1655 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
| 1656 | final boolean imeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId); |
| 1657 | buildInputMethodListLocked(!imeSelectedOnBoot /* resetDefaultEnabledIme */); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1658 | updateFromSettingsLocked(true); |
| 1659 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1660 | mSettings.getEnabledInputMethodListLocked(), currentUserId, |
| 1661 | mContext.getBasePackageName()); |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1662 | } |
| 1663 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1664 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1665 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1666 | // --------------------------------------------------------------------------------------- |
| 1667 | // Check whether or not this is a valid IPC. Assumes an IPC is valid when either |
| 1668 | // 1) it comes from the system process |
| 1669 | // 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] | 1670 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 1671 | private boolean calledFromValidUserLocked() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1672 | final int uid = Binder.getCallingUid(); |
| 1673 | final int userId = UserHandle.getUserId(uid); |
| 1674 | if (DEBUG) { |
| 1675 | Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? " |
| 1676 | + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID |
| 1677 | + " calling userId = " + userId + ", foreground user id = " |
Satoshi Kataoka | 87c2914 | 2013-07-31 23:11:54 +0900 | [diff] [blame] | 1678 | + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid() |
| 1679 | + InputMethodUtils.getApiCallStack()); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1680 | } |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 1681 | if (uid == Process.SYSTEM_UID) { |
| 1682 | return true; |
| 1683 | } |
| 1684 | if (userId == mSettings.getCurrentUserId()) { |
| 1685 | return true; |
| 1686 | } |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1687 | |
| 1688 | // Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the |
| 1689 | // foreground user, not for the user of that process. Accordingly InputMethodManagerService |
| 1690 | // must not manage background users' states in any functions. |
| 1691 | // Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded |
| 1692 | // by a token. |
| 1693 | if (mContext.checkCallingOrSelfPermission( |
| 1694 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
| 1695 | == PackageManager.PERMISSION_GRANTED) { |
| 1696 | if (DEBUG) { |
| 1697 | Slog.d(TAG, "--- Access granted because the calling process has " |
| 1698 | + "the INTERACT_ACROSS_USERS_FULL permission"); |
| 1699 | } |
| 1700 | return true; |
| 1701 | } |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1702 | // 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] | 1703 | Slog.w(TAG, "--- IPC called from background users. Ignore. callers=" |
| 1704 | + Debug.getCallers(10)); |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1705 | return false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1706 | } |
| 1707 | |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 1708 | |
| 1709 | /** |
| 1710 | * Returns true iff the caller is identified to be the current input method with the token. |
| 1711 | * @param token The window token given to the input method when it was started. |
| 1712 | * @return true if and only if non-null valid token is specified. |
| 1713 | */ |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 1714 | @GuardedBy("mMethodMap") |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 1715 | private boolean calledWithValidTokenLocked(@NonNull IBinder token) { |
| 1716 | if (token == null) { |
| 1717 | throw new InvalidParameterException("token must not be null."); |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1718 | } |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 1719 | if (token != mCurToken) { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1720 | Slog.e(TAG, "Ignoring " + Debug.getCaller() + " due to an invalid token." |
| 1721 | + " uid:" + Binder.getCallingUid() + " token:" + token); |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 1722 | return false; |
| 1723 | } |
| 1724 | return true; |
| 1725 | } |
| 1726 | |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 1727 | @GuardedBy("mMethodMap") |
| 1728 | private boolean bindCurrentInputMethodServiceLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1729 | Intent service, ServiceConnection conn, int flags) { |
| 1730 | if (service == null || conn == null) { |
| 1731 | Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn); |
| 1732 | return false; |
| 1733 | } |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 1734 | return mContext.bindServiceAsUser(service, conn, flags, |
| 1735 | new UserHandle(mSettings.getCurrentUserId())); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1736 | } |
| 1737 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1738 | @Override |
Yohei Yukawa | d20eef8 | 2019-02-05 10:45:32 -0800 | [diff] [blame] | 1739 | public List<InputMethodInfo> getInputMethodList(@UserIdInt int userId) { |
| 1740 | if (UserHandle.getCallingUserId() != userId) { |
| 1741 | mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); |
| 1742 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1743 | synchronized (mMethodMap) { |
Yohei Yukawa | d20eef8 | 2019-02-05 10:45:32 -0800 | [diff] [blame] | 1744 | final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId, |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1745 | mSettings.getCurrentUserId(), null); |
| 1746 | if (resolvedUserIds.length != 1) { |
| 1747 | return Collections.emptyList(); |
| 1748 | } |
| 1749 | final long ident = Binder.clearCallingIdentity(); |
| 1750 | try { |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 1751 | return getInputMethodListLocked(resolvedUserIds[0]); |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1752 | } finally { |
| 1753 | Binder.restoreCallingIdentity(ident); |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 1754 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | } |
| 1756 | } |
| 1757 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1758 | @Override |
Yohei Yukawa | 1fb13c5 | 2019-02-05 07:55:28 -0800 | [diff] [blame] | 1759 | public List<InputMethodInfo> getEnabledInputMethodList(@UserIdInt int userId) { |
| 1760 | if (UserHandle.getCallingUserId() != userId) { |
| 1761 | mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); |
| 1762 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1763 | synchronized (mMethodMap) { |
Yohei Yukawa | 1fb13c5 | 2019-02-05 07:55:28 -0800 | [diff] [blame] | 1764 | final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId, |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1765 | mSettings.getCurrentUserId(), null); |
| 1766 | if (resolvedUserIds.length != 1) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 1767 | return Collections.emptyList(); |
| 1768 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1769 | final long ident = Binder.clearCallingIdentity(); |
| 1770 | try { |
| 1771 | return getEnabledInputMethodListLocked(resolvedUserIds[0]); |
| 1772 | } finally { |
| 1773 | Binder.restoreCallingIdentity(ident); |
| 1774 | } |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 1779 | private List<InputMethodInfo> getInputMethodListLocked(@UserIdInt int userId) { |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1780 | final ArrayList<InputMethodInfo> methodList; |
| 1781 | if (userId == mSettings.getCurrentUserId()) { |
| 1782 | // Create a copy. |
| 1783 | methodList = new ArrayList<>(mMethodList); |
| 1784 | } else { |
| 1785 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 1786 | methodList = new ArrayList<>(); |
| 1787 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 1788 | new ArrayMap<>(); |
| 1789 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 1790 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap, |
| 1791 | methodList); |
| 1792 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1793 | return methodList; |
| 1794 | } |
| 1795 | |
| 1796 | @GuardedBy("mMethodMap") |
| 1797 | private List<InputMethodInfo> getEnabledInputMethodListLocked(@UserIdInt int userId) { |
| 1798 | if (userId == mSettings.getCurrentUserId()) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1799 | return mSettings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1800 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1801 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 1802 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 1803 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 1804 | new ArrayMap<>(); |
| 1805 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 1806 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap, |
| 1807 | methodList); |
| 1808 | final InputMethodSettings settings = new InputMethodSettings(mContext.getResources(), |
Yohei Yukawa | f927753 | 2019-01-25 02:47:32 -0800 | [diff] [blame] | 1809 | mContext.getContentResolver(), methodMap, userId, true); |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1810 | return settings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1811 | } |
| 1812 | |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 1813 | @GuardedBy("mMethodMap") |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 1814 | private void onCreateInlineSuggestionsRequestLocked(@UserIdInt int userId, |
| 1815 | ComponentName componentName, AutofillId autofillId, |
| 1816 | IInlineSuggestionsRequestCallback callback) { |
Adam He | 7bc8f60 | 2019-12-12 17:00:34 -0800 | [diff] [blame] | 1817 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 1818 | try { |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 1819 | if (userId == mSettings.getCurrentUserId() && imi != null |
| 1820 | && imi.isInlineSuggestionsEnabled() && mCurMethod != null) { |
Adam He | 7bc8f60 | 2019-12-12 17:00:34 -0800 | [diff] [blame] | 1821 | executeOrSendMessage(mCurMethod, |
| 1822 | mCaller.obtainMessageOOOO(MSG_INLINE_SUGGESTIONS_REQUEST, mCurMethod, |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 1823 | componentName, autofillId, |
| 1824 | new InlineSuggestionsRequestCallbackDecorator(callback, |
| 1825 | imi.getPackageName()))); |
Adam He | 7bc8f60 | 2019-12-12 17:00:34 -0800 | [diff] [blame] | 1826 | } else { |
| 1827 | callback.onInlineSuggestionsUnsupported(); |
| 1828 | } |
| 1829 | } catch (RemoteException e) { |
| 1830 | Slog.w(TAG, "RemoteException calling onCreateInlineSuggestionsRequest(): " + e); |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 1831 | } |
| 1832 | } |
| 1833 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1834 | /** |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 1835 | * The decorator which validates the host package name in the |
| 1836 | * {@link InlineSuggestionsRequest} argument to make sure it matches the IME package name. |
| 1837 | */ |
| 1838 | private static final class InlineSuggestionsRequestCallbackDecorator |
| 1839 | extends IInlineSuggestionsRequestCallback.Stub { |
| 1840 | @NonNull |
| 1841 | private final IInlineSuggestionsRequestCallback mCallback; |
| 1842 | @NonNull |
| 1843 | private final String mImePackageName; |
| 1844 | |
| 1845 | InlineSuggestionsRequestCallbackDecorator( |
| 1846 | @NonNull IInlineSuggestionsRequestCallback callback, |
| 1847 | @NonNull String imePackageName) { |
| 1848 | mCallback = callback; |
| 1849 | mImePackageName = imePackageName; |
| 1850 | } |
| 1851 | |
| 1852 | @Override |
| 1853 | public void onInlineSuggestionsUnsupported() throws RemoteException { |
| 1854 | mCallback.onInlineSuggestionsUnsupported(); |
| 1855 | } |
| 1856 | |
| 1857 | @Override |
| 1858 | public void onInlineSuggestionsRequest(InlineSuggestionsRequest request, |
| 1859 | IInlineSuggestionsResponseCallback callback) throws RemoteException { |
| 1860 | if (!mImePackageName.equals(request.getHostPackageName())) { |
| 1861 | throw new SecurityException( |
| 1862 | "Host package name in the provide request=[" + request.getHostPackageName() |
| 1863 | + "] doesn't match the IME package name=[" + mImePackageName |
| 1864 | + "]."); |
| 1865 | } |
| 1866 | mCallback.onInlineSuggestionsRequest(request, callback); |
| 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | /** |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1871 | * @param imiId if null, returns enabled subtypes for the current imi |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1872 | * @return enabled subtypes of the specified imi |
| 1873 | */ |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1874 | @Override |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1875 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId, |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 1876 | boolean allowsImplicitlySelectedSubtypes) { |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1877 | final int callingUserId = UserHandle.getCallingUserId(); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1878 | synchronized (mMethodMap) { |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1879 | final int[] resolvedUserIds = InputMethodUtils.resolveUserId(callingUserId, |
| 1880 | mSettings.getCurrentUserId(), null); |
| 1881 | if (resolvedUserIds.length != 1) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 1882 | return Collections.emptyList(); |
| 1883 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1884 | final long ident = Binder.clearCallingIdentity(); |
| 1885 | try { |
| 1886 | return getEnabledInputMethodSubtypeListLocked(imiId, |
| 1887 | allowsImplicitlySelectedSubtypes, resolvedUserIds[0]); |
| 1888 | } finally { |
| 1889 | Binder.restoreCallingIdentity(ident); |
| 1890 | } |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | @GuardedBy("mMethodMap") |
| 1895 | private List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(String imiId, |
| 1896 | boolean allowsImplicitlySelectedSubtypes, @UserIdInt int userId) { |
| 1897 | if (userId == mSettings.getCurrentUserId()) { |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1898 | final InputMethodInfo imi; |
| 1899 | if (imiId == null && mCurMethodId != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1900 | imi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1901 | } else { |
| 1902 | imi = mMethodMap.get(imiId); |
| 1903 | } |
| 1904 | if (imi == null) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 1905 | return Collections.emptyList(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 1906 | } |
| 1907 | return mSettings.getEnabledInputMethodSubtypeListLocked( |
| 1908 | mContext, imi, allowsImplicitlySelectedSubtypes); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1909 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1910 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 1911 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 1912 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 1913 | new ArrayMap<>(); |
| 1914 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 1915 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap, |
| 1916 | methodList); |
| 1917 | final InputMethodInfo imi = methodMap.get(imiId); |
| 1918 | if (imi == null) { |
| 1919 | return Collections.emptyList(); |
| 1920 | } |
| 1921 | final InputMethodSettings settings = new InputMethodSettings(mContext.getResources(), |
Yohei Yukawa | f927753 | 2019-01-25 02:47:32 -0800 | [diff] [blame] | 1922 | mContext.getContentResolver(), methodMap, userId, true); |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1923 | return settings.getEnabledInputMethodSubtypeListLocked( |
| 1924 | mContext, imi, allowsImplicitlySelectedSubtypes); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1925 | } |
| 1926 | |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1927 | /** |
| 1928 | * Called by each application process as a preparation to start interacting with |
| 1929 | * {@link InputMethodManagerService}. |
| 1930 | * |
| 1931 | * <p>As a general principle, IPCs from the application process that take |
Yohei Yukawa | 499e3f7 | 2018-10-21 20:15:11 -0700 | [diff] [blame] | 1932 | * {@link IInputMethodClient} will be rejected without this step.</p> |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1933 | * |
| 1934 | * @param client {@link android.os.Binder} proxy that is associated with the singleton instance |
| 1935 | * of {@link android.view.inputmethod.InputMethodManager} that runs on the client |
| 1936 | * process |
| 1937 | * @param inputContext communication channel for the dummy |
| 1938 | * {@link android.view.inputmethod.InputConnection} |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1939 | * @param selfReportedDisplayId self-reported display ID to which the client is associated. |
| 1940 | * Whether the client is still allowed to access to this display |
| 1941 | * or not needs to be evaluated every time the client interacts |
| 1942 | * with the display |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1943 | */ |
| 1944 | @Override |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1945 | public void addClient(IInputMethodClient client, IInputContext inputContext, |
| 1946 | int selfReportedDisplayId) { |
Yohei Yukawa | cb768bc | 2018-10-24 16:05:09 -0700 | [diff] [blame] | 1947 | // Here there are two scenarios where this method is called: |
| 1948 | // A. IMM is being instantiated in a different process and this is an IPC from that process |
| 1949 | // B. IMM is being instantiated in the same process but Binder.clearCallingIdentity() is |
| 1950 | // called in the caller side if necessary. |
| 1951 | // In either case the following UID/PID should be the ones where InputMethodManager is |
| 1952 | // actually running. |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1953 | final int callerUid = Binder.getCallingUid(); |
| 1954 | final int callerPid = Binder.getCallingPid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1955 | synchronized (mMethodMap) { |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1956 | // TODO: Optimize this linear search. |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 1957 | final int numClients = mClients.size(); |
| 1958 | for (int i = 0; i < numClients; ++i) { |
| 1959 | final ClientState state = mClients.valueAt(i); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1960 | if (state.uid == callerUid && state.pid == callerPid |
| 1961 | && state.selfReportedDisplayId == selfReportedDisplayId) { |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1962 | throw new SecurityException("uid=" + callerUid + "/pid=" + callerPid |
Yohei Yukawa | cb768bc | 2018-10-24 16:05:09 -0700 | [diff] [blame] | 1963 | + "/displayId=" + selfReportedDisplayId + " is already registered."); |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1964 | } |
| 1965 | } |
| 1966 | final ClientDeathRecipient deathRecipient = new ClientDeathRecipient(this, client); |
| 1967 | try { |
| 1968 | client.asBinder().linkToDeath(deathRecipient, 0); |
| 1969 | } catch (RemoteException e) { |
| 1970 | throw new IllegalStateException(e); |
| 1971 | } |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1972 | // We cannot fully avoid race conditions where the client UID already lost the access to |
| 1973 | // the given self-reported display ID, even if the client is not maliciously reporting |
| 1974 | // a fake display ID. Unconditionally returning SecurityException just because the |
| 1975 | // client doesn't pass display ID verification can cause many test failures hence not an |
| 1976 | // option right now. At the same time |
| 1977 | // context.getSystemService(InputMethodManager.class) |
| 1978 | // is expected to return a valid non-null instance at any time if we do not choose to |
| 1979 | // have the client crash. Thus we do not verify the display ID at all here. Instead we |
| 1980 | // later check the display ID every time the client needs to interact with the specified |
| 1981 | // display. |
| 1982 | mClients.put(client.asBinder(), new ClientState(client, inputContext, callerUid, |
| 1983 | callerPid, selfReportedDisplayId, deathRecipient)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1984 | } |
| 1985 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1986 | |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 1987 | void removeClient(IInputMethodClient client) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1988 | synchronized (mMethodMap) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1989 | ClientState cs = mClients.remove(client.asBinder()); |
| 1990 | if (cs != null) { |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 1991 | client.asBinder().unlinkToDeath(cs.clientDeathRecipient, 0); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1992 | clearClientSessionLocked(cs); |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 1993 | |
| 1994 | final int numItems = mActivityViewDisplayIdToParentMap.size(); |
| 1995 | for (int i = numItems - 1; i >= 0; --i) { |
| 1996 | final ActivityViewInfo info = mActivityViewDisplayIdToParentMap.valueAt(i); |
| 1997 | if (info.mParentClient == cs) { |
| 1998 | mActivityViewDisplayIdToParentMap.removeAt(i); |
| 1999 | } |
| 2000 | } |
| 2001 | |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 2002 | if (mCurClient == cs) { |
Tarandeep Singh | 93c00cea | 2018-02-16 14:31:17 -0800 | [diff] [blame] | 2003 | if (mBoundToMethod) { |
| 2004 | mBoundToMethod = false; |
| 2005 | if (mCurMethod != null) { |
| 2006 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 2007 | MSG_UNBIND_INPUT, mCurMethod)); |
| 2008 | } |
| 2009 | } |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 2010 | mCurClient = null; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2011 | mCurActivityViewToScreenMatrix = null; |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 2012 | } |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 2013 | if (mCurFocusedWindowClient == cs) { |
| 2014 | mCurFocusedWindowClient = null; |
| 2015 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2016 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2017 | } |
| 2018 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2019 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2020 | void executeOrSendMessage(IInterface target, Message msg) { |
| 2021 | if (target.asBinder() instanceof Binder) { |
| 2022 | mCaller.sendMessage(msg); |
| 2023 | } else { |
| 2024 | handleMessage(msg); |
| 2025 | msg.recycle(); |
| 2026 | } |
| 2027 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2028 | |
Yohei Yukawa | 4afd933 | 2018-10-21 10:43:53 -0700 | [diff] [blame] | 2029 | void unbindCurrentClientLocked(@UnbindReason int unbindClientReason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2030 | if (mCurClient != null) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2031 | if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2032 | + mCurClient.client.asBinder()); |
| 2033 | if (mBoundToMethod) { |
| 2034 | mBoundToMethod = false; |
| 2035 | if (mCurMethod != null) { |
| 2036 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 2037 | MSG_UNBIND_INPUT, mCurMethod)); |
| 2038 | } |
| 2039 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 2040 | |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 2041 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 2042 | MSG_SET_ACTIVE, 0, 0, mCurClient)); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2043 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 2044 | MSG_UNBIND_CLIENT, mCurSeq, unbindClientReason, mCurClient.client)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2045 | mCurClient.sessionRequested = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2046 | mCurClient = null; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2047 | mCurActivityViewToScreenMatrix = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2048 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2049 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2050 | } |
| 2051 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2052 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2053 | private int getImeShowFlags() { |
| 2054 | int flags = 0; |
| 2055 | if (mShowForced) { |
| 2056 | flags |= InputMethod.SHOW_FORCED |
| 2057 | | InputMethod.SHOW_EXPLICIT; |
| 2058 | } else if (mShowExplicitlyRequested) { |
| 2059 | flags |= InputMethod.SHOW_EXPLICIT; |
| 2060 | } |
| 2061 | return flags; |
| 2062 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2063 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2064 | private int getAppShowFlags() { |
| 2065 | int flags = 0; |
| 2066 | if (mShowForced) { |
| 2067 | flags |= InputMethodManager.SHOW_FORCED; |
| 2068 | } else if (!mShowExplicitlyRequested) { |
| 2069 | flags |= InputMethodManager.SHOW_IMPLICIT; |
| 2070 | } |
| 2071 | return flags; |
| 2072 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2073 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2074 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2075 | @NonNull |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 2076 | InputBindResult attachNewInputLocked(@StartInputReason int startInputReason, boolean initial) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2077 | if (!mBoundToMethod) { |
| 2078 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 2079 | MSG_BIND_INPUT, mCurMethod, mCurClient.binding)); |
| 2080 | mBoundToMethod = true; |
| 2081 | } |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 2082 | |
| 2083 | final Binder startInputToken = new Binder(); |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 2084 | final StartInputInfo info = new StartInputInfo(mSettings.getCurrentUserId(), mCurToken, |
| 2085 | mCurTokenDisplayId, mCurId, startInputReason, !initial, |
| 2086 | UserHandle.getUserId(mCurClient.uid), mCurClient.selfReportedDisplayId, |
| 2087 | mCurFocusedWindow, mCurAttribute, mCurFocusedWindowSoftInputMode, mCurSeq); |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2088 | mImeTargetWindowMap.put(startInputToken, mCurFocusedWindow); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 2089 | mStartInputHistory.addEntry(info); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 2090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | final SessionState session = mCurClient.curSession; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 2092 | executeOrSendMessage(session.method, mCaller.obtainMessageIIOOOO( |
Yohei Yukawa | f7526b5 | 2017-02-11 20:57:10 -0800 | [diff] [blame] | 2093 | MSG_START_INPUT, mCurInputContextMissingMethods, initial ? 0 : 1 /* restarting */, |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 2094 | startInputToken, session, mCurInputContext, mCurAttribute)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | if (mShowRequested) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2096 | if (DEBUG) Slog.v(TAG, "Attach new input asks to show input"); |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 2097 | showCurrentInputLocked(mCurFocusedWindow, getAppShowFlags(), null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2098 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2099 | return new InputBindResult(InputBindResult.ResultCode.SUCCESS_WITH_IME_SESSION, |
| 2100 | session.session, (session.channel != null ? session.channel.dup() : null), |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2101 | mCurId, mCurSeq, mCurActivityViewToScreenMatrix); |
| 2102 | } |
| 2103 | |
| 2104 | @Nullable |
| 2105 | private Matrix getActivityViewToScreenMatrixLocked(int clientDisplayId, int imeDisplayId) { |
| 2106 | if (clientDisplayId == imeDisplayId) { |
| 2107 | return null; |
| 2108 | } |
| 2109 | int displayId = clientDisplayId; |
| 2110 | Matrix matrix = null; |
| 2111 | while (true) { |
| 2112 | final ActivityViewInfo info = mActivityViewDisplayIdToParentMap.get(displayId); |
| 2113 | if (info == null) { |
| 2114 | return null; |
| 2115 | } |
| 2116 | if (matrix == null) { |
| 2117 | matrix = new Matrix(info.mMatrix); |
| 2118 | } else { |
| 2119 | matrix.postConcat(info.mMatrix); |
| 2120 | } |
| 2121 | if (info.mParentClient.selfReportedDisplayId == imeDisplayId) { |
| 2122 | return matrix; |
| 2123 | } |
| 2124 | displayId = info.mParentClient.selfReportedDisplayId; |
| 2125 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2126 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2127 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2128 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2129 | @NonNull |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2130 | InputBindResult startInputUncheckedLocked(@NonNull ClientState cs, IInputContext inputContext, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 2131 | @MissingMethodFlags int missingMethods, @NonNull EditorInfo attribute, |
| 2132 | @StartInputFlags int startInputFlags, @StartInputReason int startInputReason) { |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2133 | // If no method is currently selected, do nothing. |
| 2134 | if (mCurMethodId == null) { |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2135 | return InputBindResult.NO_IME; |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2136 | } |
| 2137 | |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2138 | if (!mSystemReady) { |
| 2139 | // If the system is not yet ready, we shouldn't be running third |
| 2140 | // party code. |
| 2141 | return new InputBindResult( |
| 2142 | InputBindResult.ResultCode.ERROR_SYSTEM_NOT_READY, |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2143 | null, null, mCurMethodId, mCurSeq, null); |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2144 | } |
| 2145 | |
Yohei Yukawa | d57ba67 | 2015-06-08 16:39:46 -0700 | [diff] [blame] | 2146 | if (!InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, cs.uid, |
| 2147 | attribute.packageName)) { |
| 2148 | Slog.e(TAG, "Rejecting this client as it reported an invalid package name." |
| 2149 | + " uid=" + cs.uid + " package=" + attribute.packageName); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2150 | return InputBindResult.INVALID_PACKAGE_NAME; |
Yohei Yukaw | a0f3ad1 | 2015-04-06 16:48:24 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2153 | if (!mWindowManagerInternal.isUidAllowedOnDisplay(cs.selfReportedDisplayId, cs.uid)) { |
| 2154 | // Wait, the client no longer has access to the display. |
| 2155 | return InputBindResult.INVALID_DISPLAY_ID; |
| 2156 | } |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2157 | // Compute the final shown display ID with validated cs.selfReportedDisplayId for this |
| 2158 | // session & other conditions. |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 2159 | final int displayIdToShowIme = computeImeDisplayIdForTarget(cs.selfReportedDisplayId, |
| 2160 | mImeDisplayValidator); |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2162 | if (mCurClient != cs) { |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 2163 | // Was the keyguard locked when switching over to the new client? |
| 2164 | mCurClientInKeyguard = isKeyguardLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2165 | // If the client is changing, we need to switch over to the new |
| 2166 | // one. |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 2167 | unbindCurrentClientLocked(UnbindReason.SWITCH_CLIENT); |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2168 | if (DEBUG) Slog.v(TAG, "switching to client: client=" |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 2169 | + cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2170 | |
| 2171 | // If the screen is on, inform the new client it is active |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 2172 | if (mIsInteractive) { |
tiansiming [田思明] | e102c97 | 2018-04-17 18:15:33 +0800 | [diff] [blame] | 2173 | 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] | 2174 | } |
| 2175 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | // Bump up the sequence for this client and attach it. |
| 2178 | mCurSeq++; |
| 2179 | if (mCurSeq <= 0) mCurSeq = 1; |
| 2180 | mCurClient = cs; |
| 2181 | mCurInputContext = inputContext; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2182 | mCurActivityViewToScreenMatrix = |
| 2183 | getActivityViewToScreenMatrixLocked(cs.selfReportedDisplayId, displayIdToShowIme); |
| 2184 | if (cs.selfReportedDisplayId != displayIdToShowIme |
| 2185 | && mCurActivityViewToScreenMatrix == null) { |
Yohei Yukawa | 3d2cc0f | 2019-04-25 18:32:15 -0700 | [diff] [blame] | 2186 | // CursorAnchorInfo API does not work as-is for cross-display scenario. Pretend that |
| 2187 | // InputConnection#requestCursorUpdates() is not implemented in the application so that |
| 2188 | // IMEs will always receive false from this API. |
| 2189 | missingMethods |= MissingMethodFlags.REQUEST_CURSOR_UPDATES; |
| 2190 | } |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2191 | mCurInputContextMissingMethods = missingMethods; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2192 | mCurAttribute = attribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2193 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2194 | // Check if the input method is changing. |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2195 | // We expect the caller has already verified that the client is allowed to access this |
| 2196 | // display ID. |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2197 | if (mCurId != null && mCurId.equals(mCurMethodId) |
| 2198 | && displayIdToShowIme == mCurTokenDisplayId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2199 | if (cs.curSession != null) { |
| 2200 | // Fast case: if we are already connected to the input method, |
| 2201 | // then just return it. |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2202 | return attachNewInputLocked(startInputReason, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 2203 | (startInputFlags & StartInputFlags.INITIAL_CONNECTION) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2204 | } |
| 2205 | if (mHaveConnection) { |
| 2206 | if (mCurMethod != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2207 | // Return to client, and we will get back with it when |
| 2208 | // we have had a session made for it. |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2209 | requestClientSessionLocked(cs); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2210 | return new InputBindResult( |
| 2211 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_SESSION, |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2212 | null, null, mCurId, mCurSeq, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2213 | } else if (SystemClock.uptimeMillis() |
| 2214 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 2215 | // In this case we have connected to the service, but |
| 2216 | // don't yet have its interface. If it hasn't been too |
| 2217 | // long since we did the connection, we'll return to |
| 2218 | // the client and wait to get the service interface so |
| 2219 | // we can report back. If it has been too long, we want |
| 2220 | // to fall through so we can try a disconnect/reconnect |
| 2221 | // to see if we can get back in touch with the service. |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2222 | return new InputBindResult( |
| 2223 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING, |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2224 | null, null, mCurId, mCurSeq, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2225 | } else { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2226 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, |
| 2227 | mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2228 | } |
| 2229 | } |
| 2230 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2232 | InputMethodInfo info = mMethodMap.get(mCurMethodId); |
| 2233 | if (info == null) { |
| 2234 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 2235 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2236 | |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2237 | unbindCurrentMethodLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2238 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2239 | mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE); |
| 2240 | mCurIntent.setComponent(info.getComponent()); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2241 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 2242 | com.android.internal.R.string.input_method_binding_label); |
| 2243 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 2244 | mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0)); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2245 | |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 2246 | if (bindCurrentInputMethodServiceLocked(mCurIntent, this, IME_CONNECTION_BIND_FLAGS)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2247 | mLastBindTime = SystemClock.uptimeMillis(); |
| 2248 | mHaveConnection = true; |
| 2249 | mCurId = info.getId(); |
| 2250 | mCurToken = new Binder(); |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2251 | mCurTokenDisplayId = displayIdToShowIme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2252 | try { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2253 | if (DEBUG) { |
| 2254 | Slog.v(TAG, "Adding window token: " + mCurToken + " for display: " |
| 2255 | + mCurTokenDisplayId); |
| 2256 | } |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 2257 | mIWindowManager.addWindowToken(mCurToken, LayoutParams.TYPE_INPUT_METHOD, |
| 2258 | mCurTokenDisplayId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2259 | } catch (RemoteException e) { |
| 2260 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2261 | return new InputBindResult( |
| 2262 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING, |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2263 | null, null, mCurId, mCurSeq, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2264 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2265 | mCurIntent = null; |
| 2266 | Slog.w(TAG, "Failure connecting to input method service: " + mCurIntent); |
| 2267 | return InputBindResult.IME_NOT_CONNECTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2268 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2269 | |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2270 | @FunctionalInterface |
| 2271 | interface ImeDisplayValidator { |
| 2272 | boolean displayCanShowIme(int displayId); |
| 2273 | } |
| 2274 | |
| 2275 | /** |
| 2276 | * Find the display where the IME should be shown. |
| 2277 | * |
| 2278 | * @param displayId the ID of the display where the IME client target is. |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2279 | * @param checker instance of {@link ImeDisplayValidator} which is used for |
| 2280 | * checking display config to adjust the final target display. |
| 2281 | * @return The ID of the display where the IME should be shown. |
| 2282 | */ |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 2283 | static int computeImeDisplayIdForTarget(int displayId, @NonNull ImeDisplayValidator checker) { |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2284 | if (displayId == DEFAULT_DISPLAY || displayId == INVALID_DISPLAY) { |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2285 | return FALLBACK_DISPLAY_ID; |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2286 | } |
lumark | 9a72d22 | 2019-03-30 18:31:45 +0800 | [diff] [blame] | 2287 | |
| 2288 | // Show IME window on fallback display when the display doesn't support system decorations |
| 2289 | // or the display is virtual and isn't owned by system for security concern. |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2290 | return checker.displayCanShowIme(displayId) ? displayId : FALLBACK_DISPLAY_ID; |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2291 | } |
| 2292 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2293 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 2295 | synchronized (mMethodMap) { |
| 2296 | if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { |
| 2297 | mCurMethod = IInputMethod.Stub.asInterface(service); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2298 | if (mCurToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2299 | Slog.w(TAG, "Service connected without a token!"); |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2300 | unbindCurrentMethodLocked(); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2301 | return; |
| 2302 | } |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2303 | if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2304 | // Dispatch display id for InputMethodService to update context display. |
| 2305 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 2306 | MSG_INITIALIZE_IME, mCurTokenDisplayId, mCurMethod, mCurToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2307 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2308 | clearClientSessionLocked(mCurClient); |
| 2309 | requestClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2310 | } |
| 2311 | } |
| 2312 | } |
| 2313 | } |
| 2314 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2315 | void onSessionCreated(IInputMethod method, IInputMethodSession session, |
| 2316 | InputChannel channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2317 | synchronized (mMethodMap) { |
| 2318 | if (mCurMethod != null && method != null |
| 2319 | && mCurMethod.asBinder() == method.asBinder()) { |
| 2320 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2321 | clearClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2322 | mCurClient.curSession = new SessionState(mCurClient, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2323 | method, session, channel); |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2324 | InputBindResult res = attachNewInputLocked( |
Yohei Yukawa | 4219422 | 2018-10-21 20:14:40 -0700 | [diff] [blame] | 2325 | StartInputReason.SESSION_CREATED_BY_IME, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2326 | if (res.method != null) { |
| 2327 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2328 | MSG_BIND_CLIENT, mCurClient.client, res)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2329 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2330 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2331 | } |
| 2332 | } |
| 2333 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2334 | |
| 2335 | // Session abandoned. Close its associated input channel. |
| 2336 | channel.dispose(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2337 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2338 | |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2339 | void unbindCurrentMethodLocked() { |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2340 | if (mVisibleBound) { |
| 2341 | mContext.unbindService(mVisibleConnection); |
| 2342 | mVisibleBound = false; |
| 2343 | } |
| 2344 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2345 | if (mHaveConnection) { |
| 2346 | mContext.unbindService(this); |
| 2347 | mHaveConnection = false; |
| 2348 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2349 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2350 | if (mCurToken != null) { |
| 2351 | try { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2352 | if (DEBUG) { |
| 2353 | Slog.v(TAG, "Removing window token: " + mCurToken + " for display: " |
| 2354 | + mCurTokenDisplayId); |
| 2355 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2356 | mIWindowManager.removeWindowToken(mCurToken, mCurTokenDisplayId); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2357 | } catch (RemoteException e) { |
| 2358 | } |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2359 | // Set IME window status as invisible when unbind current method. |
| 2360 | mImeWindowVis = 0; |
| 2361 | mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; |
| 2362 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2363 | mCurToken = null; |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2364 | mCurTokenDisplayId = INVALID_DISPLAY; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2365 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2366 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2367 | mCurId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2368 | clearCurMethodLocked(); |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 2369 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2370 | |
Yohei Yukawa | 4afd933 | 2018-10-21 10:43:53 -0700 | [diff] [blame] | 2371 | void resetCurrentMethodAndClient(@UnbindReason int unbindClientReason) { |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 2372 | mCurMethodId = null; |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2373 | unbindCurrentMethodLocked(); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2374 | unbindCurrentClientLocked(unbindClientReason); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2375 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2376 | |
| 2377 | void requestClientSessionLocked(ClientState cs) { |
| 2378 | if (!cs.sessionRequested) { |
| 2379 | if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs); |
| 2380 | InputChannel[] channels = InputChannel.openInputChannelPair(cs.toString()); |
| 2381 | cs.sessionRequested = true; |
| 2382 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOOO( |
| 2383 | MSG_CREATE_SESSION, mCurMethod, channels[1], |
| 2384 | new MethodCallback(this, mCurMethod, channels[0]))); |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | void clearClientSessionLocked(ClientState cs) { |
| 2389 | finishSessionLocked(cs.curSession); |
| 2390 | cs.curSession = null; |
| 2391 | cs.sessionRequested = false; |
| 2392 | } |
| 2393 | |
| 2394 | private void finishSessionLocked(SessionState sessionState) { |
| 2395 | if (sessionState != null) { |
| 2396 | if (sessionState.session != null) { |
| 2397 | try { |
| 2398 | sessionState.session.finishSession(); |
| 2399 | } catch (RemoteException e) { |
| 2400 | Slog.w(TAG, "Session failed to close due to remote exception", e); |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2401 | updateSystemUiLocked(0 /* vis */, mBackDisposition); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2402 | } |
| 2403 | sessionState.session = null; |
| 2404 | } |
| 2405 | if (sessionState.channel != null) { |
| 2406 | sessionState.channel.dispose(); |
| 2407 | sessionState.channel = null; |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2408 | } |
| 2409 | } |
| 2410 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2411 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2412 | void clearCurMethodLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2413 | if (mCurMethod != null) { |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 2414 | final int numClients = mClients.size(); |
| 2415 | for (int i = 0; i < numClients; ++i) { |
| 2416 | clearClientSessionLocked(mClients.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2417 | } |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2418 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2419 | finishSessionLocked(mEnabledSession); |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2420 | mEnabledSession = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2421 | mCurMethod = null; |
| 2422 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2423 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2424 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2425 | } |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 2426 | mInFullscreenMode = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2427 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2428 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2429 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2430 | public void onServiceDisconnected(ComponentName name) { |
Yohei Yukawa | 817d5f7 | 2017-01-04 20:15:02 -0800 | [diff] [blame] | 2431 | // Note that mContext.unbindService(this) does not trigger this. Hence if we are here the |
| 2432 | // disconnection is not intended by IMMS (e.g. triggered because the current IMS crashed), |
| 2433 | // which is irregular but can eventually happen for everyone just by continuing using the |
| 2434 | // device. Thus it is important to make sure that all the internal states are properly |
| 2435 | // refreshed when this method is called back. Running |
| 2436 | // adb install -r <APK that implements the current IME> |
| 2437 | // 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] | 2438 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2439 | if (DEBUG) Slog.v(TAG, "Service disconnected: " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2440 | + " mCurIntent=" + mCurIntent); |
| 2441 | if (mCurMethod != null && mCurIntent != null |
| 2442 | && name.equals(mCurIntent.getComponent())) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2443 | clearCurMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | // We consider this to be a new bind attempt, since the system |
| 2445 | // should now try to restart the service for us. |
| 2446 | mLastBindTime = SystemClock.uptimeMillis(); |
| 2447 | mShowRequested = mInputShown; |
| 2448 | mInputShown = false; |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 2449 | unbindCurrentClientLocked(UnbindReason.DISCONNECT_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | } |
| 2453 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 2454 | @BinderThread |
Yohei Yukawa | 41b094f | 2018-09-09 23:58:45 -0700 | [diff] [blame] | 2455 | private void updateStatusIcon(@NonNull IBinder token, String packageName, |
| 2456 | @DrawableRes int iconId) { |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2457 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 2458 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2459 | return; |
| 2460 | } |
| 2461 | final long ident = Binder.clearCallingIdentity(); |
| 2462 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | if (iconId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2464 | 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] | 2465 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2466 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2467 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2468 | } else if (packageName != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2469 | 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] | 2470 | CharSequence contentDescription = null; |
| 2471 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2472 | // Use PackageManager to load label |
| 2473 | final PackageManager packageManager = mContext.getPackageManager(); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 2474 | contentDescription = packageManager.getApplicationLabel( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2475 | mIPackageManager.getApplicationInfo(packageName, 0, |
| 2476 | mSettings.getCurrentUserId())); |
| 2477 | } catch (RemoteException e) { |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 2478 | /* ignore */ |
| 2479 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2480 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2481 | mStatusBar.setIcon(mSlotIme, packageName, iconId, 0, |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2482 | contentDescription != null |
| 2483 | ? contentDescription.toString() : null); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2484 | mStatusBar.setIconVisibility(mSlotIme, true); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2485 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2486 | } |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2487 | } finally { |
| 2488 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2489 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | } |
| 2491 | } |
| 2492 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2493 | private boolean shouldShowImeSwitcherLocked(int visibility) { |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2494 | if (!mShowOngoingImeSwitcherForPhones) return false; |
Jason Monk | 807ef76 | 2014-05-08 15:47:46 -0400 | [diff] [blame] | 2495 | if (mSwitchingDialog != null) return false; |
Yohei Yukawa | d2bc309 | 2017-07-31 15:37:14 -0700 | [diff] [blame] | 2496 | if (mWindowManagerInternal.isKeyguardShowingAndNotOccluded() |
| 2497 | && mKeyguardManager != null && mKeyguardManager.isKeyguardSecure()) return false; |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 2498 | if ((visibility & InputMethodService.IME_ACTIVE) == 0 |
| 2499 | || (visibility & InputMethodService.IME_INVISIBLE) != 0) { |
| 2500 | return false; |
| 2501 | } |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2502 | if (mWindowManagerInternal.isHardKeyboardAvailable()) { |
Yohei Yukawa | af023f2 | 2019-06-21 16:38:22 -0700 | [diff] [blame] | 2503 | // When physical keyboard is attached, we show the ime switcher (or notification if |
| 2504 | // NavBar is not available) because SHOW_IME_WITH_HARD_KEYBOARD settings currently |
| 2505 | // exists in the IME switcher dialog. Might be OK to remove this condition once |
| 2506 | // SHOW_IME_WITH_HARD_KEYBOARD settings finds a good place to live. |
| 2507 | return true; |
Yohei Yukawa | 8939838 | 2016-03-29 11:37:04 -0700 | [diff] [blame] | 2508 | } else if ((visibility & InputMethodService.IME_VISIBLE) == 0) { |
| 2509 | return false; |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2510 | } |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2511 | |
| 2512 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 2513 | final int N = imis.size(); |
| 2514 | if (N > 2) return true; |
| 2515 | if (N < 1) return false; |
| 2516 | int nonAuxCount = 0; |
| 2517 | int auxCount = 0; |
| 2518 | InputMethodSubtype nonAuxSubtype = null; |
| 2519 | InputMethodSubtype auxSubtype = null; |
| 2520 | for(int i = 0; i < N; ++i) { |
| 2521 | final InputMethodInfo imi = imis.get(i); |
| 2522 | final List<InputMethodSubtype> subtypes = |
| 2523 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
| 2524 | final int subtypeCount = subtypes.size(); |
| 2525 | if (subtypeCount == 0) { |
| 2526 | ++nonAuxCount; |
| 2527 | } else { |
| 2528 | for (int j = 0; j < subtypeCount; ++j) { |
| 2529 | final InputMethodSubtype subtype = subtypes.get(j); |
| 2530 | if (!subtype.isAuxiliary()) { |
| 2531 | ++nonAuxCount; |
| 2532 | nonAuxSubtype = subtype; |
| 2533 | } else { |
| 2534 | ++auxCount; |
| 2535 | auxSubtype = subtype; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2536 | } |
| 2537 | } |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2538 | } |
| 2539 | } |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2540 | if (nonAuxCount > 1 || auxCount > 1) { |
| 2541 | return true; |
| 2542 | } else if (nonAuxCount == 1 && auxCount == 1) { |
| 2543 | if (nonAuxSubtype != null && auxSubtype != null |
| 2544 | && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale()) |
| 2545 | || auxSubtype.overridesImplicitlyEnabledSubtype() |
| 2546 | || nonAuxSubtype.overridesImplicitlyEnabledSubtype()) |
| 2547 | && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) { |
| 2548 | return false; |
| 2549 | } |
| 2550 | return true; |
| 2551 | } |
| 2552 | return false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2553 | } |
| 2554 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 2555 | private boolean isKeyguardLocked() { |
| 2556 | return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked(); |
| 2557 | } |
| 2558 | |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2559 | @BinderThread |
satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 2560 | @SuppressWarnings("deprecation") |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 2561 | private void setImeWindowStatus(@NonNull IBinder token, int vis, int backDisposition) { |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2562 | final int topFocusedDisplayId = mWindowManagerInternal.getTopFocusedDisplayId(); |
| 2563 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2564 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 2565 | if (!calledWithValidTokenLocked(token)) { |
| 2566 | return; |
| 2567 | } |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2568 | // Skip update IME status when current token display is not same as focused display. |
| 2569 | // Note that we still need to update IME status when focusing external display |
| 2570 | // that does not support system decoration and fallback to show IME on default |
| 2571 | // display since it is intentional behavior. |
| 2572 | if (mCurTokenDisplayId != topFocusedDisplayId |
| 2573 | && mCurTokenDisplayId != FALLBACK_DISPLAY_ID) { |
| 2574 | return; |
| 2575 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2576 | mImeWindowVis = vis; |
| 2577 | mBackDisposition = backDisposition; |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2578 | updateSystemUiLocked(vis, backDisposition); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2579 | } |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2580 | |
| 2581 | final boolean dismissImeOnBackKeyPressed; |
| 2582 | switch (backDisposition) { |
| 2583 | case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: |
| 2584 | dismissImeOnBackKeyPressed = true; |
| 2585 | break; |
| 2586 | case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: |
| 2587 | dismissImeOnBackKeyPressed = false; |
| 2588 | break; |
| 2589 | default: |
| 2590 | case InputMethodService.BACK_DISPOSITION_DEFAULT: |
| 2591 | dismissImeOnBackKeyPressed = ((vis & InputMethodService.IME_VISIBLE) != 0); |
| 2592 | break; |
| 2593 | } |
Yohei Yukawa | ee2a7ed | 2017-02-15 21:38:57 -0800 | [diff] [blame] | 2594 | mWindowManagerInternal.updateInputMethodWindowStatus(token, |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2595 | (vis & InputMethodService.IME_VISIBLE) != 0, dismissImeOnBackKeyPressed); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2596 | } |
| 2597 | |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2598 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 2599 | private void reportStartInput(@NonNull IBinder token, IBinder startInputToken) { |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2600 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 2601 | if (!calledWithValidTokenLocked(token)) { |
| 2602 | return; |
| 2603 | } |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2604 | final IBinder targetWindow = mImeTargetWindowMap.get(startInputToken); |
| 2605 | if (targetWindow != null && mLastImeTargetWindow != targetWindow) { |
| 2606 | mWindowManagerInternal.updateInputMethodTargetWindow(token, targetWindow); |
| 2607 | } |
| 2608 | mLastImeTargetWindow = targetWindow; |
| 2609 | } |
| 2610 | } |
| 2611 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2612 | // Caution! This method is called in this class. Handle multi-user carefully |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2613 | private void updateSystemUiLocked(int vis, int backDisposition) { |
| 2614 | if (mCurToken == null) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2615 | return; |
| 2616 | } |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 2617 | if (DEBUG) { |
| 2618 | Slog.d(TAG, "IME window vis: " + vis |
| 2619 | + " active: " + (vis & InputMethodService.IME_ACTIVE) |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2620 | + " inv: " + (vis & InputMethodService.IME_INVISIBLE) |
| 2621 | + " displayId: " + mCurTokenDisplayId); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 2622 | } |
| 2623 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2624 | // TODO: Move this clearing calling identity block to setImeWindowStatus after making sure |
| 2625 | // all updateSystemUi happens on system previlege. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2626 | final long ident = Binder.clearCallingIdentity(); |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2627 | try { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2628 | // apply policy for binder calls |
| 2629 | if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) { |
| 2630 | vis = 0; |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2631 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2632 | // mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked(). |
| 2633 | final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis); |
| 2634 | if (mStatusBar != null) { |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2635 | mStatusBar.setImeWindowStatus(mCurTokenDisplayId, mCurToken, vis, backDisposition, |
Tarandeep Singh | 07b318b | 2019-07-17 11:12:04 -0700 | [diff] [blame] | 2636 | needsToShowImeSwitcher, false /*isMultiClientImeEnabled*/); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2637 | } |
| 2638 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 2639 | if (imi != null && needsToShowImeSwitcher) { |
| 2640 | // Used to load label |
| 2641 | final CharSequence title = mRes.getText( |
| 2642 | com.android.internal.R.string.select_input_method); |
| 2643 | final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName( |
| 2644 | mContext, imi, mCurrentSubtype); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2645 | mImeSwitcherNotification.setContentTitle(title) |
| 2646 | .setContentText(summary) |
| 2647 | .setContentIntent(mImeSwitchPendingIntent); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2648 | try { |
Charles Chen | ea6e7f0 | 2018-11-19 21:37:45 +0800 | [diff] [blame] | 2649 | // TODO(b/120076400): Figure out what is the best behavior |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2650 | if ((mNotificationManager != null) |
Charles Chen | ea6e7f0 | 2018-11-19 21:37:45 +0800 | [diff] [blame] | 2651 | && !mIWindowManager.hasNavigationBar(DEFAULT_DISPLAY)) { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2652 | if (DEBUG) { |
| 2653 | Slog.d(TAG, "--- show notification: label = " + summary); |
| 2654 | } |
| 2655 | mNotificationManager.notifyAsUser(null, |
Chris Wren | 282cfef | 2017-03-27 15:01:44 -0400 | [diff] [blame] | 2656 | SystemMessage.NOTE_SELECT_INPUT_METHOD, |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2657 | mImeSwitcherNotification.build(), UserHandle.ALL); |
| 2658 | mNotificationShown = true; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2659 | } |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2660 | } catch (RemoteException e) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2661 | } |
| 2662 | } else { |
| 2663 | if (mNotificationShown && mNotificationManager != null) { |
| 2664 | if (DEBUG) { |
| 2665 | Slog.d(TAG, "--- hide notification"); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2666 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2667 | mNotificationManager.cancelAsUser(null, |
Chris Wren | 282cfef | 2017-03-27 15:01:44 -0400 | [diff] [blame] | 2668 | SystemMessage.NOTE_SELECT_INPUT_METHOD, UserHandle.ALL); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2669 | mNotificationShown = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2670 | } |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2671 | } |
| 2672 | } finally { |
| 2673 | Binder.restoreCallingIdentity(ident); |
| 2674 | } |
| 2675 | } |
| 2676 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2677 | void updateFromSettingsLocked(boolean enabledMayChange) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 2678 | updateInputMethodsFromSettingsLocked(enabledMayChange); |
| 2679 | updateKeyboardFromSettingsLocked(); |
| 2680 | } |
| 2681 | |
| 2682 | void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2683 | if (enabledMayChange) { |
| 2684 | List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 2685 | for (int i=0; i<enabled.size(); i++) { |
| 2686 | // We allow the user to select "disabled until used" apps, so if they |
| 2687 | // are enabling one of those here we now need to make it enabled. |
| 2688 | InputMethodInfo imm = enabled.get(i); |
| 2689 | try { |
| 2690 | ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(), |
| 2691 | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, |
| 2692 | mSettings.getCurrentUserId()); |
Satoshi Kataoka | 7987a31 | 2013-04-17 18:59:33 +0900 | [diff] [blame] | 2693 | if (ai != null && ai.enabledSetting |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2694 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 2695 | if (DEBUG) { |
| 2696 | Slog.d(TAG, "Update state(" + imm.getId() |
| 2697 | + "): DISABLED_UNTIL_USED -> DEFAULT"); |
| 2698 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2699 | mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(), |
| 2700 | PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 2701 | PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(), |
| 2702 | mContext.getBasePackageName()); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2703 | } |
| 2704 | } catch (RemoteException e) { |
| 2705 | } |
| 2706 | } |
| 2707 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2708 | // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and |
| 2709 | // ENABLED_INPUT_METHODS is taking care of keeping them correctly in |
| 2710 | // sync, so we will never have a DEFAULT_INPUT_METHOD that is not |
| 2711 | // enabled. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2712 | String id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2713 | // There is no input method selected, try to choose new applicable input method. |
| 2714 | if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2715 | id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2716 | } |
| 2717 | if (!TextUtils.isEmpty(id)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2718 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2719 | setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2720 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2721 | Slog.w(TAG, "Unknown input method from prefs: " + id, e); |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 2722 | resetCurrentMethodAndClient(UnbindReason.SWITCH_IME_FAILED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2723 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2724 | } else { |
| 2725 | // 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] | 2726 | resetCurrentMethodAndClient(UnbindReason.NO_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2727 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 2728 | // Here is not the perfect place to reset the switching controller. Ideally |
| 2729 | // mSwitchingController and mSettings should be able to share the same state. |
| 2730 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 2731 | // the same enabled IMEs list. |
| 2732 | mSwitchingController.resetCircularListLocked(mContext); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 2733 | |
| 2734 | } |
| 2735 | |
| 2736 | public void updateKeyboardFromSettingsLocked() { |
| 2737 | mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled(); |
| 2738 | if (mSwitchingDialog != null |
| 2739 | && mSwitchingDialogTitleView != null |
| 2740 | && mSwitchingDialog.isShowing()) { |
| 2741 | final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById( |
| 2742 | com.android.internal.R.id.hard_keyboard_switch); |
| 2743 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
| 2744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2745 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2746 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2747 | /* package */ void setInputMethodLocked(String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2748 | InputMethodInfo info = mMethodMap.get(id); |
| 2749 | if (info == null) { |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 2750 | throw new IllegalArgumentException("Unknown id: " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2751 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2752 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2753 | // 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] | 2754 | if (id.equals(mCurMethodId)) { |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2755 | final int subtypeCount = info.getSubtypeCount(); |
| 2756 | if (subtypeCount <= 0) { |
| 2757 | return; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2758 | } |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2759 | final InputMethodSubtype oldSubtype = mCurrentSubtype; |
| 2760 | final InputMethodSubtype newSubtype; |
| 2761 | if (subtypeId >= 0 && subtypeId < subtypeCount) { |
| 2762 | newSubtype = info.getSubtypeAt(subtypeId); |
| 2763 | } else { |
| 2764 | // If subtype is null, try to find the most applicable one from |
| 2765 | // getCurrentInputMethodSubtype. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2766 | newSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2767 | } |
| 2768 | if (newSubtype == null || oldSubtype == null) { |
| 2769 | Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype |
| 2770 | + ", new subtype = " + newSubtype); |
| 2771 | return; |
| 2772 | } |
| 2773 | if (newSubtype != oldSubtype) { |
| 2774 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true); |
| 2775 | if (mCurMethod != null) { |
| 2776 | try { |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2777 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2778 | mCurMethod.changeInputMethodSubtype(newSubtype); |
| 2779 | } catch (RemoteException e) { |
| 2780 | Slog.w(TAG, "Failed to call changeInputMethodSubtype"); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2784 | return; |
| 2785 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2786 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2787 | // Changing to a different IME. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2788 | final long ident = Binder.clearCallingIdentity(); |
| 2789 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2790 | // Set a subtype to this input method. |
| 2791 | // subtypeId the name of a subtype which will be set. |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 2792 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false); |
| 2793 | // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked() |
| 2794 | // because mCurMethodId is stored as a history in |
| 2795 | // setSelectedInputMethodAndSubtypeLocked(). |
| 2796 | mCurMethodId = id; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2797 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 2798 | if (LocalServices.getService(ActivityManagerInternal.class).isSystemReady()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2799 | Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 2800 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2801 | intent.putExtra("input_method_id", id); |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 2802 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2803 | } |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 2804 | unbindCurrentClientLocked(UnbindReason.SWITCH_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2805 | } finally { |
| 2806 | Binder.restoreCallingIdentity(ident); |
| 2807 | } |
| 2808 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2809 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2810 | @Override |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 2811 | public boolean showSoftInput(IInputMethodClient client, IBinder windowToken, int flags, |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2812 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2813 | int uid = Binder.getCallingUid(); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2814 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 2815 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2816 | return false; |
| 2817 | } |
| 2818 | final long ident = Binder.clearCallingIdentity(); |
| 2819 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2820 | if (mCurClient == null || client == null |
| 2821 | || mCurClient.client.asBinder() != client.asBinder()) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 2822 | // We need to check if this is the current client with |
| 2823 | // focus in the window manager, to allow this call to |
| 2824 | // be made before input is started in it. |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 2825 | final ClientState cs = mClients.get(client.asBinder()); |
| 2826 | if (cs == null) { |
| 2827 | throw new IllegalArgumentException("unknown client " + client.asBinder()); |
| 2828 | } |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2829 | if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid, |
| 2830 | cs.selfReportedDisplayId)) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 2831 | Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2832 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2833 | } |
| 2834 | } |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2835 | if (DEBUG) Slog.v(TAG, "Client requesting input be shown"); |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 2836 | return showCurrentInputLocked(windowToken, flags, resultReceiver); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2837 | } finally { |
| 2838 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2839 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | } |
| 2841 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2842 | |
Andreas Gampe | d6d4206 | 2018-07-20 13:08:21 -0700 | [diff] [blame] | 2843 | @GuardedBy("mMethodMap") |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 2844 | boolean showCurrentInputLocked(IBinder windowToken, int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2845 | mShowRequested = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2846 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 2847 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2848 | } |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2849 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2850 | if ((flags&InputMethodManager.SHOW_FORCED) != 0) { |
| 2851 | mShowExplicitlyRequested = true; |
| 2852 | mShowForced = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 2853 | } else if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) { |
| 2854 | mShowExplicitlyRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2855 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2856 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2857 | if (!mSystemReady) { |
| 2858 | return false; |
| 2859 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2860 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2861 | boolean res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2862 | if (mCurMethod != null) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2863 | if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken); |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 2864 | // create a dummy token for IMS so that IMS cannot inject windows into client app. |
| 2865 | Binder showInputToken = new Binder(); |
| 2866 | mShowRequestWindowMap.put(showInputToken, windowToken); |
| 2867 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOOO( |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2868 | MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod, |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 2869 | resultReceiver, showInputToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2870 | mInputShown = true; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2871 | if (mHaveConnection && !mVisibleBound) { |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 2872 | bindCurrentInputMethodServiceLocked( |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 2873 | mCurIntent, mVisibleConnection, IME_VISIBLE_BIND_FLAGS); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2874 | mVisibleBound = true; |
| 2875 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2876 | res = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2877 | } else if (mHaveConnection && SystemClock.uptimeMillis() |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 2878 | >= (mLastBindTime+TIME_TO_RECONNECT)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2879 | // The client has asked to have the input method shown, but |
| 2880 | // we have been sitting here too long with a connection to the |
| 2881 | // service and no interface received, so let's disconnect/connect |
| 2882 | // to try to prod things along. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2883 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2884 | SystemClock.uptimeMillis()-mLastBindTime,1); |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 2885 | 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] | 2886 | mContext.unbindService(this); |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 2887 | bindCurrentInputMethodServiceLocked(mCurIntent, this, IME_CONNECTION_BIND_FLAGS); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2888 | } else { |
| 2889 | if (DEBUG) { |
| 2890 | Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = " |
| 2891 | + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis())); |
| 2892 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2893 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2894 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2895 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2897 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2898 | @Override |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2899 | public boolean hideSoftInput(IInputMethodClient client, int flags, |
| 2900 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 2901 | int uid = Binder.getCallingUid(); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2902 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 2903 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2904 | return false; |
| 2905 | } |
| 2906 | final long ident = Binder.clearCallingIdentity(); |
| 2907 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2908 | if (mCurClient == null || client == null |
| 2909 | || mCurClient.client.asBinder() != client.asBinder()) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 2910 | // We need to check if this is the current client with |
| 2911 | // focus in the window manager, to allow this call to |
| 2912 | // be made before input is started in it. |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 2913 | final ClientState cs = mClients.get(client.asBinder()); |
| 2914 | if (cs == null) { |
| 2915 | throw new IllegalArgumentException("unknown client " + client.asBinder()); |
| 2916 | } |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2917 | if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid, |
| 2918 | cs.selfReportedDisplayId)) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 2919 | if (DEBUG) { |
| 2920 | Slog.w(TAG, "Ignoring hideSoftInput of uid " + uid + ": " + client); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2922 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2923 | } |
| 2924 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2925 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2926 | 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] | 2927 | return hideCurrentInputLocked(flags, resultReceiver); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2928 | } finally { |
| 2929 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2930 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2931 | } |
| 2932 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2933 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2934 | boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2935 | if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0 |
| 2936 | && (mShowExplicitlyRequested || mShowForced)) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2937 | 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] | 2938 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2939 | } |
| 2940 | if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2941 | 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] | 2942 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2943 | } |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 2944 | |
| 2945 | // There is a chance that IMM#hideSoftInput() is called in a transient state where |
| 2946 | // IMMS#InputShown is already updated to be true whereas IMMS#mImeWindowVis is still waiting |
| 2947 | // to be updated with the new value sent from IME process. Even in such a transient state |
| 2948 | // historically we have accepted an incoming call of IMM#hideSoftInput() from the |
| 2949 | // application process as a valid request, and have even promised such a behavior with CTS |
| 2950 | // since Android Eclair. That's why we need to accept IMM#hideSoftInput() even when only |
| 2951 | // IMMS#InputShown indicates that the software keyboard is shown. |
| 2952 | // TODO: Clean up, IMMS#mInputShown, IMMS#mImeWindowVis and mShowRequested. |
| 2953 | final boolean shouldHideSoftInput = (mCurMethod != null) && (mInputShown || |
| 2954 | (mImeWindowVis & InputMethodService.IME_ACTIVE) != 0); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2955 | boolean res; |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 2956 | if (shouldHideSoftInput) { |
| 2957 | // The IME will report its visible state again after the following message finally |
| 2958 | // delivered to the IME process as an IPC. Hence the inconsistency between |
| 2959 | // IMMS#mInputShown and IMMS#mImeWindowVis should be resolved spontaneously in |
| 2960 | // the final state. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2961 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 2962 | MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver)); |
| 2963 | res = true; |
| 2964 | } else { |
| 2965 | res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2966 | } |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2967 | if (mHaveConnection && mVisibleBound) { |
| 2968 | mContext.unbindService(mVisibleConnection); |
| 2969 | mVisibleBound = false; |
| 2970 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2971 | mInputShown = false; |
| 2972 | mShowRequested = false; |
| 2973 | mShowExplicitlyRequested = false; |
| 2974 | mShowForced = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2975 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2976 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2977 | |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2978 | @NonNull |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 2979 | @Override |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2980 | public InputBindResult startInputOrWindowGainedFocus( |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 2981 | @StartInputReason int startInputReason, IInputMethodClient client, IBinder windowToken, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 2982 | @StartInputFlags int startInputFlags, @SoftInputModeFlags int softInputMode, |
| 2983 | int windowFlags, @Nullable EditorInfo attribute, IInputContext inputContext, |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 2984 | @MissingMethodFlags int missingMethods, int unverifiedTargetSdkVersion) { |
Yohei Yukawa | 80498d5 | 2018-06-21 16:24:36 -0700 | [diff] [blame] | 2985 | if (windowToken == null) { |
| 2986 | Slog.e(TAG, "windowToken cannot be null."); |
| 2987 | return InputBindResult.NULL; |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 2988 | } |
Yohei Yukawa | 0f5eade | 2019-01-18 08:48:07 -0800 | [diff] [blame] | 2989 | final int callingUserId = UserHandle.getCallingUserId(); |
| 2990 | final int userId; |
Yohei Yukawa | 716897c | 2019-01-22 00:00:53 -0800 | [diff] [blame] | 2991 | if (attribute != null && attribute.targetInputMethodUser != null |
Yohei Yukawa | 0f5eade | 2019-01-18 08:48:07 -0800 | [diff] [blame] | 2992 | && attribute.targetInputMethodUser.getIdentifier() != callingUserId) { |
| 2993 | mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
Yohei Yukawa | 670abea | 2019-01-28 00:00:50 -0800 | [diff] [blame] | 2994 | "Using EditorInfo.targetInputMethodUser requires INTERACT_ACROSS_USERS_FULL."); |
Yohei Yukawa | 0f5eade | 2019-01-18 08:48:07 -0800 | [diff] [blame] | 2995 | userId = attribute.targetInputMethodUser.getIdentifier(); |
| 2996 | if (!mUserManagerInternal.isUserRunning(userId)) { |
| 2997 | // There is a chance that we hit here because of race condition. Let's just return |
| 2998 | // an error code instead of crashing the caller process, which at least has |
| 2999 | // INTERACT_ACROSS_USERS_FULL permission thus is likely to be an important process. |
| 3000 | Slog.e(TAG, "User #" + userId + " is not running."); |
| 3001 | return InputBindResult.INVALID_USER; |
| 3002 | } |
| 3003 | } else { |
| 3004 | userId = callingUserId; |
| 3005 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3006 | final InputBindResult result; |
| 3007 | synchronized (mMethodMap) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3008 | final long ident = Binder.clearCallingIdentity(); |
| 3009 | try { |
| 3010 | result = startInputOrWindowGainedFocusInternalLocked(startInputReason, client, |
| 3011 | windowToken, startInputFlags, softInputMode, windowFlags, attribute, |
| 3012 | inputContext, missingMethods, unverifiedTargetSdkVersion, userId); |
| 3013 | } finally { |
| 3014 | Binder.restoreCallingIdentity(ident); |
| 3015 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3016 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 3017 | if (result == null) { |
| 3018 | // This must never happen, but just in case. |
| 3019 | Slog.wtf(TAG, "InputBindResult is @NonNull. startInputReason=" |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 3020 | + InputMethodDebug.startInputReasonToString(startInputReason) |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 3021 | + " windowFlags=#" + Integer.toHexString(windowFlags) |
| 3022 | + " editorInfo=" + attribute); |
| 3023 | return InputBindResult.NULL; |
| 3024 | } |
| 3025 | return result; |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 3026 | } |
| 3027 | |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 3028 | @NonNull |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3029 | private InputBindResult startInputOrWindowGainedFocusInternalLocked( |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 3030 | @StartInputReason int startInputReason, IInputMethodClient client, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 3031 | @NonNull IBinder windowToken, @StartInputFlags int startInputFlags, |
| 3032 | @SoftInputModeFlags int softInputMode, int windowFlags, EditorInfo attribute, |
| 3033 | IInputContext inputContext, @MissingMethodFlags int missingMethods, |
Yohei Yukawa | 4391c20 | 2019-01-28 00:49:10 -0800 | [diff] [blame] | 3034 | int unverifiedTargetSdkVersion, @UserIdInt int userId) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3035 | if (DEBUG) { |
| 3036 | Slog.v(TAG, "startInputOrWindowGainedFocusInternalLocked: reason=" |
| 3037 | + InputMethodDebug.startInputReasonToString(startInputReason) |
| 3038 | + " client=" + client.asBinder() |
| 3039 | + " inputContext=" + inputContext |
| 3040 | + " missingMethods=" |
| 3041 | + InputConnectionInspector.getMissingMethodFlagsAsString(missingMethods) |
| 3042 | + " attribute=" + attribute |
| 3043 | + " startInputFlags=" |
| 3044 | + InputMethodDebug.startInputFlagsToString(startInputFlags) |
| 3045 | + " softInputMode=" + InputMethodDebug.softInputModeToString(softInputMode) |
| 3046 | + " windowFlags=#" + Integer.toHexString(windowFlags) |
| 3047 | + " unverifiedTargetSdkVersion=" + unverifiedTargetSdkVersion); |
| 3048 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3049 | |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3050 | final int windowDisplayId = mWindowManagerInternal.getDisplayIdForWindow(windowToken); |
| 3051 | |
| 3052 | final ClientState cs = mClients.get(client.asBinder()); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3053 | if (cs == null) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3054 | throw new IllegalArgumentException("unknown client " + client.asBinder()); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3055 | } |
| 3056 | if (cs.selfReportedDisplayId != windowDisplayId) { |
| 3057 | Slog.e(TAG, "startInputOrWindowGainedFocusInternal: display ID mismatch." |
| 3058 | + " from client:" + cs.selfReportedDisplayId |
| 3059 | + " from window:" + windowDisplayId); |
| 3060 | return InputBindResult.DISPLAY_ID_MISMATCH; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3061 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 3062 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3063 | if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid, |
| 3064 | cs.selfReportedDisplayId)) { |
| 3065 | // Check with the window manager to make sure this client actually |
| 3066 | // has a window with focus. If not, reject. This is thread safe |
| 3067 | // because if the focus changes some time before or after, the |
| 3068 | // next client receiving focus that has any interest in input will |
| 3069 | // be calling through here after that change happens. |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3070 | if (DEBUG) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3071 | Slog.w(TAG, "Focus gain on non-focused client " + cs.client |
| 3072 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3073 | } |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3074 | return InputBindResult.NOT_IME_TARGET_WINDOW; |
| 3075 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3076 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3077 | // cross-profile access is always allowed here to allow profile-switching. |
| 3078 | if (!mSettings.isCurrentProfile(userId)) { |
| 3079 | Slog.w(TAG, "A background user is requesting window. Hiding IME."); |
| 3080 | Slog.w(TAG, "If you need to impersonate a foreground user/profile from" |
| 3081 | + " a background user, use EditorInfo.targetInputMethodUser with" |
| 3082 | + " INTERACT_ACROSS_USERS_FULL permission."); |
| 3083 | hideCurrentInputLocked(0, null); |
| 3084 | return InputBindResult.INVALID_USER; |
| 3085 | } |
| 3086 | |
Tarandeep Singh | cf5ff82 | 2019-07-08 14:06:27 -0700 | [diff] [blame] | 3087 | if (userId != mSettings.getCurrentUserId()) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3088 | switchUserLocked(userId); |
| 3089 | } |
| 3090 | // Master feature flag that overrides other conditions and forces IME preRendering. |
| 3091 | if (DEBUG) { |
| 3092 | Slog.v(TAG, "IME PreRendering MASTER flag: " |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3093 | + DebugFlags.FLAG_PRE_RENDER_IME_VIEWS.value() + ", LowRam: " + mIsLowRam); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3094 | } |
| 3095 | // pre-rendering not supported on low-ram devices. |
| 3096 | cs.shouldPreRenderIme = DebugFlags.FLAG_PRE_RENDER_IME_VIEWS.value() && !mIsLowRam; |
| 3097 | |
| 3098 | if (mCurFocusedWindow == windowToken) { |
| 3099 | if (DEBUG) { |
| 3100 | Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client |
| 3101 | + " attribute=" + attribute + ", token = " + windowToken); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3102 | } |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3103 | if (attribute != null) { |
| 3104 | return startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 3105 | attribute, startInputFlags, startInputReason); |
| 3106 | } |
| 3107 | return new InputBindResult( |
| 3108 | InputBindResult.ResultCode.SUCCESS_REPORT_WINDOW_FOCUS_ONLY, |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 3109 | null, null, null, -1, null); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3110 | } |
| 3111 | mCurFocusedWindow = windowToken; |
| 3112 | mCurFocusedWindowSoftInputMode = softInputMode; |
| 3113 | mCurFocusedWindowClient = cs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3114 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3115 | // Should we auto-show the IME even if the caller has not |
| 3116 | // specified what should be done with it? |
| 3117 | // We only do this automatically if the window can resize |
| 3118 | // to accommodate the IME (so what the user sees will give |
| 3119 | // them good context without input information being obscured |
| 3120 | // by the IME) or if running on a large screen where there |
| 3121 | // is more room for the target window + IME. |
| 3122 | final boolean doAutoShow = |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3123 | (softInputMode & LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 3124 | == LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3125 | || mRes.getConfiguration().isLayoutSizeAtLeast( |
| 3126 | Configuration.SCREENLAYOUT_SIZE_LARGE); |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3127 | final boolean isTextEditor = (startInputFlags & StartInputFlags.IS_TEXT_EDITOR) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3128 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3129 | // We want to start input before showing the IME, but after closing |
| 3130 | // it. We want to do this after closing it to help the IME disappear |
| 3131 | // more quickly (not get stuck behind it initializing itself for the |
| 3132 | // new focused input, even if its window wants to hide the IME). |
| 3133 | boolean didStart = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3134 | |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3135 | InputBindResult res = null; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3136 | switch (softInputMode & LayoutParams.SOFT_INPUT_MASK_STATE) { |
| 3137 | case LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3138 | if (!isTextEditor || !doAutoShow) { |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3139 | if (LayoutParams.mayUseInputMethod(windowFlags)) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3140 | // There is no focus view, and this window will |
| 3141 | // be behind any soft input window, so hide the |
| 3142 | // soft input window if it is shown. |
| 3143 | if (DEBUG) Slog.v(TAG, "Unspecified window will hide input"); |
| 3144 | hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3145 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3146 | // If focused display changed, we should unbind current method |
| 3147 | // to make app window in previous display relayout after Ime |
| 3148 | // window token removed. |
| 3149 | // Note that we can trust client's display ID as long as it matches |
| 3150 | // to the display ID obtained from the window. |
| 3151 | if (cs.selfReportedDisplayId != mCurTokenDisplayId) { |
| 3152 | unbindCurrentMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3153 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3154 | } |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3155 | } else if (isTextEditor && doAutoShow |
| 3156 | && (softInputMode & LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3157 | // There is a focus view, and we are navigating forward |
| 3158 | // into the window, so show the input window for the user. |
| 3159 | // We only do this automatically if the window can resize |
| 3160 | // to accommodate the IME (so what the user sees will give |
| 3161 | // them good context without input information being obscured |
| 3162 | // by the IME) or if running on a large screen where there |
| 3163 | // is more room for the target window + IME. |
| 3164 | if (DEBUG) Slog.v(TAG, "Unspecified window will show input"); |
| 3165 | if (attribute != null) { |
| 3166 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 3167 | attribute, startInputFlags, startInputReason); |
| 3168 | didStart = true; |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3169 | } |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 3170 | showCurrentInputLocked(windowToken, InputMethodManager.SHOW_IMPLICIT, null); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3171 | } |
| 3172 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3173 | case LayoutParams.SOFT_INPUT_STATE_UNCHANGED: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3174 | // Do nothing. |
| 3175 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3176 | case LayoutParams.SOFT_INPUT_STATE_HIDDEN: |
| 3177 | if ((softInputMode & LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3178 | if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward"); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3179 | hideCurrentInputLocked(0, null); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3180 | } |
| 3181 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3182 | case LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3183 | if (DEBUG) Slog.v(TAG, "Window asks to hide input"); |
| 3184 | hideCurrentInputLocked(0, null); |
| 3185 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3186 | case LayoutParams.SOFT_INPUT_STATE_VISIBLE: |
| 3187 | if ((softInputMode & LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3188 | if (DEBUG) Slog.v(TAG, "Window asks to show input going forward"); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3189 | if (InputMethodUtils.isSoftInputModeStateVisibleAllowed( |
| 3190 | unverifiedTargetSdkVersion, startInputFlags)) { |
| 3191 | if (attribute != null) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3192 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 3193 | attribute, startInputFlags, startInputReason); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3194 | didStart = true; |
| 3195 | } |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 3196 | showCurrentInputLocked(windowToken, InputMethodManager.SHOW_IMPLICIT, null); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3197 | } else { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3198 | Slog.e(TAG, "SOFT_INPUT_STATE_VISIBLE is ignored because" |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3199 | + " there is no focused view that also returns true from" |
| 3200 | + " View#onCheckIsTextEditor()"); |
| 3201 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3202 | } |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3203 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3204 | case LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3205 | if (DEBUG) Slog.v(TAG, "Window asks to always show input"); |
| 3206 | if (InputMethodUtils.isSoftInputModeStateVisibleAllowed( |
| 3207 | unverifiedTargetSdkVersion, startInputFlags)) { |
| 3208 | if (attribute != null) { |
| 3209 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 3210 | attribute, startInputFlags, startInputReason); |
| 3211 | didStart = true; |
| 3212 | } |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 3213 | showCurrentInputLocked(windowToken, InputMethodManager.SHOW_IMPLICIT, null); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3214 | } else { |
| 3215 | Slog.e(TAG, "SOFT_INPUT_STATE_ALWAYS_VISIBLE is ignored because" |
| 3216 | + " there is no focused view that also returns true from" |
| 3217 | + " View#onCheckIsTextEditor()"); |
| 3218 | } |
| 3219 | break; |
| 3220 | } |
| 3221 | |
| 3222 | if (!didStart) { |
| 3223 | if (attribute != null) { |
| 3224 | if (!DebugFlags.FLAG_OPTIMIZE_START_INPUT.value() |
| 3225 | || (startInputFlags & StartInputFlags.IS_TEXT_EDITOR) != 0) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3226 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, attribute, |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3227 | startInputFlags, startInputReason); |
| 3228 | } else { |
| 3229 | res = InputBindResult.NO_EDITOR; |
| 3230 | } |
| 3231 | } else { |
| 3232 | res = InputBindResult.NULL_EDITOR_INFO; |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3233 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3234 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 3235 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3236 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3237 | |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3238 | private boolean canShowInputMethodPickerLocked(IInputMethodClient client) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 3239 | // TODO(yukawa): multi-display support. |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3240 | final int uid = Binder.getCallingUid(); |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3241 | if (mCurFocusedWindowClient != null && client != null |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 3242 | && mCurFocusedWindowClient.client.asBinder() == client.asBinder()) { |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3243 | return true; |
| 3244 | } else if (mCurIntent != null && InputMethodUtils.checkIfPackageBelongsToUid( |
| 3245 | mAppOpsManager, |
| 3246 | uid, |
| 3247 | mCurIntent.getComponent().getPackageName())) { |
| 3248 | return true; |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3249 | } |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3250 | return false; |
| 3251 | } |
| 3252 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3253 | @Override |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3254 | public void showInputMethodPickerFromClient( |
| 3255 | IInputMethodClient client, int auxiliarySubtypeMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3256 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3257 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3258 | return; |
| 3259 | } |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3260 | if(!canShowInputMethodPickerLocked(client)) { |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3261 | Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid " |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 3262 | + Binder.getCallingUid() + ": " + client); |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3263 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3264 | } |
| 3265 | |
satok | 440aab5 | 2010-11-25 09:43:11 +0900 | [diff] [blame] | 3266 | // Always call subtype picker, because subtype picker is a superset of input method |
| 3267 | // picker. |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3268 | mHandler.sendMessage(mCaller.obtainMessageII( |
| 3269 | MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, |
| 3270 | (mCurClient != null) ? mCurClient.selfReportedDisplayId : DEFAULT_DISPLAY)); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3271 | } |
| 3272 | } |
| 3273 | |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3274 | @Override |
| 3275 | public void showInputMethodPickerFromSystem(IInputMethodClient client, int auxiliarySubtypeMode, |
| 3276 | int displayId) { |
| 3277 | if (mContext.checkCallingPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 3278 | != PackageManager.PERMISSION_GRANTED) { |
| 3279 | throw new SecurityException( |
| 3280 | "showInputMethodPickerFromSystem requires WRITE_SECURE_SETTINGS permission"); |
| 3281 | } |
| 3282 | // Always call subtype picker, because subtype picker is a superset of input method |
| 3283 | // picker. |
| 3284 | mHandler.sendMessage(mCaller.obtainMessageII( |
| 3285 | MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, displayId)); |
| 3286 | } |
| 3287 | |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 3288 | public boolean isInputMethodPickerShownForTest() { |
| 3289 | synchronized(mMethodMap) { |
| 3290 | if (mSwitchingDialog == null) { |
| 3291 | return false; |
| 3292 | } |
| 3293 | return mSwitchingDialog.isShowing(); |
| 3294 | } |
| 3295 | } |
| 3296 | |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 3297 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3298 | private void setInputMethod(@NonNull IBinder token, String id) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3299 | synchronized (mMethodMap) { |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 3300 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3301 | return; |
| 3302 | } |
| 3303 | setInputMethodWithSubtypeIdLocked(token, id, NOT_A_SUBTYPE_ID); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3304 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3305 | } |
| 3306 | |
Yohei Yukawa | 4773ee1 | 2018-12-24 21:13:53 -0800 | [diff] [blame] | 3307 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3308 | private void setInputMethodAndSubtype(@NonNull IBinder token, String id, |
| 3309 | InputMethodSubtype subtype) { |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3310 | synchronized (mMethodMap) { |
Yohei Yukawa | 4773ee1 | 2018-12-24 21:13:53 -0800 | [diff] [blame] | 3311 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3312 | return; |
| 3313 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3314 | if (subtype != null) { |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3315 | setInputMethodWithSubtypeIdLocked(token, id, |
| 3316 | InputMethodUtils.getSubtypeIdFromHashCode(mMethodMap.get(id), |
| 3317 | subtype.hashCode())); |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3318 | } else { |
| 3319 | setInputMethod(token, id); |
| 3320 | } |
| 3321 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3322 | } |
| 3323 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3324 | @Override |
satok | b416a71e | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3325 | public void showInputMethodAndSubtypeEnablerFromClient( |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3326 | IInputMethodClient client, String inputMethodId) { |
satok | b416a71e | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3327 | synchronized (mMethodMap) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3328 | // TODO(yukawa): Should we verify the display ID? |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3329 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3330 | return; |
| 3331 | } |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3332 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 3333 | MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId)); |
satok | b416a71e | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3334 | } |
| 3335 | } |
| 3336 | |
Yohei Yukawa | 0c49908 | 2018-12-09 18:52:02 -0800 | [diff] [blame] | 3337 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3338 | private boolean switchToPreviousInputMethod(@NonNull IBinder token) { |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3339 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3340 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 0c49908 | 2018-12-09 18:52:02 -0800 | [diff] [blame] | 3341 | return false; |
| 3342 | } |
satok | c445bcd | 2011-01-25 18:57:24 +0900 | [diff] [blame] | 3343 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3344 | final InputMethodInfo lastImi; |
satok | 208d563 | 2011-05-20 22:13:38 +0900 | [diff] [blame] | 3345 | if (lastIme != null) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3346 | lastImi = mMethodMap.get(lastIme.first); |
| 3347 | } else { |
| 3348 | lastImi = null; |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3349 | } |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3350 | String targetLastImiId = null; |
| 3351 | int subtypeId = NOT_A_SUBTYPE_ID; |
| 3352 | if (lastIme != null && lastImi != null) { |
| 3353 | final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId); |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3354 | final int lastSubtypeHash = Integer.parseInt(lastIme.second); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3355 | final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID |
| 3356 | : mCurrentSubtype.hashCode(); |
| 3357 | // If the last IME is the same as the current IME and the last subtype is not |
| 3358 | // defined, there is no need to switch to the last IME. |
| 3359 | if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) { |
| 3360 | targetLastImiId = lastIme.first; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3361 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3362 | } |
| 3363 | } |
| 3364 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3365 | if (TextUtils.isEmpty(targetLastImiId) |
| 3366 | && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3367 | // This is a safety net. If the currentSubtype can't be added to the history |
| 3368 | // and the framework couldn't find the last ime, we will make the last ime be |
| 3369 | // the most applicable enabled keyboard subtype of the system imes. |
| 3370 | final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 3371 | if (enabled != null) { |
| 3372 | final int N = enabled.size(); |
| 3373 | final String locale = mCurrentSubtype == null |
| 3374 | ? mRes.getConfiguration().locale.toString() |
| 3375 | : mCurrentSubtype.getLocale(); |
| 3376 | for (int i = 0; i < N; ++i) { |
| 3377 | final InputMethodInfo imi = enabled.get(i); |
Yohei Yukawa | fd70fe8 | 2018-04-08 12:19:56 -0700 | [diff] [blame] | 3378 | if (imi.getSubtypeCount() > 0 && imi.isSystem()) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3379 | InputMethodSubtype keyboardSubtype = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3380 | InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, |
| 3381 | InputMethodUtils.getSubtypes(imi), |
| 3382 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3383 | if (keyboardSubtype != null) { |
| 3384 | targetLastImiId = imi.getId(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3385 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3386 | imi, keyboardSubtype.hashCode()); |
| 3387 | if(keyboardSubtype.getLocale().equals(locale)) { |
| 3388 | break; |
| 3389 | } |
| 3390 | } |
| 3391 | } |
| 3392 | } |
| 3393 | } |
| 3394 | } |
| 3395 | |
| 3396 | if (!TextUtils.isEmpty(targetLastImiId)) { |
| 3397 | if (DEBUG) { |
| 3398 | Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second |
| 3399 | + ", from: " + mCurMethodId + ", " + subtypeId); |
| 3400 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3401 | setInputMethodWithSubtypeIdLocked(token, targetLastImiId, subtypeId); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3402 | return true; |
| 3403 | } else { |
| 3404 | return false; |
| 3405 | } |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3406 | } |
| 3407 | } |
| 3408 | |
Yohei Yukawa | 70f17e7 | 2018-12-09 18:51:38 -0800 | [diff] [blame] | 3409 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3410 | private boolean switchToNextInputMethod(@NonNull IBinder token, boolean onlyCurrentIme) { |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3411 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3412 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 3413 | return false; |
| 3414 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3415 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | 136b6ce | 2018-05-02 10:55:35 -0700 | [diff] [blame] | 3416 | onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3417 | if (nextSubtype == null) { |
| 3418 | return false; |
| 3419 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3420 | setInputMethodWithSubtypeIdLocked(token, nextSubtype.mImi.getId(), |
| 3421 | nextSubtype.mSubtypeId); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3422 | return true; |
| 3423 | } |
| 3424 | } |
| 3425 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 3426 | @BinderThread |
| 3427 | private boolean shouldOfferSwitchingToNextInputMethod(@NonNull IBinder token) { |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 3428 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3429 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 3430 | return false; |
| 3431 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3432 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | 136b6ce | 2018-05-02 10:55:35 -0700 | [diff] [blame] | 3433 | false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype); |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 3434 | if (nextSubtype == null) { |
| 3435 | return false; |
| 3436 | } |
| 3437 | return true; |
| 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | @Override |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3442 | public InputMethodSubtype getLastInputMethodSubtype() { |
| 3443 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3444 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3445 | return null; |
| 3446 | } |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3447 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
| 3448 | // TODO: Handle the case of the last IME with no subtypes |
| 3449 | if (lastIme == null || TextUtils.isEmpty(lastIme.first) |
| 3450 | || TextUtils.isEmpty(lastIme.second)) return null; |
| 3451 | final InputMethodInfo lastImi = mMethodMap.get(lastIme.first); |
| 3452 | if (lastImi == null) return null; |
| 3453 | try { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3454 | final int lastSubtypeHash = Integer.parseInt(lastIme.second); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3455 | final int lastSubtypeId = |
| 3456 | InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 0e7d7d6 | 2011-07-05 13:28:06 +0900 | [diff] [blame] | 3457 | if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) { |
| 3458 | return null; |
| 3459 | } |
| 3460 | return lastImi.getSubtypeAt(lastSubtypeId); |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3461 | } catch (NumberFormatException e) { |
| 3462 | return null; |
| 3463 | } |
| 3464 | } |
| 3465 | } |
| 3466 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3467 | @Override |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3468 | public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) { |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3469 | // By this IPC call, only a process which shares the same uid with the IME can add |
| 3470 | // additional input method subtypes to the IME. |
Yohei Yukawa | 70f5c48 | 2016-01-04 19:42:36 -0800 | [diff] [blame] | 3471 | if (TextUtils.isEmpty(imiId) || subtypes == null) return; |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3472 | final ArrayList<InputMethodSubtype> toBeAdded = new ArrayList<>(); |
| 3473 | for (InputMethodSubtype subtype : subtypes) { |
| 3474 | if (!toBeAdded.contains(subtype)) { |
| 3475 | toBeAdded.add(subtype); |
| 3476 | } else { |
| 3477 | Slog.w(TAG, "Duplicated subtype definition found: " |
| 3478 | + subtype.getLocale() + ", " + subtype.getMode()); |
| 3479 | } |
| 3480 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3481 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3482 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3483 | return; |
| 3484 | } |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 3485 | if (!mSystemReady) { |
| 3486 | return; |
| 3487 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3488 | final InputMethodInfo imi = mMethodMap.get(imiId); |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3489 | if (imi == null) return; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3490 | final String[] packageInfos; |
| 3491 | try { |
| 3492 | packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 3493 | } catch (RemoteException e) { |
| 3494 | Slog.e(TAG, "Failed to get package infos"); |
| 3495 | return; |
| 3496 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3497 | if (packageInfos != null) { |
| 3498 | final int packageNum = packageInfos.length; |
| 3499 | for (int i = 0; i < packageNum; ++i) { |
| 3500 | if (packageInfos[i].equals(imi.getPackageName())) { |
Yohei Yukawa | 7b1c8d7 | 2018-12-19 11:21:04 -0800 | [diff] [blame] | 3501 | if (subtypes.length > 0) { |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3502 | mAdditionalSubtypeMap.put(imi.getId(), toBeAdded); |
Yohei Yukawa | 7b1c8d7 | 2018-12-19 11:21:04 -0800 | [diff] [blame] | 3503 | } else { |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3504 | mAdditionalSubtypeMap.remove(imi.getId()); |
Yohei Yukawa | 7b1c8d7 | 2018-12-19 11:21:04 -0800 | [diff] [blame] | 3505 | } |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3506 | AdditionalSubtypeUtils.save(mAdditionalSubtypeMap, mMethodMap, |
| 3507 | mSettings.getCurrentUserId()); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 3508 | final long ident = Binder.clearCallingIdentity(); |
| 3509 | try { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3510 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 3511 | } finally { |
| 3512 | Binder.restoreCallingIdentity(ident); |
| 3513 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3514 | return; |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3515 | } |
| 3516 | } |
| 3517 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3518 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3519 | return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3520 | } |
| 3521 | |
Yohei Yukawa | b985e6e | 2018-09-05 17:07:52 -0700 | [diff] [blame] | 3522 | /** |
Artur Satayev | 192ca30 | 2020-01-22 21:38:23 +0000 | [diff] [blame] | 3523 | * This is kept due to {@code @UnsupportedAppUsage} in |
Yohei Yukawa | b985e6e | 2018-09-05 17:07:52 -0700 | [diff] [blame] | 3524 | * {@link InputMethodManager#getInputMethodWindowVisibleHeight()} and a dependency in |
| 3525 | * {@link InputMethodService#onCreate()}. |
| 3526 | * |
| 3527 | * <p>TODO(Bug 113914148): Check if we can remove this.</p> |
| 3528 | * @return {@link WindowManagerInternal#getInputMethodWindowVisibleHeight()} |
| 3529 | */ |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 3530 | @Override |
| 3531 | public int getInputMethodWindowVisibleHeight() { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 3532 | // TODO(yukawa): Should we verify the display ID? |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3533 | return mWindowManagerInternal.getInputMethodWindowVisibleHeight(mCurTokenDisplayId); |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 3534 | } |
| 3535 | |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 3536 | @Override |
| 3537 | public void reportActivityView(IInputMethodClient parentClient, int childDisplayId, |
| 3538 | float[] matrixValues) { |
| 3539 | final DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(childDisplayId); |
| 3540 | if (displayInfo == null) { |
| 3541 | throw new IllegalArgumentException( |
| 3542 | "Cannot find display for non-existent displayId: " + childDisplayId); |
| 3543 | } |
| 3544 | final int callingUid = Binder.getCallingUid(); |
| 3545 | if (callingUid != displayInfo.ownerUid) { |
| 3546 | throw new SecurityException("The caller doesn't own the display."); |
| 3547 | } |
| 3548 | |
| 3549 | synchronized (mMethodMap) { |
| 3550 | final ClientState cs = mClients.get(parentClient.asBinder()); |
| 3551 | if (cs == null) { |
| 3552 | return; |
| 3553 | } |
| 3554 | |
| 3555 | // null matrixValues means that the entry needs to be removed. |
| 3556 | if (matrixValues == null) { |
| 3557 | final ActivityViewInfo info = mActivityViewDisplayIdToParentMap.get(childDisplayId); |
| 3558 | if (info == null) { |
| 3559 | return; |
| 3560 | } |
| 3561 | if (info.mParentClient != cs) { |
| 3562 | throw new SecurityException("Only the owner client can clear" |
| 3563 | + " ActivityViewGeometry for display #" + childDisplayId); |
| 3564 | } |
| 3565 | mActivityViewDisplayIdToParentMap.remove(childDisplayId); |
| 3566 | return; |
| 3567 | } |
| 3568 | |
| 3569 | ActivityViewInfo info = mActivityViewDisplayIdToParentMap.get(childDisplayId); |
| 3570 | if (info != null && info.mParentClient != cs) { |
| 3571 | throw new InvalidParameterException("Display #" + childDisplayId |
| 3572 | + " is already registered by " + info.mParentClient); |
| 3573 | } |
| 3574 | if (info == null) { |
| 3575 | if (!mWindowManagerInternal.isUidAllowedOnDisplay(childDisplayId, cs.uid)) { |
| 3576 | throw new SecurityException(cs + " cannot access to display #" |
| 3577 | + childDisplayId); |
| 3578 | } |
| 3579 | info = new ActivityViewInfo(cs, new Matrix()); |
| 3580 | mActivityViewDisplayIdToParentMap.put(childDisplayId, info); |
| 3581 | } |
| 3582 | info.mMatrix.setValues(matrixValues); |
| 3583 | |
| 3584 | if (mCurClient == null || mCurClient.curSession == null) { |
| 3585 | return; |
| 3586 | } |
| 3587 | |
| 3588 | Matrix matrix = null; |
| 3589 | int displayId = mCurClient.selfReportedDisplayId; |
| 3590 | boolean needToNotify = false; |
| 3591 | while (true) { |
| 3592 | needToNotify |= (displayId == childDisplayId); |
| 3593 | final ActivityViewInfo next = mActivityViewDisplayIdToParentMap.get(displayId); |
| 3594 | if (next == null) { |
| 3595 | break; |
| 3596 | } |
| 3597 | if (matrix == null) { |
| 3598 | matrix = new Matrix(next.mMatrix); |
| 3599 | } else { |
| 3600 | matrix.postConcat(next.mMatrix); |
| 3601 | } |
| 3602 | if (next.mParentClient.selfReportedDisplayId == mCurTokenDisplayId) { |
| 3603 | if (needToNotify) { |
| 3604 | final float[] values = new float[9]; |
| 3605 | matrix.getValues(values); |
| 3606 | try { |
| 3607 | mCurClient.client.updateActivityViewToScreenMatrix(mCurSeq, values); |
| 3608 | } catch (RemoteException e) { |
| 3609 | } |
| 3610 | } |
| 3611 | break; |
| 3612 | } |
| 3613 | displayId = info.mParentClient.selfReportedDisplayId; |
| 3614 | } |
| 3615 | } |
| 3616 | } |
| 3617 | |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 3618 | @BinderThread |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3619 | private void notifyUserAction(@NonNull IBinder token) { |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3620 | if (DEBUG) { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3621 | Slog.d(TAG, "Got the notification of a user action."); |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3622 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3623 | synchronized (mMethodMap) { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3624 | if (mCurToken != token) { |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3625 | if (DEBUG) { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3626 | Slog.d(TAG, "Ignoring the user action notification from IMEs that are no longer" |
| 3627 | + " active."); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3628 | } |
| 3629 | return; |
| 3630 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3631 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 3632 | if (imi != null) { |
Yohei Yukawa | 0297051 | 2014-06-05 16:16:18 +0900 | [diff] [blame] | 3633 | mSwitchingController.onUserActionLocked(imi, mCurrentSubtype); |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3634 | } |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3635 | } |
| 3636 | } |
| 3637 | |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 3638 | @BinderThread |
| 3639 | private void reportPreRendered(IBinder token, EditorInfo info) { |
| 3640 | synchronized (mMethodMap) { |
| 3641 | if (!calledWithValidTokenLocked(token)) { |
| 3642 | return; |
| 3643 | } |
| 3644 | if (mCurClient != null && mCurClient.client != null) { |
| 3645 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
| 3646 | MSG_REPORT_PRE_RENDERED, info, mCurClient)); |
| 3647 | } |
| 3648 | } |
| 3649 | } |
| 3650 | |
| 3651 | @BinderThread |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 3652 | private void applyImeVisibility(IBinder token, IBinder windowToken, boolean setVisible) { |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 3653 | synchronized (mMethodMap) { |
| 3654 | if (!calledWithValidTokenLocked(token)) { |
| 3655 | return; |
| 3656 | } |
Tarandeep Singh | 500a38f | 2019-09-26 13:36:40 -0700 | [diff] [blame] | 3657 | if (!setVisible) { |
Taran Singh | d7fc586 | 2019-10-10 14:45:17 +0200 | [diff] [blame] | 3658 | if (mCurClient != null) { |
| 3659 | // IMMS only knows of focused window, not the actual IME target. |
| 3660 | // e.g. it isn't aware of any window that has both |
| 3661 | // NOT_FOCUSABLE, ALT_FOCUSABLE_IM flags set and can the IME target. |
| 3662 | // Send it to window manager to hide IME from IME target window. |
| 3663 | // TODO(b/139861270): send to mCurClient.client once IMMS is aware of |
| 3664 | // actual IME target. |
| 3665 | mWindowManagerInternal.hideIme(mCurClient.selfReportedDisplayId); |
Tarandeep Singh | 500a38f | 2019-09-26 13:36:40 -0700 | [diff] [blame] | 3666 | } |
| 3667 | } else { |
| 3668 | // Send to window manager to show IME after IME layout finishes. |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 3669 | mWindowManagerInternal.showImePostLayout(mShowRequestWindowMap.get(windowToken)); |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 3670 | } |
| 3671 | } |
| 3672 | } |
| 3673 | |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3674 | private void setInputMethodWithSubtypeIdLocked(IBinder token, String id, int subtypeId) { |
| 3675 | if (token == null) { |
| 3676 | if (mContext.checkCallingOrSelfPermission( |
| 3677 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 3678 | != PackageManager.PERMISSION_GRANTED) { |
| 3679 | throw new SecurityException( |
| 3680 | "Using null token requires permission " |
| 3681 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3682 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3683 | } else if (mCurToken != token) { |
| 3684 | Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid() |
| 3685 | + " token: " + token); |
| 3686 | return; |
| 3687 | } |
| 3688 | |
| 3689 | final long ident = Binder.clearCallingIdentity(); |
| 3690 | try { |
| 3691 | setInputMethodLocked(id, subtypeId); |
| 3692 | } finally { |
| 3693 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3694 | } |
| 3695 | } |
| 3696 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 3697 | @BinderThread |
| 3698 | private void hideMySoftInput(@NonNull IBinder token, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3699 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3700 | if (!calledWithValidTokenLocked(token)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3701 | return; |
| 3702 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3703 | long ident = Binder.clearCallingIdentity(); |
| 3704 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3705 | hideCurrentInputLocked(flags, null); |
| 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(ident); |
| 3708 | } |
| 3709 | } |
| 3710 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3711 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 3712 | @BinderThread |
| 3713 | private void showMySoftInput(@NonNull IBinder token, int flags) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3714 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3715 | if (!calledWithValidTokenLocked(token)) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3716 | return; |
| 3717 | } |
| 3718 | long ident = Binder.clearCallingIdentity(); |
| 3719 | try { |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 3720 | showCurrentInputLocked(mLastImeTargetWindow, flags, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3721 | } finally { |
| 3722 | Binder.restoreCallingIdentity(ident); |
| 3723 | } |
| 3724 | } |
| 3725 | } |
| 3726 | |
| 3727 | void setEnabledSessionInMainThread(SessionState session) { |
| 3728 | if (mEnabledSession != session) { |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3729 | if (mEnabledSession != null && mEnabledSession.session != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3730 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3731 | if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession); |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3732 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3733 | } catch (RemoteException e) { |
| 3734 | } |
| 3735 | } |
| 3736 | mEnabledSession = session; |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 3737 | if (mEnabledSession != null && mEnabledSession.session != null) { |
| 3738 | try { |
| 3739 | if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession); |
| 3740 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, true); |
| 3741 | } catch (RemoteException e) { |
| 3742 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3743 | } |
| 3744 | } |
| 3745 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3746 | |
Yohei Yukawa | 930328c | 2017-10-18 20:19:53 -0700 | [diff] [blame] | 3747 | @MainThread |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3748 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3749 | public boolean handleMessage(Message msg) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3750 | SomeArgs args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3751 | switch (msg.what) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3752 | case MSG_SHOW_IM_SUBTYPE_PICKER: |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3753 | final boolean showAuxSubtypes; |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3754 | final int displayId = msg.arg2; |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3755 | switch (msg.arg1) { |
| 3756 | case InputMethodManager.SHOW_IM_PICKER_MODE_AUTO: |
| 3757 | // This is undocumented so far, but IMM#showInputMethodPicker() has been |
| 3758 | // implemented so that auxiliary subtypes will be excluded when the soft |
| 3759 | // keyboard is invisible. |
| 3760 | showAuxSubtypes = mInputShown; |
| 3761 | break; |
| 3762 | case InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES: |
| 3763 | showAuxSubtypes = true; |
| 3764 | break; |
| 3765 | case InputMethodManager.SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES: |
| 3766 | showAuxSubtypes = false; |
| 3767 | break; |
| 3768 | default: |
| 3769 | Slog.e(TAG, "Unknown subtype picker mode = " + msg.arg1); |
| 3770 | return false; |
| 3771 | } |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3772 | showInputMethodMenu(showAuxSubtypes, displayId); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3773 | return true; |
| 3774 | |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3775 | case MSG_SHOW_IM_SUBTYPE_ENABLER: |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 3776 | showInputMethodAndSubtypeEnabler((String)msg.obj); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3777 | return true; |
| 3778 | |
| 3779 | case MSG_SHOW_IM_CONFIG: |
| 3780 | showConfigureInputMethods(); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3781 | return true; |
| 3782 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3783 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3784 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3785 | case MSG_UNBIND_INPUT: |
| 3786 | try { |
| 3787 | ((IInputMethod)msg.obj).unbindInput(); |
| 3788 | } catch (RemoteException e) { |
| 3789 | // There is nothing interesting about the method dying. |
| 3790 | } |
| 3791 | return true; |
| 3792 | case MSG_BIND_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3793 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3794 | try { |
| 3795 | ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2); |
| 3796 | } catch (RemoteException e) { |
| 3797 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3798 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3799 | return true; |
| 3800 | case MSG_SHOW_SOFT_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3801 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3802 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3803 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput(" |
Craig Mautner | 6efb4c7 | 2013-03-13 10:17:41 -0700 | [diff] [blame] | 3804 | + msg.arg1 + ", " + args.arg2 + ")"); |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 3805 | ((IInputMethod) args.arg1).showSoftInput( |
| 3806 | (IBinder) args.arg3, msg.arg1, (ResultReceiver) args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3807 | } catch (RemoteException e) { |
| 3808 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3809 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3810 | return true; |
| 3811 | case MSG_HIDE_SOFT_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3812 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3813 | try { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3814 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, " |
Craig Mautner | 6efb4c7 | 2013-03-13 10:17:41 -0700 | [diff] [blame] | 3815 | + args.arg2 + ")"); |
Craig Mautner | ca0ac71 | 2013-03-14 09:43:02 -0700 | [diff] [blame] | 3816 | ((IInputMethod)args.arg1).hideSoftInput(0, (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3817 | } catch (RemoteException e) { |
| 3818 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3819 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3820 | return true; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 3821 | case MSG_HIDE_CURRENT_INPUT_METHOD: |
| 3822 | synchronized (mMethodMap) { |
| 3823 | hideCurrentInputLocked(0, null); |
| 3824 | } |
| 3825 | return true; |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 3826 | case MSG_INITIALIZE_IME: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3827 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3828 | try { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3829 | if (DEBUG) { |
| 3830 | Slog.v(TAG, "Sending attach of token: " + args.arg2 + " for display: " |
| 3831 | + msg.arg1); |
| 3832 | } |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 3833 | final IBinder token = (IBinder) args.arg2; |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3834 | ((IInputMethod) args.arg1).initializeInternal(token, msg.arg1, |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 3835 | new InputMethodPrivilegedOperationsImpl(this, token)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3836 | } catch (RemoteException e) { |
| 3837 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3838 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3839 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3840 | case MSG_CREATE_SESSION: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3841 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3842 | IInputMethod method = (IInputMethod)args.arg1; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3843 | InputChannel channel = (InputChannel)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3844 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3845 | method.createSession(channel, (IInputSessionCallback)args.arg3); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3846 | } catch (RemoteException e) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3847 | } finally { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3848 | // Dispose the channel if the input method is not local to this process |
| 3849 | // because the remote proxy will get its own copy when unparceled. |
| 3850 | if (channel != null && Binder.isProxy(method)) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3851 | channel.dispose(); |
| 3852 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3853 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3854 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3855 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3856 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3857 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3858 | |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3859 | case MSG_START_INPUT: { |
Yohei Yukawa | f7526b5 | 2017-02-11 20:57:10 -0800 | [diff] [blame] | 3860 | final int missingMethods = msg.arg1; |
| 3861 | final boolean restarting = msg.arg2 != 0; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3862 | args = (SomeArgs) msg.obj; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 3863 | final IBinder startInputToken = (IBinder) args.arg1; |
| 3864 | final SessionState session = (SessionState) args.arg2; |
| 3865 | final IInputContext inputContext = (IInputContext) args.arg3; |
| 3866 | final EditorInfo editorInfo = (EditorInfo) args.arg4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3867 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3868 | setEnabledSessionInMainThread(session); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 3869 | session.method.startInput(startInputToken, inputContext, missingMethods, |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 3870 | editorInfo, restarting, session.client.shouldPreRenderIme); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3871 | } catch (RemoteException e) { |
| 3872 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3873 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3874 | return true; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 3875 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3876 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3877 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3878 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3879 | case MSG_UNBIND_CLIENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3880 | try { |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3881 | ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1, msg.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3882 | } catch (RemoteException e) { |
| 3883 | // There is nothing interesting about the last client dying. |
| 3884 | } |
| 3885 | return true; |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 3886 | case MSG_BIND_CLIENT: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3887 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3888 | IInputMethodClient client = (IInputMethodClient)args.arg1; |
| 3889 | InputBindResult res = (InputBindResult)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3890 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3891 | client.onBindMethod(res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3892 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3893 | Slog.w(TAG, "Client died receiving input method " + args.arg2); |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3894 | } finally { |
| 3895 | // Dispose the channel if the input method is not local to this process |
| 3896 | // because the remote proxy will get its own copy when unparceled. |
| 3897 | if (res.channel != null && Binder.isProxy(client)) { |
| 3898 | res.channel.dispose(); |
| 3899 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3900 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 3901 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3902 | return true; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 3903 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 3904 | case MSG_SET_ACTIVE: |
| 3905 | try { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3906 | ((ClientState)msg.obj).client.setActive(msg.arg1 != 0, msg.arg2 != 0); |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 3907 | } catch (RemoteException e) { |
| 3908 | Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid " |
| 3909 | + ((ClientState)msg.obj).pid + " uid " |
| 3910 | + ((ClientState)msg.obj).uid); |
| 3911 | } |
| 3912 | return true; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3913 | case MSG_SET_INTERACTIVE: |
| 3914 | handleSetInteractive(msg.arg1 != 0); |
| 3915 | return true; |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3916 | case MSG_REPORT_FULLSCREEN_MODE: { |
| 3917 | final boolean fullscreen = msg.arg1 != 0; |
| 3918 | final ClientState clientState = (ClientState)msg.obj; |
| 3919 | try { |
| 3920 | clientState.client.reportFullscreenMode(fullscreen); |
| 3921 | } catch (RemoteException e) { |
| 3922 | Slog.w(TAG, "Got RemoteException sending " |
| 3923 | + "reportFullscreen(" + fullscreen + ") notification to pid=" |
| 3924 | + clientState.pid + " uid=" + clientState.uid); |
| 3925 | } |
| 3926 | return true; |
| 3927 | } |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 3928 | case MSG_REPORT_PRE_RENDERED: { |
| 3929 | args = (SomeArgs) msg.obj; |
| 3930 | final EditorInfo info = (EditorInfo) args.arg1; |
| 3931 | final ClientState clientState = (ClientState) args.arg2; |
| 3932 | try { |
| 3933 | clientState.client.reportPreRendered(info); |
| 3934 | } catch (RemoteException e) { |
| 3935 | Slog.w(TAG, "Got RemoteException sending " |
| 3936 | + "reportPreRendered(" + info + ") notification to pid=" |
| 3937 | + clientState.pid + " uid=" + clientState.uid); |
| 3938 | } |
| 3939 | args.recycle(); |
| 3940 | return true; |
| 3941 | } |
| 3942 | case MSG_APPLY_IME_VISIBILITY: { |
| 3943 | final boolean setVisible = msg.arg1 != 0; |
| 3944 | final ClientState clientState = (ClientState) msg.obj; |
| 3945 | try { |
| 3946 | clientState.client.applyImeVisibility(setVisible); |
| 3947 | } catch (RemoteException e) { |
| 3948 | Slog.w(TAG, "Got RemoteException sending " |
| 3949 | + "applyImeVisibility(" + setVisible + ") notification to pid=" |
| 3950 | + clientState.pid + " uid=" + clientState.uid); |
| 3951 | } |
| 3952 | return true; |
| 3953 | } |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3954 | |
| 3955 | // -------------------------------------------------------------- |
| 3956 | case MSG_HARD_KEYBOARD_SWITCH_CHANGED: |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 3957 | mHardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 3958 | return true; |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 3959 | case MSG_SYSTEM_UNLOCK_USER: { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 3960 | final int userId = msg.arg1; |
| 3961 | onUnlockUser(userId); |
| 3962 | return true; |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 3963 | } |
| 3964 | case MSG_DISPATCH_ON_INPUT_METHOD_LIST_UPDATED: { |
| 3965 | final int userId = msg.arg1; |
| 3966 | final List<InputMethodInfo> imes = (List<InputMethodInfo>) msg.obj; |
| 3967 | mInputMethodListListeners.forEach( |
| 3968 | listener -> listener.onInputMethodListUpdated(imes, userId)); |
| 3969 | return true; |
| 3970 | } |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 3971 | |
| 3972 | // --------------------------------------------------------------- |
| 3973 | case MSG_INLINE_SUGGESTIONS_REQUEST: |
| 3974 | args = (SomeArgs) msg.obj; |
| 3975 | final ComponentName componentName = (ComponentName) args.arg2; |
| 3976 | final AutofillId autofillId = (AutofillId) args.arg3; |
| 3977 | final IInlineSuggestionsRequestCallback callback = |
| 3978 | (IInlineSuggestionsRequestCallback) args.arg4; |
| 3979 | try { |
| 3980 | ((IInputMethod) args.arg1).onCreateInlineSuggestionsRequest(componentName, |
| 3981 | autofillId, callback); |
| 3982 | } catch (RemoteException e) { |
| 3983 | Slog.w(TAG, "RemoteException calling onCreateInlineSuggestionsRequest(): " + e); |
| 3984 | } |
| 3985 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3986 | } |
| 3987 | return false; |
| 3988 | } |
| 3989 | |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3990 | private void handleSetInteractive(final boolean interactive) { |
| 3991 | synchronized (mMethodMap) { |
| 3992 | mIsInteractive = interactive; |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 3993 | updateSystemUiLocked(interactive ? mImeWindowVis : 0, mBackDisposition); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 3994 | |
| 3995 | // Inform the current client of the change in active status |
| 3996 | if (mCurClient != null && mCurClient.client != null) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3997 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 3998 | MSG_SET_ACTIVE, mIsInteractive ? 1 : 0, mInFullscreenMode ? 1 : 0, |
| 3999 | mCurClient)); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4000 | } |
| 4001 | } |
| 4002 | } |
| 4003 | |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 4004 | private boolean chooseNewDefaultIMELocked() { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4005 | final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME( |
| 4006 | mSettings.getEnabledInputMethodListLocked()); |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 4007 | if (imi != null) { |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 4008 | if (DEBUG) { |
| 4009 | Slog.d(TAG, "New default IME was selected: " + imi.getId()); |
| 4010 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4011 | resetSelectedInputMethodAndSubtypeLocked(imi.getId()); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 4012 | return true; |
| 4013 | } |
| 4014 | |
| 4015 | return false; |
| 4016 | } |
| 4017 | |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4018 | static void queryInputMethodServicesInternal(Context context, |
| 4019 | @UserIdInt int userId, ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap, |
| 4020 | ArrayMap<String, InputMethodInfo> methodMap, ArrayList<InputMethodInfo> methodList) { |
| 4021 | methodList.clear(); |
| 4022 | methodMap.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4023 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 4024 | // Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default |
| 4025 | // behavior of PackageManager is exactly what we want. It by default picks up appropriate |
| 4026 | // services depending on the unlock state for the specified user. |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4027 | final List<ResolveInfo> services = context.getPackageManager().queryIntentServicesAsUser( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4028 | new Intent(InputMethod.SERVICE_INTERFACE), |
Yohei Yukawa | 5ec1fce | 2018-12-17 07:56:14 -0800 | [diff] [blame] | 4029 | PackageManager.GET_META_DATA | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS, |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4030 | userId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4031 | |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4032 | methodList.ensureCapacity(services.size()); |
| 4033 | methodMap.ensureCapacity(services.size()); |
| 4034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4035 | for (int i = 0; i < services.size(); ++i) { |
| 4036 | ResolveInfo ri = services.get(i); |
| 4037 | ServiceInfo si = ri.serviceInfo; |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 4038 | final String imeId = InputMethodInfo.computeId(ri); |
| 4039 | if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) { |
| 4040 | Slog.w(TAG, "Skipping input method " + imeId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4041 | + ": it does not require the permission " |
| 4042 | + android.Manifest.permission.BIND_INPUT_METHOD); |
| 4043 | continue; |
| 4044 | } |
| 4045 | |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 4046 | if (DEBUG) Slog.d(TAG, "Checking " + imeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4047 | |
| 4048 | try { |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4049 | final InputMethodInfo imi = new InputMethodInfo(context, ri, |
| 4050 | additionalSubtypeMap.get(imeId)); |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 4051 | if (imi.isVrOnly()) { |
| 4052 | continue; // Skip VR-only IME, which isn't supported for now. |
| 4053 | } |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4054 | methodList.add(imi); |
| 4055 | methodMap.put(imi.getId(), imi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4056 | if (DEBUG) { |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4057 | Slog.d(TAG, "Found an input method " + imi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4058 | } |
Tadashi G. Takaoka | 3c23d5b | 2016-09-16 11:41:07 +0900 | [diff] [blame] | 4059 | } catch (Exception e) { |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 4060 | 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] | 4061 | } |
| 4062 | } |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | @GuardedBy("mMethodMap") |
| 4066 | void buildInputMethodListLocked(boolean resetDefaultEnabledIme) { |
| 4067 | if (DEBUG) { |
| 4068 | Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme |
| 4069 | + " \n ------ caller=" + Debug.getCallers(10)); |
| 4070 | } |
| 4071 | if (!mSystemReady) { |
| 4072 | Slog.e(TAG, "buildInputMethodListLocked is not allowed until system is ready"); |
| 4073 | return; |
| 4074 | } |
| 4075 | mMethodMapUpdateCount++; |
| 4076 | mMyPackageMonitor.clearKnownImePackageNamesLocked(); |
| 4077 | |
| 4078 | queryInputMethodServicesInternal(mContext, mSettings.getCurrentUserId(), |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 4079 | mAdditionalSubtypeMap, mMethodMap, mMethodList); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 4080 | |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 4081 | // Construct the set of possible IME packages for onPackageChanged() to avoid false |
| 4082 | // negatives when the package state remains to be the same but only the component state is |
| 4083 | // changed. |
| 4084 | { |
| 4085 | // Here we intentionally use PackageManager.MATCH_DISABLED_COMPONENTS since the purpose |
| 4086 | // of this query is to avoid false negatives. PackageManager.MATCH_ALL could be more |
| 4087 | // conservative, but it seems we cannot use it for now (Issue 35176630). |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4088 | final List<ResolveInfo> allInputMethodServices = |
| 4089 | mContext.getPackageManager().queryIntentServicesAsUser( |
| 4090 | new Intent(InputMethod.SERVICE_INTERFACE), |
| 4091 | PackageManager.MATCH_DISABLED_COMPONENTS, mSettings.getCurrentUserId()); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 4092 | final int N = allInputMethodServices.size(); |
| 4093 | for (int i = 0; i < N; ++i) { |
| 4094 | final ServiceInfo si = allInputMethodServices.get(i).serviceInfo; |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 4095 | if (android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) { |
| 4096 | mMyPackageMonitor.addKnownImePackageNameLocked(si.packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 4097 | } |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 4098 | } |
| 4099 | } |
| 4100 | |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4101 | boolean reenableMinimumNonAuxSystemImes = false; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 4102 | // TODO: The following code should find better place to live. |
| 4103 | if (!resetDefaultEnabledIme) { |
| 4104 | boolean enabledImeFound = false; |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4105 | boolean enabledNonAuxImeFound = false; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 4106 | final List<InputMethodInfo> enabledImes = mSettings.getEnabledInputMethodListLocked(); |
| 4107 | final int N = enabledImes.size(); |
| 4108 | for (int i = 0; i < N; ++i) { |
| 4109 | final InputMethodInfo imi = enabledImes.get(i); |
| 4110 | if (mMethodList.contains(imi)) { |
| 4111 | enabledImeFound = true; |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4112 | if (!imi.isAuxiliaryIme()) { |
| 4113 | enabledNonAuxImeFound = true; |
| 4114 | break; |
| 4115 | } |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 4116 | } |
| 4117 | } |
| 4118 | if (!enabledImeFound) { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 4119 | if (DEBUG) { |
| 4120 | Slog.i(TAG, "All the enabled IMEs are gone. Reset default enabled IMEs."); |
| 4121 | } |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 4122 | resetDefaultEnabledIme = true; |
| 4123 | resetSelectedInputMethodAndSubtypeLocked(""); |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4124 | } else if (!enabledNonAuxImeFound) { |
| 4125 | if (DEBUG) { |
| 4126 | Slog.i(TAG, "All the enabled non-Aux IMEs are gone. Do partial reset."); |
| 4127 | } |
| 4128 | reenableMinimumNonAuxSystemImes = true; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 4129 | } |
| 4130 | } |
| 4131 | |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4132 | if (resetDefaultEnabledIme || reenableMinimumNonAuxSystemImes) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 4133 | final ArrayList<InputMethodInfo> defaultEnabledIme = |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4134 | InputMethodUtils.getDefaultEnabledImes(mContext, mMethodList, |
| 4135 | reenableMinimumNonAuxSystemImes); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 4136 | final int N = defaultEnabledIme.size(); |
| 4137 | for (int i = 0; i < N; ++i) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 4138 | final InputMethodInfo imi = defaultEnabledIme.get(i); |
| 4139 | if (DEBUG) { |
| 4140 | Slog.d(TAG, "--- enable ime = " + imi); |
| 4141 | } |
| 4142 | setInputMethodEnabledLocked(imi.getId(), true); |
| 4143 | } |
| 4144 | } |
| 4145 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4146 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 4147 | if (!TextUtils.isEmpty(defaultImiId)) { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 4148 | if (!mMethodMap.containsKey(defaultImiId)) { |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 4149 | Slog.w(TAG, "Default IME is uninstalled. Choose new default IME."); |
| 4150 | if (chooseNewDefaultIMELocked()) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 4151 | updateInputMethodsFromSettingsLocked(true); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 4152 | } |
| 4153 | } else { |
| 4154 | // Double check that the default IME is certainly enabled. |
| 4155 | setInputMethodEnabledLocked(defaultImiId, true); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 4156 | } |
| 4157 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 4158 | // Here is not the perfect place to reset the switching controller. Ideally |
| 4159 | // mSwitchingController and mSettings should be able to share the same state. |
| 4160 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 4161 | // the same enabled IMEs list. |
Yohei Yukawa | c834a25 | 2014-05-21 22:42:32 +0900 | [diff] [blame] | 4162 | mSwitchingController.resetCircularListLocked(mContext); |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 4163 | |
| 4164 | // Notify InputMethodListListeners of the new installed InputMethods. |
| 4165 | final List<InputMethodInfo> inputMethodList = new ArrayList<>(mMethodList); |
| 4166 | mHandler.obtainMessage(MSG_DISPATCH_ON_INPUT_METHOD_LIST_UPDATED, |
| 4167 | mSettings.getCurrentUserId(), 0 /* unused */, inputMethodList).sendToTarget(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4168 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4170 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4171 | |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 4172 | private void showInputMethodAndSubtypeEnabler(String inputMethodId) { |
Tadashi G. Takaoka | f49688f | 2011-01-20 17:56:13 +0900 | [diff] [blame] | 4173 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 4174 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
satok | 86417ea | 2010-10-27 14:11:03 +0900 | [diff] [blame] | 4175 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 4176 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 4177 | if (!TextUtils.isEmpty(inputMethodId)) { |
Tadashi G. Takaoka | 2548020 | 2011-01-20 23:13:02 +0900 | [diff] [blame] | 4178 | intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 4179 | } |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 4180 | final int userId; |
| 4181 | synchronized (mMethodMap) { |
| 4182 | userId = mSettings.getCurrentUserId(); |
| 4183 | } |
| 4184 | mContext.startActivityAsUser(intent, null, UserHandle.of(userId)); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 4185 | } |
| 4186 | |
| 4187 | private void showConfigureInputMethods() { |
| 4188 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS); |
| 4189 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 4190 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 4191 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Satoshi Kataoka | 3ba439d | 2012-10-05 18:30:13 +0900 | [diff] [blame] | 4192 | mContext.startActivityAsUser(intent, null, UserHandle.CURRENT); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 4193 | } |
| 4194 | |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 4195 | private boolean isScreenLocked() { |
| 4196 | return mKeyguardManager != null |
| 4197 | && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure(); |
| 4198 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4199 | |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 4200 | private void showInputMethodMenu(boolean showAuxSubtypes, int displayId) { |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 4201 | 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] | 4202 | |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 4203 | final boolean isScreenLocked = isScreenLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4204 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4205 | final String lastInputMethodId = mSettings.getSelectedInputMethod(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4206 | int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4207 | if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4208 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 4209 | synchronized (mMethodMap) { |
Yohei Yukawa | cf3bbff | 2018-11-20 17:24:20 -0800 | [diff] [blame] | 4210 | final List<ImeSubtypeListItem> imList = |
| 4211 | mSwitchingController.getSortedInputMethodAndSubtypeListLocked( |
| 4212 | showAuxSubtypes, isScreenLocked); |
| 4213 | if (imList.isEmpty()) { |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 4214 | return; |
| 4215 | } |
| 4216 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 4217 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4218 | |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 4219 | if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4220 | final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 4221 | if (currentSubtype != null) { |
| 4222 | final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4223 | lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
| 4224 | currentImi, currentSubtype.hashCode()); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 4225 | } |
| 4226 | } |
| 4227 | |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 4228 | final int N = imList.size(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4229 | mIms = new InputMethodInfo[N]; |
| 4230 | mSubtypeIds = new int[N]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 4231 | int checkedItem = 0; |
| 4232 | for (int i = 0; i < N; ++i) { |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4233 | final ImeSubtypeListItem item = imList.get(i); |
| 4234 | mIms[i] = item.mImi; |
| 4235 | mSubtypeIds[i] = item.mSubtypeId; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 4236 | if (mIms[i].getId().equals(lastInputMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4237 | int subtypeId = mSubtypeIds[i]; |
| 4238 | if ((subtypeId == NOT_A_SUBTYPE_ID) |
| 4239 | || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) |
| 4240 | || (subtypeId == lastInputMethodSubtypeId)) { |
| 4241 | checkedItem = i; |
| 4242 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 4243 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4244 | } |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4245 | |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 4246 | final ActivityThread currentThread = ActivityThread.currentActivityThread(); |
Andrew Sapperstein | 8a3b4cb | 2017-04-28 14:35:31 -0700 | [diff] [blame] | 4247 | final Context settingsContext = new ContextThemeWrapper( |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 4248 | displayId == DEFAULT_DISPLAY ? currentThread.getSystemUiContext() |
| 4249 | : currentThread.createSystemUiContext(displayId), |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4250 | com.android.internal.R.style.Theme_DeviceDefault_Settings); |
| 4251 | |
| 4252 | mDialogBuilder = new AlertDialog.Builder(settingsContext); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4253 | mDialogBuilder.setOnCancelListener(new OnCancelListener() { |
| 4254 | @Override |
| 4255 | public void onCancel(DialogInterface dialog) { |
| 4256 | hideInputMethodMenu(); |
| 4257 | } |
| 4258 | }); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4259 | |
| 4260 | final Context dialogContext = mDialogBuilder.getContext(); |
| 4261 | final TypedArray a = dialogContext.obtainStyledAttributes(null, |
| 4262 | com.android.internal.R.styleable.DialogPreference, |
| 4263 | com.android.internal.R.attr.alertDialogStyle, 0); |
| 4264 | final Drawable dialogIcon = a.getDrawable( |
| 4265 | com.android.internal.R.styleable.DialogPreference_dialogIcon); |
| 4266 | a.recycle(); |
| 4267 | |
| 4268 | mDialogBuilder.setIcon(dialogIcon); |
| 4269 | |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 4270 | final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 4271 | final View tv = inflater.inflate( |
| 4272 | com.android.internal.R.layout.input_method_switch_dialog_title, null); |
| 4273 | mDialogBuilder.setCustomTitle(tv); |
| 4274 | |
| 4275 | // Setup layout for a toggle switch of the hardware keyboard |
| 4276 | mSwitchingDialogTitleView = tv; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4277 | mSwitchingDialogTitleView |
| 4278 | .findViewById(com.android.internal.R.id.hard_keyboard_section) |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 4279 | .setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4280 | ? View.VISIBLE : View.GONE); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4281 | final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById( |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4282 | com.android.internal.R.id.hard_keyboard_switch); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 4283 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4284 | hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
| 4285 | @Override |
| 4286 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 4287 | mSettings.setShowImeWithHardKeyboard(isChecked); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4288 | // Ensure that the input method dialog is dismissed when changing |
| 4289 | // the hardware keyboard state. |
| 4290 | hideInputMethodMenu(); |
| 4291 | } |
| 4292 | }); |
| 4293 | |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4294 | final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4295 | com.android.internal.R.layout.input_method_switch_item, imList, checkedItem); |
| 4296 | final OnClickListener choiceListener = new OnClickListener() { |
| 4297 | @Override |
| 4298 | public void onClick(final DialogInterface dialog, final int which) { |
| 4299 | synchronized (mMethodMap) { |
| 4300 | if (mIms == null || mIms.length <= which || mSubtypeIds == null |
| 4301 | || mSubtypeIds.length <= which) { |
| 4302 | return; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 4303 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4304 | final InputMethodInfo im = mIms[which]; |
| 4305 | int subtypeId = mSubtypeIds[which]; |
| 4306 | adapter.mCheckedItem = which; |
| 4307 | adapter.notifyDataSetChanged(); |
| 4308 | hideInputMethodMenu(); |
| 4309 | if (im != null) { |
| 4310 | if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) { |
| 4311 | subtypeId = NOT_A_SUBTYPE_ID; |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 4312 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4313 | setInputMethodLocked(im.getId(), subtypeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4314 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4315 | } |
| 4316 | } |
| 4317 | }; |
| 4318 | mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4320 | mSwitchingDialog = mDialogBuilder.create(); |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 4321 | mSwitchingDialog.setCanceledOnTouchOutside(true); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4322 | final Window w = mSwitchingDialog.getWindow(); |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 4323 | final LayoutParams attrs = w.getAttributes(); |
| 4324 | w.setType(LayoutParams.TYPE_INPUT_METHOD_DIALOG); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4325 | // Use an alternate token for the dialog for that window manager can group the token |
| 4326 | // with other IME windows based on type vs. grouping based on whichever token happens |
| 4327 | // to get selected by the system later on. |
| 4328 | attrs.token = mSwitchingDialogToken; |
Roshan Pius | a3f89c6 | 2019-10-11 08:50:53 -0700 | [diff] [blame] | 4329 | attrs.privateFlags |= LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4330 | attrs.setTitle("Select input method"); |
| 4331 | w.setAttributes(attrs); |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 4332 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4333 | mSwitchingDialog.show(); |
| 4334 | } |
| 4335 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4336 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4337 | private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> { |
| 4338 | private final LayoutInflater mInflater; |
| 4339 | private final int mTextViewResourceId; |
| 4340 | private final List<ImeSubtypeListItem> mItemsList; |
Satoshi Kataoka | d214296 | 2012-11-12 18:43:06 +0900 | [diff] [blame] | 4341 | public int mCheckedItem; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4342 | public ImeSubtypeListAdapter(Context context, int textViewResourceId, |
| 4343 | List<ImeSubtypeListItem> itemsList, int checkedItem) { |
| 4344 | super(context, textViewResourceId, itemsList); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4345 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4346 | mTextViewResourceId = textViewResourceId; |
| 4347 | mItemsList = itemsList; |
| 4348 | mCheckedItem = checkedItem; |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 4349 | mInflater = context.getSystemService(LayoutInflater.class); |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | @Override |
| 4353 | public View getView(int position, View convertView, ViewGroup parent) { |
| 4354 | final View view = convertView != null ? convertView |
| 4355 | : mInflater.inflate(mTextViewResourceId, null); |
| 4356 | if (position < 0 || position >= mItemsList.size()) return view; |
| 4357 | final ImeSubtypeListItem item = mItemsList.get(position); |
| 4358 | final CharSequence imeName = item.mImeName; |
| 4359 | final CharSequence subtypeName = item.mSubtypeName; |
| 4360 | final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1); |
| 4361 | final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2); |
| 4362 | if (TextUtils.isEmpty(subtypeName)) { |
| 4363 | firstTextView.setText(imeName); |
| 4364 | secondTextView.setVisibility(View.GONE); |
| 4365 | } else { |
| 4366 | firstTextView.setText(subtypeName); |
| 4367 | secondTextView.setText(imeName); |
| 4368 | secondTextView.setVisibility(View.VISIBLE); |
| 4369 | } |
| 4370 | final RadioButton radioButton = |
| 4371 | (RadioButton)view.findViewById(com.android.internal.R.id.radio); |
| 4372 | radioButton.setChecked(position == mCheckedItem); |
| 4373 | return view; |
| 4374 | } |
| 4375 | } |
| 4376 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4377 | void hideInputMethodMenu() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4378 | synchronized (mMethodMap) { |
| 4379 | hideInputMethodMenuLocked(); |
| 4380 | } |
| 4381 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4382 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4383 | void hideInputMethodMenuLocked() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4384 | if (DEBUG) Slog.v(TAG, "Hide switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4385 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4386 | if (mSwitchingDialog != null) { |
| 4387 | mSwitchingDialog.dismiss(); |
| 4388 | mSwitchingDialog = null; |
Yohei Yukawa | 1fc7a1d | 2018-04-18 17:31:27 -0700 | [diff] [blame] | 4389 | mSwitchingDialogTitleView = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4390 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4391 | |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 4392 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4393 | mDialogBuilder = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4394 | mIms = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4395 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4396 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4397 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4398 | |
Yohei Yukawa | 3d3abd2 | 2019-04-09 23:20:12 -0700 | [diff] [blame] | 4399 | /** |
| 4400 | * Enable or disable the given IME by updating {@link Settings.Secure#ENABLED_INPUT_METHODS}. |
| 4401 | * |
| 4402 | * @param id ID of the IME is to be manipulated. It is OK to pass IME ID that is currently not |
| 4403 | * recognized by the system. |
| 4404 | * @param enabled {@code true} if {@code id} needs to be enabled. |
| 4405 | * @return {@code true} if the IME was previously enabled. {@code false} otherwise. |
| 4406 | */ |
| 4407 | private boolean setInputMethodEnabledLocked(String id, boolean enabled) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4408 | List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings |
| 4409 | .getEnabledInputMethodsAndSubtypeListLocked(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4410 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4411 | if (enabled) { |
| 4412 | for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) { |
| 4413 | if (pair.first.equals(id)) { |
| 4414 | // We are enabling this input method, but it is already enabled. |
| 4415 | // Nothing to do. The previous state was enabled. |
| 4416 | return true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4417 | } |
| 4418 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4419 | mSettings.appendAndPutEnabledInputMethodLocked(id, false); |
| 4420 | // Previous state was disabled. |
| 4421 | return false; |
| 4422 | } else { |
| 4423 | StringBuilder builder = new StringBuilder(); |
| 4424 | if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 4425 | builder, enabledInputMethodsList, id)) { |
| 4426 | // Disabled input method is currently selected, switch to another one. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4427 | final String selId = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 4428 | if (id.equals(selId) && !chooseNewDefaultIMELocked()) { |
| 4429 | Slog.i(TAG, "Can't find new IME, unsetting the current input method."); |
| 4430 | resetSelectedInputMethodAndSubtypeLocked(""); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4431 | } |
| 4432 | // Previous state was enabled. |
| 4433 | return true; |
| 4434 | } else { |
| 4435 | // We are disabling the input method but it is already disabled. |
| 4436 | // Nothing to do. The previous state was disabled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4437 | return false; |
| 4438 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4439 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4440 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 4441 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4442 | private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId, |
| 4443 | boolean setSubtypeOnly) { |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 4444 | mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype); |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 4445 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4446 | // Set Subtype here |
| 4447 | if (imi == null || subtypeId < 0) { |
| 4448 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
Tadashi G. Takaoka | 0ba75bb | 2010-11-09 12:19:32 -0800 | [diff] [blame] | 4449 | mCurrentSubtype = null; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4450 | } else { |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 4451 | if (subtypeId < imi.getSubtypeCount()) { |
| 4452 | InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId); |
| 4453 | mSettings.putSelectedSubtype(subtype.hashCode()); |
| 4454 | mCurrentSubtype = subtype; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4455 | } else { |
| 4456 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 4457 | // If the subtype is not specified, choose the most applicable one |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4458 | mCurrentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4459 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4460 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4461 | |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 4462 | if (!setSubtypeOnly) { |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4463 | // Set InputMethod here |
| 4464 | mSettings.putSelectedInputMethod(imi != null ? imi.getId() : ""); |
| 4465 | } |
| 4466 | } |
| 4467 | |
| 4468 | private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) { |
| 4469 | InputMethodInfo imi = mMethodMap.get(newDefaultIme); |
| 4470 | int lastSubtypeId = NOT_A_SUBTYPE_ID; |
| 4471 | // newDefaultIme is empty when there is no candidate for the selected IME. |
| 4472 | if (imi != null && !TextUtils.isEmpty(newDefaultIme)) { |
| 4473 | String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme); |
| 4474 | if (subtypeHashCode != null) { |
| 4475 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4476 | lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 4477 | imi, Integer.parseInt(subtypeHashCode)); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4478 | } catch (NumberFormatException e) { |
| 4479 | Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e); |
| 4480 | } |
| 4481 | } |
| 4482 | } |
| 4483 | setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4484 | } |
| 4485 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4486 | /** |
| 4487 | * @return Return the current subtype of this input method. |
| 4488 | */ |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 4489 | @Override |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4490 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4491 | synchronized (mMethodMap) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 4492 | // TODO: Make this work even for non-current users? |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 4493 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 4494 | return null; |
| 4495 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4496 | return getCurrentInputMethodSubtypeLocked(); |
| 4497 | } |
| 4498 | } |
| 4499 | |
| 4500 | private InputMethodSubtype getCurrentInputMethodSubtypeLocked() { |
satok | fdf419e | 2012-05-08 16:52:08 +0900 | [diff] [blame] | 4501 | if (mCurMethodId == null) { |
| 4502 | return null; |
| 4503 | } |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4504 | final boolean subtypeIsSelected = mSettings.isSubtypeSelected(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4505 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 4506 | if (imi == null || imi.getSubtypeCount() == 0) { |
| 4507 | return null; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4508 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4509 | if (!subtypeIsSelected || mCurrentSubtype == null |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4510 | || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) { |
| 4511 | int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4512 | if (subtypeId == NOT_A_SUBTYPE_ID) { |
| 4513 | // If there are no selected subtypes, the framework will try to find |
| 4514 | // the most applicable subtype from explicitly or implicitly enabled |
| 4515 | // subtypes. |
| 4516 | List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4517 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4518 | // If there is only one explicitly or implicitly enabled subtype, |
| 4519 | // just returns it. |
| 4520 | if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) { |
| 4521 | mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0); |
| 4522 | } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4523 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4524 | mRes, explicitlyOrImplicitlyEnabledSubtypes, |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4525 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4526 | if (mCurrentSubtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4527 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4528 | mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, |
| 4529 | true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4530 | } |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 4531 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4532 | } else { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4533 | mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId); |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 4534 | } |
| 4535 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4536 | return mCurrentSubtype; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4537 | } |
| 4538 | |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 4539 | private List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId) { |
| 4540 | synchronized (mMethodMap) { |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 4541 | return getInputMethodListLocked(userId); |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 4542 | } |
| 4543 | } |
| 4544 | |
| 4545 | private List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId) { |
| 4546 | synchronized (mMethodMap) { |
| 4547 | return getEnabledInputMethodListLocked(userId); |
| 4548 | } |
| 4549 | } |
| 4550 | |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 4551 | private void onCreateInlineSuggestionsRequest(@UserIdInt int userId, |
| 4552 | ComponentName componentName, AutofillId autofillId, |
| 4553 | IInlineSuggestionsRequestCallback callback) { |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4554 | synchronized (mMethodMap) { |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 4555 | onCreateInlineSuggestionsRequestLocked(userId, componentName, autofillId, callback); |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4556 | } |
| 4557 | } |
| 4558 | |
mincheli | 850892b | 2019-12-05 19:47:59 +0800 | [diff] [blame] | 4559 | private boolean switchToInputMethod(String imeId, @UserIdInt int userId) { |
| 4560 | synchronized (mMethodMap) { |
| 4561 | if (userId == mSettings.getCurrentUserId()) { |
| 4562 | if (!mMethodMap.containsKey(imeId) |
| 4563 | || !mSettings.getEnabledInputMethodListLocked() |
| 4564 | .contains(mMethodMap.get(imeId))) { |
| 4565 | return false; // IME is not is found or not enabled. |
| 4566 | } |
| 4567 | setInputMethodLocked(imeId, NOT_A_SUBTYPE_ID); |
| 4568 | return true; |
| 4569 | } |
| 4570 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 4571 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 4572 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 4573 | new ArrayMap<>(); |
| 4574 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 4575 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, |
| 4576 | methodMap, methodList); |
| 4577 | final InputMethodSettings settings = new InputMethodSettings( |
| 4578 | mContext.getResources(), mContext.getContentResolver(), methodMap, |
| 4579 | userId, false); |
| 4580 | if (!methodMap.containsKey(imeId) |
| 4581 | || !settings.getEnabledInputMethodListLocked() |
| 4582 | .contains(methodMap.get(imeId))) { |
| 4583 | return false; // IME is not is found or not enabled. |
| 4584 | } |
| 4585 | settings.putSelectedInputMethod(imeId); |
| 4586 | settings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
| 4587 | return true; |
| 4588 | } |
| 4589 | } |
| 4590 | |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 4591 | private static final class LocalServiceImpl extends InputMethodManagerInternal { |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4592 | @NonNull |
Yohei Yukawa | fffc0e5 | 2018-09-04 13:24:00 -0700 | [diff] [blame] | 4593 | private final InputMethodManagerService mService; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4594 | |
Yohei Yukawa | fffc0e5 | 2018-09-04 13:24:00 -0700 | [diff] [blame] | 4595 | LocalServiceImpl(@NonNull InputMethodManagerService service) { |
| 4596 | mService = service; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | @Override |
| 4600 | public void setInteractive(boolean interactive) { |
| 4601 | // Do everything in handler so as not to block the caller. |
Yohei Yukawa | f16abb7 | 2018-09-05 11:28:42 -0700 | [diff] [blame] | 4602 | mService.mHandler.obtainMessage(MSG_SET_INTERACTIVE, interactive ? 1 : 0, 0) |
| 4603 | .sendToTarget(); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4604 | } |
Yohei Yukawa | ae61f71 | 2015-12-09 13:00:10 -0800 | [diff] [blame] | 4605 | |
| 4606 | @Override |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 4607 | public void hideCurrentInputMethod() { |
Yohei Yukawa | f16abb7 | 2018-09-05 11:28:42 -0700 | [diff] [blame] | 4608 | mService.mHandler.removeMessages(MSG_HIDE_CURRENT_INPUT_METHOD); |
| 4609 | mService.mHandler.sendEmptyMessage(MSG_HIDE_CURRENT_INPUT_METHOD); |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 4610 | } |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 4611 | |
| 4612 | @Override |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 4613 | public List<InputMethodInfo> getInputMethodListAsUser(int userId) { |
| 4614 | return mService.getInputMethodListAsUser(userId); |
| 4615 | } |
| 4616 | |
| 4617 | @Override |
| 4618 | public List<InputMethodInfo> getEnabledInputMethodListAsUser(int userId) { |
| 4619 | return mService.getEnabledInputMethodListAsUser(userId); |
| 4620 | } |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4621 | |
| 4622 | @Override |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 4623 | public void onCreateInlineSuggestionsRequest(int userId, ComponentName componentName, |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4624 | AutofillId autofillId, IInlineSuggestionsRequestCallback cb) { |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 4625 | mService.onCreateInlineSuggestionsRequest(userId, componentName, autofillId, cb); |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4626 | } |
mincheli | 850892b | 2019-12-05 19:47:59 +0800 | [diff] [blame] | 4627 | |
| 4628 | @Override |
| 4629 | public boolean switchToInputMethod(String imeId, int userId) { |
| 4630 | return mService.switchToInputMethod(imeId, userId); |
| 4631 | } |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 4632 | |
| 4633 | @Override |
| 4634 | public void registerInputMethodListListener(InputMethodListListener listener) { |
| 4635 | mService.mInputMethodListListeners.addIfAbsent(listener); |
| 4636 | } |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4637 | } |
| 4638 | |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4639 | @BinderThread |
| 4640 | private IInputContentUriToken createInputContentUriToken(@Nullable IBinder token, |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4641 | @Nullable Uri contentUri, @Nullable String packageName) { |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4642 | if (token == null) { |
| 4643 | throw new NullPointerException("token"); |
| 4644 | } |
| 4645 | if (packageName == null) { |
| 4646 | throw new NullPointerException("packageName"); |
| 4647 | } |
| 4648 | if (contentUri == null) { |
| 4649 | throw new NullPointerException("contentUri"); |
| 4650 | } |
| 4651 | final String contentUriScheme = contentUri.getScheme(); |
| 4652 | if (!"content".equals(contentUriScheme)) { |
| 4653 | throw new InvalidParameterException("contentUri must have content scheme"); |
| 4654 | } |
| 4655 | |
| 4656 | synchronized (mMethodMap) { |
| 4657 | final int uid = Binder.getCallingUid(); |
| 4658 | if (mCurMethodId == null) { |
| 4659 | return null; |
| 4660 | } |
| 4661 | if (mCurToken != token) { |
| 4662 | Slog.e(TAG, "Ignoring createInputContentUriToken mCurToken=" + mCurToken |
| 4663 | + " token=" + token); |
| 4664 | return null; |
| 4665 | } |
| 4666 | // We cannot simply distinguish a bad IME that reports an arbitrary package name from |
| 4667 | // an unfortunate IME whose internal state is already obsolete due to the asynchronous |
| 4668 | // nature of our system. Let's compare it with our internal record. |
| 4669 | if (!TextUtils.equals(mCurAttribute.packageName, packageName)) { |
| 4670 | Slog.e(TAG, "Ignoring createInputContentUriToken mCurAttribute.packageName=" |
| 4671 | + mCurAttribute.packageName + " packageName=" + packageName); |
| 4672 | return null; |
| 4673 | } |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4674 | // This user ID can never bee spoofed. |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4675 | final int imeUserId = UserHandle.getUserId(uid); |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4676 | // This user ID can never bee spoofed. |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4677 | final int appUserId = UserHandle.getUserId(mCurClient.uid); |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4678 | // This user ID may be invalid if "contentUri" embedded an invalid user ID. |
| 4679 | final int contentUriOwnerUserId = ContentProvider.getUserIdFromUri(contentUri, |
| 4680 | imeUserId); |
| 4681 | final Uri contentUriWithoutUserId = ContentProvider.getUriWithoutUserId(contentUri); |
| 4682 | // Note: InputContentUriTokenHandler.take() checks whether the IME (specified by "uid") |
| 4683 | // actually has the right to grant a read permission for "contentUriWithoutUserId" that |
| 4684 | // is claimed to belong to "contentUriOwnerUserId". For example, specifying random |
| 4685 | // content URI and/or contentUriOwnerUserId just results in a SecurityException thrown |
| 4686 | // from InputContentUriTokenHandler.take() and can never be allowed beyond what is |
| 4687 | // actually allowed to "uid", which is guaranteed to be the IME's one. |
| 4688 | return new InputContentUriTokenHandler(contentUriWithoutUserId, uid, |
| 4689 | packageName, contentUriOwnerUserId, appUserId); |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4690 | } |
| 4691 | } |
| 4692 | |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4693 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 4694 | private void reportFullscreenMode(@NonNull IBinder token, boolean fullscreen) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4695 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 4696 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4697 | return; |
| 4698 | } |
| 4699 | if (mCurClient != null && mCurClient.client != null) { |
| 4700 | mInFullscreenMode = fullscreen; |
| 4701 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 4702 | MSG_REPORT_FULLSCREEN_MODE, fullscreen ? 1 : 0, mCurClient)); |
| 4703 | } |
| 4704 | } |
| 4705 | } |
| 4706 | |
| 4707 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4708 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 4709 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4710 | |
| 4711 | IInputMethod method; |
| 4712 | ClientState client; |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4713 | ClientState focusedWindowClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4715 | final Printer p = new PrintWriterPrinter(pw); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4716 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4717 | synchronized (mMethodMap) { |
| 4718 | p.println("Current Input Method Manager state:"); |
| 4719 | int N = mMethodList.size(); |
Yohei Yukawa | 5ec1fce | 2018-12-17 07:56:14 -0800 | [diff] [blame] | 4720 | p.println(" Input Methods: mMethodMapUpdateCount=" + mMethodMapUpdateCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4721 | for (int i=0; i<N; i++) { |
| 4722 | InputMethodInfo info = mMethodList.get(i); |
| 4723 | p.println(" InputMethod #" + i + ":"); |
| 4724 | info.dump(p, " "); |
| 4725 | } |
| 4726 | p.println(" Clients:"); |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 4727 | final int numClients = mClients.size(); |
| 4728 | for (int i = 0; i < numClients; ++i) { |
| 4729 | final ClientState ci = mClients.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4730 | p.println(" Client " + ci + ":"); |
| 4731 | p.println(" client=" + ci.client); |
| 4732 | p.println(" inputContext=" + ci.inputContext); |
| 4733 | p.println(" sessionRequested=" + ci.sessionRequested); |
| 4734 | p.println(" curSession=" + ci.curSession); |
| 4735 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4736 | p.println(" mCurMethodId=" + mCurMethodId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4737 | client = mCurClient; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 4738 | p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq); |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 4739 | p.println(" mCurFocusedWindow=" + mCurFocusedWindow |
| 4740 | + " softInputMode=" + |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 4741 | InputMethodDebug.softInputModeToString(mCurFocusedWindowSoftInputMode) |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 4742 | + " client=" + mCurFocusedWindowClient); |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4743 | focusedWindowClient = mCurFocusedWindowClient; |
Yohei Yukawa | d3ef842 | 2018-06-07 16:28:07 -0700 | [diff] [blame] | 4744 | p.println(" mCurId=" + mCurId + " mHaveConnection=" + mHaveConnection |
| 4745 | + " mBoundToMethod=" + mBoundToMethod + " mVisibleBound=" + mVisibleBound); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4746 | p.println(" mCurToken=" + mCurToken); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 4747 | p.println(" mCurTokenDisplayId=" + mCurTokenDisplayId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4748 | p.println(" mCurIntent=" + mCurIntent); |
| 4749 | method = mCurMethod; |
| 4750 | p.println(" mCurMethod=" + mCurMethod); |
| 4751 | p.println(" mEnabledSession=" + mEnabledSession); |
| 4752 | p.println(" mShowRequested=" + mShowRequested |
| 4753 | + " mShowExplicitlyRequested=" + mShowExplicitlyRequested |
| 4754 | + " mShowForced=" + mShowForced |
| 4755 | + " mInputShown=" + mInputShown); |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4756 | p.println(" mInFullscreenMode=" + mInFullscreenMode); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4757 | p.println(" mSystemReady=" + mSystemReady + " mInteractive=" + mIsInteractive); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 4758 | p.println(" mSettingsObserver=" + mSettingsObserver); |
Yohei Yukawa | d724886 | 2015-06-03 23:56:12 -0700 | [diff] [blame] | 4759 | p.println(" mSwitchingController:"); |
| 4760 | mSwitchingController.dump(p); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 4761 | p.println(" mSettings:"); |
| 4762 | mSettings.dumpLocked(p, " "); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 4763 | |
| 4764 | p.println(" mStartInputHistory:"); |
| 4765 | mStartInputHistory.dump(pw, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4766 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4767 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4768 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4769 | if (client != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4770 | pw.flush(); |
| 4771 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4772 | TransferPipe.dumpAsync(client.client.asBinder(), fd, args); |
| 4773 | } catch (IOException | RemoteException e) { |
| 4774 | p.println("Failed to dump input method client: " + e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4775 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4776 | } else { |
| 4777 | p.println("No input method client."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4778 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4779 | |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4780 | if (focusedWindowClient != null && client != focusedWindowClient) { |
| 4781 | p.println(" "); |
| 4782 | p.println("Warning: Current input method client doesn't match the last focused. " |
| 4783 | + "window."); |
| 4784 | p.println("Dumping input method client in the last focused window just in case."); |
| 4785 | p.println(" "); |
| 4786 | pw.flush(); |
| 4787 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4788 | TransferPipe.dumpAsync(focusedWindowClient.client.asBinder(), fd, args); |
| 4789 | } catch (IOException | RemoteException e) { |
| 4790 | p.println("Failed to dump input method client in focused window: " + e); |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 4791 | } |
| 4792 | } |
| 4793 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4794 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4795 | if (method != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4796 | pw.flush(); |
| 4797 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 4798 | TransferPipe.dumpAsync(method.asBinder(), fd, args); |
| 4799 | } catch (IOException | RemoteException e) { |
| 4800 | p.println("Failed to dump input method service: " + e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4801 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 4802 | } else { |
| 4803 | p.println("No input method service."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4804 | } |
| 4805 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4806 | |
| 4807 | @BinderThread |
| 4808 | @Override |
| 4809 | public void onShellCommand(@Nullable FileDescriptor in, @Nullable FileDescriptor out, |
| 4810 | @Nullable FileDescriptor err, |
| 4811 | @NonNull String[] args, @Nullable ShellCallback callback, |
| 4812 | @NonNull ResultReceiver resultReceiver) throws RemoteException { |
Yohei Yukawa | b8d240f | 2018-12-26 10:03:11 -0800 | [diff] [blame] | 4813 | final int callingUid = Binder.getCallingUid(); |
| 4814 | // Reject any incoming calls from non-shell users, including ones from the system user. |
| 4815 | if (callingUid != Process.ROOT_UID && callingUid != Process.SHELL_UID) { |
| 4816 | // Note that Binder#onTransact() will automatically close "in", "out", and "err" when |
| 4817 | // returned from this method, hence there is no need to close those FDs. |
| 4818 | // "resultReceiver" is the only thing that needs to be taken care of here. |
| 4819 | if (resultReceiver != null) { |
| 4820 | resultReceiver.send(ShellCommandResult.FAILURE, null); |
| 4821 | } |
| 4822 | final String errorMsg = "InputMethodManagerService does not support shell commands from" |
| 4823 | + " non-shell users. callingUid=" + callingUid |
| 4824 | + " args=" + Arrays.toString(args); |
| 4825 | if (Process.isCoreUid(callingUid)) { |
| 4826 | // Let's not crash the calling process if the caller is one of core components. |
| 4827 | Slog.e(TAG, errorMsg); |
| 4828 | return; |
| 4829 | } |
| 4830 | throw new SecurityException(errorMsg); |
| 4831 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4832 | new ShellCommandImpl(this).exec( |
| 4833 | this, in, out, err, args, callback, resultReceiver); |
| 4834 | } |
| 4835 | |
| 4836 | private static final class ShellCommandImpl extends ShellCommand { |
| 4837 | @NonNull |
| 4838 | final InputMethodManagerService mService; |
| 4839 | |
| 4840 | ShellCommandImpl(InputMethodManagerService service) { |
| 4841 | mService = service; |
| 4842 | } |
| 4843 | |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 4844 | @RequiresPermission(allOf = { |
Yohei Yukawa | 8a2b96b | 2018-12-28 17:23:29 -0800 | [diff] [blame] | 4845 | Manifest.permission.DUMP, |
| 4846 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 4847 | Manifest.permission.WRITE_SECURE_SETTINGS, |
Yohei Yukawa | 8a2b96b | 2018-12-28 17:23:29 -0800 | [diff] [blame] | 4848 | }) |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4849 | @BinderThread |
| 4850 | @ShellCommandResult |
| 4851 | @Override |
| 4852 | public int onCommand(@Nullable String cmd) { |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 4853 | // 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] | 4854 | Arrays.asList( |
| 4855 | Manifest.permission.DUMP, |
| 4856 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 4857 | Manifest.permission.WRITE_SECURE_SETTINGS |
| 4858 | ).forEach(permission -> mService.mContext.enforceCallingPermission(permission, null)); |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 4859 | |
| 4860 | final long identity = Binder.clearCallingIdentity(); |
| 4861 | try { |
| 4862 | return onCommandWithSystemIdentity(cmd); |
| 4863 | } finally { |
| 4864 | Binder.restoreCallingIdentity(identity); |
| 4865 | } |
| 4866 | } |
| 4867 | |
| 4868 | @BinderThread |
| 4869 | @ShellCommandResult |
| 4870 | private int onCommandWithSystemIdentity(@Nullable String cmd) { |
Yohei Yukawa | dfdab73 | 2018-02-21 07:16:30 +0900 | [diff] [blame] | 4871 | if ("refresh_debug_properties".equals(cmd)) { |
| 4872 | return refreshDebugProperties(); |
| 4873 | } |
| 4874 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 4875 | if ("get-last-switch-user-id".equals(cmd)) { |
| 4876 | return mService.getLastSwitchUserId(this); |
| 4877 | } |
| 4878 | |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4879 | // For existing "adb shell ime <command>". |
| 4880 | if ("ime".equals(cmd)) { |
| 4881 | final String imeCommand = getNextArg(); |
| 4882 | if (imeCommand == null || "help".equals(imeCommand) || "-h".equals(imeCommand)) { |
| 4883 | onImeCommandHelp(); |
| 4884 | return ShellCommandResult.SUCCESS; |
| 4885 | } |
| 4886 | switch (imeCommand) { |
| 4887 | case "list": |
| 4888 | return mService.handleShellCommandListInputMethods(this); |
| 4889 | case "enable": |
| 4890 | return mService.handleShellCommandEnableDisableInputMethod(this, true); |
| 4891 | case "disable": |
| 4892 | return mService.handleShellCommandEnableDisableInputMethod(this, false); |
| 4893 | case "set": |
| 4894 | return mService.handleShellCommandSetInputMethod(this); |
| 4895 | case "reset": |
| 4896 | return mService.handleShellCommandResetInputMethod(this); |
| 4897 | default: |
| 4898 | getOutPrintWriter().println("Unknown command: " + imeCommand); |
| 4899 | return ShellCommandResult.FAILURE; |
| 4900 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4901 | } |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4902 | |
| 4903 | return handleDefaultCommands(cmd); |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4904 | } |
| 4905 | |
| 4906 | @BinderThread |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 4907 | @ShellCommandResult |
| 4908 | private int refreshDebugProperties() { |
| 4909 | DebugFlags.FLAG_OPTIMIZE_START_INPUT.refresh(); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 4910 | DebugFlags.FLAG_PRE_RENDER_IME_VIEWS.refresh(); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 4911 | return ShellCommandResult.SUCCESS; |
| 4912 | } |
| 4913 | |
| 4914 | @BinderThread |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4915 | @Override |
| 4916 | public void onHelp() { |
| 4917 | try (PrintWriter pw = getOutPrintWriter()) { |
| 4918 | pw.println("InputMethodManagerService commands:"); |
| 4919 | pw.println(" help"); |
| 4920 | pw.println(" Prints this help text."); |
| 4921 | pw.println(" dump [options]"); |
| 4922 | pw.println(" Synonym of dumpsys."); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4923 | pw.println(" ime <command> [options]"); |
| 4924 | pw.println(" Manipulate IMEs. Run \"ime help\" for details."); |
| 4925 | } |
| 4926 | } |
| 4927 | |
| 4928 | private void onImeCommandHelp() { |
| 4929 | try (IndentingPrintWriter pw = |
| 4930 | new IndentingPrintWriter(getOutPrintWriter(), " ", 100)) { |
| 4931 | pw.println("ime <command>:"); |
| 4932 | pw.increaseIndent(); |
| 4933 | |
| 4934 | pw.println("list [-a] [-s]"); |
| 4935 | pw.increaseIndent(); |
| 4936 | pw.println("prints all enabled input methods."); |
| 4937 | pw.increaseIndent(); |
| 4938 | pw.println("-a: see all input methods"); |
| 4939 | pw.println("-s: only a single summary line of each"); |
| 4940 | pw.decreaseIndent(); |
| 4941 | pw.decreaseIndent(); |
| 4942 | |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 4943 | pw.println("enable [--user <USER_ID>] <ID>"); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4944 | pw.increaseIndent(); |
| 4945 | pw.println("allows the given input method ID to be used."); |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 4946 | pw.increaseIndent(); |
| 4947 | pw.print("--user <USER_ID>: Specify which user to enable."); |
| 4948 | pw.println(" Assumes the current user if not specified."); |
| 4949 | pw.decreaseIndent(); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4950 | pw.decreaseIndent(); |
| 4951 | |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 4952 | pw.println("disable [--user <USER_ID>] <ID>"); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4953 | pw.increaseIndent(); |
| 4954 | pw.println("disallows the given input method ID to be used."); |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 4955 | pw.increaseIndent(); |
| 4956 | pw.print("--user <USER_ID>: Specify which user to disable."); |
| 4957 | pw.println(" Assumes the current user if not specified."); |
| 4958 | pw.decreaseIndent(); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4959 | pw.decreaseIndent(); |
| 4960 | |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 4961 | pw.println("set [--user <USER_ID>] <ID>"); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4962 | pw.increaseIndent(); |
| 4963 | pw.println("switches to the given input method ID."); |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 4964 | pw.increaseIndent(); |
| 4965 | pw.print("--user <USER_ID>: Specify which user to enable."); |
| 4966 | pw.println(" Assumes the current user if not specified."); |
| 4967 | pw.decreaseIndent(); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4968 | pw.decreaseIndent(); |
| 4969 | |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 4970 | pw.println("reset [--user <USER_ID>]"); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4971 | pw.increaseIndent(); |
| 4972 | pw.println("reset currently selected/enabled IMEs to the default ones as if " |
| 4973 | + "the device is initially booted with the current locale."); |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 4974 | pw.increaseIndent(); |
| 4975 | pw.print("--user <USER_ID>: Specify which user to reset."); |
| 4976 | pw.println(" Assumes the current user if not specified."); |
| 4977 | pw.decreaseIndent(); |
| 4978 | |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 4979 | pw.decreaseIndent(); |
| 4980 | |
| 4981 | pw.decreaseIndent(); |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4982 | } |
| 4983 | } |
| 4984 | } |
| 4985 | |
| 4986 | // ---------------------------------------------------------------------- |
| 4987 | // Shell command handlers: |
| 4988 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 4989 | @BinderThread |
| 4990 | @ShellCommandResult |
| 4991 | private int getLastSwitchUserId(@NonNull ShellCommand shellCommand) { |
| 4992 | synchronized (mMethodMap) { |
| 4993 | shellCommand.getOutPrintWriter().println(mLastSwitchUserId); |
| 4994 | return ShellCommandResult.SUCCESS; |
| 4995 | } |
| 4996 | } |
| 4997 | |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 4998 | /** |
| 4999 | * Handles {@code adb shell ime list}. |
| 5000 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 5001 | * @return Exit code of the command. |
| 5002 | */ |
| 5003 | @BinderThread |
| 5004 | @ShellCommandResult |
| 5005 | private int handleShellCommandListInputMethods(@NonNull ShellCommand shellCommand) { |
| 5006 | boolean all = false; |
| 5007 | boolean brief = false; |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 5008 | int userIdToBeResolved = UserHandle.USER_CURRENT; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5009 | while (true) { |
| 5010 | final String nextOption = shellCommand.getNextOption(); |
| 5011 | if (nextOption == null) { |
| 5012 | break; |
| 5013 | } |
| 5014 | switch (nextOption) { |
| 5015 | case "-a": |
| 5016 | all = true; |
| 5017 | break; |
| 5018 | case "-s": |
| 5019 | brief = true; |
| 5020 | break; |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 5021 | case "-u": |
| 5022 | case "--user": |
| 5023 | userIdToBeResolved = UserHandle.parseUserArg(shellCommand.getNextArgRequired()); |
| 5024 | break; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5025 | } |
| 5026 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 5027 | synchronized (mMethodMap) { |
| 5028 | final PrintWriter pr = shellCommand.getOutPrintWriter(); |
| 5029 | final int[] userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, |
| 5030 | mSettings.getCurrentUserId(), shellCommand.getErrPrintWriter()); |
| 5031 | for (int userId : userIds) { |
| 5032 | final List<InputMethodInfo> methods = all |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 5033 | ? getInputMethodListLocked(userId) |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 5034 | : getEnabledInputMethodListLocked(userId); |
| 5035 | if (userIds.length > 1) { |
| 5036 | pr.print("User #"); |
| 5037 | pr.print(userId); |
| 5038 | pr.println(":"); |
| 5039 | } |
| 5040 | for (InputMethodInfo info : methods) { |
| 5041 | if (brief) { |
| 5042 | pr.println(info.getId()); |
| 5043 | } else { |
| 5044 | pr.print(info.getId()); |
| 5045 | pr.println(":"); |
| 5046 | info.dump(pr::println, " "); |
| 5047 | } |
| 5048 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5049 | } |
| 5050 | } |
| 5051 | return ShellCommandResult.SUCCESS; |
| 5052 | } |
| 5053 | |
| 5054 | /** |
| 5055 | * Handles {@code adb shell ime enable} and {@code adb shell ime disable}. |
| 5056 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 5057 | * @param enabled {@code true} if the command was {@code adb shell ime enable}. |
| 5058 | * @return Exit code of the command. |
| 5059 | */ |
| 5060 | @BinderThread |
| 5061 | @ShellCommandResult |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5062 | private int handleShellCommandEnableDisableInputMethod( |
| 5063 | @NonNull ShellCommand shellCommand, boolean enabled) { |
Yohei Yukawa | 3403f2d | 2019-04-15 08:16:58 -0700 | [diff] [blame] | 5064 | final int userIdToBeResolved = handleOptionsForCommandsThatOnlyHaveUserOption(shellCommand); |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5065 | final String imeId = shellCommand.getNextArgRequired(); |
| 5066 | final PrintWriter out = shellCommand.getOutPrintWriter(); |
| 5067 | final PrintWriter error = shellCommand.getErrPrintWriter(); |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5068 | synchronized (mMethodMap) { |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5069 | final int[] userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, |
| 5070 | mSettings.getCurrentUserId(), shellCommand.getErrPrintWriter()); |
| 5071 | for (int userId : userIds) { |
| 5072 | if (!userHasDebugPriv(userId, shellCommand)) { |
| 5073 | continue; |
| 5074 | } |
| 5075 | handleShellCommandEnableDisableInputMethodInternalLocked(userId, imeId, enabled, |
| 5076 | out, error); |
Tarandeep Singh | 87e2e51 | 2019-03-06 14:28:52 -0800 | [diff] [blame] | 5077 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5078 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5079 | return ShellCommandResult.SUCCESS; |
| 5080 | } |
| 5081 | |
| 5082 | /** |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5083 | * A special helper method for commands that only have {@code -u} and {@code --user} options. |
| 5084 | * |
| 5085 | * <p>You cannot use this helper method if the command has other options.</p> |
| 5086 | * |
Yohei Yukawa | 3403f2d | 2019-04-15 08:16:58 -0700 | [diff] [blame] | 5087 | * <p>CAVEAT: This method must be called only once before any other |
| 5088 | * {@link ShellCommand#getNextArg()} and {@link ShellCommand#getNextArgRequired()} for the |
| 5089 | * main arguments.</p> |
| 5090 | * |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5091 | * @param shellCommand {@link ShellCommand} from which options should be obtained. |
| 5092 | * @return User ID to be resolved. {@link UserHandle#CURRENT} if not specified. |
| 5093 | */ |
| 5094 | @BinderThread |
| 5095 | @UserIdInt |
| 5096 | private static int handleOptionsForCommandsThatOnlyHaveUserOption(ShellCommand shellCommand) { |
| 5097 | while (true) { |
| 5098 | final String nextOption = shellCommand.getNextOption(); |
| 5099 | if (nextOption == null) { |
| 5100 | break; |
| 5101 | } |
| 5102 | switch (nextOption) { |
| 5103 | case "-u": |
| 5104 | case "--user": |
| 5105 | return UserHandle.parseUserArg(shellCommand.getNextArgRequired()); |
| 5106 | } |
| 5107 | } |
| 5108 | return UserHandle.USER_CURRENT; |
| 5109 | } |
| 5110 | |
| 5111 | @BinderThread |
| 5112 | private void handleShellCommandEnableDisableInputMethodInternalLocked( |
| 5113 | @UserIdInt int userId, String imeId, boolean enabled, PrintWriter out, |
| 5114 | PrintWriter error) { |
| 5115 | boolean failedToEnableUnknownIme = false; |
| 5116 | boolean previouslyEnabled = false; |
| 5117 | if (userId == mSettings.getCurrentUserId()) { |
| 5118 | if (enabled && !mMethodMap.containsKey(imeId)) { |
| 5119 | failedToEnableUnknownIme = true; |
| 5120 | } else { |
| 5121 | previouslyEnabled = setInputMethodEnabledLocked(imeId, enabled); |
| 5122 | } |
| 5123 | } else { |
| 5124 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 5125 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 5126 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 5127 | new ArrayMap<>(); |
| 5128 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 5129 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, |
| 5130 | methodMap, methodList); |
| 5131 | final InputMethodSettings settings = new InputMethodSettings(mContext.getResources(), |
| 5132 | mContext.getContentResolver(), methodMap, userId, false); |
| 5133 | if (enabled) { |
| 5134 | if (!methodMap.containsKey(imeId)) { |
| 5135 | failedToEnableUnknownIme = true; |
| 5136 | } else { |
| 5137 | for (InputMethodInfo imi : settings.getEnabledInputMethodListLocked()) { |
| 5138 | if (TextUtils.equals(imi.getId(), imeId)) { |
| 5139 | previouslyEnabled = true; |
| 5140 | break; |
| 5141 | } |
| 5142 | } |
| 5143 | if (!previouslyEnabled) { |
| 5144 | settings.appendAndPutEnabledInputMethodLocked(imeId, false); |
| 5145 | } |
| 5146 | } |
| 5147 | } else { |
| 5148 | previouslyEnabled = |
| 5149 | settings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 5150 | new StringBuilder(), |
| 5151 | settings.getEnabledInputMethodsAndSubtypeListLocked(), imeId); |
| 5152 | } |
| 5153 | } |
| 5154 | if (failedToEnableUnknownIme) { |
| 5155 | error.print("Unknown input method "); |
| 5156 | error.print(imeId); |
| 5157 | error.println(" cannot be enabled for user #" + userId); |
| 5158 | } else { |
| 5159 | out.print("Input method "); |
| 5160 | out.print(imeId); |
| 5161 | out.print(": "); |
| 5162 | out.print((enabled == previouslyEnabled) ? "already " : "now "); |
| 5163 | out.print(enabled ? "enabled" : "disabled"); |
| 5164 | out.print(" for user #"); |
| 5165 | out.println(userId); |
| 5166 | } |
| 5167 | } |
| 5168 | |
| 5169 | /** |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5170 | * Handles {@code adb shell ime set}. |
| 5171 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 5172 | * @return Exit code of the command. |
| 5173 | */ |
| 5174 | @BinderThread |
| 5175 | @ShellCommandResult |
| 5176 | private int handleShellCommandSetInputMethod(@NonNull ShellCommand shellCommand) { |
Yohei Yukawa | 3403f2d | 2019-04-15 08:16:58 -0700 | [diff] [blame] | 5177 | final int userIdToBeResolved = handleOptionsForCommandsThatOnlyHaveUserOption(shellCommand); |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 5178 | final String imeId = shellCommand.getNextArgRequired(); |
| 5179 | final PrintWriter out = shellCommand.getOutPrintWriter(); |
| 5180 | final PrintWriter error = shellCommand.getErrPrintWriter(); |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 5181 | synchronized (mMethodMap) { |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 5182 | final int[] userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, |
| 5183 | mSettings.getCurrentUserId(), shellCommand.getErrPrintWriter()); |
| 5184 | for (int userId : userIds) { |
| 5185 | if (!userHasDebugPriv(userId, shellCommand)) { |
| 5186 | continue; |
| 5187 | } |
mincheli | 850892b | 2019-12-05 19:47:59 +0800 | [diff] [blame] | 5188 | boolean failedToSelectUnknownIme = !switchToInputMethod(imeId, userId); |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 5189 | if (failedToSelectUnknownIme) { |
| 5190 | error.print("Unknown input method "); |
| 5191 | error.print(imeId); |
| 5192 | error.print(" cannot be selected for user #"); |
| 5193 | error.println(userId); |
| 5194 | } else { |
| 5195 | out.print("Input method "); |
| 5196 | out.print(imeId); |
| 5197 | out.print(" selected for user #"); |
Yohei Yukawa | 3403f2d | 2019-04-15 08:16:58 -0700 | [diff] [blame] | 5198 | out.println(userId); |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 5199 | } |
Tarandeep Singh | 87e2e51 | 2019-03-06 14:28:52 -0800 | [diff] [blame] | 5200 | } |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 5201 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5202 | return ShellCommandResult.SUCCESS; |
| 5203 | } |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5204 | |
| 5205 | /** |
| 5206 | * Handles {@code adb shell ime reset-ime}. |
| 5207 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 5208 | * @return Exit code of the command. |
| 5209 | */ |
| 5210 | @BinderThread |
| 5211 | @ShellCommandResult |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5212 | private int handleShellCommandResetInputMethod(@NonNull ShellCommand shellCommand) { |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 5213 | final PrintWriter out = shellCommand.getOutPrintWriter(); |
| 5214 | final int userIdToBeResolved = handleOptionsForCommandsThatOnlyHaveUserOption(shellCommand); |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5215 | synchronized (mMethodMap) { |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 5216 | final int[] userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, |
| 5217 | mSettings.getCurrentUserId(), shellCommand.getErrPrintWriter()); |
| 5218 | for (int userId : userIds) { |
| 5219 | if (!userHasDebugPriv(userId, shellCommand)) { |
| 5220 | continue; |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5221 | } |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 5222 | final String nextIme; |
| 5223 | final List<InputMethodInfo> nextEnabledImes; |
| 5224 | if (userId == mSettings.getCurrentUserId()) { |
| 5225 | hideCurrentInputLocked(0, null); |
| 5226 | unbindCurrentMethodLocked(); |
| 5227 | // Reset the current IME |
| 5228 | resetSelectedInputMethodAndSubtypeLocked(null); |
| 5229 | // Also reset the settings of the current IME |
| 5230 | mSettings.putSelectedInputMethod(null); |
| 5231 | // Disable all enabled IMEs. |
| 5232 | mSettings.getEnabledInputMethodListLocked().forEach( |
| 5233 | imi -> setInputMethodEnabledLocked(imi.getId(), false)); |
| 5234 | // Re-enable with default enabled IMEs. |
| 5235 | InputMethodUtils.getDefaultEnabledImes(mContext, mMethodList).forEach( |
| 5236 | imi -> setInputMethodEnabledLocked(imi.getId(), true)); |
| 5237 | updateInputMethodsFromSettingsLocked(true /* enabledMayChange */); |
| 5238 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 5239 | mSettings.getEnabledInputMethodListLocked(), |
| 5240 | mSettings.getCurrentUserId(), |
| 5241 | mContext.getBasePackageName()); |
| 5242 | nextIme = mSettings.getSelectedInputMethod(); |
| 5243 | nextEnabledImes = mSettings.getEnabledInputMethodListLocked(); |
| 5244 | } else { |
| 5245 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 5246 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 5247 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 5248 | new ArrayMap<>(); |
| 5249 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 5250 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, |
| 5251 | methodMap, methodList); |
| 5252 | final InputMethodSettings settings = new InputMethodSettings( |
| 5253 | mContext.getResources(), mContext.getContentResolver(), methodMap, |
| 5254 | userId, false); |
| 5255 | |
| 5256 | nextEnabledImes = InputMethodUtils.getDefaultEnabledImes(mContext, methodList); |
| 5257 | nextIme = InputMethodUtils.getMostApplicableDefaultIME(nextEnabledImes).getId(); |
| 5258 | |
| 5259 | // Reset enabled IMEs. |
| 5260 | settings.putEnabledInputMethodsStr(""); |
| 5261 | nextEnabledImes.forEach(imi -> settings.appendAndPutEnabledInputMethodLocked( |
| 5262 | imi.getId(), false)); |
| 5263 | |
| 5264 | // Reset selected IME. |
| 5265 | settings.putSelectedInputMethod(nextIme); |
| 5266 | settings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
| 5267 | } |
| 5268 | out.println("Reset current and enabled IMEs for user #" + userId); |
| 5269 | out.println(" Selected: " + nextIme); |
| 5270 | nextEnabledImes.forEach(ime -> out.println(" Enabled: " + ime.getId())); |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5271 | } |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5272 | } |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 5273 | return ShellCommandResult.SUCCESS; |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5274 | } |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5275 | |
Tarandeep Singh | 87e2e51 | 2019-03-06 14:28:52 -0800 | [diff] [blame] | 5276 | /** |
| 5277 | * @param userId the actual user handle obtained by {@link UserHandle#getIdentifier()} |
| 5278 | * and *not* pseudo ids like {@link UserHandle#USER_ALL etc}. |
| 5279 | * @return {@code true} if userId has debugging privileges. |
| 5280 | * i.e. {@link UserManager#DISALLOW_DEBUGGING_FEATURES} is {@code false}. |
| 5281 | */ |
| 5282 | private boolean userHasDebugPriv(int userId, final ShellCommand shellCommand) { |
| 5283 | if (mUserManager.hasUserRestriction( |
| 5284 | UserManager.DISALLOW_DEBUGGING_FEATURES, UserHandle.of(userId))) { |
| 5285 | shellCommand.getErrPrintWriter().println("User #" + userId |
| 5286 | + " is restricted with DISALLOW_DEBUGGING_FEATURES."); |
| 5287 | return false; |
| 5288 | } |
| 5289 | return true; |
| 5290 | } |
| 5291 | |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5292 | private static final class InputMethodPrivilegedOperationsImpl |
| 5293 | extends IInputMethodPrivilegedOperations.Stub { |
| 5294 | private final InputMethodManagerService mImms; |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 5295 | @NonNull |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5296 | private final IBinder mToken; |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 5297 | InputMethodPrivilegedOperationsImpl(InputMethodManagerService imms, |
| 5298 | @NonNull IBinder token) { |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5299 | mImms = imms; |
| 5300 | mToken = token; |
| 5301 | } |
| 5302 | |
| 5303 | @BinderThread |
| 5304 | @Override |
| 5305 | public void setImeWindowStatus(int vis, int backDisposition) { |
| 5306 | mImms.setImeWindowStatus(mToken, vis, backDisposition); |
| 5307 | } |
| 5308 | |
| 5309 | @BinderThread |
| 5310 | @Override |
| 5311 | public void reportStartInput(IBinder startInputToken) { |
| 5312 | mImms.reportStartInput(mToken, startInputToken); |
| 5313 | } |
| 5314 | |
| 5315 | @BinderThread |
| 5316 | @Override |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5317 | public IInputContentUriToken createInputContentUriToken(Uri contentUri, |
| 5318 | String packageName) { |
| 5319 | return mImms.createInputContentUriToken(mToken, contentUri, packageName); |
| 5320 | } |
| 5321 | |
| 5322 | @BinderThread |
| 5323 | @Override |
| 5324 | public void reportFullscreenMode(boolean fullscreen) { |
| 5325 | mImms.reportFullscreenMode(mToken, fullscreen); |
| 5326 | } |
Yohei Yukawa | c7ca368 | 2018-09-09 20:48:38 -0700 | [diff] [blame] | 5327 | |
| 5328 | @BinderThread |
| 5329 | @Override |
| 5330 | public void setInputMethod(String id) { |
| 5331 | mImms.setInputMethod(mToken, id); |
| 5332 | } |
| 5333 | |
| 5334 | @BinderThread |
| 5335 | @Override |
| 5336 | public void setInputMethodAndSubtype(String id, InputMethodSubtype subtype) { |
| 5337 | mImms.setInputMethodAndSubtype(mToken, id, subtype); |
| 5338 | } |
| 5339 | |
| 5340 | @BinderThread |
| 5341 | @Override |
| 5342 | public void hideMySoftInput(int flags) { |
| 5343 | mImms.hideMySoftInput(mToken, flags); |
| 5344 | } |
| 5345 | |
| 5346 | @BinderThread |
| 5347 | @Override |
| 5348 | public void showMySoftInput(int flags) { |
| 5349 | mImms.showMySoftInput(mToken, flags); |
| 5350 | } |
| 5351 | |
| 5352 | @BinderThread |
| 5353 | @Override |
Yohei Yukawa | 41b094f | 2018-09-09 23:58:45 -0700 | [diff] [blame] | 5354 | public void updateStatusIcon(String packageName, @DrawableRes int iconId) { |
Yohei Yukawa | c7ca368 | 2018-09-09 20:48:38 -0700 | [diff] [blame] | 5355 | mImms.updateStatusIcon(mToken, packageName, iconId); |
| 5356 | } |
| 5357 | |
| 5358 | @BinderThread |
| 5359 | @Override |
| 5360 | public boolean switchToPreviousInputMethod() { |
| 5361 | return mImms.switchToPreviousInputMethod(mToken); |
| 5362 | } |
| 5363 | |
| 5364 | @BinderThread |
| 5365 | @Override |
| 5366 | public boolean switchToNextInputMethod(boolean onlyCurrentIme) { |
| 5367 | return mImms.switchToNextInputMethod(mToken, onlyCurrentIme); |
| 5368 | } |
| 5369 | |
| 5370 | @BinderThread |
| 5371 | @Override |
| 5372 | public boolean shouldOfferSwitchingToNextInputMethod() { |
| 5373 | return mImms.shouldOfferSwitchingToNextInputMethod(mToken); |
| 5374 | } |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 5375 | |
| 5376 | @BinderThread |
| 5377 | @Override |
Yohei Yukawa | 9b60ba0 | 2019-01-21 00:06:27 -0800 | [diff] [blame] | 5378 | public void notifyUserAction() { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 5379 | mImms.notifyUserAction(mToken); |
| 5380 | } |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 5381 | |
| 5382 | @BinderThread |
| 5383 | @Override |
| 5384 | public void reportPreRendered(EditorInfo info) { |
| 5385 | mImms.reportPreRendered(mToken, info); |
| 5386 | } |
| 5387 | |
| 5388 | @BinderThread |
| 5389 | @Override |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 5390 | public void applyImeVisibility(IBinder windowToken, boolean setVisible) { |
| 5391 | mImms.applyImeVisibility(mToken, windowToken, setVisible); |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 5392 | } |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5393 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5394 | } |