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