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