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