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