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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import com.android.internal.os.HandlerCaller; |
| 21 | import com.android.internal.view.IInputContext; |
| 22 | import com.android.internal.view.IInputMethod; |
| 23 | import com.android.internal.view.IInputMethodCallback; |
| 24 | import com.android.internal.view.IInputMethodClient; |
| 25 | import com.android.internal.view.IInputMethodManager; |
| 26 | import com.android.internal.view.IInputMethodSession; |
| 27 | import com.android.internal.view.InputBindResult; |
| 28 | |
Joe Onorato | 7a0f36b | 2010-06-07 10:24:36 -0700 | [diff] [blame] | 29 | import com.android.server.StatusBarManagerService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| 31 | import org.xmlpull.v1.XmlPullParserException; |
| 32 | |
| 33 | import android.app.ActivityManagerNative; |
| 34 | import android.app.AlertDialog; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 35 | import android.app.PendingIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.content.ComponentName; |
| 37 | import android.content.ContentResolver; |
| 38 | import android.content.Context; |
| 39 | import android.content.DialogInterface; |
| 40 | import android.content.IntentFilter; |
| 41 | import android.content.DialogInterface.OnCancelListener; |
| 42 | import android.content.Intent; |
| 43 | import android.content.ServiceConnection; |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 44 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
| 46 | import android.content.pm.ResolveInfo; |
| 47 | import android.content.pm.ServiceInfo; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 48 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.content.res.Resources; |
| 50 | import android.content.res.TypedArray; |
| 51 | import android.database.ContentObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | import android.os.Binder; |
| 53 | import android.os.Handler; |
| 54 | import android.os.IBinder; |
| 55 | import android.os.IInterface; |
| 56 | import android.os.Message; |
| 57 | import android.os.Parcel; |
| 58 | import android.os.RemoteException; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 59 | import android.os.ResultReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.os.ServiceManager; |
| 61 | import android.os.SystemClock; |
| 62 | import android.provider.Settings; |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 63 | import android.provider.Settings.Secure; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 64 | import android.provider.Settings.SettingNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | import android.text.TextUtils; |
| 66 | import android.util.EventLog; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 67 | import android.util.Pair; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 68 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import android.util.PrintWriterPrinter; |
| 70 | import android.util.Printer; |
| 71 | import android.view.IWindowManager; |
| 72 | import android.view.WindowManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 73 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.view.inputmethod.InputBinding; |
| 75 | import android.view.inputmethod.InputMethod; |
| 76 | import android.view.inputmethod.InputMethodInfo; |
| 77 | import android.view.inputmethod.InputMethodManager; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 78 | import android.view.inputmethod.InputMethodSubtype; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | |
| 80 | import java.io.FileDescriptor; |
| 81 | import java.io.IOException; |
| 82 | import java.io.PrintWriter; |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 83 | import java.text.Collator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | import java.util.ArrayList; |
| 85 | import java.util.HashMap; |
| 86 | import java.util.List; |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 87 | import java.util.Map; |
| 88 | import java.util.TreeMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * This class provides a system service that manages input methods. |
| 92 | */ |
| 93 | public class InputMethodManagerService extends IInputMethodManager.Stub |
| 94 | implements ServiceConnection, Handler.Callback { |
| 95 | static final boolean DEBUG = false; |
| 96 | static final String TAG = "InputManagerService"; |
| 97 | |
| 98 | static final int MSG_SHOW_IM_PICKER = 1; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 99 | static final int MSG_SHOW_IM_SUBTYPE_PICKER = 2; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | static final int MSG_UNBIND_INPUT = 1000; |
| 102 | static final int MSG_BIND_INPUT = 1010; |
| 103 | static final int MSG_SHOW_SOFT_INPUT = 1020; |
| 104 | static final int MSG_HIDE_SOFT_INPUT = 1030; |
| 105 | static final int MSG_ATTACH_TOKEN = 1040; |
| 106 | static final int MSG_CREATE_SESSION = 1050; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 107 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | static final int MSG_START_INPUT = 2000; |
| 109 | static final int MSG_RESTART_INPUT = 2010; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 110 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | static final int MSG_UNBIND_METHOD = 3000; |
| 112 | static final int MSG_BIND_METHOD = 3010; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | static final long TIME_TO_RECONNECT = 10*1000; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 115 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 116 | private static final int NOT_A_SUBTYPE_ID = -1; |
| 117 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | final Context mContext; |
| 119 | final Handler mHandler; |
| 120 | final SettingsObserver mSettingsObserver; |
Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 121 | final StatusBarManagerService mStatusBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | final IWindowManager mIWindowManager; |
| 123 | final HandlerCaller mCaller; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | final InputBindResult mNoBinding = new InputBindResult(null, null, -1); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | // All known input methods. mMethodMap also serves as the global |
| 128 | // lock for this class. |
| 129 | final ArrayList<InputMethodInfo> mMethodList |
| 130 | = new ArrayList<InputMethodInfo>(); |
| 131 | final HashMap<String, InputMethodInfo> mMethodMap |
| 132 | = new HashMap<String, InputMethodInfo>(); |
| 133 | |
| 134 | final TextUtils.SimpleStringSplitter mStringColonSplitter |
| 135 | = new TextUtils.SimpleStringSplitter(':'); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 136 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | class SessionState { |
| 138 | final ClientState client; |
| 139 | final IInputMethod method; |
| 140 | final IInputMethodSession session; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 141 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | @Override |
| 143 | public String toString() { |
| 144 | return "SessionState{uid " + client.uid + " pid " + client.pid |
| 145 | + " method " + Integer.toHexString( |
| 146 | System.identityHashCode(method)) |
| 147 | + " session " + Integer.toHexString( |
| 148 | System.identityHashCode(session)) |
| 149 | + "}"; |
| 150 | } |
| 151 | |
| 152 | SessionState(ClientState _client, IInputMethod _method, |
| 153 | IInputMethodSession _session) { |
| 154 | client = _client; |
| 155 | method = _method; |
| 156 | session = _session; |
| 157 | } |
| 158 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | class ClientState { |
| 161 | final IInputMethodClient client; |
| 162 | final IInputContext inputContext; |
| 163 | final int uid; |
| 164 | final int pid; |
| 165 | final InputBinding binding; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | boolean sessionRequested; |
| 168 | SessionState curSession; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | @Override |
| 171 | public String toString() { |
| 172 | return "ClientState{" + Integer.toHexString( |
| 173 | System.identityHashCode(this)) + " uid " + uid |
| 174 | + " pid " + pid + "}"; |
| 175 | } |
| 176 | |
| 177 | ClientState(IInputMethodClient _client, IInputContext _inputContext, |
| 178 | int _uid, int _pid) { |
| 179 | client = _client; |
| 180 | inputContext = _inputContext; |
| 181 | uid = _uid; |
| 182 | pid = _pid; |
| 183 | binding = new InputBinding(null, inputContext.asBinder(), uid, pid); |
| 184 | } |
| 185 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 186 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | final HashMap<IBinder, ClientState> mClients |
| 188 | = new HashMap<IBinder, ClientState>(); |
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 | /** |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 191 | * Set once the system is ready to run third party code. |
| 192 | */ |
| 193 | boolean mSystemReady; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 194 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 195 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | * Id of the currently selected input method. |
| 197 | */ |
| 198 | String mCurMethodId; |
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 | /** |
| 201 | * The current binding sequence number, incremented every time there is |
| 202 | * a new bind performed. |
| 203 | */ |
| 204 | int mCurSeq; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 205 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | /** |
| 207 | * The client that is currently bound to an input method. |
| 208 | */ |
| 209 | ClientState mCurClient; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 212 | * The last window token that gained focus. |
| 213 | */ |
| 214 | IBinder mCurFocusedWindow; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 215 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 216 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | * The input context last provided by the current client. |
| 218 | */ |
| 219 | IInputContext mCurInputContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 220 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | /** |
| 222 | * The attributes last provided by the current client. |
| 223 | */ |
| 224 | EditorInfo mCurAttribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 225 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | /** |
| 227 | * The input method ID of the input method service that we are currently |
| 228 | * connected to or in the process of connecting to. |
| 229 | */ |
| 230 | String mCurId; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | /** |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 233 | * The current subtype of the current input method. |
| 234 | */ |
| 235 | private InputMethodSubtype mCurrentSubtype; |
| 236 | |
| 237 | |
| 238 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | * Set to true if our ServiceConnection is currently actively bound to |
| 240 | * a service (whether or not we have gotten its IBinder back yet). |
| 241 | */ |
| 242 | boolean mHaveConnection; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 243 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | /** |
| 245 | * Set if the client has asked for the input method to be shown. |
| 246 | */ |
| 247 | boolean mShowRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 248 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | /** |
| 250 | * Set if we were explicitly told to show the input method. |
| 251 | */ |
| 252 | boolean mShowExplicitlyRequested; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 253 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | /** |
| 255 | * Set if we were forced to be shown. |
| 256 | */ |
| 257 | boolean mShowForced; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 258 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | /** |
| 260 | * Set if we last told the input method to show itself. |
| 261 | */ |
| 262 | boolean mInputShown; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 263 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | /** |
| 265 | * The Intent used to connect to the current input method. |
| 266 | */ |
| 267 | Intent mCurIntent; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | /** |
| 270 | * The token we have made for the currently active input method, to |
| 271 | * identify it in the future. |
| 272 | */ |
| 273 | IBinder mCurToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | /** |
| 276 | * If non-null, this is the input method service we are currently connected |
| 277 | * to. |
| 278 | */ |
| 279 | IInputMethod mCurMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | /** |
| 282 | * Time that we last initiated a bind to the input method, to determine |
| 283 | * if we should try to disconnect and reconnect to it. |
| 284 | */ |
| 285 | long mLastBindTime; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 286 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | /** |
| 288 | * Have we called mCurMethod.bindInput()? |
| 289 | */ |
| 290 | boolean mBoundToMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 291 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | /** |
| 293 | * Currently enabled session. Only touched by service thread, not |
| 294 | * protected by a lock. |
| 295 | */ |
| 296 | SessionState mEnabledSession; |
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 | * True if the screen is on. The value is true initially. |
| 300 | */ |
| 301 | boolean mScreenOn = true; |
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 | AlertDialog.Builder mDialogBuilder; |
| 304 | AlertDialog mSwitchingDialog; |
| 305 | InputMethodInfo[] mIms; |
| 306 | CharSequence[] mItems; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 307 | int[] mSubtypeIds; |
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 | class SettingsObserver extends ContentObserver { |
| 310 | SettingsObserver(Handler handler) { |
| 311 | super(handler); |
| 312 | ContentResolver resolver = mContext.getContentResolver(); |
| 313 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 314 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 315 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 316 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 318 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | @Override public void onChange(boolean selfChange) { |
| 320 | synchronized (mMethodMap) { |
| 321 | updateFromSettingsLocked(); |
| 322 | } |
| 323 | } |
| 324 | } |
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 | class ScreenOnOffReceiver extends android.content.BroadcastReceiver { |
| 327 | @Override |
| 328 | public void onReceive(Context context, Intent intent) { |
| 329 | if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { |
| 330 | mScreenOn = true; |
| 331 | } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { |
| 332 | mScreenOn = false; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 333 | } else if (intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) { |
| 334 | hideInputMethodMenu(); |
| 335 | return; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 337 | Slog.w(TAG, "Unexpected intent " + intent); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | // Inform the current client of the change in active status |
| 341 | try { |
| 342 | if (mCurClient != null && mCurClient.client != null) { |
| 343 | mCurClient.client.setActive(mScreenOn); |
| 344 | } |
| 345 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 346 | 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] | 347 | + mCurClient.pid + " uid " + mCurClient.uid); |
| 348 | } |
| 349 | } |
| 350 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 351 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 352 | class MyPackageMonitor extends PackageMonitor { |
| 353 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 355 | 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] | 356 | synchronized (mMethodMap) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 357 | String curInputMethodId = Settings.Secure.getString(mContext |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| 359 | final int N = mMethodList.size(); |
| 360 | if (curInputMethodId != null) { |
| 361 | for (int i=0; i<N; i++) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 362 | InputMethodInfo imi = mMethodList.get(i); |
| 363 | if (imi.getId().equals(curInputMethodId)) { |
| 364 | for (String pkg : packages) { |
| 365 | if (imi.getPackageName().equals(pkg)) { |
| 366 | if (!doit) { |
| 367 | return true; |
| 368 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 369 | Settings.Secure.putString(mContext.getContentResolver(), |
| 370 | Settings.Secure.DEFAULT_INPUT_METHOD, ""); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 371 | resetSelectedInputMethodSubtype(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 372 | chooseNewDefaultIMELocked(); |
| 373 | return true; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | return false; |
| 381 | } |
| 382 | |
| 383 | @Override |
| 384 | public void onSomePackagesChanged() { |
| 385 | synchronized (mMethodMap) { |
| 386 | InputMethodInfo curIm = null; |
| 387 | String curInputMethodId = Settings.Secure.getString(mContext |
| 388 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| 389 | final int N = mMethodList.size(); |
| 390 | if (curInputMethodId != null) { |
| 391 | for (int i=0; i<N; i++) { |
| 392 | InputMethodInfo imi = mMethodList.get(i); |
| 393 | if (imi.getId().equals(curInputMethodId)) { |
| 394 | curIm = imi; |
| 395 | } |
| 396 | int change = isPackageDisappearing(imi.getPackageName()); |
| 397 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 398 | || change == PACKAGE_PERMANENT_CHANGE) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 399 | Slog.i(TAG, "Input method uninstalled, disabling: " |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 400 | + imi.getComponent()); |
| 401 | setInputMethodEnabledLocked(imi.getId(), false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 405 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 406 | buildInputMethodListLocked(mMethodList, mMethodMap); |
| 407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | boolean changed = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 409 | |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 410 | if (curIm != null) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 411 | int change = isPackageDisappearing(curIm.getPackageName()); |
| 412 | if (change == PACKAGE_TEMPORARY_CHANGE |
| 413 | || change == PACKAGE_PERMANENT_CHANGE) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 414 | ServiceInfo si = null; |
| 415 | try { |
| 416 | si = mContext.getPackageManager().getServiceInfo( |
| 417 | curIm.getComponent(), 0); |
| 418 | } catch (PackageManager.NameNotFoundException ex) { |
| 419 | } |
| 420 | if (si == null) { |
| 421 | // Uh oh, current input method is no longer around! |
| 422 | // Pick another one... |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 423 | Slog.i(TAG, "Current input method removed: " + curInputMethodId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 424 | if (!chooseNewDefaultIMELocked()) { |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 425 | changed = true; |
| 426 | curIm = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 427 | Slog.i(TAG, "Unsetting current input method"); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 428 | Settings.Secure.putString(mContext.getContentResolver(), |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 429 | Settings.Secure.DEFAULT_INPUT_METHOD, ""); |
| 430 | resetSelectedInputMethodSubtype(); |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 431 | } |
| 432 | } |
Suchi Amalapurapu | 08675a3 | 2010-01-28 09:57:30 -0800 | [diff] [blame] | 433 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 434 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 435 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 436 | if (curIm == null) { |
| 437 | // We currently don't have a default input method... is |
| 438 | // one now available? |
| 439 | changed = chooseNewDefaultIMELocked(); |
| 440 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 441 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 442 | if (changed) { |
| 443 | updateFromSettingsLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | } |
| 447 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 448 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | class MethodCallback extends IInputMethodCallback.Stub { |
| 450 | final IInputMethod mMethod; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | MethodCallback(IInputMethod method) { |
| 453 | mMethod = method; |
| 454 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | public void finishedEvent(int seq, boolean handled) throws RemoteException { |
| 457 | } |
| 458 | |
| 459 | public void sessionCreated(IInputMethodSession session) throws RemoteException { |
| 460 | onSessionCreated(mMethod, session); |
| 461 | } |
| 462 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 463 | |
Joe Onorato | 089de88 | 2010-04-12 08:18:45 -0700 | [diff] [blame] | 464 | public InputMethodManagerService(Context context, StatusBarManagerService statusBar) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | mContext = context; |
| 466 | mHandler = new Handler(this); |
| 467 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 468 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
| 469 | mCaller = new HandlerCaller(context, new HandlerCaller.Callback() { |
| 470 | public void executeMessage(Message msg) { |
| 471 | handleMessage(msg); |
| 472 | } |
| 473 | }); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 474 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 475 | (new MyPackageMonitor()).register(mContext, true); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 476 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | IntentFilter screenOnOffFilt = new IntentFilter(); |
| 478 | screenOnOffFilt.addAction(Intent.ACTION_SCREEN_ON); |
| 479 | screenOnOffFilt.addAction(Intent.ACTION_SCREEN_OFF); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 480 | screenOnOffFilt.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | mContext.registerReceiver(new ScreenOnOffReceiver(), screenOnOffFilt); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 482 | |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 483 | mStatusBar = statusBar; |
| 484 | statusBar.setIconVisibility("ime", false); |
| 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | buildInputMethodListLocked(mMethodList, mMethodMap); |
| 487 | |
| 488 | final String enabledStr = Settings.Secure.getString( |
| 489 | mContext.getContentResolver(), |
| 490 | Settings.Secure.ENABLED_INPUT_METHODS); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 491 | Slog.i(TAG, "Enabled input methods: " + enabledStr); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 492 | final String defaultIme = Settings.Secure.getString(mContext |
| 493 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
| 494 | if (enabledStr == null || TextUtils.isEmpty(defaultIme)) { |
| 495 | Slog.i(TAG, "Enabled input methods or default IME has not been set, enabling all"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | InputMethodInfo defIm = null; |
| 497 | StringBuilder sb = new StringBuilder(256); |
| 498 | final int N = mMethodList.size(); |
| 499 | for (int i=0; i<N; i++) { |
| 500 | InputMethodInfo imi = mMethodList.get(i); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 501 | Slog.i(TAG, "Adding: " + imi.getId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | if (i > 0) sb.append(':'); |
| 503 | sb.append(imi.getId()); |
| 504 | if (defIm == null && imi.getIsDefaultResourceId() != 0) { |
| 505 | try { |
| 506 | Resources res = mContext.createPackageContext( |
| 507 | imi.getPackageName(), 0).getResources(); |
| 508 | if (res.getBoolean(imi.getIsDefaultResourceId())) { |
| 509 | defIm = imi; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 510 | Slog.i(TAG, "Selected default: " + imi.getId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | } |
| 512 | } catch (PackageManager.NameNotFoundException ex) { |
| 513 | } catch (Resources.NotFoundException ex) { |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | if (defIm == null && N > 0) { |
| 518 | defIm = mMethodList.get(0); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 519 | Slog.i(TAG, "No default found, using " + defIm.getId()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | } |
| 521 | Settings.Secure.putString(mContext.getContentResolver(), |
| 522 | Settings.Secure.ENABLED_INPUT_METHODS, sb.toString()); |
| 523 | if (defIm != null) { |
| 524 | Settings.Secure.putString(mContext.getContentResolver(), |
| 525 | Settings.Secure.DEFAULT_INPUT_METHOD, defIm.getId()); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 526 | putSelectedInputMethodSubtype(defIm, NOT_A_SUBTYPE_ID); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | } |
| 528 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 529 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | mSettingsObserver = new SettingsObserver(mHandler); |
| 531 | updateFromSettingsLocked(); |
| 532 | } |
| 533 | |
| 534 | @Override |
| 535 | public boolean onTransact(int code, Parcel data, Parcel reply, int flags) |
| 536 | throws RemoteException { |
| 537 | try { |
| 538 | return super.onTransact(code, data, reply, flags); |
| 539 | } catch (RuntimeException e) { |
| 540 | // The input method manager only throws security exceptions, so let's |
| 541 | // log all others. |
| 542 | if (!(e instanceof SecurityException)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 543 | Slog.e(TAG, "Input Method Manager Crash", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | } |
| 545 | throw e; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | public void systemReady() { |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 550 | synchronized (mMethodMap) { |
| 551 | if (!mSystemReady) { |
| 552 | mSystemReady = true; |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 553 | try { |
| 554 | startInputInnerLocked(); |
| 555 | } catch (RuntimeException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 556 | Slog.w(TAG, "Unexpected exception", e); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 557 | } |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 558 | } |
| 559 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | public List<InputMethodInfo> getInputMethodList() { |
| 563 | synchronized (mMethodMap) { |
| 564 | return new ArrayList<InputMethodInfo>(mMethodList); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | public List<InputMethodInfo> getEnabledInputMethodList() { |
| 569 | synchronized (mMethodMap) { |
| 570 | return getEnabledInputMethodListLocked(); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | List<InputMethodInfo> getEnabledInputMethodListLocked() { |
| 575 | final ArrayList<InputMethodInfo> res = new ArrayList<InputMethodInfo>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 576 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | final String enabledStr = Settings.Secure.getString( |
| 578 | mContext.getContentResolver(), |
| 579 | Settings.Secure.ENABLED_INPUT_METHODS); |
| 580 | if (enabledStr != null) { |
| 581 | final TextUtils.SimpleStringSplitter splitter = mStringColonSplitter; |
| 582 | splitter.setString(enabledStr); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 583 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | while (splitter.hasNext()) { |
| 585 | InputMethodInfo info = mMethodMap.get(splitter.next()); |
| 586 | if (info != null) { |
| 587 | res.add(info); |
| 588 | } |
| 589 | } |
| 590 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 591 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 592 | return res; |
| 593 | } |
| 594 | |
| 595 | public void addClient(IInputMethodClient client, |
| 596 | IInputContext inputContext, int uid, int pid) { |
| 597 | synchronized (mMethodMap) { |
| 598 | mClients.put(client.asBinder(), new ClientState(client, |
| 599 | inputContext, uid, pid)); |
| 600 | } |
| 601 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 602 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | public void removeClient(IInputMethodClient client) { |
| 604 | synchronized (mMethodMap) { |
| 605 | mClients.remove(client.asBinder()); |
| 606 | } |
| 607 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 608 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | void executeOrSendMessage(IInterface target, Message msg) { |
| 610 | if (target.asBinder() instanceof Binder) { |
| 611 | mCaller.sendMessage(msg); |
| 612 | } else { |
| 613 | handleMessage(msg); |
| 614 | msg.recycle(); |
| 615 | } |
| 616 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 617 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 618 | void unbindCurrentClientLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | if (mCurClient != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 620 | if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | + mCurClient.client.asBinder()); |
| 622 | if (mBoundToMethod) { |
| 623 | mBoundToMethod = false; |
| 624 | if (mCurMethod != null) { |
| 625 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( |
| 626 | MSG_UNBIND_INPUT, mCurMethod)); |
| 627 | } |
| 628 | } |
| 629 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 630 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 631 | mCurClient.sessionRequested = false; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 632 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | // Call setActive(false) on the old client |
| 634 | try { |
| 635 | mCurClient.client.setActive(false); |
| 636 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 637 | 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] | 638 | + mCurClient.pid + " uid " + mCurClient.uid); |
| 639 | } |
| 640 | mCurClient = null; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 641 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 642 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 643 | } |
| 644 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 645 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 646 | private int getImeShowFlags() { |
| 647 | int flags = 0; |
| 648 | if (mShowForced) { |
| 649 | flags |= InputMethod.SHOW_FORCED |
| 650 | | InputMethod.SHOW_EXPLICIT; |
| 651 | } else if (mShowExplicitlyRequested) { |
| 652 | flags |= InputMethod.SHOW_EXPLICIT; |
| 653 | } |
| 654 | return flags; |
| 655 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 656 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | private int getAppShowFlags() { |
| 658 | int flags = 0; |
| 659 | if (mShowForced) { |
| 660 | flags |= InputMethodManager.SHOW_FORCED; |
| 661 | } else if (!mShowExplicitlyRequested) { |
| 662 | flags |= InputMethodManager.SHOW_IMPLICIT; |
| 663 | } |
| 664 | return flags; |
| 665 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 666 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | InputBindResult attachNewInputLocked(boolean initial, boolean needResult) { |
| 668 | if (!mBoundToMethod) { |
| 669 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 670 | MSG_BIND_INPUT, mCurMethod, mCurClient.binding)); |
| 671 | mBoundToMethod = true; |
| 672 | } |
| 673 | final SessionState session = mCurClient.curSession; |
| 674 | if (initial) { |
| 675 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 676 | MSG_START_INPUT, session, mCurInputContext, mCurAttribute)); |
| 677 | } else { |
| 678 | executeOrSendMessage(session.method, mCaller.obtainMessageOOO( |
| 679 | MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute)); |
| 680 | } |
| 681 | if (mShowRequested) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 682 | 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] | 683 | showCurrentInputLocked(getAppShowFlags(), null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 684 | } |
| 685 | return needResult |
| 686 | ? new InputBindResult(session.session, mCurId, mCurSeq) |
| 687 | : null; |
| 688 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 689 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | InputBindResult startInputLocked(IInputMethodClient client, |
| 691 | IInputContext inputContext, EditorInfo attribute, |
| 692 | boolean initial, boolean needResult) { |
| 693 | // If no method is currently selected, do nothing. |
| 694 | if (mCurMethodId == null) { |
| 695 | return mNoBinding; |
| 696 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 697 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 698 | ClientState cs = mClients.get(client.asBinder()); |
| 699 | if (cs == null) { |
| 700 | throw new IllegalArgumentException("unknown client " |
| 701 | + client.asBinder()); |
| 702 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 703 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 704 | try { |
| 705 | if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) { |
| 706 | // Check with the window manager to make sure this client actually |
| 707 | // has a window with focus. If not, reject. This is thread safe |
| 708 | // because if the focus changes some time before or after, the |
| 709 | // next client receiving focus that has any interest in input will |
| 710 | // be calling through here after that change happens. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 711 | 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] | 712 | + " (uid=" + cs.uid + " pid=" + cs.pid + ")"); |
| 713 | return null; |
| 714 | } |
| 715 | } catch (RemoteException e) { |
| 716 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 717 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | if (mCurClient != cs) { |
| 719 | // If the client is changing, we need to switch over to the new |
| 720 | // one. |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 721 | unbindCurrentClientLocked(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 722 | if (DEBUG) Slog.v(TAG, "switching to client: client = " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 723 | + cs.client.asBinder()); |
| 724 | |
| 725 | // If the screen is on, inform the new client it is active |
| 726 | if (mScreenOn) { |
| 727 | try { |
| 728 | cs.client.setActive(mScreenOn); |
| 729 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 730 | 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] | 731 | + cs.pid + " uid " + cs.uid); |
| 732 | } |
| 733 | } |
| 734 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 735 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | // Bump up the sequence for this client and attach it. |
| 737 | mCurSeq++; |
| 738 | if (mCurSeq <= 0) mCurSeq = 1; |
| 739 | mCurClient = cs; |
| 740 | mCurInputContext = inputContext; |
| 741 | mCurAttribute = attribute; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 742 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | // Check if the input method is changing. |
| 744 | if (mCurId != null && mCurId.equals(mCurMethodId)) { |
| 745 | if (cs.curSession != null) { |
| 746 | // Fast case: if we are already connected to the input method, |
| 747 | // then just return it. |
| 748 | return attachNewInputLocked(initial, needResult); |
| 749 | } |
| 750 | if (mHaveConnection) { |
| 751 | if (mCurMethod != null) { |
| 752 | if (!cs.sessionRequested) { |
| 753 | cs.sessionRequested = true; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 754 | 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] | 755 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 756 | MSG_CREATE_SESSION, mCurMethod, |
| 757 | new MethodCallback(mCurMethod))); |
| 758 | } |
| 759 | // Return to client, and we will get back with it when |
| 760 | // we have had a session made for it. |
| 761 | return new InputBindResult(null, mCurId, mCurSeq); |
| 762 | } else if (SystemClock.uptimeMillis() |
| 763 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 764 | // In this case we have connected to the service, but |
| 765 | // don't yet have its interface. If it hasn't been too |
| 766 | // long since we did the connection, we'll return to |
| 767 | // the client and wait to get the service interface so |
| 768 | // we can report back. If it has been too long, we want |
| 769 | // to fall through so we can try a disconnect/reconnect |
| 770 | // to see if we can get back in touch with the service. |
| 771 | return new InputBindResult(null, mCurId, mCurSeq); |
| 772 | } else { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 773 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, |
| 774 | mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | } |
| 776 | } |
| 777 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 778 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 779 | return startInputInnerLocked(); |
| 780 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 781 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 782 | InputBindResult startInputInnerLocked() { |
| 783 | if (mCurMethodId == null) { |
| 784 | return mNoBinding; |
| 785 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 786 | |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 787 | if (!mSystemReady) { |
| 788 | // If the system is not yet ready, we shouldn't be running third |
| 789 | // party code. |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 790 | return new InputBindResult(null, mCurMethodId, mCurSeq); |
Dianne Hackborn | a34f1ad | 2009-09-02 13:26:28 -0700 | [diff] [blame] | 791 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 792 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 793 | InputMethodInfo info = mMethodMap.get(mCurMethodId); |
| 794 | if (info == null) { |
| 795 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 796 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 797 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 798 | unbindCurrentMethodLocked(false); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 799 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE); |
| 801 | mCurIntent.setComponent(info.getComponent()); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 802 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 803 | com.android.internal.R.string.input_method_binding_label); |
| 804 | mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
| 805 | 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] | 806 | if (mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE)) { |
| 807 | mLastBindTime = SystemClock.uptimeMillis(); |
| 808 | mHaveConnection = true; |
| 809 | mCurId = info.getId(); |
| 810 | mCurToken = new Binder(); |
| 811 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 812 | if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | mIWindowManager.addWindowToken(mCurToken, |
| 814 | WindowManager.LayoutParams.TYPE_INPUT_METHOD); |
| 815 | } catch (RemoteException e) { |
| 816 | } |
| 817 | return new InputBindResult(null, mCurId, mCurSeq); |
| 818 | } else { |
| 819 | mCurIntent = null; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 820 | Slog.w(TAG, "Failure connecting to input method service: " |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | + mCurIntent); |
| 822 | } |
| 823 | return null; |
| 824 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 825 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | public InputBindResult startInput(IInputMethodClient client, |
| 827 | IInputContext inputContext, EditorInfo attribute, |
| 828 | boolean initial, boolean needResult) { |
| 829 | synchronized (mMethodMap) { |
| 830 | final long ident = Binder.clearCallingIdentity(); |
| 831 | try { |
| 832 | return startInputLocked(client, inputContext, attribute, |
| 833 | initial, needResult); |
| 834 | } finally { |
| 835 | Binder.restoreCallingIdentity(ident); |
| 836 | } |
| 837 | } |
| 838 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 839 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 840 | public void finishInput(IInputMethodClient client) { |
| 841 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 842 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 843 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 844 | synchronized (mMethodMap) { |
| 845 | if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { |
| 846 | mCurMethod = IInputMethod.Stub.asInterface(service); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 847 | if (mCurToken == null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 848 | Slog.w(TAG, "Service connected without a token!"); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 849 | unbindCurrentMethodLocked(false); |
| 850 | return; |
| 851 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 852 | if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 853 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 854 | MSG_ATTACH_TOKEN, mCurMethod, mCurToken)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | if (mCurClient != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 856 | if (DEBUG) Slog.v(TAG, "Creating first session while with client " |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 857 | + mCurClient); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 859 | MSG_CREATE_SESSION, mCurMethod, |
| 860 | new MethodCallback(mCurMethod))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | void onSessionCreated(IInputMethod method, IInputMethodSession session) { |
| 867 | synchronized (mMethodMap) { |
| 868 | if (mCurMethod != null && method != null |
| 869 | && mCurMethod.asBinder() == method.asBinder()) { |
| 870 | if (mCurClient != null) { |
| 871 | mCurClient.curSession = new SessionState(mCurClient, |
| 872 | method, session); |
| 873 | mCurClient.sessionRequested = false; |
| 874 | InputBindResult res = attachNewInputLocked(true, true); |
| 875 | if (res.method != null) { |
| 876 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( |
| 877 | MSG_BIND_METHOD, mCurClient.client, res)); |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | } |
| 882 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 883 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 884 | void unbindCurrentMethodLocked(boolean reportToClient) { |
| 885 | if (mHaveConnection) { |
| 886 | mContext.unbindService(this); |
| 887 | mHaveConnection = false; |
| 888 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 889 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 890 | if (mCurToken != null) { |
| 891 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 892 | if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 893 | mIWindowManager.removeWindowToken(mCurToken); |
| 894 | } catch (RemoteException e) { |
| 895 | } |
| 896 | mCurToken = null; |
| 897 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 898 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 899 | mCurId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 900 | clearCurMethodLocked(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 901 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 902 | if (reportToClient && mCurClient != null) { |
| 903 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 904 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 905 | } |
| 906 | } |
| 907 | |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 908 | private void finishSession(SessionState sessionState) { |
| 909 | if (sessionState != null && sessionState.session != null) { |
| 910 | try { |
| 911 | sessionState.session.finishSession(); |
| 912 | } catch (RemoteException e) { |
Jean-Baptiste Queru | 9d0f6df | 2010-03-29 12:55:09 -0700 | [diff] [blame] | 913 | Slog.w(TAG, "Session failed to close due to remote exception", e); |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 917 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 918 | void clearCurMethodLocked() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | if (mCurMethod != null) { |
| 920 | for (ClientState cs : mClients.values()) { |
| 921 | cs.sessionRequested = false; |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 922 | finishSession(cs.curSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | cs.curSession = null; |
| 924 | } |
Devin Taylor | 0c33ed2 | 2010-02-23 13:26:46 -0600 | [diff] [blame] | 925 | |
| 926 | finishSession(mEnabledSession); |
| 927 | mEnabledSession = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | mCurMethod = null; |
| 929 | } |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 930 | mStatusBar.setIconVisibility("ime", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 932 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | public void onServiceDisconnected(ComponentName name) { |
| 934 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 935 | if (DEBUG) Slog.v(TAG, "Service disconnected: " + name |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | + " mCurIntent=" + mCurIntent); |
| 937 | if (mCurMethod != null && mCurIntent != null |
| 938 | && name.equals(mCurIntent.getComponent())) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 939 | clearCurMethodLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | // We consider this to be a new bind attempt, since the system |
| 941 | // should now try to restart the service for us. |
| 942 | mLastBindTime = SystemClock.uptimeMillis(); |
| 943 | mShowRequested = mInputShown; |
| 944 | mInputShown = false; |
| 945 | if (mCurClient != null) { |
| 946 | executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO( |
| 947 | MSG_UNBIND_METHOD, mCurSeq, mCurClient.client)); |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | public void updateStatusIcon(IBinder token, String packageName, int iconId) { |
| 954 | long ident = Binder.clearCallingIdentity(); |
| 955 | try { |
| 956 | if (token == null || mCurToken != token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 957 | Slog.w(TAG, "Ignoring setInputMethod of token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 958 | return; |
| 959 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | synchronized (mMethodMap) { |
| 962 | if (iconId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 963 | 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] | 964 | mStatusBar.setIconVisibility("ime", false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | } else if (packageName != null) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 966 | 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] | 967 | mStatusBar.setIcon("ime", packageName, iconId, 0); |
| 968 | mStatusBar.setIconVisibility("ime", true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | } finally { |
| 972 | Binder.restoreCallingIdentity(ident); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | void updateFromSettingsLocked() { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 977 | // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and |
| 978 | // ENABLED_INPUT_METHODS is taking care of keeping them correctly in |
| 979 | // sync, so we will never have a DEFAULT_INPUT_METHOD that is not |
| 980 | // enabled. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | String id = Settings.Secure.getString(mContext.getContentResolver(), |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 982 | Settings.Secure.DEFAULT_INPUT_METHOD); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 983 | if (id != null && id.length() > 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 984 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 985 | setInputMethodLocked(id, getSelectedInputMethodSubtypeId(id)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 986 | } catch (IllegalArgumentException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 987 | 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] | 988 | mCurMethodId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 989 | unbindCurrentMethodLocked(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 990 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 991 | } else { |
| 992 | // 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] | 993 | mCurMethodId = null; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 994 | unbindCurrentMethodLocked(true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 995 | } |
| 996 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 997 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 998 | /* package */ void setInputMethodLocked(String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 999 | InputMethodInfo info = mMethodMap.get(id); |
| 1000 | if (info == null) { |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1001 | throw new IllegalArgumentException("Unknown id: " + id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1002 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1003 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | if (id.equals(mCurMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1005 | if (subtypeId != NOT_A_SUBTYPE_ID) { |
| 1006 | InputMethodSubtype subtype = info.getSubtypes().get(subtypeId); |
| 1007 | if (subtype != mCurrentSubtype) { |
| 1008 | synchronized (mMethodMap) { |
| 1009 | if (mCurMethod != null) { |
| 1010 | try { |
| 1011 | putSelectedInputMethodSubtype(info, subtypeId); |
| 1012 | mCurMethod.changeInputMethodSubtype(subtype); |
| 1013 | } catch (RemoteException e) { |
| 1014 | return; |
| 1015 | } |
| 1016 | } |
| 1017 | } |
| 1018 | } |
| 1019 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1020 | return; |
| 1021 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1022 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1023 | final long ident = Binder.clearCallingIdentity(); |
| 1024 | try { |
| 1025 | mCurMethodId = id; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1026 | // Set a subtype to this input method. |
| 1027 | // subtypeId the name of a subtype which will be set. |
| 1028 | if (putSelectedInputMethodSubtype(info, subtypeId)) { |
| 1029 | mCurrentSubtype = info.getSubtypes().get(subtypeId); |
| 1030 | } else { |
| 1031 | mCurrentSubtype = null; |
| 1032 | } |
| 1033 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | Settings.Secure.putString(mContext.getContentResolver(), |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1035 | Settings.Secure.DEFAULT_INPUT_METHOD, id); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1036 | |
| 1037 | if (ActivityManagerNative.isSystemReady()) { |
| 1038 | Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED); |
Dianne Hackborn | 1c633fc | 2009-12-08 19:45:14 -0800 | [diff] [blame] | 1039 | intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | intent.putExtra("input_method_id", id); |
| 1041 | mContext.sendBroadcast(intent); |
| 1042 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1043 | unbindCurrentClientLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | } finally { |
| 1045 | Binder.restoreCallingIdentity(ident); |
| 1046 | } |
| 1047 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1048 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1049 | public boolean showSoftInput(IInputMethodClient client, int flags, |
| 1050 | ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1051 | long ident = Binder.clearCallingIdentity(); |
| 1052 | try { |
| 1053 | synchronized (mMethodMap) { |
| 1054 | if (mCurClient == null || client == null |
| 1055 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1056 | try { |
| 1057 | // We need to check if this is the current client with |
| 1058 | // focus in the window manager, to allow this call to |
| 1059 | // be made before input is started in it. |
| 1060 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1061 | Slog.w(TAG, "Ignoring showSoftInput of: " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1062 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | } |
| 1064 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1065 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | } |
| 1067 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1068 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1069 | 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] | 1070 | return showCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1071 | } |
| 1072 | } finally { |
| 1073 | Binder.restoreCallingIdentity(ident); |
| 1074 | } |
| 1075 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1076 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1077 | boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | mShowRequested = true; |
| 1079 | if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) { |
| 1080 | mShowExplicitlyRequested = true; |
| 1081 | } |
| 1082 | if ((flags&InputMethodManager.SHOW_FORCED) != 0) { |
| 1083 | mShowExplicitlyRequested = true; |
| 1084 | mShowForced = true; |
| 1085 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1086 | |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1087 | if (!mSystemReady) { |
| 1088 | return false; |
| 1089 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1090 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1091 | boolean res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1092 | if (mCurMethod != null) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1093 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO( |
| 1094 | MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod, |
| 1095 | resultReceiver)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1096 | mInputShown = true; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1097 | res = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | } else if (mHaveConnection && SystemClock.uptimeMillis() |
| 1099 | < (mLastBindTime+TIME_TO_RECONNECT)) { |
| 1100 | // The client has asked to have the input method shown, but |
| 1101 | // we have been sitting here too long with a connection to the |
| 1102 | // service and no interface received, so let's disconnect/connect |
| 1103 | // to try to prod things along. |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1104 | EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | SystemClock.uptimeMillis()-mLastBindTime,1); |
| 1106 | mContext.unbindService(this); |
| 1107 | mContext.bindService(mCurIntent, this, Context.BIND_AUTO_CREATE); |
| 1108 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1109 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1110 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1112 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1113 | public boolean hideSoftInput(IInputMethodClient client, int flags, |
| 1114 | ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | long ident = Binder.clearCallingIdentity(); |
| 1116 | try { |
| 1117 | synchronized (mMethodMap) { |
| 1118 | if (mCurClient == null || client == null |
| 1119 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1120 | try { |
| 1121 | // We need to check if this is the current client with |
| 1122 | // focus in the window manager, to allow this call to |
| 1123 | // be made before input is started in it. |
| 1124 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1125 | Slog.w(TAG, "Ignoring hideSoftInput of: " + client); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1126 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1127 | } |
| 1128 | } catch (RemoteException e) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1129 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | } |
| 1131 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1132 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1133 | 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] | 1134 | return hideCurrentInputLocked(flags, resultReceiver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | } |
| 1136 | } finally { |
| 1137 | Binder.restoreCallingIdentity(ident); |
| 1138 | } |
| 1139 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1140 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1141 | boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0 |
| 1143 | && (mShowExplicitlyRequested || mShowForced)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1144 | if (DEBUG) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | "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] | 1146 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | } |
| 1148 | if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1149 | if (DEBUG) Slog.v(TAG, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | "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] | 1151 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1152 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1153 | boolean res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | if (mInputShown && mCurMethod != null) { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1155 | executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO( |
| 1156 | MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver)); |
| 1157 | res = true; |
| 1158 | } else { |
| 1159 | res = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | } |
| 1161 | mInputShown = false; |
| 1162 | mShowRequested = false; |
| 1163 | mShowExplicitlyRequested = false; |
| 1164 | mShowForced = false; |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1165 | return res; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1167 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1168 | public void windowGainedFocus(IInputMethodClient client, IBinder windowToken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1169 | boolean viewHasFocus, boolean isTextEditor, int softInputMode, |
| 1170 | boolean first, int windowFlags) { |
| 1171 | long ident = Binder.clearCallingIdentity(); |
| 1172 | try { |
| 1173 | synchronized (mMethodMap) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1174 | if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | + " viewHasFocus=" + viewHasFocus |
| 1176 | + " isTextEditor=" + isTextEditor |
| 1177 | + " softInputMode=#" + Integer.toHexString(softInputMode) |
| 1178 | + " first=" + first + " flags=#" |
| 1179 | + Integer.toHexString(windowFlags)); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | if (mCurClient == null || client == null |
| 1182 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1183 | try { |
| 1184 | // We need to check if this is the current client with |
| 1185 | // focus in the window manager, to allow this call to |
| 1186 | // be made before input is started in it. |
| 1187 | if (!mIWindowManager.inputMethodClientHasFocus(client)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1188 | 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] | 1189 | return; |
| 1190 | } |
| 1191 | } catch (RemoteException e) { |
| 1192 | } |
| 1193 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1194 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1195 | if (mCurFocusedWindow == windowToken) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1196 | 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] | 1197 | return; |
| 1198 | } |
| 1199 | mCurFocusedWindow = windowToken; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1200 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) { |
| 1202 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED: |
| 1203 | if (!isTextEditor || (softInputMode & |
| 1204 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 1205 | != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) { |
| 1206 | if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) { |
| 1207 | // There is no focus view, and this window will |
| 1208 | // be behind any soft input window, so hide the |
| 1209 | // soft input window if it is shown. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1210 | 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] | 1211 | hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | } |
| 1213 | } else if (isTextEditor && (softInputMode & |
| 1214 | WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST) |
| 1215 | == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
| 1216 | && (softInputMode & |
| 1217 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
| 1218 | // There is a focus view, and we are navigating forward |
| 1219 | // into the window, so show the input window for the user. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1220 | 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] | 1221 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | } |
| 1223 | break; |
| 1224 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED: |
| 1225 | // Do nothing. |
| 1226 | break; |
| 1227 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN: |
| 1228 | if ((softInputMode & |
| 1229 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1230 | 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] | 1231 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | } |
| 1233 | break; |
| 1234 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1235 | 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] | 1236 | hideCurrentInputLocked(0, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1237 | break; |
| 1238 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE: |
| 1239 | if ((softInputMode & |
| 1240 | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1241 | 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] | 1242 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | } |
| 1244 | break; |
| 1245 | case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE: |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1246 | 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] | 1247 | showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1248 | break; |
| 1249 | } |
| 1250 | } |
| 1251 | } finally { |
| 1252 | Binder.restoreCallingIdentity(ident); |
| 1253 | } |
| 1254 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | public void showInputMethodPickerFromClient(IInputMethodClient client) { |
| 1257 | synchronized (mMethodMap) { |
| 1258 | if (mCurClient == null || client == null |
| 1259 | || mCurClient.client.asBinder() != client.asBinder()) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1260 | Slog.w(TAG, "Ignoring showInputMethodDialogFromClient of: " + client); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | mHandler.sendEmptyMessage(MSG_SHOW_IM_PICKER); |
| 1264 | } |
| 1265 | } |
| 1266 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1267 | public void showInputMethodSubtypePickerFromClient(IInputMethodClient client) { |
| 1268 | synchronized (mMethodMap) { |
| 1269 | if (mCurClient == null || client == null |
| 1270 | || mCurClient.client.asBinder() != client.asBinder()) { |
| 1271 | Slog.w(TAG, "Ignoring showInputSubtypeMethodDialogFromClient of: " + client); |
| 1272 | } |
| 1273 | |
| 1274 | mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER); |
| 1275 | } |
| 1276 | } |
| 1277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | public void setInputMethod(IBinder token, String id) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1279 | setInputMethodWithSubtype(token, id, NOT_A_SUBTYPE_ID); |
| 1280 | } |
| 1281 | |
| 1282 | private void setInputMethodWithSubtype(IBinder token, String id, int subtypeId) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | synchronized (mMethodMap) { |
| 1284 | if (token == null) { |
| 1285 | if (mContext.checkCallingOrSelfPermission( |
| 1286 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 1287 | != PackageManager.PERMISSION_GRANTED) { |
| 1288 | throw new SecurityException( |
| 1289 | "Using null token requires permission " |
| 1290 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 1291 | } |
| 1292 | } else if (mCurToken != token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1293 | Slog.w(TAG, "Ignoring setInputMethod of token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | return; |
| 1295 | } |
| 1296 | |
| 1297 | long ident = Binder.clearCallingIdentity(); |
| 1298 | try { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1299 | setInputMethodLocked(id, subtypeId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1300 | } finally { |
| 1301 | Binder.restoreCallingIdentity(ident); |
| 1302 | } |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | public void hideMySoftInput(IBinder token, int flags) { |
| 1307 | synchronized (mMethodMap) { |
| 1308 | if (token == null || mCurToken != token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1309 | Slog.w(TAG, "Ignoring hideInputMethod of token: " + token); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1310 | return; |
| 1311 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1312 | long ident = Binder.clearCallingIdentity(); |
| 1313 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1314 | hideCurrentInputLocked(flags, null); |
| 1315 | } finally { |
| 1316 | Binder.restoreCallingIdentity(ident); |
| 1317 | } |
| 1318 | } |
| 1319 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1320 | |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1321 | public void showMySoftInput(IBinder token, int flags) { |
| 1322 | synchronized (mMethodMap) { |
| 1323 | if (token == null || mCurToken != token) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1324 | Slog.w(TAG, "Ignoring hideInputMethod of token: " + token); |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1325 | return; |
| 1326 | } |
| 1327 | long ident = Binder.clearCallingIdentity(); |
| 1328 | try { |
| 1329 | showCurrentInputLocked(flags, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | } finally { |
| 1331 | Binder.restoreCallingIdentity(ident); |
| 1332 | } |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | void setEnabledSessionInMainThread(SessionState session) { |
| 1337 | if (mEnabledSession != session) { |
| 1338 | if (mEnabledSession != null) { |
| 1339 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1340 | if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1341 | mEnabledSession.method.setSessionEnabled( |
| 1342 | mEnabledSession.session, false); |
| 1343 | } catch (RemoteException e) { |
| 1344 | } |
| 1345 | } |
| 1346 | mEnabledSession = session; |
| 1347 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1348 | if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1349 | session.method.setSessionEnabled( |
| 1350 | session.session, true); |
| 1351 | } catch (RemoteException e) { |
| 1352 | } |
| 1353 | } |
| 1354 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1355 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1356 | public boolean handleMessage(Message msg) { |
| 1357 | HandlerCaller.SomeArgs args; |
| 1358 | switch (msg.what) { |
| 1359 | case MSG_SHOW_IM_PICKER: |
| 1360 | showInputMethodMenu(); |
| 1361 | return true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1362 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1363 | case MSG_SHOW_IM_SUBTYPE_PICKER: |
| 1364 | showInputMethodSubtypeMenu(); |
| 1365 | return true; |
| 1366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1367 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1369 | case MSG_UNBIND_INPUT: |
| 1370 | try { |
| 1371 | ((IInputMethod)msg.obj).unbindInput(); |
| 1372 | } catch (RemoteException e) { |
| 1373 | // There is nothing interesting about the method dying. |
| 1374 | } |
| 1375 | return true; |
| 1376 | case MSG_BIND_INPUT: |
| 1377 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1378 | try { |
| 1379 | ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2); |
| 1380 | } catch (RemoteException e) { |
| 1381 | } |
| 1382 | return true; |
| 1383 | case MSG_SHOW_SOFT_INPUT: |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1384 | args = (HandlerCaller.SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1386 | ((IInputMethod)args.arg1).showSoftInput(msg.arg1, |
| 1387 | (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1388 | } catch (RemoteException e) { |
| 1389 | } |
| 1390 | return true; |
| 1391 | case MSG_HIDE_SOFT_INPUT: |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1392 | args = (HandlerCaller.SomeArgs)msg.obj; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1393 | try { |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1394 | ((IInputMethod)args.arg1).hideSoftInput(0, |
| 1395 | (ResultReceiver)args.arg2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1396 | } catch (RemoteException e) { |
| 1397 | } |
| 1398 | return true; |
| 1399 | case MSG_ATTACH_TOKEN: |
| 1400 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1401 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1402 | 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] | 1403 | ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2); |
| 1404 | } catch (RemoteException e) { |
| 1405 | } |
| 1406 | return true; |
| 1407 | case MSG_CREATE_SESSION: |
| 1408 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1409 | try { |
| 1410 | ((IInputMethod)args.arg1).createSession( |
| 1411 | (IInputMethodCallback)args.arg2); |
| 1412 | } catch (RemoteException e) { |
| 1413 | } |
| 1414 | return true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1415 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1417 | case MSG_START_INPUT: |
| 1418 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1419 | try { |
| 1420 | SessionState session = (SessionState)args.arg1; |
| 1421 | setEnabledSessionInMainThread(session); |
| 1422 | session.method.startInput((IInputContext)args.arg2, |
| 1423 | (EditorInfo)args.arg3); |
| 1424 | } catch (RemoteException e) { |
| 1425 | } |
| 1426 | return true; |
| 1427 | case MSG_RESTART_INPUT: |
| 1428 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1429 | try { |
| 1430 | SessionState session = (SessionState)args.arg1; |
| 1431 | setEnabledSessionInMainThread(session); |
| 1432 | session.method.restartInput((IInputContext)args.arg2, |
| 1433 | (EditorInfo)args.arg3); |
| 1434 | } catch (RemoteException e) { |
| 1435 | } |
| 1436 | return true; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1437 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1438 | // --------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1439 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1440 | case MSG_UNBIND_METHOD: |
| 1441 | try { |
| 1442 | ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1); |
| 1443 | } catch (RemoteException e) { |
| 1444 | // There is nothing interesting about the last client dying. |
| 1445 | } |
| 1446 | return true; |
| 1447 | case MSG_BIND_METHOD: |
| 1448 | args = (HandlerCaller.SomeArgs)msg.obj; |
| 1449 | try { |
| 1450 | ((IInputMethodClient)args.arg1).onBindMethod( |
| 1451 | (InputBindResult)args.arg2); |
| 1452 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1453 | 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] | 1454 | } |
| 1455 | return true; |
| 1456 | } |
| 1457 | return false; |
| 1458 | } |
| 1459 | |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1460 | private boolean isSystemIme(InputMethodInfo inputMethod) { |
| 1461 | return (inputMethod.getServiceInfo().applicationInfo.flags |
| 1462 | & ApplicationInfo.FLAG_SYSTEM) != 0; |
| 1463 | } |
| 1464 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1465 | private boolean chooseNewDefaultIMELocked() { |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1466 | List<InputMethodInfo> enabled = getEnabledInputMethodListLocked(); |
| 1467 | if (enabled != null && enabled.size() > 0) { |
Dianne Hackborn | 83e48f5 | 2010-03-23 23:03:25 -0700 | [diff] [blame] | 1468 | // We'd prefer to fall back on a system IME, since that is safer. |
| 1469 | int i=enabled.size(); |
| 1470 | while (i > 0) { |
| 1471 | i--; |
| 1472 | if ((enabled.get(i).getServiceInfo().applicationInfo.flags |
| 1473 | & ApplicationInfo.FLAG_SYSTEM) != 0) { |
| 1474 | break; |
| 1475 | } |
| 1476 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1477 | InputMethodInfo imi = enabled.get(i); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1478 | Settings.Secure.putString(mContext.getContentResolver(), |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1479 | Settings.Secure.DEFAULT_INPUT_METHOD, imi.getId()); |
| 1480 | putSelectedInputMethodSubtype(imi, NOT_A_SUBTYPE_ID); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1481 | return true; |
| 1482 | } |
| 1483 | |
| 1484 | return false; |
| 1485 | } |
| 1486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1487 | void buildInputMethodListLocked(ArrayList<InputMethodInfo> list, |
| 1488 | HashMap<String, InputMethodInfo> map) { |
| 1489 | list.clear(); |
| 1490 | map.clear(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1491 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1492 | PackageManager pm = mContext.getPackageManager(); |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1493 | final Configuration config = mContext.getResources().getConfiguration(); |
| 1494 | final boolean haveHardKeyboard = config.keyboard == Configuration.KEYBOARD_QWERTY; |
| 1495 | String disabledSysImes = Settings.Secure.getString(mContext.getContentResolver(), |
| 1496 | Secure.DISABLED_SYSTEM_INPUT_METHODS); |
| 1497 | if (disabledSysImes == null) disabledSysImes = ""; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1498 | |
| 1499 | List<ResolveInfo> services = pm.queryIntentServices( |
| 1500 | new Intent(InputMethod.SERVICE_INTERFACE), |
| 1501 | PackageManager.GET_META_DATA); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1502 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | for (int i = 0; i < services.size(); ++i) { |
| 1504 | ResolveInfo ri = services.get(i); |
| 1505 | ServiceInfo si = ri.serviceInfo; |
| 1506 | ComponentName compName = new ComponentName(si.packageName, si.name); |
| 1507 | if (!android.Manifest.permission.BIND_INPUT_METHOD.equals( |
| 1508 | si.permission)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1509 | Slog.w(TAG, "Skipping input method " + compName |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1510 | + ": it does not require the permission " |
| 1511 | + android.Manifest.permission.BIND_INPUT_METHOD); |
| 1512 | continue; |
| 1513 | } |
| 1514 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1515 | if (DEBUG) Slog.d(TAG, "Checking " + compName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | |
| 1517 | try { |
| 1518 | InputMethodInfo p = new InputMethodInfo(mContext, ri); |
| 1519 | list.add(p); |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1520 | final String id = p.getId(); |
| 1521 | map.put(id, p); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | |
Amith Yamasani | e861ec1 | 2010-03-24 21:39:27 -0700 | [diff] [blame] | 1523 | // System IMEs are enabled by default, unless there's a hard keyboard |
| 1524 | // and the system IME was explicitly disabled |
| 1525 | if (isSystemIme(p) && (!haveHardKeyboard || disabledSysImes.indexOf(id) < 0)) { |
| 1526 | setInputMethodEnabledLocked(id, true); |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1529 | if (DEBUG) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1530 | 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] | 1531 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1532 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1533 | } catch (XmlPullParserException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1534 | 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] | 1535 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1536 | 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] | 1537 | } |
| 1538 | } |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1539 | |
| 1540 | String defaultIme = Settings.Secure.getString(mContext |
| 1541 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1542 | if (!TextUtils.isEmpty(defaultIme) && !map.containsKey(defaultIme)) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1543 | if (chooseNewDefaultIMELocked()) { |
Brandon Ballinger | 6da35a0 | 2009-10-21 00:38:13 -0700 | [diff] [blame] | 1544 | updateFromSettingsLocked(); |
| 1545 | } |
| 1546 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1548 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1549 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1550 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1551 | private void showInputMethodMenu() { |
| 1552 | showInputMethodMenuInternal(false); |
| 1553 | } |
| 1554 | |
| 1555 | private void showInputMethodSubtypeMenu() { |
| 1556 | showInputMethodMenuInternal(true); |
| 1557 | } |
| 1558 | |
| 1559 | private void showInputMethodMenuInternal(boolean showSubtypes) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1560 | if (DEBUG) Slog.v(TAG, "Show switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1561 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1562 | final Context context = mContext; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | final PackageManager pm = context.getPackageManager(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1565 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1566 | String lastInputMethodId = Settings.Secure.getString(context |
| 1567 | .getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1568 | int lastInputMethodSubtypeId = getSelectedInputMethodSubtypeId(lastInputMethodId); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1569 | if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1570 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | final List<InputMethodInfo> immis = getEnabledInputMethodList(); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1572 | ArrayList<Integer> subtypeIds = new ArrayList<Integer>(); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1573 | |
Dianne Hackborn | 97106ab | 2010-03-03 00:08:31 -0800 | [diff] [blame] | 1574 | if (immis == null) { |
| 1575 | return; |
| 1576 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1577 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1578 | synchronized (mMethodMap) { |
| 1579 | hideInputMethodMenuLocked(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1580 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1581 | int N = immis.size(); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1582 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1583 | final Map<CharSequence, Pair<InputMethodInfo, Integer>> imMap = |
| 1584 | new TreeMap<CharSequence, Pair<InputMethodInfo, Integer>>(Collator.getInstance()); |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1585 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1586 | for (int i = 0; i < N; ++i) { |
| 1587 | InputMethodInfo property = immis.get(i); |
| 1588 | if (property == null) { |
| 1589 | continue; |
| 1590 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1591 | // TODO: Show only enabled subtypes |
| 1592 | ArrayList<InputMethodSubtype> subtypes = property.getSubtypes(); |
| 1593 | CharSequence label = property.loadLabel(pm); |
| 1594 | if (showSubtypes && subtypes.size() > 0) { |
| 1595 | for (int j = 0; j < subtypes.size(); ++j) { |
| 1596 | InputMethodSubtype subtype = subtypes.get(j); |
| 1597 | CharSequence title; |
| 1598 | int nameResId = subtype.getNameResId(); |
| 1599 | int modeResId = subtype.getModeResId(); |
| 1600 | if (nameResId != 0) { |
| 1601 | title = pm.getText(property.getPackageName(), nameResId, |
| 1602 | property.getServiceInfo().applicationInfo); |
| 1603 | } else { |
| 1604 | CharSequence language = subtype.getLocale(); |
| 1605 | CharSequence mode = modeResId == 0 ? null |
| 1606 | : pm.getText(property.getPackageName(), modeResId, |
| 1607 | property.getServiceInfo().applicationInfo); |
| 1608 | // TODO: Use more friendly Title and UI |
| 1609 | title = label + "," + (mode == null ? "" : mode) + "," |
| 1610 | + (language == null ? "" : language); |
| 1611 | } |
| 1612 | imMap.put(title, new Pair<InputMethodInfo, Integer>(property, j)); |
| 1613 | } |
| 1614 | } else { |
| 1615 | imMap.put(label, |
| 1616 | new Pair<InputMethodInfo, Integer>(property, NOT_A_SUBTYPE_ID)); |
| 1617 | subtypeIds.add(0); |
| 1618 | } |
Dianne Hackborn | 97106ab | 2010-03-03 00:08:31 -0800 | [diff] [blame] | 1619 | } |
satok | 913a892 | 2010-08-26 21:53:41 +0900 | [diff] [blame] | 1620 | |
| 1621 | N = imMap.size(); |
| 1622 | mItems = imMap.keySet().toArray(new CharSequence[N]); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1623 | mIms = new InputMethodInfo[N]; |
| 1624 | mSubtypeIds = new int[N]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1625 | int checkedItem = 0; |
| 1626 | for (int i = 0; i < N; ++i) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1627 | Pair<InputMethodInfo, Integer> value = imMap.get(mItems[i]); |
| 1628 | mIms[i] = value.first; |
| 1629 | mSubtypeIds[i] = value.second; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1630 | if (mIms[i].getId().equals(lastInputMethodId)) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1631 | int subtypeId = mSubtypeIds[i]; |
| 1632 | if ((subtypeId == NOT_A_SUBTYPE_ID) |
| 1633 | || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) |
| 1634 | || (subtypeId == lastInputMethodSubtypeId)) { |
| 1635 | checkedItem = i; |
| 1636 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1637 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1638 | } |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1639 | |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1640 | AlertDialog.OnClickListener adocl = new AlertDialog.OnClickListener() { |
| 1641 | public void onClick(DialogInterface dialog, int which) { |
| 1642 | hideInputMethodMenu(); |
| 1643 | } |
| 1644 | }; |
| 1645 | |
| 1646 | TypedArray a = context.obtainStyledAttributes(null, |
| 1647 | com.android.internal.R.styleable.DialogPreference, |
| 1648 | com.android.internal.R.attr.alertDialogStyle, 0); |
| 1649 | mDialogBuilder = new AlertDialog.Builder(context) |
| 1650 | .setTitle(com.android.internal.R.string.select_input_method) |
| 1651 | .setOnCancelListener(new OnCancelListener() { |
| 1652 | public void onCancel(DialogInterface dialog) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1653 | hideInputMethodMenu(); |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1654 | } |
| 1655 | }) |
| 1656 | .setIcon(a.getDrawable( |
| 1657 | com.android.internal.R.styleable.DialogPreference_dialogTitle)); |
| 1658 | a.recycle(); |
| 1659 | |
| 1660 | mDialogBuilder.setSingleChoiceItems(mItems, checkedItem, |
| 1661 | new AlertDialog.OnClickListener() { |
| 1662 | public void onClick(DialogInterface dialog, int which) { |
| 1663 | synchronized (mMethodMap) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1664 | if (mIms == null || mIms.length <= which |
| 1665 | || mSubtypeIds == null || mSubtypeIds.length <= which) { |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1666 | return; |
| 1667 | } |
| 1668 | InputMethodInfo im = mIms[which]; |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1669 | int subtypeId = mSubtypeIds[which]; |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1670 | hideInputMethodMenu(); |
| 1671 | if (im != null) { |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1672 | if ((subtypeId < 0) |
| 1673 | || (subtypeId >= im.getSubtypes().size())) { |
| 1674 | subtypeId = NOT_A_SUBTYPE_ID; |
| 1675 | } |
| 1676 | setInputMethodLocked(im.getId(), subtypeId); |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1677 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 1678 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | } |
Dianne Hackborn | 8cf1bcd | 2010-03-16 13:06:10 -0700 | [diff] [blame] | 1680 | }); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1681 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1682 | mSwitchingDialog = mDialogBuilder.create(); |
| 1683 | mSwitchingDialog.getWindow().setType( |
| 1684 | WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG); |
| 1685 | mSwitchingDialog.show(); |
| 1686 | } |
| 1687 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1689 | void hideInputMethodMenu() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1690 | synchronized (mMethodMap) { |
| 1691 | hideInputMethodMenuLocked(); |
| 1692 | } |
| 1693 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1694 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1695 | void hideInputMethodMenuLocked() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1696 | if (DEBUG) Slog.v(TAG, "Hide switching menu"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1697 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1698 | if (mSwitchingDialog != null) { |
| 1699 | mSwitchingDialog.dismiss(); |
| 1700 | mSwitchingDialog = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1701 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1702 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1703 | mDialogBuilder = null; |
| 1704 | mItems = null; |
| 1705 | mIms = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1706 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1708 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1709 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1710 | public boolean setInputMethodEnabled(String id, boolean enabled) { |
| 1711 | synchronized (mMethodMap) { |
| 1712 | if (mContext.checkCallingOrSelfPermission( |
| 1713 | android.Manifest.permission.WRITE_SECURE_SETTINGS) |
| 1714 | != PackageManager.PERMISSION_GRANTED) { |
| 1715 | throw new SecurityException( |
| 1716 | "Requires permission " |
| 1717 | + android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 1718 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1719 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1720 | long ident = Binder.clearCallingIdentity(); |
| 1721 | try { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1722 | return setInputMethodEnabledLocked(id, enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | } finally { |
| 1724 | Binder.restoreCallingIdentity(ident); |
| 1725 | } |
| 1726 | } |
| 1727 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1728 | |
| 1729 | boolean setInputMethodEnabledLocked(String id, boolean enabled) { |
| 1730 | // Make sure this is a valid input method. |
| 1731 | InputMethodInfo imm = mMethodMap.get(id); |
| 1732 | if (imm == null) { |
| 1733 | if (imm == null) { |
| 1734 | throw new IllegalArgumentException("Unknown id: " + mCurMethodId); |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | StringBuilder builder = new StringBuilder(256); |
| 1739 | |
| 1740 | boolean removed = false; |
| 1741 | String firstId = null; |
| 1742 | |
| 1743 | // Look through the currently enabled input methods. |
| 1744 | String enabledStr = Settings.Secure.getString(mContext.getContentResolver(), |
| 1745 | Settings.Secure.ENABLED_INPUT_METHODS); |
| 1746 | if (enabledStr != null) { |
| 1747 | final TextUtils.SimpleStringSplitter splitter = mStringColonSplitter; |
| 1748 | splitter.setString(enabledStr); |
| 1749 | while (splitter.hasNext()) { |
| 1750 | String curId = splitter.next(); |
| 1751 | if (curId.equals(id)) { |
| 1752 | if (enabled) { |
| 1753 | // We are enabling this input method, but it is |
| 1754 | // already enabled. Nothing to do. The previous |
| 1755 | // state was enabled. |
| 1756 | return true; |
| 1757 | } |
| 1758 | // We are disabling this input method, and it is |
| 1759 | // currently enabled. Skip it to remove from the |
| 1760 | // new list. |
| 1761 | removed = true; |
| 1762 | } else if (!enabled) { |
| 1763 | // We are building a new list of input methods that |
| 1764 | // doesn't contain the given one. |
| 1765 | if (firstId == null) firstId = curId; |
| 1766 | if (builder.length() > 0) builder.append(':'); |
| 1767 | builder.append(curId); |
| 1768 | } |
| 1769 | } |
| 1770 | } |
| 1771 | |
| 1772 | if (!enabled) { |
| 1773 | if (!removed) { |
| 1774 | // We are disabling the input method but it is already |
| 1775 | // disabled. Nothing to do. The previous state was |
| 1776 | // disabled. |
| 1777 | return false; |
| 1778 | } |
| 1779 | // Update the setting with the new list of input methods. |
| 1780 | Settings.Secure.putString(mContext.getContentResolver(), |
| 1781 | Settings.Secure.ENABLED_INPUT_METHODS, builder.toString()); |
| 1782 | // We the disabled input method is currently selected, switch |
| 1783 | // to another one. |
| 1784 | String selId = Settings.Secure.getString(mContext.getContentResolver(), |
| 1785 | Settings.Secure.DEFAULT_INPUT_METHOD); |
| 1786 | if (id.equals(selId)) { |
| 1787 | Settings.Secure.putString(mContext.getContentResolver(), |
| 1788 | Settings.Secure.DEFAULT_INPUT_METHOD, |
| 1789 | firstId != null ? firstId : ""); |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1790 | resetSelectedInputMethodSubtype(); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1791 | } |
| 1792 | // Previous state was enabled. |
| 1793 | return true; |
| 1794 | } |
| 1795 | |
| 1796 | // Add in the newly enabled input method. |
| 1797 | if (enabledStr == null || enabledStr.length() == 0) { |
| 1798 | enabledStr = id; |
| 1799 | } else { |
| 1800 | enabledStr = enabledStr + ':' + id; |
| 1801 | } |
| 1802 | |
| 1803 | Settings.Secure.putString(mContext.getContentResolver(), |
| 1804 | Settings.Secure.ENABLED_INPUT_METHODS, enabledStr); |
| 1805 | |
| 1806 | // Previous state was disabled. |
| 1807 | return false; |
| 1808 | } |
The Android Open Source Project | 4df2423 | 2009-03-05 14:34:35 -0800 | [diff] [blame] | 1809 | |
satok | ab751aa | 2010-09-14 19:17:36 +0900 | [diff] [blame^] | 1810 | private void resetSelectedInputMethodSubtype() { |
| 1811 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 1812 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, NOT_A_SUBTYPE_ID); |
| 1813 | } |
| 1814 | |
| 1815 | private boolean putSelectedInputMethodSubtype(InputMethodInfo imi, int subtypeId) { |
| 1816 | ArrayList<InputMethodSubtype> subtypes = imi.getSubtypes(); |
| 1817 | if (subtypeId >= 0 && subtypeId < subtypes.size()) { |
| 1818 | Settings.Secure.putInt(mContext.getContentResolver(), |
| 1819 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE, |
| 1820 | subtypes.get(subtypeId).hashCode()); |
| 1821 | return true; |
| 1822 | } else { |
| 1823 | resetSelectedInputMethodSubtype(); |
| 1824 | return false; |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | private int getSelectedInputMethodSubtypeId(String id) { |
| 1829 | InputMethodInfo imi = mMethodMap.get(id); |
| 1830 | if (imi == null) { |
| 1831 | return NOT_A_SUBTYPE_ID; |
| 1832 | } |
| 1833 | ArrayList<InputMethodSubtype> subtypes = imi.getSubtypes(); |
| 1834 | int subtypeId; |
| 1835 | try { |
| 1836 | subtypeId = Settings.Secure.getInt(mContext.getContentResolver(), |
| 1837 | Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE); |
| 1838 | } catch (SettingNotFoundException e) { |
| 1839 | return NOT_A_SUBTYPE_ID; |
| 1840 | } |
| 1841 | for (int i = 0; i < subtypes.size(); ++i) { |
| 1842 | InputMethodSubtype ims = subtypes.get(i); |
| 1843 | if (subtypeId == ims.hashCode()) { |
| 1844 | return i; |
| 1845 | } |
| 1846 | } |
| 1847 | return NOT_A_SUBTYPE_ID; |
| 1848 | } |
| 1849 | |
| 1850 | /** |
| 1851 | * @return Return the current subtype of this input method. |
| 1852 | */ |
| 1853 | public InputMethodSubtype getCurrentInputMethodSubtype() { |
| 1854 | return mCurrentSubtype; |
| 1855 | } |
| 1856 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1857 | // ---------------------------------------------------------------------- |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1858 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1859 | @Override |
| 1860 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1861 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1862 | != PackageManager.PERMISSION_GRANTED) { |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1863 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1864 | pw.println("Permission Denial: can't dump InputMethodManager from from pid=" |
| 1865 | + Binder.getCallingPid() |
| 1866 | + ", uid=" + Binder.getCallingUid()); |
| 1867 | return; |
| 1868 | } |
| 1869 | |
| 1870 | IInputMethod method; |
| 1871 | ClientState client; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1872 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1873 | final Printer p = new PrintWriterPrinter(pw); |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1874 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1875 | synchronized (mMethodMap) { |
| 1876 | p.println("Current Input Method Manager state:"); |
| 1877 | int N = mMethodList.size(); |
| 1878 | p.println(" Input Methods:"); |
| 1879 | for (int i=0; i<N; i++) { |
| 1880 | InputMethodInfo info = mMethodList.get(i); |
| 1881 | p.println(" InputMethod #" + i + ":"); |
| 1882 | info.dump(p, " "); |
| 1883 | } |
| 1884 | p.println(" Clients:"); |
| 1885 | for (ClientState ci : mClients.values()) { |
| 1886 | p.println(" Client " + ci + ":"); |
| 1887 | p.println(" client=" + ci.client); |
| 1888 | p.println(" inputContext=" + ci.inputContext); |
| 1889 | p.println(" sessionRequested=" + ci.sessionRequested); |
| 1890 | p.println(" curSession=" + ci.curSession); |
| 1891 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1892 | p.println(" mCurMethodId=" + mCurMethodId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | client = mCurClient; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1894 | p.println(" mCurClient=" + client + " mCurSeq=" + mCurSeq); |
| 1895 | p.println(" mCurFocusedWindow=" + mCurFocusedWindow); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1896 | p.println(" mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection |
| 1897 | + " mBoundToMethod=" + mBoundToMethod); |
| 1898 | p.println(" mCurToken=" + mCurToken); |
| 1899 | p.println(" mCurIntent=" + mCurIntent); |
| 1900 | method = mCurMethod; |
| 1901 | p.println(" mCurMethod=" + mCurMethod); |
| 1902 | p.println(" mEnabledSession=" + mEnabledSession); |
| 1903 | p.println(" mShowRequested=" + mShowRequested |
| 1904 | + " mShowExplicitlyRequested=" + mShowExplicitlyRequested |
| 1905 | + " mShowForced=" + mShowForced |
| 1906 | + " mInputShown=" + mInputShown); |
Dianne Hackborn | cc27870 | 2009-09-02 23:07:23 -0700 | [diff] [blame] | 1907 | p.println(" mSystemReady=" + mSystemReady + " mScreenOn=" + mScreenOn); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1908 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1909 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1910 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1911 | if (client != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1912 | pw.flush(); |
| 1913 | try { |
| 1914 | client.client.asBinder().dump(fd, args); |
| 1915 | } catch (RemoteException e) { |
| 1916 | p.println("Input method client dead: " + e); |
| 1917 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1918 | } else { |
| 1919 | p.println("No input method client."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1920 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 1921 | |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1922 | p.println(" "); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1923 | if (method != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1924 | pw.flush(); |
| 1925 | try { |
| 1926 | method.asBinder().dump(fd, args); |
| 1927 | } catch (RemoteException e) { |
| 1928 | p.println("Input method service dead: " + e); |
| 1929 | } |
Jeff Brown | b88102f | 2010-09-08 11:49:43 -0700 | [diff] [blame] | 1930 | } else { |
| 1931 | p.println("No input method service."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1932 | } |
| 1933 | } |
| 1934 | } |