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