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