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