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