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