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; |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 68 | import android.hardware.input.InputManagerInternal; |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 69 | import android.inputmethodservice.InputMethodService; |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 70 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | import android.os.Binder; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 72 | import android.os.Bundle; |
Seigo Nonaka | e27dc2b | 2015-08-14 18:21:27 -0700 | [diff] [blame] | 73 | import android.os.Debug; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.os.Handler; |
| 75 | import android.os.IBinder; |
| 76 | import android.os.IInterface; |
Yohei Yukawa | 23cbe85 | 2016-05-17 16:42:58 -0700 | [diff] [blame] | 77 | import android.os.LocaleList; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 78 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | import android.os.Parcel; |
Yohei Yukawa | 6ab1a82 | 2015-08-25 14:01:28 -0700 | [diff] [blame] | 80 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | import android.os.RemoteException; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 82 | import android.os.ResultReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | import android.os.ServiceManager; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 84 | import android.os.ShellCallback; |
| 85 | import android.os.ShellCommand; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import android.os.SystemClock; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 87 | import android.os.SystemProperties; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 88 | import android.os.UserHandle; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 89 | import android.os.UserManager; |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 90 | import android.os.UserManagerInternal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | import android.provider.Settings; |
| 92 | import android.text.TextUtils; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 93 | import android.text.style.SuggestionSpan; |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 94 | import android.util.ArrayMap; |
Christopher Tate | 7b9a28c | 2015-03-18 13:06:16 -0700 | [diff] [blame] | 95 | import android.util.ArraySet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | import android.util.EventLog; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 97 | import android.util.LruCache; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 98 | import android.util.Pair; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | import android.util.PrintWriterPrinter; |
| 100 | import android.util.Printer; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 101 | import android.util.Slog; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 102 | import android.util.SparseArray; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 103 | import android.view.ContextThemeWrapper; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 104 | import android.view.DisplayInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | import android.view.IWindowManager; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 106 | import android.view.InputChannel; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 107 | import android.view.LayoutInflater; |
| 108 | import android.view.View; |
| 109 | import android.view.ViewGroup; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 110 | import android.view.Window; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 111 | import android.view.WindowManager.LayoutParams; |
Yohei Yukawa | b0c2645 | 2018-10-21 10:42:52 -0700 | [diff] [blame] | 112 | import android.view.WindowManager.LayoutParams.SoftInputModeFlags; |
Feng Cao | 7c85eb7 | 2020-02-28 11:39:56 -0800 | [diff] [blame] | 113 | import android.view.autofill.AutofillId; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 114 | import android.view.inputmethod.EditorInfo; |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 115 | import android.view.inputmethod.InlineSuggestionsRequest; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | import android.view.inputmethod.InputBinding; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 117 | import android.view.inputmethod.InputConnection; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 118 | import android.view.inputmethod.InputConnectionInspector; |
Yohei Yukawa | 432cf60 | 2018-10-21 10:41:37 -0700 | [diff] [blame] | 119 | import android.view.inputmethod.InputConnectionInspector.MissingMethodFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | import android.view.inputmethod.InputMethod; |
| 121 | import android.view.inputmethod.InputMethodInfo; |
| 122 | import android.view.inputmethod.InputMethodManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 123 | import android.view.inputmethod.InputMethodSubtype; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 124 | import android.widget.ArrayAdapter; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 125 | import android.widget.CompoundButton; |
| 126 | import android.widget.CompoundButton.OnCheckedChangeListener; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 127 | import android.widget.RadioButton; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 128 | import android.widget.Switch; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 129 | import android.widget.TextView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 131 | import com.android.internal.annotations.GuardedBy; |
| 132 | import com.android.internal.content.PackageMonitor; |
| 133 | import com.android.internal.inputmethod.IInputContentUriToken; |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 134 | import com.android.internal.inputmethod.IInputMethodPrivilegedOperations; |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 135 | import com.android.internal.inputmethod.InputMethodDebug; |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 136 | import com.android.internal.inputmethod.SoftInputShowHideReason; |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 137 | import com.android.internal.inputmethod.StartInputFlags; |
Yohei Yukawa | c6632df | 2018-10-21 11:47:16 -0700 | [diff] [blame] | 138 | import com.android.internal.inputmethod.StartInputReason; |
Yohei Yukawa | 499e3f7 | 2018-10-21 20:15:11 -0700 | [diff] [blame] | 139 | import com.android.internal.inputmethod.UnbindReason; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 140 | import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; |
| 141 | import com.android.internal.notification.SystemNotificationChannels; |
| 142 | import com.android.internal.os.HandlerCaller; |
| 143 | import com.android.internal.os.SomeArgs; |
| 144 | import com.android.internal.os.TransferPipe; |
| 145 | import com.android.internal.util.DumpUtils; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 146 | import com.android.internal.util.IndentingPrintWriter; |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 147 | import com.android.internal.view.IInlineSuggestionsRequestCallback; |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 148 | import com.android.internal.view.IInlineSuggestionsResponseCallback; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 149 | import com.android.internal.view.IInputContext; |
| 150 | import com.android.internal.view.IInputMethod; |
| 151 | import com.android.internal.view.IInputMethodClient; |
| 152 | import com.android.internal.view.IInputMethodManager; |
| 153 | import com.android.internal.view.IInputMethodSession; |
| 154 | import com.android.internal.view.IInputSessionCallback; |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 155 | import com.android.internal.view.InlineSuggestionsRequestInfo; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 156 | import com.android.internal.view.InputBindResult; |
Yohei Yukawa | 603f4d0 | 2018-09-11 15:04:58 -0700 | [diff] [blame] | 157 | import com.android.server.EventLogTags; |
| 158 | import com.android.server.LocalServices; |
| 159 | import com.android.server.SystemService; |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 160 | import com.android.server.inputmethod.InputMethodManagerInternal.InputMethodListListener; |
Yohei Yukawa | e6b6e0e | 2018-09-12 16:42:48 -0700 | [diff] [blame] | 161 | import com.android.server.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem; |
| 162 | import com.android.server.inputmethod.InputMethodUtils.InputMethodSettings; |
Yohei Yukawa | 0569a18 | 2018-08-28 16:09:28 -0700 | [diff] [blame] | 163 | import com.android.server.statusbar.StatusBarManagerService; |
Adrian Roos | e99bc05 | 2017-11-20 17:55:31 +0100 | [diff] [blame] | 164 | import com.android.server.wm.WindowManagerInternal; |
| 165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | import java.io.FileDescriptor; |
| 167 | import java.io.IOException; |
| 168 | import java.io.PrintWriter; |
Yohei Yukawa | fa0e47e | 2016-04-05 09:55:56 -0700 | [diff] [blame] | 169 | import java.lang.annotation.Retention; |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 170 | import java.security.InvalidParameterException; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 171 | import java.text.SimpleDateFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | import java.util.ArrayList; |
Yohei Yukawa | b8d240f | 2018-12-26 10:03:11 -0800 | [diff] [blame] | 173 | import java.util.Arrays; |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 174 | import java.util.Collections; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 175 | import java.util.Date; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | import java.util.List; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 177 | import java.util.Locale; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 178 | import java.util.WeakHashMap; |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 179 | import java.util.concurrent.CopyOnWriteArrayList; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 180 | import java.util.concurrent.atomic.AtomicInteger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * This class provides a system service that manages input methods. |
| 184 | */ |
| 185 | public class InputMethodManagerService extends IInputMethodManager.Stub |
| 186 | implements ServiceConnection, Handler.Callback { |
| 187 | static final boolean DEBUG = false; |
Jeff Brown | 6ec6f79 | 2012-04-17 16:52:41 -0700 | [diff] [blame] | 188 | static final String TAG = "InputMethodManagerService"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 190 | @Retention(SOURCE) |
| 191 | @IntDef({ShellCommandResult.SUCCESS, ShellCommandResult.FAILURE}) |
| 192 | private @interface ShellCommandResult { |
| 193 | int SUCCESS = 0; |
| 194 | int FAILURE = -1; |
| 195 | } |
| 196 | |
Seigo Nonaka | d4474cb | 2015-05-04 16:53:24 -0700 | [diff] [blame] | 197 | static final int MSG_SHOW_IM_SUBTYPE_PICKER = 1; |
| 198 | static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 2; |
| 199 | static final int MSG_SHOW_IM_CONFIG = 3; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | static final int MSG_UNBIND_INPUT = 1000; |
| 202 | static final int MSG_BIND_INPUT = 1010; |
| 203 | static final int MSG_SHOW_SOFT_INPUT = 1020; |
| 204 | static final int MSG_HIDE_SOFT_INPUT = 1030; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 205 | static final int MSG_HIDE_CURRENT_INPUT_METHOD = 1035; |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 206 | static final int MSG_INITIALIZE_IME = 1040; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | static final int MSG_CREATE_SESSION = 1050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 208 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | static final int MSG_START_INPUT = 2000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 210 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 211 | static final int MSG_UNBIND_CLIENT = 3000; |
| 212 | static final int MSG_BIND_CLIENT = 3010; |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 213 | static final int MSG_SET_ACTIVE = 3020; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 214 | static final int MSG_SET_INTERACTIVE = 3030; |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 215 | static final int MSG_REPORT_FULLSCREEN_MODE = 3045; |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 216 | static final int MSG_REPORT_PRE_RENDERED = 3060; |
| 217 | static final int MSG_APPLY_IME_VISIBILITY = 3070; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 218 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 219 | static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000; |
| 220 | |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 221 | static final int MSG_SYSTEM_UNLOCK_USER = 5000; |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 222 | static final int MSG_DISPATCH_ON_INPUT_METHOD_LIST_UPDATED = 5010; |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 223 | |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 224 | static final int MSG_INLINE_SUGGESTIONS_REQUEST = 6000; |
| 225 | |
Satoshi Kataoka | bcacc32 | 2013-10-21 17:57:27 -0700 | [diff] [blame] | 226 | static final long TIME_TO_RECONNECT = 3 * 1000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 227 | |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 228 | static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20; |
| 229 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 230 | private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID; |
satok | b635941 | 2011-06-28 17:47:41 +0900 | [diff] [blame] | 231 | private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher"; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 232 | |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 233 | /** |
| 234 | * Binding flags for establishing connection to the {@link InputMethodService}. |
| 235 | */ |
| 236 | private static final int IME_CONNECTION_BIND_FLAGS = |
| 237 | Context.BIND_AUTO_CREATE |
| 238 | | Context.BIND_NOT_VISIBLE |
| 239 | | Context.BIND_NOT_FOREGROUND |
Yohei Yukawa | ad78a61 | 2017-08-04 01:57:27 -0700 | [diff] [blame] | 240 | | Context.BIND_IMPORTANT_BACKGROUND; |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 241 | |
| 242 | /** |
| 243 | * Binding flags used only while the {@link InputMethodService} is showing window. |
| 244 | */ |
| 245 | private static final int IME_VISIBLE_BIND_FLAGS = |
| 246 | Context.BIND_AUTO_CREATE |
| 247 | | Context.BIND_TREAT_LIKE_ACTIVITY |
Yohei Yukawa | ad78a61 | 2017-08-04 01:57:27 -0700 | [diff] [blame] | 248 | | Context.BIND_FOREGROUND_SERVICE |
Amith Yamasani | c45a990 | 2019-04-05 16:29:30 -0700 | [diff] [blame] | 249 | | Context.BIND_INCLUDE_CAPABILITIES |
Yohei Yukawa | 5973096 | 2019-03-18 10:47:22 -0700 | [diff] [blame] | 250 | | Context.BIND_SHOWING_UI |
| 251 | | Context.BIND_SCHEDULE_LIKE_TOP_APP; |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 252 | |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 253 | /** |
| 254 | * A protected broadcast intent action for internal use for {@link PendingIntent} in |
| 255 | * the notification. |
| 256 | */ |
| 257 | private static final String ACTION_SHOW_INPUT_METHOD_PICKER = |
Yohei Yukawa | 603f4d0 | 2018-09-11 15:04:58 -0700 | [diff] [blame] | 258 | "com.android.server.inputmethod.InputMethodManagerService.SHOW_INPUT_METHOD_PICKER"; |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 259 | |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 260 | /** |
| 261 | * Debug flag for overriding runtime {@link SystemProperties}. |
| 262 | */ |
| 263 | @AnyThread |
| 264 | private static final class DebugFlag { |
| 265 | private static final Object LOCK = new Object(); |
| 266 | private final String mKey; |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 267 | private final boolean mDefaultValue; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 268 | @GuardedBy("LOCK") |
| 269 | private boolean mValue; |
| 270 | |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 271 | public DebugFlag(String key, boolean defaultValue) { |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 272 | mKey = key; |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 273 | mDefaultValue = defaultValue; |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 274 | mValue = SystemProperties.getBoolean(key, defaultValue); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | void refresh() { |
| 278 | synchronized (LOCK) { |
Tarandeep Singh | 9df4ad1 | 2018-04-03 13:35:50 -0700 | [diff] [blame] | 279 | mValue = SystemProperties.getBoolean(mKey, mDefaultValue); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
| 283 | boolean value() { |
| 284 | synchronized (LOCK) { |
| 285 | return mValue; |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Debug flags that can be overridden using "adb shell setprop <key>" |
| 292 | * Note: These flags are cached. To refresh, run "adb shell ime refresh_debug_properties". |
| 293 | */ |
| 294 | private static final class DebugFlags { |
| 295 | static final DebugFlag FLAG_OPTIMIZE_START_INPUT = |
Tarandeep Singh | 1c042c5 | 2018-03-29 17:04:44 -0700 | [diff] [blame] | 296 | new DebugFlag("debug.optimize_startinput", false); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 297 | static final DebugFlag FLAG_PRE_RENDER_IME_VIEWS = |
| 298 | new DebugFlag("persist.pre_render_ime_views", false); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 301 | @UserIdInt |
| 302 | private int mLastSwitchUserId; |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | final Context mContext; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 305 | final Resources mRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | final Handler mHandler; |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 307 | final InputMethodSettings mSettings; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | final SettingsObserver mSettingsObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | final IWindowManager mIWindowManager; |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 310 | final WindowManagerInternal mWindowManagerInternal; |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 311 | final InputManagerInternal mInputManagerInternal; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 312 | private final DisplayManagerInternal mDisplayManagerInternal; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | final HandlerCaller mCaller; |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 314 | final boolean mHasFeature; |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 315 | private final ArrayMap<String, List<InputMethodSubtype>> mAdditionalSubtypeMap = |
| 316 | new ArrayMap<>(); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 317 | private final boolean mIsLowRam; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 318 | private final HardKeyboardListener mHardKeyboardListener; |
Yohei Yukawa | e63b5fa | 2014-09-19 13:14:55 +0900 | [diff] [blame] | 319 | private final AppOpsManager mAppOpsManager; |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 320 | private final UserManager mUserManager; |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 321 | private final UserManagerInternal mUserManagerInternal; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | // All known input methods. mMethodMap also serves as the global |
| 324 | // lock for this class. |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 325 | final ArrayList<InputMethodInfo> mMethodList = new ArrayList<>(); |
Yohei Yukawa | 1dd7de6 | 2018-11-20 19:25:29 -0800 | [diff] [blame] | 326 | final ArrayMap<String, InputMethodInfo> mMethodMap = new ArrayMap<>(); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 327 | private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans = |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 328 | new LruCache<>(SECURE_SUGGESTION_SPANS_MAX_SIZE); |
Satoshi Kataoka | d787f69 | 2013-10-26 04:44:21 +0900 | [diff] [blame] | 329 | private final InputMethodSubtypeSwitchingController mSwitchingController; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 330 | |
Yohei Yukawa | e073306 | 2017-02-09 22:49:35 -0800 | [diff] [blame] | 331 | /** |
| 332 | * Tracks how many times {@link #mMethodMap} was updated. |
| 333 | */ |
| 334 | @GuardedBy("mMethodMap") |
| 335 | private int mMethodMapUpdateCount = 0; |
| 336 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 337 | // Used to bring IME service up to visible adjustment while it is being shown. |
| 338 | final ServiceConnection mVisibleConnection = new ServiceConnection() { |
Yohei Yukawa | d3ef842 | 2018-06-07 16:28:07 -0700 | [diff] [blame] | 339 | @Override public void onBindingDied(ComponentName name) { |
| 340 | synchronized (mMethodMap) { |
| 341 | if (mVisibleBound) { |
| 342 | mContext.unbindService(mVisibleConnection); |
| 343 | mVisibleBound = false; |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 348 | @Override public void onServiceConnected(ComponentName name, IBinder service) { |
| 349 | } |
| 350 | |
| 351 | @Override public void onServiceDisconnected(ComponentName name) { |
| 352 | } |
| 353 | }; |
| 354 | boolean mVisibleBound = false; |
| 355 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 356 | // Ongoing notification |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 357 | private NotificationManager mNotificationManager; |
| 358 | private KeyguardManager mKeyguardManager; |
Griff Hazen | 6090c26 | 2016-03-25 08:11:24 -0700 | [diff] [blame] | 359 | private @Nullable StatusBarManagerService mStatusBar; |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 360 | private Notification.Builder mImeSwitcherNotification; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 361 | private PendingIntent mImeSwitchPendingIntent; |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 362 | private boolean mShowOngoingImeSwitcherForPhones; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 363 | private boolean mNotificationShown; |
| 364 | |
Tadashi G. Takaoka | 8c6d477 | 2014-08-05 15:29:17 +0900 | [diff] [blame] | 365 | static class SessionState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | final ClientState client; |
| 367 | final IInputMethod method; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 368 | |
| 369 | IInputMethodSession session; |
| 370 | InputChannel channel; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 371 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 372 | @Override |
| 373 | public String toString() { |
| 374 | return "SessionState{uid " + client.uid + " pid " + client.pid |
| 375 | + " method " + Integer.toHexString( |
| 376 | System.identityHashCode(method)) |
| 377 | + " session " + Integer.toHexString( |
| 378 | System.identityHashCode(session)) |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 379 | + " channel " + channel |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | + "}"; |
| 381 | } |
| 382 | |
| 383 | SessionState(ClientState _client, IInputMethod _method, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 384 | IInputMethodSession _session, InputChannel _channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | client = _client; |
| 386 | method = _method; |
| 387 | session = _session; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 388 | channel = _channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | } |
| 390 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 391 | |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 392 | private static final class ClientDeathRecipient implements IBinder.DeathRecipient { |
| 393 | private final InputMethodManagerService mImms; |
| 394 | private final IInputMethodClient mClient; |
| 395 | |
| 396 | ClientDeathRecipient(InputMethodManagerService imms, IInputMethodClient client) { |
| 397 | mImms = imms; |
| 398 | mClient = client; |
| 399 | } |
| 400 | |
| 401 | @Override |
| 402 | public void binderDied() { |
| 403 | mImms.removeClient(mClient); |
| 404 | } |
| 405 | } |
| 406 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 407 | static final class ClientState { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | final IInputMethodClient client; |
| 409 | final IInputContext inputContext; |
| 410 | final int uid; |
| 411 | final int pid; |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 412 | final int selfReportedDisplayId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | final InputBinding binding; |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 414 | final ClientDeathRecipient clientDeathRecipient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 415 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | boolean sessionRequested; |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 417 | // Determines if IMEs should be pre-rendered. |
| 418 | // DebugFlag can be flipped anytime. This flag is kept per-client to maintain behavior |
| 419 | // through the life of the current client. |
| 420 | boolean shouldPreRenderIme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | SessionState curSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 422 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | @Override |
| 424 | public String toString() { |
| 425 | return "ClientState{" + Integer.toHexString( |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 426 | System.identityHashCode(this)) + " uid=" + uid |
| 427 | + " pid=" + pid + " displayId=" + selfReportedDisplayId + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | ClientState(IInputMethodClient _client, IInputContext _inputContext, |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 431 | int _uid, int _pid, int _selfReportedDisplayId, |
| 432 | ClientDeathRecipient _clientDeathRecipient) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | client = _client; |
| 434 | inputContext = _inputContext; |
| 435 | uid = _uid; |
| 436 | pid = _pid; |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 437 | selfReportedDisplayId = _selfReportedDisplayId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | binding = new InputBinding(null, inputContext.asBinder(), uid, pid); |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 439 | clientDeathRecipient = _clientDeathRecipient; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | } |
| 441 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 442 | |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 443 | final ArrayMap<IBinder, ClientState> mClients = new ArrayMap<>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 444 | |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 445 | private static final class ActivityViewInfo { |
| 446 | /** |
| 447 | * {@link ClientState} where {@link android.app.ActivityView} is running. |
| 448 | */ |
| 449 | private final ClientState mParentClient; |
| 450 | /** |
| 451 | * {@link Matrix} to convert screen coordinates in the embedded virtual display to |
| 452 | * screen coordinates where {@link #mParentClient} exists. |
| 453 | */ |
| 454 | private final Matrix mMatrix; |
| 455 | |
| 456 | ActivityViewInfo(ClientState parentClient, Matrix matrix) { |
| 457 | mParentClient = parentClient; |
| 458 | mMatrix = matrix; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * A mapping table from virtual display IDs created for {@link android.app.ActivityView} |
| 464 | * to its parent IME client where {@link android.app.ActivityView} is running. |
| 465 | * |
| 466 | * <p>Note: this can be used only for virtual display IDs created by |
| 467 | * {@link android.app.ActivityView}.</p> |
| 468 | */ |
| 469 | private SparseArray<ActivityViewInfo> mActivityViewDisplayIdToParentMap = new SparseArray<>(); |
| 470 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | /** |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 472 | * Set once the system is ready to run third party code. |
| 473 | */ |
| 474 | boolean mSystemReady; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 475 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 476 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 477 | * Id obtained with {@link InputMethodInfo#getId()} for the currently selected input method. |
| 478 | * method. This is to be synchronized with the secure settings keyed with |
| 479 | * {@link Settings.Secure#DEFAULT_INPUT_METHOD}. |
| 480 | * |
| 481 | * <p>This can be transiently {@code null} when the system is re-initializing input method |
| 482 | * settings, e.g., the system locale is just changed.</p> |
| 483 | * |
| 484 | * <p>Note that {@link #mCurId} is used to track which IME is being connected to |
| 485 | * {@link InputMethodManagerService}.</p> |
| 486 | * |
| 487 | * @see #mCurId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 489 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | String mCurMethodId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | /** |
| 493 | * The current binding sequence number, incremented every time there is |
| 494 | * a new bind performed. |
| 495 | */ |
| 496 | int mCurSeq; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 497 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | /** |
| 499 | * The client that is currently bound to an input method. |
| 500 | */ |
| 501 | ClientState mCurClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | /** |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 504 | * The last window token that we confirmed to be focused. This is always updated upon reports |
| 505 | * from the input method client. If the window state is already changed before the report is |
| 506 | * handled, this field just keeps the last value. |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 507 | */ |
| 508 | IBinder mCurFocusedWindow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 509 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 510 | /** |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 511 | * The last window token that we confirmed that IME started talking to. This is always updated |
| 512 | * upon reports from the input method. If the window state is already changed before the report |
| 513 | * is handled, this field just keeps the last value. |
| 514 | */ |
| 515 | IBinder mLastImeTargetWindow; |
| 516 | |
| 517 | /** |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 518 | * {@link LayoutParams#softInputMode} of {@link #mCurFocusedWindow}. |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 519 | * |
| 520 | * @see #mCurFocusedWindow |
| 521 | */ |
Yohei Yukawa | b0c2645 | 2018-10-21 10:42:52 -0700 | [diff] [blame] | 522 | @SoftInputModeFlags |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 523 | int mCurFocusedWindowSoftInputMode; |
| 524 | |
| 525 | /** |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 526 | * The client by which {@link #mCurFocusedWindow} was reported. |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 527 | */ |
| 528 | ClientState mCurFocusedWindowClient; |
| 529 | |
| 530 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | * The input context last provided by the current client. |
| 532 | */ |
| 533 | IInputContext mCurInputContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 534 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | /** |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 536 | * The missing method flags for the input context last provided by the current client. |
| 537 | * |
| 538 | * @see android.view.inputmethod.InputConnectionInspector.MissingMethodFlags |
| 539 | */ |
Yohei Yukawa | 432cf60 | 2018-10-21 10:41:37 -0700 | [diff] [blame] | 540 | @MissingMethodFlags |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 541 | int mCurInputContextMissingMethods; |
| 542 | |
| 543 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | * The attributes last provided by the current client. |
| 545 | */ |
| 546 | EditorInfo mCurAttribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 547 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | /** |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 549 | * A special {@link Matrix} to convert virtual screen coordinates to the IME target display |
| 550 | * coordinates. |
| 551 | * |
| 552 | * <p>Used only while the IME client is running in a virtual display inside |
| 553 | * {@link android.app.ActivityView}. {@code null} otherwise.</p> |
| 554 | */ |
| 555 | @Nullable |
| 556 | private Matrix mCurActivityViewToScreenMatrix = null; |
| 557 | |
| 558 | /** |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 559 | * 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] | 560 | * connected to or in the process of connecting to. |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 561 | * |
| 562 | * <p>This can be {@code null} when no input method is connected.</p> |
| 563 | * |
| 564 | * @see #mCurMethodId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | */ |
Yohei Yukawa | e13a20fa | 2015-09-30 19:11:32 -0700 | [diff] [blame] | 566 | @Nullable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 567 | String mCurId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 568 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | /** |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 570 | * The current subtype of the current input method. |
| 571 | */ |
| 572 | private InputMethodSubtype mCurrentSubtype; |
| 573 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 574 | // Was the keyguard locked when this client became current? |
| 575 | private boolean mCurClientInKeyguard; |
| 576 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 577 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | * Set to true if our ServiceConnection is currently actively bound to |
| 579 | * a service (whether or not we have gotten its IBinder back yet). |
| 580 | */ |
| 581 | boolean mHaveConnection; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | /** |
| 584 | * Set if the client has asked for the input method to be shown. |
| 585 | */ |
| 586 | boolean mShowRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 587 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | /** |
| 589 | * Set if we were explicitly told to show the input method. |
| 590 | */ |
| 591 | boolean mShowExplicitlyRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 592 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | /** |
| 594 | * Set if we were forced to be shown. |
| 595 | */ |
| 596 | boolean mShowForced; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | /** |
| 599 | * Set if we last told the input method to show itself. |
| 600 | */ |
| 601 | boolean mInputShown; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | /** |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 604 | * {@code true} if the current input method is in fullscreen mode. |
| 605 | */ |
| 606 | boolean mInFullscreenMode; |
| 607 | |
| 608 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | * The Intent used to connect to the current input method. |
| 610 | */ |
| 611 | Intent mCurIntent; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 612 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | /** |
| 614 | * The token we have made for the currently active input method, to |
| 615 | * identify it in the future. |
| 616 | */ |
| 617 | IBinder mCurToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 618 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | /** |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 620 | * The displayId of current active input method. |
| 621 | */ |
| 622 | int mCurTokenDisplayId = INVALID_DISPLAY; |
| 623 | |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 624 | /** |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 625 | * The host input token of the current active input method. |
| 626 | */ |
| 627 | @GuardedBy("mMethodMap") |
| 628 | @Nullable |
| 629 | private IBinder mCurHostInputToken; |
| 630 | |
| 631 | /** |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 632 | * The display ID of the input method indicates the fallback display which returned by |
| 633 | * {@link #computeImeDisplayIdForTarget}. |
| 634 | */ |
| 635 | private static final int FALLBACK_DISPLAY_ID = DEFAULT_DISPLAY; |
| 636 | |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 637 | final ImeDisplayValidator mImeDisplayValidator; |
| 638 | |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 639 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | * If non-null, this is the input method service we are currently connected |
| 641 | * to. |
| 642 | */ |
| 643 | IInputMethod mCurMethod; |
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 | * Time that we last initiated a bind to the input method, to determine |
| 647 | * if we should try to disconnect and reconnect to it. |
| 648 | */ |
| 649 | long mLastBindTime; |
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 | /** |
| 652 | * Have we called mCurMethod.bindInput()? |
| 653 | */ |
| 654 | boolean mBoundToMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 655 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | /** |
| 657 | * Currently enabled session. Only touched by service thread, not |
| 658 | * protected by a lock. |
| 659 | */ |
| 660 | SessionState mEnabledSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 661 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 662 | /** |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 663 | * 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] | 664 | */ |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 665 | boolean mIsInteractive = true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 666 | |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 667 | int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 668 | |
| 669 | /** |
| 670 | * A set of status bits regarding the active IME. |
| 671 | * |
| 672 | * <p>This value is a combination of following two bits:</p> |
| 673 | * <dl> |
| 674 | * <dt>{@link InputMethodService#IME_ACTIVE}</dt> |
| 675 | * <dd> |
| 676 | * If this bit is ON, connected IME is ready to accept touch/key events. |
| 677 | * </dd> |
| 678 | * <dt>{@link InputMethodService#IME_VISIBLE}</dt> |
| 679 | * <dd> |
| 680 | * If this bit is ON, some of IME view, e.g. software input, candidate view, is visible. |
| 681 | * </dd> |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 682 | * dt>{@link InputMethodService#IME_INVISIBLE}</dt> |
| 683 | * <dd> If this bit is ON, IME is ready with views from last EditorInfo but is |
| 684 | * currently invisible. |
| 685 | * </dd> |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 686 | * </dl> |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 687 | * <em>Do not update this value outside of {@link #setImeWindowStatus(IBinder, int, int)} and |
| 688 | * {@link #unbindCurrentMethodLocked()}.</em> |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 689 | */ |
Joe Onorato | 857fd9b | 2011-01-27 15:08:35 -0800 | [diff] [blame] | 690 | int mImeWindowVis; |
| 691 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 692 | private AlertDialog.Builder mDialogBuilder; |
| 693 | private AlertDialog mSwitchingDialog; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 694 | private IBinder mSwitchingDialogToken = new Binder(); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 695 | private View mSwitchingDialogTitleView; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 696 | private InputMethodInfo[] mIms; |
| 697 | private int[] mSubtypeIds; |
Yohei Yukawa | e985c24 | 2016-02-24 18:27:04 -0800 | [diff] [blame] | 698 | private LocaleList mLastSystemLocales; |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 699 | private boolean mShowImeWithHardKeyboard; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 700 | private boolean mAccessibilityRequestingNoSoftKeyboard; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 701 | private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor(); |
| 702 | private final IPackageManager mIPackageManager; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 703 | private final String mSlotIme; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 704 | |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 705 | /** |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 706 | * Registered {@link InputMethodListListeners}. |
| 707 | * This variable can be accessed from both of MainThread and BinderThread. |
| 708 | */ |
| 709 | private final CopyOnWriteArrayList<InputMethodListListener> mInputMethodListListeners = |
| 710 | new CopyOnWriteArrayList<>(); |
| 711 | |
| 712 | /** |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 713 | * Internal state snapshot when {@link #MSG_START_INPUT} message is about to be posted to the |
| 714 | * internal message queue. Any subsequent state change inside {@link InputMethodManagerService} |
| 715 | * will not affect those tasks that are already posted. |
| 716 | * |
| 717 | * <p>Posting {@link #MSG_START_INPUT} message basically means that |
| 718 | * {@link InputMethodService#doStartInput(InputConnection, EditorInfo, boolean)} will be called |
| 719 | * back in the current IME process shortly, which will also affect what the current IME starts |
| 720 | * receiving from {@link InputMethodService#getCurrentInputConnection()}. In other words, this |
| 721 | * snapshot will be taken every time when {@link InputMethodManagerService} is initiating a new |
| 722 | * logical input session between the client application and the current IME.</p> |
| 723 | * |
| 724 | * <p>Be careful to not keep strong references to this object forever, which can prevent |
| 725 | * {@link StartInputInfo#mImeToken} and {@link StartInputInfo#mTargetWindow} from being GC-ed. |
| 726 | * </p> |
| 727 | */ |
| 728 | private static class StartInputInfo { |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 729 | private static final AtomicInteger sSequenceNumber = new AtomicInteger(0); |
| 730 | |
| 731 | final int mSequenceNumber; |
| 732 | final long mTimestamp; |
| 733 | final long mWallTime; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 734 | @UserIdInt |
| 735 | final int mImeUserId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 736 | @NonNull |
| 737 | final IBinder mImeToken; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 738 | final int mImeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 739 | @NonNull |
| 740 | final String mImeId; |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 741 | @StartInputReason |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 742 | final int mStartInputReason; |
| 743 | final boolean mRestarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 744 | @UserIdInt |
| 745 | final int mTargetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 746 | final int mTargetDisplayId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 747 | @Nullable |
| 748 | final IBinder mTargetWindow; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 749 | @NonNull |
| 750 | final EditorInfo mEditorInfo; |
Yohei Yukawa | b0c2645 | 2018-10-21 10:42:52 -0700 | [diff] [blame] | 751 | @SoftInputModeFlags |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 752 | final int mTargetWindowSoftInputMode; |
| 753 | final int mClientBindSequenceNumber; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 754 | |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 755 | StartInputInfo(@UserIdInt int imeUserId, @NonNull IBinder imeToken, int imeDisplayId, |
| 756 | @NonNull String imeId, @StartInputReason int startInputReason, boolean restarting, |
| 757 | @UserIdInt int targetUserId, int targetDisplayId, @Nullable IBinder targetWindow, |
| 758 | @NonNull EditorInfo editorInfo, @SoftInputModeFlags int targetWindowSoftInputMode, |
| 759 | int clientBindSequenceNumber) { |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 760 | mSequenceNumber = sSequenceNumber.getAndIncrement(); |
| 761 | mTimestamp = SystemClock.uptimeMillis(); |
| 762 | mWallTime = System.currentTimeMillis(); |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 763 | mImeUserId = imeUserId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 764 | mImeToken = imeToken; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 765 | mImeDisplayId = imeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 766 | mImeId = imeId; |
| 767 | mStartInputReason = startInputReason; |
| 768 | mRestarting = restarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 769 | mTargetUserId = targetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 770 | mTargetDisplayId = targetDisplayId; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 771 | mTargetWindow = targetWindow; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 772 | mEditorInfo = editorInfo; |
| 773 | mTargetWindowSoftInputMode = targetWindowSoftInputMode; |
| 774 | mClientBindSequenceNumber = clientBindSequenceNumber; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | |
Yohei Yukawa | b37d8bd | 2017-02-13 18:29:05 -0800 | [diff] [blame] | 778 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 779 | private final WeakHashMap<IBinder, IBinder> mImeTargetWindowMap = new WeakHashMap<>(); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 780 | |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 781 | private static final class SoftInputShowHideHistory { |
| 782 | private Entry[] mEntries = new Entry[16]; |
| 783 | private int mNextIndex = 0; |
| 784 | private static final AtomicInteger sSequenceNumber = new AtomicInteger(0); |
| 785 | |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 786 | private static final class Entry { |
Ming-Shin Lu | a0605a6 | 2020-04-15 23:49:40 +0800 | [diff] [blame] | 787 | final int mSequenceNumber = sSequenceNumber.getAndIncrement(); |
Anmol Gupta | 29f209d | 2020-03-11 11:34:46 -0700 | [diff] [blame] | 788 | final ClientState mClientState; |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 789 | @SoftInputModeFlags |
Anmol Gupta | 29f209d | 2020-03-11 11:34:46 -0700 | [diff] [blame] | 790 | final int mFocusedWindowSoftInputMode; |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 791 | @SoftInputShowHideReason |
Anmol Gupta | 29f209d | 2020-03-11 11:34:46 -0700 | [diff] [blame] | 792 | final int mReason; |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 793 | // The timing of handling MSG_SHOW_SOFT_INPUT or MSG_HIDE_SOFT_INPUT. |
Anmol Gupta | 29f209d | 2020-03-11 11:34:46 -0700 | [diff] [blame] | 794 | final long mTimestamp; |
| 795 | final long mWallTime; |
| 796 | final boolean mInFullscreenMode; |
| 797 | @NonNull |
| 798 | final String mFocusedWindowName; |
| 799 | @NonNull |
| 800 | final EditorInfo mEditorInfo; |
| 801 | @NonNull |
| 802 | final String mRequestWindowName; |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 803 | |
Anmol Gupta | 29f209d | 2020-03-11 11:34:46 -0700 | [diff] [blame] | 804 | Entry(ClientState client, EditorInfo editorInfo, String focusedWindowName, |
| 805 | @SoftInputModeFlags int softInputMode, @SoftInputShowHideReason int reason, |
| 806 | boolean inFullscreenMode, String requestWindowName) { |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 807 | mClientState = client; |
Anmol Gupta | 29f209d | 2020-03-11 11:34:46 -0700 | [diff] [blame] | 808 | mEditorInfo = editorInfo; |
| 809 | mFocusedWindowName = focusedWindowName; |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 810 | mFocusedWindowSoftInputMode = softInputMode; |
| 811 | mReason = reason; |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 812 | mTimestamp = SystemClock.uptimeMillis(); |
| 813 | mWallTime = System.currentTimeMillis(); |
Anmol Gupta | 29f209d | 2020-03-11 11:34:46 -0700 | [diff] [blame] | 814 | mInFullscreenMode = inFullscreenMode; |
| 815 | mRequestWindowName = requestWindowName; |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | |
| 819 | void addEntry(@NonNull Entry entry) { |
| 820 | final int index = mNextIndex; |
| 821 | mEntries[index] = entry; |
| 822 | mNextIndex = (mNextIndex + 1) % mEntries.length; |
| 823 | } |
| 824 | |
| 825 | void dump(@NonNull PrintWriter pw, @NonNull String prefix) { |
| 826 | final SimpleDateFormat dataFormat = |
| 827 | new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US); |
| 828 | |
| 829 | for (int i = 0; i < mEntries.length; ++i) { |
| 830 | final Entry entry = mEntries[(i + mNextIndex) % mEntries.length]; |
| 831 | if (entry == null) { |
| 832 | continue; |
| 833 | } |
| 834 | pw.print(prefix); |
Ming-Shin Lu | a0605a6 | 2020-04-15 23:49:40 +0800 | [diff] [blame] | 835 | pw.println("SoftInputShowHideHistory #" + entry.mSequenceNumber + ":"); |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 836 | |
| 837 | pw.print(prefix); |
| 838 | pw.println(" time=" + dataFormat.format(new Date(entry.mWallTime)) |
| 839 | + " (timestamp=" + entry.mTimestamp + ")"); |
| 840 | |
| 841 | pw.print(prefix); |
Anmol Gupta | 29f209d | 2020-03-11 11:34:46 -0700 | [diff] [blame] | 842 | pw.print(" reason=" + InputMethodDebug.softInputDisplayReasonToString( |
| 843 | entry.mReason)); |
| 844 | pw.println(" inFullscreenMode=" + entry.mInFullscreenMode); |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 845 | |
| 846 | pw.print(prefix); |
Anmol Gupta | 29f209d | 2020-03-11 11:34:46 -0700 | [diff] [blame] | 847 | pw.println(" requestClient=" + entry.mClientState); |
| 848 | |
| 849 | pw.print(prefix); |
| 850 | pw.println(" focusedWindowName=" + entry.mFocusedWindowName); |
| 851 | |
| 852 | pw.print(prefix); |
| 853 | pw.println(" requestWindowName=" + entry.mRequestWindowName); |
| 854 | |
| 855 | pw.print(prefix); |
| 856 | pw.print(" editorInfo: "); |
| 857 | pw.print(" inputType=" + entry.mEditorInfo.inputType); |
| 858 | pw.print(" privateImeOptions=" + entry.mEditorInfo.privateImeOptions); |
| 859 | pw.println(" fieldId (viewId)=" + entry.mEditorInfo.fieldId); |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 860 | |
| 861 | pw.print(prefix); |
| 862 | pw.println(" focusedWindowSoftInputMode=" + InputMethodDebug.softInputModeToString( |
| 863 | entry.mFocusedWindowSoftInputMode)); |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 868 | /** |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 869 | * Map of generated token to windowToken that is requesting |
| 870 | * {@link InputMethodManager#showSoftInput(View, int)}. |
| 871 | * This map tracks origin of showSoftInput requests. |
| 872 | */ |
| 873 | @GuardedBy("mMethodMap") |
| 874 | private final WeakHashMap<IBinder, IBinder> mShowRequestWindowMap = new WeakHashMap<>(); |
| 875 | |
| 876 | /** |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 877 | * Map of generated token to windowToken that is requesting |
| 878 | * {@link InputMethodManager#hideSoftInputFromWindow(IBinder, int)}. |
| 879 | * This map tracks origin of hideSoftInput requests. |
| 880 | */ |
| 881 | @GuardedBy("mMethodMap") |
| 882 | private final WeakHashMap<IBinder, IBinder> mHideRequestWindowMap = new WeakHashMap<>(); |
| 883 | |
| 884 | /** |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 885 | * A ring buffer to store the history of {@link StartInputInfo}. |
| 886 | */ |
| 887 | private static final class StartInputHistory { |
| 888 | /** |
| 889 | * Entry size for non low-RAM devices. |
| 890 | * |
| 891 | * <p>TODO: Consider to follow what other system services have been doing to manage |
| 892 | * constants (e.g. {@link android.provider.Settings.Global#ACTIVITY_MANAGER_CONSTANTS}).</p> |
| 893 | */ |
| 894 | private final static int ENTRY_SIZE_FOR_HIGH_RAM_DEVICE = 16; |
| 895 | |
| 896 | /** |
| 897 | * Entry size for non low-RAM devices. |
| 898 | * |
| 899 | * <p>TODO: Consider to follow what other system services have been doing to manage |
| 900 | * constants (e.g. {@link android.provider.Settings.Global#ACTIVITY_MANAGER_CONSTANTS}).</p> |
| 901 | */ |
| 902 | private final static int ENTRY_SIZE_FOR_LOW_RAM_DEVICE = 5; |
| 903 | |
| 904 | private static int getEntrySize() { |
| 905 | if (ActivityManager.isLowRamDeviceStatic()) { |
| 906 | return ENTRY_SIZE_FOR_LOW_RAM_DEVICE; |
| 907 | } else { |
| 908 | return ENTRY_SIZE_FOR_HIGH_RAM_DEVICE; |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * Backing store for the ring bugger. |
| 914 | */ |
| 915 | private final Entry[] mEntries = new Entry[getEntrySize()]; |
| 916 | |
| 917 | /** |
| 918 | * An index of {@link #mEntries}, to which next {@link #addEntry(StartInputInfo)} should |
| 919 | * write. |
| 920 | */ |
| 921 | private int mNextIndex = 0; |
| 922 | |
| 923 | /** |
| 924 | * Recyclable entry to store the information in {@link StartInputInfo}. |
| 925 | */ |
| 926 | private static final class Entry { |
| 927 | int mSequenceNumber; |
| 928 | long mTimestamp; |
| 929 | long mWallTime; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 930 | @UserIdInt |
| 931 | int mImeUserId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 932 | @NonNull |
| 933 | String mImeTokenString; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 934 | int mImeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 935 | @NonNull |
| 936 | String mImeId; |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 937 | @StartInputReason |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 938 | int mStartInputReason; |
| 939 | boolean mRestarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 940 | @UserIdInt |
| 941 | int mTargetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 942 | int mTargetDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 943 | @NonNull |
| 944 | String mTargetWindowString; |
| 945 | @NonNull |
| 946 | EditorInfo mEditorInfo; |
Yohei Yukawa | b0c2645 | 2018-10-21 10:42:52 -0700 | [diff] [blame] | 947 | @SoftInputModeFlags |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 948 | int mTargetWindowSoftInputMode; |
| 949 | int mClientBindSequenceNumber; |
| 950 | |
| 951 | Entry(@NonNull StartInputInfo original) { |
| 952 | set(original); |
| 953 | } |
| 954 | |
| 955 | void set(@NonNull StartInputInfo original) { |
| 956 | mSequenceNumber = original.mSequenceNumber; |
| 957 | mTimestamp = original.mTimestamp; |
| 958 | mWallTime = original.mWallTime; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 959 | mImeUserId = original.mImeUserId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 960 | // Intentionally convert to String so as not to keep a strong reference to a Binder |
| 961 | // object. |
| 962 | mImeTokenString = String.valueOf(original.mImeToken); |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 963 | mImeDisplayId = original.mImeDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 964 | mImeId = original.mImeId; |
| 965 | mStartInputReason = original.mStartInputReason; |
| 966 | mRestarting = original.mRestarting; |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 967 | mTargetUserId = original.mTargetUserId; |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 968 | mTargetDisplayId = original.mTargetDisplayId; |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 969 | // Intentionally convert to String so as not to keep a strong reference to a Binder |
| 970 | // object. |
| 971 | mTargetWindowString = String.valueOf(original.mTargetWindow); |
| 972 | mEditorInfo = original.mEditorInfo; |
| 973 | mTargetWindowSoftInputMode = original.mTargetWindowSoftInputMode; |
| 974 | mClientBindSequenceNumber = original.mClientBindSequenceNumber; |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | /** |
| 979 | * Add a new entry and discard the oldest entry as needed. |
| 980 | * @param info {@lin StartInputInfo} to be added. |
| 981 | */ |
| 982 | void addEntry(@NonNull StartInputInfo info) { |
| 983 | final int index = mNextIndex; |
| 984 | if (mEntries[index] == null) { |
| 985 | mEntries[index] = new Entry(info); |
| 986 | } else { |
| 987 | mEntries[index].set(info); |
| 988 | } |
| 989 | mNextIndex = (mNextIndex + 1) % mEntries.length; |
| 990 | } |
| 991 | |
| 992 | void dump(@NonNull PrintWriter pw, @NonNull String prefix) { |
| 993 | final SimpleDateFormat dataFormat = |
| 994 | new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US); |
| 995 | |
| 996 | for (int i = 0; i < mEntries.length; ++i) { |
| 997 | final Entry entry = mEntries[(i + mNextIndex) % mEntries.length]; |
| 998 | if (entry == null) { |
| 999 | continue; |
| 1000 | } |
| 1001 | pw.print(prefix); |
| 1002 | pw.println("StartInput #" + entry.mSequenceNumber + ":"); |
| 1003 | |
| 1004 | pw.print(prefix); |
| 1005 | pw.println(" time=" + dataFormat.format(new Date(entry.mWallTime)) |
| 1006 | + " (timestamp=" + entry.mTimestamp + ")" |
| 1007 | + " reason=" |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 1008 | + InputMethodDebug.startInputReasonToString(entry.mStartInputReason) |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 1009 | + " restarting=" + entry.mRestarting); |
| 1010 | |
| 1011 | pw.print(prefix); |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 1012 | pw.print(" imeToken=" + entry.mImeTokenString + " [" + entry.mImeId + "]"); |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 1013 | pw.print(" imeUserId=" + entry.mImeUserId); |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 1014 | pw.println(" imeDisplayId=" + entry.mImeDisplayId); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 1015 | |
| 1016 | pw.print(prefix); |
| 1017 | pw.println(" targetWin=" + entry.mTargetWindowString |
| 1018 | + " [" + entry.mEditorInfo.packageName + "]" |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 1019 | + " targetUserId=" + entry.mTargetUserId |
Yohei Yukawa | 557afbb | 2019-02-12 02:01:00 -0800 | [diff] [blame] | 1020 | + " targetDisplayId=" + entry.mTargetDisplayId |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 1021 | + " clientBindSeq=" + entry.mClientBindSequenceNumber); |
| 1022 | |
| 1023 | pw.print(prefix); |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 1024 | pw.println(" softInputMode=" + InputMethodDebug.softInputModeToString( |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 1025 | entry.mTargetWindowSoftInputMode)); |
| 1026 | |
| 1027 | pw.print(prefix); |
| 1028 | pw.println(" inputType=0x" + Integer.toHexString(entry.mEditorInfo.inputType) |
| 1029 | + " imeOptions=0x" + Integer.toHexString(entry.mEditorInfo.imeOptions) |
| 1030 | + " fieldId=0x" + Integer.toHexString(entry.mEditorInfo.fieldId) |
| 1031 | + " fieldName=" + entry.mEditorInfo.fieldName |
| 1032 | + " actionId=" + entry.mEditorInfo.actionId |
| 1033 | + " actionLabel=" + entry.mEditorInfo.actionLabel); |
| 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | @GuardedBy("mMethodMap") |
| 1039 | @NonNull |
| 1040 | private final StartInputHistory mStartInputHistory = new StartInputHistory(); |
| 1041 | |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 1042 | @GuardedBy("mMethodMap") |
| 1043 | @NonNull |
| 1044 | private final SoftInputShowHideHistory mSoftInputShowHideHistory = |
| 1045 | new SoftInputShowHideHistory(); |
| 1046 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | class SettingsObserver extends ContentObserver { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1048 | int mUserId; |
| 1049 | boolean mRegistered = false; |
Yohei Yukawa | 7b574cb | 2016-03-16 17:22:22 -0700 | [diff] [blame] | 1050 | @NonNull |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1051 | String mLastEnabled = ""; |
| 1052 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1053 | /** |
| 1054 | * <em>This constructor must be called within the lock.</em> |
| 1055 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | SettingsObserver(Handler handler) { |
| 1057 | super(handler); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1060 | public void registerContentObserverLocked(@UserIdInt int userId) { |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1061 | if (mRegistered && mUserId == userId) { |
| 1062 | return; |
| 1063 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1064 | ContentResolver resolver = mContext.getContentResolver(); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1065 | if (mRegistered) { |
| 1066 | mContext.getContentResolver().unregisterContentObserver(this); |
| 1067 | mRegistered = false; |
| 1068 | } |
| 1069 | if (mUserId != userId) { |
| 1070 | mLastEnabled = ""; |
| 1071 | mUserId = userId; |
| 1072 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1073 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1074 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, userId); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1075 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1076 | Settings.Secure.ENABLED_INPUT_METHODS), false, this, userId); |
satok | b6109bb | 2011-02-03 22:24:54 +0900 | [diff] [blame] | 1077 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1078 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this, userId); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1079 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1080 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD), false, this, userId); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1081 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 1082 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE), false, this, userId); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1083 | mRegistered = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1085 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1086 | @Override public void onChange(boolean selfChange, Uri uri) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1087 | final Uri showImeUri = Settings.Secure.getUriFor( |
| 1088 | Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD); |
| 1089 | final Uri accessibilityRequestingNoImeUri = Settings.Secure.getUriFor( |
| 1090 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | synchronized (mMethodMap) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1092 | if (showImeUri.equals(uri)) { |
| 1093 | updateKeyboardFromSettingsLocked(); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1094 | } else if (accessibilityRequestingNoImeUri.equals(uri)) { |
Phil Weaver | 03a65b0 | 2018-07-19 16:07:57 -0700 | [diff] [blame] | 1095 | final int accessibilitySoftKeyboardSetting = Settings.Secure.getIntForUser( |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1096 | mContext.getContentResolver(), |
Phil Weaver | 03a65b0 | 2018-07-19 16:07:57 -0700 | [diff] [blame] | 1097 | Settings.Secure.ACCESSIBILITY_SOFT_KEYBOARD_MODE, 0, mUserId); |
| 1098 | mAccessibilityRequestingNoSoftKeyboard = |
| 1099 | (accessibilitySoftKeyboardSetting & AccessibilityService.SHOW_MODE_MASK) |
| 1100 | == AccessibilityService.SHOW_MODE_HIDDEN; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1101 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 1102 | final boolean showRequested = mShowRequested; |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 1103 | hideCurrentInputLocked(mCurFocusedWindow, 0, null, |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 1104 | SoftInputShowHideReason.HIDE_SETTINGS_ON_CHANGE); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1105 | mShowRequested = showRequested; |
| 1106 | } else if (mShowRequested) { |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 1107 | showCurrentInputLocked(mCurFocusedWindow, |
| 1108 | InputMethodManager.SHOW_IMPLICIT, null, |
| 1109 | SoftInputShowHideReason.SHOW_SETTINGS_ON_CHANGE); |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1110 | } |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1111 | } else { |
| 1112 | boolean enabledChanged = false; |
| 1113 | String newEnabled = mSettings.getEnabledInputMethodsStr(); |
| 1114 | if (!mLastEnabled.equals(newEnabled)) { |
| 1115 | mLastEnabled = newEnabled; |
| 1116 | enabledChanged = true; |
| 1117 | } |
| 1118 | updateInputMethodsFromSettingsLocked(enabledChanged); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1119 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1120 | } |
| 1121 | } |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1122 | |
| 1123 | @Override |
| 1124 | public String toString() { |
| 1125 | return "SettingsObserver{mUserId=" + mUserId + " mRegistered=" + mRegistered |
| 1126 | + " mLastEnabled=" + mLastEnabled + "}"; |
| 1127 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1129 | |
Yohei Yukawa | 0ec0800 | 2019-03-08 10:48:26 -0800 | [diff] [blame] | 1130 | /** |
| 1131 | * {@link BroadcastReceiver} that is intended to listen to broadcasts sent to the system user |
| 1132 | * only. |
| 1133 | */ |
| 1134 | private final class ImmsBroadcastReceiverForSystemUser extends BroadcastReceiver { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1135 | @Override |
| 1136 | public void onReceive(Context context, Intent intent) { |
| 1137 | final String action = intent.getAction(); |
Yohei Yukawa | 4225c7d | 2019-03-08 00:06:11 -0800 | [diff] [blame] | 1138 | if (Intent.ACTION_USER_ADDED.equals(action) |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 1139 | || Intent.ACTION_USER_REMOVED.equals(action)) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1140 | updateCurrentProfileIds(); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 1141 | return; |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1142 | } else if (Intent.ACTION_LOCALE_CHANGED.equals(action)) { |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1143 | onActionLocaleChanged(); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1144 | } else if (ACTION_SHOW_INPUT_METHOD_PICKER.equals(action)) { |
| 1145 | // ACTION_SHOW_INPUT_METHOD_PICKER action is a protected-broadcast and it is |
| 1146 | // guaranteed to be send only from the system, so that there is no need for extra |
| 1147 | // security check such as |
| 1148 | // {@link #canShowInputMethodPickerLocked(IInputMethodClient)}. |
| 1149 | mHandler.obtainMessage( |
| 1150 | MSG_SHOW_IM_SUBTYPE_PICKER, |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 1151 | // TODO(b/120076400): Design and implement IME switcher for heterogeneous |
| 1152 | // navbar configuration. |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1153 | InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES, |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 1154 | DEFAULT_DISPLAY).sendToTarget(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1155 | } else { |
| 1156 | Slog.w(TAG, "Unexpected intent " + intent); |
| 1157 | } |
| 1158 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1160 | |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1161 | /** |
Yohei Yukawa | 0ec0800 | 2019-03-08 10:48:26 -0800 | [diff] [blame] | 1162 | * {@link BroadcastReceiver} that is intended to listen to broadcasts sent to all the users. |
| 1163 | */ |
| 1164 | private final class ImmsBroadcastReceiverForAllUsers extends BroadcastReceiver { |
| 1165 | @Override |
| 1166 | public void onReceive(Context context, Intent intent) { |
| 1167 | final String action = intent.getAction(); |
| 1168 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { |
| 1169 | final PendingResult pendingResult = getPendingResult(); |
| 1170 | if (pendingResult == null) { |
| 1171 | return; |
| 1172 | } |
| 1173 | // sender userId can be a real user ID or USER_ALL. |
| 1174 | final int senderUserId = pendingResult.getSendingUserId(); |
| 1175 | if (senderUserId != UserHandle.USER_ALL) { |
Tarandeep Singh | cf5ff82 | 2019-07-08 14:06:27 -0700 | [diff] [blame] | 1176 | if (senderUserId != mSettings.getCurrentUserId()) { |
Yohei Yukawa | 0ec0800 | 2019-03-08 10:48:26 -0800 | [diff] [blame] | 1177 | // A background user is trying to hide the dialog. Ignore. |
| 1178 | return; |
| 1179 | } |
| 1180 | } |
| 1181 | hideInputMethodMenu(); |
| 1182 | } else { |
| 1183 | Slog.w(TAG, "Unexpected intent " + intent); |
| 1184 | } |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | /** |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1189 | * Handles {@link Intent#ACTION_LOCALE_CHANGED}. |
| 1190 | * |
| 1191 | * <p>Note: For historical reasons, {@link Intent#ACTION_LOCALE_CHANGED} has been sent to all |
| 1192 | * the users. We should ignore this event if this is about any background user's locale.</p> |
| 1193 | * |
| 1194 | * <p>Caution: This method must not be called when system is not ready.</p> |
| 1195 | */ |
| 1196 | void onActionLocaleChanged() { |
| 1197 | synchronized (mMethodMap) { |
| 1198 | final LocaleList possibleNewLocale = mRes.getConfiguration().getLocales(); |
| 1199 | if (possibleNewLocale != null && possibleNewLocale.equals(mLastSystemLocales)) { |
| 1200 | return; |
| 1201 | } |
| 1202 | buildInputMethodListLocked(true); |
| 1203 | // If the locale is changed, needs to reset the default ime |
| 1204 | resetDefaultImeLocked(mContext); |
| 1205 | updateFromSettingsLocked(true); |
| 1206 | mLastSystemLocales = possibleNewLocale; |
| 1207 | } |
| 1208 | } |
| 1209 | |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1210 | final class MyPackageMonitor extends PackageMonitor { |
| 1211 | /** |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1212 | * Package names that are known to contain {@link InputMethodService}. |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1213 | * |
| 1214 | * <p>No need to include packages because of direct-boot unaware IMEs since we always rescan |
| 1215 | * all the packages when the user is unlocked, and direct-boot awareness will not be changed |
| 1216 | * dynamically unless the entire package is updated, which also always triggers package |
| 1217 | * rescanning.</p> |
| 1218 | */ |
| 1219 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1220 | final private ArraySet<String> mKnownImePackageNames = new ArraySet<>(); |
| 1221 | |
| 1222 | /** |
| 1223 | * Packages that are appeared, disappeared, or modified for whatever reason. |
| 1224 | * |
| 1225 | * <p>Note: For now we intentionally use {@link ArrayList} instead of {@link ArraySet} |
| 1226 | * because 1) the number of elements is almost always 1 or so, and 2) we do not care |
| 1227 | * duplicate elements for our use case.</p> |
| 1228 | * |
| 1229 | * <p>This object must be accessed only from callback methods in {@link PackageMonitor}, |
| 1230 | * which should be bound to {@link #getRegisteredHandler()}.</p> |
| 1231 | */ |
| 1232 | private final ArrayList<String> mChangedPackages = new ArrayList<>(); |
| 1233 | |
| 1234 | /** |
| 1235 | * {@code true} if one or more packages that contain {@link InputMethodService} appeared. |
| 1236 | * |
| 1237 | * <p>This field must be accessed only from callback methods in {@link PackageMonitor}, |
| 1238 | * which should be bound to {@link #getRegisteredHandler()}.</p> |
| 1239 | */ |
| 1240 | private boolean mImePackageAppeared = false; |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1241 | |
| 1242 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1243 | void clearKnownImePackageNamesLocked() { |
| 1244 | mKnownImePackageNames.clear(); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1248 | final void addKnownImePackageNameLocked(@NonNull String packageName) { |
| 1249 | mKnownImePackageNames.add(packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1250 | } |
| 1251 | |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1252 | @GuardedBy("mMethodMap") |
| 1253 | private boolean isChangingPackagesOfCurrentUserLocked() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1254 | final int userId = getChangingUserId(); |
| 1255 | final boolean retval = userId == mSettings.getCurrentUserId(); |
| 1256 | if (DEBUG) { |
satok | 81f8b7c | 2012-12-04 20:42:56 +0900 | [diff] [blame] | 1257 | if (!retval) { |
| 1258 | Slog.d(TAG, "--- ignore this call back from a background user: " + userId); |
| 1259 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1260 | } |
| 1261 | return retval; |
| 1262 | } |
| 1263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1264 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1265 | 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] | 1266 | synchronized (mMethodMap) { |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1267 | if (!isChangingPackagesOfCurrentUserLocked()) { |
| 1268 | return false; |
| 1269 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1270 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | final int N = mMethodList.size(); |
| 1272 | if (curInputMethodId != null) { |
| 1273 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1274 | InputMethodInfo imi = mMethodList.get(i); |
| 1275 | if (imi.getId().equals(curInputMethodId)) { |
| 1276 | for (String pkg : packages) { |
| 1277 | if (imi.getPackageName().equals(pkg)) { |
| 1278 | if (!doit) { |
| 1279 | return true; |
| 1280 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1281 | resetSelectedInputMethodAndSubtypeLocked(""); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1282 | chooseNewDefaultIMELocked(); |
| 1283 | return true; |
| 1284 | } |
| 1285 | } |
| 1286 | } |
| 1287 | } |
| 1288 | } |
| 1289 | } |
| 1290 | return false; |
| 1291 | } |
| 1292 | |
| 1293 | @Override |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1294 | public void onBeginPackageChanges() { |
| 1295 | clearPackageChangeState(); |
| 1296 | } |
| 1297 | |
| 1298 | @Override |
| 1299 | public void onPackageAppeared(String packageName, int reason) { |
| 1300 | if (!mImePackageAppeared) { |
| 1301 | final PackageManager pm = mContext.getPackageManager(); |
| 1302 | final List<ResolveInfo> services = pm.queryIntentServicesAsUser( |
| 1303 | new Intent(InputMethod.SERVICE_INTERFACE).setPackage(packageName), |
Yohei Yukawa | 5ec1fce | 2018-12-17 07:56:14 -0800 | [diff] [blame] | 1304 | PackageManager.MATCH_DISABLED_COMPONENTS, getChangingUserId()); |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1305 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1306 | if (!services.isEmpty()) { |
| 1307 | mImePackageAppeared = true; |
| 1308 | } |
| 1309 | } |
| 1310 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1311 | mChangedPackages.add(packageName); |
| 1312 | } |
| 1313 | |
| 1314 | @Override |
| 1315 | public void onPackageDisappeared(String packageName, int reason) { |
| 1316 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1317 | mChangedPackages.add(packageName); |
| 1318 | } |
| 1319 | |
| 1320 | @Override |
| 1321 | public void onPackageModified(String packageName) { |
| 1322 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1323 | mChangedPackages.add(packageName); |
| 1324 | } |
| 1325 | |
| 1326 | @Override |
| 1327 | public void onPackagesSuspended(String[] packages) { |
| 1328 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1329 | for (String packageName : packages) { |
| 1330 | mChangedPackages.add(packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | @Override |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1335 | public void onPackagesUnsuspended(String[] packages) { |
| 1336 | // No need to lock this because we access it only on getRegisteredHandler(). |
| 1337 | for (String packageName : packages) { |
| 1338 | mChangedPackages.add(packageName); |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | @Override |
| 1343 | public void onFinishPackageChanges() { |
| 1344 | onFinishPackageChangesInternal(); |
| 1345 | clearPackageChangeState(); |
| 1346 | } |
| 1347 | |
| 1348 | private void clearPackageChangeState() { |
| 1349 | // No need to lock them because we access these fields only on getRegisteredHandler(). |
| 1350 | mChangedPackages.clear(); |
| 1351 | mImePackageAppeared = false; |
| 1352 | } |
| 1353 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1354 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1355 | private boolean shouldRebuildInputMethodListLocked() { |
| 1356 | // This method is guaranteed to be called only by getRegisteredHandler(). |
| 1357 | |
| 1358 | // If there is any new package that contains at least one IME, then rebuilt the list |
| 1359 | // of IMEs. |
| 1360 | if (mImePackageAppeared) { |
| 1361 | return true; |
| 1362 | } |
| 1363 | |
| 1364 | // Otherwise, check if mKnownImePackageNames and mChangedPackages have any intersection. |
| 1365 | // TODO: Consider to create a utility method to do the following test. List.retainAll() |
| 1366 | // is an option, but it may still do some extra operations that we do not need here. |
| 1367 | final int N = mChangedPackages.size(); |
| 1368 | for (int i = 0; i < N; ++i) { |
| 1369 | final String packageName = mChangedPackages.get(i); |
| 1370 | if (mKnownImePackageNames.contains(packageName)) { |
| 1371 | return true; |
| 1372 | } |
| 1373 | } |
| 1374 | return false; |
| 1375 | } |
| 1376 | |
| 1377 | private void onFinishPackageChangesInternal() { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1378 | synchronized (mMethodMap) { |
Yohei Yukawa | 278f2ab | 2017-02-14 19:51:33 -0800 | [diff] [blame] | 1379 | if (!isChangingPackagesOfCurrentUserLocked()) { |
| 1380 | return; |
| 1381 | } |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 1382 | if (!shouldRebuildInputMethodListLocked()) { |
| 1383 | return; |
| 1384 | } |
| 1385 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1386 | InputMethodInfo curIm = null; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1387 | String curInputMethodId = mSettings.getSelectedInputMethod(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1388 | final int N = mMethodList.size(); |
| 1389 | if (curInputMethodId != null) { |
| 1390 | for (int i=0; i<N; i++) { |
| 1391 | InputMethodInfo imi = mMethodList.get(i); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1392 | final String imiId = imi.getId(); |
| 1393 | if (imiId.equals(curInputMethodId)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1394 | curIm = imi; |
| 1395 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1396 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1397 | int change = isPackageDisappearing(imi.getPackageName()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1398 | if (isPackageModified(imi.getPackageName())) { |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 1399 | mAdditionalSubtypeMap.remove(imi.getId()); |
| 1400 | AdditionalSubtypeUtils.save(mAdditionalSubtypeMap, mMethodMap, |
| 1401 | mSettings.getCurrentUserId()); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1402 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1403 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 1404 | || change == PACKAGE_PERMANENT_CHANGE) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1405 | Slog.i(TAG, "Input method uninstalled, disabling: " |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1406 | + imi.getComponent()); |
| 1407 | setInputMethodEnabledLocked(imi.getId(), false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1408 | } |
| 1409 | } |
| 1410 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1411 | |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 1412 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1414 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1415 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1416 | if (curIm != null) { |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 1417 | int change = isPackageDisappearing(curIm.getPackageName()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1418 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 1419 | || change == PACKAGE_PERMANENT_CHANGE) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1420 | ServiceInfo si = null; |
| 1421 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1422 | si = mIPackageManager.getServiceInfo( |
| 1423 | curIm.getComponent(), 0, mSettings.getCurrentUserId()); |
| 1424 | } catch (RemoteException ex) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1425 | } |
| 1426 | if (si == null) { |
| 1427 | // Uh oh, current input method is no longer around! |
| 1428 | // Pick another one... |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1429 | Slog.i(TAG, "Current input method removed: " + curInputMethodId); |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 1430 | updateSystemUiLocked(0 /* vis */, mBackDisposition); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1431 | if (!chooseNewDefaultIMELocked()) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1432 | changed = true; |
| 1433 | curIm = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1434 | Slog.i(TAG, "Unsetting current input method"); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 1435 | resetSelectedInputMethodAndSubtypeLocked(""); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1436 | } |
| 1437 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 1438 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1439 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 1440 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1441 | if (curIm == null) { |
| 1442 | // We currently don't have a default input method... is |
| 1443 | // one now available? |
| 1444 | changed = chooseNewDefaultIMELocked(); |
Yohei Yukawa | 54d512c | 2015-05-19 22:15:02 -0700 | [diff] [blame] | 1445 | } else if (!changed && isPackageModified(curIm.getPackageName())) { |
| 1446 | // Even if the current input method is still available, mCurrentSubtype could |
| 1447 | // be obsolete when the package is modified in practice. |
| 1448 | changed = true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1449 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1450 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1451 | if (changed) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 1452 | updateFromSettingsLocked(false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | } |
| 1454 | } |
| 1455 | } |
| 1456 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1457 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1458 | private static final class MethodCallback extends IInputSessionCallback.Stub { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 1459 | private final InputMethodManagerService mParentIMMS; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1460 | private final IInputMethod mMethod; |
| 1461 | private final InputChannel mChannel; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1462 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1463 | MethodCallback(InputMethodManagerService imms, IInputMethod method, |
| 1464 | InputChannel channel) { |
Jean Chalard | e0d32a6 | 2011-10-20 20:36:07 +0900 | [diff] [blame] | 1465 | mParentIMMS = imms; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1466 | mMethod = method; |
| 1467 | mChannel = channel; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1469 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1470 | @Override |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1471 | public void sessionCreated(IInputMethodSession session) { |
Dianne Hackborn | 6b6b3fd | 2014-03-24 11:27:18 -0700 | [diff] [blame] | 1472 | long ident = Binder.clearCallingIdentity(); |
| 1473 | try { |
| 1474 | mParentIMMS.onSessionCreated(mMethod, session, mChannel); |
| 1475 | } finally { |
| 1476 | Binder.restoreCallingIdentity(ident); |
| 1477 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1478 | } |
| 1479 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1480 | |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1481 | private class HardKeyboardListener |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1482 | implements WindowManagerInternal.OnHardKeyboardStatusChangeListener { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1483 | @Override |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1484 | public void onHardKeyboardStatusChange(boolean available) { |
| 1485 | mHandler.sendMessage(mHandler.obtainMessage(MSG_HARD_KEYBOARD_SWITCH_CHANGED, |
| 1486 | available ? 1 : 0)); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1487 | } |
| 1488 | |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1489 | public void handleHardKeyboardStatusChange(boolean available) { |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1490 | if (DEBUG) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 1491 | Slog.w(TAG, "HardKeyboardStatusChanged: available=" + available); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1492 | } |
| 1493 | synchronized(mMethodMap) { |
| 1494 | if (mSwitchingDialog != null && mSwitchingDialogTitleView != null |
| 1495 | && mSwitchingDialog.isShowing()) { |
| 1496 | mSwitchingDialogTitleView.findViewById( |
| 1497 | com.android.internal.R.id.hard_keyboard_section).setVisibility( |
| 1498 | available ? View.VISIBLE : View.GONE); |
| 1499 | } |
| 1500 | } |
| 1501 | } |
| 1502 | } |
| 1503 | |
Yohei Yukawa | d277d69 | 2020-02-19 17:12:17 -0800 | [diff] [blame] | 1504 | private static final class UserSwitchHandlerTask implements Runnable { |
| 1505 | final InputMethodManagerService mService; |
| 1506 | |
| 1507 | @UserIdInt |
| 1508 | final int mToUserId; |
| 1509 | |
| 1510 | @Nullable |
| 1511 | IInputMethodClient mClientToBeReset; |
| 1512 | |
| 1513 | UserSwitchHandlerTask(InputMethodManagerService service, @UserIdInt int toUserId, |
| 1514 | @Nullable IInputMethodClient clientToBeReset) { |
| 1515 | mService = service; |
| 1516 | mToUserId = toUserId; |
| 1517 | mClientToBeReset = clientToBeReset; |
| 1518 | } |
| 1519 | |
| 1520 | @Override |
| 1521 | public void run() { |
| 1522 | synchronized (mService.mMethodMap) { |
| 1523 | if (mService.mUserSwitchHandlerTask != this) { |
| 1524 | // This task was already canceled before it is handled here. So do nothing. |
| 1525 | return; |
| 1526 | } |
| 1527 | mService.switchUserOnHandlerLocked(mService.mUserSwitchHandlerTask.mToUserId, |
| 1528 | mClientToBeReset); |
| 1529 | mService.mUserSwitchHandlerTask = null; |
| 1530 | } |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | /** |
| 1535 | * When non-{@code null}, this represents pending user-switch task, which is to be executed as |
| 1536 | * a handler callback. This needs to be set and unset only within the lock. |
| 1537 | */ |
| 1538 | @Nullable |
| 1539 | @GuardedBy("mMethodMap") |
| 1540 | private UserSwitchHandlerTask mUserSwitchHandlerTask; |
| 1541 | |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1542 | public static final class Lifecycle extends SystemService { |
| 1543 | private InputMethodManagerService mService; |
| 1544 | |
| 1545 | public Lifecycle(Context context) { |
| 1546 | super(context); |
| 1547 | mService = new InputMethodManagerService(context); |
| 1548 | } |
| 1549 | |
| 1550 | @Override |
| 1551 | public void onStart() { |
| 1552 | LocalServices.addService(InputMethodManagerInternal.class, |
Yohei Yukawa | fffc0e5 | 2018-09-04 13:24:00 -0700 | [diff] [blame] | 1553 | new LocalServiceImpl(mService)); |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1554 | publishBinderService(Context.INPUT_METHOD_SERVICE, mService); |
| 1555 | } |
| 1556 | |
| 1557 | @Override |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1558 | public void onSwitchUser(@UserIdInt int userHandle) { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1559 | // Called on ActivityManager thread. |
Yohei Yukawa | d277d69 | 2020-02-19 17:12:17 -0800 | [diff] [blame] | 1560 | synchronized (mService.mMethodMap) { |
| 1561 | mService.scheduleSwitchUserTaskLocked(userHandle, null /* clientToBeReset */); |
| 1562 | } |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | @Override |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1566 | public void onBootPhase(int phase) { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1567 | // Called on ActivityManager thread. |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1568 | // TODO: Dispatch this to a worker thread as needed. |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1569 | if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) { |
| 1570 | StatusBarManagerService statusBarService = (StatusBarManagerService) ServiceManager |
| 1571 | .getService(Context.STATUS_BAR_SERVICE); |
| 1572 | mService.systemRunning(statusBarService); |
| 1573 | } |
| 1574 | } |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1575 | |
| 1576 | @Override |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 1577 | public void onUnlockUser(final @UserIdInt int userHandle) { |
| 1578 | // Called on ActivityManager thread. |
| 1579 | mService.mHandler.sendMessage(mService.mHandler.obtainMessage(MSG_SYSTEM_UNLOCK_USER, |
Fyodor Kupolov | 0f57cce | 2016-09-09 10:36:30 -0700 | [diff] [blame] | 1580 | userHandle /* arg1 */, 0 /* arg2 */)); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1581 | } |
| 1582 | } |
| 1583 | |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1584 | void onUnlockUser(@UserIdInt int userId) { |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1585 | synchronized(mMethodMap) { |
| 1586 | final int currentUserId = mSettings.getCurrentUserId(); |
| 1587 | if (DEBUG) { |
| 1588 | Slog.d(TAG, "onUnlockUser: userId=" + userId + " curUserId=" + currentUserId); |
| 1589 | } |
| 1590 | if (userId != currentUserId) { |
| 1591 | return; |
| 1592 | } |
| 1593 | mSettings.switchCurrentUser(currentUserId, !mSystemReady); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1594 | if (mSystemReady) { |
| 1595 | // We need to rebuild IMEs. |
| 1596 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
| 1597 | updateInputMethodsFromSettingsLocked(true /* enabledChanged */); |
| 1598 | } |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1599 | } |
Fyodor Kupolov | 1e33dc8 | 2016-01-21 12:02:58 -0800 | [diff] [blame] | 1600 | } |
| 1601 | |
Yohei Yukawa | d277d69 | 2020-02-19 17:12:17 -0800 | [diff] [blame] | 1602 | @GuardedBy("mMethodMap") |
| 1603 | void scheduleSwitchUserTaskLocked(@UserIdInt int userId, |
| 1604 | @Nullable IInputMethodClient clientToBeReset) { |
| 1605 | if (mUserSwitchHandlerTask != null) { |
| 1606 | if (mUserSwitchHandlerTask.mToUserId == userId) { |
| 1607 | mUserSwitchHandlerTask.mClientToBeReset = clientToBeReset; |
| 1608 | return; |
| 1609 | } |
| 1610 | mHandler.removeCallbacks(mUserSwitchHandlerTask); |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1611 | } |
Yohei Yukawa | d277d69 | 2020-02-19 17:12:17 -0800 | [diff] [blame] | 1612 | final UserSwitchHandlerTask task = new UserSwitchHandlerTask(this, userId, |
| 1613 | clientToBeReset); |
| 1614 | mUserSwitchHandlerTask = task; |
| 1615 | mHandler.post(task); |
Yohei Yukawa | 7b18aec | 2016-03-07 13:04:32 -0800 | [diff] [blame] | 1616 | } |
| 1617 | |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1618 | public InputMethodManagerService(Context context) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1619 | mIPackageManager = AppGlobals.getPackageManager(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1620 | mContext = context; |
Dianne Hackborn | 7d3a5bc | 2010-11-29 22:52:12 -0800 | [diff] [blame] | 1621 | mRes = context.getResources(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1622 | mHandler = new Handler(this); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1623 | // Note: SettingsObserver doesn't register observers in its constructor. |
| 1624 | mSettingsObserver = new SettingsObserver(mHandler); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1625 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 1626 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1627 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 1628 | mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 1629 | mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); |
lumark | 9a72d22 | 2019-03-30 18:31:45 +0800 | [diff] [blame] | 1630 | mImeDisplayValidator = displayId -> mWindowManagerInternal.shouldShowIme(displayId); |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 1631 | mCaller = new HandlerCaller(context, null, new HandlerCaller.Callback() { |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1632 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1633 | public void executeMessage(Message msg) { |
| 1634 | handleMessage(msg); |
| 1635 | } |
Mita Yun | ed218c7 | 2012-12-06 17:18:25 -0800 | [diff] [blame] | 1636 | }, true /*asyncHandler*/); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 1637 | mAppOpsManager = mContext.getSystemService(AppOpsManager.class); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1638 | mUserManager = mContext.getSystemService(UserManager.class); |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 1639 | mUserManagerInternal = LocalServices.getService(UserManagerInternal.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1640 | mHardKeyboardListener = new HardKeyboardListener(); |
Dianne Hackborn | 119bbc3 | 2013-03-22 17:27:25 -0700 | [diff] [blame] | 1641 | mHasFeature = context.getPackageManager().hasSystemFeature( |
| 1642 | PackageManager.FEATURE_INPUT_METHODS); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 1643 | mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 1644 | mIsLowRam = ActivityManager.isLowRamDeviceStatic(); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1645 | |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 1646 | Bundle extras = new Bundle(); |
| 1647 | extras.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, true); |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1648 | @ColorInt final int accentColor = mContext.getColor( |
| 1649 | com.android.internal.R.color.system_notification_accent_color); |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 1650 | mImeSwitcherNotification = |
| 1651 | new Notification.Builder(mContext, SystemNotificationChannels.VIRTUAL_KEYBOARD) |
| 1652 | .setSmallIcon(com.android.internal.R.drawable.ic_notification_ime_default) |
| 1653 | .setWhen(0) |
| 1654 | .setOngoing(true) |
| 1655 | .addExtras(extras) |
| 1656 | .setCategory(Notification.CATEGORY_SYSTEM) |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1657 | .setColor(accentColor); |
Daniel Sandler | 590d515 | 2012-06-14 16:10:13 -0400 | [diff] [blame] | 1658 | |
Tadashi G. Takaoka | 01065a5 | 2017-07-19 14:10:24 +0900 | [diff] [blame] | 1659 | Intent intent = new Intent(ACTION_SHOW_INPUT_METHOD_PICKER) |
| 1660 | .setPackage(mContext.getPackageName()); |
satok | 683e238 | 2011-07-12 08:28:52 +0900 | [diff] [blame] | 1661 | mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 1662 | |
| 1663 | mShowOngoingImeSwitcherForPhones = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1664 | |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 1665 | mNotificationShown = false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1666 | int userId = 0; |
| 1667 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1668 | userId = ActivityManager.getService().getCurrentUser().id; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1669 | } catch (RemoteException e) { |
| 1670 | Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e); |
| 1671 | } |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1672 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 1673 | mLastSwitchUserId = userId; |
| 1674 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1675 | // mSettings should be created before buildInputMethodListLocked |
satok | df31ae6 | 2011-01-15 06:19:44 +0900 | [diff] [blame] | 1676 | mSettings = new InputMethodSettings( |
Yohei Yukawa | f927753 | 2019-01-25 02:47:32 -0800 | [diff] [blame] | 1677 | mRes, context.getContentResolver(), mMethodMap, userId, !mSystemReady); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 1678 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1679 | updateCurrentProfileIds(); |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 1680 | AdditionalSubtypeUtils.load(mAdditionalSubtypeMap, userId); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1681 | mSwitchingController = InputMethodSubtypeSwitchingController.createInstanceLocked( |
| 1682 | mSettings, context); |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1683 | } |
| 1684 | |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1685 | private void resetDefaultImeLocked(Context context) { |
| 1686 | // 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] | 1687 | if (mCurMethodId != null && !mMethodMap.get(mCurMethodId).isSystem()) { |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1688 | return; |
| 1689 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1690 | final List<InputMethodInfo> suitableImes = InputMethodUtils.getDefaultEnabledImes( |
Yohei Yukawa | af5cee8 | 2017-01-23 16:17:11 -0800 | [diff] [blame] | 1691 | context, mSettings.getEnabledInputMethodListLocked()); |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1692 | if (suitableImes.isEmpty()) { |
| 1693 | Slog.i(TAG, "No default found"); |
| 1694 | return; |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1695 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1696 | final InputMethodInfo defIm = suitableImes.get(0); |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1697 | if (DEBUG) { |
| 1698 | Slog.i(TAG, "Default found, using " + defIm.getId()); |
| 1699 | } |
Yohei Yukawa | c2393ac | 2016-02-18 00:30:45 -0800 | [diff] [blame] | 1700 | setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false); |
satok | 5b927c43 | 2012-05-01 20:09:34 +0900 | [diff] [blame] | 1701 | } |
| 1702 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1703 | @GuardedBy("mMethodMap") |
Yohei Yukawa | d277d69 | 2020-02-19 17:12:17 -0800 | [diff] [blame] | 1704 | private void switchUserOnHandlerLocked(@UserIdInt int newUserId, |
| 1705 | IInputMethodClient clientToBeReset) { |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1706 | if (DEBUG) Slog.d(TAG, "Switching user stage 1/3. newUserId=" + newUserId |
| 1707 | + " currentUserId=" + mSettings.getCurrentUserId()); |
| 1708 | |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 1709 | // ContentObserver should be registered again when the user is changed |
| 1710 | mSettingsObserver.registerContentObserverLocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1711 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1712 | // If the system is not ready or the device is not yed unlocked by the user, then we use |
| 1713 | // copy-on-write settings. |
| 1714 | final boolean useCopyOnWriteSettings = |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 1715 | !mSystemReady || !mUserManagerInternal.isUserUnlockingOrUnlocked(newUserId); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1716 | mSettings.switchCurrentUser(newUserId, useCopyOnWriteSettings); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1717 | updateCurrentProfileIds(); |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 1718 | // Additional subtypes should be reset when the user is changed |
| 1719 | AdditionalSubtypeUtils.load(mAdditionalSubtypeMap, newUserId); |
Satoshi Kataoka | 7f7535f | 2013-02-18 12:54:16 +0900 | [diff] [blame] | 1720 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1721 | |
| 1722 | if (DEBUG) Slog.d(TAG, "Switching user stage 2/3. newUserId=" + newUserId |
| 1723 | + " defaultImiId=" + defaultImiId); |
| 1724 | |
Satoshi Kataoka | 7c4a2a1 | 2013-02-25 15:25:43 +0900 | [diff] [blame] | 1725 | // For secondary users, the list of enabled IMEs may not have been updated since the |
| 1726 | // callbacks to PackageMonitor are ignored for the secondary user. Here, defaultImiId may |
| 1727 | // not be empty even if the IME has been uninstalled by the primary user. |
| 1728 | // Even in such cases, IMMS works fine because it will find the most applicable |
| 1729 | // IME for that user. |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1730 | final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId); |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1731 | mLastSystemLocales = mRes.getConfiguration().getLocales(); |
| 1732 | |
| 1733 | // TODO: Is it really possible that switchUserLocked() happens before system ready? |
| 1734 | if (mSystemReady) { |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 1735 | hideCurrentInputLocked( |
| 1736 | mCurFocusedWindow, 0, null, SoftInputShowHideReason.HIDE_SWITCH_USER); |
| 1737 | |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 1738 | resetCurrentMethodAndClient(UnbindReason.SWITCH_USER); |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1739 | buildInputMethodListLocked(initialUserSwitch); |
| 1740 | if (TextUtils.isEmpty(mSettings.getSelectedInputMethod())) { |
| 1741 | // This is the first time of the user switch and |
| 1742 | // set the current ime to the proper one. |
| 1743 | resetDefaultImeLocked(mContext); |
| 1744 | } |
| 1745 | updateFromSettingsLocked(true); |
Yohei Yukawa | 0d7aff8 | 2017-02-10 00:40:51 -0800 | [diff] [blame] | 1746 | } |
| 1747 | |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1748 | if (initialUserSwitch) { |
Yohei Yukawa | 094c71f | 2015-06-20 00:41:31 -0700 | [diff] [blame] | 1749 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1750 | mSettings.getEnabledInputMethodListLocked(), newUserId, |
| 1751 | mContext.getBasePackageName()); |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 1752 | } |
Yohei Yukawa | 90bf708 | 2015-06-03 23:50:27 -0700 | [diff] [blame] | 1753 | |
| 1754 | if (DEBUG) Slog.d(TAG, "Switching user stage 3/3. newUserId=" + newUserId |
| 1755 | + " selectedIme=" + mSettings.getSelectedInputMethod()); |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 1756 | |
| 1757 | mLastSwitchUserId = newUserId; |
Yohei Yukawa | d277d69 | 2020-02-19 17:12:17 -0800 | [diff] [blame] | 1758 | |
| 1759 | if (mIsInteractive && clientToBeReset != null) { |
| 1760 | final ClientState cs = mClients.get(clientToBeReset.asBinder()); |
| 1761 | if (cs == null) { |
| 1762 | // The client is already gone. |
| 1763 | return; |
| 1764 | } |
| 1765 | try { |
| 1766 | cs.client.scheduleStartInputIfNecessary(mInFullscreenMode); |
| 1767 | } catch (RemoteException e) { |
| 1768 | } |
| 1769 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1770 | } |
| 1771 | |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1772 | void updateCurrentProfileIds() { |
Fyodor Kupolov | 7f98aa4 | 2016-04-07 14:56:25 -0700 | [diff] [blame] | 1773 | mSettings.setCurrentProfileIds( |
| 1774 | mUserManager.getProfileIdsWithDisabled(mSettings.getCurrentUserId())); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 1775 | } |
| 1776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1777 | @Override |
| 1778 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 1779 | throws RemoteException { |
| 1780 | try { |
| 1781 | return super.onTransact(code, data, reply, flags); |
| 1782 | } catch (RuntimeException e) { |
| 1783 | // The input method manager only throws security exceptions, so let's |
| 1784 | // log all others. |
| 1785 | if (!(e instanceof SecurityException)) { |
Dianne Hackborn | 164371f | 2013-10-01 19:10:13 -0700 | [diff] [blame] | 1786 | Slog.wtf(TAG, "Input Method Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | } |
| 1788 | throw e; |
| 1789 | } |
| 1790 | } |
| 1791 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 1792 | public void systemRunning(StatusBarManagerService statusBar) { |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1793 | synchronized (mMethodMap) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1794 | if (DEBUG) { |
| 1795 | Slog.d(TAG, "--- systemReady"); |
| 1796 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1797 | if (!mSystemReady) { |
| 1798 | mSystemReady = true; |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1799 | mLastSystemLocales = mRes.getConfiguration().getLocales(); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 1800 | final int currentUserId = mSettings.getCurrentUserId(); |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 1801 | mSettings.switchCurrentUser(currentUserId, |
Yohei Yukawa | 4208140 | 2019-01-15 09:57:50 -0800 | [diff] [blame] | 1802 | !mUserManagerInternal.isUserUnlockingOrUnlocked(currentUserId)); |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 1803 | mKeyguardManager = mContext.getSystemService(KeyguardManager.class); |
| 1804 | mNotificationManager = mContext.getSystemService(NotificationManager.class); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 1805 | mStatusBar = statusBar; |
Griff Hazen | 6090c26 | 2016-03-25 08:11:24 -0700 | [diff] [blame] | 1806 | if (mStatusBar != null) { |
| 1807 | mStatusBar.setIconVisibility(mSlotIme, false); |
| 1808 | } |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 1809 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
satok | b858c73 | 2011-07-22 19:54:34 +0900 | [diff] [blame] | 1810 | mShowOngoingImeSwitcherForPhones = mRes.getBoolean( |
| 1811 | com.android.internal.R.bool.show_ongoing_ime_switcher); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1812 | if (mShowOngoingImeSwitcherForPhones) { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 1813 | mWindowManagerInternal.setOnHardKeyboardStatusChangeListener( |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 1814 | mHardKeyboardListener); |
| 1815 | } |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1816 | |
| 1817 | mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true); |
| 1818 | mSettingsObserver.registerContentObserverLocked(currentUserId); |
| 1819 | |
Yohei Yukawa | 0ec0800 | 2019-03-08 10:48:26 -0800 | [diff] [blame] | 1820 | final IntentFilter broadcastFilterForSystemUser = new IntentFilter(); |
| 1821 | broadcastFilterForSystemUser.addAction(Intent.ACTION_USER_ADDED); |
| 1822 | broadcastFilterForSystemUser.addAction(Intent.ACTION_USER_REMOVED); |
| 1823 | broadcastFilterForSystemUser.addAction(Intent.ACTION_LOCALE_CHANGED); |
| 1824 | broadcastFilterForSystemUser.addAction(ACTION_SHOW_INPUT_METHOD_PICKER); |
| 1825 | mContext.registerReceiver(new ImmsBroadcastReceiverForSystemUser(), |
| 1826 | broadcastFilterForSystemUser); |
| 1827 | |
| 1828 | final IntentFilter broadcastFilterForAllUsers = new IntentFilter(); |
| 1829 | broadcastFilterForAllUsers.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 1830 | mContext.registerReceiverAsUser(new ImmsBroadcastReceiverForAllUsers(), |
| 1831 | UserHandle.ALL, broadcastFilterForAllUsers, null, null); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1832 | |
Yohei Yukawa | 1f9a3cb | 2017-10-26 15:00:59 -0700 | [diff] [blame] | 1833 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
| 1834 | final boolean imeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId); |
| 1835 | buildInputMethodListLocked(!imeSelectedOnBoot /* resetDefaultEnabledIme */); |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 1836 | updateFromSettingsLocked(true); |
| 1837 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 1838 | mSettings.getEnabledInputMethodListLocked(), currentUserId, |
| 1839 | mContext.getBasePackageName()); |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 1840 | } |
| 1841 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1842 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1843 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1844 | // --------------------------------------------------------------------------------------- |
| 1845 | // Check whether or not this is a valid IPC. Assumes an IPC is valid when either |
| 1846 | // 1) it comes from the system process |
| 1847 | // 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] | 1848 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 1849 | private boolean calledFromValidUserLocked() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1850 | final int uid = Binder.getCallingUid(); |
| 1851 | final int userId = UserHandle.getUserId(uid); |
| 1852 | if (DEBUG) { |
| 1853 | Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? " |
| 1854 | + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID |
| 1855 | + " calling userId = " + userId + ", foreground user id = " |
Satoshi Kataoka | 87c2914 | 2013-07-31 23:11:54 +0900 | [diff] [blame] | 1856 | + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid() |
| 1857 | + InputMethodUtils.getApiCallStack()); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1858 | } |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 1859 | if (uid == Process.SYSTEM_UID) { |
| 1860 | return true; |
| 1861 | } |
| 1862 | if (userId == mSettings.getCurrentUserId()) { |
| 1863 | return true; |
| 1864 | } |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1865 | |
| 1866 | // Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the |
| 1867 | // foreground user, not for the user of that process. Accordingly InputMethodManagerService |
| 1868 | // must not manage background users' states in any functions. |
| 1869 | // Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded |
| 1870 | // by a token. |
| 1871 | if (mContext.checkCallingOrSelfPermission( |
| 1872 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
| 1873 | == PackageManager.PERMISSION_GRANTED) { |
| 1874 | if (DEBUG) { |
| 1875 | Slog.d(TAG, "--- Access granted because the calling process has " |
| 1876 | + "the INTERACT_ACROSS_USERS_FULL permission"); |
| 1877 | } |
| 1878 | return true; |
| 1879 | } |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1880 | // 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] | 1881 | Slog.w(TAG, "--- IPC called from background users. Ignore. callers=" |
| 1882 | + Debug.getCallers(10)); |
Satoshi Kataoka | 135e5fb | 2012-09-28 18:25:06 +0900 | [diff] [blame] | 1883 | return false; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1884 | } |
| 1885 | |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 1886 | |
| 1887 | /** |
| 1888 | * Returns true iff the caller is identified to be the current input method with the token. |
| 1889 | * @param token The window token given to the input method when it was started. |
| 1890 | * @return true if and only if non-null valid token is specified. |
| 1891 | */ |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 1892 | @GuardedBy("mMethodMap") |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 1893 | private boolean calledWithValidTokenLocked(@NonNull IBinder token) { |
| 1894 | if (token == null) { |
| 1895 | throw new InvalidParameterException("token must not be null."); |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1896 | } |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 1897 | if (token != mCurToken) { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 1898 | Slog.e(TAG, "Ignoring " + Debug.getCaller() + " due to an invalid token." |
| 1899 | + " uid:" + Binder.getCallingUid() + " token:" + token); |
Yohei Yukawa | 22c97be | 2014-06-04 19:43:36 +0900 | [diff] [blame] | 1900 | return false; |
| 1901 | } |
| 1902 | return true; |
| 1903 | } |
| 1904 | |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 1905 | @GuardedBy("mMethodMap") |
| 1906 | private boolean bindCurrentInputMethodServiceLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1907 | Intent service, ServiceConnection conn, int flags) { |
| 1908 | if (service == null || conn == null) { |
| 1909 | Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn); |
| 1910 | return false; |
| 1911 | } |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 1912 | return mContext.bindServiceAsUser(service, conn, flags, |
| 1913 | new UserHandle(mSettings.getCurrentUserId())); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 1914 | } |
| 1915 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1916 | @Override |
Yohei Yukawa | d20eef8 | 2019-02-05 10:45:32 -0800 | [diff] [blame] | 1917 | public List<InputMethodInfo> getInputMethodList(@UserIdInt int userId) { |
| 1918 | if (UserHandle.getCallingUserId() != userId) { |
| 1919 | mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); |
| 1920 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1921 | synchronized (mMethodMap) { |
Yohei Yukawa | d20eef8 | 2019-02-05 10:45:32 -0800 | [diff] [blame] | 1922 | final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId, |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1923 | mSettings.getCurrentUserId(), null); |
| 1924 | if (resolvedUserIds.length != 1) { |
| 1925 | return Collections.emptyList(); |
| 1926 | } |
| 1927 | final long ident = Binder.clearCallingIdentity(); |
| 1928 | try { |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 1929 | return getInputMethodListLocked(resolvedUserIds[0]); |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1930 | } finally { |
| 1931 | Binder.restoreCallingIdentity(ident); |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 1932 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1933 | } |
| 1934 | } |
| 1935 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 1936 | @Override |
Yohei Yukawa | 1fb13c5 | 2019-02-05 07:55:28 -0800 | [diff] [blame] | 1937 | public List<InputMethodInfo> getEnabledInputMethodList(@UserIdInt int userId) { |
| 1938 | if (UserHandle.getCallingUserId() != userId) { |
| 1939 | mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); |
| 1940 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1941 | synchronized (mMethodMap) { |
Yohei Yukawa | 1fb13c5 | 2019-02-05 07:55:28 -0800 | [diff] [blame] | 1942 | final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId, |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1943 | mSettings.getCurrentUserId(), null); |
| 1944 | if (resolvedUserIds.length != 1) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 1945 | return Collections.emptyList(); |
| 1946 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1947 | final long ident = Binder.clearCallingIdentity(); |
| 1948 | try { |
| 1949 | return getEnabledInputMethodListLocked(resolvedUserIds[0]); |
| 1950 | } finally { |
| 1951 | Binder.restoreCallingIdentity(ident); |
| 1952 | } |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 1957 | private List<InputMethodInfo> getInputMethodListLocked(@UserIdInt int userId) { |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1958 | final ArrayList<InputMethodInfo> methodList; |
| 1959 | if (userId == mSettings.getCurrentUserId()) { |
| 1960 | // Create a copy. |
| 1961 | methodList = new ArrayList<>(mMethodList); |
| 1962 | } else { |
| 1963 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 1964 | methodList = new ArrayList<>(); |
| 1965 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 1966 | new ArrayMap<>(); |
| 1967 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 1968 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap, |
| 1969 | methodList); |
| 1970 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1971 | return methodList; |
| 1972 | } |
| 1973 | |
| 1974 | @GuardedBy("mMethodMap") |
| 1975 | private List<InputMethodInfo> getEnabledInputMethodListLocked(@UserIdInt int userId) { |
| 1976 | if (userId == mSettings.getCurrentUserId()) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 1977 | return mSettings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1978 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1979 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 1980 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 1981 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 1982 | new ArrayMap<>(); |
| 1983 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 1984 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap, |
| 1985 | methodList); |
| 1986 | final InputMethodSettings settings = new InputMethodSettings(mContext.getResources(), |
Yohei Yukawa | f927753 | 2019-01-25 02:47:32 -0800 | [diff] [blame] | 1987 | mContext.getContentResolver(), methodMap, userId, true); |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 1988 | return settings.getEnabledInputMethodListLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1989 | } |
| 1990 | |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 1991 | @GuardedBy("mMethodMap") |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 1992 | private void onCreateInlineSuggestionsRequestLocked(@UserIdInt int userId, |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 1993 | InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback callback) { |
Adam He | 7bc8f60 | 2019-12-12 17:00:34 -0800 | [diff] [blame] | 1994 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 1995 | try { |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 1996 | if (userId == mSettings.getCurrentUserId() && imi != null |
| 1997 | && imi.isInlineSuggestionsEnabled() && mCurMethod != null) { |
Adam He | 7bc8f60 | 2019-12-12 17:00:34 -0800 | [diff] [blame] | 1998 | executeOrSendMessage(mCurMethod, |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 1999 | mCaller.obtainMessageOOO(MSG_INLINE_SUGGESTIONS_REQUEST, mCurMethod, |
| 2000 | requestInfo, new InlineSuggestionsRequestCallbackDecorator(callback, |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 2001 | imi.getPackageName(), mCurTokenDisplayId, mCurToken, |
| 2002 | this))); |
Adam He | 7bc8f60 | 2019-12-12 17:00:34 -0800 | [diff] [blame] | 2003 | } else { |
| 2004 | callback.onInlineSuggestionsUnsupported(); |
| 2005 | } |
| 2006 | } catch (RemoteException e) { |
| 2007 | Slog.w(TAG, "RemoteException calling onCreateInlineSuggestionsRequest(): " + e); |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 2008 | } |
| 2009 | } |
| 2010 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2011 | /** |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 2012 | * The decorator which validates the host package name in the |
| 2013 | * {@link InlineSuggestionsRequest} argument to make sure it matches the IME package name. |
| 2014 | */ |
| 2015 | private static final class InlineSuggestionsRequestCallbackDecorator |
| 2016 | extends IInlineSuggestionsRequestCallback.Stub { |
| 2017 | @NonNull |
| 2018 | private final IInlineSuggestionsRequestCallback mCallback; |
| 2019 | @NonNull |
| 2020 | private final String mImePackageName; |
| 2021 | |
Svet Ganov | 02fdd34 | 2020-02-20 20:48:34 -0800 | [diff] [blame] | 2022 | private final int mImeDisplayId; |
| 2023 | |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 2024 | @NonNull |
| 2025 | private final IBinder mImeToken; |
| 2026 | @NonNull |
| 2027 | private final InputMethodManagerService mImms; |
| 2028 | |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 2029 | InlineSuggestionsRequestCallbackDecorator( |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 2030 | @NonNull IInlineSuggestionsRequestCallback callback, @NonNull String imePackageName, |
| 2031 | int displayId, @NonNull IBinder imeToken, @NonNull InputMethodManagerService imms) { |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 2032 | mCallback = callback; |
| 2033 | mImePackageName = imePackageName; |
Svet Ganov | 02fdd34 | 2020-02-20 20:48:34 -0800 | [diff] [blame] | 2034 | mImeDisplayId = displayId; |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 2035 | mImeToken = imeToken; |
| 2036 | mImms = imms; |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | @Override |
| 2040 | public void onInlineSuggestionsUnsupported() throws RemoteException { |
| 2041 | mCallback.onInlineSuggestionsUnsupported(); |
| 2042 | } |
| 2043 | |
| 2044 | @Override |
| 2045 | public void onInlineSuggestionsRequest(InlineSuggestionsRequest request, |
Feng Cao | 97ec1c4 | 2020-03-25 12:20:42 -0700 | [diff] [blame] | 2046 | IInlineSuggestionsResponseCallback callback) |
Feng Cao | 7c85eb7 | 2020-02-28 11:39:56 -0800 | [diff] [blame] | 2047 | throws RemoteException { |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 2048 | if (!mImePackageName.equals(request.getHostPackageName())) { |
| 2049 | throw new SecurityException( |
| 2050 | "Host package name in the provide request=[" + request.getHostPackageName() |
| 2051 | + "] doesn't match the IME package name=[" + mImePackageName |
| 2052 | + "]."); |
| 2053 | } |
Svet Ganov | 02fdd34 | 2020-02-20 20:48:34 -0800 | [diff] [blame] | 2054 | request.setHostDisplayId(mImeDisplayId); |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 2055 | mImms.setCurHostInputToken(mImeToken, request.getHostInputToken()); |
Feng Cao | 97ec1c4 | 2020-03-25 12:20:42 -0700 | [diff] [blame] | 2056 | mCallback.onInlineSuggestionsRequest(request, callback); |
Feng Cao | 7c85eb7 | 2020-02-28 11:39:56 -0800 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | @Override |
Feng Cao | 97ec1c4 | 2020-03-25 12:20:42 -0700 | [diff] [blame] | 2060 | public void onInputMethodStartInput(AutofillId imeFieldId) throws RemoteException { |
| 2061 | mCallback.onInputMethodStartInput(imeFieldId); |
Feng Cao | 7c85eb7 | 2020-02-28 11:39:56 -0800 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | @Override |
Feng Cao | 97ec1c4 | 2020-03-25 12:20:42 -0700 | [diff] [blame] | 2065 | public void onInputMethodShowInputRequested(boolean requestResult) throws RemoteException { |
| 2066 | mCallback.onInputMethodShowInputRequested(requestResult); |
| 2067 | } |
| 2068 | |
| 2069 | @Override |
| 2070 | public void onInputMethodStartInputView() throws RemoteException { |
| 2071 | mCallback.onInputMethodStartInputView(); |
| 2072 | } |
| 2073 | |
| 2074 | @Override |
| 2075 | public void onInputMethodFinishInputView() throws RemoteException { |
| 2076 | mCallback.onInputMethodFinishInputView(); |
| 2077 | } |
| 2078 | |
| 2079 | @Override |
| 2080 | public void onInputMethodFinishInput() throws RemoteException { |
| 2081 | mCallback.onInputMethodFinishInput(); |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | /** |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 2086 | * Sets current host input token. |
| 2087 | * |
| 2088 | * @param callerImeToken the token has been made for the current active input method |
| 2089 | * @param hostInputToken the host input token of the current active input method |
| 2090 | */ |
| 2091 | void setCurHostInputToken(@NonNull IBinder callerImeToken, @Nullable IBinder hostInputToken) { |
| 2092 | synchronized (mMethodMap) { |
| 2093 | if (!calledWithValidTokenLocked(callerImeToken)) { |
| 2094 | return; |
| 2095 | } |
| 2096 | mCurHostInputToken = hostInputToken; |
| 2097 | } |
| 2098 | } |
| 2099 | |
| 2100 | /** |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 2101 | * @param imiId if null, returns enabled subtypes for the current imi |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2102 | * @return enabled subtypes of the specified imi |
| 2103 | */ |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2104 | @Override |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 2105 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId, |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 2106 | boolean allowsImplicitlySelectedSubtypes) { |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 2107 | final int callingUserId = UserHandle.getCallingUserId(); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2108 | synchronized (mMethodMap) { |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 2109 | final int[] resolvedUserIds = InputMethodUtils.resolveUserId(callingUserId, |
| 2110 | mSettings.getCurrentUserId(), null); |
| 2111 | if (resolvedUserIds.length != 1) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 2112 | return Collections.emptyList(); |
| 2113 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 2114 | final long ident = Binder.clearCallingIdentity(); |
| 2115 | try { |
| 2116 | return getEnabledInputMethodSubtypeListLocked(imiId, |
| 2117 | allowsImplicitlySelectedSubtypes, resolvedUserIds[0]); |
| 2118 | } finally { |
| 2119 | Binder.restoreCallingIdentity(ident); |
| 2120 | } |
| 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | @GuardedBy("mMethodMap") |
| 2125 | private List<InputMethodSubtype> getEnabledInputMethodSubtypeListLocked(String imiId, |
| 2126 | boolean allowsImplicitlySelectedSubtypes, @UserIdInt int userId) { |
| 2127 | if (userId == mSettings.getCurrentUserId()) { |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 2128 | final InputMethodInfo imi; |
| 2129 | if (imiId == null && mCurMethodId != null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2130 | imi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 2131 | } else { |
| 2132 | imi = mMethodMap.get(imiId); |
| 2133 | } |
| 2134 | if (imi == null) { |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 2135 | return Collections.emptyList(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2136 | } |
| 2137 | return mSettings.getEnabledInputMethodSubtypeListLocked( |
| 2138 | mContext, imi, allowsImplicitlySelectedSubtypes); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2139 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 2140 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 2141 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 2142 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 2143 | new ArrayMap<>(); |
| 2144 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 2145 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap, |
| 2146 | methodList); |
| 2147 | final InputMethodInfo imi = methodMap.get(imiId); |
| 2148 | if (imi == null) { |
| 2149 | return Collections.emptyList(); |
| 2150 | } |
| 2151 | final InputMethodSettings settings = new InputMethodSettings(mContext.getResources(), |
Yohei Yukawa | f927753 | 2019-01-25 02:47:32 -0800 | [diff] [blame] | 2152 | mContext.getContentResolver(), methodMap, userId, true); |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 2153 | return settings.getEnabledInputMethodSubtypeListLocked( |
| 2154 | mContext, imi, allowsImplicitlySelectedSubtypes); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 2155 | } |
| 2156 | |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 2157 | /** |
| 2158 | * Called by each application process as a preparation to start interacting with |
| 2159 | * {@link InputMethodManagerService}. |
| 2160 | * |
| 2161 | * <p>As a general principle, IPCs from the application process that take |
Yohei Yukawa | 499e3f7 | 2018-10-21 20:15:11 -0700 | [diff] [blame] | 2162 | * {@link IInputMethodClient} will be rejected without this step.</p> |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 2163 | * |
| 2164 | * @param client {@link android.os.Binder} proxy that is associated with the singleton instance |
| 2165 | * of {@link android.view.inputmethod.InputMethodManager} that runs on the client |
| 2166 | * process |
| 2167 | * @param inputContext communication channel for the dummy |
| 2168 | * {@link android.view.inputmethod.InputConnection} |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2169 | * @param selfReportedDisplayId self-reported display ID to which the client is associated. |
| 2170 | * Whether the client is still allowed to access to this display |
| 2171 | * or not needs to be evaluated every time the client interacts |
| 2172 | * with the display |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 2173 | */ |
| 2174 | @Override |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2175 | public void addClient(IInputMethodClient client, IInputContext inputContext, |
| 2176 | int selfReportedDisplayId) { |
Yohei Yukawa | cb768bc | 2018-10-24 16:05:09 -0700 | [diff] [blame] | 2177 | // Here there are two scenarios where this method is called: |
| 2178 | // A. IMM is being instantiated in a different process and this is an IPC from that process |
| 2179 | // B. IMM is being instantiated in the same process but Binder.clearCallingIdentity() is |
| 2180 | // called in the caller side if necessary. |
| 2181 | // In either case the following UID/PID should be the ones where InputMethodManager is |
| 2182 | // actually running. |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 2183 | final int callerUid = Binder.getCallingUid(); |
| 2184 | final int callerPid = Binder.getCallingPid(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2185 | synchronized (mMethodMap) { |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 2186 | // TODO: Optimize this linear search. |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 2187 | final int numClients = mClients.size(); |
| 2188 | for (int i = 0; i < numClients; ++i) { |
| 2189 | final ClientState state = mClients.valueAt(i); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2190 | if (state.uid == callerUid && state.pid == callerPid |
| 2191 | && state.selfReportedDisplayId == selfReportedDisplayId) { |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 2192 | throw new SecurityException("uid=" + callerUid + "/pid=" + callerPid |
Yohei Yukawa | cb768bc | 2018-10-24 16:05:09 -0700 | [diff] [blame] | 2193 | + "/displayId=" + selfReportedDisplayId + " is already registered."); |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | final ClientDeathRecipient deathRecipient = new ClientDeathRecipient(this, client); |
| 2197 | try { |
| 2198 | client.asBinder().linkToDeath(deathRecipient, 0); |
| 2199 | } catch (RemoteException e) { |
| 2200 | throw new IllegalStateException(e); |
| 2201 | } |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2202 | // We cannot fully avoid race conditions where the client UID already lost the access to |
| 2203 | // the given self-reported display ID, even if the client is not maliciously reporting |
| 2204 | // a fake display ID. Unconditionally returning SecurityException just because the |
| 2205 | // client doesn't pass display ID verification can cause many test failures hence not an |
| 2206 | // option right now. At the same time |
| 2207 | // context.getSystemService(InputMethodManager.class) |
| 2208 | // is expected to return a valid non-null instance at any time if we do not choose to |
| 2209 | // have the client crash. Thus we do not verify the display ID at all here. Instead we |
| 2210 | // later check the display ID every time the client needs to interact with the specified |
| 2211 | // display. |
| 2212 | mClients.put(client.asBinder(), new ClientState(client, inputContext, callerUid, |
| 2213 | callerPid, selfReportedDisplayId, deathRecipient)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2214 | } |
| 2215 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2216 | |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 2217 | void removeClient(IInputMethodClient client) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | synchronized (mMethodMap) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2219 | ClientState cs = mClients.remove(client.asBinder()); |
| 2220 | if (cs != null) { |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 2221 | client.asBinder().unlinkToDeath(cs.clientDeathRecipient, 0); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2222 | clearClientSessionLocked(cs); |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2223 | |
| 2224 | final int numItems = mActivityViewDisplayIdToParentMap.size(); |
| 2225 | for (int i = numItems - 1; i >= 0; --i) { |
| 2226 | final ActivityViewInfo info = mActivityViewDisplayIdToParentMap.valueAt(i); |
| 2227 | if (info.mParentClient == cs) { |
| 2228 | mActivityViewDisplayIdToParentMap.removeAt(i); |
| 2229 | } |
| 2230 | } |
| 2231 | |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 2232 | if (mCurClient == cs) { |
Tarandeep Singh | 93c00cea | 2018-02-16 14:31:17 -0800 | [diff] [blame] | 2233 | if (mBoundToMethod) { |
| 2234 | mBoundToMethod = false; |
| 2235 | if (mCurMethod != null) { |
| 2236 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 2237 | MSG_UNBIND_INPUT, mCurMethod)); |
| 2238 | } |
| 2239 | } |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 2240 | mCurClient = null; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2241 | mCurActivityViewToScreenMatrix = null; |
Yohei Yukawa | 072b1b5 | 2015-11-18 15:54:34 -0800 | [diff] [blame] | 2242 | } |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 2243 | if (mCurFocusedWindowClient == cs) { |
| 2244 | mCurFocusedWindowClient = null; |
| 2245 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2246 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2247 | } |
| 2248 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2250 | void executeOrSendMessage(IInterface target, Message msg) { |
| 2251 | if (target.asBinder() instanceof Binder) { |
| 2252 | mCaller.sendMessage(msg); |
| 2253 | } else { |
| 2254 | handleMessage(msg); |
| 2255 | msg.recycle(); |
| 2256 | } |
| 2257 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2258 | |
Yohei Yukawa | 4afd933 | 2018-10-21 10:43:53 -0700 | [diff] [blame] | 2259 | void unbindCurrentClientLocked(@UnbindReason int unbindClientReason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2260 | if (mCurClient != null) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2261 | if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client=" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | + mCurClient.client.asBinder()); |
| 2263 | if (mBoundToMethod) { |
| 2264 | mBoundToMethod = false; |
| 2265 | if (mCurMethod != null) { |
| 2266 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 2267 | MSG_UNBIND_INPUT, mCurMethod)); |
| 2268 | } |
| 2269 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 2270 | |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 2271 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 2272 | MSG_SET_ACTIVE, 0, 0, mCurClient)); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2273 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIIO( |
| 2274 | MSG_UNBIND_CLIENT, mCurSeq, unbindClientReason, mCurClient.client)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2275 | mCurClient.sessionRequested = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2276 | mCurClient = null; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2277 | mCurActivityViewToScreenMatrix = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2278 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2279 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2280 | } |
| 2281 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2282 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2283 | private int getImeShowFlags() { |
| 2284 | int flags = 0; |
| 2285 | if (mShowForced) { |
| 2286 | flags |= InputMethod.SHOW_FORCED |
| 2287 | | InputMethod.SHOW_EXPLICIT; |
| 2288 | } else if (mShowExplicitlyRequested) { |
| 2289 | flags |= InputMethod.SHOW_EXPLICIT; |
| 2290 | } |
| 2291 | return flags; |
| 2292 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2294 | private int getAppShowFlags() { |
| 2295 | int flags = 0; |
| 2296 | if (mShowForced) { |
| 2297 | flags |= InputMethodManager.SHOW_FORCED; |
| 2298 | } else if (!mShowExplicitlyRequested) { |
| 2299 | flags |= InputMethodManager.SHOW_IMPLICIT; |
| 2300 | } |
| 2301 | return flags; |
| 2302 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2303 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2304 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2305 | @NonNull |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 2306 | InputBindResult attachNewInputLocked(@StartInputReason int startInputReason, boolean initial) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2307 | if (!mBoundToMethod) { |
| 2308 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 2309 | MSG_BIND_INPUT, mCurMethod, mCurClient.binding)); |
| 2310 | mBoundToMethod = true; |
| 2311 | } |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 2312 | |
| 2313 | final Binder startInputToken = new Binder(); |
Yohei Yukawa | 7979e1a | 2019-02-12 02:01:10 -0800 | [diff] [blame] | 2314 | final StartInputInfo info = new StartInputInfo(mSettings.getCurrentUserId(), mCurToken, |
| 2315 | mCurTokenDisplayId, mCurId, startInputReason, !initial, |
| 2316 | UserHandle.getUserId(mCurClient.uid), mCurClient.selfReportedDisplayId, |
| 2317 | mCurFocusedWindow, mCurAttribute, mCurFocusedWindowSoftInputMode, mCurSeq); |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2318 | mImeTargetWindowMap.put(startInputToken, mCurFocusedWindow); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 2319 | mStartInputHistory.addEntry(info); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 2320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2321 | final SessionState session = mCurClient.curSession; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 2322 | executeOrSendMessage(session.method, mCaller.obtainMessageIIOOOO( |
Yohei Yukawa | f7526b5 | 2017-02-11 20:57:10 -0800 | [diff] [blame] | 2323 | MSG_START_INPUT, mCurInputContextMissingMethods, initial ? 0 : 1 /* restarting */, |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 2324 | startInputToken, session, mCurInputContext, mCurAttribute)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2325 | if (mShowRequested) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2326 | if (DEBUG) Slog.v(TAG, "Attach new input asks to show input"); |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 2327 | showCurrentInputLocked(mCurFocusedWindow, getAppShowFlags(), null, |
| 2328 | SoftInputShowHideReason.ATTACH_NEW_INPUT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2329 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2330 | return new InputBindResult(InputBindResult.ResultCode.SUCCESS_WITH_IME_SESSION, |
| 2331 | session.session, (session.channel != null ? session.channel.dup() : null), |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2332 | mCurId, mCurSeq, mCurActivityViewToScreenMatrix); |
| 2333 | } |
| 2334 | |
| 2335 | @Nullable |
| 2336 | private Matrix getActivityViewToScreenMatrixLocked(int clientDisplayId, int imeDisplayId) { |
| 2337 | if (clientDisplayId == imeDisplayId) { |
| 2338 | return null; |
| 2339 | } |
| 2340 | int displayId = clientDisplayId; |
| 2341 | Matrix matrix = null; |
| 2342 | while (true) { |
| 2343 | final ActivityViewInfo info = mActivityViewDisplayIdToParentMap.get(displayId); |
| 2344 | if (info == null) { |
| 2345 | return null; |
| 2346 | } |
| 2347 | if (matrix == null) { |
| 2348 | matrix = new Matrix(info.mMatrix); |
| 2349 | } else { |
| 2350 | matrix.postConcat(info.mMatrix); |
| 2351 | } |
| 2352 | if (info.mParentClient.selfReportedDisplayId == imeDisplayId) { |
| 2353 | return matrix; |
| 2354 | } |
| 2355 | displayId = info.mParentClient.selfReportedDisplayId; |
| 2356 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2357 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2358 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2359 | @GuardedBy("mMethodMap") |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2360 | @NonNull |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2361 | InputBindResult startInputUncheckedLocked(@NonNull ClientState cs, IInputContext inputContext, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 2362 | @MissingMethodFlags int missingMethods, @NonNull EditorInfo attribute, |
| 2363 | @StartInputFlags int startInputFlags, @StartInputReason int startInputReason) { |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2364 | // If no method is currently selected, do nothing. |
| 2365 | if (mCurMethodId == null) { |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2366 | return InputBindResult.NO_IME; |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 2367 | } |
| 2368 | |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2369 | if (!mSystemReady) { |
| 2370 | // If the system is not yet ready, we shouldn't be running third |
| 2371 | // party code. |
| 2372 | return new InputBindResult( |
| 2373 | InputBindResult.ResultCode.ERROR_SYSTEM_NOT_READY, |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2374 | null, null, mCurMethodId, mCurSeq, null); |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2375 | } |
| 2376 | |
Yohei Yukawa | d57ba67 | 2015-06-08 16:39:46 -0700 | [diff] [blame] | 2377 | if (!InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, cs.uid, |
| 2378 | attribute.packageName)) { |
| 2379 | Slog.e(TAG, "Rejecting this client as it reported an invalid package name." |
| 2380 | + " uid=" + cs.uid + " package=" + attribute.packageName); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2381 | return InputBindResult.INVALID_PACKAGE_NAME; |
Yohei Yukaw | a0f3ad1 | 2015-04-06 16:48:24 -0700 | [diff] [blame] | 2382 | } |
| 2383 | |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2384 | if (!mWindowManagerInternal.isUidAllowedOnDisplay(cs.selfReportedDisplayId, cs.uid)) { |
| 2385 | // Wait, the client no longer has access to the display. |
| 2386 | return InputBindResult.INVALID_DISPLAY_ID; |
| 2387 | } |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2388 | // Compute the final shown display ID with validated cs.selfReportedDisplayId for this |
| 2389 | // session & other conditions. |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 2390 | final int displayIdToShowIme = computeImeDisplayIdForTarget(cs.selfReportedDisplayId, |
| 2391 | mImeDisplayValidator); |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2393 | if (mCurClient != cs) { |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 2394 | // Was the keyguard locked when switching over to the new client? |
| 2395 | mCurClientInKeyguard = isKeyguardLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2396 | // If the client is changing, we need to switch over to the new |
| 2397 | // one. |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 2398 | unbindCurrentClientLocked(UnbindReason.SWITCH_CLIENT); |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 2399 | if (DEBUG) Slog.v(TAG, "switching to client: client=" |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 2400 | + cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2401 | |
| 2402 | // If the screen is on, inform the new client it is active |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 2403 | if (mIsInteractive) { |
tiansiming [田思明] | e102c97 | 2018-04-17 18:15:33 +0800 | [diff] [blame] | 2404 | 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] | 2405 | } |
| 2406 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2408 | // Bump up the sequence for this client and attach it. |
| 2409 | mCurSeq++; |
| 2410 | if (mCurSeq <= 0) mCurSeq = 1; |
| 2411 | mCurClient = cs; |
| 2412 | mCurInputContext = inputContext; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2413 | mCurActivityViewToScreenMatrix = |
| 2414 | getActivityViewToScreenMatrixLocked(cs.selfReportedDisplayId, displayIdToShowIme); |
| 2415 | if (cs.selfReportedDisplayId != displayIdToShowIme |
| 2416 | && mCurActivityViewToScreenMatrix == null) { |
Yohei Yukawa | 3d2cc0f | 2019-04-25 18:32:15 -0700 | [diff] [blame] | 2417 | // CursorAnchorInfo API does not work as-is for cross-display scenario. Pretend that |
| 2418 | // InputConnection#requestCursorUpdates() is not implemented in the application so that |
| 2419 | // IMEs will always receive false from this API. |
| 2420 | missingMethods |= MissingMethodFlags.REQUEST_CURSOR_UPDATES; |
| 2421 | } |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 2422 | mCurInputContextMissingMethods = missingMethods; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2423 | mCurAttribute = attribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2424 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2425 | // Check if the input method is changing. |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2426 | // We expect the caller has already verified that the client is allowed to access this |
| 2427 | // display ID. |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2428 | if (mCurId != null && mCurId.equals(mCurMethodId) |
| 2429 | && displayIdToShowIme == mCurTokenDisplayId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2430 | if (cs.curSession != null) { |
| 2431 | // Fast case: if we are already connected to the input method, |
| 2432 | // then just return it. |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2433 | return attachNewInputLocked(startInputReason, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 2434 | (startInputFlags & StartInputFlags.INITIAL_CONNECTION) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2435 | } |
| 2436 | if (mHaveConnection) { |
| 2437 | if (mCurMethod != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | // Return to client, and we will get back with it when |
| 2439 | // we have had a session made for it. |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2440 | requestClientSessionLocked(cs); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2441 | return new InputBindResult( |
| 2442 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_SESSION, |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2443 | null, null, mCurId, mCurSeq, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2444 | } else if (SystemClock.uptimeMillis() |
| 2445 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 2446 | // In this case we have connected to the service, but |
| 2447 | // don't yet have its interface. If it hasn't been too |
| 2448 | // long since we did the connection, we'll return to |
| 2449 | // the client and wait to get the service interface so |
| 2450 | // we can report back. If it has been too long, we want |
| 2451 | // to fall through so we can try a disconnect/reconnect |
| 2452 | // to see if we can get back in touch with the service. |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2453 | return new InputBindResult( |
| 2454 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING, |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2455 | null, null, mCurId, mCurSeq, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2456 | } else { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2457 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, |
| 2458 | mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2459 | } |
| 2460 | } |
| 2461 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2463 | InputMethodInfo info = mMethodMap.get(mCurMethodId); |
| 2464 | if (info == null) { |
| 2465 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 2466 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2467 | |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2468 | unbindCurrentMethodLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2469 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2470 | mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE); |
| 2471 | mCurIntent.setComponent(info.getComponent()); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2472 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 2473 | com.android.internal.R.string.input_method_binding_label); |
| 2474 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 2475 | mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0)); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2476 | |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 2477 | if (bindCurrentInputMethodServiceLocked(mCurIntent, this, IME_CONNECTION_BIND_FLAGS)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2478 | mLastBindTime = SystemClock.uptimeMillis(); |
| 2479 | mHaveConnection = true; |
| 2480 | mCurId = info.getId(); |
| 2481 | mCurToken = new Binder(); |
Yohei Yukawa | 0deaef0 | 2018-10-17 10:33:48 +0800 | [diff] [blame] | 2482 | mCurTokenDisplayId = displayIdToShowIme; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2483 | try { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2484 | if (DEBUG) { |
| 2485 | Slog.v(TAG, "Adding window token: " + mCurToken + " for display: " |
| 2486 | + mCurTokenDisplayId); |
| 2487 | } |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 2488 | mIWindowManager.addWindowToken(mCurToken, LayoutParams.TYPE_INPUT_METHOD, |
| 2489 | mCurTokenDisplayId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2490 | } catch (RemoteException e) { |
| 2491 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2492 | return new InputBindResult( |
| 2493 | InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING, |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2494 | null, null, mCurId, mCurSeq, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2495 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 2496 | mCurIntent = null; |
| 2497 | Slog.w(TAG, "Failure connecting to input method service: " + mCurIntent); |
| 2498 | return InputBindResult.IME_NOT_CONNECTED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2500 | |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2501 | @FunctionalInterface |
| 2502 | interface ImeDisplayValidator { |
| 2503 | boolean displayCanShowIme(int displayId); |
| 2504 | } |
| 2505 | |
| 2506 | /** |
| 2507 | * Find the display where the IME should be shown. |
| 2508 | * |
| 2509 | * @param displayId the ID of the display where the IME client target is. |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2510 | * @param checker instance of {@link ImeDisplayValidator} which is used for |
| 2511 | * checking display config to adjust the final target display. |
| 2512 | * @return The ID of the display where the IME should be shown. |
| 2513 | */ |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 2514 | static int computeImeDisplayIdForTarget(int displayId, @NonNull ImeDisplayValidator checker) { |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2515 | if (displayId == DEFAULT_DISPLAY || displayId == INVALID_DISPLAY) { |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2516 | return FALLBACK_DISPLAY_ID; |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2517 | } |
lumark | 9a72d22 | 2019-03-30 18:31:45 +0800 | [diff] [blame] | 2518 | |
| 2519 | // Show IME window on fallback display when the display doesn't support system decorations |
| 2520 | // 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] | 2521 | return checker.displayCanShowIme(displayId) ? displayId : FALLBACK_DISPLAY_ID; |
lumark | ef1965b | 2018-09-12 17:42:53 +0800 | [diff] [blame] | 2522 | } |
| 2523 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2524 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2525 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 2526 | synchronized (mMethodMap) { |
| 2527 | if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { |
| 2528 | mCurMethod = IInputMethod.Stub.asInterface(service); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2529 | if (mCurToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2530 | Slog.w(TAG, "Service connected without a token!"); |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2531 | unbindCurrentMethodLocked(); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 2532 | return; |
| 2533 | } |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 2534 | if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2535 | // Dispatch display id for InputMethodService to update context display. |
| 2536 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 2537 | MSG_INITIALIZE_IME, mCurTokenDisplayId, mCurMethod, mCurToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2538 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2539 | clearClientSessionLocked(mCurClient); |
| 2540 | requestClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2541 | } |
| 2542 | } |
| 2543 | } |
| 2544 | } |
| 2545 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2546 | void onSessionCreated(IInputMethod method, IInputMethodSession session, |
| 2547 | InputChannel channel) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2548 | synchronized (mMethodMap) { |
Yohei Yukawa | 32807ad | 2020-03-04 12:27:29 -0800 | [diff] [blame] | 2549 | if (mUserSwitchHandlerTask != null) { |
| 2550 | // We have a pending user-switching task so it's better to just ignore this session. |
| 2551 | channel.dispose(); |
| 2552 | return; |
| 2553 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2554 | if (mCurMethod != null && method != null |
| 2555 | && mCurMethod.asBinder() == method.asBinder()) { |
| 2556 | if (mCurClient != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2557 | clearClientSessionLocked(mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2558 | mCurClient.curSession = new SessionState(mCurClient, |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2559 | method, session, channel); |
Yohei Yukawa | 87ca840 | 2017-02-07 00:13:14 -0800 | [diff] [blame] | 2560 | InputBindResult res = attachNewInputLocked( |
Yohei Yukawa | 4219422 | 2018-10-21 20:14:40 -0700 | [diff] [blame] | 2561 | StartInputReason.SESSION_CREATED_BY_IME, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | if (res.method != null) { |
| 2563 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2564 | MSG_BIND_CLIENT, mCurClient.client, res)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2565 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2566 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2567 | } |
| 2568 | } |
| 2569 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2570 | |
| 2571 | // Session abandoned. Close its associated input channel. |
| 2572 | channel.dispose(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2573 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2574 | |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2575 | void unbindCurrentMethodLocked() { |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 2576 | if (mVisibleBound) { |
| 2577 | mContext.unbindService(mVisibleConnection); |
| 2578 | mVisibleBound = false; |
| 2579 | } |
| 2580 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2581 | if (mHaveConnection) { |
| 2582 | mContext.unbindService(this); |
| 2583 | mHaveConnection = false; |
| 2584 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2585 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2586 | if (mCurToken != null) { |
| 2587 | try { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2588 | if (DEBUG) { |
| 2589 | Slog.v(TAG, "Removing window token: " + mCurToken + " for display: " |
| 2590 | + mCurTokenDisplayId); |
| 2591 | } |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2592 | mIWindowManager.removeWindowToken(mCurToken, mCurTokenDisplayId); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2593 | } catch (RemoteException e) { |
| 2594 | } |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2595 | // Set IME window status as invisible when unbind current method. |
| 2596 | mImeWindowVis = 0; |
| 2597 | mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; |
| 2598 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2599 | mCurToken = null; |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 2600 | mCurTokenDisplayId = INVALID_DISPLAY; |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 2601 | mCurHostInputToken = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2602 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2603 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 2604 | mCurId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2605 | clearCurMethodLocked(); |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 2606 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2607 | |
Yohei Yukawa | 4afd933 | 2018-10-21 10:43:53 -0700 | [diff] [blame] | 2608 | void resetCurrentMethodAndClient(@UnbindReason int unbindClientReason) { |
Yohei Yukawa | bc7b526 | 2015-11-17 17:38:41 -0800 | [diff] [blame] | 2609 | mCurMethodId = null; |
Yohei Yukawa | d4d895e | 2018-09-24 16:01:20 -0700 | [diff] [blame] | 2610 | unbindCurrentMethodLocked(); |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 2611 | unbindCurrentClientLocked(unbindClientReason); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2612 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2613 | |
| 2614 | void requestClientSessionLocked(ClientState cs) { |
| 2615 | if (!cs.sessionRequested) { |
| 2616 | if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs); |
| 2617 | InputChannel[] channels = InputChannel.openInputChannelPair(cs.toString()); |
| 2618 | cs.sessionRequested = true; |
| 2619 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOOO( |
| 2620 | MSG_CREATE_SESSION, mCurMethod, channels[1], |
| 2621 | new MethodCallback(this, mCurMethod, channels[0]))); |
| 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | void clearClientSessionLocked(ClientState cs) { |
| 2626 | finishSessionLocked(cs.curSession); |
| 2627 | cs.curSession = null; |
| 2628 | cs.sessionRequested = false; |
| 2629 | } |
| 2630 | |
| 2631 | private void finishSessionLocked(SessionState sessionState) { |
| 2632 | if (sessionState != null) { |
| 2633 | if (sessionState.session != null) { |
| 2634 | try { |
| 2635 | sessionState.session.finishSession(); |
| 2636 | } catch (RemoteException e) { |
| 2637 | Slog.w(TAG, "Session failed to close due to remote exception", e); |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2638 | updateSystemUiLocked(0 /* vis */, mBackDisposition); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2639 | } |
| 2640 | sessionState.session = null; |
| 2641 | } |
| 2642 | if (sessionState.channel != null) { |
| 2643 | sessionState.channel.dispose(); |
| 2644 | sessionState.channel = null; |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2645 | } |
| 2646 | } |
| 2647 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2648 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2649 | void clearCurMethodLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2650 | if (mCurMethod != null) { |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 2651 | final int numClients = mClients.size(); |
| 2652 | for (int i = 0; i < numClients; ++i) { |
| 2653 | clearClientSessionLocked(mClients.valueAt(i)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2654 | } |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2655 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2656 | finishSessionLocked(mEnabledSession); |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 2657 | mEnabledSession = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2658 | mCurMethod = null; |
| 2659 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2660 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2661 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2662 | } |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 2663 | mInFullscreenMode = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2664 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2665 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2666 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2667 | public void onServiceDisconnected(ComponentName name) { |
Yohei Yukawa | 817d5f7 | 2017-01-04 20:15:02 -0800 | [diff] [blame] | 2668 | // Note that mContext.unbindService(this) does not trigger this. Hence if we are here the |
| 2669 | // disconnection is not intended by IMMS (e.g. triggered because the current IMS crashed), |
| 2670 | // which is irregular but can eventually happen for everyone just by continuing using the |
| 2671 | // device. Thus it is important to make sure that all the internal states are properly |
| 2672 | // refreshed when this method is called back. Running |
| 2673 | // adb install -r <APK that implements the current IME> |
| 2674 | // 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] | 2675 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2676 | if (DEBUG) Slog.v(TAG, "Service disconnected: " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2677 | + " mCurIntent=" + mCurIntent); |
| 2678 | if (mCurMethod != null && mCurIntent != null |
| 2679 | && name.equals(mCurIntent.getComponent())) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2680 | clearCurMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2681 | // We consider this to be a new bind attempt, since the system |
| 2682 | // should now try to restart the service for us. |
| 2683 | mLastBindTime = SystemClock.uptimeMillis(); |
| 2684 | mShowRequested = mInputShown; |
| 2685 | mInputShown = false; |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 2686 | unbindCurrentClientLocked(UnbindReason.DISCONNECT_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2687 | } |
| 2688 | } |
| 2689 | } |
| 2690 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 2691 | @BinderThread |
Yohei Yukawa | 41b094f | 2018-09-09 23:58:45 -0700 | [diff] [blame] | 2692 | private void updateStatusIcon(@NonNull IBinder token, String packageName, |
| 2693 | @DrawableRes int iconId) { |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2694 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 2695 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2696 | return; |
| 2697 | } |
| 2698 | final long ident = Binder.clearCallingIdentity(); |
| 2699 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2700 | if (iconId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2701 | 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] | 2702 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2703 | mStatusBar.setIconVisibility(mSlotIme, false); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2704 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2705 | } else if (packageName != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2706 | 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] | 2707 | CharSequence contentDescription = null; |
| 2708 | try { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2709 | // Use PackageManager to load label |
| 2710 | final PackageManager packageManager = mContext.getPackageManager(); |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 2711 | contentDescription = packageManager.getApplicationLabel( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2712 | mIPackageManager.getApplicationInfo(packageName, 0, |
| 2713 | mSettings.getCurrentUserId())); |
| 2714 | } catch (RemoteException e) { |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 2715 | /* ignore */ |
| 2716 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2717 | if (mStatusBar != null) { |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2718 | mStatusBar.setIcon(mSlotIme, packageName, iconId, 0, |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2719 | contentDescription != null |
| 2720 | ? contentDescription.toString() : null); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 2721 | mStatusBar.setIconVisibility(mSlotIme, true); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2722 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2723 | } |
Yohei Yukawa | 59377ca | 2017-01-31 21:32:26 -0800 | [diff] [blame] | 2724 | } finally { |
| 2725 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2726 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2727 | } |
| 2728 | } |
| 2729 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2730 | private boolean shouldShowImeSwitcherLocked(int visibility) { |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2731 | if (!mShowOngoingImeSwitcherForPhones) return false; |
Jason Monk | 807ef76 | 2014-05-08 15:47:46 -0400 | [diff] [blame] | 2732 | if (mSwitchingDialog != null) return false; |
Yohei Yukawa | d2bc309 | 2017-07-31 15:37:14 -0700 | [diff] [blame] | 2733 | if (mWindowManagerInternal.isKeyguardShowingAndNotOccluded() |
| 2734 | && mKeyguardManager != null && mKeyguardManager.isKeyguardSecure()) return false; |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 2735 | if ((visibility & InputMethodService.IME_ACTIVE) == 0 |
| 2736 | || (visibility & InputMethodService.IME_INVISIBLE) != 0) { |
| 2737 | return false; |
| 2738 | } |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2739 | if (mWindowManagerInternal.isHardKeyboardAvailable()) { |
Yohei Yukawa | af023f2 | 2019-06-21 16:38:22 -0700 | [diff] [blame] | 2740 | // When physical keyboard is attached, we show the ime switcher (or notification if |
| 2741 | // NavBar is not available) because SHOW_IME_WITH_HARD_KEYBOARD settings currently |
| 2742 | // exists in the IME switcher dialog. Might be OK to remove this condition once |
| 2743 | // SHOW_IME_WITH_HARD_KEYBOARD settings finds a good place to live. |
| 2744 | return true; |
Yohei Yukawa | 8939838 | 2016-03-29 11:37:04 -0700 | [diff] [blame] | 2745 | } else if ((visibility & InputMethodService.IME_VISIBLE) == 0) { |
| 2746 | return false; |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2747 | } |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2748 | |
| 2749 | List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked(); |
| 2750 | final int N = imis.size(); |
| 2751 | if (N > 2) return true; |
| 2752 | if (N < 1) return false; |
| 2753 | int nonAuxCount = 0; |
| 2754 | int auxCount = 0; |
| 2755 | InputMethodSubtype nonAuxSubtype = null; |
| 2756 | InputMethodSubtype auxSubtype = null; |
| 2757 | for(int i = 0; i < N; ++i) { |
| 2758 | final InputMethodInfo imi = imis.get(i); |
| 2759 | final List<InputMethodSubtype> subtypes = |
| 2760 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
| 2761 | final int subtypeCount = subtypes.size(); |
| 2762 | if (subtypeCount == 0) { |
| 2763 | ++nonAuxCount; |
| 2764 | } else { |
| 2765 | for (int j = 0; j < subtypeCount; ++j) { |
| 2766 | final InputMethodSubtype subtype = subtypes.get(j); |
| 2767 | if (!subtype.isAuxiliary()) { |
| 2768 | ++nonAuxCount; |
| 2769 | nonAuxSubtype = subtype; |
| 2770 | } else { |
| 2771 | ++auxCount; |
| 2772 | auxSubtype = subtype; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2773 | } |
| 2774 | } |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2775 | } |
| 2776 | } |
Yohei Yukawa | c6c7cd2 | 2015-05-12 15:00:33 -0700 | [diff] [blame] | 2777 | if (nonAuxCount > 1 || auxCount > 1) { |
| 2778 | return true; |
| 2779 | } else if (nonAuxCount == 1 && auxCount == 1) { |
| 2780 | if (nonAuxSubtype != null && auxSubtype != null |
| 2781 | && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale()) |
| 2782 | || auxSubtype.overridesImplicitlyEnabledSubtype() |
| 2783 | || nonAuxSubtype.overridesImplicitlyEnabledSubtype()) |
| 2784 | && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) { |
| 2785 | return false; |
| 2786 | } |
| 2787 | return true; |
| 2788 | } |
| 2789 | return false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2790 | } |
| 2791 | |
John Spurlock | e098050 | 2013-10-25 11:59:29 -0400 | [diff] [blame] | 2792 | private boolean isKeyguardLocked() { |
| 2793 | return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked(); |
| 2794 | } |
| 2795 | |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2796 | @BinderThread |
satok | dbf2950 | 2011-08-25 15:28:23 +0900 | [diff] [blame] | 2797 | @SuppressWarnings("deprecation") |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 2798 | private void setImeWindowStatus(@NonNull IBinder token, int vis, int backDisposition) { |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2799 | final int topFocusedDisplayId = mWindowManagerInternal.getTopFocusedDisplayId(); |
| 2800 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2801 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 2802 | if (!calledWithValidTokenLocked(token)) { |
| 2803 | return; |
| 2804 | } |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2805 | // Skip update IME status when current token display is not same as focused display. |
| 2806 | // Note that we still need to update IME status when focusing external display |
| 2807 | // that does not support system decoration and fallback to show IME on default |
| 2808 | // display since it is intentional behavior. |
| 2809 | if (mCurTokenDisplayId != topFocusedDisplayId |
| 2810 | && mCurTokenDisplayId != FALLBACK_DISPLAY_ID) { |
| 2811 | return; |
| 2812 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2813 | mImeWindowVis = vis; |
| 2814 | mBackDisposition = backDisposition; |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2815 | updateSystemUiLocked(vis, backDisposition); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2816 | } |
Yohei Yukawa | d6475a6 | 2017-04-17 10:35:27 -0700 | [diff] [blame] | 2817 | |
| 2818 | final boolean dismissImeOnBackKeyPressed; |
| 2819 | switch (backDisposition) { |
| 2820 | case InputMethodService.BACK_DISPOSITION_WILL_DISMISS: |
| 2821 | dismissImeOnBackKeyPressed = true; |
| 2822 | break; |
| 2823 | case InputMethodService.BACK_DISPOSITION_WILL_NOT_DISMISS: |
| 2824 | dismissImeOnBackKeyPressed = false; |
| 2825 | break; |
| 2826 | default: |
| 2827 | case InputMethodService.BACK_DISPOSITION_DEFAULT: |
| 2828 | dismissImeOnBackKeyPressed = ((vis & InputMethodService.IME_VISIBLE) != 0); |
| 2829 | break; |
| 2830 | } |
Yohei Yukawa | ee2a7ed | 2017-02-15 21:38:57 -0800 | [diff] [blame] | 2831 | mWindowManagerInternal.updateInputMethodWindowStatus(token, |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2832 | (vis & InputMethodService.IME_VISIBLE) != 0, dismissImeOnBackKeyPressed); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2833 | } |
| 2834 | |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2835 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 2836 | private void reportStartInput(@NonNull IBinder token, IBinder startInputToken) { |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2837 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 2838 | if (!calledWithValidTokenLocked(token)) { |
| 2839 | return; |
| 2840 | } |
Yohei Yukawa | 99e1f6e | 2018-06-22 17:33:19 -0700 | [diff] [blame] | 2841 | final IBinder targetWindow = mImeTargetWindowMap.get(startInputToken); |
| 2842 | if (targetWindow != null && mLastImeTargetWindow != targetWindow) { |
| 2843 | mWindowManagerInternal.updateInputMethodTargetWindow(token, targetWindow); |
| 2844 | } |
| 2845 | mLastImeTargetWindow = targetWindow; |
| 2846 | } |
| 2847 | } |
| 2848 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2849 | // Caution! This method is called in this class. Handle multi-user carefully |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 2850 | private void updateSystemUiLocked(int vis, int backDisposition) { |
| 2851 | if (mCurToken == null) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2852 | return; |
| 2853 | } |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 2854 | if (DEBUG) { |
| 2855 | Slog.d(TAG, "IME window vis: " + vis |
| 2856 | + " active: " + (vis & InputMethodService.IME_ACTIVE) |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2857 | + " inv: " + (vis & InputMethodService.IME_INVISIBLE) |
| 2858 | + " displayId: " + mCurTokenDisplayId); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 2859 | } |
| 2860 | |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2861 | // TODO: Move this clearing calling identity block to setImeWindowStatus after making sure |
| 2862 | // all updateSystemUi happens on system previlege. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2863 | final long ident = Binder.clearCallingIdentity(); |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2864 | try { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2865 | // apply policy for binder calls |
| 2866 | if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) { |
| 2867 | vis = 0; |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2868 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2869 | // mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked(). |
| 2870 | final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis); |
| 2871 | if (mStatusBar != null) { |
lumark | 7570cac | 2019-03-07 22:14:38 +0800 | [diff] [blame] | 2872 | mStatusBar.setImeWindowStatus(mCurTokenDisplayId, mCurToken, vis, backDisposition, |
Tarandeep Singh | 07b318b | 2019-07-17 11:12:04 -0700 | [diff] [blame] | 2873 | needsToShowImeSwitcher, false /*isMultiClientImeEnabled*/); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2874 | } |
| 2875 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 2876 | if (imi != null && needsToShowImeSwitcher) { |
| 2877 | // Used to load label |
| 2878 | final CharSequence title = mRes.getText( |
| 2879 | com.android.internal.R.string.select_input_method); |
| 2880 | final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName( |
| 2881 | mContext, imi, mCurrentSubtype); |
Chris Wren | 1ce4b6d | 2015-06-11 10:19:43 -0400 | [diff] [blame] | 2882 | mImeSwitcherNotification.setContentTitle(title) |
| 2883 | .setContentText(summary) |
| 2884 | .setContentIntent(mImeSwitchPendingIntent); |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2885 | try { |
Charles Chen | ea6e7f0 | 2018-11-19 21:37:45 +0800 | [diff] [blame] | 2886 | // TODO(b/120076400): Figure out what is the best behavior |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2887 | if ((mNotificationManager != null) |
Charles Chen | ea6e7f0 | 2018-11-19 21:37:45 +0800 | [diff] [blame] | 2888 | && !mIWindowManager.hasNavigationBar(DEFAULT_DISPLAY)) { |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2889 | if (DEBUG) { |
| 2890 | Slog.d(TAG, "--- show notification: label = " + summary); |
| 2891 | } |
| 2892 | mNotificationManager.notifyAsUser(null, |
Chris Wren | 282cfef | 2017-03-27 15:01:44 -0400 | [diff] [blame] | 2893 | SystemMessage.NOTE_SELECT_INPUT_METHOD, |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2894 | mImeSwitcherNotification.build(), UserHandle.ALL); |
| 2895 | mNotificationShown = true; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 2896 | } |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 2897 | } catch (RemoteException e) { |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2898 | } |
| 2899 | } else { |
| 2900 | if (mNotificationShown && mNotificationManager != null) { |
| 2901 | if (DEBUG) { |
| 2902 | Slog.d(TAG, "--- hide notification"); |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2903 | } |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2904 | mNotificationManager.cancelAsUser(null, |
Chris Wren | 282cfef | 2017-03-27 15:01:44 -0400 | [diff] [blame] | 2905 | SystemMessage.NOTE_SELECT_INPUT_METHOD, UserHandle.ALL); |
Seigo Nonaka | d9eb911 | 2015-05-26 20:54:43 +0900 | [diff] [blame] | 2906 | mNotificationShown = false; |
satok | 7cfc0ed | 2011-06-20 21:29:36 +0900 | [diff] [blame] | 2907 | } |
satok | 06487a5 | 2010-10-29 11:37:18 +0900 | [diff] [blame] | 2908 | } |
| 2909 | } finally { |
| 2910 | Binder.restoreCallingIdentity(ident); |
| 2911 | } |
| 2912 | } |
| 2913 | |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2914 | void updateFromSettingsLocked(boolean enabledMayChange) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 2915 | updateInputMethodsFromSettingsLocked(enabledMayChange); |
| 2916 | updateKeyboardFromSettingsLocked(); |
| 2917 | } |
| 2918 | |
| 2919 | void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) { |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2920 | if (enabledMayChange) { |
| 2921 | List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 2922 | for (int i=0; i<enabled.size(); i++) { |
| 2923 | // We allow the user to select "disabled until used" apps, so if they |
| 2924 | // are enabling one of those here we now need to make it enabled. |
| 2925 | InputMethodInfo imm = enabled.get(i); |
| 2926 | try { |
| 2927 | ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(), |
| 2928 | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, |
| 2929 | mSettings.getCurrentUserId()); |
Satoshi Kataoka | 7987a31 | 2013-04-17 18:59:33 +0900 | [diff] [blame] | 2930 | if (ai != null && ai.enabledSetting |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2931 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) { |
Satoshi Kataoka | ed1cdb2 | 2013-04-17 16:41:58 +0900 | [diff] [blame] | 2932 | if (DEBUG) { |
| 2933 | Slog.d(TAG, "Update state(" + imm.getId() |
| 2934 | + "): DISABLED_UNTIL_USED -> DEFAULT"); |
| 2935 | } |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2936 | mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(), |
| 2937 | PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, |
Dianne Hackborn | 3fa3c28a | 2013-03-26 16:15:41 -0700 | [diff] [blame] | 2938 | PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(), |
| 2939 | mContext.getBasePackageName()); |
Dianne Hackborn | fd7aded | 2013-01-22 17:10:23 -0800 | [diff] [blame] | 2940 | } |
| 2941 | } catch (RemoteException e) { |
| 2942 | } |
| 2943 | } |
| 2944 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2945 | // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and |
| 2946 | // ENABLED_INPUT_METHODS is taking care of keeping them correctly in |
| 2947 | // sync, so we will never have a DEFAULT_INPUT_METHOD that is not |
| 2948 | // enabled. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2949 | String id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2950 | // There is no input method selected, try to choose new applicable input method. |
| 2951 | if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 2952 | id = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 2953 | } |
| 2954 | if (!TextUtils.isEmpty(id)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2955 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 2956 | setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2957 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2958 | Slog.w(TAG, "Unknown input method from prefs: " + id, e); |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 2959 | resetCurrentMethodAndClient(UnbindReason.SWITCH_IME_FAILED); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2960 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2961 | } else { |
| 2962 | // 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] | 2963 | resetCurrentMethodAndClient(UnbindReason.NO_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2964 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 2965 | // Here is not the perfect place to reset the switching controller. Ideally |
| 2966 | // mSwitchingController and mSettings should be able to share the same state. |
| 2967 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 2968 | // the same enabled IMEs list. |
| 2969 | mSwitchingController.resetCircularListLocked(mContext); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 2970 | |
| 2971 | } |
| 2972 | |
| 2973 | public void updateKeyboardFromSettingsLocked() { |
| 2974 | mShowImeWithHardKeyboard = mSettings.isShowImeWithHardKeyboardEnabled(); |
| 2975 | if (mSwitchingDialog != null |
| 2976 | && mSwitchingDialogTitleView != null |
| 2977 | && mSwitchingDialog.isShowing()) { |
| 2978 | final Switch hardKeySwitch = (Switch)mSwitchingDialogTitleView.findViewById( |
| 2979 | com.android.internal.R.id.hard_keyboard_switch); |
| 2980 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
| 2981 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2982 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2983 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2984 | /* package */ void setInputMethodLocked(String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2985 | InputMethodInfo info = mMethodMap.get(id); |
| 2986 | if (info == null) { |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 2987 | throw new IllegalArgumentException("Unknown id: " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2988 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 2989 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2990 | // 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] | 2991 | if (id.equals(mCurMethodId)) { |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2992 | final int subtypeCount = info.getSubtypeCount(); |
| 2993 | if (subtypeCount <= 0) { |
| 2994 | return; |
satok | cd7cd29 | 2010-11-20 15:46:23 +0900 | [diff] [blame] | 2995 | } |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 2996 | final InputMethodSubtype oldSubtype = mCurrentSubtype; |
| 2997 | final InputMethodSubtype newSubtype; |
| 2998 | if (subtypeId >= 0 && subtypeId < subtypeCount) { |
| 2999 | newSubtype = info.getSubtypeAt(subtypeId); |
| 3000 | } else { |
| 3001 | // If subtype is null, try to find the most applicable one from |
| 3002 | // getCurrentInputMethodSubtype. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3003 | newSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 3004 | } |
| 3005 | if (newSubtype == null || oldSubtype == null) { |
| 3006 | Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype |
| 3007 | + ", new subtype = " + newSubtype); |
| 3008 | return; |
| 3009 | } |
| 3010 | if (newSubtype != oldSubtype) { |
| 3011 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true); |
| 3012 | if (mCurMethod != null) { |
| 3013 | try { |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 3014 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 3015 | mCurMethod.changeInputMethodSubtype(newSubtype); |
| 3016 | } catch (RemoteException e) { |
| 3017 | Slog.w(TAG, "Failed to call changeInputMethodSubtype"); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3018 | } |
| 3019 | } |
| 3020 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3021 | return; |
| 3022 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3023 | |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 3024 | // Changing to a different IME. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3025 | final long ident = Binder.clearCallingIdentity(); |
| 3026 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3027 | // Set a subtype to this input method. |
| 3028 | // subtypeId the name of a subtype which will be set. |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 3029 | setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false); |
| 3030 | // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked() |
| 3031 | // because mCurMethodId is stored as a history in |
| 3032 | // setSelectedInputMethodAndSubtypeLocked(). |
| 3033 | mCurMethodId = id; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3034 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 3035 | if (LocalServices.getService(ActivityManagerInternal.class).isSystemReady()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3036 | Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 3037 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3038 | intent.putExtra("input_method_id", id); |
Amith Yamasani | cd75706 | 2012-10-19 18:23:52 -0700 | [diff] [blame] | 3039 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3040 | } |
Yohei Yukawa | b752645 | 2018-10-21 20:15:17 -0700 | [diff] [blame] | 3041 | unbindCurrentClientLocked(UnbindReason.SWITCH_IME); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3042 | } finally { |
| 3043 | Binder.restoreCallingIdentity(ident); |
| 3044 | } |
| 3045 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3046 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3047 | @Override |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 3048 | public boolean showSoftInput(IInputMethodClient client, IBinder windowToken, int flags, |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3049 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 3050 | int uid = Binder.getCallingUid(); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3051 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3052 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3053 | return false; |
| 3054 | } |
| 3055 | final long ident = Binder.clearCallingIdentity(); |
| 3056 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3057 | if (mCurClient == null || client == null |
| 3058 | || mCurClient.client.asBinder() != client.asBinder()) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 3059 | // We need to check if this is the current client with |
| 3060 | // focus in the window manager, to allow this call to |
| 3061 | // be made before input is started in it. |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3062 | final ClientState cs = mClients.get(client.asBinder()); |
| 3063 | if (cs == null) { |
| 3064 | throw new IllegalArgumentException("unknown client " + client.asBinder()); |
| 3065 | } |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 3066 | if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid, |
| 3067 | cs.selfReportedDisplayId)) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 3068 | Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3069 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3070 | } |
| 3071 | } |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3072 | if (DEBUG) Slog.v(TAG, "Client requesting input be shown"); |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3073 | return showCurrentInputLocked(windowToken, flags, resultReceiver, |
| 3074 | SoftInputShowHideReason.SHOW_SOFT_INPUT); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3075 | } finally { |
| 3076 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3077 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3078 | } |
| 3079 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3080 | |
Andreas Gampe | d6d4206 | 2018-07-20 13:08:21 -0700 | [diff] [blame] | 3081 | @GuardedBy("mMethodMap") |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3082 | boolean showCurrentInputLocked(IBinder windowToken, int flags, ResultReceiver resultReceiver, |
| 3083 | @SoftInputShowHideReason int reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3084 | mShowRequested = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 3085 | if (mAccessibilityRequestingNoSoftKeyboard) { |
| 3086 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3087 | } |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 3088 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3089 | if ((flags&InputMethodManager.SHOW_FORCED) != 0) { |
| 3090 | mShowExplicitlyRequested = true; |
| 3091 | mShowForced = true; |
Anna Galusza | 9b27811 | 2016-01-04 11:37:37 -0800 | [diff] [blame] | 3092 | } else if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) { |
| 3093 | mShowExplicitlyRequested = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3094 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3095 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 3096 | if (!mSystemReady) { |
| 3097 | return false; |
| 3098 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3099 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3100 | boolean res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3101 | if (mCurMethod != null) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3102 | if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken); |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 3103 | // create a dummy token for IMS so that IMS cannot inject windows into client app. |
| 3104 | Binder showInputToken = new Binder(); |
| 3105 | mShowRequestWindowMap.put(showInputToken, windowToken); |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3106 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIIOOO( |
| 3107 | MSG_SHOW_SOFT_INPUT, getImeShowFlags(), reason, mCurMethod, resultReceiver, |
| 3108 | showInputToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3109 | mInputShown = true; |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 3110 | if (mHaveConnection && !mVisibleBound) { |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 3111 | bindCurrentInputMethodServiceLocked( |
Yohei Yukawa | a67a459 | 2017-03-30 15:57:02 -0700 | [diff] [blame] | 3112 | mCurIntent, mVisibleConnection, IME_VISIBLE_BIND_FLAGS); |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 3113 | mVisibleBound = true; |
| 3114 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3115 | res = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3116 | } else if (mHaveConnection && SystemClock.uptimeMillis() |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 3117 | >= (mLastBindTime+TIME_TO_RECONNECT)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3118 | // The client has asked to have the input method shown, but |
| 3119 | // we have been sitting here too long with a connection to the |
| 3120 | // service and no interface received, so let's disconnect/connect |
| 3121 | // to try to prod things along. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3122 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3123 | SystemClock.uptimeMillis()-mLastBindTime,1); |
satok | 59b424c | 2011-09-30 17:21:46 +0900 | [diff] [blame] | 3124 | 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] | 3125 | mContext.unbindService(this); |
Yohei Yukawa | f80087c | 2018-05-21 09:47:53 -0700 | [diff] [blame] | 3126 | bindCurrentInputMethodServiceLocked(mCurIntent, this, IME_CONNECTION_BIND_FLAGS); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3127 | } else { |
| 3128 | if (DEBUG) { |
| 3129 | Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = " |
| 3130 | + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis())); |
| 3131 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3132 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3133 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3134 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3135 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3136 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3137 | @Override |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 3138 | public boolean hideSoftInput(IInputMethodClient client, IBinder windowToken, int flags, |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3139 | ResultReceiver resultReceiver) { |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 3140 | int uid = Binder.getCallingUid(); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3141 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3142 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3143 | return false; |
| 3144 | } |
| 3145 | final long ident = Binder.clearCallingIdentity(); |
| 3146 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3147 | if (mCurClient == null || client == null |
| 3148 | || mCurClient.client.asBinder() != client.asBinder()) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 3149 | // We need to check if this is the current client with |
| 3150 | // focus in the window manager, to allow this call to |
| 3151 | // be made before input is started in it. |
Yohei Yukawa | 41f89c3 | 2018-09-19 14:30:04 -0700 | [diff] [blame] | 3152 | final ClientState cs = mClients.get(client.asBinder()); |
| 3153 | if (cs == null) { |
| 3154 | throw new IllegalArgumentException("unknown client " + client.asBinder()); |
| 3155 | } |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 3156 | if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid, |
| 3157 | cs.selfReportedDisplayId)) { |
Yohei Yukawa | cf93f9a | 2018-08-30 15:58:47 -0700 | [diff] [blame] | 3158 | if (DEBUG) { |
| 3159 | Slog.w(TAG, "Ignoring hideSoftInput of uid " + uid + ": " + client); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3160 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3161 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3162 | } |
| 3163 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3164 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3165 | if (DEBUG) Slog.v(TAG, "Client requesting input be hidden"); |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 3166 | return hideCurrentInputLocked(windowToken, flags, resultReceiver, |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3167 | SoftInputShowHideReason.HIDE_SOFT_INPUT); |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3168 | } finally { |
| 3169 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3170 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3171 | } |
| 3172 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3173 | |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 3174 | boolean hideCurrentInputLocked(IBinder windowToken, int flags, ResultReceiver resultReceiver, |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3175 | @SoftInputShowHideReason int reason) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3176 | if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0 |
| 3177 | && (mShowExplicitlyRequested || mShowForced)) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3178 | 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] | 3179 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3180 | } |
| 3181 | if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) { |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 3182 | 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] | 3183 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3184 | } |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 3185 | |
| 3186 | // There is a chance that IMM#hideSoftInput() is called in a transient state where |
| 3187 | // IMMS#InputShown is already updated to be true whereas IMMS#mImeWindowVis is still waiting |
| 3188 | // to be updated with the new value sent from IME process. Even in such a transient state |
| 3189 | // historically we have accepted an incoming call of IMM#hideSoftInput() from the |
| 3190 | // application process as a valid request, and have even promised such a behavior with CTS |
| 3191 | // since Android Eclair. That's why we need to accept IMM#hideSoftInput() even when only |
| 3192 | // IMMS#InputShown indicates that the software keyboard is shown. |
| 3193 | // TODO: Clean up, IMMS#mInputShown, IMMS#mImeWindowVis and mShowRequested. |
| 3194 | final boolean shouldHideSoftInput = (mCurMethod != null) && (mInputShown || |
| 3195 | (mImeWindowVis & InputMethodService.IME_ACTIVE) != 0); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3196 | boolean res; |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 3197 | if (shouldHideSoftInput) { |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 3198 | final Binder hideInputToken = new Binder(); |
| 3199 | mHideRequestWindowMap.put(hideInputToken, windowToken); |
Seigo Nonaka | ec92865 | 2015-06-10 15:31:20 +0900 | [diff] [blame] | 3200 | // The IME will report its visible state again after the following message finally |
| 3201 | // delivered to the IME process as an IPC. Hence the inconsistency between |
| 3202 | // IMMS#mInputShown and IMMS#mImeWindowVis should be resolved spontaneously in |
| 3203 | // the final state. |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 3204 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOOO(MSG_HIDE_SOFT_INPUT, |
| 3205 | reason, mCurMethod, resultReceiver, hideInputToken)); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3206 | res = true; |
| 3207 | } else { |
| 3208 | res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3209 | } |
Dianne Hackborn | 2c84cfc | 2011-10-31 15:39:59 -0700 | [diff] [blame] | 3210 | if (mHaveConnection && mVisibleBound) { |
| 3211 | mContext.unbindService(mVisibleConnection); |
| 3212 | mVisibleBound = false; |
| 3213 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3214 | mInputShown = false; |
| 3215 | mShowRequested = false; |
| 3216 | mShowExplicitlyRequested = false; |
| 3217 | mShowForced = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3218 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3219 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3220 | |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 3221 | @NonNull |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3222 | @Override |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 3223 | public InputBindResult startInputOrWindowGainedFocus( |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 3224 | @StartInputReason int startInputReason, IInputMethodClient client, IBinder windowToken, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 3225 | @StartInputFlags int startInputFlags, @SoftInputModeFlags int softInputMode, |
| 3226 | int windowFlags, @Nullable EditorInfo attribute, IInputContext inputContext, |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 3227 | @MissingMethodFlags int missingMethods, int unverifiedTargetSdkVersion) { |
Yohei Yukawa | 80498d5 | 2018-06-21 16:24:36 -0700 | [diff] [blame] | 3228 | if (windowToken == null) { |
| 3229 | Slog.e(TAG, "windowToken cannot be null."); |
| 3230 | return InputBindResult.NULL; |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 3231 | } |
Yohei Yukawa | 0f5eade | 2019-01-18 08:48:07 -0800 | [diff] [blame] | 3232 | final int callingUserId = UserHandle.getCallingUserId(); |
| 3233 | final int userId; |
Yohei Yukawa | 716897c | 2019-01-22 00:00:53 -0800 | [diff] [blame] | 3234 | if (attribute != null && attribute.targetInputMethodUser != null |
Yohei Yukawa | 0f5eade | 2019-01-18 08:48:07 -0800 | [diff] [blame] | 3235 | && attribute.targetInputMethodUser.getIdentifier() != callingUserId) { |
| 3236 | mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
Yohei Yukawa | 670abea | 2019-01-28 00:00:50 -0800 | [diff] [blame] | 3237 | "Using EditorInfo.targetInputMethodUser requires INTERACT_ACROSS_USERS_FULL."); |
Yohei Yukawa | 0f5eade | 2019-01-18 08:48:07 -0800 | [diff] [blame] | 3238 | userId = attribute.targetInputMethodUser.getIdentifier(); |
| 3239 | if (!mUserManagerInternal.isUserRunning(userId)) { |
| 3240 | // There is a chance that we hit here because of race condition. Let's just return |
| 3241 | // an error code instead of crashing the caller process, which at least has |
| 3242 | // INTERACT_ACROSS_USERS_FULL permission thus is likely to be an important process. |
| 3243 | Slog.e(TAG, "User #" + userId + " is not running."); |
| 3244 | return InputBindResult.INVALID_USER; |
| 3245 | } |
| 3246 | } else { |
| 3247 | userId = callingUserId; |
| 3248 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3249 | final InputBindResult result; |
| 3250 | synchronized (mMethodMap) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3251 | final long ident = Binder.clearCallingIdentity(); |
| 3252 | try { |
| 3253 | result = startInputOrWindowGainedFocusInternalLocked(startInputReason, client, |
| 3254 | windowToken, startInputFlags, softInputMode, windowFlags, attribute, |
| 3255 | inputContext, missingMethods, unverifiedTargetSdkVersion, userId); |
| 3256 | } finally { |
| 3257 | Binder.restoreCallingIdentity(ident); |
| 3258 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3259 | } |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 3260 | if (result == null) { |
| 3261 | // This must never happen, but just in case. |
| 3262 | Slog.wtf(TAG, "InputBindResult is @NonNull. startInputReason=" |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 3263 | + InputMethodDebug.startInputReasonToString(startInputReason) |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 3264 | + " windowFlags=#" + Integer.toHexString(windowFlags) |
| 3265 | + " editorInfo=" + attribute); |
| 3266 | return InputBindResult.NULL; |
| 3267 | } |
| 3268 | return result; |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 3269 | } |
| 3270 | |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 3271 | @NonNull |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3272 | private InputBindResult startInputOrWindowGainedFocusInternalLocked( |
Yohei Yukawa | dc66e52 | 2018-10-21 10:43:14 -0700 | [diff] [blame] | 3273 | @StartInputReason int startInputReason, IInputMethodClient client, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 3274 | @NonNull IBinder windowToken, @StartInputFlags int startInputFlags, |
| 3275 | @SoftInputModeFlags int softInputMode, int windowFlags, EditorInfo attribute, |
| 3276 | IInputContext inputContext, @MissingMethodFlags int missingMethods, |
Yohei Yukawa | 4391c20 | 2019-01-28 00:49:10 -0800 | [diff] [blame] | 3277 | int unverifiedTargetSdkVersion, @UserIdInt int userId) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3278 | if (DEBUG) { |
| 3279 | Slog.v(TAG, "startInputOrWindowGainedFocusInternalLocked: reason=" |
| 3280 | + InputMethodDebug.startInputReasonToString(startInputReason) |
| 3281 | + " client=" + client.asBinder() |
| 3282 | + " inputContext=" + inputContext |
| 3283 | + " missingMethods=" |
| 3284 | + InputConnectionInspector.getMissingMethodFlagsAsString(missingMethods) |
| 3285 | + " attribute=" + attribute |
| 3286 | + " startInputFlags=" |
| 3287 | + InputMethodDebug.startInputFlagsToString(startInputFlags) |
| 3288 | + " softInputMode=" + InputMethodDebug.softInputModeToString(softInputMode) |
| 3289 | + " windowFlags=#" + Integer.toHexString(windowFlags) |
| 3290 | + " unverifiedTargetSdkVersion=" + unverifiedTargetSdkVersion); |
| 3291 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3292 | |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3293 | final int windowDisplayId = mWindowManagerInternal.getDisplayIdForWindow(windowToken); |
| 3294 | |
| 3295 | final ClientState cs = mClients.get(client.asBinder()); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3296 | if (cs == null) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3297 | throw new IllegalArgumentException("unknown client " + client.asBinder()); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3298 | } |
| 3299 | if (cs.selfReportedDisplayId != windowDisplayId) { |
| 3300 | Slog.e(TAG, "startInputOrWindowGainedFocusInternal: display ID mismatch." |
| 3301 | + " from client:" + cs.selfReportedDisplayId |
| 3302 | + " from window:" + windowDisplayId); |
| 3303 | return InputBindResult.DISPLAY_ID_MISMATCH; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3304 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 3305 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3306 | if (!mWindowManagerInternal.isInputMethodClientFocus(cs.uid, cs.pid, |
| 3307 | cs.selfReportedDisplayId)) { |
| 3308 | // Check with the window manager to make sure this client actually |
| 3309 | // has a window with focus. If not, reject. This is thread safe |
| 3310 | // because if the focus changes some time before or after, the |
| 3311 | // next client receiving focus that has any interest in input will |
| 3312 | // be calling through here after that change happens. |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3313 | if (DEBUG) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3314 | Slog.w(TAG, "Focus gain on non-focused client " + cs.client |
| 3315 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3316 | } |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3317 | return InputBindResult.NOT_IME_TARGET_WINDOW; |
| 3318 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3319 | |
Yohei Yukawa | d277d69 | 2020-02-19 17:12:17 -0800 | [diff] [blame] | 3320 | if (mUserSwitchHandlerTask != null) { |
| 3321 | // There is already an on-going pending user switch task. |
| 3322 | final int nextUserId = mUserSwitchHandlerTask.mToUserId; |
| 3323 | if (userId == nextUserId) { |
| 3324 | scheduleSwitchUserTaskLocked(userId, cs.client); |
| 3325 | return InputBindResult.USER_SWITCHING; |
| 3326 | } |
| 3327 | for (int profileId : mUserManager.getProfileIdsWithDisabled(nextUserId)) { |
| 3328 | if (profileId == userId) { |
| 3329 | scheduleSwitchUserTaskLocked(userId, cs.client); |
| 3330 | return InputBindResult.USER_SWITCHING; |
| 3331 | } |
| 3332 | } |
| 3333 | return InputBindResult.INVALID_USER; |
| 3334 | } |
| 3335 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3336 | // cross-profile access is always allowed here to allow profile-switching. |
| 3337 | if (!mSettings.isCurrentProfile(userId)) { |
| 3338 | Slog.w(TAG, "A background user is requesting window. Hiding IME."); |
| 3339 | Slog.w(TAG, "If you need to impersonate a foreground user/profile from" |
| 3340 | + " a background user, use EditorInfo.targetInputMethodUser with" |
| 3341 | + " INTERACT_ACROSS_USERS_FULL permission."); |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 3342 | hideCurrentInputLocked( |
| 3343 | mCurFocusedWindow, 0, null, SoftInputShowHideReason.HIDE_INVALID_USER); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3344 | return InputBindResult.INVALID_USER; |
| 3345 | } |
| 3346 | |
Tarandeep Singh | cf5ff82 | 2019-07-08 14:06:27 -0700 | [diff] [blame] | 3347 | if (userId != mSettings.getCurrentUserId()) { |
Yohei Yukawa | d277d69 | 2020-02-19 17:12:17 -0800 | [diff] [blame] | 3348 | scheduleSwitchUserTaskLocked(userId, cs.client); |
| 3349 | return InputBindResult.USER_SWITCHING; |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3350 | } |
Yohei Yukawa | d277d69 | 2020-02-19 17:12:17 -0800 | [diff] [blame] | 3351 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3352 | // Master feature flag that overrides other conditions and forces IME preRendering. |
| 3353 | if (DEBUG) { |
| 3354 | Slog.v(TAG, "IME PreRendering MASTER flag: " |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3355 | + DebugFlags.FLAG_PRE_RENDER_IME_VIEWS.value() + ", LowRam: " + mIsLowRam); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3356 | } |
| 3357 | // pre-rendering not supported on low-ram devices. |
| 3358 | cs.shouldPreRenderIme = DebugFlags.FLAG_PRE_RENDER_IME_VIEWS.value() && !mIsLowRam; |
| 3359 | |
| 3360 | if (mCurFocusedWindow == windowToken) { |
| 3361 | if (DEBUG) { |
| 3362 | Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client |
| 3363 | + " attribute=" + attribute + ", token = " + windowToken); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3364 | } |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3365 | if (attribute != null) { |
| 3366 | return startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 3367 | attribute, startInputFlags, startInputReason); |
| 3368 | } |
| 3369 | return new InputBindResult( |
| 3370 | InputBindResult.ResultCode.SUCCESS_REPORT_WINDOW_FOCUS_ONLY, |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 3371 | null, null, null, -1, null); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3372 | } |
| 3373 | mCurFocusedWindow = windowToken; |
| 3374 | mCurFocusedWindowSoftInputMode = softInputMode; |
| 3375 | mCurFocusedWindowClient = cs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3376 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3377 | // Should we auto-show the IME even if the caller has not |
| 3378 | // specified what should be done with it? |
| 3379 | // We only do this automatically if the window can resize |
| 3380 | // to accommodate the IME (so what the user sees will give |
| 3381 | // them good context without input information being obscured |
| 3382 | // by the IME) or if running on a large screen where there |
| 3383 | // is more room for the target window + IME. |
| 3384 | final boolean doAutoShow = |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3385 | (softInputMode & LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 3386 | == LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3387 | || mRes.getConfiguration().isLayoutSizeAtLeast( |
| 3388 | Configuration.SCREENLAYOUT_SIZE_LARGE); |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3389 | final boolean isTextEditor = (startInputFlags & StartInputFlags.IS_TEXT_EDITOR) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3390 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3391 | // We want to start input before showing the IME, but after closing |
| 3392 | // it. We want to do this after closing it to help the IME disappear |
| 3393 | // more quickly (not get stuck behind it initializing itself for the |
| 3394 | // new focused input, even if its window wants to hide the IME). |
| 3395 | boolean didStart = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3396 | |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3397 | InputBindResult res = null; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3398 | switch (softInputMode & LayoutParams.SOFT_INPUT_MASK_STATE) { |
| 3399 | case LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3400 | if (!isTextEditor || !doAutoShow) { |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3401 | if (LayoutParams.mayUseInputMethod(windowFlags)) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3402 | // There is no focus view, and this window will |
| 3403 | // be behind any soft input window, so hide the |
| 3404 | // soft input window if it is shown. |
| 3405 | if (DEBUG) Slog.v(TAG, "Unspecified window will hide input"); |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 3406 | hideCurrentInputLocked( |
| 3407 | mCurFocusedWindow, InputMethodManager.HIDE_NOT_ALWAYS, null, |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3408 | SoftInputShowHideReason.HIDE_UNSPECIFIED_WINDOW); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3409 | |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3410 | // If focused display changed, we should unbind current method |
| 3411 | // to make app window in previous display relayout after Ime |
| 3412 | // window token removed. |
| 3413 | // Note that we can trust client's display ID as long as it matches |
| 3414 | // to the display ID obtained from the window. |
| 3415 | if (cs.selfReportedDisplayId != mCurTokenDisplayId) { |
| 3416 | unbindCurrentMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3417 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3418 | } |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3419 | } else if (isTextEditor && doAutoShow |
| 3420 | && (softInputMode & LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3421 | // There is a focus view, and we are navigating forward |
| 3422 | // into the window, so show the input window for the user. |
| 3423 | // We only do this automatically if the window can resize |
| 3424 | // to accommodate the IME (so what the user sees will give |
| 3425 | // them good context without input information being obscured |
| 3426 | // by the IME) or if running on a large screen where there |
| 3427 | // is more room for the target window + IME. |
| 3428 | if (DEBUG) Slog.v(TAG, "Unspecified window will show input"); |
| 3429 | if (attribute != null) { |
| 3430 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 3431 | attribute, startInputFlags, startInputReason); |
| 3432 | didStart = true; |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3433 | } |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3434 | showCurrentInputLocked(windowToken, InputMethodManager.SHOW_IMPLICIT, null, |
| 3435 | SoftInputShowHideReason.SHOW_AUTO_EDITOR_FORWARD_NAV); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3436 | } |
| 3437 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3438 | case LayoutParams.SOFT_INPUT_STATE_UNCHANGED: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3439 | // Do nothing. |
| 3440 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3441 | case LayoutParams.SOFT_INPUT_STATE_HIDDEN: |
| 3442 | if ((softInputMode & LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3443 | if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward"); |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 3444 | hideCurrentInputLocked(mCurFocusedWindow, 0, null, |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3445 | SoftInputShowHideReason.HIDE_STATE_HIDDEN_FORWARD_NAV); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3446 | } |
| 3447 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3448 | case LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3449 | if (DEBUG) Slog.v(TAG, "Window asks to hide input"); |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 3450 | hideCurrentInputLocked(mCurFocusedWindow, 0, null, |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3451 | SoftInputShowHideReason.HIDE_ALWAYS_HIDDEN_STATE); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3452 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3453 | case LayoutParams.SOFT_INPUT_STATE_VISIBLE: |
| 3454 | if ((softInputMode & LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3455 | if (DEBUG) Slog.v(TAG, "Window asks to show input going forward"); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3456 | if (InputMethodUtils.isSoftInputModeStateVisibleAllowed( |
| 3457 | unverifiedTargetSdkVersion, startInputFlags)) { |
| 3458 | if (attribute != null) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3459 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 3460 | attribute, startInputFlags, startInputReason); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3461 | didStart = true; |
| 3462 | } |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3463 | showCurrentInputLocked(windowToken, InputMethodManager.SHOW_IMPLICIT, null, |
| 3464 | SoftInputShowHideReason.SHOW_STATE_VISIBLE_FORWARD_NAV); |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3465 | } else { |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3466 | Slog.e(TAG, "SOFT_INPUT_STATE_VISIBLE is ignored because" |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3467 | + " there is no focused view that also returns true from" |
| 3468 | + " View#onCheckIsTextEditor()"); |
| 3469 | } |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3470 | } |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3471 | break; |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 3472 | case LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3473 | if (DEBUG) Slog.v(TAG, "Window asks to always show input"); |
| 3474 | if (InputMethodUtils.isSoftInputModeStateVisibleAllowed( |
| 3475 | unverifiedTargetSdkVersion, startInputFlags)) { |
| 3476 | if (attribute != null) { |
| 3477 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, |
| 3478 | attribute, startInputFlags, startInputReason); |
| 3479 | didStart = true; |
| 3480 | } |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3481 | showCurrentInputLocked(windowToken, InputMethodManager.SHOW_IMPLICIT, null, |
| 3482 | SoftInputShowHideReason.SHOW_STATE_ALWAYS_VISIBLE); |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3483 | } else { |
| 3484 | Slog.e(TAG, "SOFT_INPUT_STATE_ALWAYS_VISIBLE is ignored because" |
| 3485 | + " there is no focused view that also returns true from" |
| 3486 | + " View#onCheckIsTextEditor()"); |
| 3487 | } |
| 3488 | break; |
| 3489 | } |
| 3490 | |
| 3491 | if (!didStart) { |
| 3492 | if (attribute != null) { |
| 3493 | if (!DebugFlags.FLAG_OPTIMIZE_START_INPUT.value() |
| 3494 | || (startInputFlags & StartInputFlags.IS_TEXT_EDITOR) != 0) { |
Yohei Yukawa | 6746452 | 2019-01-28 00:50:09 -0800 | [diff] [blame] | 3495 | res = startInputUncheckedLocked(cs, inputContext, missingMethods, attribute, |
Yohei Yukawa | 13dc12f | 2019-01-28 00:49:24 -0800 | [diff] [blame] | 3496 | startInputFlags, startInputReason); |
| 3497 | } else { |
| 3498 | res = InputBindResult.NO_EDITOR; |
| 3499 | } |
| 3500 | } else { |
| 3501 | res = InputBindResult.NULL_EDITOR_INFO; |
Yohei Yukawa | 7cc3356 | 2019-01-28 00:49:18 -0800 | [diff] [blame] | 3502 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3503 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 3504 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3505 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3506 | |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3507 | private boolean canShowInputMethodPickerLocked(IInputMethodClient client) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 3508 | // TODO(yukawa): multi-display support. |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3509 | final int uid = Binder.getCallingUid(); |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3510 | if (mCurFocusedWindowClient != null && client != null |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 3511 | && mCurFocusedWindowClient.client.asBinder() == client.asBinder()) { |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3512 | return true; |
| 3513 | } else if (mCurIntent != null && InputMethodUtils.checkIfPackageBelongsToUid( |
| 3514 | mAppOpsManager, |
| 3515 | uid, |
| 3516 | mCurIntent.getComponent().getPackageName())) { |
| 3517 | return true; |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3518 | } |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3519 | return false; |
| 3520 | } |
| 3521 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3522 | @Override |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 3523 | public void showInputMethodPickerFromClient( |
| 3524 | IInputMethodClient client, int auxiliarySubtypeMode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3525 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3526 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3527 | return; |
| 3528 | } |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3529 | if(!canShowInputMethodPickerLocked(client)) { |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 3530 | Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid " |
Dianne Hackborn | cef65ee | 2010-09-30 18:27:22 -0700 | [diff] [blame] | 3531 | + Binder.getCallingUid() + ": " + client); |
Guliz Tuncay | 6908c15 | 2017-06-02 16:06:10 -0700 | [diff] [blame] | 3532 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3533 | } |
| 3534 | |
satok | 440aab5 | 2010-11-25 09:43:11 +0900 | [diff] [blame] | 3535 | // Always call subtype picker, because subtype picker is a superset of input method |
| 3536 | // picker. |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3537 | mHandler.sendMessage(mCaller.obtainMessageII( |
| 3538 | MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, |
| 3539 | (mCurClient != null) ? mCurClient.selfReportedDisplayId : DEFAULT_DISPLAY)); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3540 | } |
| 3541 | } |
| 3542 | |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 3543 | @Override |
| 3544 | public void showInputMethodPickerFromSystem(IInputMethodClient client, int auxiliarySubtypeMode, |
| 3545 | int displayId) { |
| 3546 | if (mContext.checkCallingPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 3547 | != PackageManager.PERMISSION_GRANTED) { |
| 3548 | throw new SecurityException( |
| 3549 | "showInputMethodPickerFromSystem requires WRITE_SECURE_SETTINGS permission"); |
| 3550 | } |
| 3551 | // Always call subtype picker, because subtype picker is a superset of input method |
| 3552 | // picker. |
| 3553 | mHandler.sendMessage(mCaller.obtainMessageII( |
| 3554 | MSG_SHOW_IM_SUBTYPE_PICKER, auxiliarySubtypeMode, displayId)); |
| 3555 | } |
| 3556 | |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 3557 | public boolean isInputMethodPickerShownForTest() { |
| 3558 | synchronized(mMethodMap) { |
| 3559 | if (mSwitchingDialog == null) { |
| 3560 | return false; |
| 3561 | } |
| 3562 | return mSwitchingDialog.isShowing(); |
| 3563 | } |
| 3564 | } |
| 3565 | |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 3566 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3567 | private void setInputMethod(@NonNull IBinder token, String id) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3568 | synchronized (mMethodMap) { |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 3569 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3570 | return; |
| 3571 | } |
| 3572 | setInputMethodWithSubtypeIdLocked(token, id, NOT_A_SUBTYPE_ID); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3573 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3574 | } |
| 3575 | |
Yohei Yukawa | 4773ee1 | 2018-12-24 21:13:53 -0800 | [diff] [blame] | 3576 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3577 | private void setInputMethodAndSubtype(@NonNull IBinder token, String id, |
| 3578 | InputMethodSubtype subtype) { |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3579 | synchronized (mMethodMap) { |
Yohei Yukawa | 4773ee1 | 2018-12-24 21:13:53 -0800 | [diff] [blame] | 3580 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3581 | return; |
| 3582 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3583 | if (subtype != null) { |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3584 | setInputMethodWithSubtypeIdLocked(token, id, |
| 3585 | InputMethodUtils.getSubtypeIdFromHashCode(mMethodMap.get(id), |
| 3586 | subtype.hashCode())); |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 3587 | } else { |
| 3588 | setInputMethod(token, id); |
| 3589 | } |
| 3590 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 3591 | } |
| 3592 | |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 3593 | @Override |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3594 | public void showInputMethodAndSubtypeEnablerFromClient( |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 3595 | IInputMethodClient client, String inputMethodId) { |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3596 | synchronized (mMethodMap) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3597 | // TODO(yukawa): Should we verify the display ID? |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3598 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3599 | return; |
| 3600 | } |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 3601 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 3602 | MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId)); |
satok | b416a71 | 2010-11-25 20:42:14 +0900 | [diff] [blame] | 3603 | } |
| 3604 | } |
| 3605 | |
Yohei Yukawa | 0c49908 | 2018-12-09 18:52:02 -0800 | [diff] [blame] | 3606 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3607 | private boolean switchToPreviousInputMethod(@NonNull IBinder token) { |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3608 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3609 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 0c49908 | 2018-12-09 18:52:02 -0800 | [diff] [blame] | 3610 | return false; |
| 3611 | } |
satok | c445bcd | 2011-01-25 18:57:24 +0900 | [diff] [blame] | 3612 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3613 | final InputMethodInfo lastImi; |
satok | 208d563 | 2011-05-20 22:13:38 +0900 | [diff] [blame] | 3614 | if (lastIme != null) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3615 | lastImi = mMethodMap.get(lastIme.first); |
| 3616 | } else { |
| 3617 | lastImi = null; |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3618 | } |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3619 | String targetLastImiId = null; |
| 3620 | int subtypeId = NOT_A_SUBTYPE_ID; |
| 3621 | if (lastIme != null && lastImi != null) { |
| 3622 | final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId); |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3623 | final int lastSubtypeHash = Integer.parseInt(lastIme.second); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3624 | final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID |
| 3625 | : mCurrentSubtype.hashCode(); |
| 3626 | // If the last IME is the same as the current IME and the last subtype is not |
| 3627 | // defined, there is no need to switch to the last IME. |
| 3628 | if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) { |
| 3629 | targetLastImiId = lastIme.first; |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3630 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3631 | } |
| 3632 | } |
| 3633 | |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3634 | if (TextUtils.isEmpty(targetLastImiId) |
| 3635 | && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3636 | // This is a safety net. If the currentSubtype can't be added to the history |
| 3637 | // and the framework couldn't find the last ime, we will make the last ime be |
| 3638 | // the most applicable enabled keyboard subtype of the system imes. |
| 3639 | final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked(); |
| 3640 | if (enabled != null) { |
| 3641 | final int N = enabled.size(); |
| 3642 | final String locale = mCurrentSubtype == null |
| 3643 | ? mRes.getConfiguration().locale.toString() |
| 3644 | : mCurrentSubtype.getLocale(); |
| 3645 | for (int i = 0; i < N; ++i) { |
| 3646 | final InputMethodInfo imi = enabled.get(i); |
Yohei Yukawa | fd70fe8 | 2018-04-08 12:19:56 -0700 | [diff] [blame] | 3647 | if (imi.getSubtypeCount() > 0 && imi.isSystem()) { |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3648 | InputMethodSubtype keyboardSubtype = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3649 | InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, |
| 3650 | InputMethodUtils.getSubtypes(imi), |
| 3651 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3652 | if (keyboardSubtype != null) { |
| 3653 | targetLastImiId = imi.getId(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3654 | subtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3655 | imi, keyboardSubtype.hashCode()); |
| 3656 | if(keyboardSubtype.getLocale().equals(locale)) { |
| 3657 | break; |
| 3658 | } |
| 3659 | } |
| 3660 | } |
| 3661 | } |
| 3662 | } |
| 3663 | } |
| 3664 | |
| 3665 | if (!TextUtils.isEmpty(targetLastImiId)) { |
| 3666 | if (DEBUG) { |
| 3667 | Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second |
| 3668 | + ", from: " + mCurMethodId + ", " + subtypeId); |
| 3669 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3670 | setInputMethodWithSubtypeIdLocked(token, targetLastImiId, subtypeId); |
satok | 4fc87d6 | 2011-05-20 16:13:43 +0900 | [diff] [blame] | 3671 | return true; |
| 3672 | } else { |
| 3673 | return false; |
| 3674 | } |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 3675 | } |
| 3676 | } |
| 3677 | |
Yohei Yukawa | 70f17e7 | 2018-12-09 18:51:38 -0800 | [diff] [blame] | 3678 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 3679 | private boolean switchToNextInputMethod(@NonNull IBinder token, boolean onlyCurrentIme) { |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3680 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3681 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 3682 | return false; |
| 3683 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3684 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | 136b6ce | 2018-05-02 10:55:35 -0700 | [diff] [blame] | 3685 | onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3686 | if (nextSubtype == null) { |
| 3687 | return false; |
| 3688 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3689 | setInputMethodWithSubtypeIdLocked(token, nextSubtype.mImi.getId(), |
| 3690 | nextSubtype.mSubtypeId); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 3691 | return true; |
| 3692 | } |
| 3693 | } |
| 3694 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 3695 | @BinderThread |
| 3696 | private boolean shouldOfferSwitchingToNextInputMethod(@NonNull IBinder token) { |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 3697 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3698 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | a075574 | 2014-06-04 20:28:18 +0900 | [diff] [blame] | 3699 | return false; |
| 3700 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3701 | final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked( |
Yohei Yukawa | 136b6ce | 2018-05-02 10:55:35 -0700 | [diff] [blame] | 3702 | false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype); |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 3703 | if (nextSubtype == null) { |
| 3704 | return false; |
| 3705 | } |
| 3706 | return true; |
| 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | @Override |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3711 | public InputMethodSubtype getLastInputMethodSubtype() { |
| 3712 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3713 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3714 | return null; |
| 3715 | } |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3716 | final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked(); |
| 3717 | // TODO: Handle the case of the last IME with no subtypes |
| 3718 | if (lastIme == null || TextUtils.isEmpty(lastIme.first) |
| 3719 | || TextUtils.isEmpty(lastIme.second)) return null; |
| 3720 | final InputMethodInfo lastImi = mMethodMap.get(lastIme.first); |
| 3721 | if (lastImi == null) return null; |
| 3722 | try { |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 3723 | final int lastSubtypeHash = Integer.parseInt(lastIme.second); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 3724 | final int lastSubtypeId = |
| 3725 | InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash); |
satok | 0e7d7d6 | 2011-07-05 13:28:06 +0900 | [diff] [blame] | 3726 | if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) { |
| 3727 | return null; |
| 3728 | } |
| 3729 | return lastImi.getSubtypeAt(lastSubtypeId); |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 3730 | } catch (NumberFormatException e) { |
| 3731 | return null; |
| 3732 | } |
| 3733 | } |
| 3734 | } |
| 3735 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3736 | @Override |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3737 | public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) { |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3738 | // By this IPC call, only a process which shares the same uid with the IME can add |
| 3739 | // additional input method subtypes to the IME. |
Yohei Yukawa | 70f5c48 | 2016-01-04 19:42:36 -0800 | [diff] [blame] | 3740 | if (TextUtils.isEmpty(imiId) || subtypes == null) return; |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3741 | final ArrayList<InputMethodSubtype> toBeAdded = new ArrayList<>(); |
| 3742 | for (InputMethodSubtype subtype : subtypes) { |
| 3743 | if (!toBeAdded.contains(subtype)) { |
| 3744 | toBeAdded.add(subtype); |
| 3745 | } else { |
| 3746 | Slog.w(TAG, "Duplicated subtype definition found: " |
| 3747 | + subtype.getLocale() + ", " + subtype.getMode()); |
| 3748 | } |
| 3749 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3750 | synchronized (mMethodMap) { |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 3751 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 3752 | return; |
| 3753 | } |
Yohei Yukawa | 7924782 | 2017-01-23 15:26:15 -0800 | [diff] [blame] | 3754 | if (!mSystemReady) { |
| 3755 | return; |
| 3756 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3757 | final InputMethodInfo imi = mMethodMap.get(imiId); |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3758 | if (imi == null) return; |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 3759 | final String[] packageInfos; |
| 3760 | try { |
| 3761 | packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid()); |
| 3762 | } catch (RemoteException e) { |
| 3763 | Slog.e(TAG, "Failed to get package infos"); |
| 3764 | return; |
| 3765 | } |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3766 | if (packageInfos != null) { |
| 3767 | final int packageNum = packageInfos.length; |
| 3768 | for (int i = 0; i < packageNum; ++i) { |
| 3769 | if (packageInfos[i].equals(imi.getPackageName())) { |
Yohei Yukawa | 7b1c8d7 | 2018-12-19 11:21:04 -0800 | [diff] [blame] | 3770 | if (subtypes.length > 0) { |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3771 | mAdditionalSubtypeMap.put(imi.getId(), toBeAdded); |
Yohei Yukawa | 7b1c8d7 | 2018-12-19 11:21:04 -0800 | [diff] [blame] | 3772 | } else { |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3773 | mAdditionalSubtypeMap.remove(imi.getId()); |
Yohei Yukawa | 7b1c8d7 | 2018-12-19 11:21:04 -0800 | [diff] [blame] | 3774 | } |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 3775 | AdditionalSubtypeUtils.save(mAdditionalSubtypeMap, mMethodMap, |
| 3776 | mSettings.getCurrentUserId()); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 3777 | final long ident = Binder.clearCallingIdentity(); |
| 3778 | try { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 3779 | buildInputMethodListLocked(false /* resetDefaultEnabledIme */); |
satok | c593380 | 2011-08-31 21:26:04 +0900 | [diff] [blame] | 3780 | } finally { |
| 3781 | Binder.restoreCallingIdentity(ident); |
| 3782 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3783 | return; |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 3784 | } |
| 3785 | } |
| 3786 | } |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3787 | } |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 3788 | return; |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 3789 | } |
| 3790 | |
Yohei Yukawa | b985e6e | 2018-09-05 17:07:52 -0700 | [diff] [blame] | 3791 | /** |
Artur Satayev | 192ca30 | 2020-01-22 21:38:23 +0000 | [diff] [blame] | 3792 | * This is kept due to {@code @UnsupportedAppUsage} in |
Yohei Yukawa | b985e6e | 2018-09-05 17:07:52 -0700 | [diff] [blame] | 3793 | * {@link InputMethodManager#getInputMethodWindowVisibleHeight()} and a dependency in |
| 3794 | * {@link InputMethodService#onCreate()}. |
| 3795 | * |
| 3796 | * <p>TODO(Bug 113914148): Check if we can remove this.</p> |
| 3797 | * @return {@link WindowManagerInternal#getInputMethodWindowVisibleHeight()} |
| 3798 | */ |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 3799 | @Override |
| 3800 | public int getInputMethodWindowVisibleHeight() { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 3801 | // TODO(yukawa): Should we verify the display ID? |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 3802 | return mWindowManagerInternal.getInputMethodWindowVisibleHeight(mCurTokenDisplayId); |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 3803 | } |
| 3804 | |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 3805 | @Override |
| 3806 | public void reportActivityView(IInputMethodClient parentClient, int childDisplayId, |
| 3807 | float[] matrixValues) { |
| 3808 | final DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(childDisplayId); |
| 3809 | if (displayInfo == null) { |
| 3810 | throw new IllegalArgumentException( |
| 3811 | "Cannot find display for non-existent displayId: " + childDisplayId); |
| 3812 | } |
| 3813 | final int callingUid = Binder.getCallingUid(); |
| 3814 | if (callingUid != displayInfo.ownerUid) { |
| 3815 | throw new SecurityException("The caller doesn't own the display."); |
| 3816 | } |
| 3817 | |
| 3818 | synchronized (mMethodMap) { |
| 3819 | final ClientState cs = mClients.get(parentClient.asBinder()); |
| 3820 | if (cs == null) { |
| 3821 | return; |
| 3822 | } |
| 3823 | |
| 3824 | // null matrixValues means that the entry needs to be removed. |
| 3825 | if (matrixValues == null) { |
| 3826 | final ActivityViewInfo info = mActivityViewDisplayIdToParentMap.get(childDisplayId); |
| 3827 | if (info == null) { |
| 3828 | return; |
| 3829 | } |
| 3830 | if (info.mParentClient != cs) { |
| 3831 | throw new SecurityException("Only the owner client can clear" |
| 3832 | + " ActivityViewGeometry for display #" + childDisplayId); |
| 3833 | } |
| 3834 | mActivityViewDisplayIdToParentMap.remove(childDisplayId); |
| 3835 | return; |
| 3836 | } |
| 3837 | |
| 3838 | ActivityViewInfo info = mActivityViewDisplayIdToParentMap.get(childDisplayId); |
| 3839 | if (info != null && info.mParentClient != cs) { |
| 3840 | throw new InvalidParameterException("Display #" + childDisplayId |
| 3841 | + " is already registered by " + info.mParentClient); |
| 3842 | } |
| 3843 | if (info == null) { |
| 3844 | if (!mWindowManagerInternal.isUidAllowedOnDisplay(childDisplayId, cs.uid)) { |
| 3845 | throw new SecurityException(cs + " cannot access to display #" |
| 3846 | + childDisplayId); |
| 3847 | } |
| 3848 | info = new ActivityViewInfo(cs, new Matrix()); |
| 3849 | mActivityViewDisplayIdToParentMap.put(childDisplayId, info); |
| 3850 | } |
| 3851 | info.mMatrix.setValues(matrixValues); |
| 3852 | |
| 3853 | if (mCurClient == null || mCurClient.curSession == null) { |
| 3854 | return; |
| 3855 | } |
| 3856 | |
| 3857 | Matrix matrix = null; |
| 3858 | int displayId = mCurClient.selfReportedDisplayId; |
| 3859 | boolean needToNotify = false; |
| 3860 | while (true) { |
| 3861 | needToNotify |= (displayId == childDisplayId); |
| 3862 | final ActivityViewInfo next = mActivityViewDisplayIdToParentMap.get(displayId); |
| 3863 | if (next == null) { |
| 3864 | break; |
| 3865 | } |
| 3866 | if (matrix == null) { |
| 3867 | matrix = new Matrix(next.mMatrix); |
| 3868 | } else { |
| 3869 | matrix.postConcat(next.mMatrix); |
| 3870 | } |
| 3871 | if (next.mParentClient.selfReportedDisplayId == mCurTokenDisplayId) { |
| 3872 | if (needToNotify) { |
| 3873 | final float[] values = new float[9]; |
| 3874 | matrix.getValues(values); |
| 3875 | try { |
| 3876 | mCurClient.client.updateActivityViewToScreenMatrix(mCurSeq, values); |
| 3877 | } catch (RemoteException e) { |
| 3878 | } |
| 3879 | } |
| 3880 | break; |
| 3881 | } |
| 3882 | displayId = info.mParentClient.selfReportedDisplayId; |
| 3883 | } |
| 3884 | } |
| 3885 | } |
| 3886 | |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 3887 | @BinderThread |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3888 | private void notifyUserAction(@NonNull IBinder token) { |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3889 | if (DEBUG) { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3890 | Slog.d(TAG, "Got the notification of a user action."); |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3891 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3892 | synchronized (mMethodMap) { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3893 | if (mCurToken != token) { |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3894 | if (DEBUG) { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 3895 | Slog.d(TAG, "Ignoring the user action notification from IMEs that are no longer" |
| 3896 | + " active."); |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 3897 | } |
| 3898 | return; |
| 3899 | } |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3900 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 3901 | if (imi != null) { |
Yohei Yukawa | 0297051 | 2014-06-05 16:16:18 +0900 | [diff] [blame] | 3902 | mSwitchingController.onUserActionLocked(imi, mCurrentSubtype); |
Yohei Yukawa | 5a647b69 | 2014-05-22 12:49:00 +0900 | [diff] [blame] | 3903 | } |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 3904 | } |
| 3905 | } |
| 3906 | |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 3907 | @BinderThread |
| 3908 | private void reportPreRendered(IBinder token, EditorInfo info) { |
| 3909 | synchronized (mMethodMap) { |
| 3910 | if (!calledWithValidTokenLocked(token)) { |
| 3911 | return; |
| 3912 | } |
| 3913 | if (mCurClient != null && mCurClient.client != null) { |
| 3914 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
| 3915 | MSG_REPORT_PRE_RENDERED, info, mCurClient)); |
| 3916 | } |
| 3917 | } |
| 3918 | } |
| 3919 | |
| 3920 | @BinderThread |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 3921 | private void applyImeVisibility(IBinder token, IBinder windowToken, boolean setVisible) { |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 3922 | synchronized (mMethodMap) { |
| 3923 | if (!calledWithValidTokenLocked(token)) { |
| 3924 | return; |
| 3925 | } |
Tarandeep Singh | 500a38f | 2019-09-26 13:36:40 -0700 | [diff] [blame] | 3926 | if (!setVisible) { |
Taran Singh | d7fc586 | 2019-10-10 14:45:17 +0200 | [diff] [blame] | 3927 | if (mCurClient != null) { |
| 3928 | // IMMS only knows of focused window, not the actual IME target. |
| 3929 | // e.g. it isn't aware of any window that has both |
| 3930 | // NOT_FOCUSABLE, ALT_FOCUSABLE_IM flags set and can the IME target. |
| 3931 | // Send it to window manager to hide IME from IME target window. |
| 3932 | // TODO(b/139861270): send to mCurClient.client once IMMS is aware of |
| 3933 | // actual IME target. |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 3934 | mWindowManagerInternal.hideIme(mHideRequestWindowMap.get(windowToken)); |
Tarandeep Singh | 500a38f | 2019-09-26 13:36:40 -0700 | [diff] [blame] | 3935 | } |
| 3936 | } else { |
| 3937 | // Send to window manager to show IME after IME layout finishes. |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 3938 | mWindowManagerInternal.showImePostLayout(mShowRequestWindowMap.get(windowToken)); |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 3939 | } |
| 3940 | } |
| 3941 | } |
| 3942 | |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3943 | private void setInputMethodWithSubtypeIdLocked(IBinder token, String id, int subtypeId) { |
| 3944 | if (token == null) { |
| 3945 | if (mContext.checkCallingOrSelfPermission( |
| 3946 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 3947 | != PackageManager.PERMISSION_GRANTED) { |
| 3948 | throw new SecurityException( |
| 3949 | "Using null token requires permission " |
| 3950 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3951 | } |
Yohei Yukawa | 4e02bc6 | 2014-06-04 18:37:20 +0900 | [diff] [blame] | 3952 | } else if (mCurToken != token) { |
| 3953 | Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid() |
| 3954 | + " token: " + token); |
| 3955 | return; |
| 3956 | } |
| 3957 | |
| 3958 | final long ident = Binder.clearCallingIdentity(); |
| 3959 | try { |
| 3960 | setInputMethodLocked(id, subtypeId); |
| 3961 | } finally { |
| 3962 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3963 | } |
| 3964 | } |
| 3965 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 3966 | @BinderThread |
| 3967 | private void hideMySoftInput(@NonNull IBinder token, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3968 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3969 | if (!calledWithValidTokenLocked(token)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3970 | return; |
| 3971 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3972 | long ident = Binder.clearCallingIdentity(); |
| 3973 | try { |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 3974 | hideCurrentInputLocked( |
| 3975 | mLastImeTargetWindow, flags, null, |
| 3976 | SoftInputShowHideReason.HIDE_MY_SOFT_INPUT); |
| 3977 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3978 | } finally { |
| 3979 | Binder.restoreCallingIdentity(ident); |
| 3980 | } |
| 3981 | } |
| 3982 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 3983 | |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 3984 | @BinderThread |
| 3985 | private void showMySoftInput(@NonNull IBinder token, int flags) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3986 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 3987 | if (!calledWithValidTokenLocked(token)) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 3988 | return; |
| 3989 | } |
| 3990 | long ident = Binder.clearCallingIdentity(); |
| 3991 | try { |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 3992 | showCurrentInputLocked(mLastImeTargetWindow, flags, null, |
| 3993 | SoftInputShowHideReason.SHOW_MY_SOFT_INPUT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3994 | } finally { |
| 3995 | Binder.restoreCallingIdentity(ident); |
| 3996 | } |
| 3997 | } |
| 3998 | } |
| 3999 | |
| 4000 | void setEnabledSessionInMainThread(SessionState session) { |
| 4001 | if (mEnabledSession != session) { |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 4002 | if (mEnabledSession != null && mEnabledSession.session != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4003 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4004 | if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession); |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 4005 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4006 | } catch (RemoteException e) { |
| 4007 | } |
| 4008 | } |
| 4009 | mEnabledSession = session; |
Yohei Yukawa | 9d91b43 | 2014-05-19 16:03:24 +0900 | [diff] [blame] | 4010 | if (mEnabledSession != null && mEnabledSession.session != null) { |
| 4011 | try { |
| 4012 | if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession); |
| 4013 | mEnabledSession.method.setSessionEnabled(mEnabledSession.session, true); |
| 4014 | } catch (RemoteException e) { |
| 4015 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4016 | } |
| 4017 | } |
| 4018 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4019 | |
Yohei Yukawa | 930328c | 2017-10-18 20:19:53 -0700 | [diff] [blame] | 4020 | @MainThread |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 4021 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4022 | public boolean handleMessage(Message msg) { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4023 | SomeArgs args; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4024 | switch (msg.what) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4025 | case MSG_SHOW_IM_SUBTYPE_PICKER: |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 4026 | final boolean showAuxSubtypes; |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 4027 | final int displayId = msg.arg2; |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 4028 | switch (msg.arg1) { |
| 4029 | case InputMethodManager.SHOW_IM_PICKER_MODE_AUTO: |
| 4030 | // This is undocumented so far, but IMM#showInputMethodPicker() has been |
| 4031 | // implemented so that auxiliary subtypes will be excluded when the soft |
| 4032 | // keyboard is invisible. |
| 4033 | showAuxSubtypes = mInputShown; |
| 4034 | break; |
| 4035 | case InputMethodManager.SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES: |
| 4036 | showAuxSubtypes = true; |
| 4037 | break; |
| 4038 | case InputMethodManager.SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES: |
| 4039 | showAuxSubtypes = false; |
| 4040 | break; |
| 4041 | default: |
| 4042 | Slog.e(TAG, "Unknown subtype picker mode = " + msg.arg1); |
| 4043 | return false; |
| 4044 | } |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 4045 | showInputMethodMenu(showAuxSubtypes, displayId); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4046 | return true; |
| 4047 | |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 4048 | case MSG_SHOW_IM_SUBTYPE_ENABLER: |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 4049 | showInputMethodAndSubtypeEnabler((String)msg.obj); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 4050 | return true; |
| 4051 | |
| 4052 | case MSG_SHOW_IM_CONFIG: |
| 4053 | showConfigureInputMethods(); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 4054 | return true; |
| 4055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4056 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4057 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4058 | case MSG_UNBIND_INPUT: |
| 4059 | try { |
| 4060 | ((IInputMethod)msg.obj).unbindInput(); |
| 4061 | } catch (RemoteException e) { |
| 4062 | // There is nothing interesting about the method dying. |
| 4063 | } |
| 4064 | return true; |
| 4065 | case MSG_BIND_INPUT: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4066 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4067 | try { |
| 4068 | ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2); |
| 4069 | } catch (RemoteException e) { |
| 4070 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4071 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4072 | return true; |
| 4073 | case MSG_SHOW_SOFT_INPUT: |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 4074 | args = (SomeArgs) msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4075 | try { |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 4076 | final @SoftInputShowHideReason int reason = msg.arg2; |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 4077 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput(" |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 4078 | + args.arg3 + ", " + msg.arg1 + ", " + args.arg2 + ") for reason: " |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 4079 | + InputMethodDebug.softInputDisplayReasonToString(reason)); |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 4080 | ((IInputMethod) args.arg1).showSoftInput( |
| 4081 | (IBinder) args.arg3, msg.arg1, (ResultReceiver) args.arg2); |
Anmol Gupta | 29f209d | 2020-03-11 11:34:46 -0700 | [diff] [blame] | 4082 | mSoftInputShowHideHistory.addEntry(new SoftInputShowHideHistory.Entry( |
| 4083 | mCurClient, mCurAttribute, |
| 4084 | mWindowManagerInternal.getWindowName(mCurFocusedWindow), |
| 4085 | mCurFocusedWindowSoftInputMode, reason, mInFullscreenMode, |
| 4086 | mWindowManagerInternal.getWindowName( |
| 4087 | mShowRequestWindowMap.get(args.arg3)))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4088 | } catch (RemoteException e) { |
| 4089 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4090 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4091 | return true; |
| 4092 | case MSG_HIDE_SOFT_INPUT: |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 4093 | args = (SomeArgs) msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4094 | try { |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 4095 | final @SoftInputShowHideReason int reason = msg.arg1; |
Craig Mautner | e4bbb1c | 2013-03-15 11:38:44 -0700 | [diff] [blame] | 4096 | if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, " |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 4097 | + args.arg3 + ", " + args.arg2 + ") for reason: " |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 4098 | + InputMethodDebug.softInputDisplayReasonToString(reason)); |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 4099 | ((IInputMethod)args.arg1).hideSoftInput( |
| 4100 | (IBinder) args.arg3, 0, (ResultReceiver)args.arg2); |
Anmol Gupta | 29f209d | 2020-03-11 11:34:46 -0700 | [diff] [blame] | 4101 | mSoftInputShowHideHistory.addEntry(new SoftInputShowHideHistory.Entry( |
| 4102 | mCurClient, mCurAttribute, |
| 4103 | mWindowManagerInternal.getWindowName(mCurFocusedWindow), |
| 4104 | mCurFocusedWindowSoftInputMode, reason, mInFullscreenMode, |
| 4105 | mWindowManagerInternal.getWindowName( |
| 4106 | mHideRequestWindowMap.get(args.arg3)))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4107 | } catch (RemoteException e) { |
| 4108 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4109 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4110 | return true; |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 4111 | case MSG_HIDE_CURRENT_INPUT_METHOD: |
| 4112 | synchronized (mMethodMap) { |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 4113 | final @SoftInputShowHideReason int reason = (int) msg.obj; |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 4114 | hideCurrentInputLocked(mCurFocusedWindow, 0, null, reason); |
| 4115 | |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 4116 | } |
| 4117 | return true; |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4118 | case MSG_INITIALIZE_IME: |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4119 | args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4120 | try { |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 4121 | if (DEBUG) { |
| 4122 | Slog.v(TAG, "Sending attach of token: " + args.arg2 + " for display: " |
| 4123 | + msg.arg1); |
| 4124 | } |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4125 | final IBinder token = (IBinder) args.arg2; |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 4126 | ((IInputMethod) args.arg1).initializeInternal(token, msg.arg1, |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4127 | new InputMethodPrivilegedOperationsImpl(this, token)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4128 | } catch (RemoteException e) { |
| 4129 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4130 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4131 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 4132 | case MSG_CREATE_SESSION: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4133 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 4134 | IInputMethod method = (IInputMethod)args.arg1; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 4135 | InputChannel channel = (InputChannel)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4136 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 4137 | method.createSession(channel, (IInputSessionCallback)args.arg3); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4138 | } catch (RemoteException e) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 4139 | } finally { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 4140 | // Dispose the channel if the input method is not local to this process |
| 4141 | // because the remote proxy will get its own copy when unparceled. |
| 4142 | if (channel != null && Binder.isProxy(method)) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 4143 | channel.dispose(); |
| 4144 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4145 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4146 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4147 | return true; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 4148 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4149 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4150 | |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 4151 | case MSG_START_INPUT: { |
Yohei Yukawa | f7526b5 | 2017-02-11 20:57:10 -0800 | [diff] [blame] | 4152 | final int missingMethods = msg.arg1; |
| 4153 | final boolean restarting = msg.arg2 != 0; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 4154 | args = (SomeArgs) msg.obj; |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 4155 | final IBinder startInputToken = (IBinder) args.arg1; |
| 4156 | final SessionState session = (SessionState) args.arg2; |
| 4157 | final IInputContext inputContext = (IInputContext) args.arg3; |
| 4158 | final EditorInfo editorInfo = (EditorInfo) args.arg4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4159 | try { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4160 | setEnabledSessionInMainThread(session); |
Yohei Yukawa | 6db3bfe | 2017-02-13 12:04:41 -0800 | [diff] [blame] | 4161 | session.method.startInput(startInputToken, inputContext, missingMethods, |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 4162 | editorInfo, restarting, session.client.shouldPreRenderIme); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4163 | } catch (RemoteException e) { |
| 4164 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4165 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4166 | return true; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 4167 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4168 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4169 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4170 | |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 4171 | case MSG_UNBIND_CLIENT: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4172 | try { |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 4173 | ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1, msg.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4174 | } catch (RemoteException e) { |
| 4175 | // There is nothing interesting about the last client dying. |
| 4176 | } |
| 4177 | return true; |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 4178 | case MSG_BIND_CLIENT: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4179 | args = (SomeArgs)msg.obj; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 4180 | IInputMethodClient client = (IInputMethodClient)args.arg1; |
| 4181 | InputBindResult res = (InputBindResult)args.arg2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4182 | try { |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 4183 | client.onBindMethod(res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4184 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4185 | Slog.w(TAG, "Client died receiving input method " + args.arg2); |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 4186 | } finally { |
| 4187 | // Dispose the channel if the input method is not local to this process |
| 4188 | // because the remote proxy will get its own copy when unparceled. |
| 4189 | if (res.channel != null && Binder.isProxy(client)) { |
| 4190 | res.channel.dispose(); |
| 4191 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4192 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 4193 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4194 | return true; |
Jeff Brown | 1951ce8 | 2013-04-04 22:45:12 -0700 | [diff] [blame] | 4195 | } |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 4196 | case MSG_SET_ACTIVE: |
| 4197 | try { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4198 | ((ClientState)msg.obj).client.setActive(msg.arg1 != 0, msg.arg2 != 0); |
Dianne Hackborn | a6e4134 | 2012-05-22 16:30:34 -0700 | [diff] [blame] | 4199 | } catch (RemoteException e) { |
| 4200 | Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid " |
| 4201 | + ((ClientState)msg.obj).pid + " uid " |
| 4202 | + ((ClientState)msg.obj).uid); |
| 4203 | } |
| 4204 | return true; |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4205 | case MSG_REPORT_FULLSCREEN_MODE: { |
| 4206 | final boolean fullscreen = msg.arg1 != 0; |
| 4207 | final ClientState clientState = (ClientState)msg.obj; |
| 4208 | try { |
| 4209 | clientState.client.reportFullscreenMode(fullscreen); |
| 4210 | } catch (RemoteException e) { |
| 4211 | Slog.w(TAG, "Got RemoteException sending " |
| 4212 | + "reportFullscreen(" + fullscreen + ") notification to pid=" |
| 4213 | + clientState.pid + " uid=" + clientState.uid); |
| 4214 | } |
| 4215 | return true; |
| 4216 | } |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 4217 | case MSG_REPORT_PRE_RENDERED: { |
| 4218 | args = (SomeArgs) msg.obj; |
| 4219 | final EditorInfo info = (EditorInfo) args.arg1; |
| 4220 | final ClientState clientState = (ClientState) args.arg2; |
| 4221 | try { |
| 4222 | clientState.client.reportPreRendered(info); |
| 4223 | } catch (RemoteException e) { |
| 4224 | Slog.w(TAG, "Got RemoteException sending " |
| 4225 | + "reportPreRendered(" + info + ") notification to pid=" |
| 4226 | + clientState.pid + " uid=" + clientState.uid); |
| 4227 | } |
| 4228 | args.recycle(); |
| 4229 | return true; |
| 4230 | } |
| 4231 | case MSG_APPLY_IME_VISIBILITY: { |
| 4232 | final boolean setVisible = msg.arg1 != 0; |
| 4233 | final ClientState clientState = (ClientState) msg.obj; |
| 4234 | try { |
| 4235 | clientState.client.applyImeVisibility(setVisible); |
| 4236 | } catch (RemoteException e) { |
| 4237 | Slog.w(TAG, "Got RemoteException sending " |
| 4238 | + "applyImeVisibility(" + setVisible + ") notification to pid=" |
| 4239 | + clientState.pid + " uid=" + clientState.uid); |
| 4240 | } |
| 4241 | return true; |
| 4242 | } |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 4243 | |
| 4244 | // -------------------------------------------------------------- |
| 4245 | case MSG_HARD_KEYBOARD_SWITCH_CHANGED: |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 4246 | mHardKeyboardListener.handleHardKeyboardStatusChange(msg.arg1 == 1); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 4247 | return true; |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 4248 | case MSG_SYSTEM_UNLOCK_USER: { |
Fyodor Kupolov | 7877b8a | 2016-06-29 14:39:19 -0700 | [diff] [blame] | 4249 | final int userId = msg.arg1; |
| 4250 | onUnlockUser(userId); |
| 4251 | return true; |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 4252 | } |
| 4253 | case MSG_DISPATCH_ON_INPUT_METHOD_LIST_UPDATED: { |
| 4254 | final int userId = msg.arg1; |
| 4255 | final List<InputMethodInfo> imes = (List<InputMethodInfo>) msg.obj; |
| 4256 | mInputMethodListListeners.forEach( |
| 4257 | listener -> listener.onInputMethodListUpdated(imes, userId)); |
| 4258 | return true; |
| 4259 | } |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4260 | |
| 4261 | // --------------------------------------------------------------- |
| 4262 | case MSG_INLINE_SUGGESTIONS_REQUEST: |
| 4263 | args = (SomeArgs) msg.obj; |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 4264 | final InlineSuggestionsRequestInfo requestInfo = |
| 4265 | (InlineSuggestionsRequestInfo) args.arg2; |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4266 | final IInlineSuggestionsRequestCallback callback = |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 4267 | (IInlineSuggestionsRequestCallback) args.arg3; |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4268 | try { |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 4269 | ((IInputMethod) args.arg1).onCreateInlineSuggestionsRequest(requestInfo, |
| 4270 | callback); |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4271 | } catch (RemoteException e) { |
| 4272 | Slog.w(TAG, "RemoteException calling onCreateInlineSuggestionsRequest(): " + e); |
| 4273 | } |
| 4274 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4275 | } |
| 4276 | return false; |
| 4277 | } |
| 4278 | |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 4279 | private boolean chooseNewDefaultIMELocked() { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4280 | final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME( |
| 4281 | mSettings.getEnabledInputMethodListLocked()); |
satok | dc9ddae | 2011-10-06 12:22:36 +0900 | [diff] [blame] | 4282 | if (imi != null) { |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 4283 | if (DEBUG) { |
| 4284 | Slog.d(TAG, "New default IME was selected: " + imi.getId()); |
| 4285 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4286 | resetSelectedInputMethodAndSubtypeLocked(imi.getId()); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 4287 | return true; |
| 4288 | } |
| 4289 | |
| 4290 | return false; |
| 4291 | } |
| 4292 | |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4293 | static void queryInputMethodServicesInternal(Context context, |
| 4294 | @UserIdInt int userId, ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap, |
| 4295 | ArrayMap<String, InputMethodInfo> methodMap, ArrayList<InputMethodInfo> methodList) { |
| 4296 | methodList.clear(); |
| 4297 | methodMap.clear(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4298 | |
Yohei Yukawa | ed4952a | 2016-02-17 07:57:25 -0800 | [diff] [blame] | 4299 | // Note: We do not specify PackageManager.MATCH_ENCRYPTION_* flags here because the default |
| 4300 | // behavior of PackageManager is exactly what we want. It by default picks up appropriate |
| 4301 | // services depending on the unlock state for the specified user. |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4302 | final List<ResolveInfo> services = context.getPackageManager().queryIntentServicesAsUser( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4303 | new Intent(InputMethod.SERVICE_INTERFACE), |
Yohei Yukawa | 5ec1fce | 2018-12-17 07:56:14 -0800 | [diff] [blame] | 4304 | PackageManager.GET_META_DATA | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS, |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4305 | userId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4306 | |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4307 | methodList.ensureCapacity(services.size()); |
| 4308 | methodMap.ensureCapacity(services.size()); |
| 4309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4310 | for (int i = 0; i < services.size(); ++i) { |
| 4311 | ResolveInfo ri = services.get(i); |
| 4312 | ServiceInfo si = ri.serviceInfo; |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 4313 | final String imeId = InputMethodInfo.computeId(ri); |
| 4314 | if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) { |
| 4315 | Slog.w(TAG, "Skipping input method " + imeId |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4316 | + ": it does not require the permission " |
| 4317 | + android.Manifest.permission.BIND_INPUT_METHOD); |
| 4318 | continue; |
| 4319 | } |
| 4320 | |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 4321 | if (DEBUG) Slog.d(TAG, "Checking " + imeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4322 | |
| 4323 | try { |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4324 | final InputMethodInfo imi = new InputMethodInfo(context, ri, |
| 4325 | additionalSubtypeMap.get(imeId)); |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 4326 | if (imi.isVrOnly()) { |
| 4327 | continue; // Skip VR-only IME, which isn't supported for now. |
| 4328 | } |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4329 | methodList.add(imi); |
| 4330 | methodMap.put(imi.getId(), imi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4331 | if (DEBUG) { |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4332 | Slog.d(TAG, "Found an input method " + imi); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4333 | } |
Tadashi G. Takaoka | 3c23d5b | 2016-09-16 11:41:07 +0900 | [diff] [blame] | 4334 | } catch (Exception e) { |
Yohei Yukawa | ddad4b9 | 2017-02-02 01:46:13 -0800 | [diff] [blame] | 4335 | 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] | 4336 | } |
| 4337 | } |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | @GuardedBy("mMethodMap") |
| 4341 | void buildInputMethodListLocked(boolean resetDefaultEnabledIme) { |
| 4342 | if (DEBUG) { |
| 4343 | Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme |
| 4344 | + " \n ------ caller=" + Debug.getCallers(10)); |
| 4345 | } |
| 4346 | if (!mSystemReady) { |
| 4347 | Slog.e(TAG, "buildInputMethodListLocked is not allowed until system is ready"); |
| 4348 | return; |
| 4349 | } |
| 4350 | mMethodMapUpdateCount++; |
| 4351 | mMyPackageMonitor.clearKnownImePackageNamesLocked(); |
| 4352 | |
| 4353 | queryInputMethodServicesInternal(mContext, mSettings.getCurrentUserId(), |
Yohei Yukawa | b557d57 | 2018-12-29 21:26:26 -0800 | [diff] [blame] | 4354 | mAdditionalSubtypeMap, mMethodMap, mMethodList); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 4355 | |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 4356 | // Construct the set of possible IME packages for onPackageChanged() to avoid false |
| 4357 | // negatives when the package state remains to be the same but only the component state is |
| 4358 | // changed. |
| 4359 | { |
| 4360 | // Here we intentionally use PackageManager.MATCH_DISABLED_COMPONENTS since the purpose |
| 4361 | // of this query is to avoid false negatives. PackageManager.MATCH_ALL could be more |
| 4362 | // conservative, but it seems we cannot use it for now (Issue 35176630). |
Yohei Yukawa | 0513932 | 2018-12-25 10:34:14 -0800 | [diff] [blame] | 4363 | final List<ResolveInfo> allInputMethodServices = |
| 4364 | mContext.getPackageManager().queryIntentServicesAsUser( |
| 4365 | new Intent(InputMethod.SERVICE_INTERFACE), |
| 4366 | PackageManager.MATCH_DISABLED_COMPONENTS, mSettings.getCurrentUserId()); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 4367 | final int N = allInputMethodServices.size(); |
| 4368 | for (int i = 0; i < N; ++i) { |
| 4369 | final ServiceInfo si = allInputMethodServices.get(i).serviceInfo; |
Yohei Yukawa | 5e3e8a5 | 2017-02-14 20:05:17 -0800 | [diff] [blame] | 4370 | if (android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) { |
| 4371 | mMyPackageMonitor.addKnownImePackageNameLocked(si.packageName); |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 4372 | } |
Yohei Yukawa | c4e4491 | 2017-02-09 19:30:22 -0800 | [diff] [blame] | 4373 | } |
| 4374 | } |
| 4375 | |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4376 | boolean reenableMinimumNonAuxSystemImes = false; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 4377 | // TODO: The following code should find better place to live. |
| 4378 | if (!resetDefaultEnabledIme) { |
| 4379 | boolean enabledImeFound = false; |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4380 | boolean enabledNonAuxImeFound = false; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 4381 | final List<InputMethodInfo> enabledImes = mSettings.getEnabledInputMethodListLocked(); |
| 4382 | final int N = enabledImes.size(); |
| 4383 | for (int i = 0; i < N; ++i) { |
| 4384 | final InputMethodInfo imi = enabledImes.get(i); |
| 4385 | if (mMethodList.contains(imi)) { |
| 4386 | enabledImeFound = true; |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4387 | if (!imi.isAuxiliaryIme()) { |
| 4388 | enabledNonAuxImeFound = true; |
| 4389 | break; |
| 4390 | } |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 4391 | } |
| 4392 | } |
| 4393 | if (!enabledImeFound) { |
Yohei Yukawa | d033283 | 2017-02-01 13:59:43 -0800 | [diff] [blame] | 4394 | if (DEBUG) { |
| 4395 | Slog.i(TAG, "All the enabled IMEs are gone. Reset default enabled IMEs."); |
| 4396 | } |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 4397 | resetDefaultEnabledIme = true; |
| 4398 | resetSelectedInputMethodAndSubtypeLocked(""); |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4399 | } else if (!enabledNonAuxImeFound) { |
| 4400 | if (DEBUG) { |
| 4401 | Slog.i(TAG, "All the enabled non-Aux IMEs are gone. Do partial reset."); |
| 4402 | } |
| 4403 | reenableMinimumNonAuxSystemImes = true; |
Yohei Yukawa | 859df05 | 2016-02-17 07:56:46 -0800 | [diff] [blame] | 4404 | } |
| 4405 | } |
| 4406 | |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4407 | if (resetDefaultEnabledIme || reenableMinimumNonAuxSystemImes) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 4408 | final ArrayList<InputMethodInfo> defaultEnabledIme = |
Yohei Yukawa | 9c37219 | 2018-03-20 22:54:56 -0700 | [diff] [blame] | 4409 | InputMethodUtils.getDefaultEnabledImes(mContext, mMethodList, |
| 4410 | reenableMinimumNonAuxSystemImes); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 4411 | final int N = defaultEnabledIme.size(); |
| 4412 | for (int i = 0; i < N; ++i) { |
Satoshi Kataoka | f1367b7 | 2013-01-25 17:20:12 +0900 | [diff] [blame] | 4413 | final InputMethodInfo imi = defaultEnabledIme.get(i); |
| 4414 | if (DEBUG) { |
| 4415 | Slog.d(TAG, "--- enable ime = " + imi); |
| 4416 | } |
| 4417 | setInputMethodEnabledLocked(imi.getId(), true); |
| 4418 | } |
| 4419 | } |
| 4420 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4421 | final String defaultImiId = mSettings.getSelectedInputMethod(); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 4422 | if (!TextUtils.isEmpty(defaultImiId)) { |
Yohei Yukawa | 94e3330 | 2016-02-12 19:37:03 -0800 | [diff] [blame] | 4423 | if (!mMethodMap.containsKey(defaultImiId)) { |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 4424 | Slog.w(TAG, "Default IME is uninstalled. Choose new default IME."); |
| 4425 | if (chooseNewDefaultIMELocked()) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 4426 | updateInputMethodsFromSettingsLocked(true); |
satok | 0a1bcf4 | 2012-05-16 19:26:31 +0900 | [diff] [blame] | 4427 | } |
| 4428 | } else { |
| 4429 | // Double check that the default IME is certainly enabled. |
| 4430 | setInputMethodEnabledLocked(defaultImiId, true); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 4431 | } |
| 4432 | } |
Yohei Yukawa | 3d46bab | 2014-05-30 18:10:18 +0900 | [diff] [blame] | 4433 | // Here is not the perfect place to reset the switching controller. Ideally |
| 4434 | // mSwitchingController and mSettings should be able to share the same state. |
| 4435 | // TODO: Make sure that mSwitchingController and mSettings are sharing the |
| 4436 | // the same enabled IMEs list. |
Yohei Yukawa | c834a25 | 2014-05-21 22:42:32 +0900 | [diff] [blame] | 4437 | mSwitchingController.resetCircularListLocked(mContext); |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 4438 | |
| 4439 | // Notify InputMethodListListeners of the new installed InputMethods. |
| 4440 | final List<InputMethodInfo> inputMethodList = new ArrayList<>(mMethodList); |
| 4441 | mHandler.obtainMessage(MSG_DISPATCH_ON_INPUT_METHOD_LIST_UPDATED, |
| 4442 | mSettings.getCurrentUserId(), 0 /* unused */, inputMethodList).sendToTarget(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4443 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4445 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4446 | |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 4447 | private void showInputMethodAndSubtypeEnabler(String inputMethodId) { |
Tadashi G. Takaoka | f49688f | 2011-01-20 17:56:13 +0900 | [diff] [blame] | 4448 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 4449 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
satok | 86417ea | 2010-10-27 14:11:03 +0900 | [diff] [blame] | 4450 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 4451 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 4452 | if (!TextUtils.isEmpty(inputMethodId)) { |
Tadashi G. Takaoka | 2548020 | 2011-01-20 23:13:02 +0900 | [diff] [blame] | 4453 | intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId); |
satok | 7fee71f | 2010-12-17 18:54:26 +0900 | [diff] [blame] | 4454 | } |
Yohei Yukawa | 41f3427 | 2015-12-14 15:41:52 -0800 | [diff] [blame] | 4455 | final int userId; |
| 4456 | synchronized (mMethodMap) { |
| 4457 | userId = mSettings.getCurrentUserId(); |
| 4458 | } |
| 4459 | mContext.startActivityAsUser(intent, null, UserHandle.of(userId)); |
satok | 217f548 | 2010-12-15 05:19:19 +0900 | [diff] [blame] | 4460 | } |
| 4461 | |
| 4462 | private void showConfigureInputMethods() { |
| 4463 | Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS); |
| 4464 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 4465 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
| 4466 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
Satoshi Kataoka | 3ba439d | 2012-10-05 18:30:13 +0900 | [diff] [blame] | 4467 | mContext.startActivityAsUser(intent, null, UserHandle.CURRENT); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 4468 | } |
| 4469 | |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 4470 | private boolean isScreenLocked() { |
| 4471 | return mKeyguardManager != null |
| 4472 | && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure(); |
| 4473 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4474 | |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 4475 | private void showInputMethodMenu(boolean showAuxSubtypes, int displayId) { |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 4476 | 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] | 4477 | |
satok | 2c93efc | 2012-04-02 19:33:47 +0900 | [diff] [blame] | 4478 | final boolean isScreenLocked = isScreenLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4479 | |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4480 | final String lastInputMethodId = mSettings.getSelectedInputMethod(); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4481 | int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4482 | if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4483 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 4484 | synchronized (mMethodMap) { |
Yohei Yukawa | cf3bbff | 2018-11-20 17:24:20 -0800 | [diff] [blame] | 4485 | final List<ImeSubtypeListItem> imList = |
| 4486 | mSwitchingController.getSortedInputMethodAndSubtypeListLocked( |
| 4487 | showAuxSubtypes, isScreenLocked); |
| 4488 | if (imList.isEmpty()) { |
satok | 7f35c8c | 2010-10-07 21:13:11 +0900 | [diff] [blame] | 4489 | return; |
| 4490 | } |
| 4491 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 4492 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4493 | |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 4494 | if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4495 | final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 4496 | if (currentSubtype != null) { |
| 4497 | final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId); |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4498 | lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
| 4499 | currentImi, currentSubtype.hashCode()); |
satok | c369056 | 2012-01-10 20:14:43 +0900 | [diff] [blame] | 4500 | } |
| 4501 | } |
| 4502 | |
Ken Wakasa | 761eb37 | 2011-03-04 19:06:18 +0900 | [diff] [blame] | 4503 | final int N = imList.size(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4504 | mIms = new InputMethodInfo[N]; |
| 4505 | mSubtypeIds = new int[N]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 4506 | int checkedItem = 0; |
| 4507 | for (int i = 0; i < N; ++i) { |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4508 | final ImeSubtypeListItem item = imList.get(i); |
| 4509 | mIms[i] = item.mImi; |
| 4510 | mSubtypeIds[i] = item.mSubtypeId; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 4511 | if (mIms[i].getId().equals(lastInputMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4512 | int subtypeId = mSubtypeIds[i]; |
| 4513 | if ((subtypeId == NOT_A_SUBTYPE_ID) |
| 4514 | || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) |
| 4515 | || (subtypeId == lastInputMethodSubtypeId)) { |
| 4516 | checkedItem = i; |
| 4517 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 4518 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4519 | } |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4520 | |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 4521 | final ActivityThread currentThread = ActivityThread.currentActivityThread(); |
Andrew Sapperstein | 8a3b4cb | 2017-04-28 14:35:31 -0700 | [diff] [blame] | 4522 | final Context settingsContext = new ContextThemeWrapper( |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 4523 | displayId == DEFAULT_DISPLAY ? currentThread.getSystemUiContext() |
| 4524 | : currentThread.createSystemUiContext(displayId), |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4525 | com.android.internal.R.style.Theme_DeviceDefault_Settings); |
| 4526 | |
| 4527 | mDialogBuilder = new AlertDialog.Builder(settingsContext); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4528 | mDialogBuilder.setOnCancelListener(new OnCancelListener() { |
| 4529 | @Override |
| 4530 | public void onCancel(DialogInterface dialog) { |
| 4531 | hideInputMethodMenu(); |
| 4532 | } |
| 4533 | }); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4534 | |
| 4535 | final Context dialogContext = mDialogBuilder.getContext(); |
| 4536 | final TypedArray a = dialogContext.obtainStyledAttributes(null, |
| 4537 | com.android.internal.R.styleable.DialogPreference, |
| 4538 | com.android.internal.R.attr.alertDialogStyle, 0); |
| 4539 | final Drawable dialogIcon = a.getDrawable( |
| 4540 | com.android.internal.R.styleable.DialogPreference_dialogIcon); |
| 4541 | a.recycle(); |
| 4542 | |
| 4543 | mDialogBuilder.setIcon(dialogIcon); |
| 4544 | |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 4545 | final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class); |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 4546 | final View tv = inflater.inflate( |
| 4547 | com.android.internal.R.layout.input_method_switch_dialog_title, null); |
| 4548 | mDialogBuilder.setCustomTitle(tv); |
| 4549 | |
| 4550 | // Setup layout for a toggle switch of the hardware keyboard |
| 4551 | mSwitchingDialogTitleView = tv; |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4552 | mSwitchingDialogTitleView |
| 4553 | .findViewById(com.android.internal.R.id.hard_keyboard_section) |
Seigo Nonaka | 7309b12 | 2015-08-17 18:34:13 -0700 | [diff] [blame] | 4554 | .setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4555 | ? View.VISIBLE : View.GONE); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4556 | final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById( |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4557 | com.android.internal.R.id.hard_keyboard_switch); |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 4558 | hardKeySwitch.setChecked(mShowImeWithHardKeyboard); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4559 | hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
| 4560 | @Override |
| 4561 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
Michael Wright | 7b5a96b | 2014-08-09 19:28:42 -0700 | [diff] [blame] | 4562 | mSettings.setShowImeWithHardKeyboard(isChecked); |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4563 | // Ensure that the input method dialog is dismissed when changing |
| 4564 | // the hardware keyboard state. |
| 4565 | hideInputMethodMenu(); |
| 4566 | } |
| 4567 | }); |
| 4568 | |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4569 | final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4570 | com.android.internal.R.layout.input_method_switch_item, imList, checkedItem); |
| 4571 | final OnClickListener choiceListener = new OnClickListener() { |
| 4572 | @Override |
| 4573 | public void onClick(final DialogInterface dialog, final int which) { |
| 4574 | synchronized (mMethodMap) { |
| 4575 | if (mIms == null || mIms.length <= which || mSubtypeIds == null |
| 4576 | || mSubtypeIds.length <= which) { |
| 4577 | return; |
satok | 0103849 | 2012-04-09 21:08:27 +0900 | [diff] [blame] | 4578 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4579 | final InputMethodInfo im = mIms[which]; |
| 4580 | int subtypeId = mSubtypeIds[which]; |
| 4581 | adapter.mCheckedItem = which; |
| 4582 | adapter.notifyDataSetChanged(); |
| 4583 | hideInputMethodMenu(); |
| 4584 | if (im != null) { |
| 4585 | if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) { |
| 4586 | subtypeId = NOT_A_SUBTYPE_ID; |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 4587 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4588 | setInputMethodLocked(im.getId(), subtypeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4589 | } |
Tadashi G. Takaoka | d130b80 | 2014-08-01 14:05:47 +0900 | [diff] [blame] | 4590 | } |
| 4591 | } |
| 4592 | }; |
| 4593 | mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4594 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4595 | mSwitchingDialog = mDialogBuilder.create(); |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 4596 | mSwitchingDialog.setCanceledOnTouchOutside(true); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4597 | final Window w = mSwitchingDialog.getWindow(); |
Yohei Yukawa | 6e87559 | 2019-01-28 00:49:30 -0800 | [diff] [blame] | 4598 | final LayoutParams attrs = w.getAttributes(); |
| 4599 | w.setType(LayoutParams.TYPE_INPUT_METHOD_DIALOG); |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4600 | // Use an alternate token for the dialog for that window manager can group the token |
| 4601 | // with other IME windows based on type vs. grouping based on whichever token happens |
| 4602 | // to get selected by the system later on. |
| 4603 | attrs.token = mSwitchingDialogToken; |
Roshan Pius | a3f89c6 | 2019-10-11 08:50:53 -0700 | [diff] [blame] | 4604 | attrs.privateFlags |= LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | 3a93169 | 2016-11-02 16:49:48 -0700 | [diff] [blame] | 4605 | attrs.setTitle("Select input method"); |
| 4606 | w.setAttributes(attrs); |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 4607 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4608 | mSwitchingDialog.show(); |
| 4609 | } |
| 4610 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4611 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4612 | private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> { |
| 4613 | private final LayoutInflater mInflater; |
| 4614 | private final int mTextViewResourceId; |
| 4615 | private final List<ImeSubtypeListItem> mItemsList; |
Satoshi Kataoka | d214296 | 2012-11-12 18:43:06 +0900 | [diff] [blame] | 4616 | public int mCheckedItem; |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4617 | public ImeSubtypeListAdapter(Context context, int textViewResourceId, |
| 4618 | List<ImeSubtypeListItem> itemsList, int checkedItem) { |
| 4619 | super(context, textViewResourceId, itemsList); |
Alan Viverette | 505e3ab | 2014-11-24 15:22:11 -0800 | [diff] [blame] | 4620 | |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4621 | mTextViewResourceId = textViewResourceId; |
| 4622 | mItemsList = itemsList; |
| 4623 | mCheckedItem = checkedItem; |
Yohei Yukawa | d34e148 | 2016-02-11 08:03:52 -0800 | [diff] [blame] | 4624 | mInflater = context.getSystemService(LayoutInflater.class); |
Ken Wakasa | 05dbb65 | 2011-08-22 15:22:43 +0900 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | @Override |
| 4628 | public View getView(int position, View convertView, ViewGroup parent) { |
| 4629 | final View view = convertView != null ? convertView |
| 4630 | : mInflater.inflate(mTextViewResourceId, null); |
| 4631 | if (position < 0 || position >= mItemsList.size()) return view; |
| 4632 | final ImeSubtypeListItem item = mItemsList.get(position); |
| 4633 | final CharSequence imeName = item.mImeName; |
| 4634 | final CharSequence subtypeName = item.mSubtypeName; |
| 4635 | final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1); |
| 4636 | final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2); |
| 4637 | if (TextUtils.isEmpty(subtypeName)) { |
| 4638 | firstTextView.setText(imeName); |
| 4639 | secondTextView.setVisibility(View.GONE); |
| 4640 | } else { |
| 4641 | firstTextView.setText(subtypeName); |
| 4642 | secondTextView.setText(imeName); |
| 4643 | secondTextView.setVisibility(View.VISIBLE); |
| 4644 | } |
| 4645 | final RadioButton radioButton = |
| 4646 | (RadioButton)view.findViewById(com.android.internal.R.id.radio); |
| 4647 | radioButton.setChecked(position == mCheckedItem); |
| 4648 | return view; |
| 4649 | } |
| 4650 | } |
| 4651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4652 | void hideInputMethodMenu() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4653 | synchronized (mMethodMap) { |
| 4654 | hideInputMethodMenuLocked(); |
| 4655 | } |
| 4656 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4657 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4658 | void hideInputMethodMenuLocked() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 4659 | if (DEBUG) Slog.v(TAG, "Hide switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4660 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4661 | if (mSwitchingDialog != null) { |
| 4662 | mSwitchingDialog.dismiss(); |
| 4663 | mSwitchingDialog = null; |
Yohei Yukawa | 1fc7a1d | 2018-04-18 17:31:27 -0700 | [diff] [blame] | 4664 | mSwitchingDialogTitleView = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4665 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4666 | |
Yohei Yukawa | 849443c | 2019-01-21 09:02:25 -0800 | [diff] [blame] | 4667 | updateSystemUiLocked(mImeWindowVis, mBackDisposition); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4668 | mDialogBuilder = null; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 4669 | mIms = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4670 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4671 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4672 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 4673 | |
Yohei Yukawa | 3d3abd2 | 2019-04-09 23:20:12 -0700 | [diff] [blame] | 4674 | /** |
| 4675 | * Enable or disable the given IME by updating {@link Settings.Secure#ENABLED_INPUT_METHODS}. |
| 4676 | * |
| 4677 | * @param id ID of the IME is to be manipulated. It is OK to pass IME ID that is currently not |
| 4678 | * recognized by the system. |
| 4679 | * @param enabled {@code true} if {@code id} needs to be enabled. |
| 4680 | * @return {@code true} if the IME was previously enabled. {@code false} otherwise. |
| 4681 | */ |
| 4682 | private boolean setInputMethodEnabledLocked(String id, boolean enabled) { |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4683 | List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings |
| 4684 | .getEnabledInputMethodsAndSubtypeListLocked(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4685 | |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4686 | if (enabled) { |
| 4687 | for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) { |
| 4688 | if (pair.first.equals(id)) { |
| 4689 | // We are enabling this input method, but it is already enabled. |
| 4690 | // Nothing to do. The previous state was enabled. |
| 4691 | return true; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4692 | } |
| 4693 | } |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4694 | mSettings.appendAndPutEnabledInputMethodLocked(id, false); |
| 4695 | // Previous state was disabled. |
| 4696 | return false; |
| 4697 | } else { |
| 4698 | StringBuilder builder = new StringBuilder(); |
| 4699 | if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 4700 | builder, enabledInputMethodsList, id)) { |
| 4701 | // Disabled input method is currently selected, switch to another one. |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4702 | final String selId = mSettings.getSelectedInputMethod(); |
satok | 03eb319a | 2010-11-11 18:17:42 +0900 | [diff] [blame] | 4703 | if (id.equals(selId) && !chooseNewDefaultIMELocked()) { |
| 4704 | Slog.i(TAG, "Can't find new IME, unsetting the current input method."); |
| 4705 | resetSelectedInputMethodAndSubtypeLocked(""); |
satok | d87c259 | 2010-09-29 11:52:06 +0900 | [diff] [blame] | 4706 | } |
| 4707 | // Previous state was enabled. |
| 4708 | return true; |
| 4709 | } else { |
| 4710 | // We are disabling the input method but it is already disabled. |
| 4711 | // Nothing to do. The previous state was disabled. |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4712 | return false; |
| 4713 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4714 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 4715 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 4716 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4717 | private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId, |
| 4718 | boolean setSubtypeOnly) { |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 4719 | mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype); |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 4720 | |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4721 | // Set Subtype here |
| 4722 | if (imi == null || subtypeId < 0) { |
| 4723 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
Tadashi G. Takaoka | 0ba75bb | 2010-11-09 12:19:32 -0800 | [diff] [blame] | 4724 | mCurrentSubtype = null; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4725 | } else { |
Ken Wakasa | 586f051 | 2011-01-20 22:31:01 +0900 | [diff] [blame] | 4726 | if (subtypeId < imi.getSubtypeCount()) { |
| 4727 | InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId); |
| 4728 | mSettings.putSelectedSubtype(subtype.hashCode()); |
| 4729 | mCurrentSubtype = subtype; |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4730 | } else { |
| 4731 | mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
satok | d81e950 | 2012-05-21 12:58:45 +0900 | [diff] [blame] | 4732 | // If the subtype is not specified, choose the most applicable one |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4733 | mCurrentSubtype = getCurrentInputMethodSubtypeLocked(); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4734 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4735 | } |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4736 | |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 4737 | if (!setSubtypeOnly) { |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4738 | // Set InputMethod here |
| 4739 | mSettings.putSelectedInputMethod(imi != null ? imi.getId() : ""); |
| 4740 | } |
| 4741 | } |
| 4742 | |
| 4743 | private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) { |
| 4744 | InputMethodInfo imi = mMethodMap.get(newDefaultIme); |
| 4745 | int lastSubtypeId = NOT_A_SUBTYPE_ID; |
| 4746 | // newDefaultIme is empty when there is no candidate for the selected IME. |
| 4747 | if (imi != null && !TextUtils.isEmpty(newDefaultIme)) { |
| 4748 | String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme); |
| 4749 | if (subtypeHashCode != null) { |
| 4750 | try { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4751 | lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode( |
Narayan Kamath | a09b4d2 | 2016-04-15 18:32:45 +0100 | [diff] [blame] | 4752 | imi, Integer.parseInt(subtypeHashCode)); |
satok | 723a27e | 2010-11-11 14:58:11 +0900 | [diff] [blame] | 4753 | } catch (NumberFormatException e) { |
| 4754 | Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e); |
| 4755 | } |
| 4756 | } |
| 4757 | } |
| 4758 | setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4759 | } |
| 4760 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4761 | /** |
| 4762 | * @return Return the current subtype of this input method. |
| 4763 | */ |
satok | 42c5a16 | 2011-05-26 16:46:14 +0900 | [diff] [blame] | 4764 | @Override |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4765 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4766 | synchronized (mMethodMap) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 4767 | // TODO: Make this work even for non-current users? |
Yohei Yukawa | 46d7476 | 2019-01-22 10:17:22 -0800 | [diff] [blame] | 4768 | if (!calledFromValidUserLocked()) { |
Yohei Yukawa | 91e6cd0 | 2018-12-09 22:58:57 -0800 | [diff] [blame] | 4769 | return null; |
| 4770 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4771 | return getCurrentInputMethodSubtypeLocked(); |
| 4772 | } |
| 4773 | } |
| 4774 | |
| 4775 | private InputMethodSubtype getCurrentInputMethodSubtypeLocked() { |
satok | fdf419e | 2012-05-08 16:52:08 +0900 | [diff] [blame] | 4776 | if (mCurMethodId == null) { |
| 4777 | return null; |
| 4778 | } |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4779 | final boolean subtypeIsSelected = mSettings.isSubtypeSelected(); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4780 | final InputMethodInfo imi = mMethodMap.get(mCurMethodId); |
| 4781 | if (imi == null || imi.getSubtypeCount() == 0) { |
| 4782 | return null; |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4783 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4784 | if (!subtypeIsSelected || mCurrentSubtype == null |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4785 | || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) { |
| 4786 | int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4787 | if (subtypeId == NOT_A_SUBTYPE_ID) { |
| 4788 | // If there are no selected subtypes, the framework will try to find |
| 4789 | // the most applicable subtype from explicitly or implicitly enabled |
| 4790 | // subtypes. |
| 4791 | List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4792 | mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4793 | // If there is only one explicitly or implicitly enabled subtype, |
| 4794 | // just returns it. |
| 4795 | if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) { |
| 4796 | mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0); |
| 4797 | } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4798 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4799 | mRes, explicitlyOrImplicitlyEnabledSubtypes, |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4800 | InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true); |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4801 | if (mCurrentSubtype == null) { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4802 | mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked( |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4803 | mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, |
| 4804 | true); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 4805 | } |
satok | 3ef8b29 | 2010-11-23 06:06:29 +0900 | [diff] [blame] | 4806 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4807 | } else { |
Satoshi Kataoka | 8e303cc | 2013-01-11 15:55:28 +0900 | [diff] [blame] | 4808 | mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId); |
satok | 8fbb1e8 | 2010-11-02 23:15:58 +0900 | [diff] [blame] | 4809 | } |
| 4810 | } |
Satoshi Kataoka | 4e1ab15 | 2012-09-13 21:34:20 +0900 | [diff] [blame] | 4811 | return mCurrentSubtype; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 4812 | } |
| 4813 | |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 4814 | private List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId) { |
| 4815 | synchronized (mMethodMap) { |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 4816 | return getInputMethodListLocked(userId); |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 4817 | } |
| 4818 | } |
| 4819 | |
| 4820 | private List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId) { |
| 4821 | synchronized (mMethodMap) { |
| 4822 | return getEnabledInputMethodListLocked(userId); |
| 4823 | } |
| 4824 | } |
| 4825 | |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 4826 | private void onCreateInlineSuggestionsRequest(@UserIdInt int userId, |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 4827 | InlineSuggestionsRequestInfo requestInfo, |
Feng Cao | 16b2de5 | 2020-01-09 17:27:27 -0800 | [diff] [blame] | 4828 | IInlineSuggestionsRequestCallback callback) { |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4829 | synchronized (mMethodMap) { |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 4830 | onCreateInlineSuggestionsRequestLocked(userId, requestInfo, callback); |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4831 | } |
| 4832 | } |
| 4833 | |
mincheli | 850892b | 2019-12-05 19:47:59 +0800 | [diff] [blame] | 4834 | private boolean switchToInputMethod(String imeId, @UserIdInt int userId) { |
| 4835 | synchronized (mMethodMap) { |
| 4836 | if (userId == mSettings.getCurrentUserId()) { |
| 4837 | if (!mMethodMap.containsKey(imeId) |
| 4838 | || !mSettings.getEnabledInputMethodListLocked() |
| 4839 | .contains(mMethodMap.get(imeId))) { |
| 4840 | return false; // IME is not is found or not enabled. |
| 4841 | } |
| 4842 | setInputMethodLocked(imeId, NOT_A_SUBTYPE_ID); |
| 4843 | return true; |
| 4844 | } |
| 4845 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 4846 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 4847 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 4848 | new ArrayMap<>(); |
| 4849 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 4850 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, |
| 4851 | methodMap, methodList); |
| 4852 | final InputMethodSettings settings = new InputMethodSettings( |
| 4853 | mContext.getResources(), mContext.getContentResolver(), methodMap, |
| 4854 | userId, false); |
| 4855 | if (!methodMap.containsKey(imeId) |
| 4856 | || !settings.getEnabledInputMethodListLocked() |
| 4857 | .contains(methodMap.get(imeId))) { |
| 4858 | return false; // IME is not is found or not enabled. |
| 4859 | } |
| 4860 | settings.putSelectedInputMethod(imeId); |
| 4861 | settings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
| 4862 | return true; |
| 4863 | } |
| 4864 | } |
| 4865 | |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 4866 | private boolean transferTouchFocusToImeWindow(@NonNull IBinder sourceInputToken, |
| 4867 | int displayId) { |
| 4868 | //TODO(b/150843766): Check if Input Token is valid. |
| 4869 | final IBinder curHostInputToken; |
| 4870 | synchronized (mMethodMap) { |
| 4871 | if (displayId != mCurTokenDisplayId || mCurHostInputToken == null) { |
| 4872 | return false; |
| 4873 | } |
| 4874 | curHostInputToken = mCurHostInputToken; |
| 4875 | } |
| 4876 | return mInputManagerInternal.transferTouchFocus(sourceInputToken, curHostInputToken); |
| 4877 | } |
| 4878 | |
Yohei Yukawa | e24ed79 | 2018-08-28 19:10:32 -0700 | [diff] [blame] | 4879 | private static final class LocalServiceImpl extends InputMethodManagerInternal { |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4880 | @NonNull |
Yohei Yukawa | fffc0e5 | 2018-09-04 13:24:00 -0700 | [diff] [blame] | 4881 | private final InputMethodManagerService mService; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4882 | |
Yohei Yukawa | fffc0e5 | 2018-09-04 13:24:00 -0700 | [diff] [blame] | 4883 | LocalServiceImpl(@NonNull InputMethodManagerService service) { |
| 4884 | mService = service; |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4885 | } |
| 4886 | |
| 4887 | @Override |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 4888 | public void hideCurrentInputMethod(@SoftInputShowHideReason int reason) { |
Yohei Yukawa | f16abb7 | 2018-09-05 11:28:42 -0700 | [diff] [blame] | 4889 | mService.mHandler.removeMessages(MSG_HIDE_CURRENT_INPUT_METHOD); |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 4890 | mService.mHandler.obtainMessage(MSG_HIDE_CURRENT_INPUT_METHOD, reason).sendToTarget(); |
Jorim Jaggi | 3c5d0f1 | 2016-05-24 19:04:30 -0700 | [diff] [blame] | 4891 | } |
Tarandeep Singh | 89a6c48 | 2017-11-21 14:26:11 -0800 | [diff] [blame] | 4892 | |
| 4893 | @Override |
Yohei Yukawa | a878b95 | 2019-01-10 19:36:24 -0800 | [diff] [blame] | 4894 | public List<InputMethodInfo> getInputMethodListAsUser(int userId) { |
| 4895 | return mService.getInputMethodListAsUser(userId); |
| 4896 | } |
| 4897 | |
| 4898 | @Override |
| 4899 | public List<InputMethodInfo> getEnabledInputMethodListAsUser(int userId) { |
| 4900 | return mService.getEnabledInputMethodListAsUser(userId); |
| 4901 | } |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4902 | |
| 4903 | @Override |
Feng Cao | 36960ee | 2020-02-18 18:23:30 -0800 | [diff] [blame] | 4904 | public void onCreateInlineSuggestionsRequest(int userId, |
| 4905 | InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback cb) { |
| 4906 | mService.onCreateInlineSuggestionsRequest(userId, requestInfo, cb); |
Adam He | bc67f2e | 2019-11-13 14:34:56 -0800 | [diff] [blame] | 4907 | } |
mincheli | 850892b | 2019-12-05 19:47:59 +0800 | [diff] [blame] | 4908 | |
| 4909 | @Override |
| 4910 | public boolean switchToInputMethod(String imeId, int userId) { |
| 4911 | return mService.switchToInputMethod(imeId, userId); |
| 4912 | } |
Yuichiro Hanada | 34c4c0e | 2020-01-15 16:53:07 +0900 | [diff] [blame] | 4913 | |
| 4914 | @Override |
| 4915 | public void registerInputMethodListListener(InputMethodListListener listener) { |
| 4916 | mService.mInputMethodListListeners.addIfAbsent(listener); |
| 4917 | } |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 4918 | |
| 4919 | @Override |
| 4920 | public boolean transferTouchFocusToImeWindow(@NonNull IBinder sourceInputToken, |
| 4921 | int displayId) { |
| 4922 | return mService.transferTouchFocusToImeWindow(sourceInputToken, displayId); |
| 4923 | } |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 4924 | } |
| 4925 | |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4926 | @BinderThread |
| 4927 | private IInputContentUriToken createInputContentUriToken(@Nullable IBinder token, |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4928 | @Nullable Uri contentUri, @Nullable String packageName) { |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4929 | if (token == null) { |
| 4930 | throw new NullPointerException("token"); |
| 4931 | } |
| 4932 | if (packageName == null) { |
| 4933 | throw new NullPointerException("packageName"); |
| 4934 | } |
| 4935 | if (contentUri == null) { |
| 4936 | throw new NullPointerException("contentUri"); |
| 4937 | } |
| 4938 | final String contentUriScheme = contentUri.getScheme(); |
| 4939 | if (!"content".equals(contentUriScheme)) { |
| 4940 | throw new InvalidParameterException("contentUri must have content scheme"); |
| 4941 | } |
| 4942 | |
| 4943 | synchronized (mMethodMap) { |
| 4944 | final int uid = Binder.getCallingUid(); |
| 4945 | if (mCurMethodId == null) { |
| 4946 | return null; |
| 4947 | } |
| 4948 | if (mCurToken != token) { |
| 4949 | Slog.e(TAG, "Ignoring createInputContentUriToken mCurToken=" + mCurToken |
| 4950 | + " token=" + token); |
| 4951 | return null; |
| 4952 | } |
| 4953 | // We cannot simply distinguish a bad IME that reports an arbitrary package name from |
| 4954 | // an unfortunate IME whose internal state is already obsolete due to the asynchronous |
| 4955 | // nature of our system. Let's compare it with our internal record. |
| 4956 | if (!TextUtils.equals(mCurAttribute.packageName, packageName)) { |
| 4957 | Slog.e(TAG, "Ignoring createInputContentUriToken mCurAttribute.packageName=" |
| 4958 | + mCurAttribute.packageName + " packageName=" + packageName); |
| 4959 | return null; |
| 4960 | } |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4961 | // This user ID can never bee spoofed. |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4962 | final int imeUserId = UserHandle.getUserId(uid); |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4963 | // This user ID can never bee spoofed. |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4964 | final int appUserId = UserHandle.getUserId(mCurClient.uid); |
Yohei Yukawa | 3933a6e | 2016-11-10 00:47:48 -0800 | [diff] [blame] | 4965 | // This user ID may be invalid if "contentUri" embedded an invalid user ID. |
| 4966 | final int contentUriOwnerUserId = ContentProvider.getUserIdFromUri(contentUri, |
| 4967 | imeUserId); |
| 4968 | final Uri contentUriWithoutUserId = ContentProvider.getUriWithoutUserId(contentUri); |
| 4969 | // Note: InputContentUriTokenHandler.take() checks whether the IME (specified by "uid") |
| 4970 | // actually has the right to grant a read permission for "contentUriWithoutUserId" that |
| 4971 | // is claimed to belong to "contentUriOwnerUserId". For example, specifying random |
| 4972 | // content URI and/or contentUriOwnerUserId just results in a SecurityException thrown |
| 4973 | // from InputContentUriTokenHandler.take() and can never be allowed beyond what is |
| 4974 | // actually allowed to "uid", which is guaranteed to be the IME's one. |
| 4975 | return new InputContentUriTokenHandler(contentUriWithoutUserId, uid, |
| 4976 | packageName, contentUriOwnerUserId, appUserId); |
Yohei Yukawa | 25e0813 | 2016-06-22 16:31:41 -0700 | [diff] [blame] | 4977 | } |
| 4978 | } |
| 4979 | |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 4980 | @BinderThread |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 4981 | private void reportFullscreenMode(@NonNull IBinder token, boolean fullscreen) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4982 | synchronized (mMethodMap) { |
Yohei Yukawa | 79e4c6a | 2018-12-09 19:07:17 -0800 | [diff] [blame] | 4983 | if (!calledWithValidTokenLocked(token)) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 4984 | return; |
| 4985 | } |
| 4986 | if (mCurClient != null && mCurClient.client != null) { |
| 4987 | mInFullscreenMode = fullscreen; |
| 4988 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 4989 | MSG_REPORT_FULLSCREEN_MODE, fullscreen ? 1 : 0, mCurClient)); |
| 4990 | } |
| 4991 | } |
| 4992 | } |
| 4993 | |
| 4994 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4995 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 4996 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4997 | |
| 4998 | IInputMethod method; |
| 4999 | ClientState client; |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 5000 | ClientState focusedWindowClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5001 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5002 | final Printer p = new PrintWriterPrinter(pw); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5004 | synchronized (mMethodMap) { |
| 5005 | p.println("Current Input Method Manager state:"); |
| 5006 | int N = mMethodList.size(); |
Yohei Yukawa | 5ec1fce | 2018-12-17 07:56:14 -0800 | [diff] [blame] | 5007 | p.println(" Input Methods: mMethodMapUpdateCount=" + mMethodMapUpdateCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5008 | for (int i=0; i<N; i++) { |
| 5009 | InputMethodInfo info = mMethodList.get(i); |
| 5010 | p.println(" InputMethod #" + i + ":"); |
| 5011 | info.dump(p, " "); |
| 5012 | } |
| 5013 | p.println(" Clients:"); |
Yohei Yukawa | ac9311e | 2018-11-20 19:25:23 -0800 | [diff] [blame] | 5014 | final int numClients = mClients.size(); |
| 5015 | for (int i = 0; i < numClients; ++i) { |
| 5016 | final ClientState ci = mClients.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5017 | p.println(" Client " + ci + ":"); |
| 5018 | p.println(" client=" + ci.client); |
| 5019 | p.println(" inputContext=" + ci.inputContext); |
| 5020 | p.println(" sessionRequested=" + ci.sessionRequested); |
| 5021 | p.println(" curSession=" + ci.curSession); |
| 5022 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 5023 | p.println(" mCurMethodId=" + mCurMethodId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5024 | client = mCurClient; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 5025 | p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq); |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 5026 | p.println(" mCurFocusedWindow=" + mCurFocusedWindow |
| 5027 | + " softInputMode=" + |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 5028 | InputMethodDebug.softInputModeToString(mCurFocusedWindowSoftInputMode) |
Yohei Yukawa | 22a8923 | 2017-02-12 16:38:59 -0800 | [diff] [blame] | 5029 | + " client=" + mCurFocusedWindowClient); |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 5030 | focusedWindowClient = mCurFocusedWindowClient; |
Yohei Yukawa | d3ef842 | 2018-06-07 16:28:07 -0700 | [diff] [blame] | 5031 | p.println(" mCurId=" + mCurId + " mHaveConnection=" + mHaveConnection |
| 5032 | + " mBoundToMethod=" + mBoundToMethod + " mVisibleBound=" + mVisibleBound); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5033 | p.println(" mCurToken=" + mCurToken); |
lumark | 90120a8 | 2018-08-15 00:33:03 +0800 | [diff] [blame] | 5034 | p.println(" mCurTokenDisplayId=" + mCurTokenDisplayId); |
lpeter | 133fce0 | 2020-03-05 20:32:16 +0800 | [diff] [blame] | 5035 | p.println(" mCurHostInputToken=" + mCurHostInputToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5036 | p.println(" mCurIntent=" + mCurIntent); |
| 5037 | method = mCurMethod; |
| 5038 | p.println(" mCurMethod=" + mCurMethod); |
| 5039 | p.println(" mEnabledSession=" + mEnabledSession); |
| 5040 | p.println(" mShowRequested=" + mShowRequested |
| 5041 | + " mShowExplicitlyRequested=" + mShowExplicitlyRequested |
| 5042 | + " mShowForced=" + mShowForced |
| 5043 | + " mInputShown=" + mInputShown); |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 5044 | p.println(" mInFullscreenMode=" + mInFullscreenMode); |
Yohei Yukawa | fa6e0a8 | 2015-07-23 15:08:59 -0700 | [diff] [blame] | 5045 | p.println(" mSystemReady=" + mSystemReady + " mInteractive=" + mIsInteractive); |
Yohei Yukawa | 8148297 | 2015-06-04 00:58:59 -0700 | [diff] [blame] | 5046 | p.println(" mSettingsObserver=" + mSettingsObserver); |
Yohei Yukawa | d724886 | 2015-06-03 23:56:12 -0700 | [diff] [blame] | 5047 | p.println(" mSwitchingController:"); |
| 5048 | mSwitchingController.dump(p); |
Yohei Yukawa | 68645a6 | 2016-02-17 07:54:20 -0800 | [diff] [blame] | 5049 | p.println(" mSettings:"); |
| 5050 | mSettings.dumpLocked(p, " "); |
Yohei Yukawa | 357b2f6 | 2017-02-14 09:40:03 -0800 | [diff] [blame] | 5051 | |
| 5052 | p.println(" mStartInputHistory:"); |
| 5053 | mStartInputHistory.dump(pw, " "); |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 5054 | |
| 5055 | p.println(" mSoftInputShowHideHistory:"); |
| 5056 | mSoftInputShowHideHistory.dump(pw, " "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5057 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5058 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5059 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5060 | if (client != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5061 | pw.flush(); |
| 5062 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 5063 | TransferPipe.dumpAsync(client.client.asBinder(), fd, args); |
| 5064 | } catch (IOException | RemoteException e) { |
| 5065 | p.println("Failed to dump input method client: " + e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5066 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5067 | } else { |
| 5068 | p.println("No input method client."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5069 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 5070 | |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 5071 | if (focusedWindowClient != null && client != focusedWindowClient) { |
| 5072 | p.println(" "); |
| 5073 | p.println("Warning: Current input method client doesn't match the last focused. " |
| 5074 | + "window."); |
| 5075 | p.println("Dumping input method client in the last focused window just in case."); |
| 5076 | p.println(" "); |
| 5077 | pw.flush(); |
| 5078 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 5079 | TransferPipe.dumpAsync(focusedWindowClient.client.asBinder(), fd, args); |
| 5080 | } catch (IOException | RemoteException e) { |
| 5081 | p.println("Failed to dump input method client in focused window: " + e); |
Yohei Yukawa | e39d4ed | 2015-11-19 03:38:49 -0800 | [diff] [blame] | 5082 | } |
| 5083 | } |
| 5084 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5085 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5086 | if (method != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5087 | pw.flush(); |
| 5088 | try { |
Jeff Sharkey | 850c83e | 2016-11-09 12:25:44 -0700 | [diff] [blame] | 5089 | TransferPipe.dumpAsync(method.asBinder(), fd, args); |
| 5090 | } catch (IOException | RemoteException e) { |
| 5091 | p.println("Failed to dump input method service: " + e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5092 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 5093 | } else { |
| 5094 | p.println("No input method service."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5095 | } |
| 5096 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5097 | |
| 5098 | @BinderThread |
| 5099 | @Override |
| 5100 | public void onShellCommand(@Nullable FileDescriptor in, @Nullable FileDescriptor out, |
| 5101 | @Nullable FileDescriptor err, |
| 5102 | @NonNull String[] args, @Nullable ShellCallback callback, |
| 5103 | @NonNull ResultReceiver resultReceiver) throws RemoteException { |
Yohei Yukawa | b8d240f | 2018-12-26 10:03:11 -0800 | [diff] [blame] | 5104 | final int callingUid = Binder.getCallingUid(); |
| 5105 | // Reject any incoming calls from non-shell users, including ones from the system user. |
| 5106 | if (callingUid != Process.ROOT_UID && callingUid != Process.SHELL_UID) { |
| 5107 | // Note that Binder#onTransact() will automatically close "in", "out", and "err" when |
| 5108 | // returned from this method, hence there is no need to close those FDs. |
| 5109 | // "resultReceiver" is the only thing that needs to be taken care of here. |
| 5110 | if (resultReceiver != null) { |
| 5111 | resultReceiver.send(ShellCommandResult.FAILURE, null); |
| 5112 | } |
| 5113 | final String errorMsg = "InputMethodManagerService does not support shell commands from" |
| 5114 | + " non-shell users. callingUid=" + callingUid |
| 5115 | + " args=" + Arrays.toString(args); |
| 5116 | if (Process.isCoreUid(callingUid)) { |
| 5117 | // Let's not crash the calling process if the caller is one of core components. |
| 5118 | Slog.e(TAG, errorMsg); |
| 5119 | return; |
| 5120 | } |
| 5121 | throw new SecurityException(errorMsg); |
| 5122 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5123 | new ShellCommandImpl(this).exec( |
| 5124 | this, in, out, err, args, callback, resultReceiver); |
| 5125 | } |
| 5126 | |
| 5127 | private static final class ShellCommandImpl extends ShellCommand { |
| 5128 | @NonNull |
| 5129 | final InputMethodManagerService mService; |
| 5130 | |
| 5131 | ShellCommandImpl(InputMethodManagerService service) { |
| 5132 | mService = service; |
| 5133 | } |
| 5134 | |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 5135 | @RequiresPermission(allOf = { |
Yohei Yukawa | 8a2b96b | 2018-12-28 17:23:29 -0800 | [diff] [blame] | 5136 | Manifest.permission.DUMP, |
| 5137 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 5138 | Manifest.permission.WRITE_SECURE_SETTINGS, |
Yohei Yukawa | 8a2b96b | 2018-12-28 17:23:29 -0800 | [diff] [blame] | 5139 | }) |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5140 | @BinderThread |
| 5141 | @ShellCommandResult |
| 5142 | @Override |
| 5143 | public int onCommand(@Nullable String cmd) { |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 5144 | // 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] | 5145 | Arrays.asList( |
| 5146 | Manifest.permission.DUMP, |
| 5147 | Manifest.permission.INTERACT_ACROSS_USERS_FULL, |
| 5148 | Manifest.permission.WRITE_SECURE_SETTINGS |
| 5149 | ).forEach(permission -> mService.mContext.enforceCallingPermission(permission, null)); |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 5150 | |
| 5151 | final long identity = Binder.clearCallingIdentity(); |
| 5152 | try { |
| 5153 | return onCommandWithSystemIdentity(cmd); |
| 5154 | } finally { |
| 5155 | Binder.restoreCallingIdentity(identity); |
| 5156 | } |
| 5157 | } |
| 5158 | |
| 5159 | @BinderThread |
| 5160 | @ShellCommandResult |
| 5161 | private int onCommandWithSystemIdentity(@Nullable String cmd) { |
Yohei Yukawa | dfdab73 | 2018-02-21 07:16:30 +0900 | [diff] [blame] | 5162 | if ("refresh_debug_properties".equals(cmd)) { |
| 5163 | return refreshDebugProperties(); |
| 5164 | } |
| 5165 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 5166 | if ("get-last-switch-user-id".equals(cmd)) { |
| 5167 | return mService.getLastSwitchUserId(this); |
| 5168 | } |
| 5169 | |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 5170 | // For existing "adb shell ime <command>". |
| 5171 | if ("ime".equals(cmd)) { |
| 5172 | final String imeCommand = getNextArg(); |
| 5173 | if (imeCommand == null || "help".equals(imeCommand) || "-h".equals(imeCommand)) { |
| 5174 | onImeCommandHelp(); |
| 5175 | return ShellCommandResult.SUCCESS; |
| 5176 | } |
| 5177 | switch (imeCommand) { |
| 5178 | case "list": |
| 5179 | return mService.handleShellCommandListInputMethods(this); |
| 5180 | case "enable": |
| 5181 | return mService.handleShellCommandEnableDisableInputMethod(this, true); |
| 5182 | case "disable": |
| 5183 | return mService.handleShellCommandEnableDisableInputMethod(this, false); |
| 5184 | case "set": |
| 5185 | return mService.handleShellCommandSetInputMethod(this); |
| 5186 | case "reset": |
| 5187 | return mService.handleShellCommandResetInputMethod(this); |
| 5188 | default: |
| 5189 | getOutPrintWriter().println("Unknown command: " + imeCommand); |
| 5190 | return ShellCommandResult.FAILURE; |
| 5191 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5192 | } |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 5193 | |
| 5194 | return handleDefaultCommands(cmd); |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | @BinderThread |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 5198 | @ShellCommandResult |
| 5199 | private int refreshDebugProperties() { |
| 5200 | DebugFlags.FLAG_OPTIMIZE_START_INPUT.refresh(); |
Tarandeep Singh | eadb139 | 2018-11-09 18:15:57 +0100 | [diff] [blame] | 5201 | DebugFlags.FLAG_PRE_RENDER_IME_VIEWS.refresh(); |
Tarandeep Singh | 75a9239 | 2018-01-12 14:58:59 -0800 | [diff] [blame] | 5202 | return ShellCommandResult.SUCCESS; |
| 5203 | } |
| 5204 | |
| 5205 | @BinderThread |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5206 | @Override |
| 5207 | public void onHelp() { |
| 5208 | try (PrintWriter pw = getOutPrintWriter()) { |
| 5209 | pw.println("InputMethodManagerService commands:"); |
| 5210 | pw.println(" help"); |
| 5211 | pw.println(" Prints this help text."); |
| 5212 | pw.println(" dump [options]"); |
| 5213 | pw.println(" Synonym of dumpsys."); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 5214 | pw.println(" ime <command> [options]"); |
| 5215 | pw.println(" Manipulate IMEs. Run \"ime help\" for details."); |
| 5216 | } |
| 5217 | } |
| 5218 | |
| 5219 | private void onImeCommandHelp() { |
| 5220 | try (IndentingPrintWriter pw = |
| 5221 | new IndentingPrintWriter(getOutPrintWriter(), " ", 100)) { |
| 5222 | pw.println("ime <command>:"); |
| 5223 | pw.increaseIndent(); |
| 5224 | |
| 5225 | pw.println("list [-a] [-s]"); |
| 5226 | pw.increaseIndent(); |
| 5227 | pw.println("prints all enabled input methods."); |
| 5228 | pw.increaseIndent(); |
| 5229 | pw.println("-a: see all input methods"); |
| 5230 | pw.println("-s: only a single summary line of each"); |
| 5231 | pw.decreaseIndent(); |
| 5232 | pw.decreaseIndent(); |
| 5233 | |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5234 | pw.println("enable [--user <USER_ID>] <ID>"); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 5235 | pw.increaseIndent(); |
| 5236 | pw.println("allows the given input method ID to be used."); |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5237 | pw.increaseIndent(); |
| 5238 | pw.print("--user <USER_ID>: Specify which user to enable."); |
| 5239 | pw.println(" Assumes the current user if not specified."); |
| 5240 | pw.decreaseIndent(); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 5241 | pw.decreaseIndent(); |
| 5242 | |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5243 | pw.println("disable [--user <USER_ID>] <ID>"); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 5244 | pw.increaseIndent(); |
| 5245 | pw.println("disallows the given input method ID to be used."); |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5246 | pw.increaseIndent(); |
| 5247 | pw.print("--user <USER_ID>: Specify which user to disable."); |
| 5248 | pw.println(" Assumes the current user if not specified."); |
| 5249 | pw.decreaseIndent(); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 5250 | pw.decreaseIndent(); |
| 5251 | |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 5252 | pw.println("set [--user <USER_ID>] <ID>"); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 5253 | pw.increaseIndent(); |
| 5254 | pw.println("switches to the given input method ID."); |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 5255 | pw.increaseIndent(); |
| 5256 | pw.print("--user <USER_ID>: Specify which user to enable."); |
| 5257 | pw.println(" Assumes the current user if not specified."); |
| 5258 | pw.decreaseIndent(); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 5259 | pw.decreaseIndent(); |
| 5260 | |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 5261 | pw.println("reset [--user <USER_ID>]"); |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 5262 | pw.increaseIndent(); |
| 5263 | pw.println("reset currently selected/enabled IMEs to the default ones as if " |
| 5264 | + "the device is initially booted with the current locale."); |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 5265 | pw.increaseIndent(); |
| 5266 | pw.print("--user <USER_ID>: Specify which user to reset."); |
| 5267 | pw.println(" Assumes the current user if not specified."); |
| 5268 | pw.decreaseIndent(); |
| 5269 | |
Yohei Yukawa | cac9772 | 2017-12-15 16:52:05 -0800 | [diff] [blame] | 5270 | pw.decreaseIndent(); |
| 5271 | |
| 5272 | pw.decreaseIndent(); |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5273 | } |
| 5274 | } |
| 5275 | } |
| 5276 | |
| 5277 | // ---------------------------------------------------------------------- |
| 5278 | // Shell command handlers: |
| 5279 | |
Yohei Yukawa | a7babbb | 2019-01-08 16:45:34 -0800 | [diff] [blame] | 5280 | @BinderThread |
| 5281 | @ShellCommandResult |
| 5282 | private int getLastSwitchUserId(@NonNull ShellCommand shellCommand) { |
| 5283 | synchronized (mMethodMap) { |
| 5284 | shellCommand.getOutPrintWriter().println(mLastSwitchUserId); |
| 5285 | return ShellCommandResult.SUCCESS; |
| 5286 | } |
| 5287 | } |
| 5288 | |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5289 | /** |
| 5290 | * Handles {@code adb shell ime list}. |
| 5291 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 5292 | * @return Exit code of the command. |
| 5293 | */ |
| 5294 | @BinderThread |
| 5295 | @ShellCommandResult |
| 5296 | private int handleShellCommandListInputMethods(@NonNull ShellCommand shellCommand) { |
| 5297 | boolean all = false; |
| 5298 | boolean brief = false; |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 5299 | int userIdToBeResolved = UserHandle.USER_CURRENT; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5300 | while (true) { |
| 5301 | final String nextOption = shellCommand.getNextOption(); |
| 5302 | if (nextOption == null) { |
| 5303 | break; |
| 5304 | } |
| 5305 | switch (nextOption) { |
| 5306 | case "-a": |
| 5307 | all = true; |
| 5308 | break; |
| 5309 | case "-s": |
| 5310 | brief = true; |
| 5311 | break; |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 5312 | case "-u": |
| 5313 | case "--user": |
| 5314 | userIdToBeResolved = UserHandle.parseUserArg(shellCommand.getNextArgRequired()); |
| 5315 | break; |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5316 | } |
| 5317 | } |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 5318 | synchronized (mMethodMap) { |
| 5319 | final PrintWriter pr = shellCommand.getOutPrintWriter(); |
| 5320 | final int[] userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, |
| 5321 | mSettings.getCurrentUserId(), shellCommand.getErrPrintWriter()); |
| 5322 | for (int userId : userIds) { |
| 5323 | final List<InputMethodInfo> methods = all |
Yohei Yukawa | 2988d2d | 2019-01-22 21:29:09 -0800 | [diff] [blame] | 5324 | ? getInputMethodListLocked(userId) |
Yohei Yukawa | 7f8ee4b | 2019-01-10 08:44:57 -0800 | [diff] [blame] | 5325 | : getEnabledInputMethodListLocked(userId); |
| 5326 | if (userIds.length > 1) { |
| 5327 | pr.print("User #"); |
| 5328 | pr.print(userId); |
| 5329 | pr.println(":"); |
| 5330 | } |
| 5331 | for (InputMethodInfo info : methods) { |
| 5332 | if (brief) { |
| 5333 | pr.println(info.getId()); |
| 5334 | } else { |
| 5335 | pr.print(info.getId()); |
| 5336 | pr.println(":"); |
| 5337 | info.dump(pr::println, " "); |
| 5338 | } |
| 5339 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5340 | } |
| 5341 | } |
| 5342 | return ShellCommandResult.SUCCESS; |
| 5343 | } |
| 5344 | |
| 5345 | /** |
| 5346 | * Handles {@code adb shell ime enable} and {@code adb shell ime disable}. |
| 5347 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 5348 | * @param enabled {@code true} if the command was {@code adb shell ime enable}. |
| 5349 | * @return Exit code of the command. |
| 5350 | */ |
| 5351 | @BinderThread |
| 5352 | @ShellCommandResult |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5353 | private int handleShellCommandEnableDisableInputMethod( |
| 5354 | @NonNull ShellCommand shellCommand, boolean enabled) { |
Yohei Yukawa | 3403f2d | 2019-04-15 08:16:58 -0700 | [diff] [blame] | 5355 | final int userIdToBeResolved = handleOptionsForCommandsThatOnlyHaveUserOption(shellCommand); |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5356 | final String imeId = shellCommand.getNextArgRequired(); |
| 5357 | final PrintWriter out = shellCommand.getOutPrintWriter(); |
| 5358 | final PrintWriter error = shellCommand.getErrPrintWriter(); |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5359 | synchronized (mMethodMap) { |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5360 | final int[] userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, |
| 5361 | mSettings.getCurrentUserId(), shellCommand.getErrPrintWriter()); |
| 5362 | for (int userId : userIds) { |
| 5363 | if (!userHasDebugPriv(userId, shellCommand)) { |
| 5364 | continue; |
| 5365 | } |
| 5366 | handleShellCommandEnableDisableInputMethodInternalLocked(userId, imeId, enabled, |
| 5367 | out, error); |
Tarandeep Singh | 87e2e51 | 2019-03-06 14:28:52 -0800 | [diff] [blame] | 5368 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5369 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5370 | return ShellCommandResult.SUCCESS; |
| 5371 | } |
| 5372 | |
| 5373 | /** |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5374 | * A special helper method for commands that only have {@code -u} and {@code --user} options. |
| 5375 | * |
| 5376 | * <p>You cannot use this helper method if the command has other options.</p> |
| 5377 | * |
Yohei Yukawa | 3403f2d | 2019-04-15 08:16:58 -0700 | [diff] [blame] | 5378 | * <p>CAVEAT: This method must be called only once before any other |
| 5379 | * {@link ShellCommand#getNextArg()} and {@link ShellCommand#getNextArgRequired()} for the |
| 5380 | * main arguments.</p> |
| 5381 | * |
Yohei Yukawa | e177170 | 2019-04-10 23:20:51 -0700 | [diff] [blame] | 5382 | * @param shellCommand {@link ShellCommand} from which options should be obtained. |
| 5383 | * @return User ID to be resolved. {@link UserHandle#CURRENT} if not specified. |
| 5384 | */ |
| 5385 | @BinderThread |
| 5386 | @UserIdInt |
| 5387 | private static int handleOptionsForCommandsThatOnlyHaveUserOption(ShellCommand shellCommand) { |
| 5388 | while (true) { |
| 5389 | final String nextOption = shellCommand.getNextOption(); |
| 5390 | if (nextOption == null) { |
| 5391 | break; |
| 5392 | } |
| 5393 | switch (nextOption) { |
| 5394 | case "-u": |
| 5395 | case "--user": |
| 5396 | return UserHandle.parseUserArg(shellCommand.getNextArgRequired()); |
| 5397 | } |
| 5398 | } |
| 5399 | return UserHandle.USER_CURRENT; |
| 5400 | } |
| 5401 | |
| 5402 | @BinderThread |
| 5403 | private void handleShellCommandEnableDisableInputMethodInternalLocked( |
| 5404 | @UserIdInt int userId, String imeId, boolean enabled, PrintWriter out, |
| 5405 | PrintWriter error) { |
| 5406 | boolean failedToEnableUnknownIme = false; |
| 5407 | boolean previouslyEnabled = false; |
| 5408 | if (userId == mSettings.getCurrentUserId()) { |
| 5409 | if (enabled && !mMethodMap.containsKey(imeId)) { |
| 5410 | failedToEnableUnknownIme = true; |
| 5411 | } else { |
| 5412 | previouslyEnabled = setInputMethodEnabledLocked(imeId, enabled); |
| 5413 | } |
| 5414 | } else { |
| 5415 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 5416 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 5417 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 5418 | new ArrayMap<>(); |
| 5419 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 5420 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, |
| 5421 | methodMap, methodList); |
| 5422 | final InputMethodSettings settings = new InputMethodSettings(mContext.getResources(), |
| 5423 | mContext.getContentResolver(), methodMap, userId, false); |
| 5424 | if (enabled) { |
| 5425 | if (!methodMap.containsKey(imeId)) { |
| 5426 | failedToEnableUnknownIme = true; |
| 5427 | } else { |
| 5428 | for (InputMethodInfo imi : settings.getEnabledInputMethodListLocked()) { |
| 5429 | if (TextUtils.equals(imi.getId(), imeId)) { |
| 5430 | previouslyEnabled = true; |
| 5431 | break; |
| 5432 | } |
| 5433 | } |
| 5434 | if (!previouslyEnabled) { |
| 5435 | settings.appendAndPutEnabledInputMethodLocked(imeId, false); |
| 5436 | } |
| 5437 | } |
| 5438 | } else { |
| 5439 | previouslyEnabled = |
| 5440 | settings.buildAndPutEnabledInputMethodsStrRemovingIdLocked( |
| 5441 | new StringBuilder(), |
| 5442 | settings.getEnabledInputMethodsAndSubtypeListLocked(), imeId); |
| 5443 | } |
| 5444 | } |
| 5445 | if (failedToEnableUnknownIme) { |
| 5446 | error.print("Unknown input method "); |
| 5447 | error.print(imeId); |
| 5448 | error.println(" cannot be enabled for user #" + userId); |
| 5449 | } else { |
| 5450 | out.print("Input method "); |
| 5451 | out.print(imeId); |
| 5452 | out.print(": "); |
| 5453 | out.print((enabled == previouslyEnabled) ? "already " : "now "); |
| 5454 | out.print(enabled ? "enabled" : "disabled"); |
| 5455 | out.print(" for user #"); |
| 5456 | out.println(userId); |
| 5457 | } |
| 5458 | } |
| 5459 | |
| 5460 | /** |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5461 | * Handles {@code adb shell ime set}. |
| 5462 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 5463 | * @return Exit code of the command. |
| 5464 | */ |
| 5465 | @BinderThread |
| 5466 | @ShellCommandResult |
| 5467 | private int handleShellCommandSetInputMethod(@NonNull ShellCommand shellCommand) { |
Yohei Yukawa | 3403f2d | 2019-04-15 08:16:58 -0700 | [diff] [blame] | 5468 | final int userIdToBeResolved = handleOptionsForCommandsThatOnlyHaveUserOption(shellCommand); |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 5469 | final String imeId = shellCommand.getNextArgRequired(); |
| 5470 | final PrintWriter out = shellCommand.getOutPrintWriter(); |
| 5471 | final PrintWriter error = shellCommand.getErrPrintWriter(); |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 5472 | synchronized (mMethodMap) { |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 5473 | final int[] userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, |
| 5474 | mSettings.getCurrentUserId(), shellCommand.getErrPrintWriter()); |
| 5475 | for (int userId : userIds) { |
| 5476 | if (!userHasDebugPriv(userId, shellCommand)) { |
| 5477 | continue; |
| 5478 | } |
mincheli | 850892b | 2019-12-05 19:47:59 +0800 | [diff] [blame] | 5479 | boolean failedToSelectUnknownIme = !switchToInputMethod(imeId, userId); |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 5480 | if (failedToSelectUnknownIme) { |
| 5481 | error.print("Unknown input method "); |
| 5482 | error.print(imeId); |
| 5483 | error.print(" cannot be selected for user #"); |
| 5484 | error.println(userId); |
| 5485 | } else { |
| 5486 | out.print("Input method "); |
| 5487 | out.print(imeId); |
| 5488 | out.print(" selected for user #"); |
Yohei Yukawa | 3403f2d | 2019-04-15 08:16:58 -0700 | [diff] [blame] | 5489 | out.println(userId); |
Yohei Yukawa | 099f80c | 2019-04-10 23:23:17 -0700 | [diff] [blame] | 5490 | } |
Tarandeep Singh | 87e2e51 | 2019-03-06 14:28:52 -0800 | [diff] [blame] | 5491 | } |
Yohei Yukawa | db25df7 | 2018-12-27 08:40:41 -0800 | [diff] [blame] | 5492 | } |
Yohei Yukawa | 926488d | 2017-12-11 17:24:55 -0800 | [diff] [blame] | 5493 | return ShellCommandResult.SUCCESS; |
| 5494 | } |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5495 | |
| 5496 | /** |
| 5497 | * Handles {@code adb shell ime reset-ime}. |
| 5498 | * @param shellCommand {@link ShellCommand} object that is handling this command. |
| 5499 | * @return Exit code of the command. |
| 5500 | */ |
| 5501 | @BinderThread |
| 5502 | @ShellCommandResult |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5503 | private int handleShellCommandResetInputMethod(@NonNull ShellCommand shellCommand) { |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 5504 | final PrintWriter out = shellCommand.getOutPrintWriter(); |
| 5505 | final int userIdToBeResolved = handleOptionsForCommandsThatOnlyHaveUserOption(shellCommand); |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5506 | synchronized (mMethodMap) { |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 5507 | final int[] userIds = InputMethodUtils.resolveUserId(userIdToBeResolved, |
| 5508 | mSettings.getCurrentUserId(), shellCommand.getErrPrintWriter()); |
| 5509 | for (int userId : userIds) { |
| 5510 | if (!userHasDebugPriv(userId, shellCommand)) { |
| 5511 | continue; |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5512 | } |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 5513 | final String nextIme; |
| 5514 | final List<InputMethodInfo> nextEnabledImes; |
| 5515 | if (userId == mSettings.getCurrentUserId()) { |
Tarandeep Singh | 4fe5b65 | 2020-02-20 17:20:19 -0800 | [diff] [blame] | 5516 | hideCurrentInputLocked(mCurFocusedWindow, 0, null, |
lumark | d85e158 | 2019-12-29 20:20:41 +0800 | [diff] [blame] | 5517 | SoftInputShowHideReason.HIDE_RESET_SHELL_COMMAND); |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 5518 | unbindCurrentMethodLocked(); |
| 5519 | // Reset the current IME |
| 5520 | resetSelectedInputMethodAndSubtypeLocked(null); |
| 5521 | // Also reset the settings of the current IME |
| 5522 | mSettings.putSelectedInputMethod(null); |
| 5523 | // Disable all enabled IMEs. |
| 5524 | mSettings.getEnabledInputMethodListLocked().forEach( |
| 5525 | imi -> setInputMethodEnabledLocked(imi.getId(), false)); |
| 5526 | // Re-enable with default enabled IMEs. |
| 5527 | InputMethodUtils.getDefaultEnabledImes(mContext, mMethodList).forEach( |
| 5528 | imi -> setInputMethodEnabledLocked(imi.getId(), true)); |
| 5529 | updateInputMethodsFromSettingsLocked(true /* enabledMayChange */); |
| 5530 | InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mIPackageManager, |
| 5531 | mSettings.getEnabledInputMethodListLocked(), |
| 5532 | mSettings.getCurrentUserId(), |
| 5533 | mContext.getBasePackageName()); |
| 5534 | nextIme = mSettings.getSelectedInputMethod(); |
| 5535 | nextEnabledImes = mSettings.getEnabledInputMethodListLocked(); |
| 5536 | } else { |
| 5537 | final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>(); |
| 5538 | final ArrayList<InputMethodInfo> methodList = new ArrayList<>(); |
| 5539 | final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = |
| 5540 | new ArrayMap<>(); |
| 5541 | AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); |
| 5542 | queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, |
| 5543 | methodMap, methodList); |
| 5544 | final InputMethodSettings settings = new InputMethodSettings( |
| 5545 | mContext.getResources(), mContext.getContentResolver(), methodMap, |
| 5546 | userId, false); |
| 5547 | |
| 5548 | nextEnabledImes = InputMethodUtils.getDefaultEnabledImes(mContext, methodList); |
| 5549 | nextIme = InputMethodUtils.getMostApplicableDefaultIME(nextEnabledImes).getId(); |
| 5550 | |
| 5551 | // Reset enabled IMEs. |
| 5552 | settings.putEnabledInputMethodsStr(""); |
| 5553 | nextEnabledImes.forEach(imi -> settings.appendAndPutEnabledInputMethodLocked( |
| 5554 | imi.getId(), false)); |
| 5555 | |
| 5556 | // Reset selected IME. |
| 5557 | settings.putSelectedInputMethod(nextIme); |
| 5558 | settings.putSelectedSubtype(NOT_A_SUBTYPE_ID); |
| 5559 | } |
| 5560 | out.println("Reset current and enabled IMEs for user #" + userId); |
| 5561 | out.println(" Selected: " + nextIme); |
| 5562 | nextEnabledImes.forEach(ime -> out.println(" Enabled: " + ime.getId())); |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5563 | } |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5564 | } |
Yohei Yukawa | 2d4b343 | 2019-04-10 23:23:25 -0700 | [diff] [blame] | 5565 | return ShellCommandResult.SUCCESS; |
Yohei Yukawa | cc97ebd | 2017-12-11 17:54:43 -0800 | [diff] [blame] | 5566 | } |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5567 | |
Tarandeep Singh | 87e2e51 | 2019-03-06 14:28:52 -0800 | [diff] [blame] | 5568 | /** |
| 5569 | * @param userId the actual user handle obtained by {@link UserHandle#getIdentifier()} |
| 5570 | * and *not* pseudo ids like {@link UserHandle#USER_ALL etc}. |
| 5571 | * @return {@code true} if userId has debugging privileges. |
| 5572 | * i.e. {@link UserManager#DISALLOW_DEBUGGING_FEATURES} is {@code false}. |
| 5573 | */ |
| 5574 | private boolean userHasDebugPriv(int userId, final ShellCommand shellCommand) { |
| 5575 | if (mUserManager.hasUserRestriction( |
| 5576 | UserManager.DISALLOW_DEBUGGING_FEATURES, UserHandle.of(userId))) { |
| 5577 | shellCommand.getErrPrintWriter().println("User #" + userId |
| 5578 | + " is restricted with DISALLOW_DEBUGGING_FEATURES."); |
| 5579 | return false; |
| 5580 | } |
| 5581 | return true; |
| 5582 | } |
| 5583 | |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5584 | private static final class InputMethodPrivilegedOperationsImpl |
| 5585 | extends IInputMethodPrivilegedOperations.Stub { |
| 5586 | private final InputMethodManagerService mImms; |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 5587 | @NonNull |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5588 | private final IBinder mToken; |
Yohei Yukawa | d3e0fd93 | 2019-01-21 09:16:48 -0800 | [diff] [blame] | 5589 | InputMethodPrivilegedOperationsImpl(InputMethodManagerService imms, |
| 5590 | @NonNull IBinder token) { |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5591 | mImms = imms; |
| 5592 | mToken = token; |
| 5593 | } |
| 5594 | |
| 5595 | @BinderThread |
| 5596 | @Override |
| 5597 | public void setImeWindowStatus(int vis, int backDisposition) { |
| 5598 | mImms.setImeWindowStatus(mToken, vis, backDisposition); |
| 5599 | } |
| 5600 | |
| 5601 | @BinderThread |
| 5602 | @Override |
| 5603 | public void reportStartInput(IBinder startInputToken) { |
| 5604 | mImms.reportStartInput(mToken, startInputToken); |
| 5605 | } |
| 5606 | |
| 5607 | @BinderThread |
| 5608 | @Override |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5609 | public IInputContentUriToken createInputContentUriToken(Uri contentUri, |
| 5610 | String packageName) { |
| 5611 | return mImms.createInputContentUriToken(mToken, contentUri, packageName); |
| 5612 | } |
| 5613 | |
| 5614 | @BinderThread |
| 5615 | @Override |
| 5616 | public void reportFullscreenMode(boolean fullscreen) { |
| 5617 | mImms.reportFullscreenMode(mToken, fullscreen); |
| 5618 | } |
Yohei Yukawa | c7ca368 | 2018-09-09 20:48:38 -0700 | [diff] [blame] | 5619 | |
| 5620 | @BinderThread |
| 5621 | @Override |
| 5622 | public void setInputMethod(String id) { |
| 5623 | mImms.setInputMethod(mToken, id); |
| 5624 | } |
| 5625 | |
| 5626 | @BinderThread |
| 5627 | @Override |
| 5628 | public void setInputMethodAndSubtype(String id, InputMethodSubtype subtype) { |
| 5629 | mImms.setInputMethodAndSubtype(mToken, id, subtype); |
| 5630 | } |
| 5631 | |
| 5632 | @BinderThread |
| 5633 | @Override |
| 5634 | public void hideMySoftInput(int flags) { |
| 5635 | mImms.hideMySoftInput(mToken, flags); |
| 5636 | } |
| 5637 | |
| 5638 | @BinderThread |
| 5639 | @Override |
| 5640 | public void showMySoftInput(int flags) { |
| 5641 | mImms.showMySoftInput(mToken, flags); |
| 5642 | } |
| 5643 | |
| 5644 | @BinderThread |
| 5645 | @Override |
Yohei Yukawa | 41b094f | 2018-09-09 23:58:45 -0700 | [diff] [blame] | 5646 | public void updateStatusIcon(String packageName, @DrawableRes int iconId) { |
Yohei Yukawa | c7ca368 | 2018-09-09 20:48:38 -0700 | [diff] [blame] | 5647 | mImms.updateStatusIcon(mToken, packageName, iconId); |
| 5648 | } |
| 5649 | |
| 5650 | @BinderThread |
| 5651 | @Override |
| 5652 | public boolean switchToPreviousInputMethod() { |
| 5653 | return mImms.switchToPreviousInputMethod(mToken); |
| 5654 | } |
| 5655 | |
| 5656 | @BinderThread |
| 5657 | @Override |
| 5658 | public boolean switchToNextInputMethod(boolean onlyCurrentIme) { |
| 5659 | return mImms.switchToNextInputMethod(mToken, onlyCurrentIme); |
| 5660 | } |
| 5661 | |
| 5662 | @BinderThread |
| 5663 | @Override |
| 5664 | public boolean shouldOfferSwitchingToNextInputMethod() { |
| 5665 | return mImms.shouldOfferSwitchingToNextInputMethod(mToken); |
| 5666 | } |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 5667 | |
| 5668 | @BinderThread |
| 5669 | @Override |
Yohei Yukawa | 9b60ba0 | 2019-01-21 00:06:27 -0800 | [diff] [blame] | 5670 | public void notifyUserAction() { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 5671 | mImms.notifyUserAction(mToken); |
| 5672 | } |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 5673 | |
| 5674 | @BinderThread |
| 5675 | @Override |
| 5676 | public void reportPreRendered(EditorInfo info) { |
| 5677 | mImms.reportPreRendered(mToken, info); |
| 5678 | } |
| 5679 | |
| 5680 | @BinderThread |
| 5681 | @Override |
Tarandeep Singh | bb0e2f7 | 2020-01-15 13:58:29 -0800 | [diff] [blame] | 5682 | public void applyImeVisibility(IBinder windowToken, boolean setVisible) { |
| 5683 | mImms.applyImeVisibility(mToken, windowToken, setVisible); |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 5684 | } |
Yohei Yukawa | c54c117 | 2018-09-06 11:39:50 -0700 | [diff] [blame] | 5685 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5686 | } |