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