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