The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007-2008 The Android Open Source Project |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 3 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | * use this file except in compliance with the License. You may obtain a copy of |
| 6 | * the License at |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 7 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 9 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations under |
| 14 | * the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view.inputmethod; |
| 18 | |
Yohei Yukawa | 1fb13c5 | 2019-02-05 07:55:28 -0800 | [diff] [blame] | 19 | import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 20 | import static android.Manifest.permission.WRITE_SECURE_SETTINGS; |
Gilles Debunne | 8cbb4c6 | 2011-01-24 12:33:56 -0800 | [diff] [blame] | 21 | |
Yohei Yukawa | 41b094f | 2018-09-09 23:58:45 -0700 | [diff] [blame] | 22 | import android.annotation.DrawableRes; |
Yohei Yukawa | 2afe2aa | 2016-01-07 18:09:44 -0800 | [diff] [blame] | 23 | import android.annotation.NonNull; |
| 24 | import android.annotation.Nullable; |
Jeff Sharkey | 98af2e4 | 2018-02-16 10:14:57 -0700 | [diff] [blame] | 25 | import android.annotation.RequiresFeature; |
Yoshiki Iguchi | 00d5122 | 2015-05-29 15:36:22 +0900 | [diff] [blame] | 26 | import android.annotation.RequiresPermission; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 27 | import android.annotation.SystemService; |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 28 | import android.annotation.TestApi; |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 29 | import android.annotation.UnsupportedAppUsage; |
Yohei Yukawa | 1fb13c5 | 2019-02-05 07:55:28 -0800 | [diff] [blame] | 30 | import android.annotation.UserIdInt; |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 31 | import android.app.ActivityThread; |
Yohei Yukawa | fd8f721 | 2019-01-22 19:25:44 -0800 | [diff] [blame] | 32 | import android.content.ComponentName; |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 33 | import android.content.ContentResolver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.content.Context; |
Jeff Sharkey | 98af2e4 | 2018-02-16 10:14:57 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 36 | import android.graphics.Matrix; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.graphics.Rect; |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 38 | import android.inputmethodservice.InputMethodService; |
Yohei Yukawa | cb768bc | 2018-10-24 16:05:09 -0700 | [diff] [blame] | 39 | import android.os.Binder; |
Yohei Yukawa | a086f95 | 2018-09-11 11:37:08 -0700 | [diff] [blame] | 40 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
| 43 | import android.os.IBinder; |
| 44 | import android.os.Looper; |
| 45 | import android.os.Message; |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 46 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import android.os.RemoteException; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 48 | import android.os.ResultReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.os.ServiceManager; |
Jeff Sharkey | 49ca529 | 2016-05-10 12:54:45 -0600 | [diff] [blame] | 50 | import android.os.ServiceManager.ServiceNotFoundException; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 51 | import android.os.Trace; |
Yohei Yukawa | 1fb13c5 | 2019-02-05 07:55:28 -0800 | [diff] [blame] | 52 | import android.os.UserHandle; |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 53 | import android.provider.Settings; |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 54 | import android.text.style.SuggestionSpan; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | import android.util.Log; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 56 | import android.util.Pools.Pool; |
| 57 | import android.util.Pools.SimplePool; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | import android.util.PrintWriterPrinter; |
| 59 | import android.util.Printer; |
Yohei Yukawa | b7b7907 | 2014-03-25 11:02:00 +0900 | [diff] [blame] | 60 | import android.util.SparseArray; |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 61 | import android.view.Display; |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 62 | import android.view.ImeInsetsSourceConsumer; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 63 | import android.view.InputChannel; |
| 64 | import android.view.InputEvent; |
| 65 | import android.view.InputEventSender; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | import android.view.KeyEvent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | import android.view.View; |
Dianne Hackborn | 6dd005b | 2011-07-18 13:22:50 -0700 | [diff] [blame] | 68 | import android.view.ViewRootImpl; |
Yohei Yukawa | 22dac1c | 2017-02-12 16:54:16 -0800 | [diff] [blame] | 69 | import android.view.WindowManager.LayoutParams.SoftInputModeFlags; |
Dake Gu | ddf6c1e | 2018-05-10 11:41:19 -0700 | [diff] [blame] | 70 | import android.view.autofill.AutofillManager; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 71 | |
Yohei Yukawa | 3b3a2ad | 2018-09-20 15:50:35 -0700 | [diff] [blame] | 72 | import com.android.internal.annotations.GuardedBy; |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 73 | import com.android.internal.inputmethod.InputMethodDebug; |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 74 | import com.android.internal.inputmethod.InputMethodPrivilegedOperationsRegistry; |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 75 | import com.android.internal.inputmethod.StartInputFlags; |
Yohei Yukawa | c6632df | 2018-10-21 11:47:16 -0700 | [diff] [blame] | 76 | import com.android.internal.inputmethod.StartInputReason; |
Yohei Yukawa | 499e3f7 | 2018-10-21 20:15:11 -0700 | [diff] [blame] | 77 | import com.android.internal.inputmethod.UnbindReason; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 78 | import com.android.internal.os.SomeArgs; |
| 79 | import com.android.internal.view.IInputConnectionWrapper; |
| 80 | import com.android.internal.view.IInputContext; |
| 81 | import com.android.internal.view.IInputMethodClient; |
| 82 | import com.android.internal.view.IInputMethodManager; |
| 83 | import com.android.internal.view.IInputMethodSession; |
| 84 | import com.android.internal.view.InputBindResult; |
Gilles Debunne | d4723bb | 2010-09-02 15:27:32 -0700 | [diff] [blame] | 85 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | import java.io.FileDescriptor; |
| 87 | import java.io.PrintWriter; |
Yohei Yukawa | daf0d1b | 2018-09-20 15:53:07 -0700 | [diff] [blame] | 88 | import java.lang.reflect.Proxy; |
Andreas Gampe | e6748ce | 2015-12-11 18:00:38 -0800 | [diff] [blame] | 89 | import java.util.Arrays; |
Yohei Yukawa | fefedc5 | 2018-12-24 19:43:17 -0800 | [diff] [blame] | 90 | import java.util.Collections; |
| 91 | import java.util.Comparator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | import java.util.List; |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 93 | import java.util.Map; |
Yohei Yukawa | c941fed | 2014-05-14 19:33:35 +0900 | [diff] [blame] | 94 | import java.util.Objects; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | import java.util.concurrent.CountDownLatch; |
| 96 | import java.util.concurrent.TimeUnit; |
| 97 | |
| 98 | /** |
| 99 | * Central system API to the overall input method framework (IMF) architecture, |
| 100 | * which arbitrates interaction between applications and the current input method. |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 101 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | * <p>Topics covered here: |
| 103 | * <ol> |
| 104 | * <li><a href="#ArchitectureOverview">Architecture Overview</a> |
Ken Wakasa | 384f8ba | 2012-03-10 09:59:31 +0900 | [diff] [blame] | 105 | * <li><a href="#Applications">Applications</a> |
| 106 | * <li><a href="#InputMethods">Input Methods</a> |
| 107 | * <li><a href="#Security">Security</a> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | * </ol> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 109 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | * <a name="ArchitectureOverview"></a> |
| 111 | * <h3>Architecture Overview</h3> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 112 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | * <p>There are three primary parties involved in the input method |
| 114 | * framework (IMF) architecture:</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 115 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | * <ul> |
| 117 | * <li> The <strong>input method manager</strong> as expressed by this class |
| 118 | * is the central point of the system that manages interaction between all |
| 119 | * other parts. It is expressed as the client-side API here which exists |
| 120 | * in each application context and communicates with a global system service |
| 121 | * that manages the interaction across all processes. |
| 122 | * <li> An <strong>input method (IME)</strong> implements a particular |
| 123 | * interaction model allowing the user to generate text. The system binds |
Nick Felker | 8efc3ee | 2017-06-26 15:50:19 -0700 | [diff] [blame] | 124 | * to the current input method that is in use, causing it to be created and run, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | * and tells it when to hide and show its UI. Only one IME is running at a time. |
| 126 | * <li> Multiple <strong>client applications</strong> arbitrate with the input |
| 127 | * method manager for input focus and control over the state of the IME. Only |
| 128 | * one such client is ever active (working with the IME) at a time. |
| 129 | * </ul> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 130 | * |
| 131 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | * <a name="Applications"></a> |
| 133 | * <h3>Applications</h3> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 134 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | * <p>In most cases, applications that are using the standard |
| 136 | * {@link android.widget.TextView} or its subclasses will have little they need |
| 137 | * to do to work well with soft input methods. The main things you need to |
| 138 | * be aware of are:</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 139 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | * <ul> |
Gilles Debunne | 8cbb4c6 | 2011-01-24 12:33:56 -0800 | [diff] [blame] | 141 | * <li> Properly set the {@link android.R.attr#inputType} in your editable |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | * text views, so that the input method will have enough context to help the |
| 143 | * user in entering text into them. |
| 144 | * <li> Deal well with losing screen space when the input method is |
| 145 | * displayed. Ideally an application should handle its window being resized |
| 146 | * smaller, but it can rely on the system performing panning of the window |
| 147 | * if needed. You should set the {@link android.R.attr#windowSoftInputMode} |
| 148 | * attribute on your activity or the corresponding values on windows you |
| 149 | * create to help the system determine whether to pan or resize (it will |
| 150 | * try to determine this automatically but may get it wrong). |
| 151 | * <li> You can also control the preferred soft input state (open, closed, etc) |
| 152 | * for your window using the same {@link android.R.attr#windowSoftInputMode} |
| 153 | * attribute. |
| 154 | * </ul> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 155 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | * <p>More finer-grained control is available through the APIs here to directly |
| 157 | * interact with the IMF and its IME -- either showing or hiding the input |
| 158 | * area, letting the user pick an input method, etc.</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 159 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | * <p>For the rare people amongst us writing their own text editors, you |
| 161 | * will need to implement {@link android.view.View#onCreateInputConnection} |
| 162 | * to return a new instance of your own {@link InputConnection} interface |
| 163 | * allowing the IME to interact with your editor.</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 164 | * |
| 165 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | * <a name="InputMethods"></a> |
| 167 | * <h3>Input Methods</h3> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 168 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | * <p>An input method (IME) is implemented |
| 170 | * as a {@link android.app.Service}, typically deriving from |
| 171 | * {@link android.inputmethodservice.InputMethodService}. It must provide |
| 172 | * the core {@link InputMethod} interface, though this is normally handled by |
| 173 | * {@link android.inputmethodservice.InputMethodService} and implementors will |
| 174 | * only need to deal with the higher-level API there.</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 175 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | * See the {@link android.inputmethodservice.InputMethodService} class for |
| 177 | * more information on implementing IMEs. |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 178 | * |
| 179 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | * <a name="Security"></a> |
| 181 | * <h3>Security</h3> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 182 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | * <p>There are a lot of security issues associated with input methods, |
| 184 | * since they essentially have freedom to completely drive the UI and monitor |
| 185 | * everything the user enters. The Android input method framework also allows |
| 186 | * arbitrary third party IMEs, so care must be taken to restrict their |
| 187 | * selection and interactions.</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 188 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | * <p>Here are some key points about the security architecture behind the |
| 190 | * IMF:</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 191 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | * <ul> |
| 193 | * <li> <p>Only the system is allowed to directly access an IME's |
| 194 | * {@link InputMethod} interface, via the |
| 195 | * {@link android.Manifest.permission#BIND_INPUT_METHOD} permission. This is |
| 196 | * enforced in the system by not binding to an input method service that does |
| 197 | * not require this permission, so the system can guarantee no other untrusted |
| 198 | * clients are accessing the current input method outside of its control.</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 199 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | * <li> <p>There may be many client processes of the IMF, but only one may |
| 201 | * be active at a time. The inactive clients can not interact with key |
| 202 | * parts of the IMF through the mechanisms described below.</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 203 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | * <li> <p>Clients of an input method are only given access to its |
| 205 | * {@link InputMethodSession} interface. One instance of this interface is |
| 206 | * created for each client, and only calls from the session associated with |
| 207 | * the active client will be processed by the current IME. This is enforced |
| 208 | * by {@link android.inputmethodservice.AbstractInputMethodService} for normal |
| 209 | * IMEs, but must be explicitly handled by an IME that is customizing the |
| 210 | * raw {@link InputMethodSession} implementation.</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 211 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | * <li> <p>Only the active client's {@link InputConnection} will accept |
| 213 | * operations. The IMF tells each client process whether it is active, and |
| 214 | * the framework enforces that in inactive processes calls on to the current |
| 215 | * InputConnection will be ignored. This ensures that the current IME can |
| 216 | * only deliver events and text edits to the UI that the user sees as |
| 217 | * being in focus.</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 218 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | * <li> <p>An IME can never interact with an {@link InputConnection} while |
| 220 | * the screen is off. This is enforced by making all clients inactive while |
| 221 | * the screen is off, and prevents bad IMEs from driving the UI when the user |
| 222 | * can not be aware of its behavior.</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 223 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | * <li> <p>A client application can ask that the system let the user pick a |
| 225 | * new IME, but can not programmatically switch to one itself. This avoids |
| 226 | * malicious applications from switching the user to their own IME, which |
| 227 | * remains running when the user navigates away to another application. An |
| 228 | * IME, on the other hand, <em>is</em> allowed to programmatically switch |
| 229 | * the system to another IME, since it already has full control of user |
| 230 | * input.</p> |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 231 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | * <li> <p>The user must explicitly enable a new IME in settings before |
| 233 | * they can switch to it, to confirm with the system that they know about it |
| 234 | * and want to make it available for use.</p> |
| 235 | * </ul> |
| 236 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 237 | @SystemService(Context.INPUT_METHOD_SERVICE) |
Jeff Sharkey | 98af2e4 | 2018-02-16 10:14:57 -0700 | [diff] [blame] | 238 | @RequiresFeature(PackageManager.FEATURE_INPUT_METHODS) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | public final class InputMethodManager { |
Dianne Hackborn | 4eba271 | 2009-03-24 19:20:06 -0700 | [diff] [blame] | 240 | static final boolean DEBUG = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | static final String TAG = "InputMethodManager"; |
| 242 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 243 | static final String PENDING_EVENT_COUNTER = "aq:imm"; |
| 244 | |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 245 | private static final int NOT_A_SUBTYPE_ID = -1; |
| 246 | |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 247 | /** |
Yohei Yukawa | fefedc5 | 2018-12-24 19:43:17 -0800 | [diff] [blame] | 248 | * A constant that represents Voice IME. |
| 249 | * |
| 250 | * @see InputMethodSubtype#getMode() |
| 251 | */ |
| 252 | private static final String SUBTYPE_MODE_VOICE = "voice"; |
| 253 | |
| 254 | /** |
Yohei Yukawa | 6c07572 | 2018-09-21 14:52:12 -0700 | [diff] [blame] | 255 | * Ensures that {@link #sInstance} becomes non-{@code null} for application that have directly |
| 256 | * or indirectly relied on {@link #sInstance} via reflection or something like that. |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 257 | * |
Yohei Yukawa | 6c07572 | 2018-09-21 14:52:12 -0700 | [diff] [blame] | 258 | * <p>Here are scenarios we know and there could be more scenarios we are not |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 259 | * aware of right know.</p> |
| 260 | * |
| 261 | * <ul> |
| 262 | * <li>Apps that directly access {@link #sInstance} via reflection, which is currently |
| 263 | * allowed because of {@link UnsupportedAppUsage} annotation. Currently |
| 264 | * {@link android.view.WindowManagerGlobal#getWindowSession()} is likely to guarantee that |
| 265 | * {@link #sInstance} is not {@code null} when such an app is accessing it, but removing |
| 266 | * that code from {@link android.view.WindowManagerGlobal#getWindowSession()} can reveal |
| 267 | * untested code paths in their apps, which probably happen in an early startup time of that |
| 268 | * app.</li> |
| 269 | * <li>Apps that directly access {@link #peekInstance()} via reflection, which is currently |
| 270 | * allowed because of {@link UnsupportedAppUsage} annotation. Currently |
| 271 | * {@link android.view.WindowManagerGlobal#getWindowSession()} is likely to guarantee that |
| 272 | * {@link #peekInstance()} returns non-{@code null} object when such an app is calling |
| 273 | * {@link #peekInstance()}, but removing that code from |
| 274 | * {@link android.view.WindowManagerGlobal#getWindowSession()} can reveal untested code |
| 275 | * paths in their apps, which probably happen in an early startup time of that app. The good |
| 276 | * news is that unlike {@link #sInstance}'s case we can at least work around this scenario |
| 277 | * by changing the semantics of {@link #peekInstance()}, which is currently defined as |
| 278 | * "retrieve the global {@link InputMethodManager} instance, if it exists" to something that |
| 279 | * always returns non-{@code null} {@link InputMethodManager}. However, introducing such an |
| 280 | * workaround can also trigger different compatibility issues if {@link #peekInstance()} was |
| 281 | * called before {@link android.view.WindowManagerGlobal#getWindowSession()} and it expected |
| 282 | * {@link #peekInstance()} to return {@code null} as written in the JavaDoc.</li> |
| 283 | * </ul> |
| 284 | * |
Yohei Yukawa | 6c07572 | 2018-09-21 14:52:12 -0700 | [diff] [blame] | 285 | * <p>Since this is purely a compatibility hack, this method must be used only from |
| 286 | * {@link android.view.WindowManagerGlobal#getWindowSession()} and {@link #getInstance()}.</p> |
| 287 | * |
| 288 | * <p>TODO(Bug 116157766): Remove this method once we clean up {@link UnsupportedAppUsage}.</p> |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 289 | * @hide |
| 290 | */ |
Yohei Yukawa | 6c07572 | 2018-09-21 14:52:12 -0700 | [diff] [blame] | 291 | public static void ensureDefaultInstanceForDefaultDisplayIfNecessary() { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 292 | forContextInternal(Display.DEFAULT_DISPLAY, Looper.getMainLooper()); |
Yohei Yukawa | 6c07572 | 2018-09-21 14:52:12 -0700 | [diff] [blame] | 293 | } |
Yohei Yukawa | a71bb25 | 2018-09-19 19:21:24 -0700 | [diff] [blame] | 294 | |
Yohei Yukawa | 3b3a2ad | 2018-09-20 15:50:35 -0700 | [diff] [blame] | 295 | private static final Object sLock = new Object(); |
| 296 | |
Yohei Yukawa | 6c07572 | 2018-09-21 14:52:12 -0700 | [diff] [blame] | 297 | /** |
| 298 | * @deprecated This cannot be compatible with multi-display. Please do not use this. |
| 299 | */ |
| 300 | @Deprecated |
Yohei Yukawa | 3b3a2ad | 2018-09-20 15:50:35 -0700 | [diff] [blame] | 301 | @GuardedBy("sLock") |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 302 | @UnsupportedAppUsage |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 303 | static InputMethodManager sInstance; |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 304 | |
| 305 | /** |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 306 | * Global map between display to {@link InputMethodManager}. |
| 307 | * |
| 308 | * <p>Currently this map works like a so-called leaky singleton. Once an instance is registered |
| 309 | * for the associated display ID, that instance will never be garbage collected.</p> |
| 310 | * |
| 311 | * <p>TODO(Bug 116699479): Implement instance clean up mechanism.</p> |
| 312 | */ |
| 313 | @GuardedBy("sLock") |
| 314 | private static final SparseArray<InputMethodManager> sInstanceMap = new SparseArray<>(); |
| 315 | |
| 316 | /** |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 317 | * Timeout in milliseconds for delivering a key to an IME. |
| 318 | */ |
| 319 | static final long INPUT_METHOD_NOT_RESPONDING_TIMEOUT = 2500; |
| 320 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 321 | /** @hide */ |
| 322 | public static final int DISPATCH_IN_PROGRESS = -1; |
| 323 | |
| 324 | /** @hide */ |
| 325 | public static final int DISPATCH_NOT_HANDLED = 0; |
| 326 | |
| 327 | /** @hide */ |
| 328 | public static final int DISPATCH_HANDLED = 1; |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 329 | |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 330 | /** @hide */ |
| 331 | public static final int SHOW_IM_PICKER_MODE_AUTO = 0; |
| 332 | /** @hide */ |
| 333 | public static final int SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES = 1; |
| 334 | /** @hide */ |
| 335 | public static final int SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES = 2; |
| 336 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 337 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | final IInputMethodManager mService; |
| 339 | final Looper mMainLooper; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 340 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | // For scheduling work on the main thread. This also serves as our |
| 342 | // global lock. |
Sergey Vasilinets | 6f1b7a2 | 2019-02-06 15:47:43 +0000 | [diff] [blame] | 343 | // Remark on @UnsupportedAppUsage: there were context leaks on old versions |
| 344 | // of android (b/37043700), so developers used this field to perform manual clean up. |
| 345 | // Leaks were fixed, hacks were backported to AppCompatActivity, |
| 346 | // so an access to the field is closed. |
| 347 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | final H mH; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 349 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | // Our generic input connection if the current target does not have its own. |
| 351 | final IInputContext mIInputContext; |
| 352 | |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 353 | private final int mDisplayId; |
| 354 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | /** |
| 356 | * True if this input method client is active, initially false. |
| 357 | */ |
| 358 | boolean mActive = false; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | /** |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 361 | * {@code true} if next {@link #onPostWindowFocus(View, View, int, boolean, int)} needs to |
| 362 | * restart input. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | */ |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 364 | boolean mRestartOnNextWindowFocus = true; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | /** |
| 367 | * As reported by IME through InputConnection. |
| 368 | */ |
| 369 | boolean mFullscreenMode; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | // ----------------------------------------------------------- |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 372 | |
Wale Ogunwale | 159c3d8 | 2015-05-14 12:20:53 -0700 | [diff] [blame] | 373 | /** |
| 374 | * This is the root view of the overall window that currently has input |
| 375 | * method focus. |
| 376 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 377 | @UnsupportedAppUsage |
Wale Ogunwale | 159c3d8 | 2015-05-14 12:20:53 -0700 | [diff] [blame] | 378 | View mCurRootView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | /** |
| 380 | * This is the view that should currently be served by an input method, |
| 381 | * regardless of the state of setting that up. |
| 382 | */ |
Sergey Vasilinets | 6f1b7a2 | 2019-02-06 15:47:43 +0000 | [diff] [blame] | 383 | // See comment to mH field in regard to @UnsupportedAppUsage |
| 384 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | View mServedView; |
| 386 | /** |
| 387 | * This is then next view that will be served by the input method, when |
| 388 | * we get around to updating things. |
| 389 | */ |
Sergey Vasilinets | 6f1b7a2 | 2019-02-06 15:47:43 +0000 | [diff] [blame] | 390 | // See comment to mH field in regard to @UnsupportedAppUsage |
| 391 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | View mNextServedView; |
| 393 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 394 | * This is set when we are in the process of connecting, to determine |
| 395 | * when we have actually finished. |
| 396 | */ |
| 397 | boolean mServedConnecting; |
| 398 | /** |
| 399 | * This is non-null when we have connected the served view; it holds |
| 400 | * the attributes that were last retrieved from the served view and given |
| 401 | * to the input connection. |
| 402 | */ |
| 403 | EditorInfo mCurrentTextBoxAttribute; |
| 404 | /** |
| 405 | * The InputConnection that was last retrieved from the served view. |
| 406 | */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 407 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 408 | ControlledInputConnectionWrapper mServedInputConnectionWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | /** |
| 410 | * The completions that were last provided by the served view. |
| 411 | */ |
| 412 | CompletionInfo[] mCompletions; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | // Cursor position on the screen. |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 415 | @UnsupportedAppUsage |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 416 | Rect mTmpCursorRect = new Rect(); |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 417 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | Rect mCursorRect = new Rect(); |
| 419 | int mCursorSelStart; |
| 420 | int mCursorSelEnd; |
| 421 | int mCursorCandStart; |
| 422 | int mCursorCandEnd; |
Yohei Yukawa | 056ffe6 | 2014-05-13 14:26:09 +0900 | [diff] [blame] | 423 | |
| 424 | /** |
| 425 | * The instance that has previously been sent to the input method. |
| 426 | */ |
| 427 | private CursorAnchorInfo mCursorAnchorInfo = null; |
| 428 | |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 429 | /** |
| 430 | * A special {@link Matrix} that can be provided by the system when this instance is running |
| 431 | * inside a virtual display that is managed by {@link android.app.ActivityView}. |
| 432 | * |
| 433 | * <p>If this is non-{@code null}, {@link #updateCursorAnchorInfo(View, CursorAnchorInfo)} |
| 434 | * should be adjusted with this {@link Matrix}.</p> |
| 435 | * |
| 436 | * <p>{@code null} when not used.</p> |
| 437 | */ |
| 438 | private Matrix mActivityViewToScreenMatrix = null; |
| 439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | // ----------------------------------------------------------- |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 441 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | /** |
| 443 | * Sequence number of this binding, as returned by the server. |
| 444 | */ |
| 445 | int mBindSequence = -1; |
| 446 | /** |
| 447 | * ID of the method we are bound to. |
| 448 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 449 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | String mCurId; |
| 451 | /** |
| 452 | * The actual instance of the method to make calls on it. |
| 453 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 454 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | IInputMethodSession mCurMethod; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 456 | InputChannel mCurChannel; |
| 457 | ImeInputEventSender mCurSender; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 459 | private static final int REQUEST_UPDATE_CURSOR_ANCHOR_INFO_NONE = 0x0; |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 460 | |
| 461 | /** |
| 462 | * The monitor mode for {@link #updateCursorAnchorInfo(View, CursorAnchorInfo)}. |
| 463 | */ |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 464 | private int mRequestUpdateCursorAnchorInfoMonitorMode = REQUEST_UPDATE_CURSOR_ANCHOR_INFO_NONE; |
Yohei Yukawa | b7b7907 | 2014-03-25 11:02:00 +0900 | [diff] [blame] | 465 | |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 466 | /** |
| 467 | * When {@link ViewRootImpl#sNewInsetsMode} is set to |
| 468 | * >= {@link ViewRootImpl#NEW_INSETS_MODE_IME}, {@link ImeInsetsSourceConsumer} applies the |
| 469 | * IME visibility and listens for other state changes. |
| 470 | */ |
| 471 | private ImeInsetsSourceConsumer mImeInsetsConsumer; |
| 472 | |
Yohei Yukawa | b0377bb | 2015-08-10 21:06:30 -0700 | [diff] [blame] | 473 | final Pool<PendingEvent> mPendingEventPool = new SimplePool<>(20); |
| 474 | final SparseArray<PendingEvent> mPendingEvents = new SparseArray<>(20); |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 475 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | // ----------------------------------------------------------- |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | static final int MSG_DUMP = 1; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 479 | static final int MSG_BIND = 2; |
| 480 | static final int MSG_UNBIND = 3; |
| 481 | static final int MSG_SET_ACTIVE = 4; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 482 | static final int MSG_SEND_INPUT_EVENT = 5; |
| 483 | static final int MSG_TIMEOUT_INPUT_EVENT = 6; |
| 484 | static final int MSG_FLUSH_INPUT_EVENT = 7; |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 485 | static final int MSG_REPORT_FULLSCREEN_MODE = 10; |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 486 | static final int MSG_REPORT_PRE_RENDERED = 15; |
| 487 | static final int MSG_APPLY_IME_VISIBILITY = 20; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 488 | static final int MSG_UPDATE_ACTIVITY_VIEW_TO_SCREEN_MATRIX = 30; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 489 | |
Dake Gu | ddf6c1e | 2018-05-10 11:41:19 -0700 | [diff] [blame] | 490 | private static boolean isAutofillUIShowing(View servedView) { |
| 491 | AutofillManager afm = servedView.getContext().getSystemService(AutofillManager.class); |
| 492 | return afm != null && afm.isAutofillUiShowing(); |
| 493 | } |
| 494 | |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 495 | /** |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 496 | * Returns fallback {@link InputMethodManager} if the called one is not likely to be compatible |
| 497 | * with the given {@code view}. |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 498 | * |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 499 | * @param view {@link View} to be checked. |
| 500 | * @return {@code null} when it is unnecessary (or impossible) to use fallback |
| 501 | * {@link InputMethodManager} to which IME API calls need to be re-dispatched. |
| 502 | * Non-{@code null} {@link InputMethodManager} if this method believes it'd be safer to |
| 503 | * re-dispatch IME APIs calls on it. |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 504 | */ |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 505 | @Nullable |
| 506 | private InputMethodManager getFallbackInputMethodManagerIfNecessary(@Nullable View view) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 507 | if (view == null) { |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 508 | return null; |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 509 | } |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 510 | // As evidenced in Bug 118341760, view.getViewRootImpl().getDisplayId() is supposed to be |
| 511 | // more reliable to determine with which display the given view is interacting than |
| 512 | // view.getContext().getDisplayId() / view.getContext().getSystemService(), which can be |
| 513 | // easily messed up by app developers (or library authors) by creating inconsistent |
| 514 | // ContextWrapper objects that re-dispatch those methods to other Context such as |
| 515 | // ApplicationContext. |
| 516 | final ViewRootImpl viewRootImpl = view.getViewRootImpl(); |
| 517 | if (viewRootImpl == null) { |
| 518 | return null; |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 519 | } |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 520 | final int viewRootDisplayId = viewRootImpl.getDisplayId(); |
| 521 | if (viewRootDisplayId == mDisplayId) { |
| 522 | // Expected case. Good to go. |
| 523 | return null; |
| 524 | } |
| 525 | final InputMethodManager fallbackImm = |
Charles Chen | 5299ad0 | 2019-04-18 13:09:53 +0000 | [diff] [blame] | 526 | viewRootImpl.mContext.getSystemService(InputMethodManager.class); |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 527 | if (fallbackImm == null) { |
| 528 | Log.e(TAG, "b/117267690: Failed to get non-null fallback IMM. view=" + view); |
| 529 | return null; |
| 530 | } |
| 531 | if (fallbackImm.mDisplayId != viewRootDisplayId) { |
| 532 | Log.e(TAG, "b/117267690: Failed to get fallback IMM with expected displayId=" |
| 533 | + viewRootDisplayId + " actual IMM#displayId=" + fallbackImm.mDisplayId |
| 534 | + " view=" + view); |
| 535 | return null; |
| 536 | } |
| 537 | Log.w(TAG, "b/117267690: Display ID mismatch found." |
| 538 | + " ViewRootImpl displayId=" + viewRootDisplayId |
| 539 | + " InputMethodManager displayId=" + mDisplayId |
| 540 | + ". Use the right InputMethodManager instance to avoid performance overhead.", |
| 541 | new Throwable()); |
| 542 | return fallbackImm; |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 543 | } |
| 544 | |
Dake Gu | ddf6c1e | 2018-05-10 11:41:19 -0700 | [diff] [blame] | 545 | private static boolean canStartInput(View servedView) { |
| 546 | // We can start input ether the servedView has window focus |
| 547 | // or the activity is showing autofill ui. |
| 548 | return servedView.hasWindowFocus() || isAutofillUIShowing(servedView); |
| 549 | } |
| 550 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | class H extends Handler { |
| 552 | H(Looper looper) { |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 553 | super(looper, null, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 555 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | @Override |
| 557 | public void handleMessage(Message msg) { |
| 558 | switch (msg.what) { |
| 559 | case MSG_DUMP: { |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 560 | SomeArgs args = (SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | try { |
| 562 | doDump((FileDescriptor)args.arg1, |
| 563 | (PrintWriter)args.arg2, (String[])args.arg3); |
| 564 | } catch (RuntimeException e) { |
| 565 | ((PrintWriter)args.arg2).println("Exception: " + e); |
| 566 | } |
| 567 | synchronized (args.arg4) { |
| 568 | ((CountDownLatch)args.arg4).countDown(); |
| 569 | } |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 570 | args.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 571 | return; |
| 572 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 573 | case MSG_BIND: { |
| 574 | final InputBindResult res = (InputBindResult)msg.obj; |
Satoshi Kataoka | 4e5184f | 2012-07-13 23:10:58 +0900 | [diff] [blame] | 575 | if (DEBUG) { |
| 576 | Log.i(TAG, "handleMessage: MSG_BIND " + res.sequence + "," + res.id); |
| 577 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 578 | synchronized (mH) { |
| 579 | if (mBindSequence < 0 || mBindSequence != res.sequence) { |
| 580 | Log.w(TAG, "Ignoring onBind: cur seq=" + mBindSequence |
| 581 | + ", given seq=" + res.sequence); |
Jeff Brown | 4d65688 | 2013-04-03 14:39:19 -0700 | [diff] [blame] | 582 | if (res.channel != null && res.channel != mCurChannel) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 583 | res.channel.dispose(); |
| 584 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 585 | return; |
| 586 | } |
Jeff Brown | 4d65688 | 2013-04-03 14:39:19 -0700 | [diff] [blame] | 587 | |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 588 | mRequestUpdateCursorAnchorInfoMonitorMode = |
| 589 | REQUEST_UPDATE_CURSOR_ANCHOR_INFO_NONE; |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 590 | |
Jeff Brown | 4d65688 | 2013-04-03 14:39:19 -0700 | [diff] [blame] | 591 | setInputChannelLocked(res.channel); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 592 | mCurMethod = res.method; |
| 593 | mCurId = res.id; |
| 594 | mBindSequence = res.sequence; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 595 | mActivityViewToScreenMatrix = res.getActivityViewToScreenMatrix(); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 596 | } |
Yohei Yukawa | 4219422 | 2018-10-21 20:14:40 -0700 | [diff] [blame] | 597 | startInputInner(StartInputReason.BOUND_TO_IMMS, null, 0, 0, 0); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 598 | return; |
| 599 | } |
| 600 | case MSG_UNBIND: { |
| 601 | final int sequence = msg.arg1; |
Yohei Yukawa | 499e3f7 | 2018-10-21 20:15:11 -0700 | [diff] [blame] | 602 | @UnbindReason |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 603 | final int reason = msg.arg2; |
Satoshi Kataoka | 4e5184f | 2012-07-13 23:10:58 +0900 | [diff] [blame] | 604 | if (DEBUG) { |
Yohei Yukawa | 33e8179 | 2015-11-17 21:14:42 -0800 | [diff] [blame] | 605 | Log.i(TAG, "handleMessage: MSG_UNBIND " + sequence + |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 606 | " reason=" + InputMethodDebug.unbindReasonToString(reason)); |
Satoshi Kataoka | 4e5184f | 2012-07-13 23:10:58 +0900 | [diff] [blame] | 607 | } |
Yohei Yukawa | 678e38e | 2015-11-13 18:36:21 -0800 | [diff] [blame] | 608 | final boolean startInput; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 609 | synchronized (mH) { |
Yohei Yukawa | 678e38e | 2015-11-13 18:36:21 -0800 | [diff] [blame] | 610 | if (mBindSequence != sequence) { |
| 611 | return; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 612 | } |
Yohei Yukawa | 678e38e | 2015-11-13 18:36:21 -0800 | [diff] [blame] | 613 | clearBindingLocked(); |
| 614 | // If we were actively using the last input method, then |
| 615 | // we would like to re-connect to the next input method. |
| 616 | if (mServedView != null && mServedView.isFocused()) { |
| 617 | mServedConnecting = true; |
| 618 | } |
| 619 | startInput = mActive; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 620 | } |
Dianne Hackborn | 06a591c | 2012-02-16 10:25:26 -0800 | [diff] [blame] | 621 | if (startInput) { |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 622 | startInputInner( |
Yohei Yukawa | 4219422 | 2018-10-21 20:14:40 -0700 | [diff] [blame] | 623 | StartInputReason.UNBOUND_FROM_IMMS, null, 0, 0, 0); |
Dianne Hackborn | 06a591c | 2012-02-16 10:25:26 -0800 | [diff] [blame] | 624 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 625 | return; |
| 626 | } |
| 627 | case MSG_SET_ACTIVE: { |
| 628 | final boolean active = msg.arg1 != 0; |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 629 | final boolean fullscreen = msg.arg2 != 0; |
Satoshi Kataoka | 4e5184f | 2012-07-13 23:10:58 +0900 | [diff] [blame] | 630 | if (DEBUG) { |
| 631 | Log.i(TAG, "handleMessage: MSG_SET_ACTIVE " + active + ", was " + mActive); |
| 632 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 633 | synchronized (mH) { |
| 634 | mActive = active; |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 635 | mFullscreenMode = fullscreen; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 636 | if (!active) { |
| 637 | // Some other client has starting using the IME, so note |
| 638 | // that this happened and make sure our own editor's |
| 639 | // state is reset. |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 640 | mRestartOnNextWindowFocus = true; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 641 | try { |
| 642 | // Note that finishComposingText() is allowed to run |
| 643 | // even when we are not active. |
| 644 | mIInputContext.finishComposingText(); |
| 645 | } catch (RemoteException e) { |
| 646 | } |
Mikael Gullstrand | 82ae3ff | 2014-11-25 12:41:53 +0100 | [diff] [blame] | 647 | } |
| 648 | // Check focus again in case that "onWindowFocus" is called before |
| 649 | // handling this message. |
Dake Gu | ddf6c1e | 2018-05-10 11:41:19 -0700 | [diff] [blame] | 650 | if (mServedView != null && canStartInput(mServedView)) { |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 651 | if (checkFocusNoStartInput(mRestartOnNextWindowFocus)) { |
Yohei Yukawa | 4219422 | 2018-10-21 20:14:40 -0700 | [diff] [blame] | 652 | final int reason = active ? StartInputReason.ACTIVATED_BY_IMMS |
| 653 | : StartInputReason.DEACTIVATED_BY_IMMS; |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 654 | startInputInner(reason, null, 0, 0, 0); |
satok | 05a6cbe | 2012-04-05 23:04:08 +0900 | [diff] [blame] | 655 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | return; |
| 659 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 660 | case MSG_SEND_INPUT_EVENT: { |
| 661 | sendInputEventAndReportResultOnMainLooper((PendingEvent)msg.obj); |
| 662 | return; |
| 663 | } |
| 664 | case MSG_TIMEOUT_INPUT_EVENT: { |
| 665 | finishedInputEvent(msg.arg1, false, true); |
| 666 | return; |
| 667 | } |
| 668 | case MSG_FLUSH_INPUT_EVENT: { |
| 669 | finishedInputEvent(msg.arg1, false, false); |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 670 | return; |
| 671 | } |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 672 | case MSG_REPORT_FULLSCREEN_MODE: { |
| 673 | final boolean fullscreen = msg.arg1 != 0; |
| 674 | InputConnection ic = null; |
| 675 | synchronized (mH) { |
| 676 | mFullscreenMode = fullscreen; |
| 677 | if (mServedInputConnectionWrapper != null) { |
| 678 | ic = mServedInputConnectionWrapper.getInputConnection(); |
| 679 | } |
| 680 | } |
| 681 | if (ic != null) { |
| 682 | ic.reportFullscreenMode(fullscreen); |
| 683 | } |
| 684 | return; |
Yohei Yukawa | 3d1e812 | 2014-06-06 19:12:47 +0900 | [diff] [blame] | 685 | } |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 686 | case MSG_REPORT_PRE_RENDERED: { |
| 687 | synchronized (mH) { |
| 688 | if (mImeInsetsConsumer != null) { |
| 689 | mImeInsetsConsumer.onPreRendered((EditorInfo) msg.obj); |
| 690 | } |
| 691 | } |
| 692 | return; |
| 693 | |
| 694 | } |
| 695 | case MSG_APPLY_IME_VISIBILITY: { |
| 696 | synchronized (mH) { |
| 697 | if (mImeInsetsConsumer != null) { |
| 698 | mImeInsetsConsumer.applyImeVisibility(msg.arg1 != 0); |
| 699 | } |
| 700 | } |
| 701 | return; |
| 702 | } |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 703 | case MSG_UPDATE_ACTIVITY_VIEW_TO_SCREEN_MATRIX: { |
| 704 | final float[] matrixValues = (float[]) msg.obj; |
| 705 | final int bindSequence = msg.arg1; |
| 706 | synchronized (mH) { |
| 707 | if (mBindSequence != bindSequence) { |
| 708 | return; |
| 709 | } |
| 710 | if (matrixValues == null) { |
| 711 | // That this app is unbound from the parent ActivityView. In this case, |
| 712 | // calling updateCursorAnchorInfo() isn't safe. Only clear the matrix. |
| 713 | mActivityViewToScreenMatrix = null; |
| 714 | return; |
| 715 | } |
| 716 | |
| 717 | final float[] currentValues = new float[9]; |
| 718 | mActivityViewToScreenMatrix.getValues(currentValues); |
| 719 | if (Arrays.equals(currentValues, matrixValues)) { |
| 720 | return; |
| 721 | } |
| 722 | mActivityViewToScreenMatrix.setValues(matrixValues); |
| 723 | |
| 724 | if (mCursorAnchorInfo == null || mCurMethod == null |
| 725 | || mServedInputConnectionWrapper == null) { |
| 726 | return; |
| 727 | } |
| 728 | final boolean isMonitoring = (mRequestUpdateCursorAnchorInfoMonitorMode |
| 729 | & InputConnection.CURSOR_UPDATE_MONITOR) != 0; |
| 730 | if (!isMonitoring) { |
| 731 | return; |
| 732 | } |
| 733 | // Since the host ActivityView is moved, we need to issue |
| 734 | // IMS#updateCursorAnchorInfo() again. |
| 735 | try { |
| 736 | mCurMethod.updateCursorAnchorInfo( |
| 737 | CursorAnchorInfo.createForAdditionalParentMatrix( |
| 738 | mCursorAnchorInfo, mActivityViewToScreenMatrix)); |
| 739 | } catch (RemoteException e) { |
| 740 | Log.w(TAG, "IME died: " + mCurId, e); |
| 741 | } |
| 742 | } |
| 743 | return; |
| 744 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | } |
Yohei Yukawa | 159dd47 | 2016-01-07 16:52:33 -0800 | [diff] [blame] | 748 | |
Jean Chalard | de9dbb0 | 2011-10-20 19:50:45 +0900 | [diff] [blame] | 749 | private static class ControlledInputConnectionWrapper extends IInputConnectionWrapper { |
| 750 | private final InputMethodManager mParentInputMethodManager; |
| 751 | |
| 752 | public ControlledInputConnectionWrapper(final Looper mainLooper, final InputConnection conn, |
| 753 | final InputMethodManager inputMethodManager) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | super(mainLooper, conn); |
Jean Chalard | de9dbb0 | 2011-10-20 19:50:45 +0900 | [diff] [blame] | 755 | mParentInputMethodManager = inputMethodManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 756 | } |
| 757 | |
Gilles Debunne | 8cbb4c6 | 2011-01-24 12:33:56 -0800 | [diff] [blame] | 758 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | public boolean isActive() { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame] | 760 | return mParentInputMethodManager.mActive && !isFinished(); |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | void deactivate() { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame] | 764 | if (isFinished()) { |
| 765 | // This is a small performance optimization. Still only the 1st call of |
| 766 | // reportFinish() will take effect. |
| 767 | return; |
| 768 | } |
Yohei Yukawa | 9f9afe52 | 2016-03-30 12:03:51 -0700 | [diff] [blame] | 769 | closeConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | } |
Yohei Yukawa | 12d66c2 | 2015-11-18 13:44:14 -0800 | [diff] [blame] | 771 | |
| 772 | @Override |
| 773 | public String toString() { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame] | 774 | return "ControlledInputConnectionWrapper{" |
| 775 | + "connection=" + getInputConnection() |
| 776 | + " finished=" + isFinished() |
Yohei Yukawa | 12d66c2 | 2015-11-18 13:44:14 -0800 | [diff] [blame] | 777 | + " mParentInputMethodManager.mActive=" + mParentInputMethodManager.mActive |
| 778 | + "}"; |
| 779 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 780 | } |
Yohei Yukawa | 159dd47 | 2016-01-07 16:52:33 -0800 | [diff] [blame] | 781 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | final IInputMethodClient.Stub mClient = new IInputMethodClient.Stub() { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 783 | @Override |
| 784 | protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | // No need to check for dump permission, since we only give this |
| 786 | // interface to the system. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | CountDownLatch latch = new CountDownLatch(1); |
Svetoslav Ganov | 758143e | 2012-08-06 16:40:27 -0700 | [diff] [blame] | 788 | SomeArgs sargs = SomeArgs.obtain(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 789 | sargs.arg1 = fd; |
| 790 | sargs.arg2 = fout; |
| 791 | sargs.arg3 = args; |
| 792 | sargs.arg4 = latch; |
| 793 | mH.sendMessage(mH.obtainMessage(MSG_DUMP, sargs)); |
| 794 | try { |
| 795 | if (!latch.await(5, TimeUnit.SECONDS)) { |
| 796 | fout.println("Timeout waiting for dump"); |
| 797 | } |
| 798 | } catch (InterruptedException e) { |
| 799 | fout.println("Interrupted waiting for dump"); |
| 800 | } |
| 801 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 802 | |
| 803 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | public void onBindMethod(InputBindResult res) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 805 | mH.obtainMessage(MSG_BIND, res).sendToTarget(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 807 | |
| 808 | @Override |
Yohei Yukawa | 499e3f7 | 2018-10-21 20:15:11 -0700 | [diff] [blame] | 809 | public void onUnbindMethod(int sequence, @UnbindReason int unbindReason) { |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 810 | mH.obtainMessage(MSG_UNBIND, sequence, unbindReason).sendToTarget(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 812 | |
| 813 | @Override |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 814 | public void setActive(boolean active, boolean fullscreen) { |
| 815 | mH.obtainMessage(MSG_SET_ACTIVE, active ? 1 : 0, fullscreen ? 1 : 0).sendToTarget(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 | } |
Yohei Yukawa | b7b7907 | 2014-03-25 11:02:00 +0900 | [diff] [blame] | 817 | |
| 818 | @Override |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 819 | public void reportFullscreenMode(boolean fullscreen) { |
| 820 | mH.obtainMessage(MSG_REPORT_FULLSCREEN_MODE, fullscreen ? 1 : 0, 0) |
| 821 | .sendToTarget(); |
| 822 | } |
| 823 | |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 824 | @Override |
| 825 | public void reportPreRendered(EditorInfo info) { |
| 826 | mH.obtainMessage(MSG_REPORT_PRE_RENDERED, 0, 0, info) |
| 827 | .sendToTarget(); |
| 828 | } |
| 829 | |
| 830 | @Override |
| 831 | public void applyImeVisibility(boolean setVisible) { |
| 832 | mH.obtainMessage(MSG_APPLY_IME_VISIBILITY, setVisible ? 1 : 0, 0) |
| 833 | .sendToTarget(); |
| 834 | } |
| 835 | |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 836 | @Override |
| 837 | public void updateActivityViewToScreenMatrix(int bindSequence, float[] matrixValues) { |
| 838 | mH.obtainMessage(MSG_UPDATE_ACTIVITY_VIEW_TO_SCREEN_MATRIX, bindSequence, 0, |
| 839 | matrixValues).sendToTarget(); |
| 840 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 841 | }; |
| 842 | |
Dianne Hackborn | 51bf077 | 2009-03-24 19:11:41 -0700 | [diff] [blame] | 843 | final InputConnection mDummyInputConnection = new BaseInputConnection(this, false); |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 844 | |
Yohei Yukawa | daf0d1b | 2018-09-20 15:53:07 -0700 | [diff] [blame] | 845 | /** |
| 846 | * For layoutlib to clean up static objects inside {@link InputMethodManager}. |
| 847 | */ |
| 848 | static void tearDownEditMode() { |
| 849 | if (!isInEditMode()) { |
| 850 | throw new UnsupportedOperationException( |
| 851 | "This method must be called only from layoutlib"); |
| 852 | } |
| 853 | synchronized (sLock) { |
| 854 | sInstance = null; |
| 855 | } |
Jeff Sharkey | a4603d3c | 2016-08-11 16:54:13 -0600 | [diff] [blame] | 856 | } |
| 857 | |
Yohei Yukawa | daf0d1b | 2018-09-20 15:53:07 -0700 | [diff] [blame] | 858 | /** |
| 859 | * For layoutlib to override this method to return {@code true}. |
| 860 | * |
| 861 | * @return {@code true} if the process is running for developer tools |
| 862 | * @see View#isInEditMode() |
| 863 | */ |
| 864 | private static boolean isInEditMode() { |
| 865 | return false; |
| 866 | } |
| 867 | |
Yohei Yukawa | f682b1a5c4 | 2018-10-24 16:05:02 -0700 | [diff] [blame] | 868 | @NonNull |
| 869 | private static InputMethodManager createInstance(int displayId, Looper looper) { |
| 870 | return isInEditMode() ? createStubInstance(displayId, looper) |
| 871 | : createRealInstance(displayId, looper); |
Yohei Yukawa | daf0d1b | 2018-09-20 15:53:07 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Yohei Yukawa | f682b1a5c4 | 2018-10-24 16:05:02 -0700 | [diff] [blame] | 874 | @NonNull |
| 875 | private static InputMethodManager createRealInstance(int displayId, Looper looper) { |
| 876 | final IInputMethodManager service; |
| 877 | try { |
| 878 | service = IInputMethodManager.Stub.asInterface( |
| 879 | ServiceManager.getServiceOrThrow(Context.INPUT_METHOD_SERVICE)); |
| 880 | } catch (ServiceNotFoundException e) { |
| 881 | throw new IllegalStateException(e); |
| 882 | } |
| 883 | final InputMethodManager imm = new InputMethodManager(service, displayId, looper); |
Yohei Yukawa | cb768bc | 2018-10-24 16:05:09 -0700 | [diff] [blame] | 884 | // InputMethodManagerService#addClient() relies on Binder.getCalling{Pid, Uid}() to |
| 885 | // associate PID/UID with each IME client. This means: |
| 886 | // A. if this method call will be handled as an IPC, there is no problem. |
| 887 | // B. if this method call will be handled as an in-proc method call, we need to |
| 888 | // ensure that Binder.getCalling{Pid, Uid}() return Process.my{Pid, Uid}() |
| 889 | // Either ways we can always call Binder.{clear, restore}CallingIdentity() because |
| 890 | // 1) doing so has no effect for A and 2) doing so is sufficient for B. |
| 891 | final long identity = Binder.clearCallingIdentity(); |
Yohei Yukawa | f682b1a5c4 | 2018-10-24 16:05:02 -0700 | [diff] [blame] | 892 | try { |
| 893 | service.addClient(imm.mClient, imm.mIInputContext, displayId); |
| 894 | } catch (RemoteException e) { |
| 895 | e.rethrowFromSystemServer(); |
Yohei Yukawa | cb768bc | 2018-10-24 16:05:09 -0700 | [diff] [blame] | 896 | } finally { |
| 897 | Binder.restoreCallingIdentity(identity); |
Yohei Yukawa | f682b1a5c4 | 2018-10-24 16:05:02 -0700 | [diff] [blame] | 898 | } |
| 899 | return imm; |
| 900 | } |
| 901 | |
| 902 | @NonNull |
| 903 | private static InputMethodManager createStubInstance(int displayId, Looper looper) { |
| 904 | // If InputMethodManager is running for layoutlib, stub out IPCs into IMMS. |
| 905 | final Class<IInputMethodManager> c = IInputMethodManager.class; |
| 906 | final IInputMethodManager stubInterface = |
| 907 | (IInputMethodManager) Proxy.newProxyInstance(c.getClassLoader(), |
| 908 | new Class[]{c}, (proxy, method, args) -> { |
| 909 | final Class<?> returnType = method.getReturnType(); |
| 910 | if (returnType == boolean.class) { |
| 911 | return false; |
| 912 | } else if (returnType == int.class) { |
| 913 | return 0; |
| 914 | } else if (returnType == long.class) { |
| 915 | return 0L; |
| 916 | } else if (returnType == short.class) { |
| 917 | return 0; |
| 918 | } else if (returnType == char.class) { |
| 919 | return 0; |
| 920 | } else if (returnType == byte.class) { |
| 921 | return 0; |
| 922 | } else if (returnType == float.class) { |
| 923 | return 0f; |
| 924 | } else if (returnType == double.class) { |
| 925 | return 0.0; |
| 926 | } else { |
| 927 | return null; |
| 928 | } |
| 929 | }); |
| 930 | return new InputMethodManager(stubInterface, displayId, looper); |
| 931 | } |
| 932 | |
| 933 | private InputMethodManager(IInputMethodManager service, int displayId, Looper looper) { |
| 934 | mService = service; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | mMainLooper = looper; |
| 936 | mH = new H(looper); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 937 | mDisplayId = displayId; |
Yohei Yukawa | f682b1a5c4 | 2018-10-24 16:05:02 -0700 | [diff] [blame] | 938 | mIInputContext = new ControlledInputConnectionWrapper(looper, mDummyInputConnection, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | /** |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 942 | * Retrieve an instance for the given {@link Context}, creating it if it doesn't already exist. |
Yohei Yukawa | 6c07572 | 2018-09-21 14:52:12 -0700 | [diff] [blame] | 943 | * |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 944 | * @param context {@link Context} for which IME APIs need to work |
| 945 | * @return {@link InputMethodManager} instance |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 946 | * @hide |
| 947 | */ |
Yohei Yukawa | f682b1a5c4 | 2018-10-24 16:05:02 -0700 | [diff] [blame] | 948 | @NonNull |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 949 | public static InputMethodManager forContext(Context context) { |
| 950 | final int displayId = context.getDisplayId(); |
| 951 | // For better backward compatibility, we always use Looper.getMainLooper() for the default |
| 952 | // display case. |
| 953 | final Looper looper = displayId == Display.DEFAULT_DISPLAY |
| 954 | ? Looper.getMainLooper() : context.getMainLooper(); |
| 955 | return forContextInternal(displayId, looper); |
| 956 | } |
| 957 | |
Yohei Yukawa | f682b1a5c4 | 2018-10-24 16:05:02 -0700 | [diff] [blame] | 958 | @NonNull |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 959 | private static InputMethodManager forContextInternal(int displayId, Looper looper) { |
| 960 | final boolean isDefaultDisplay = displayId == Display.DEFAULT_DISPLAY; |
Yohei Yukawa | 3b3a2ad | 2018-09-20 15:50:35 -0700 | [diff] [blame] | 961 | synchronized (sLock) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 962 | InputMethodManager instance = sInstanceMap.get(displayId); |
| 963 | if (instance != null) { |
| 964 | return instance; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | } |
Yohei Yukawa | f682b1a5c4 | 2018-10-24 16:05:02 -0700 | [diff] [blame] | 966 | instance = createInstance(displayId, looper); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 967 | // For backward compatibility, store the instance also to sInstance for default display. |
| 968 | if (sInstance == null && isDefaultDisplay) { |
| 969 | sInstance = instance; |
| 970 | } |
| 971 | sInstanceMap.put(displayId, instance); |
| 972 | return instance; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 973 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 974 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 975 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 976 | /** |
Yohei Yukawa | 6c07572 | 2018-09-21 14:52:12 -0700 | [diff] [blame] | 977 | * Deprecated. Do not use. |
| 978 | * |
| 979 | * @return global {@link InputMethodManager} instance |
Yohei Yukawa | 484d4af | 2018-09-17 16:47:08 -0700 | [diff] [blame] | 980 | * @deprecated Use {@link Context#getSystemService(Class)} instead. This method cannot fully |
| 981 | * support multi-display scenario. |
Yohei Yukawa | 6c07572 | 2018-09-21 14:52:12 -0700 | [diff] [blame] | 982 | * @hide |
| 983 | */ |
| 984 | @Deprecated |
| 985 | @UnsupportedAppUsage |
| 986 | public static InputMethodManager getInstance() { |
| 987 | Log.w(TAG, "InputMethodManager.getInstance() is deprecated because it cannot be" |
| 988 | + " compatible with multi-display." |
| 989 | + " Use context.getSystemService(InputMethodManager.class) instead.", |
| 990 | new Throwable()); |
| 991 | ensureDefaultInstanceForDefaultDisplayIfNecessary(); |
| 992 | return peekInstance(); |
| 993 | } |
| 994 | |
| 995 | /** |
| 996 | * Deprecated. Do not use. |
| 997 | * |
| 998 | * @return {@link #sInstance} |
| 999 | * @deprecated Use {@link Context#getSystemService(Class)} instead. This method cannot fully |
| 1000 | * support multi-display scenario. |
| 1001 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | */ |
Yohei Yukawa | 484d4af | 2018-09-17 16:47:08 -0700 | [diff] [blame] | 1003 | @Deprecated |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1004 | @UnsupportedAppUsage |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 1005 | public static InputMethodManager peekInstance() { |
Yohei Yukawa | 6c07572 | 2018-09-21 14:52:12 -0700 | [diff] [blame] | 1006 | Log.w(TAG, "InputMethodManager.peekInstance() is deprecated because it cannot be" |
| 1007 | + " compatible with multi-display." |
| 1008 | + " Use context.getSystemService(InputMethodManager.class) instead.", |
| 1009 | new Throwable()); |
Yohei Yukawa | 3b3a2ad | 2018-09-20 15:50:35 -0700 | [diff] [blame] | 1010 | synchronized (sLock) { |
| 1011 | return sInstance; |
| 1012 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1013 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1014 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1015 | /** @hide */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1016 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | public IInputMethodClient getClient() { |
| 1018 | return mClient; |
| 1019 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1020 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1021 | /** @hide */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1022 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | public IInputContext getInputContext() { |
| 1024 | return mIInputContext; |
| 1025 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1026 | |
Yohei Yukawa | 629271a | 2019-02-05 07:50:36 -0800 | [diff] [blame] | 1027 | /** |
| 1028 | * Returns the list of installed input methods. |
| 1029 | * |
| 1030 | * <p>On multi user environment, this API returns a result for the calling process user.</p> |
| 1031 | * |
| 1032 | * @return {@link List} of {@link InputMethodInfo}. |
| 1033 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | public List<InputMethodInfo> getInputMethodList() { |
| 1035 | try { |
Yohei Yukawa | d20eef8 | 2019-02-05 10:45:32 -0800 | [diff] [blame] | 1036 | // We intentionally do not use UserHandle.getCallingUserId() here because for system |
| 1037 | // services InputMethodManagerInternal.getInputMethodListAsUser() should be used |
| 1038 | // instead. |
| 1039 | return mService.getInputMethodList(UserHandle.myUserId()); |
| 1040 | } catch (RemoteException e) { |
| 1041 | throw e.rethrowFromSystemServer(); |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | /** |
| 1046 | * Returns the list of installed input methods for the specified user. |
| 1047 | * |
| 1048 | * @param userId user ID to query |
| 1049 | * @return {@link List} of {@link InputMethodInfo}. |
| 1050 | * @hide |
| 1051 | */ |
| 1052 | @RequiresPermission(INTERACT_ACROSS_USERS_FULL) |
| 1053 | public List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId) { |
| 1054 | try { |
| 1055 | return mService.getInputMethodList(userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1057 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
Yohei Yukawa | 629271a | 2019-02-05 07:50:36 -0800 | [diff] [blame] | 1061 | /** |
| 1062 | * Returns the list of enabled input methods. |
| 1063 | * |
| 1064 | * <p>On multi user environment, this API returns a result for the calling process user.</p> |
| 1065 | * |
| 1066 | * @return {@link List} of {@link InputMethodInfo}. |
| 1067 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1068 | public List<InputMethodInfo> getEnabledInputMethodList() { |
| 1069 | try { |
Yohei Yukawa | 1fb13c5 | 2019-02-05 07:55:28 -0800 | [diff] [blame] | 1070 | // We intentionally do not use UserHandle.getCallingUserId() here because for system |
| 1071 | // services InputMethodManagerInternal.getEnabledInputMethodListAsUser() should be used |
| 1072 | // instead. |
| 1073 | return mService.getEnabledInputMethodList(UserHandle.myUserId()); |
| 1074 | } catch (RemoteException e) { |
| 1075 | throw e.rethrowFromSystemServer(); |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | /** |
| 1080 | * Returns the list of enabled input methods for the specified user. |
| 1081 | * |
| 1082 | * @param userId user ID to query |
| 1083 | * @return {@link List} of {@link InputMethodInfo}. |
| 1084 | * @hide |
| 1085 | */ |
| 1086 | @RequiresPermission(INTERACT_ACROSS_USERS_FULL) |
| 1087 | public List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId) { |
| 1088 | try { |
| 1089 | return mService.getEnabledInputMethodList(userId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1091 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | } |
| 1093 | } |
| 1094 | |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 1095 | /** |
| 1096 | * Returns a list of enabled input method subtypes for the specified input method info. |
Yohei Yukawa | 629271a | 2019-02-05 07:50:36 -0800 | [diff] [blame] | 1097 | * |
| 1098 | * <p>On multi user environment, this API returns a result for the calling process user.</p> |
| 1099 | * |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 1100 | * @param imi An input method info whose subtypes list will be returned. |
| 1101 | * @param allowsImplicitlySelectedSubtypes A boolean flag to allow to return the implicitly |
| 1102 | * selected subtypes. If an input method info doesn't have enabled subtypes, the framework |
| 1103 | * will implicitly enable subtypes according to the current system language. |
| 1104 | */ |
satok | 16331c8 | 2010-12-20 23:48:46 +0900 | [diff] [blame] | 1105 | public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(InputMethodInfo imi, |
| 1106 | boolean allowsImplicitlySelectedSubtypes) { |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1107 | try { |
Satoshi Kataoka | b3c21ac | 2013-08-07 15:43:29 +0900 | [diff] [blame] | 1108 | return mService.getEnabledInputMethodSubtypeList( |
| 1109 | imi == null ? null : imi.getId(), allowsImplicitlySelectedSubtypes); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1110 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1111 | throw e.rethrowFromSystemServer(); |
satok | 67ddf9c | 2010-11-17 09:45:54 +0900 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 1115 | /** |
| 1116 | * @deprecated Use {@link InputMethodService#showStatusIcon(int)} instead. This method was |
| 1117 | * intended for IME developers who should be accessing APIs through the service. APIs in this |
| 1118 | * class are intended for app developers interacting with the IME. |
| 1119 | */ |
| 1120 | @Deprecated |
Yohei Yukawa | 41b094f | 2018-09-09 23:58:45 -0700 | [diff] [blame] | 1121 | public void showStatusIcon(IBinder imeToken, String packageName, @DrawableRes int iconId) { |
Yohei Yukawa | d746a7e | 2018-09-18 18:55:02 -0700 | [diff] [blame] | 1122 | InputMethodPrivilegedOperationsRegistry.get(imeToken).updateStatusIcon(packageName, iconId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | } |
| 1124 | |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 1125 | /** |
| 1126 | * @deprecated Use {@link InputMethodService#hideStatusIcon()} instead. This method was |
| 1127 | * intended for IME developers who should be accessing APIs through the service. APIs in |
| 1128 | * this class are intended for app developers interacting with the IME. |
| 1129 | */ |
| 1130 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1131 | public void hideStatusIcon(IBinder imeToken) { |
Yohei Yukawa | d746a7e | 2018-09-18 18:55:02 -0700 | [diff] [blame] | 1132 | InputMethodPrivilegedOperationsRegistry.get(imeToken).updateStatusIcon(null, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | } |
| 1134 | |
Yohei Yukawa | 17ace29 | 2019-01-21 09:24:26 -0800 | [diff] [blame] | 1135 | /** |
| 1136 | * This hidden API is deprecated in {@link android.os.Build.VERSION_CODES#Q}. Does nothing. |
| 1137 | * |
| 1138 | * @param spans will be ignored. |
| 1139 | * |
| 1140 | * @deprecated Do not use. |
| 1141 | * @hide |
| 1142 | */ |
| 1143 | @Deprecated |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1144 | @UnsupportedAppUsage |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1145 | public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) { |
Yohei Yukawa | 17ace29 | 2019-01-21 09:24:26 -0800 | [diff] [blame] | 1146 | Log.w(TAG, "registerSuggestionSpansForNotification() is deprecated. Does nothing."); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1147 | } |
| 1148 | |
Yohei Yukawa | 17ace29 | 2019-01-21 09:24:26 -0800 | [diff] [blame] | 1149 | /** |
| 1150 | * This hidden API is deprecated in {@link android.os.Build.VERSION_CODES#Q}. Does nothing. |
| 1151 | * |
| 1152 | * @deprecated Do not use. |
| 1153 | * @hide |
| 1154 | */ |
| 1155 | @Deprecated |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1156 | @UnsupportedAppUsage |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1157 | public void notifySuggestionPicked(SuggestionSpan span, String originalString, int index) { |
Yohei Yukawa | 17ace29 | 2019-01-21 09:24:26 -0800 | [diff] [blame] | 1158 | Log.w(TAG, "notifySuggestionPicked() is deprecated. Does nothing."); |
satok | f9f0100 | 2011-05-19 21:31:50 +0900 | [diff] [blame] | 1159 | } |
| 1160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | /** |
| 1162 | * Allows you to discover whether the attached input method is running |
| 1163 | * in fullscreen mode. Return true if it is fullscreen, entirely covering |
| 1164 | * your UI, else returns false. |
| 1165 | */ |
| 1166 | public boolean isFullscreenMode() { |
Yohei Yukawa | 1544def | 2016-04-26 17:13:38 -0700 | [diff] [blame] | 1167 | synchronized (mH) { |
| 1168 | return mFullscreenMode; |
| 1169 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1170 | } |
Yohei Yukawa | 1544def | 2016-04-26 17:13:38 -0700 | [diff] [blame] | 1171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | /** |
| 1173 | * Return true if the given view is the currently active view for the |
| 1174 | * input method. |
| 1175 | */ |
| 1176 | public boolean isActive(View view) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1177 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 1178 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(view); |
| 1179 | if (fallbackImm != null) { |
| 1180 | return fallbackImm.isActive(view); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1181 | } |
| 1182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1183 | checkFocus(); |
| 1184 | synchronized (mH) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1185 | return (mServedView == view |
| 1186 | || (mServedView != null |
| 1187 | && mServedView.checkInputConnectionProxy(view))) |
| 1188 | && mCurrentTextBoxAttribute != null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1189 | } |
| 1190 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1191 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1192 | /** |
| 1193 | * Return true if any view is currently active in the input method. |
| 1194 | */ |
| 1195 | public boolean isActive() { |
| 1196 | checkFocus(); |
| 1197 | synchronized (mH) { |
| 1198 | return mServedView != null && mCurrentTextBoxAttribute != null; |
| 1199 | } |
| 1200 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1201 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1202 | /** |
| 1203 | * Return true if the currently served view is accepting full text edits. |
| 1204 | * If false, it has no input connection, so can only handle raw key events. |
| 1205 | */ |
| 1206 | public boolean isAcceptingText() { |
| 1207 | checkFocus(); |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame] | 1208 | return mServedInputConnectionWrapper != null && |
| 1209 | mServedInputConnectionWrapper.getInputConnection() != null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | /** |
| 1213 | * Reset all of the state associated with being bound to an input method. |
| 1214 | */ |
| 1215 | void clearBindingLocked() { |
Dianne Hackborn | 6b6b3fd | 2014-03-24 11:27:18 -0700 | [diff] [blame] | 1216 | if (DEBUG) Log.v(TAG, "Clearing binding!"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1217 | clearConnectionLocked(); |
Jeff Brown | 4d65688 | 2013-04-03 14:39:19 -0700 | [diff] [blame] | 1218 | setInputChannelLocked(null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | mBindSequence = -1; |
| 1220 | mCurId = null; |
| 1221 | mCurMethod = null; |
Jeff Brown | 4d65688 | 2013-04-03 14:39:19 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | void setInputChannelLocked(InputChannel channel) { |
| 1225 | if (mCurChannel != channel) { |
| 1226 | if (mCurSender != null) { |
| 1227 | flushPendingEventsLocked(); |
| 1228 | mCurSender.dispose(); |
| 1229 | mCurSender = null; |
| 1230 | } |
| 1231 | if (mCurChannel != null) { |
| 1232 | mCurChannel.dispose(); |
| 1233 | } |
| 1234 | mCurChannel = channel; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 1235 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1236 | } |
Jeff Brown | 4d65688 | 2013-04-03 14:39:19 -0700 | [diff] [blame] | 1237 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | /** |
| 1239 | * Reset all of the state associated with a served view being connected |
| 1240 | * to an input method |
| 1241 | */ |
| 1242 | void clearConnectionLocked() { |
| 1243 | mCurrentTextBoxAttribute = null; |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 1244 | if (mServedInputConnectionWrapper != null) { |
| 1245 | mServedInputConnectionWrapper.deactivate(); |
| 1246 | mServedInputConnectionWrapper = null; |
| 1247 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | } |
Yohei Yukawa | 0f3a99d | 2015-05-21 00:15:05 -0700 | [diff] [blame] | 1249 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1250 | /** |
| 1251 | * Disconnect any existing input connection, clearing the served view. |
| 1252 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1253 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1254 | void finishInputLocked() { |
| 1255 | mNextServedView = null; |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 1256 | mActivityViewToScreenMatrix = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | if (mServedView != null) { |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 1258 | if (DEBUG) Log.v(TAG, "FINISH INPUT: mServedView=" + dumpViewInfo(mServedView)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1259 | mServedView = null; |
| 1260 | mCompletions = null; |
| 1261 | mServedConnecting = false; |
| 1262 | clearConnectionLocked(); |
| 1263 | } |
| 1264 | } |
Gilles Debunne | c478c17 | 2011-12-19 17:29:24 -0800 | [diff] [blame] | 1265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | public void displayCompletions(View view, CompletionInfo[] completions) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1267 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 1268 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(view); |
| 1269 | if (fallbackImm != null) { |
| 1270 | fallbackImm.displayCompletions(view, completions); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1271 | return; |
| 1272 | } |
| 1273 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1274 | checkFocus(); |
| 1275 | synchronized (mH) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1276 | if (mServedView != view && (mServedView == null |
| 1277 | || !mServedView.checkInputConnectionProxy(view))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | return; |
| 1279 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1281 | mCompletions = completions; |
| 1282 | if (mCurMethod != null) { |
| 1283 | try { |
| 1284 | mCurMethod.displayCompletions(mCompletions); |
| 1285 | } catch (RemoteException e) { |
| 1286 | } |
| 1287 | } |
| 1288 | } |
| 1289 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1291 | public void updateExtractedText(View view, int token, ExtractedText text) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1292 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 1293 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(view); |
| 1294 | if (fallbackImm != null) { |
| 1295 | fallbackImm.updateExtractedText(view, token, text); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1296 | return; |
| 1297 | } |
| 1298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | checkFocus(); |
| 1300 | synchronized (mH) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1301 | if (mServedView != view && (mServedView == null |
| 1302 | || !mServedView.checkInputConnectionProxy(view))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1303 | return; |
| 1304 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1305 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | if (mCurMethod != null) { |
| 1307 | try { |
| 1308 | mCurMethod.updateExtractedText(token, text); |
| 1309 | } catch (RemoteException e) { |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1314 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | /** |
| 1316 | * Flag for {@link #showSoftInput} to indicate that this is an implicit |
| 1317 | * request to show the input window, not as the result of a direct request |
| 1318 | * by the user. The window may not be shown in this case. |
| 1319 | */ |
| 1320 | public static final int SHOW_IMPLICIT = 0x0001; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | /** |
| 1323 | * Flag for {@link #showSoftInput} to indicate that the user has forced |
| 1324 | * the input method open (such as by long-pressing menu) so it should |
| 1325 | * not be closed until they explicitly do so. |
| 1326 | */ |
| 1327 | public static final int SHOW_FORCED = 0x0002; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1329 | /** |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1330 | * Synonym for {@link #showSoftInput(View, int, ResultReceiver)} without |
| 1331 | * a result receiver: explicitly request that the current input method's |
| 1332 | * soft input area be shown to the user, if needed. |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1333 | * |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1334 | * @param view The currently focused view, which would like to receive |
| 1335 | * soft keyboard input. |
| 1336 | * @param flags Provides additional operating flags. Currently may be |
| 1337 | * 0 or have the {@link #SHOW_IMPLICIT} bit set. |
| 1338 | */ |
| 1339 | public boolean showSoftInput(View view, int flags) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1340 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 1341 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(view); |
| 1342 | if (fallbackImm != null) { |
| 1343 | return fallbackImm.showSoftInput(view, flags); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1344 | } |
| 1345 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1346 | return showSoftInput(view, flags, null); |
| 1347 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1348 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1349 | /** |
| 1350 | * Flag for the {@link ResultReceiver} result code from |
| 1351 | * {@link #showSoftInput(View, int, ResultReceiver)} and |
| 1352 | * {@link #hideSoftInputFromWindow(IBinder, int, ResultReceiver)}: the |
| 1353 | * state of the soft input window was unchanged and remains shown. |
| 1354 | */ |
| 1355 | public static final int RESULT_UNCHANGED_SHOWN = 0; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1356 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1357 | /** |
| 1358 | * Flag for the {@link ResultReceiver} result code from |
| 1359 | * {@link #showSoftInput(View, int, ResultReceiver)} and |
| 1360 | * {@link #hideSoftInputFromWindow(IBinder, int, ResultReceiver)}: the |
| 1361 | * state of the soft input window was unchanged and remains hidden. |
| 1362 | */ |
| 1363 | public static final int RESULT_UNCHANGED_HIDDEN = 1; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1364 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1365 | /** |
| 1366 | * Flag for the {@link ResultReceiver} result code from |
| 1367 | * {@link #showSoftInput(View, int, ResultReceiver)} and |
| 1368 | * {@link #hideSoftInputFromWindow(IBinder, int, ResultReceiver)}: the |
| 1369 | * state of the soft input window changed from hidden to shown. |
| 1370 | */ |
| 1371 | public static final int RESULT_SHOWN = 2; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1372 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1373 | /** |
| 1374 | * Flag for the {@link ResultReceiver} result code from |
| 1375 | * {@link #showSoftInput(View, int, ResultReceiver)} and |
| 1376 | * {@link #hideSoftInputFromWindow(IBinder, int, ResultReceiver)}: the |
| 1377 | * state of the soft input window changed from shown to hidden. |
| 1378 | */ |
| 1379 | public static final int RESULT_HIDDEN = 3; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1380 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1381 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1382 | * Explicitly request that the current input method's soft input area be |
| 1383 | * shown to the user, if needed. Call this if the user interacts with |
| 1384 | * your view in such a way that they have expressed they would like to |
| 1385 | * start performing input into it. |
Yohei Yukawa | d552a52 | 2016-03-20 15:08:31 -0700 | [diff] [blame] | 1386 | * |
| 1387 | * <p><strong>Caveat:</strong> {@link ResultReceiver} instance passed to |
| 1388 | * this method can be a long-lived object, because it may not be |
| 1389 | * garbage-collected until all the corresponding {@link ResultReceiver} |
| 1390 | * objects transferred to different processes get garbage-collected. |
| 1391 | * Follow the general patterns to avoid memory leaks in Android. |
| 1392 | * Consider to use {@link java.lang.ref.WeakReference} so that application |
| 1393 | * logic objects such as {@link android.app.Activity} and {@link Context} |
| 1394 | * can be garbage collected regardless of the lifetime of |
| 1395 | * {@link ResultReceiver}. |
| 1396 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1397 | * @param view The currently focused view, which would like to receive |
| 1398 | * soft keyboard input. |
| 1399 | * @param flags Provides additional operating flags. Currently may be |
| 1400 | * 0 or have the {@link #SHOW_IMPLICIT} bit set. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1401 | * @param resultReceiver If non-null, this will be called by the IME when |
| 1402 | * it has processed your request to tell you what it has done. The result |
| 1403 | * code you receive may be either {@link #RESULT_UNCHANGED_SHOWN}, |
| 1404 | * {@link #RESULT_UNCHANGED_HIDDEN}, {@link #RESULT_SHOWN}, or |
| 1405 | * {@link #RESULT_HIDDEN}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1406 | */ |
Gilles Debunne | ad8484b | 2011-02-17 17:37:51 -0800 | [diff] [blame] | 1407 | public boolean showSoftInput(View view, int flags, ResultReceiver resultReceiver) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1408 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 1409 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(view); |
| 1410 | if (fallbackImm != null) { |
| 1411 | return fallbackImm.showSoftInput(view, flags, resultReceiver); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1412 | } |
| 1413 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1414 | checkFocus(); |
| 1415 | synchronized (mH) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1416 | if (mServedView != view && (mServedView == null |
| 1417 | || !mServedView.checkInputConnectionProxy(view))) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1418 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1422 | return mService.showSoftInput(mClient, flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1423 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1424 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | } |
| 1426 | } |
| 1427 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1428 | |
Yohei Yukawa | 101ae46 | 2017-03-31 14:28:18 -0700 | [diff] [blame] | 1429 | /** |
| 1430 | * This method is still kept for a while until android.support.v7.widget.SearchView ver. 26.0 |
| 1431 | * is publicly released because previous implementations of that class had relied on this method |
| 1432 | * via reflection. |
| 1433 | * |
| 1434 | * @deprecated This is a hidden API. You should never use this. |
| 1435 | * @hide |
| 1436 | */ |
| 1437 | @Deprecated |
Yohei Yukawa | 1466e4a | 2019-02-12 01:42:56 -0800 | [diff] [blame] | 1438 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768499) |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1439 | public void showSoftInputUnchecked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1440 | try { |
Yohei Yukawa | 101ae46 | 2017-03-31 14:28:18 -0700 | [diff] [blame] | 1441 | Log.w(TAG, "showSoftInputUnchecked() is a hidden method, which will be removed " |
| 1442 | + "soon. If you are using android.support.v7.widget.SearchView, please update " |
| 1443 | + "to version 26.0 or newer version."); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1444 | mService.showSoftInput(mClient, flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1445 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1446 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1447 | } |
| 1448 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1449 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1450 | /** |
Yohei Yukawa | fbc2f7a | 2018-01-16 08:09:11 -0800 | [diff] [blame] | 1451 | * Flag for {@link #hideSoftInputFromWindow} and {@link InputMethodService#requestHideSelf(int)} |
| 1452 | * to indicate that the soft input window should only be hidden if it was not explicitly shown |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | * by the user. |
| 1454 | */ |
| 1455 | public static final int HIDE_IMPLICIT_ONLY = 0x0001; |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1457 | /** |
Yohei Yukawa | fbc2f7a | 2018-01-16 08:09:11 -0800 | [diff] [blame] | 1458 | * Flag for {@link #hideSoftInputFromWindow} and {@link InputMethodService#requestShowSelf(int)} |
| 1459 | * to indicate that the soft input window should normally be hidden, unless it was originally |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1460 | * shown with {@link #SHOW_FORCED}. |
| 1461 | */ |
| 1462 | public static final int HIDE_NOT_ALWAYS = 0x0002; |
Gilles Debunne | c478c17 | 2011-12-19 17:29:24 -0800 | [diff] [blame] | 1463 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1464 | /** |
Gilles Debunne | 7c8c6d6 | 2011-01-24 14:48:14 -0800 | [diff] [blame] | 1465 | * Synonym for {@link #hideSoftInputFromWindow(IBinder, int, ResultReceiver)} |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1466 | * without a result: request to hide the soft input window from the |
| 1467 | * context of the window that is currently accepting input. |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1468 | * |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1469 | * @param windowToken The token of the window that is making the request, |
| 1470 | * as returned by {@link View#getWindowToken() View.getWindowToken()}. |
| 1471 | * @param flags Provides additional operating flags. Currently may be |
| 1472 | * 0 or have the {@link #HIDE_IMPLICIT_ONLY} bit set. |
| 1473 | */ |
| 1474 | public boolean hideSoftInputFromWindow(IBinder windowToken, int flags) { |
| 1475 | return hideSoftInputFromWindow(windowToken, flags, null); |
| 1476 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1477 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1478 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | * Request to hide the soft input window from the context of the window |
| 1480 | * that is currently accepting input. This should be called as a result |
| 1481 | * of the user doing some actually than fairly explicitly requests to |
| 1482 | * have the input window hidden. |
Yohei Yukawa | d552a52 | 2016-03-20 15:08:31 -0700 | [diff] [blame] | 1483 | * |
| 1484 | * <p><strong>Caveat:</strong> {@link ResultReceiver} instance passed to |
| 1485 | * this method can be a long-lived object, because it may not be |
| 1486 | * garbage-collected until all the corresponding {@link ResultReceiver} |
| 1487 | * objects transferred to different processes get garbage-collected. |
| 1488 | * Follow the general patterns to avoid memory leaks in Android. |
| 1489 | * Consider to use {@link java.lang.ref.WeakReference} so that application |
| 1490 | * logic objects such as {@link android.app.Activity} and {@link Context} |
| 1491 | * can be garbage collected regardless of the lifetime of |
| 1492 | * {@link ResultReceiver}. |
| 1493 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | * @param windowToken The token of the window that is making the request, |
| 1495 | * as returned by {@link View#getWindowToken() View.getWindowToken()}. |
| 1496 | * @param flags Provides additional operating flags. Currently may be |
| 1497 | * 0 or have the {@link #HIDE_IMPLICIT_ONLY} bit set. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1498 | * @param resultReceiver If non-null, this will be called by the IME when |
| 1499 | * it has processed your request to tell you what it has done. The result |
| 1500 | * code you receive may be either {@link #RESULT_UNCHANGED_SHOWN}, |
| 1501 | * {@link #RESULT_UNCHANGED_HIDDEN}, {@link #RESULT_SHOWN}, or |
| 1502 | * {@link #RESULT_HIDDEN}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | */ |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1504 | public boolean hideSoftInputFromWindow(IBinder windowToken, int flags, |
| 1505 | ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | checkFocus(); |
| 1507 | synchronized (mH) { |
| 1508 | if (mServedView == null || mServedView.getWindowToken() != windowToken) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1509 | return false; |
| 1510 | } |
| 1511 | |
| 1512 | try { |
| 1513 | return mService.hideSoftInput(mClient, flags, resultReceiver); |
| 1514 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1515 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1516 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1517 | } |
| 1518 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1519 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1520 | /** |
| 1521 | * This method toggles the input method window display. |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1522 | * If the input window is already displayed, it gets hidden. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1523 | * If not the input window will be displayed. |
| 1524 | * @param windowToken The token of the window that is making the request, |
| 1525 | * as returned by {@link View#getWindowToken() View.getWindowToken()}. |
| 1526 | * @param showFlags Provides additional operating flags. May be |
| 1527 | * 0 or have the {@link #SHOW_IMPLICIT}, |
| 1528 | * {@link #SHOW_FORCED} bit set. |
| 1529 | * @param hideFlags Provides additional operating flags. May be |
| 1530 | * 0 or have the {@link #HIDE_IMPLICIT_ONLY}, |
| 1531 | * {@link #HIDE_NOT_ALWAYS} bit set. |
| 1532 | **/ |
| 1533 | public void toggleSoftInputFromWindow(IBinder windowToken, int showFlags, int hideFlags) { |
| 1534 | synchronized (mH) { |
| 1535 | if (mServedView == null || mServedView.getWindowToken() != windowToken) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1536 | return; |
| 1537 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1538 | if (mCurMethod != null) { |
| 1539 | try { |
| 1540 | mCurMethod.toggleSoftInput(showFlags, hideFlags); |
| 1541 | } catch (RemoteException e) { |
| 1542 | } |
| 1543 | } |
| 1544 | } |
| 1545 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1546 | |
Yohei Yukawa | 3db07bb | 2018-02-05 15:26:25 +0900 | [diff] [blame] | 1547 | /** |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1548 | * This method toggles the input method window display. |
Yohei Yukawa | 3db07bb | 2018-02-05 15:26:25 +0900 | [diff] [blame] | 1549 | * |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1550 | * If the input window is already displayed, it gets hidden. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1551 | * If not the input window will be displayed. |
| 1552 | * @param showFlags Provides additional operating flags. May be |
| 1553 | * 0 or have the {@link #SHOW_IMPLICIT}, |
| 1554 | * {@link #SHOW_FORCED} bit set. |
| 1555 | * @param hideFlags Provides additional operating flags. May be |
| 1556 | * 0 or have the {@link #HIDE_IMPLICIT_ONLY}, |
| 1557 | * {@link #HIDE_NOT_ALWAYS} bit set. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1558 | */ |
| 1559 | public void toggleSoftInput(int showFlags, int hideFlags) { |
| 1560 | if (mCurMethod != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1562 | mCurMethod.toggleSoftInput(showFlags, hideFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1563 | } catch (RemoteException e) { |
| 1564 | } |
| 1565 | } |
| 1566 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1567 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1568 | /** |
| 1569 | * If the input method is currently connected to the given view, |
| 1570 | * restart it with its new contents. You should call this when the text |
| 1571 | * within your view changes outside of the normal input method or key |
| 1572 | * input flow, such as when an application calls TextView.setText(). |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1573 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1574 | * @param view The view whose text has changed. |
| 1575 | */ |
| 1576 | public void restartInput(View view) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1577 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 1578 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(view); |
| 1579 | if (fallbackImm != null) { |
| 1580 | fallbackImm.restartInput(view); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 1581 | return; |
| 1582 | } |
| 1583 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1584 | checkFocus(); |
| 1585 | synchronized (mH) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1586 | if (mServedView != view && (mServedView == null |
| 1587 | || !mServedView.checkInputConnectionProxy(view))) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1588 | return; |
| 1589 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1590 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1591 | mServedConnecting = true; |
| 1592 | } |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1593 | |
Yohei Yukawa | 4219422 | 2018-10-21 20:14:40 -0700 | [diff] [blame] | 1594 | startInputInner(StartInputReason.APP_CALLED_RESTART_INPUT_API, null, 0, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1595 | } |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1596 | |
Yohei Yukawa | c6632df | 2018-10-21 11:47:16 -0700 | [diff] [blame] | 1597 | boolean startInputInner(@StartInputReason int startInputReason, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1598 | @Nullable IBinder windowGainingFocus, @StartInputFlags int startInputFlags, |
| 1599 | @SoftInputModeFlags int softInputMode, int windowFlags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1600 | final View view; |
| 1601 | synchronized (mH) { |
| 1602 | view = mServedView; |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 1603 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1604 | // Make sure we have a window token for the served view. |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1605 | if (DEBUG) { |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 1606 | Log.v(TAG, "Starting input: view=" + dumpViewInfo(view) + |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 1607 | " reason=" + InputMethodDebug.startInputReasonToString(startInputReason)); |
Yohei Yukawa | 35d3f37 | 2015-11-25 11:07:19 -0800 | [diff] [blame] | 1608 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1609 | if (view == null) { |
| 1610 | if (DEBUG) Log.v(TAG, "ABORT input: no served view!"); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1611 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1612 | } |
| 1613 | } |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 1614 | |
Yohei Yukawa | 80498d5 | 2018-06-21 16:24:36 -0700 | [diff] [blame] | 1615 | if (windowGainingFocus == null) { |
| 1616 | windowGainingFocus = view.getWindowToken(); |
| 1617 | if (windowGainingFocus == null) { |
| 1618 | Log.e(TAG, "ABORT input: ServedView must be attached to a Window"); |
| 1619 | return false; |
| 1620 | } |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1621 | startInputFlags |= StartInputFlags.VIEW_HAS_FOCUS; |
Yohei Yukawa | 80498d5 | 2018-06-21 16:24:36 -0700 | [diff] [blame] | 1622 | if (view.onCheckIsTextEditor()) { |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1623 | startInputFlags |= StartInputFlags.IS_TEXT_EDITOR; |
Yohei Yukawa | 80498d5 | 2018-06-21 16:24:36 -0700 | [diff] [blame] | 1624 | } |
| 1625 | softInputMode = view.getViewRootImpl().mWindowAttributes.softInputMode; |
| 1626 | windowFlags = view.getViewRootImpl().mWindowAttributes.flags; |
| 1627 | } |
| 1628 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | // Now we need to get an input connection from the served view. |
| 1630 | // This is complicated in a couple ways: we can't be holding our lock |
| 1631 | // when calling out to the view, and we need to make sure we call into |
| 1632 | // the view on the same thread that is driving its view hierarchy. |
| 1633 | Handler vh = view.getHandler(); |
| 1634 | if (vh == null) { |
| 1635 | // If the view doesn't have a handler, something has changed out |
Satoshi Kataoka | 3573950 | 2012-10-02 19:00:26 +0900 | [diff] [blame] | 1636 | // from under us, so just close the current input. |
| 1637 | // If we don't close the current input, the current input method can remain on the |
| 1638 | // screen without a connection. |
| 1639 | if (DEBUG) Log.v(TAG, "ABORT input: no handler for view! Close current input."); |
| 1640 | closeCurrentInput(); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1641 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1642 | } |
| 1643 | if (vh.getLooper() != Looper.myLooper()) { |
| 1644 | // The view is running on a different thread than our own, so |
| 1645 | // we need to reschedule our work for over there. |
| 1646 | if (DEBUG) Log.v(TAG, "Starting input: reschedule to view thread"); |
Yohei Yukawa | 623e94b | 2018-01-14 16:30:59 -0800 | [diff] [blame] | 1647 | vh.post(() -> startInputInner(startInputReason, null, 0, 0, 0)); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1648 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1649 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1650 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1651 | // Okay we are now ready to call into the served view and have it |
| 1652 | // do its stuff. |
| 1653 | // Life is good: let's hook everything up! |
| 1654 | EditorInfo tba = new EditorInfo(); |
Yohei Yukawa | 02df328 | 2015-06-03 15:58:59 -0700 | [diff] [blame] | 1655 | // Note: Use Context#getOpPackageName() rather than Context#getPackageName() so that the |
| 1656 | // system can verify the consistency between the uid of this process and package name passed |
| 1657 | // from here. See comment of Context#getOpPackageName() for details. |
| 1658 | tba.packageName = view.getContext().getOpPackageName(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1659 | tba.fieldId = view.getId(); |
| 1660 | InputConnection ic = view.onCreateInputConnection(tba); |
| 1661 | if (DEBUG) Log.v(TAG, "Starting input: tba=" + tba + " ic=" + ic); |
Gilles Debunne | c478c17 | 2011-12-19 17:29:24 -0800 | [diff] [blame] | 1662 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | synchronized (mH) { |
| 1664 | // Now that we are locked again, validate that our state hasn't |
| 1665 | // changed. |
| 1666 | if (mServedView != view || !mServedConnecting) { |
| 1667 | // Something else happened, so abort. |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 1668 | if (DEBUG) Log.v(TAG, |
| 1669 | "Starting input: finished by someone else. view=" + dumpViewInfo(view) |
| 1670 | + " mServedView=" + dumpViewInfo(mServedView) |
| 1671 | + " mServedConnecting=" + mServedConnecting); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1672 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1674 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | // If we already have a text box, then this view is already |
| 1676 | // connected so we want to restart it. |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1677 | if (mCurrentTextBoxAttribute == null) { |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1678 | startInputFlags |= StartInputFlags.INITIAL_CONNECTION; |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1679 | } |
Yohei Yukawa | 612cce9 | 2016-02-11 17:47:33 -0800 | [diff] [blame] | 1680 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1681 | // Hook 'em up and let 'er rip. |
| 1682 | mCurrentTextBoxAttribute = tba; |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 1683 | maybeCallServedViewChangedLocked(tba); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | mServedConnecting = false; |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame] | 1685 | if (mServedInputConnectionWrapper != null) { |
| 1686 | mServedInputConnectionWrapper.deactivate(); |
| 1687 | mServedInputConnectionWrapper = null; |
| 1688 | } |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 1689 | ControlledInputConnectionWrapper servedContext; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1690 | final int missingMethodFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1691 | if (ic != null) { |
| 1692 | mCursorSelStart = tba.initialSelStart; |
| 1693 | mCursorSelEnd = tba.initialSelEnd; |
| 1694 | mCursorCandStart = -1; |
| 1695 | mCursorCandEnd = -1; |
| 1696 | mCursorRect.setEmpty(); |
Yohei Yukawa | 056ffe6 | 2014-05-13 14:26:09 +0900 | [diff] [blame] | 1697 | mCursorAnchorInfo = null; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1698 | final Handler icHandler; |
| 1699 | missingMethodFlags = InputConnectionInspector.getMissingMethodFlags(ic); |
| 1700 | if ((missingMethodFlags & InputConnectionInspector.MissingMethodFlags.GET_HANDLER) |
| 1701 | != 0) { |
| 1702 | // InputConnection#getHandler() is not implemented. |
| 1703 | icHandler = null; |
| 1704 | } else { |
| 1705 | icHandler = ic.getHandler(); |
| 1706 | } |
Yohei Yukawa | 612cce9 | 2016-02-11 17:47:33 -0800 | [diff] [blame] | 1707 | servedContext = new ControlledInputConnectionWrapper( |
| 1708 | icHandler != null ? icHandler.getLooper() : vh.getLooper(), ic, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1709 | } else { |
| 1710 | servedContext = null; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 1711 | missingMethodFlags = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1712 | } |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 1713 | mServedInputConnectionWrapper = servedContext; |
Yohei Yukawa | 612cce9 | 2016-02-11 17:47:33 -0800 | [diff] [blame] | 1714 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1715 | try { |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 1716 | if (DEBUG) Log.v(TAG, "START INPUT: view=" + dumpViewInfo(view) + " ic=" |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1717 | + ic + " tba=" + tba + " startInputFlags=" |
| 1718 | + InputMethodDebug.startInputFlagsToString(startInputFlags)); |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 1719 | final InputBindResult res = mService.startInputOrWindowGainedFocus( |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1720 | startInputReason, mClient, windowGainingFocus, startInputFlags, |
| 1721 | softInputMode, windowFlags, tba, servedContext, missingMethodFlags, |
Yohei Yukawa | cf68d52 | 2017-12-12 09:33:26 -0800 | [diff] [blame] | 1722 | view.getContext().getApplicationInfo().targetSdkVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | if (DEBUG) Log.v(TAG, "Starting input: Bind result=" + res); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1724 | if (res == null) { |
| 1725 | Log.wtf(TAG, "startInputOrWindowGainedFocus must not return" |
| 1726 | + " null. startInputReason=" |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 1727 | + InputMethodDebug.startInputReasonToString(startInputReason) |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1728 | + " editorInfo=" + tba |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1729 | + " startInputFlags=" |
| 1730 | + InputMethodDebug.startInputFlagsToString(startInputFlags)); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1731 | return false; |
| 1732 | } |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 1733 | mActivityViewToScreenMatrix = res.getActivityViewToScreenMatrix(); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1734 | if (res.id != null) { |
| 1735 | setInputChannelLocked(res.channel); |
| 1736 | mBindSequence = res.sequence; |
| 1737 | mCurMethod = res.method; |
| 1738 | mCurId = res.id; |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1739 | } else if (res.channel != null && res.channel != mCurChannel) { |
| 1740 | res.channel.dispose(); |
| 1741 | } |
| 1742 | switch (res.result) { |
| 1743 | case InputBindResult.ResultCode.ERROR_NOT_IME_TARGET_WINDOW: |
| 1744 | mRestartOnNextWindowFocus = true; |
| 1745 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1746 | } |
| 1747 | if (mCurMethod != null && mCompletions != null) { |
| 1748 | try { |
| 1749 | mCurMethod.displayCompletions(mCompletions); |
| 1750 | } catch (RemoteException e) { |
| 1751 | } |
| 1752 | } |
| 1753 | } catch (RemoteException e) { |
| 1754 | Log.w(TAG, "IME died: " + mCurId, e); |
| 1755 | } |
| 1756 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1757 | |
| 1758 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | /** |
| 1762 | * When the focused window is dismissed, this method is called to finish the |
| 1763 | * input method started before. |
| 1764 | * @hide |
| 1765 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1766 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1767 | public void windowDismissed(IBinder appWindowToken) { |
| 1768 | checkFocus(); |
| 1769 | synchronized (mH) { |
| 1770 | if (mServedView != null && |
| 1771 | mServedView.getWindowToken() == appWindowToken) { |
| 1772 | finishInputLocked(); |
| 1773 | } |
daqi | dff365e | 2018-09-19 15:51:22 +0800 | [diff] [blame] | 1774 | if (mCurRootView != null && |
| 1775 | mCurRootView.getWindowToken() == appWindowToken) { |
| 1776 | mCurRootView = null; |
| 1777 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | /** |
| 1782 | * Call this when a view receives focus. |
| 1783 | * @hide |
| 1784 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1785 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1786 | public void focusIn(View view) { |
| 1787 | synchronized (mH) { |
| 1788 | focusInLocked(view); |
| 1789 | } |
| 1790 | } |
| 1791 | |
| 1792 | void focusInLocked(View view) { |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 1793 | if (DEBUG) Log.v(TAG, "focusIn: " + dumpViewInfo(view)); |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 1794 | |
Yohei Yukawa | a4ed0cf | 2016-03-29 19:06:36 -0700 | [diff] [blame] | 1795 | if (view != null && view.isTemporarilyDetached()) { |
| 1796 | // This is a request from a view that is temporarily detached from a window. |
| 1797 | if (DEBUG) Log.v(TAG, "Temporarily detached view, ignoring"); |
| 1798 | return; |
| 1799 | } |
| 1800 | |
Wale Ogunwale | 159c3d8 | 2015-05-14 12:20:53 -0700 | [diff] [blame] | 1801 | if (mCurRootView != view.getRootView()) { |
| 1802 | // This is a request from a window that isn't in the window with |
| 1803 | // IME focus, so ignore it. |
| 1804 | if (DEBUG) Log.v(TAG, "Not IME target window, ignoring"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1805 | return; |
| 1806 | } |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 1807 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1808 | mNextServedView = view; |
| 1809 | scheduleCheckFocusLocked(view); |
| 1810 | } |
| 1811 | |
| 1812 | /** |
| 1813 | * Call this when a view loses focus. |
| 1814 | * @hide |
| 1815 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1816 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1817 | public void focusOut(View view) { |
| 1818 | synchronized (mH) { |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 1819 | if (DEBUG) Log.v(TAG, "focusOut: view=" + dumpViewInfo(view) |
| 1820 | + " mServedView=" + dumpViewInfo(mServedView)); |
Yohei Yukawa | 0b52ed0 | 2015-05-29 11:07:02 -0700 | [diff] [blame] | 1821 | if (mServedView != view) { |
| 1822 | // The following code would auto-hide the IME if we end up |
| 1823 | // with no more views with focus. This can happen, however, |
| 1824 | // whenever we go into touch mode, so it ends up hiding |
| 1825 | // at times when we don't really want it to. For now it |
| 1826 | // seems better to just turn it all off. |
Yohei Yukawa | a4ed0cf | 2016-03-29 19:06:36 -0700 | [diff] [blame] | 1827 | // TODO: Check view.isTemporarilyDetached() when re-enable the following code. |
Dake Gu | ddf6c1e | 2018-05-10 11:41:19 -0700 | [diff] [blame] | 1828 | if (false && canStartInput(view)) { |
Yohei Yukawa | 0b52ed0 | 2015-05-29 11:07:02 -0700 | [diff] [blame] | 1829 | mNextServedView = null; |
| 1830 | scheduleCheckFocusLocked(view); |
| 1831 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | } |
| 1835 | |
Yohei Yukawa | b13f015 | 2015-05-29 17:09:14 -0700 | [diff] [blame] | 1836 | /** |
| 1837 | * Call this when a view is being detached from a {@link android.view.Window}. |
| 1838 | * @hide |
| 1839 | */ |
| 1840 | public void onViewDetachedFromWindow(View view) { |
| 1841 | synchronized (mH) { |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 1842 | if (DEBUG) Log.v(TAG, "onViewDetachedFromWindow: view=" + dumpViewInfo(view) |
| 1843 | + " mServedView=" + dumpViewInfo(mServedView)); |
Yohei Yukawa | a4f52ad | 2016-03-28 17:21:55 -0700 | [diff] [blame] | 1844 | if (mServedView == view) { |
Yohei Yukawa | b13f015 | 2015-05-29 17:09:14 -0700 | [diff] [blame] | 1845 | mNextServedView = null; |
| 1846 | scheduleCheckFocusLocked(view); |
| 1847 | } |
| 1848 | } |
| 1849 | } |
| 1850 | |
Gilles Debunne | c478c17 | 2011-12-19 17:29:24 -0800 | [diff] [blame] | 1851 | static void scheduleCheckFocusLocked(View view) { |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 1852 | ViewRootImpl viewRootImpl = view.getViewRootImpl(); |
| 1853 | if (viewRootImpl != null) { |
| 1854 | viewRootImpl.dispatchCheckFocus(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1855 | } |
| 1856 | } |
Jeff Brown | a175a5b | 2012-02-15 19:18:31 -0800 | [diff] [blame] | 1857 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1858 | /** |
| 1859 | * @hide |
| 1860 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1861 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1862 | public void checkFocus() { |
Yohei Yukawa | 241eac2 | 2016-03-28 00:28:50 -0700 | [diff] [blame] | 1863 | if (checkFocusNoStartInput(false)) { |
Yohei Yukawa | 4219422 | 2018-10-21 20:14:40 -0700 | [diff] [blame] | 1864 | startInputInner(StartInputReason.CHECK_FOCUS, null, 0, 0, 0); |
Satoshi Kataoka | 4e5184f | 2012-07-13 23:10:58 +0900 | [diff] [blame] | 1865 | } |
Dianne Hackborn | a82ba54 | 2012-02-15 18:19:55 -0800 | [diff] [blame] | 1866 | } |
| 1867 | |
Yohei Yukawa | 241eac2 | 2016-03-28 00:28:50 -0700 | [diff] [blame] | 1868 | private boolean checkFocusNoStartInput(boolean forceNewFocus) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1869 | // This is called a lot, so short-circuit before locking. |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1870 | if (mServedView == mNextServedView && !forceNewFocus) { |
Dianne Hackborn | a82ba54 | 2012-02-15 18:19:55 -0800 | [diff] [blame] | 1871 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1872 | } |
satok | 863fcd6 | 2011-06-21 17:38:02 +0900 | [diff] [blame] | 1873 | |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame] | 1874 | final ControlledInputConnectionWrapper ic; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | synchronized (mH) { |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1876 | if (mServedView == mNextServedView && !forceNewFocus) { |
Dianne Hackborn | a82ba54 | 2012-02-15 18:19:55 -0800 | [diff] [blame] | 1877 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1878 | } |
| 1879 | if (DEBUG) Log.v(TAG, "checkFocus: view=" + mServedView |
| 1880 | + " next=" + mNextServedView |
satok | 05a6cbe | 2012-04-05 23:04:08 +0900 | [diff] [blame] | 1881 | + " forceNewFocus=" + forceNewFocus |
| 1882 | + " package=" |
| 1883 | + (mServedView != null ? mServedView.getContext().getPackageName() : "<none>")); |
Dianne Hackborn | a82ba54 | 2012-02-15 18:19:55 -0800 | [diff] [blame] | 1884 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | if (mNextServedView == null) { |
| 1886 | finishInputLocked(); |
| 1887 | // In this case, we used to have a focused view on the window, |
| 1888 | // but no longer do. We should make sure the input method is |
| 1889 | // no longer shown, since it serves no purpose. |
| 1890 | closeCurrentInput(); |
Dianne Hackborn | a82ba54 | 2012-02-15 18:19:55 -0800 | [diff] [blame] | 1891 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1892 | } |
Dianne Hackborn | a82ba54 | 2012-02-15 18:19:55 -0800 | [diff] [blame] | 1893 | |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame] | 1894 | ic = mServedInputConnectionWrapper; |
Dianne Hackborn | a82ba54 | 2012-02-15 18:19:55 -0800 | [diff] [blame] | 1895 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1896 | mServedView = mNextServedView; |
| 1897 | mCurrentTextBoxAttribute = null; |
| 1898 | mCompletions = null; |
| 1899 | mServedConnecting = true; |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 1900 | // servedView has changed and it's not editable. |
| 1901 | if (!mServedView.onCheckIsTextEditor()) { |
| 1902 | maybeCallServedViewChangedLocked(null); |
| 1903 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1904 | } |
Dianne Hackborn | a82ba54 | 2012-02-15 18:19:55 -0800 | [diff] [blame] | 1905 | |
Yohei Yukawa | 241eac2 | 2016-03-28 00:28:50 -0700 | [diff] [blame] | 1906 | if (ic != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1907 | ic.finishComposingText(); |
| 1908 | } |
Dianne Hackborn | a82ba54 | 2012-02-15 18:19:55 -0800 | [diff] [blame] | 1909 | |
| 1910 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1911 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1912 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1913 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1914 | void closeCurrentInput() { |
| 1915 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1916 | mService.hideSoftInput(mClient, HIDE_NOT_ALWAYS, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1917 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1918 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1919 | } |
| 1920 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1922 | /** |
Joe Onorato | c6cc0f8 | 2011-04-12 11:53:13 -0700 | [diff] [blame] | 1923 | * Called by ViewAncestor when its window gets input focus. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | * @hide |
| 1925 | */ |
Yohei Yukawa | 22dac1c | 2017-02-12 16:54:16 -0800 | [diff] [blame] | 1926 | public void onPostWindowFocus(View rootView, View focusedView, |
| 1927 | @SoftInputModeFlags int softInputMode, boolean first, int windowFlags) { |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1928 | boolean forceNewFocus = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1929 | synchronized (mH) { |
| 1930 | if (DEBUG) Log.v(TAG, "onWindowFocus: " + focusedView |
Yohei Yukawa | a468d70 | 2018-10-21 11:42:34 -0700 | [diff] [blame] | 1931 | + " softInputMode=" + InputMethodDebug.softInputModeToString(softInputMode) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | + " first=" + first + " flags=#" |
| 1933 | + Integer.toHexString(windowFlags)); |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 1934 | if (mRestartOnNextWindowFocus) { |
| 1935 | if (DEBUG) Log.v(TAG, "Restarting due to mRestartOnNextWindowFocus"); |
| 1936 | mRestartOnNextWindowFocus = false; |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1937 | forceNewFocus = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | } |
| 1939 | focusInLocked(focusedView != null ? focusedView : rootView); |
| 1940 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1941 | |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1942 | int startInputFlags = 0; |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1943 | if (focusedView != null) { |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1944 | startInputFlags |= StartInputFlags.VIEW_HAS_FOCUS; |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1945 | if (focusedView.onCheckIsTextEditor()) { |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1946 | startInputFlags |= StartInputFlags.IS_TEXT_EDITOR; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1947 | } |
| 1948 | } |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1949 | if (first) { |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1950 | startInputFlags |= StartInputFlags.FIRST_WINDOW_FOCUS_GAIN; |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1951 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 1952 | |
Yohei Yukawa | 241eac2 | 2016-03-28 00:28:50 -0700 | [diff] [blame] | 1953 | if (checkFocusNoStartInput(forceNewFocus)) { |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1954 | // We need to restart input on the current focus view. This |
| 1955 | // should be done in conjunction with telling the system service |
| 1956 | // about the window gaining focus, to help make the transition |
| 1957 | // smooth. |
Yohei Yukawa | 4219422 | 2018-10-21 20:14:40 -0700 | [diff] [blame] | 1958 | if (startInputInner(StartInputReason.WINDOW_FOCUS_GAIN, rootView.getWindowToken(), |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1959 | startInputFlags, softInputMode, windowFlags)) { |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1960 | return; |
| 1961 | } |
| 1962 | } |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 1963 | |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1964 | // For some reason we didn't do a startInput + windowFocusGain, so |
| 1965 | // we'll just do a window focus gain and call it a day. |
| 1966 | synchronized (mH) { |
| 1967 | try { |
Dianne Hackborn | ac92087 | 2012-05-22 11:49:49 -0700 | [diff] [blame] | 1968 | if (DEBUG) Log.v(TAG, "Reporting focus gain, without startInput"); |
Yohei Yukawa | 05c25f8 | 2016-02-22 12:41:17 -0800 | [diff] [blame] | 1969 | mService.startInputOrWindowGainedFocus( |
Yohei Yukawa | 4219422 | 2018-10-21 20:14:40 -0700 | [diff] [blame] | 1970 | StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY, mClient, |
Yohei Yukawa | 35fa6d5 | 2018-10-31 11:33:32 -0700 | [diff] [blame] | 1971 | rootView.getWindowToken(), startInputFlags, softInputMode, windowFlags, |
| 1972 | null, null, 0 /* missingMethodFlags */, |
Yohei Yukawa | cf68d52 | 2017-12-12 09:33:26 -0800 | [diff] [blame] | 1973 | rootView.getContext().getApplicationInfo().targetSdkVersion); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1974 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1975 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 1976 | } |
Dianne Hackborn | 06a591c | 2012-02-16 10:25:26 -0800 | [diff] [blame] | 1977 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1978 | } |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 1979 | |
Wale Ogunwale | 159c3d8 | 2015-05-14 12:20:53 -0700 | [diff] [blame] | 1980 | /** @hide */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 1981 | @UnsupportedAppUsage |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 1982 | public void onPreWindowFocus(View rootView, boolean hasWindowFocus) { |
Wale Ogunwale | 159c3d8 | 2015-05-14 12:20:53 -0700 | [diff] [blame] | 1983 | synchronized (mH) { |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 1984 | if (rootView == null) { |
| 1985 | mCurRootView = null; |
| 1986 | } if (hasWindowFocus) { |
| 1987 | mCurRootView = rootView; |
| 1988 | } else if (rootView == mCurRootView) { |
| 1989 | // If the mCurRootView is losing window focus, release the strong reference to it |
| 1990 | // so as not to prevent it from being garbage-collected. |
| 1991 | mCurRootView = null; |
| 1992 | } else { |
| 1993 | if (DEBUG) { |
| 1994 | Log.v(TAG, "Ignoring onPreWindowFocus()." |
| 1995 | + " mCurRootView=" + mCurRootView + " rootView=" + rootView); |
| 1996 | } |
| 1997 | } |
Wale Ogunwale | 159c3d8 | 2015-05-14 12:20:53 -0700 | [diff] [blame] | 1998 | } |
| 1999 | } |
Yohei Yukawa | 5f05965 | 2015-05-14 22:16:41 -0700 | [diff] [blame] | 2000 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2001 | /** |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 2002 | * Register for IME state callbacks and applying visibility in |
| 2003 | * {@link android.view.ImeInsetsSourceConsumer}. |
| 2004 | * @hide |
| 2005 | */ |
| 2006 | public void registerImeConsumer(@NonNull ImeInsetsSourceConsumer imeInsetsConsumer) { |
| 2007 | if (imeInsetsConsumer == null) { |
| 2008 | throw new IllegalStateException("ImeInsetsSourceConsumer cannot be null."); |
| 2009 | } |
| 2010 | |
| 2011 | synchronized (mH) { |
| 2012 | mImeInsetsConsumer = imeInsetsConsumer; |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | /** |
Louis Chang | 3d4a7d1 | 2019-04-12 16:18:30 +0800 | [diff] [blame] | 2017 | * Unregister for IME state callbacks and applying visibility in |
| 2018 | * {@link android.view.ImeInsetsSourceConsumer}. |
| 2019 | * @hide |
| 2020 | */ |
| 2021 | public void unregisterImeConsumer(@NonNull ImeInsetsSourceConsumer imeInsetsConsumer) { |
| 2022 | if (imeInsetsConsumer == null) { |
| 2023 | throw new IllegalStateException("ImeInsetsSourceConsumer cannot be null."); |
| 2024 | } |
| 2025 | |
| 2026 | synchronized (mH) { |
| 2027 | if (mImeInsetsConsumer == imeInsetsConsumer) { |
| 2028 | mImeInsetsConsumer = null; |
| 2029 | } |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | /** |
Tarandeep Singh | 46d59f0 | 2019-01-29 18:09:15 -0800 | [diff] [blame] | 2034 | * Call showSoftInput with currently focused view. |
| 2035 | * @return {@code true} if IME can be shown. |
| 2036 | * @hide |
| 2037 | */ |
| 2038 | public boolean requestImeShow(ResultReceiver resultReceiver) { |
| 2039 | synchronized (mH) { |
| 2040 | if (mServedView == null) { |
| 2041 | return false; |
| 2042 | } |
| 2043 | showSoftInput(mServedView, 0 /* flags */, resultReceiver); |
| 2044 | return true; |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | /** |
| 2049 | * Notify IME directly that it is no longer visible. |
| 2050 | * @hide |
| 2051 | */ |
| 2052 | public void notifyImeHidden() { |
| 2053 | synchronized (mH) { |
| 2054 | try { |
| 2055 | if (mCurMethod != null) { |
| 2056 | mCurMethod.notifyImeHidden(); |
| 2057 | } |
| 2058 | } catch (RemoteException re) { |
| 2059 | } |
| 2060 | } |
| 2061 | } |
| 2062 | |
| 2063 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2064 | * Report the current selection range. |
Jean Chalard | 6fd68e0 | 2014-02-20 17:48:46 +0900 | [diff] [blame] | 2065 | * |
| 2066 | * <p><strong>Editor authors</strong>, you need to call this method whenever |
| 2067 | * the cursor moves in your editor. Remember that in addition to doing this, your |
| 2068 | * editor needs to always supply current cursor values in |
| 2069 | * {@link EditorInfo#initialSelStart} and {@link EditorInfo#initialSelEnd} every |
| 2070 | * time {@link android.view.View#onCreateInputConnection(EditorInfo)} is |
| 2071 | * called, which happens whenever the keyboard shows up or the focus changes |
| 2072 | * to a text field, among other cases.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2073 | */ |
| 2074 | public void updateSelection(View view, int selStart, int selEnd, |
| 2075 | int candidatesStart, int candidatesEnd) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2076 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 2077 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(view); |
| 2078 | if (fallbackImm != null) { |
| 2079 | fallbackImm.updateSelection(view, selStart, selEnd, candidatesStart, candidatesEnd); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2080 | return; |
| 2081 | } |
| 2082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | checkFocus(); |
| 2084 | synchronized (mH) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2085 | if ((mServedView != view && (mServedView == null |
| 2086 | || !mServedView.checkInputConnectionProxy(view))) |
| 2087 | || mCurrentTextBoxAttribute == null || mCurMethod == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2088 | return; |
| 2089 | } |
Yohei Yukawa | c2ddd60 | 2014-05-06 21:22:49 +0900 | [diff] [blame] | 2090 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | if (mCursorSelStart != selStart || mCursorSelEnd != selEnd |
| 2092 | || mCursorCandStart != candidatesStart |
| 2093 | || mCursorCandEnd != candidatesEnd) { |
| 2094 | if (DEBUG) Log.d(TAG, "updateSelection"); |
| 2095 | |
| 2096 | try { |
| 2097 | if (DEBUG) Log.v(TAG, "SELECTION CHANGE: " + mCurMethod); |
Jean Chalard | c743cb9 | 2013-09-12 16:28:45 +0900 | [diff] [blame] | 2098 | final int oldSelStart = mCursorSelStart; |
| 2099 | final int oldSelEnd = mCursorSelEnd; |
| 2100 | // Update internal values before sending updateSelection to the IME, because |
| 2101 | // if it changes the text within its onUpdateSelection handler in a way that |
| 2102 | // does not move the cursor we don't want to call it again with the same values. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2103 | mCursorSelStart = selStart; |
| 2104 | mCursorSelEnd = selEnd; |
| 2105 | mCursorCandStart = candidatesStart; |
| 2106 | mCursorCandEnd = candidatesEnd; |
Jean Chalard | c743cb9 | 2013-09-12 16:28:45 +0900 | [diff] [blame] | 2107 | mCurMethod.updateSelection(oldSelStart, oldSelEnd, |
| 2108 | selStart, selEnd, candidatesStart, candidatesEnd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | } catch (RemoteException e) { |
| 2110 | Log.w(TAG, "IME died: " + mCurId, e); |
| 2111 | } |
| 2112 | } |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | /** |
satok | 863fcd6 | 2011-06-21 17:38:02 +0900 | [diff] [blame] | 2117 | * Notify the event when the user tapped or clicked the text view. |
Yohei Yukawa | 0eb8d16 | 2019-01-22 21:47:57 -0800 | [diff] [blame] | 2118 | * |
| 2119 | * @param view {@link View} which is being clicked. |
| 2120 | * @see InputMethodService#onViewClicked(boolean) |
| 2121 | * @deprecated The semantics of this method can never be defined well for composite {@link View} |
| 2122 | * that works as a giant "Canvas", which can host its own UI hierarchy and sub focus |
| 2123 | * state. {@link android.webkit.WebView} is a good example. Application / IME |
| 2124 | * developers should not rely on this method. |
satok | 863fcd6 | 2011-06-21 17:38:02 +0900 | [diff] [blame] | 2125 | */ |
Yohei Yukawa | 0eb8d16 | 2019-01-22 21:47:57 -0800 | [diff] [blame] | 2126 | @Deprecated |
satok | 863fcd6 | 2011-06-21 17:38:02 +0900 | [diff] [blame] | 2127 | public void viewClicked(View view) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2128 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 2129 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(view); |
| 2130 | if (fallbackImm != null) { |
| 2131 | fallbackImm.viewClicked(view); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2132 | return; |
| 2133 | } |
| 2134 | |
satok | 863fcd6 | 2011-06-21 17:38:02 +0900 | [diff] [blame] | 2135 | final boolean focusChanged = mServedView != mNextServedView; |
| 2136 | checkFocus(); |
| 2137 | synchronized (mH) { |
| 2138 | if ((mServedView != view && (mServedView == null |
| 2139 | || !mServedView.checkInputConnectionProxy(view))) |
| 2140 | || mCurrentTextBoxAttribute == null || mCurMethod == null) { |
| 2141 | return; |
| 2142 | } |
| 2143 | try { |
| 2144 | if (DEBUG) Log.v(TAG, "onViewClicked: " + focusChanged); |
| 2145 | mCurMethod.viewClicked(focusChanged); |
| 2146 | } catch (RemoteException e) { |
| 2147 | Log.w(TAG, "IME died: " + mCurId, e); |
| 2148 | } |
| 2149 | } |
| 2150 | } |
| 2151 | |
| 2152 | /** |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2153 | * Return true if the current input method wants to watch the location |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2154 | * of the input editor's cursor in its window. |
Yohei Yukawa | 4de0479 | 2014-04-17 12:40:31 +0900 | [diff] [blame] | 2155 | * |
Yohei Yukawa | d8636ea | 2014-09-02 22:03:30 -0700 | [diff] [blame] | 2156 | * @deprecated Use {@link InputConnection#requestCursorUpdates(int)} instead. |
Yohei Yukawa | 4de0479 | 2014-04-17 12:40:31 +0900 | [diff] [blame] | 2157 | */ |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2158 | @Deprecated |
| 2159 | public boolean isWatchingCursor(View view) { |
| 2160 | return false; |
Yohei Yukawa | 4de0479 | 2014-04-17 12:40:31 +0900 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | /** |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2164 | * Return true if the current input method wants to be notified when cursor/anchor location |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 2165 | * is changed. |
Yohei Yukawa | b7b7907 | 2014-03-25 11:02:00 +0900 | [diff] [blame] | 2166 | * |
| 2167 | * @hide |
| 2168 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2169 | @UnsupportedAppUsage |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 2170 | public boolean isCursorAnchorInfoEnabled() { |
| 2171 | synchronized (mH) { |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2172 | final boolean isImmediate = (mRequestUpdateCursorAnchorInfoMonitorMode & |
Yohei Yukawa | d8636ea | 2014-09-02 22:03:30 -0700 | [diff] [blame] | 2173 | InputConnection.CURSOR_UPDATE_IMMEDIATE) != 0; |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2174 | final boolean isMonitoring = (mRequestUpdateCursorAnchorInfoMonitorMode & |
Yohei Yukawa | d8636ea | 2014-09-02 22:03:30 -0700 | [diff] [blame] | 2175 | InputConnection.CURSOR_UPDATE_MONITOR) != 0; |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 2176 | return isImmediate || isMonitoring; |
| 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | /** |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2181 | * Set the requested mode for {@link #updateCursorAnchorInfo(View, CursorAnchorInfo)}. |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 2182 | * |
| 2183 | * @hide |
| 2184 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2185 | @UnsupportedAppUsage |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2186 | public void setUpdateCursorAnchorInfoMode(int flags) { |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 2187 | synchronized (mH) { |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2188 | mRequestUpdateCursorAnchorInfoMonitorMode = flags; |
Yohei Yukawa | b7b7907 | 2014-03-25 11:02:00 +0900 | [diff] [blame] | 2189 | } |
| 2190 | } |
| 2191 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2192 | /** |
| 2193 | * Report the current cursor location in its window. |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2194 | * |
| 2195 | * @deprecated Use {@link #updateCursorAnchorInfo(View, CursorAnchorInfo)} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2196 | */ |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2197 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2198 | public void updateCursor(View view, int left, int top, int right, int bottom) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2199 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 2200 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(view); |
| 2201 | if (fallbackImm != null) { |
| 2202 | fallbackImm.updateCursor(view, left, top, right, bottom); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2203 | return; |
| 2204 | } |
| 2205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2206 | checkFocus(); |
| 2207 | synchronized (mH) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2208 | if ((mServedView != view && (mServedView == null |
| 2209 | || !mServedView.checkInputConnectionProxy(view))) |
| 2210 | || mCurrentTextBoxAttribute == null || mCurMethod == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2211 | return; |
| 2212 | } |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2213 | |
| 2214 | mTmpCursorRect.set(left, top, right, bottom); |
| 2215 | if (!mCursorRect.equals(mTmpCursorRect)) { |
| 2216 | if (DEBUG) Log.d(TAG, "updateCursor"); |
| 2217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2218 | try { |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2219 | if (DEBUG) Log.v(TAG, "CURSOR CHANGE: " + mCurMethod); |
| 2220 | mCurMethod.updateCursor(mTmpCursorRect); |
| 2221 | mCursorRect.set(mTmpCursorRect); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2222 | } catch (RemoteException e) { |
| 2223 | Log.w(TAG, "IME died: " + mCurId, e); |
| 2224 | } |
| 2225 | } |
| 2226 | } |
| 2227 | } |
| 2228 | |
| 2229 | /** |
Yohei Yukawa | c2ddd60 | 2014-05-06 21:22:49 +0900 | [diff] [blame] | 2230 | * Report positional change of the text insertion point and/or characters in the composition |
| 2231 | * string. |
| 2232 | */ |
| 2233 | public void updateCursorAnchorInfo(View view, final CursorAnchorInfo cursorAnchorInfo) { |
| 2234 | if (view == null || cursorAnchorInfo == null) { |
| 2235 | return; |
| 2236 | } |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2237 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 2238 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(view); |
| 2239 | if (fallbackImm != null) { |
| 2240 | fallbackImm.updateCursorAnchorInfo(view, cursorAnchorInfo); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2241 | return; |
| 2242 | } |
| 2243 | |
Yohei Yukawa | c2ddd60 | 2014-05-06 21:22:49 +0900 | [diff] [blame] | 2244 | checkFocus(); |
| 2245 | synchronized (mH) { |
| 2246 | if ((mServedView != view && |
| 2247 | (mServedView == null || !mServedView.checkInputConnectionProxy(view))) |
| 2248 | || mCurrentTextBoxAttribute == null || mCurMethod == null) { |
| 2249 | return; |
| 2250 | } |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 2251 | // If immediate bit is set, we will call updateCursorAnchorInfo() even when the data has |
| 2252 | // not been changed from the previous call. |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2253 | final boolean isImmediate = (mRequestUpdateCursorAnchorInfoMonitorMode & |
Yohei Yukawa | d8636ea | 2014-09-02 22:03:30 -0700 | [diff] [blame] | 2254 | InputConnection.CURSOR_UPDATE_IMMEDIATE) != 0; |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 2255 | if (!isImmediate && Objects.equals(mCursorAnchorInfo, cursorAnchorInfo)) { |
Yohei Yukawa | 7360591 | 2014-08-13 16:49:35 +0900 | [diff] [blame] | 2256 | // TODO: Consider always emitting this message once we have addressed redundant |
| 2257 | // calls of this method from android.widget.Editor. |
| 2258 | if (DEBUG) { |
| 2259 | Log.w(TAG, "Ignoring redundant updateCursorAnchorInfo: info=" |
| 2260 | + cursorAnchorInfo); |
| 2261 | } |
Yohei Yukawa | 056ffe6 | 2014-05-13 14:26:09 +0900 | [diff] [blame] | 2262 | return; |
| 2263 | } |
| 2264 | if (DEBUG) Log.v(TAG, "updateCursorAnchorInfo: " + cursorAnchorInfo); |
Yohei Yukawa | c2ddd60 | 2014-05-06 21:22:49 +0900 | [diff] [blame] | 2265 | try { |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2266 | if (mActivityViewToScreenMatrix != null) { |
| 2267 | mCurMethod.updateCursorAnchorInfo( |
| 2268 | CursorAnchorInfo.createForAdditionalParentMatrix( |
| 2269 | cursorAnchorInfo, mActivityViewToScreenMatrix)); |
| 2270 | } else { |
| 2271 | mCurMethod.updateCursorAnchorInfo(cursorAnchorInfo); |
| 2272 | } |
Yohei Yukawa | 056ffe6 | 2014-05-13 14:26:09 +0900 | [diff] [blame] | 2273 | mCursorAnchorInfo = cursorAnchorInfo; |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 2274 | // Clear immediate bit (if any). |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 2275 | mRequestUpdateCursorAnchorInfoMonitorMode &= |
Yohei Yukawa | d8636ea | 2014-09-02 22:03:30 -0700 | [diff] [blame] | 2276 | ~InputConnection.CURSOR_UPDATE_IMMEDIATE; |
Yohei Yukawa | c2ddd60 | 2014-05-06 21:22:49 +0900 | [diff] [blame] | 2277 | } catch (RemoteException e) { |
| 2278 | Log.w(TAG, "IME died: " + mCurId, e); |
| 2279 | } |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2284 | * Call {@link InputMethodSession#appPrivateCommand(String, Bundle) |
| 2285 | * InputMethodSession.appPrivateCommand()} on the current Input Method. |
| 2286 | * @param view Optional View that is sending the command, or null if |
| 2287 | * you want to send the command regardless of the view that is attached |
| 2288 | * to the input method. |
| 2289 | * @param action Name of the command to be performed. This <em>must</em> |
| 2290 | * be a scoped name, i.e. prefixed with a package name you own, so that |
| 2291 | * different developers will not create conflicting commands. |
| 2292 | * @param data Any data to include with the command. |
| 2293 | */ |
| 2294 | public void sendAppPrivateCommand(View view, String action, Bundle data) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2295 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 2296 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(view); |
| 2297 | if (fallbackImm != null) { |
| 2298 | fallbackImm.sendAppPrivateCommand(view, action, data); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2299 | return; |
| 2300 | } |
| 2301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2302 | checkFocus(); |
| 2303 | synchronized (mH) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 2304 | if ((mServedView != view && (mServedView == null |
| 2305 | || !mServedView.checkInputConnectionProxy(view))) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2306 | || mCurrentTextBoxAttribute == null || mCurMethod == null) { |
| 2307 | return; |
| 2308 | } |
| 2309 | try { |
| 2310 | if (DEBUG) Log.v(TAG, "APP PRIVATE COMMAND " + action + ": " + data); |
| 2311 | mCurMethod.appPrivateCommand(action, data); |
| 2312 | } catch (RemoteException e) { |
| 2313 | Log.w(TAG, "IME died: " + mCurId, e); |
| 2314 | } |
| 2315 | } |
| 2316 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2317 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2318 | /** |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2319 | * Force switch to a new input method component. This can only be called |
| 2320 | * from an application or a service which has a token of the currently active input method. |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 2321 | * |
| 2322 | * <p>On Android {@link Build.VERSION_CODES#Q} and later devices, the undocumented behavior that |
| 2323 | * token can be {@code null} when the caller has |
| 2324 | * {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} is deprecated. Instead, update |
| 2325 | * {@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD} and |
| 2326 | * {@link android.provider.Settings.Secure#SELECTED_INPUT_METHOD_SUBTYPE} directly.</p> |
| 2327 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2328 | * @param token Supplies the identifying token given to an input method |
| 2329 | * when it was started, which allows it to perform this operation on |
| 2330 | * itself. |
| 2331 | * @param id The unique identifier for the new input method to be switched to. |
Tarandeep Singh | 164cfba | 2018-02-28 14:17:43 -0800 | [diff] [blame] | 2332 | * @deprecated Use {@link InputMethodService#switchInputMethod(String)} |
| 2333 | * instead. This method was intended for IME developers who should be accessing APIs through |
| 2334 | * the service. APIs in this class are intended for app developers interacting with the IME. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2335 | */ |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2336 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2337 | public void setInputMethod(IBinder token, String id) { |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 2338 | if (token == null) { |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 2339 | // There are still some system components that rely on this undocumented behavior |
| 2340 | // regarding null IME token with WRITE_SECURE_SETTINGS. Provide a fallback logic as a |
| 2341 | // temporary remedy. |
| 2342 | if (id == null) { |
| 2343 | return; |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 2344 | } |
Yohei Yukawa | 0c1ebff | 2018-12-27 14:06:28 -0800 | [diff] [blame] | 2345 | if (Process.myUid() == Process.SYSTEM_UID) { |
| 2346 | Log.w(TAG, "System process should not be calling setInputMethod() because almost " |
| 2347 | + "always it is a bug under multi-user / multi-profile environment. " |
| 2348 | + "Consider interacting with InputMethodManagerService directly via " |
| 2349 | + "LocalServices."); |
| 2350 | return; |
| 2351 | } |
| 2352 | final Context fallbackContext = ActivityThread.currentApplication(); |
| 2353 | if (fallbackContext == null) { |
| 2354 | return; |
| 2355 | } |
| 2356 | if (fallbackContext.checkSelfPermission(WRITE_SECURE_SETTINGS) |
| 2357 | != PackageManager.PERMISSION_GRANTED) { |
| 2358 | return; |
| 2359 | } |
| 2360 | final List<InputMethodInfo> imis = getEnabledInputMethodList(); |
| 2361 | final int numImis = imis.size(); |
| 2362 | boolean found = false; |
| 2363 | for (int i = 0; i < numImis; ++i) { |
| 2364 | final InputMethodInfo imi = imis.get(i); |
| 2365 | if (id.equals(imi.getId())) { |
| 2366 | found = true; |
| 2367 | break; |
| 2368 | } |
| 2369 | } |
| 2370 | if (!found) { |
| 2371 | Log.e(TAG, "Ignoring setInputMethod(null, " + id + ") because the specified " |
| 2372 | + "id not found in enabled IMEs."); |
| 2373 | return; |
| 2374 | } |
| 2375 | Log.w(TAG, "The undocumented behavior that setInputMethod() accepts null token " |
| 2376 | + "when the caller has WRITE_SECURE_SETTINGS is deprecated. This behavior may " |
| 2377 | + "be completely removed in a future version. Update secure settings directly " |
| 2378 | + "instead."); |
| 2379 | final ContentResolver resolver = fallbackContext.getContentResolver(); |
| 2380 | Settings.Secure.putInt(resolver, Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, |
| 2381 | NOT_A_SUBTYPE_ID); |
| 2382 | Settings.Secure.putString(resolver, Settings.Secure.DEFAULT_INPUT_METHOD, id); |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 2383 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2384 | } |
Yohei Yukawa | d746a7e | 2018-09-18 18:55:02 -0700 | [diff] [blame] | 2385 | InputMethodPrivilegedOperationsRegistry.get(token).setInputMethod(id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2386 | } |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2387 | |
| 2388 | /** |
| 2389 | * Force switch to a new input method and subtype. This can only be called |
| 2390 | * from an application or a service which has a token of the currently active input method. |
Yohei Yukawa | 4773ee1 | 2018-12-24 21:13:53 -0800 | [diff] [blame] | 2391 | * |
| 2392 | * <p>On Android {@link Build.VERSION_CODES#Q} and later devices, {@code token} cannot be |
| 2393 | * {@code null} even with {@link android.Manifest.permission#WRITE_SECURE_SETTINGS}. Instead, |
| 2394 | * update {@link android.provider.Settings.Secure#DEFAULT_INPUT_METHOD} and |
| 2395 | * {@link android.provider.Settings.Secure#SELECTED_INPUT_METHOD_SUBTYPE} directly.</p> |
| 2396 | * |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2397 | * @param token Supplies the identifying token given to an input method |
| 2398 | * when it was started, which allows it to perform this operation on |
| 2399 | * itself. |
| 2400 | * @param id The unique identifier for the new input method to be switched to. |
| 2401 | * @param subtype The new subtype of the new input method to be switched to. |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2402 | * @deprecated Use |
Tarandeep Singh | 164cfba | 2018-02-28 14:17:43 -0800 | [diff] [blame] | 2403 | * {@link InputMethodService#switchInputMethod(String, InputMethodSubtype)} |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2404 | * instead. This method was intended for IME developers who should be accessing APIs through |
| 2405 | * the service. APIs in this class are intended for app developers interacting with the IME. |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2406 | */ |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2407 | @Deprecated |
Yohei Yukawa | 4773ee1 | 2018-12-24 21:13:53 -0800 | [diff] [blame] | 2408 | public void setInputMethodAndSubtype(@NonNull IBinder token, String id, |
| 2409 | InputMethodSubtype subtype) { |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 2410 | if (token == null) { |
Yohei Yukawa | 4773ee1 | 2018-12-24 21:13:53 -0800 | [diff] [blame] | 2411 | Log.e(TAG, "setInputMethodAndSubtype() does not accept null token on Android Q " |
| 2412 | + "and later."); |
Yohei Yukawa | eec552e | 2018-09-09 20:48:41 -0700 | [diff] [blame] | 2413 | return; |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2414 | } |
Yohei Yukawa | d746a7e | 2018-09-18 18:55:02 -0700 | [diff] [blame] | 2415 | InputMethodPrivilegedOperationsRegistry.get(token).setInputMethodAndSubtype(id, subtype); |
satok | 2820351 | 2010-11-24 11:06:49 +0900 | [diff] [blame] | 2416 | } |
| 2417 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2418 | /** |
| 2419 | * Close/hide the input method's soft input area, so the user no longer |
| 2420 | * sees it or can interact with it. This can only be called |
| 2421 | * from the currently active input method, as validated by the given token. |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 2422 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2423 | * @param token Supplies the identifying token given to an input method |
| 2424 | * when it was started, which allows it to perform this operation on |
| 2425 | * itself. |
| 2426 | * @param flags Provides additional operating flags. Currently may be |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2427 | * 0 or have the {@link #HIDE_IMPLICIT_ONLY}, |
| 2428 | * {@link #HIDE_NOT_ALWAYS} bit set. |
Yohei Yukawa | fbc2f7a | 2018-01-16 08:09:11 -0800 | [diff] [blame] | 2429 | * @deprecated Use {@link InputMethodService#requestHideSelf(int)} instead. This method was |
| 2430 | * intended for IME developers who should be accessing APIs through the service. APIs in this |
| 2431 | * class are intended for app developers interacting with the IME. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2432 | */ |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2433 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2434 | public void hideSoftInputFromInputMethod(IBinder token, int flags) { |
Yohei Yukawa | d746a7e | 2018-09-18 18:55:02 -0700 | [diff] [blame] | 2435 | InputMethodPrivilegedOperationsRegistry.get(token).hideMySoftInput(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2436 | } |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 2437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2438 | /** |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 2439 | * Show the input method's soft input area, so the user |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2440 | * sees the input method window and can interact with it. |
| 2441 | * This can only be called from the currently active input method, |
| 2442 | * as validated by the given token. |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 2443 | * |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2444 | * @param token Supplies the identifying token given to an input method |
| 2445 | * when it was started, which allows it to perform this operation on |
| 2446 | * itself. |
| 2447 | * @param flags Provides additional operating flags. Currently may be |
| 2448 | * 0 or have the {@link #SHOW_IMPLICIT} or |
| 2449 | * {@link #SHOW_FORCED} bit set. |
Yohei Yukawa | fbc2f7a | 2018-01-16 08:09:11 -0800 | [diff] [blame] | 2450 | * @deprecated Use {@link InputMethodService#requestShowSelf(int)} instead. This method was |
| 2451 | * intended for IME developers who should be accessing APIs through the service. APIs in this |
| 2452 | * class are intended for app developers interacting with the IME. |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2453 | */ |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2454 | @Deprecated |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2455 | public void showSoftInputFromInputMethod(IBinder token, int flags) { |
Yohei Yukawa | d746a7e | 2018-09-18 18:55:02 -0700 | [diff] [blame] | 2456 | InputMethodPrivilegedOperationsRegistry.get(token).showMySoftInput(flags); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2457 | } |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2458 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2459 | /** |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2460 | * Dispatches an input event to the IME. |
| 2461 | * |
| 2462 | * Returns {@link #DISPATCH_HANDLED} if the event was handled. |
| 2463 | * Returns {@link #DISPATCH_NOT_HANDLED} if the event was not handled. |
| 2464 | * Returns {@link #DISPATCH_IN_PROGRESS} if the event is in progress and the |
| 2465 | * callback will be invoked later. |
| 2466 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2467 | * @hide |
| 2468 | */ |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2469 | public int dispatchInputEvent(InputEvent event, Object token, |
| 2470 | FinishedInputEventCallback callback, Handler handler) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2471 | synchronized (mH) { |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2472 | if (mCurMethod != null) { |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2473 | if (event instanceof KeyEvent) { |
| 2474 | KeyEvent keyEvent = (KeyEvent)event; |
| 2475 | if (keyEvent.getAction() == KeyEvent.ACTION_DOWN |
| 2476 | && keyEvent.getKeyCode() == KeyEvent.KEYCODE_SYM |
| 2477 | && keyEvent.getRepeatCount() == 0) { |
| 2478 | showInputMethodPickerLocked(); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2479 | return DISPATCH_HANDLED; |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2480 | } |
Jeff Brown | 29c0ed2 | 2013-01-14 13:50:37 -0800 | [diff] [blame] | 2481 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2482 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 2483 | if (DEBUG) Log.v(TAG, "DISPATCH INPUT EVENT: " + mCurMethod); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2484 | |
| 2485 | PendingEvent p = obtainPendingEventLocked( |
| 2486 | event, token, mCurId, callback, handler); |
| 2487 | if (mMainLooper.isCurrentThread()) { |
| 2488 | // Already running on the IMM thread so we can send the event immediately. |
| 2489 | return sendInputEventOnMainLooperLocked(p); |
Victoria Lease | b38070c | 2012-08-24 13:46:02 -0700 | [diff] [blame] | 2490 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2491 | |
| 2492 | // Post the event to the IMM thread. |
| 2493 | Message msg = mH.obtainMessage(MSG_SEND_INPUT_EVENT, p); |
| 2494 | msg.setAsynchronous(true); |
| 2495 | mH.sendMessage(msg); |
| 2496 | return DISPATCH_IN_PROGRESS; |
Victoria Lease | b38070c | 2012-08-24 13:46:02 -0700 | [diff] [blame] | 2497 | } |
| 2498 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2499 | return DISPATCH_NOT_HANDLED; |
Victoria Lease | b38070c | 2012-08-24 13:46:02 -0700 | [diff] [blame] | 2500 | } |
| 2501 | |
Yohei Yukawa | 2afe2aa | 2016-01-07 18:09:44 -0800 | [diff] [blame] | 2502 | /** |
| 2503 | * Provides the default implementation of {@link InputConnection#sendKeyEvent(KeyEvent)}, which |
| 2504 | * is expected to dispatch an keyboard event sent from the IME to an appropriate event target |
| 2505 | * depending on the given {@link View} and the current focus state. |
| 2506 | * |
| 2507 | * <p>CAUTION: This method is provided only for the situation where |
| 2508 | * {@link InputConnection#sendKeyEvent(KeyEvent)} needs to be implemented without relying on |
| 2509 | * {@link BaseInputConnection}. Do not use this API for anything else.</p> |
| 2510 | * |
| 2511 | * @param targetView the default target view. If {@code null} is specified, then this method |
| 2512 | * tries to find a good event target based on the current focus state. |
| 2513 | * @param event the key event to be dispatched. |
| 2514 | */ |
| 2515 | public void dispatchKeyEventFromInputMethod(@Nullable View targetView, |
| 2516 | @NonNull KeyEvent event) { |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2517 | // Re-dispatch if there is a context mismatch. |
Yohei Yukawa | 052ab8c | 2018-10-26 08:43:30 -0700 | [diff] [blame] | 2518 | final InputMethodManager fallbackImm = getFallbackInputMethodManagerIfNecessary(targetView); |
| 2519 | if (fallbackImm != null) { |
| 2520 | fallbackImm.dispatchKeyEventFromInputMethod(targetView, event); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 2521 | return; |
| 2522 | } |
| 2523 | |
Yohei Yukawa | 2afe2aa | 2016-01-07 18:09:44 -0800 | [diff] [blame] | 2524 | synchronized (mH) { |
| 2525 | ViewRootImpl viewRootImpl = targetView != null ? targetView.getViewRootImpl() : null; |
| 2526 | if (viewRootImpl == null) { |
| 2527 | if (mServedView != null) { |
| 2528 | viewRootImpl = mServedView.getViewRootImpl(); |
| 2529 | } |
| 2530 | } |
| 2531 | if (viewRootImpl != null) { |
| 2532 | viewRootImpl.dispatchKeyFromIme(event); |
| 2533 | } |
| 2534 | } |
| 2535 | } |
| 2536 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2537 | // Must be called on the main looper |
| 2538 | void sendInputEventAndReportResultOnMainLooper(PendingEvent p) { |
| 2539 | final boolean handled; |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2540 | synchronized (mH) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2541 | int result = sendInputEventOnMainLooperLocked(p); |
| 2542 | if (result == DISPATCH_IN_PROGRESS) { |
| 2543 | return; |
| 2544 | } |
| 2545 | |
| 2546 | handled = (result == DISPATCH_HANDLED); |
| 2547 | } |
| 2548 | |
| 2549 | invokeFinishedInputEventCallback(p, handled); |
| 2550 | } |
| 2551 | |
| 2552 | // Must be called on the main looper |
| 2553 | int sendInputEventOnMainLooperLocked(PendingEvent p) { |
| 2554 | if (mCurChannel != null) { |
| 2555 | if (mCurSender == null) { |
| 2556 | mCurSender = new ImeInputEventSender(mCurChannel, mH.getLooper()); |
| 2557 | } |
| 2558 | |
| 2559 | final InputEvent event = p.mEvent; |
| 2560 | final int seq = event.getSequenceNumber(); |
| 2561 | if (mCurSender.sendInputEvent(seq, event)) { |
| 2562 | mPendingEvents.put(seq, p); |
| 2563 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, PENDING_EVENT_COUNTER, |
| 2564 | mPendingEvents.size()); |
| 2565 | |
gaoshang | 863ad2f | 2017-04-20 14:14:18 +0800 | [diff] [blame] | 2566 | Message msg = mH.obtainMessage(MSG_TIMEOUT_INPUT_EVENT, seq, 0, p); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2567 | msg.setAsynchronous(true); |
| 2568 | mH.sendMessageDelayed(msg, INPUT_METHOD_NOT_RESPONDING_TIMEOUT); |
| 2569 | return DISPATCH_IN_PROGRESS; |
| 2570 | } |
| 2571 | |
| 2572 | Log.w(TAG, "Unable to send input event to IME: " |
| 2573 | + mCurId + " dropping: " + event); |
| 2574 | } |
| 2575 | return DISPATCH_NOT_HANDLED; |
| 2576 | } |
| 2577 | |
| 2578 | void finishedInputEvent(int seq, boolean handled, boolean timeout) { |
| 2579 | final PendingEvent p; |
| 2580 | synchronized (mH) { |
| 2581 | int index = mPendingEvents.indexOfKey(seq); |
| 2582 | if (index < 0) { |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2583 | return; // spurious, event already finished or timed out |
| 2584 | } |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2585 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2586 | p = mPendingEvents.valueAt(index); |
| 2587 | mPendingEvents.removeAt(index); |
| 2588 | Trace.traceCounter(Trace.TRACE_TAG_INPUT, PENDING_EVENT_COUNTER, mPendingEvents.size()); |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2589 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2590 | if (timeout) { |
| 2591 | Log.w(TAG, "Timeout waiting for IME to handle input event after " |
| 2592 | + INPUT_METHOD_NOT_RESPONDING_TIMEOUT + " ms: " + p.mInputMethodId); |
| 2593 | } else { |
| 2594 | mH.removeMessages(MSG_TIMEOUT_INPUT_EVENT, p); |
Jeff Brown | 4d65688 | 2013-04-03 14:39:19 -0700 | [diff] [blame] | 2595 | } |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2596 | } |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2597 | |
| 2598 | invokeFinishedInputEventCallback(p, handled); |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2599 | } |
| 2600 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2601 | // Assumes the event has already been removed from the queue. |
| 2602 | void invokeFinishedInputEventCallback(PendingEvent p, boolean handled) { |
| 2603 | p.mHandled = handled; |
| 2604 | if (p.mHandler.getLooper().isCurrentThread()) { |
| 2605 | // Already running on the callback handler thread so we can send the |
| 2606 | // callback immediately. |
| 2607 | p.run(); |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2608 | } else { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2609 | // Post the event to the callback handler thread. |
| 2610 | // In this case, the callback will be responsible for recycling the event. |
| 2611 | Message msg = Message.obtain(p.mHandler, p); |
| 2612 | msg.setAsynchronous(true); |
| 2613 | msg.sendToTarget(); |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2614 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2615 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame] | 2616 | |
Michael Wright | ef17e87 | 2013-04-01 13:15:55 -0700 | [diff] [blame] | 2617 | private void flushPendingEventsLocked() { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2618 | mH.removeMessages(MSG_FLUSH_INPUT_EVENT); |
Jeff Brown | 4d65688 | 2013-04-03 14:39:19 -0700 | [diff] [blame] | 2619 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2620 | final int count = mPendingEvents.size(); |
| 2621 | for (int i = 0; i < count; i++) { |
| 2622 | int seq = mPendingEvents.keyAt(i); |
| 2623 | Message msg = mH.obtainMessage(MSG_FLUSH_INPUT_EVENT, seq, 0); |
Michael Wright | ef17e87 | 2013-04-01 13:15:55 -0700 | [diff] [blame] | 2624 | msg.setAsynchronous(true); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2625 | msg.sendToTarget(); |
Michael Wright | ef17e87 | 2013-04-01 13:15:55 -0700 | [diff] [blame] | 2626 | } |
| 2627 | } |
| 2628 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 2629 | private PendingEvent obtainPendingEventLocked(InputEvent event, Object token, |
| 2630 | String inputMethodId, FinishedInputEventCallback callback, Handler handler) { |
| 2631 | PendingEvent p = mPendingEventPool.acquire(); |
| 2632 | if (p == null) { |
| 2633 | p = new PendingEvent(); |
| 2634 | } |
| 2635 | p.mEvent = event; |
| 2636 | p.mToken = token; |
| 2637 | p.mInputMethodId = inputMethodId; |
| 2638 | p.mCallback = callback; |
| 2639 | p.mHandler = handler; |
| 2640 | return p; |
| 2641 | } |
| 2642 | |
| 2643 | private void recyclePendingEventLocked(PendingEvent p) { |
| 2644 | p.recycle(); |
| 2645 | mPendingEventPool.release(p); |
| 2646 | } |
| 2647 | |
Tarandeep Singh | 47e49fd | 2019-03-12 13:39:38 -0700 | [diff] [blame] | 2648 | /** |
| 2649 | * Show IME picker popup window. |
| 2650 | * |
| 2651 | * <p>Requires the {@link PackageManager#FEATURE_INPUT_METHODS} feature which can be detected |
| 2652 | * using {@link PackageManager#hasSystemFeature(String)}. |
| 2653 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2654 | public void showInputMethodPicker() { |
| 2655 | synchronized (mH) { |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2656 | showInputMethodPickerLocked(); |
| 2657 | } |
| 2658 | } |
| 2659 | |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2660 | /** |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 2661 | * Shows the input method chooser dialog from system. |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2662 | * |
| 2663 | * @param showAuxiliarySubtypes Set true to show auxiliary input methods. |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 2664 | * @param displayId The ID of the display where the chooser dialog should be shown. |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2665 | * @hide |
| 2666 | */ |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 2667 | @RequiresPermission(WRITE_SECURE_SETTINGS) |
| 2668 | public void showInputMethodPickerFromSystem(boolean showAuxiliarySubtypes, int displayId) { |
Yohei Yukawa | 83b7d72 | 2018-09-09 20:48:25 -0700 | [diff] [blame] | 2669 | final int mode = showAuxiliarySubtypes |
| 2670 | ? SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES |
| 2671 | : SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES; |
| 2672 | try { |
lumark | 0b05f9e | 2018-11-26 15:09:06 +0800 | [diff] [blame] | 2673 | mService.showInputMethodPickerFromSystem(mClient, mode, displayId); |
Yohei Yukawa | 83b7d72 | 2018-09-09 20:48:25 -0700 | [diff] [blame] | 2674 | } catch (RemoteException e) { |
| 2675 | throw e.rethrowFromSystemServer(); |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2676 | } |
| 2677 | } |
| 2678 | |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2679 | private void showInputMethodPickerLocked() { |
| 2680 | try { |
Seigo Nonaka | 14e1391 | 2015-05-06 21:04:13 -0700 | [diff] [blame] | 2681 | mService.showInputMethodPickerFromClient(mClient, SHOW_IM_PICKER_MODE_AUTO); |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 2682 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 2683 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2684 | } |
| 2685 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 2686 | |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 2687 | /** |
Tarandeep Singh | eb57061 | 2018-01-29 16:20:32 -0800 | [diff] [blame] | 2688 | * A test API for CTS to make sure that {@link #showInputMethodPicker()} works as expected. |
| 2689 | * |
| 2690 | * <p>When customizing the implementation of {@link #showInputMethodPicker()} API, make sure |
| 2691 | * that this test API returns when and only while and only while |
| 2692 | * {@link #showInputMethodPicker()} is showing UI. Otherwise your OS implementation may not |
| 2693 | * pass CTS.</p> |
| 2694 | * |
| 2695 | * @return {@code true} while and only while {@link #showInputMethodPicker()} is showing UI. |
| 2696 | * @hide |
| 2697 | */ |
| 2698 | @TestApi |
| 2699 | public boolean isInputMethodPickerShown() { |
| 2700 | try { |
| 2701 | return mService.isInputMethodPickerShownForTest(); |
| 2702 | } catch (RemoteException e) { |
| 2703 | throw e.rethrowFromSystemServer(); |
| 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | /** |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 2708 | * Show the settings for enabling subtypes of the specified input method. |
| 2709 | * @param imiId An input method, whose subtypes settings will be shown. If imiId is null, |
| 2710 | * subtypes of all input methods will be shown. |
| 2711 | */ |
| 2712 | public void showInputMethodAndSubtypeEnabler(String imiId) { |
Yohei Yukawa | 83b7d72 | 2018-09-09 20:48:25 -0700 | [diff] [blame] | 2713 | try { |
| 2714 | mService.showInputMethodAndSubtypeEnablerFromClient(mClient, imiId); |
| 2715 | } catch (RemoteException e) { |
| 2716 | throw e.rethrowFromSystemServer(); |
satok | 47a4491 | 2010-10-06 16:03:58 +0900 | [diff] [blame] | 2717 | } |
| 2718 | } |
| 2719 | |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 2720 | /** |
| 2721 | * Returns the current input method subtype. This subtype is one of the subtypes in |
| 2722 | * the current input method. This method returns null when the current input method doesn't |
| 2723 | * have any input method subtype. |
| 2724 | */ |
satok | 04d5020 | 2010-10-25 22:20:12 +0900 | [diff] [blame] | 2725 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
Gopal Krishna Shukla | fa1886f | 2016-06-30 11:34:21 +0530 | [diff] [blame] | 2726 | try { |
| 2727 | return mService.getCurrentInputMethodSubtype(); |
| 2728 | } catch (RemoteException e) { |
| 2729 | throw e.rethrowFromSystemServer(); |
satok | 04d5020 | 2010-10-25 22:20:12 +0900 | [diff] [blame] | 2730 | } |
| 2731 | } |
| 2732 | |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 2733 | /** |
| 2734 | * Switch to a new input method subtype of the current input method. |
| 2735 | * @param subtype A new input method subtype to switch. |
| 2736 | * @return true if the current subtype was successfully switched. When the specified subtype is |
| 2737 | * null, this method returns false. |
Yohei Yukawa | ff42b1b | 2019-01-23 15:47:35 -0800 | [diff] [blame] | 2738 | * @deprecated If the calling process is an IME, use |
| 2739 | * {@link InputMethodService#switchInputMethod(String, InputMethodSubtype)}, which |
| 2740 | * does not require any permission as long as the caller is the current IME. |
| 2741 | * If the calling process is some privileged app that already has |
| 2742 | * {@link android.Manifest.permission#WRITE_SECURE_SETTINGS} permission, just |
| 2743 | * directly update {@link Settings.Secure#SELECTED_INPUT_METHOD_SUBTYPE}. |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 2744 | */ |
Yohei Yukawa | ff42b1b | 2019-01-23 15:47:35 -0800 | [diff] [blame] | 2745 | @Deprecated |
Yoshiki Iguchi | 00d5122 | 2015-05-29 15:36:22 +0900 | [diff] [blame] | 2746 | @RequiresPermission(WRITE_SECURE_SETTINGS) |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 2747 | public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) { |
Yohei Yukawa | fd8f721 | 2019-01-22 19:25:44 -0800 | [diff] [blame] | 2748 | if (Process.myUid() == Process.SYSTEM_UID) { |
| 2749 | Log.w(TAG, "System process should not call setCurrentInputMethodSubtype() because " |
| 2750 | + "almost always it is a bug under multi-user / multi-profile environment. " |
| 2751 | + "Consider directly interacting with InputMethodManagerService " |
| 2752 | + "via LocalServices."); |
| 2753 | return false; |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 2754 | } |
Yohei Yukawa | fd8f721 | 2019-01-22 19:25:44 -0800 | [diff] [blame] | 2755 | if (subtype == null) { |
| 2756 | // See the JavaDoc. This is how this method has worked. |
| 2757 | return false; |
| 2758 | } |
| 2759 | final Context fallbackContext = ActivityThread.currentApplication(); |
| 2760 | if (fallbackContext == null) { |
| 2761 | return false; |
| 2762 | } |
| 2763 | if (fallbackContext.checkSelfPermission(WRITE_SECURE_SETTINGS) |
| 2764 | != PackageManager.PERMISSION_GRANTED) { |
| 2765 | return false; |
| 2766 | } |
| 2767 | final ContentResolver contentResolver = fallbackContext.getContentResolver(); |
| 2768 | final String imeId = Settings.Secure.getString(contentResolver, |
| 2769 | Settings.Secure.DEFAULT_INPUT_METHOD); |
| 2770 | if (ComponentName.unflattenFromString(imeId) == null) { |
| 2771 | // Null or invalid IME ID format. |
| 2772 | return false; |
| 2773 | } |
| 2774 | final List<InputMethodSubtype> enabledSubtypes; |
| 2775 | try { |
| 2776 | enabledSubtypes = mService.getEnabledInputMethodSubtypeList(imeId, true); |
| 2777 | } catch (RemoteException e) { |
| 2778 | return false; |
| 2779 | } |
| 2780 | final int numSubtypes = enabledSubtypes.size(); |
| 2781 | for (int i = 0; i < numSubtypes; ++i) { |
| 2782 | final InputMethodSubtype enabledSubtype = enabledSubtypes.get(i); |
| 2783 | if (enabledSubtype.equals(subtype)) { |
| 2784 | Settings.Secure.putInt(contentResolver, |
| 2785 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, enabledSubtype.hashCode()); |
| 2786 | return true; |
| 2787 | } |
| 2788 | } |
| 2789 | return false; |
satok | b66d287 | 2010-11-10 01:04:04 +0900 | [diff] [blame] | 2790 | } |
| 2791 | |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 2792 | /** |
Yohei Yukawa | 0297051 | 2014-06-05 16:16:18 +0900 | [diff] [blame] | 2793 | * Notify that a user took some action with this input method. |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 2794 | * |
| 2795 | * @deprecated Just kept to avoid possible app compat issue. |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 2796 | * @hide |
| 2797 | */ |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 2798 | @Deprecated |
Yohei Yukawa | a086f95 | 2018-09-11 11:37:08 -0700 | [diff] [blame] | 2799 | @UnsupportedAppUsage(trackingBug = 114740982, maxTargetSdk = Build.VERSION_CODES.P) |
Yohei Yukawa | 0297051 | 2014-06-05 16:16:18 +0900 | [diff] [blame] | 2800 | public void notifyUserAction() { |
Yohei Yukawa | c07fd4c | 2018-09-11 11:37:13 -0700 | [diff] [blame] | 2801 | Log.w(TAG, "notifyUserAction() is a hidden method, which is now just a stub method" |
| 2802 | + " that does nothing. Leave comments in b.android.com/114740982 if your " |
| 2803 | + " application still depends on the previous behavior of this method."); |
Satoshi Kataoka | d7443c8 | 2013-10-15 17:45:43 +0900 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | /** |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 2807 | * Returns a map of all shortcut input method info and their subtypes. |
| 2808 | */ |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2809 | public Map<InputMethodInfo, List<InputMethodSubtype>> getShortcutInputMethodsAndSubtypes() { |
Yohei Yukawa | fefedc5 | 2018-12-24 19:43:17 -0800 | [diff] [blame] | 2810 | final List<InputMethodInfo> enabledImes = getEnabledInputMethodList(); |
| 2811 | |
| 2812 | // Ensure we check system IMEs first. |
| 2813 | enabledImes.sort(Comparator.comparingInt(imi -> imi.isSystem() ? 0 : 1)); |
| 2814 | |
| 2815 | final int numEnabledImes = enabledImes.size(); |
| 2816 | for (int imiIndex = 0; imiIndex < numEnabledImes; ++imiIndex) { |
| 2817 | final InputMethodInfo imi = enabledImes.get(imiIndex); |
| 2818 | final List<InputMethodSubtype> subtypes = getEnabledInputMethodSubtypeList( |
| 2819 | imi, true); |
| 2820 | final int subtypeCount = subtypes.size(); |
| 2821 | for (int subtypeIndex = 0; subtypeIndex < subtypeCount; ++subtypeIndex) { |
| 2822 | final InputMethodSubtype subtype = imi.getSubtypeAt(subtypeIndex); |
| 2823 | if (SUBTYPE_MODE_VOICE.equals(subtype.getMode())) { |
| 2824 | return Collections.singletonMap(imi, Collections.singletonList(subtype)); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2825 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2826 | } |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2827 | } |
Yohei Yukawa | fefedc5 | 2018-12-24 19:43:17 -0800 | [diff] [blame] | 2828 | return Collections.emptyMap(); |
satok | 4e4569d | 2010-11-19 18:45:53 +0900 | [diff] [blame] | 2829 | } |
satok | f3db1af | 2010-11-23 13:34:33 +0900 | [diff] [blame] | 2830 | |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 2831 | /** |
Yohei Yukawa | b985e6e | 2018-09-05 17:07:52 -0700 | [diff] [blame] | 2832 | * This is kept due to {@link android.annotation.UnsupportedAppUsage}. |
| 2833 | * |
| 2834 | * <p>TODO(Bug 113914148): Check if we can remove this. We have accidentally exposed |
| 2835 | * WindowManagerInternal#getInputMethodWindowVisibleHeight to app developers and some of them |
| 2836 | * started relying on it.</p> |
| 2837 | * |
| 2838 | * @return Something that is not well-defined. |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 2839 | * @hide |
| 2840 | */ |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 2841 | @UnsupportedAppUsage |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 2842 | public int getInputMethodWindowVisibleHeight() { |
Yohei Yukawa | 83b7d72 | 2018-09-09 20:48:25 -0700 | [diff] [blame] | 2843 | try { |
| 2844 | return mService.getInputMethodWindowVisibleHeight(); |
| 2845 | } catch (RemoteException e) { |
| 2846 | throw e.rethrowFromSystemServer(); |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 2847 | } |
| 2848 | } |
| 2849 | |
| 2850 | /** |
Yohei Yukawa | b4f328a | 2019-05-02 08:41:27 -0700 | [diff] [blame] | 2851 | * An internal API for {@link android.app.ActivityView} to report where its embedded virtual |
| 2852 | * display is placed. |
| 2853 | * |
| 2854 | * @param childDisplayId Display ID of the embedded virtual display. |
| 2855 | * @param matrix {@link Matrix} to convert virtual display screen coordinates to |
| 2856 | * the host screen coordinates. {@code null} to clear the relationship. |
| 2857 | * @hide |
| 2858 | */ |
| 2859 | public void reportActivityView(int childDisplayId, @Nullable Matrix matrix) { |
| 2860 | try { |
| 2861 | final float[] matrixValues; |
| 2862 | if (matrix == null) { |
| 2863 | matrixValues = null; |
| 2864 | } else { |
| 2865 | matrixValues = new float[9]; |
| 2866 | matrix.getValues(matrixValues); |
| 2867 | } |
| 2868 | mService.reportActivityView(mClient, childDisplayId, matrixValues); |
| 2869 | } catch (RemoteException e) { |
| 2870 | throw e.rethrowFromSystemServer(); |
| 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | /** |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 2875 | * Force switch to the last used input method and subtype. If the last input method didn't have |
| 2876 | * any subtypes, the framework will simply switch to the last input method with no subtype |
| 2877 | * specified. |
| 2878 | * @param imeToken Supplies the identifying token given to an input method when it was started, |
| 2879 | * which allows it to perform this operation on itself. |
| 2880 | * @return true if the current input method and subtype was successfully switched to the last |
| 2881 | * used input method and subtype. |
Tarandeep Singh | 164cfba | 2018-02-28 14:17:43 -0800 | [diff] [blame] | 2882 | * @deprecated Use {@link InputMethodService#switchToPreviousInputMethod()} instead. This method |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2883 | * was intended for IME developers who should be accessing APIs through the service. APIs in |
| 2884 | * this class are intended for app developers interacting with the IME. |
satok | d4fce2b | 2011-04-11 12:07:13 +0900 | [diff] [blame] | 2885 | */ |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2886 | @Deprecated |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 2887 | public boolean switchToLastInputMethod(IBinder imeToken) { |
Yohei Yukawa | d746a7e | 2018-09-18 18:55:02 -0700 | [diff] [blame] | 2888 | return InputMethodPrivilegedOperationsRegistry.get(imeToken).switchToPreviousInputMethod(); |
satok | 735cf38 | 2010-11-11 20:40:09 +0900 | [diff] [blame] | 2889 | } |
| 2890 | |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2891 | /** |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2892 | * Force switch to the next input method and subtype. If there is no IME enabled except |
| 2893 | * current IME and subtype, do nothing. |
| 2894 | * @param imeToken Supplies the identifying token given to an input method when it was started, |
| 2895 | * which allows it to perform this operation on itself. |
| 2896 | * @param onlyCurrentIme if true, the framework will find the next subtype which |
| 2897 | * belongs to the current IME |
| 2898 | * @return true if the current input method and subtype was successfully switched to the next |
| 2899 | * input method and subtype. |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2900 | * @deprecated Use {@link InputMethodService#switchToNextInputMethod(boolean)} instead. This |
| 2901 | * method was intended for IME developers who should be accessing APIs through the service. |
| 2902 | * APIs in this class are intended for app developers interacting with the IME. |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2903 | */ |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2904 | @Deprecated |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2905 | public boolean switchToNextInputMethod(IBinder imeToken, boolean onlyCurrentIme) { |
Yohei Yukawa | d746a7e | 2018-09-18 18:55:02 -0700 | [diff] [blame] | 2906 | return InputMethodPrivilegedOperationsRegistry.get(imeToken) |
| 2907 | .switchToNextInputMethod(onlyCurrentIme); |
satok | 688bd47 | 2012-02-09 20:09:17 +0900 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | /** |
satok | 15ab6b0 | 2013-08-26 14:17:18 +0900 | [diff] [blame] | 2911 | * Returns true if the current IME needs to offer the users ways to switch to a next input |
| 2912 | * method (e.g. a globe key.). |
| 2913 | * When an IME sets supportsSwitchingToNextInputMethod and this method returns true, |
| 2914 | * the IME has to offer ways to to invoke {@link #switchToNextInputMethod} accordingly. |
| 2915 | * <p> Note that the system determines the most appropriate next input method |
| 2916 | * and subtype in order to provide the consistent user experience in switching |
| 2917 | * between IMEs and subtypes. |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 2918 | * @param imeToken Supplies the identifying token given to an input method when it was started, |
| 2919 | * which allows it to perform this operation on itself. |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2920 | * @deprecated Use {@link InputMethodService#shouldOfferSwitchingToNextInputMethod()} |
| 2921 | * instead. This method was intended for IME developers who should be accessing APIs through |
| 2922 | * the service. APIs in this class are intended for app developers interacting with the IME. |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 2923 | */ |
Tarandeep Singh | d8d03a8 | 2017-11-28 13:35:32 -0800 | [diff] [blame] | 2924 | @Deprecated |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 2925 | public boolean shouldOfferSwitchingToNextInputMethod(IBinder imeToken) { |
Yohei Yukawa | d746a7e | 2018-09-18 18:55:02 -0700 | [diff] [blame] | 2926 | return InputMethodPrivilegedOperationsRegistry.get(imeToken) |
| 2927 | .shouldOfferSwitchingToNextInputMethod(); |
Satoshi Kataoka | 2b10b52 | 2013-08-21 20:39:12 +0900 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | /** |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 2931 | * Set additional input method subtypes. Only a process which shares the same uid with the IME |
| 2932 | * can add additional input method subtypes to the IME. |
satok | 75917b6 | 2011-08-31 23:27:39 +0900 | [diff] [blame] | 2933 | * Please note that a subtype's status is stored in the system. |
| 2934 | * For example, enabled subtypes are remembered by the framework even after they are removed |
| 2935 | * by using this method. If you re-add the same subtypes again, |
| 2936 | * they will just get enabled. If you want to avoid such conflicts, for instance, you may |
| 2937 | * want to create a "different" new subtype even with the same locale and mode, |
| 2938 | * by changing its extra value. The different subtype won't get affected by the stored past |
| 2939 | * status. (You may want to take a look at {@link InputMethodSubtype#hashCode()} to refer |
| 2940 | * to the current implementation.) |
Yohei Yukawa | 70f5c48 | 2016-01-04 19:42:36 -0800 | [diff] [blame] | 2941 | * |
| 2942 | * <p>NOTE: If the same subtype exists in both the manifest XML file and additional subtypes |
| 2943 | * specified by {@code subtypes}, those multiple instances are automatically merged into one |
| 2944 | * instance.</p> |
| 2945 | * |
| 2946 | * <p>CAVEAT: In API Level 23 and prior, the system may do nothing if an empty |
| 2947 | * {@link InputMethodSubtype} is specified in {@code subtypes}, which prevents you from removing |
| 2948 | * the last one entry of additional subtypes. If your IME statically defines one or more |
| 2949 | * subtypes in the manifest XML file, you may be able to work around this limitation by |
| 2950 | * specifying one of those statically defined subtypes in {@code subtypes}.</p> |
| 2951 | * |
satok | 91e8812 | 2011-07-18 11:11:42 +0900 | [diff] [blame] | 2952 | * @param imiId Id of InputMethodInfo which additional input method subtypes will be added to. |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2953 | * @param subtypes subtypes will be added as additional subtypes of the current input method. |
Yohei Yukawa | 92c15b1 | 2019-01-22 13:26:45 -0800 | [diff] [blame] | 2954 | * @deprecated For IMEs that have already implemented features like customizable/downloadable |
| 2955 | * keyboard layouts/languages, please start migration to other approaches. One idea |
| 2956 | * would be exposing only one unified {@link InputMethodSubtype} then implement |
| 2957 | * IME's own language switching mechanism within that unified subtype. The support |
| 2958 | * of "Additional Subtype" may be completely dropped in a future version of Android. |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2959 | */ |
Yohei Yukawa | 92c15b1 | 2019-01-22 13:26:45 -0800 | [diff] [blame] | 2960 | @Deprecated |
satok | ee5e77c | 2011-09-02 18:50:15 +0900 | [diff] [blame] | 2961 | public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) { |
Yohei Yukawa | 83b7d72 | 2018-09-09 20:48:25 -0700 | [diff] [blame] | 2962 | try { |
| 2963 | mService.setAdditionalInputMethodSubtypes(imiId, subtypes); |
| 2964 | } catch (RemoteException e) { |
| 2965 | throw e.rethrowFromSystemServer(); |
satok | e7c6998e | 2011-06-03 17:57:59 +0900 | [diff] [blame] | 2966 | } |
| 2967 | } |
| 2968 | |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 2969 | public InputMethodSubtype getLastInputMethodSubtype() { |
Yohei Yukawa | 83b7d72 | 2018-09-09 20:48:25 -0700 | [diff] [blame] | 2970 | try { |
| 2971 | return mService.getLastInputMethodSubtype(); |
| 2972 | } catch (RemoteException e) { |
| 2973 | throw e.rethrowFromSystemServer(); |
satok | 68f1b78 | 2011-04-11 14:26:04 +0900 | [diff] [blame] | 2974 | } |
| 2975 | } |
| 2976 | |
Tarandeep Singh | 2cbcd7f | 2019-01-25 11:47:57 -0800 | [diff] [blame] | 2977 | private void maybeCallServedViewChangedLocked(EditorInfo tba) { |
| 2978 | if (mImeInsetsConsumer != null) { |
| 2979 | mImeInsetsConsumer.onServedEditorChanged(tba); |
| 2980 | } |
| 2981 | } |
| 2982 | |
Charles Chen | 414820e | 2019-04-15 15:33:26 +0800 | [diff] [blame] | 2983 | /** |
| 2984 | * <p>This is used for CTS test only. Do not use this method outside of CTS package.<p/> |
| 2985 | * @return the ID of this display which this {@link InputMethodManager} resides |
| 2986 | * @hide |
| 2987 | */ |
| 2988 | @TestApi |
| 2989 | public int getDisplayId() { |
| 2990 | return mDisplayId; |
| 2991 | } |
| 2992 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2993 | void doDump(FileDescriptor fd, PrintWriter fout, String[] args) { |
| 2994 | final Printer p = new PrintWriterPrinter(fout); |
| 2995 | p.println("Input method client state for " + this + ":"); |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 2996 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2997 | p.println(" mService=" + mService); |
| 2998 | p.println(" mMainLooper=" + mMainLooper); |
| 2999 | p.println(" mIInputContext=" + mIInputContext); |
| 3000 | p.println(" mActive=" + mActive |
Yohei Yukawa | 2553e48 | 2017-12-15 15:47:33 -0800 | [diff] [blame] | 3001 | + " mRestartOnNextWindowFocus=" + mRestartOnNextWindowFocus |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3002 | + " mBindSequence=" + mBindSequence |
| 3003 | + " mCurId=" + mCurId); |
Yohei Yukawa | 2bc6617 | 2017-02-08 11:13:25 -0800 | [diff] [blame] | 3004 | p.println(" mFullscreenMode=" + mFullscreenMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3005 | p.println(" mCurMethod=" + mCurMethod); |
Wale Ogunwale | 159c3d8 | 2015-05-14 12:20:53 -0700 | [diff] [blame] | 3006 | p.println(" mCurRootView=" + mCurRootView); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3007 | p.println(" mServedView=" + mServedView); |
Dianne Hackborn | 7663d80 | 2012-02-24 13:08:49 -0800 | [diff] [blame] | 3008 | p.println(" mNextServedView=" + mNextServedView); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3009 | p.println(" mServedConnecting=" + mServedConnecting); |
| 3010 | if (mCurrentTextBoxAttribute != null) { |
| 3011 | p.println(" mCurrentTextBoxAttribute:"); |
| 3012 | mCurrentTextBoxAttribute.dump(p, " "); |
| 3013 | } else { |
| 3014 | p.println(" mCurrentTextBoxAttribute: null"); |
| 3015 | } |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame] | 3016 | p.println(" mServedInputConnectionWrapper=" + mServedInputConnectionWrapper); |
Andreas Gampe | e6748ce | 2015-12-11 18:00:38 -0800 | [diff] [blame] | 3017 | p.println(" mCompletions=" + Arrays.toString(mCompletions)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3018 | p.println(" mCursorRect=" + mCursorRect); |
| 3019 | p.println(" mCursorSelStart=" + mCursorSelStart |
| 3020 | + " mCursorSelEnd=" + mCursorSelEnd |
| 3021 | + " mCursorCandStart=" + mCursorCandStart |
| 3022 | + " mCursorCandEnd=" + mCursorCandEnd); |
| 3023 | } |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 3024 | |
| 3025 | /** |
| 3026 | * Callback that is invoked when an input event that was dispatched to |
| 3027 | * the IME has been finished. |
| 3028 | * @hide |
| 3029 | */ |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3030 | public interface FinishedInputEventCallback { |
| 3031 | public void onFinishedInputEvent(Object token, boolean handled); |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3034 | private final class ImeInputEventSender extends InputEventSender { |
| 3035 | public ImeInputEventSender(InputChannel inputChannel, Looper looper) { |
| 3036 | super(inputChannel, looper); |
| 3037 | } |
| 3038 | |
| 3039 | @Override |
| 3040 | public void onInputEventFinished(int seq, boolean handled) { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3041 | finishedInputEvent(seq, handled, false); |
Jeff Brown | c28867a | 2013-03-26 15:42:39 -0700 | [diff] [blame] | 3042 | } |
| 3043 | } |
| 3044 | |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3045 | private final class PendingEvent implements Runnable { |
| 3046 | public InputEvent mEvent; |
| 3047 | public Object mToken; |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 3048 | public String mInputMethodId; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 3049 | public FinishedInputEventCallback mCallback; |
| 3050 | public Handler mHandler; |
| 3051 | public boolean mHandled; |
| 3052 | |
| 3053 | public void recycle() { |
| 3054 | mEvent = null; |
| 3055 | mToken = null; |
| 3056 | mInputMethodId = null; |
| 3057 | mCallback = null; |
| 3058 | mHandler = null; |
| 3059 | mHandled = false; |
| 3060 | } |
| 3061 | |
| 3062 | @Override |
| 3063 | public void run() { |
| 3064 | mCallback.onFinishedInputEvent(mToken, mHandled); |
| 3065 | |
| 3066 | synchronized (mH) { |
| 3067 | recyclePendingEventLocked(this); |
| 3068 | } |
| 3069 | } |
Jeff Brown | 04ddf3c | 2012-06-14 03:57:49 -0700 | [diff] [blame] | 3070 | } |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 3071 | |
| 3072 | private static String dumpViewInfo(@Nullable final View view) { |
| 3073 | if (view == null) { |
| 3074 | return "null"; |
| 3075 | } |
| 3076 | final StringBuilder sb = new StringBuilder(); |
| 3077 | sb.append(view); |
| 3078 | sb.append(",focus=" + view.hasFocus()); |
| 3079 | sb.append(",windowFocus=" + view.hasWindowFocus()); |
Dake Gu | ddf6c1e | 2018-05-10 11:41:19 -0700 | [diff] [blame] | 3080 | sb.append(",autofillUiShowing=" + isAutofillUIShowing(view)); |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 3081 | sb.append(",window=" + view.getWindowToken()); |
Yohei Yukawa | 4052a10f | 2018-10-15 15:35:55 +0800 | [diff] [blame] | 3082 | sb.append(",displayId=" + view.getContext().getDisplayId()); |
Yohei Yukawa | a4ed0cf | 2016-03-29 19:06:36 -0700 | [diff] [blame] | 3083 | sb.append(",temporaryDetach=" + view.isTemporarilyDetached()); |
Yohei Yukawa | 5c1e675 | 2016-03-28 01:52:47 -0700 | [diff] [blame] | 3084 | return sb.toString(); |
| 3085 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3086 | } |