blob: 6c1ebb43287b789423e2156b84998b554a6132ad [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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 Project9066cfe2009-03-03 19:31:44 -080017package com.android.internal.view;
18
Yohei Yukawaaaa38c92016-03-27 23:46:04 -070019import com.android.internal.annotations.GuardedBy;
20
21import android.annotation.NonNull;
22import android.annotation.Nullable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.os.Bundle;
24import android.os.Handler;
25import android.os.Looper;
26import android.os.Message;
27import android.os.RemoteException;
28import android.util.Log;
29import android.view.KeyEvent;
Yohei Yukawaaaa38c92016-03-27 23:46:04 -070030import android.view.inputmethod.BaseInputConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.view.inputmethod.CompletionInfo;
Gilles Debunnecf9cf2f2010-12-08 17:43:58 -080032import android.view.inputmethod.CorrectionInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.view.inputmethod.ExtractedTextRequest;
34import android.view.inputmethod.InputConnection;
35
36import java.lang.ref.WeakReference;
37
Yohei Yukawa159dd472016-01-07 16:52:33 -080038public abstract class IInputConnectionWrapper extends IInputContext.Stub {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 static final String TAG = "IInputConnectionWrapper";
Amith Yamasania90b7f02010-08-25 18:27:20 -070040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041 private static final int DO_GET_TEXT_AFTER_CURSOR = 10;
42 private static final int DO_GET_TEXT_BEFORE_CURSOR = 20;
Amith Yamasania90b7f02010-08-25 18:27:20 -070043 private static final int DO_GET_SELECTED_TEXT = 25;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 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 Debunnecf9cf2f2010-12-08 17:43:58 -080048 private static final int DO_COMMIT_CORRECTION = 56;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 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 Yamasania90b7f02010-08-25 18:27:20 -070053 private static final int DO_SET_COMPOSING_REGION = 63;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 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 Yukawac89e22a2016-01-13 22:48:14 -080057 private static final int DO_DELETE_SURROUNDING_TEXT_IN_CODE_POINTS = 81;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 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 Yukawaa277db22014-08-21 18:38:44 -070063 private static final int DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO = 140;
Yohei Yukawaaaa38c92016-03-27 23:46:04 -070064 private static final int DO_REPORT_FINISH = 150;
Amith Yamasania90b7f02010-08-25 18:27:20 -070065
Yohei Yukawaaaa38c92016-03-27 23:46:04 -070066 @GuardedBy("mLock")
67 @Nullable
68 private InputConnection mInputConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
70 private Looper mMainLooper;
71 private Handler mH;
Yohei Yukawaaaa38c92016-03-27 23:46:04 -070072 private Object mLock = new Object();
73 @GuardedBy("mLock")
74 private boolean mFinished = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075
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 Yukawaaaa38c92016-03-27 23:46:04 -070094 public IInputConnectionWrapper(Looper mainLooper, @NonNull InputConnection inputConnection) {
95 mInputConnection = inputConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 mMainLooper = mainLooper;
97 mH = new MyHandler(mMainLooper);
98 }
99
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700100 @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 Yukawa159dd472016-01-07 16:52:33 -0800113 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 Project9066cfe2009-03-03 19:31:44 -0800127 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 Yamasania90b7f02010-08-25 18:27:20 -0700135 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 Project9066cfe2009-03-03 19:31:44 -0800139 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 Debunnecf9cf2f2010-12-08 17:43:58 -0800157 public void commitCorrection(CorrectionInfo info) {
158 dispatchMessage(obtainMessageO(DO_COMMIT_CORRECTION, info));
159 }
160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 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 Yamasania90b7f02010-08-25 18:27:20 -0700173 public void setComposingRegion(int start, int end) {
174 dispatchMessage(obtainMessageII(DO_SET_COMPOSING_REGION, start, end));
175 }
176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 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 Yukawac89e22a2016-01-13 22:48:14 -0800193 public void deleteSurroundingText(int beforeLength, int afterLength) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 dispatchMessage(obtainMessageII(DO_DELETE_SURROUNDING_TEXT,
Yohei Yukawac89e22a2016-01-13 22:48:14 -0800195 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 Project9066cfe2009-03-03 19:31:44 -0800201 }
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 }
satokadb43582011-03-09 10:08:47 +0900218
Yohei Yukawaa277db22014-08-21 18:38:44 -0700219 public void requestUpdateCursorAnchorInfo(int cursorUpdateMode, int seq,
Yohei Yukawa0023d0e2014-07-11 04:13:03 +0900220 IInputContextCallback callback) {
Yohei Yukawaa277db22014-08-21 18:38:44 -0700221 dispatchMessage(obtainMessageISC(DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO, cursorUpdateMode,
222 seq, callback));
Yohei Yukawa0023d0e2014-07-11 04:13:03 +0900223 }
224
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700225 public void reportFinish() {
226 dispatchMessage(obtainMessage(DO_REPORT_FINISH));
227 }
228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 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 Yukawaaaa38c92016-03-27 23:46:04 -0700241
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 void executeMessage(Message msg) {
243 switch (msg.what) {
244 case DO_GET_TEXT_AFTER_CURSOR: {
245 SomeArgs args = (SomeArgs)msg.obj;
246 try {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700247 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 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 Yukawaaaa38c92016-03-27 23:46:04 -0700263 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 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 Yamasania90b7f02010-08-25 18:27:20 -0700276 case DO_GET_SELECTED_TEXT: {
277 SomeArgs args = (SomeArgs)msg.obj;
278 try {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700279 InputConnection ic = getInputConnection();
Amith Yamasania90b7f02010-08-25 18:27:20 -0700280 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 Project9066cfe2009-03-03 19:31:44 -0800292 case DO_GET_CURSOR_CAPS_MODE: {
293 SomeArgs args = (SomeArgs)msg.obj;
294 try {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700295 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 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 Yukawaaaa38c92016-03-27 23:46:04 -0700311 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312 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 Yukawaaaa38c92016-03-27 23:46:04 -0700325 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 if (ic == null || !isActive()) {
327 Log.w(TAG, "commitText on inactive InputConnection");
328 return;
329 }
330 ic.commitText((CharSequence)msg.obj, msg.arg1);
Yohei Yukawa159dd472016-01-07 16:52:33 -0800331 onUserAction();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800332 return;
333 }
334 case DO_SET_SELECTION: {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700335 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 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 Yukawaaaa38c92016-03-27 23:46:04 -0700344 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 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 Yukawaaaa38c92016-03-27 23:46:04 -0700353 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 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 Yukawaaaa38c92016-03-27 23:46:04 -0700362 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 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 Debunnecf9cf2f2010-12-08 17:43:58 -0800370 case DO_COMMIT_CORRECTION: {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700371 InputConnection ic = getInputConnection();
Gilles Debunnecf9cf2f2010-12-08 17:43:58 -0800372 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 Project9066cfe2009-03-03 19:31:44 -0800379 case DO_SET_COMPOSING_TEXT: {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700380 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 if (ic == null || !isActive()) {
382 Log.w(TAG, "setComposingText on inactive InputConnection");
383 return;
384 }
385 ic.setComposingText((CharSequence)msg.obj, msg.arg1);
Yohei Yukawa159dd472016-01-07 16:52:33 -0800386 onUserAction();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 return;
388 }
Amith Yamasania90b7f02010-08-25 18:27:20 -0700389 case DO_SET_COMPOSING_REGION: {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700390 InputConnection ic = getInputConnection();
Amith Yamasania90b7f02010-08-25 18:27:20 -0700391 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 Project9066cfe2009-03-03 19:31:44 -0800398 case DO_FINISH_COMPOSING_TEXT: {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700399 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 // 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 Yukawaaaa38c92016-03-27 23:46:04 -0700412 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 if (ic == null || !isActive()) {
414 Log.w(TAG, "sendKeyEvent on inactive InputConnection");
415 return;
416 }
417 ic.sendKeyEvent((KeyEvent)msg.obj);
Yohei Yukawa159dd472016-01-07 16:52:33 -0800418 onUserAction();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 return;
420 }
421 case DO_CLEAR_META_KEY_STATES: {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700422 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 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 Yukawaaaa38c92016-03-27 23:46:04 -0700431 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800432 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 Yukawac89e22a2016-01-13 22:48:14 -0800439 case DO_DELETE_SURROUNDING_TEXT_IN_CODE_POINTS: {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700440 InputConnection ic = getInputConnection();
Yohei Yukawac89e22a2016-01-13 22:48:14 -0800441 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 Project9066cfe2009-03-03 19:31:44 -0800448 case DO_BEGIN_BATCH_EDIT: {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700449 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 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 Yukawaaaa38c92016-03-27 23:46:04 -0700458 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 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 Yukawaaaa38c92016-03-27 23:46:04 -0700467 InputConnection ic = getInputConnection();
Andrei Stingaceanuda589df2015-06-17 10:38:08 +0100468 if (ic == null) {
469 Log.w(TAG, "reportFullscreenMode on inexistent InputConnection");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 return;
471 }
Yohei Yukawa159dd472016-01-07 16:52:33 -0800472 final boolean enabled = msg.arg1 == 1;
473 ic.reportFullscreenMode(enabled);
474 onReportFullscreenMode(enabled);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 return;
476 }
477 case DO_PERFORM_PRIVATE_COMMAND: {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700478 InputConnection ic = getInputConnection();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 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 Yukawaa277db22014-08-21 18:38:44 -0700488 case DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO: {
Yohei Yukawa0023d0e2014-07-11 04:13:03 +0900489 SomeArgs args = (SomeArgs)msg.obj;
490 try {
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700491 InputConnection ic = getInputConnection();
Yohei Yukawa0023d0e2014-07-11 04:13:03 +0900492 if (ic == null || !isActive()) {
493 Log.w(TAG, "requestCursorAnchorInfo on inactive InputConnection");
Yohei Yukawaa277db22014-08-21 18:38:44 -0700494 args.callback.setRequestUpdateCursorAnchorInfoResult(false, args.seq);
Yohei Yukawa0023d0e2014-07-11 04:13:03 +0900495 return;
496 }
Yohei Yukawaa277db22014-08-21 18:38:44 -0700497 args.callback.setRequestUpdateCursorAnchorInfoResult(
Yohei Yukawad8636ea2014-09-02 22:03:30 -0700498 ic.requestCursorUpdates(msg.arg1), args.seq);
Yohei Yukawa0023d0e2014-07-11 04:13:03 +0900499 } catch (RemoteException e) {
500 Log.w(TAG, "Got RemoteException calling requestCursorAnchorInfo", e);
501 }
502 return;
503 }
Yohei Yukawaaaa38c92016-03-27 23:46:04 -0700504 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 Project9066cfe2009-03-03 19:31:44 -0800535 }
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 Yukawac89e22a2016-01-13 22:48:14 -0800546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 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 Yukawa0023d0e2014-07-11 04:13:03 +0900564
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 Project9066cfe2009-03-03 19:31:44 -0800573 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 Project9066cfe2009-03-03 19:31:44 -0800592}