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