Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package com.android.internal.view; |
| 18 | |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 19 | import com.android.internal.annotations.GuardedBy; |
| 20 | |
| 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.os.Bundle; |
| 24 | import android.os.Handler; |
| 25 | import android.os.Looper; |
| 26 | import android.os.Message; |
| 27 | import android.os.RemoteException; |
| 28 | import android.util.Log; |
| 29 | import android.view.KeyEvent; |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 30 | import android.view.inputmethod.BaseInputConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.view.inputmethod.CompletionInfo; |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 32 | import android.view.inputmethod.CorrectionInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.view.inputmethod.ExtractedTextRequest; |
| 34 | import android.view.inputmethod.InputConnection; |
| 35 | |
| 36 | import java.lang.ref.WeakReference; |
| 37 | |
Yohei Yukawa | 159dd47 | 2016-01-07 16:52:33 -0800 | [diff] [blame] | 38 | public abstract class IInputConnectionWrapper extends IInputContext.Stub { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | static final String TAG = "IInputConnectionWrapper"; |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 40 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | private static final int DO_GET_TEXT_AFTER_CURSOR = 10; |
| 42 | private static final int DO_GET_TEXT_BEFORE_CURSOR = 20; |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 43 | private static final int DO_GET_SELECTED_TEXT = 25; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | private static final int DO_GET_CURSOR_CAPS_MODE = 30; |
| 45 | private static final int DO_GET_EXTRACTED_TEXT = 40; |
| 46 | private static final int DO_COMMIT_TEXT = 50; |
| 47 | private static final int DO_COMMIT_COMPLETION = 55; |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 48 | private static final int DO_COMMIT_CORRECTION = 56; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | private static final int DO_SET_SELECTION = 57; |
| 50 | private static final int DO_PERFORM_EDITOR_ACTION = 58; |
| 51 | private static final int DO_PERFORM_CONTEXT_MENU_ACTION = 59; |
| 52 | private static final int DO_SET_COMPOSING_TEXT = 60; |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 53 | private static final int DO_SET_COMPOSING_REGION = 63; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | private static final int DO_FINISH_COMPOSING_TEXT = 65; |
| 55 | private static final int DO_SEND_KEY_EVENT = 70; |
| 56 | private static final int DO_DELETE_SURROUNDING_TEXT = 80; |
Yohei Yukawa | c89e22a | 2016-01-13 22:48:14 -0800 | [diff] [blame] | 57 | private static final int DO_DELETE_SURROUNDING_TEXT_IN_CODE_POINTS = 81; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | private static final int DO_BEGIN_BATCH_EDIT = 90; |
| 59 | private static final int DO_END_BATCH_EDIT = 95; |
| 60 | private static final int DO_REPORT_FULLSCREEN_MODE = 100; |
| 61 | private static final int DO_PERFORM_PRIVATE_COMMAND = 120; |
| 62 | private static final int DO_CLEAR_META_KEY_STATES = 130; |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 63 | private static final int DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO = 140; |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 64 | private static final int DO_REPORT_FINISH = 150; |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 65 | |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 66 | @GuardedBy("mLock") |
| 67 | @Nullable |
| 68 | private InputConnection mInputConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
| 70 | private Looper mMainLooper; |
| 71 | private Handler mH; |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 72 | private Object mLock = new Object(); |
| 73 | @GuardedBy("mLock") |
| 74 | private boolean mFinished = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | |
| 76 | static class SomeArgs { |
| 77 | Object arg1; |
| 78 | Object arg2; |
| 79 | IInputContextCallback callback; |
| 80 | int seq; |
| 81 | } |
| 82 | |
| 83 | class MyHandler extends Handler { |
| 84 | MyHandler(Looper looper) { |
| 85 | super(looper); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public void handleMessage(Message msg) { |
| 90 | executeMessage(msg); |
| 91 | } |
| 92 | } |
| 93 | |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 94 | public IInputConnectionWrapper(Looper mainLooper, @NonNull InputConnection inputConnection) { |
| 95 | mInputConnection = inputConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | mMainLooper = mainLooper; |
| 97 | mH = new MyHandler(mMainLooper); |
| 98 | } |
| 99 | |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 100 | @Nullable |
| 101 | public InputConnection getInputConnection() { |
| 102 | synchronized (mLock) { |
| 103 | return mInputConnection; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | protected boolean isFinished() { |
| 108 | synchronized (mLock) { |
| 109 | return mFinished; |
| 110 | } |
| 111 | } |
| 112 | |
Yohei Yukawa | 159dd47 | 2016-01-07 16:52:33 -0800 | [diff] [blame] | 113 | abstract protected boolean isActive(); |
| 114 | |
| 115 | /** |
| 116 | * Called when the user took some actions that should be taken into consideration to update the |
| 117 | * LRU list for input method rotation. |
| 118 | */ |
| 119 | abstract protected void onUserAction(); |
| 120 | |
| 121 | /** |
| 122 | * Called when the input method started or stopped full-screen mode. |
| 123 | * |
| 124 | */ |
| 125 | abstract protected void onReportFullscreenMode(boolean enabled); |
| 126 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | public void getTextAfterCursor(int length, int flags, int seq, IInputContextCallback callback) { |
| 128 | dispatchMessage(obtainMessageIISC(DO_GET_TEXT_AFTER_CURSOR, length, flags, seq, callback)); |
| 129 | } |
| 130 | |
| 131 | public void getTextBeforeCursor(int length, int flags, int seq, IInputContextCallback callback) { |
| 132 | dispatchMessage(obtainMessageIISC(DO_GET_TEXT_BEFORE_CURSOR, length, flags, seq, callback)); |
| 133 | } |
| 134 | |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 135 | public void getSelectedText(int flags, int seq, IInputContextCallback callback) { |
| 136 | dispatchMessage(obtainMessageISC(DO_GET_SELECTED_TEXT, flags, seq, callback)); |
| 137 | } |
| 138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | public void getCursorCapsMode(int reqModes, int seq, IInputContextCallback callback) { |
| 140 | dispatchMessage(obtainMessageISC(DO_GET_CURSOR_CAPS_MODE, reqModes, seq, callback)); |
| 141 | } |
| 142 | |
| 143 | public void getExtractedText(ExtractedTextRequest request, |
| 144 | int flags, int seq, IInputContextCallback callback) { |
| 145 | dispatchMessage(obtainMessageIOSC(DO_GET_EXTRACTED_TEXT, flags, |
| 146 | request, seq, callback)); |
| 147 | } |
| 148 | |
| 149 | public void commitText(CharSequence text, int newCursorPosition) { |
| 150 | dispatchMessage(obtainMessageIO(DO_COMMIT_TEXT, newCursorPosition, text)); |
| 151 | } |
| 152 | |
| 153 | public void commitCompletion(CompletionInfo text) { |
| 154 | dispatchMessage(obtainMessageO(DO_COMMIT_COMPLETION, text)); |
| 155 | } |
| 156 | |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 157 | public void commitCorrection(CorrectionInfo info) { |
| 158 | dispatchMessage(obtainMessageO(DO_COMMIT_CORRECTION, info)); |
| 159 | } |
| 160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | public void setSelection(int start, int end) { |
| 162 | dispatchMessage(obtainMessageII(DO_SET_SELECTION, start, end)); |
| 163 | } |
| 164 | |
| 165 | public void performEditorAction(int id) { |
| 166 | dispatchMessage(obtainMessageII(DO_PERFORM_EDITOR_ACTION, id, 0)); |
| 167 | } |
| 168 | |
| 169 | public void performContextMenuAction(int id) { |
| 170 | dispatchMessage(obtainMessageII(DO_PERFORM_CONTEXT_MENU_ACTION, id, 0)); |
| 171 | } |
| 172 | |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 173 | public void setComposingRegion(int start, int end) { |
| 174 | dispatchMessage(obtainMessageII(DO_SET_COMPOSING_REGION, start, end)); |
| 175 | } |
| 176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | public void setComposingText(CharSequence text, int newCursorPosition) { |
| 178 | dispatchMessage(obtainMessageIO(DO_SET_COMPOSING_TEXT, newCursorPosition, text)); |
| 179 | } |
| 180 | |
| 181 | public void finishComposingText() { |
| 182 | dispatchMessage(obtainMessage(DO_FINISH_COMPOSING_TEXT)); |
| 183 | } |
| 184 | |
| 185 | public void sendKeyEvent(KeyEvent event) { |
| 186 | dispatchMessage(obtainMessageO(DO_SEND_KEY_EVENT, event)); |
| 187 | } |
| 188 | |
| 189 | public void clearMetaKeyStates(int states) { |
| 190 | dispatchMessage(obtainMessageII(DO_CLEAR_META_KEY_STATES, states, 0)); |
| 191 | } |
| 192 | |
Yohei Yukawa | c89e22a | 2016-01-13 22:48:14 -0800 | [diff] [blame] | 193 | public void deleteSurroundingText(int beforeLength, int afterLength) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | dispatchMessage(obtainMessageII(DO_DELETE_SURROUNDING_TEXT, |
Yohei Yukawa | c89e22a | 2016-01-13 22:48:14 -0800 | [diff] [blame] | 195 | beforeLength, afterLength)); |
| 196 | } |
| 197 | |
| 198 | public void deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) { |
| 199 | dispatchMessage(obtainMessageII(DO_DELETE_SURROUNDING_TEXT_IN_CODE_POINTS, |
| 200 | beforeLength, afterLength)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | public void beginBatchEdit() { |
| 204 | dispatchMessage(obtainMessage(DO_BEGIN_BATCH_EDIT)); |
| 205 | } |
| 206 | |
| 207 | public void endBatchEdit() { |
| 208 | dispatchMessage(obtainMessage(DO_END_BATCH_EDIT)); |
| 209 | } |
| 210 | |
| 211 | public void reportFullscreenMode(boolean enabled) { |
| 212 | dispatchMessage(obtainMessageII(DO_REPORT_FULLSCREEN_MODE, enabled ? 1 : 0, 0)); |
| 213 | } |
| 214 | |
| 215 | public void performPrivateCommand(String action, Bundle data) { |
| 216 | dispatchMessage(obtainMessageOO(DO_PERFORM_PRIVATE_COMMAND, action, data)); |
| 217 | } |
satok | adb4358 | 2011-03-09 10:08:47 +0900 | [diff] [blame] | 218 | |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 219 | public void requestUpdateCursorAnchorInfo(int cursorUpdateMode, int seq, |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 220 | IInputContextCallback callback) { |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 221 | dispatchMessage(obtainMessageISC(DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO, cursorUpdateMode, |
| 222 | seq, callback)); |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 223 | } |
| 224 | |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 225 | public void reportFinish() { |
| 226 | dispatchMessage(obtainMessage(DO_REPORT_FINISH)); |
| 227 | } |
| 228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | void dispatchMessage(Message msg) { |
| 230 | // If we are calling this from the main thread, then we can call |
| 231 | // right through. Otherwise, we need to send the message to the |
| 232 | // main thread. |
| 233 | if (Looper.myLooper() == mMainLooper) { |
| 234 | executeMessage(msg); |
| 235 | msg.recycle(); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | mH.sendMessage(msg); |
| 240 | } |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 241 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | void executeMessage(Message msg) { |
| 243 | switch (msg.what) { |
| 244 | case DO_GET_TEXT_AFTER_CURSOR: { |
| 245 | SomeArgs args = (SomeArgs)msg.obj; |
| 246 | try { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 247 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | if (ic == null || !isActive()) { |
| 249 | Log.w(TAG, "getTextAfterCursor on inactive InputConnection"); |
| 250 | args.callback.setTextAfterCursor(null, args.seq); |
| 251 | return; |
| 252 | } |
| 253 | args.callback.setTextAfterCursor(ic.getTextAfterCursor( |
| 254 | msg.arg1, msg.arg2), args.seq); |
| 255 | } catch (RemoteException e) { |
| 256 | Log.w(TAG, "Got RemoteException calling setTextAfterCursor", e); |
| 257 | } |
| 258 | return; |
| 259 | } |
| 260 | case DO_GET_TEXT_BEFORE_CURSOR: { |
| 261 | SomeArgs args = (SomeArgs)msg.obj; |
| 262 | try { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 263 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | if (ic == null || !isActive()) { |
| 265 | Log.w(TAG, "getTextBeforeCursor on inactive InputConnection"); |
| 266 | args.callback.setTextBeforeCursor(null, args.seq); |
| 267 | return; |
| 268 | } |
| 269 | args.callback.setTextBeforeCursor(ic.getTextBeforeCursor( |
| 270 | msg.arg1, msg.arg2), args.seq); |
| 271 | } catch (RemoteException e) { |
| 272 | Log.w(TAG, "Got RemoteException calling setTextBeforeCursor", e); |
| 273 | } |
| 274 | return; |
| 275 | } |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 276 | case DO_GET_SELECTED_TEXT: { |
| 277 | SomeArgs args = (SomeArgs)msg.obj; |
| 278 | try { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 279 | InputConnection ic = getInputConnection(); |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 280 | if (ic == null || !isActive()) { |
| 281 | Log.w(TAG, "getSelectedText on inactive InputConnection"); |
| 282 | args.callback.setSelectedText(null, args.seq); |
| 283 | return; |
| 284 | } |
| 285 | args.callback.setSelectedText(ic.getSelectedText( |
| 286 | msg.arg1), args.seq); |
| 287 | } catch (RemoteException e) { |
| 288 | Log.w(TAG, "Got RemoteException calling setSelectedText", e); |
| 289 | } |
| 290 | return; |
| 291 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | case DO_GET_CURSOR_CAPS_MODE: { |
| 293 | SomeArgs args = (SomeArgs)msg.obj; |
| 294 | try { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 295 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | if (ic == null || !isActive()) { |
| 297 | Log.w(TAG, "getCursorCapsMode on inactive InputConnection"); |
| 298 | args.callback.setCursorCapsMode(0, args.seq); |
| 299 | return; |
| 300 | } |
| 301 | args.callback.setCursorCapsMode(ic.getCursorCapsMode(msg.arg1), |
| 302 | args.seq); |
| 303 | } catch (RemoteException e) { |
| 304 | Log.w(TAG, "Got RemoteException calling setCursorCapsMode", e); |
| 305 | } |
| 306 | return; |
| 307 | } |
| 308 | case DO_GET_EXTRACTED_TEXT: { |
| 309 | SomeArgs args = (SomeArgs)msg.obj; |
| 310 | try { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 311 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | if (ic == null || !isActive()) { |
| 313 | Log.w(TAG, "getExtractedText on inactive InputConnection"); |
| 314 | args.callback.setExtractedText(null, args.seq); |
| 315 | return; |
| 316 | } |
| 317 | args.callback.setExtractedText(ic.getExtractedText( |
| 318 | (ExtractedTextRequest)args.arg1, msg.arg1), args.seq); |
| 319 | } catch (RemoteException e) { |
| 320 | Log.w(TAG, "Got RemoteException calling setExtractedText", e); |
| 321 | } |
| 322 | return; |
| 323 | } |
| 324 | case DO_COMMIT_TEXT: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 325 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | if (ic == null || !isActive()) { |
| 327 | Log.w(TAG, "commitText on inactive InputConnection"); |
| 328 | return; |
| 329 | } |
| 330 | ic.commitText((CharSequence)msg.obj, msg.arg1); |
Yohei Yukawa | 159dd47 | 2016-01-07 16:52:33 -0800 | [diff] [blame] | 331 | onUserAction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | return; |
| 333 | } |
| 334 | case DO_SET_SELECTION: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 335 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | if (ic == null || !isActive()) { |
| 337 | Log.w(TAG, "setSelection on inactive InputConnection"); |
| 338 | return; |
| 339 | } |
| 340 | ic.setSelection(msg.arg1, msg.arg2); |
| 341 | return; |
| 342 | } |
| 343 | case DO_PERFORM_EDITOR_ACTION: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 344 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | if (ic == null || !isActive()) { |
| 346 | Log.w(TAG, "performEditorAction on inactive InputConnection"); |
| 347 | return; |
| 348 | } |
| 349 | ic.performEditorAction(msg.arg1); |
| 350 | return; |
| 351 | } |
| 352 | case DO_PERFORM_CONTEXT_MENU_ACTION: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 353 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | if (ic == null || !isActive()) { |
| 355 | Log.w(TAG, "performContextMenuAction on inactive InputConnection"); |
| 356 | return; |
| 357 | } |
| 358 | ic.performContextMenuAction(msg.arg1); |
| 359 | return; |
| 360 | } |
| 361 | case DO_COMMIT_COMPLETION: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 362 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | if (ic == null || !isActive()) { |
| 364 | Log.w(TAG, "commitCompletion on inactive InputConnection"); |
| 365 | return; |
| 366 | } |
| 367 | ic.commitCompletion((CompletionInfo)msg.obj); |
| 368 | return; |
| 369 | } |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 370 | case DO_COMMIT_CORRECTION: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 371 | InputConnection ic = getInputConnection(); |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 372 | if (ic == null || !isActive()) { |
| 373 | Log.w(TAG, "commitCorrection on inactive InputConnection"); |
| 374 | return; |
| 375 | } |
| 376 | ic.commitCorrection((CorrectionInfo)msg.obj); |
| 377 | return; |
| 378 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | case DO_SET_COMPOSING_TEXT: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 380 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | if (ic == null || !isActive()) { |
| 382 | Log.w(TAG, "setComposingText on inactive InputConnection"); |
| 383 | return; |
| 384 | } |
| 385 | ic.setComposingText((CharSequence)msg.obj, msg.arg1); |
Yohei Yukawa | 159dd47 | 2016-01-07 16:52:33 -0800 | [diff] [blame] | 386 | onUserAction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | return; |
| 388 | } |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 389 | case DO_SET_COMPOSING_REGION: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 390 | InputConnection ic = getInputConnection(); |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 391 | if (ic == null || !isActive()) { |
| 392 | Log.w(TAG, "setComposingRegion on inactive InputConnection"); |
| 393 | return; |
| 394 | } |
| 395 | ic.setComposingRegion(msg.arg1, msg.arg2); |
| 396 | return; |
| 397 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | case DO_FINISH_COMPOSING_TEXT: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 399 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | // Note we do NOT check isActive() here, because this is safe |
| 401 | // for an IME to call at any time, and we need to allow it |
| 402 | // through to clean up our state after the IME has switched to |
| 403 | // another client. |
| 404 | if (ic == null) { |
| 405 | Log.w(TAG, "finishComposingText on inactive InputConnection"); |
| 406 | return; |
| 407 | } |
| 408 | ic.finishComposingText(); |
| 409 | return; |
| 410 | } |
| 411 | case DO_SEND_KEY_EVENT: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 412 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | if (ic == null || !isActive()) { |
| 414 | Log.w(TAG, "sendKeyEvent on inactive InputConnection"); |
| 415 | return; |
| 416 | } |
| 417 | ic.sendKeyEvent((KeyEvent)msg.obj); |
Yohei Yukawa | 159dd47 | 2016-01-07 16:52:33 -0800 | [diff] [blame] | 418 | onUserAction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | return; |
| 420 | } |
| 421 | case DO_CLEAR_META_KEY_STATES: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 422 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | if (ic == null || !isActive()) { |
| 424 | Log.w(TAG, "clearMetaKeyStates on inactive InputConnection"); |
| 425 | return; |
| 426 | } |
| 427 | ic.clearMetaKeyStates(msg.arg1); |
| 428 | return; |
| 429 | } |
| 430 | case DO_DELETE_SURROUNDING_TEXT: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 431 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 432 | if (ic == null || !isActive()) { |
| 433 | Log.w(TAG, "deleteSurroundingText on inactive InputConnection"); |
| 434 | return; |
| 435 | } |
| 436 | ic.deleteSurroundingText(msg.arg1, msg.arg2); |
| 437 | return; |
| 438 | } |
Yohei Yukawa | c89e22a | 2016-01-13 22:48:14 -0800 | [diff] [blame] | 439 | case DO_DELETE_SURROUNDING_TEXT_IN_CODE_POINTS: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 440 | InputConnection ic = getInputConnection(); |
Yohei Yukawa | c89e22a | 2016-01-13 22:48:14 -0800 | [diff] [blame] | 441 | if (ic == null || !isActive()) { |
| 442 | Log.w(TAG, "deleteSurroundingTextInCodePoints on inactive InputConnection"); |
| 443 | return; |
| 444 | } |
| 445 | ic.deleteSurroundingTextInCodePoints(msg.arg1, msg.arg2); |
| 446 | return; |
| 447 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | case DO_BEGIN_BATCH_EDIT: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 449 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | if (ic == null || !isActive()) { |
| 451 | Log.w(TAG, "beginBatchEdit on inactive InputConnection"); |
| 452 | return; |
| 453 | } |
| 454 | ic.beginBatchEdit(); |
| 455 | return; |
| 456 | } |
| 457 | case DO_END_BATCH_EDIT: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 458 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | if (ic == null || !isActive()) { |
| 460 | Log.w(TAG, "endBatchEdit on inactive InputConnection"); |
| 461 | return; |
| 462 | } |
| 463 | ic.endBatchEdit(); |
| 464 | return; |
| 465 | } |
| 466 | case DO_REPORT_FULLSCREEN_MODE: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 467 | InputConnection ic = getInputConnection(); |
Andrei Stingaceanu | da589df | 2015-06-17 10:38:08 +0100 | [diff] [blame] | 468 | if (ic == null) { |
| 469 | Log.w(TAG, "reportFullscreenMode on inexistent InputConnection"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | return; |
| 471 | } |
Yohei Yukawa | 159dd47 | 2016-01-07 16:52:33 -0800 | [diff] [blame] | 472 | final boolean enabled = msg.arg1 == 1; |
| 473 | ic.reportFullscreenMode(enabled); |
| 474 | onReportFullscreenMode(enabled); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | return; |
| 476 | } |
| 477 | case DO_PERFORM_PRIVATE_COMMAND: { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 478 | InputConnection ic = getInputConnection(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | if (ic == null || !isActive()) { |
| 480 | Log.w(TAG, "performPrivateCommand on inactive InputConnection"); |
| 481 | return; |
| 482 | } |
| 483 | SomeArgs args = (SomeArgs)msg.obj; |
| 484 | ic.performPrivateCommand((String)args.arg1, |
| 485 | (Bundle)args.arg2); |
| 486 | return; |
| 487 | } |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 488 | case DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO: { |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 489 | SomeArgs args = (SomeArgs)msg.obj; |
| 490 | try { |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 491 | InputConnection ic = getInputConnection(); |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 492 | if (ic == null || !isActive()) { |
| 493 | Log.w(TAG, "requestCursorAnchorInfo on inactive InputConnection"); |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 494 | args.callback.setRequestUpdateCursorAnchorInfoResult(false, args.seq); |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 495 | return; |
| 496 | } |
Yohei Yukawa | a277db2 | 2014-08-21 18:38:44 -0700 | [diff] [blame] | 497 | args.callback.setRequestUpdateCursorAnchorInfoResult( |
Yohei Yukawa | d8636ea | 2014-09-02 22:03:30 -0700 | [diff] [blame] | 498 | ic.requestCursorUpdates(msg.arg1), args.seq); |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 499 | } catch (RemoteException e) { |
| 500 | Log.w(TAG, "Got RemoteException calling requestCursorAnchorInfo", e); |
| 501 | } |
| 502 | return; |
| 503 | } |
Yohei Yukawa | aaa38c9 | 2016-03-27 23:46:04 -0700 | [diff] [blame^] | 504 | case DO_REPORT_FINISH: { |
| 505 | // Note that we do not need to worry about race condition here, because 1) mFinished |
| 506 | // is updated only inside this block, and 2) the code here is running on a Handler |
| 507 | // hence we assume multiple DO_REPORT_FINISH messages will not be handled at the |
| 508 | // same time. |
| 509 | if (isFinished()) { |
| 510 | return; |
| 511 | } |
| 512 | try { |
| 513 | InputConnection ic = getInputConnection(); |
| 514 | // Note we do NOT check isActive() here, because this is safe |
| 515 | // for an IME to call at any time, and we need to allow it |
| 516 | // through to clean up our state after the IME has switched to |
| 517 | // another client. |
| 518 | if (ic == null) { |
| 519 | return; |
| 520 | } |
| 521 | ic.finishComposingText(); |
| 522 | // TODO: Make reportFinish() public method of InputConnection to remove this |
| 523 | // check. |
| 524 | if (ic instanceof BaseInputConnection) { |
| 525 | ((BaseInputConnection) ic).reportFinish(); |
| 526 | } |
| 527 | } finally { |
| 528 | synchronized (mLock) { |
| 529 | mInputConnection = null; |
| 530 | mFinished = true; |
| 531 | } |
| 532 | } |
| 533 | return; |
| 534 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | } |
| 536 | Log.w(TAG, "Unhandled message code: " + msg.what); |
| 537 | } |
| 538 | |
| 539 | Message obtainMessage(int what) { |
| 540 | return mH.obtainMessage(what); |
| 541 | } |
| 542 | |
| 543 | Message obtainMessageII(int what, int arg1, int arg2) { |
| 544 | return mH.obtainMessage(what, arg1, arg2); |
| 545 | } |
Yohei Yukawa | c89e22a | 2016-01-13 22:48:14 -0800 | [diff] [blame] | 546 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 547 | Message obtainMessageO(int what, Object arg1) { |
| 548 | return mH.obtainMessage(what, 0, 0, arg1); |
| 549 | } |
| 550 | |
| 551 | Message obtainMessageISC(int what, int arg1, int seq, IInputContextCallback callback) { |
| 552 | SomeArgs args = new SomeArgs(); |
| 553 | args.callback = callback; |
| 554 | args.seq = seq; |
| 555 | return mH.obtainMessage(what, arg1, 0, args); |
| 556 | } |
| 557 | |
| 558 | Message obtainMessageIISC(int what, int arg1, int arg2, int seq, IInputContextCallback callback) { |
| 559 | SomeArgs args = new SomeArgs(); |
| 560 | args.callback = callback; |
| 561 | args.seq = seq; |
| 562 | return mH.obtainMessage(what, arg1, arg2, args); |
| 563 | } |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 564 | |
| 565 | Message obtainMessageOSC(int what, Object arg1, int seq, IInputContextCallback callback) { |
| 566 | SomeArgs args = new SomeArgs(); |
| 567 | args.arg1 = arg1; |
| 568 | args.callback = callback; |
| 569 | args.seq = seq; |
| 570 | return mH.obtainMessage(what, 0, 0, args); |
| 571 | } |
| 572 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | Message obtainMessageIOSC(int what, int arg1, Object arg2, int seq, |
| 574 | IInputContextCallback callback) { |
| 575 | SomeArgs args = new SomeArgs(); |
| 576 | args.arg1 = arg2; |
| 577 | args.callback = callback; |
| 578 | args.seq = seq; |
| 579 | return mH.obtainMessage(what, arg1, 0, args); |
| 580 | } |
| 581 | |
| 582 | Message obtainMessageIO(int what, int arg1, Object arg2) { |
| 583 | return mH.obtainMessage(what, arg1, 0, arg2); |
| 584 | } |
| 585 | |
| 586 | Message obtainMessageOO(int what, Object arg1, Object arg2) { |
| 587 | SomeArgs args = new SomeArgs(); |
| 588 | args.arg1 = arg1; |
| 589 | args.arg2 = arg2; |
| 590 | return mH.obtainMessage(what, 0, 0, args); |
| 591 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 592 | } |