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