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