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