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