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