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