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