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