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