| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.inputmethod; |
| 18 |
|
| 19 |
import android.annotation.AnyThread; |
| 20 |
import android.annotation.NonNull; |
| 21 |
import android.annotation.Nullable; |
| 22 |
import android.os.Bundle; |
| 23 |
import android.os.RemoteException; |
| 24 |
import android.view.KeyEvent; |
| 25 |
import android.view.inputmethod.CompletionInfo; |
| 26 |
import android.view.inputmethod.CorrectionInfo; |
| 27 |
import android.view.inputmethod.ExtractedText; |
| 28 |
import android.view.inputmethod.ExtractedTextRequest; |
| 29 |
import android.view.inputmethod.InputContentInfo; |
| 30 |
import android.view.inputmethod.SurroundingText; |
| 31 |
import android.view.inputmethod.TextAttribute; |
| 32 |
|
| 33 |
import com.android.internal.infra.AndroidFuture; |
| 34 |
import com.android.internal.view.IInputContext; |
| 35 |
|
| 36 |
import java.util.Objects; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public final class IInputContextInvoker { |
| 43 |
|
| 44 |
@NonNull |
| 45 |
private final IInputContext mIInputContext; |
| 46 |
private final int mSessionId; |
| 47 |
|
| 48 |
private IInputContextInvoker(@NonNull IInputContext inputContext, int sessionId) { |
| 49 |
mIInputContext = inputContext; |
| 50 |
mSessionId = sessionId; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public static IInputContextInvoker create(@NonNull IInputContext inputContext) { |
| 60 |
Objects.requireNonNull(inputContext); |
| 61 |
return new IInputContextInvoker(inputContext, 0); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
@NonNull |
| 71 |
public IInputContextInvoker cloneWithSessionId(int sessionId) { |
| 72 |
return new IInputContextInvoker(mIInputContext, sessionId); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
@AnyThread |
| 81 |
public boolean isSameConnection(@NonNull IInputContext inputContext) { |
| 82 |
if (inputContext == null) { |
| 83 |
return false; |
| 84 |
} |
| 85 |
return mIInputContext.asBinder() == inputContext.asBinder(); |
| 86 |
} |
| 87 |
|
| 88 |
@NonNull |
| 89 |
InputConnectionCommandHeader createHeader() { |
| 90 |
return new InputConnectionCommandHeader(mSessionId); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
@AnyThread |
| 103 |
@NonNull |
| 104 |
public AndroidFuture<CharSequence> getTextAfterCursor(int length, int flags) { |
| 105 |
final AndroidFuture<CharSequence> future = new AndroidFuture<>(); |
| 106 |
try { |
| 107 |
mIInputContext.getTextAfterCursor(createHeader(), length, flags, future); |
| 108 |
} catch (RemoteException e) { |
| 109 |
future.completeExceptionally(e); |
| 110 |
} |
| 111 |
return future; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
@AnyThread |
| 124 |
@NonNull |
| 125 |
public AndroidFuture<CharSequence> getTextBeforeCursor(int length, int flags) { |
| 126 |
final AndroidFuture<CharSequence> future = new AndroidFuture<>(); |
| 127 |
try { |
| 128 |
mIInputContext.getTextBeforeCursor(createHeader(), length, flags, future); |
| 129 |
} catch (RemoteException e) { |
| 130 |
future.completeExceptionally(e); |
| 131 |
} |
| 132 |
return future; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
@AnyThread |
| 144 |
@NonNull |
| 145 |
public AndroidFuture<CharSequence> getSelectedText(int flags) { |
| 146 |
final AndroidFuture<CharSequence> future = new AndroidFuture<>(); |
| 147 |
try { |
| 148 |
mIInputContext.getSelectedText(createHeader(), flags, future); |
| 149 |
} catch (RemoteException e) { |
| 150 |
future.completeExceptionally(e); |
| 151 |
} |
| 152 |
return future; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
@AnyThread |
| 167 |
@NonNull |
| 168 |
public AndroidFuture<SurroundingText> getSurroundingText(int beforeLength, int afterLength, |
| 169 |
int flags) { |
| 170 |
final AndroidFuture<SurroundingText> future = new AndroidFuture<>(); |
| 171 |
try { |
| 172 |
mIInputContext.getSurroundingText(createHeader(), beforeLength, afterLength, flags, |
| 173 |
future); |
| 174 |
} catch (RemoteException e) { |
| 175 |
future.completeExceptionally(e); |
| 176 |
} |
| 177 |
return future; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
@AnyThread |
| 189 |
@NonNull |
| 190 |
public AndroidFuture<Integer> getCursorCapsMode(int reqModes) { |
| 191 |
final AndroidFuture<Integer> future = new AndroidFuture<>(); |
| 192 |
try { |
| 193 |
mIInputContext.getCursorCapsMode(createHeader(), reqModes, future); |
| 194 |
} catch (RemoteException e) { |
| 195 |
future.completeExceptionally(e); |
| 196 |
} |
| 197 |
return future; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
@AnyThread |
| 210 |
@NonNull |
| 211 |
public AndroidFuture<ExtractedText> getExtractedText(ExtractedTextRequest request, |
| 212 |
int flags) { |
| 213 |
final AndroidFuture<ExtractedText> future = new AndroidFuture<>(); |
| 214 |
try { |
| 215 |
mIInputContext.getExtractedText(createHeader(), request, flags, future); |
| 216 |
} catch (RemoteException e) { |
| 217 |
future.completeExceptionally(e); |
| 218 |
} |
| 219 |
return future; |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
@AnyThread |
| 231 |
public boolean commitText(CharSequence text, int newCursorPosition) { |
| 232 |
try { |
| 233 |
mIInputContext.commitText(createHeader(), text, newCursorPosition); |
| 234 |
return true; |
| 235 |
} catch (RemoteException e) { |
| 236 |
return false; |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
@AnyThread |
| 251 |
public boolean commitText(CharSequence text, int newCursorPosition, |
| 252 |
@Nullable TextAttribute textAttribute) { |
| 253 |
try { |
| 254 |
mIInputContext.commitTextWithTextAttribute( |
| 255 |
createHeader(), text, newCursorPosition, textAttribute); |
| 256 |
return true; |
| 257 |
} catch (RemoteException e) { |
| 258 |
return false; |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
@AnyThread |
| 270 |
public boolean commitCompletion(CompletionInfo text) { |
| 271 |
try { |
| 272 |
mIInputContext.commitCompletion(createHeader(), text); |
| 273 |
return true; |
| 274 |
} catch (RemoteException e) { |
| 275 |
return false; |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
@AnyThread |
| 287 |
public boolean commitCorrection(CorrectionInfo correctionInfo) { |
| 288 |
try { |
| 289 |
mIInputContext.commitCorrection(createHeader(), correctionInfo); |
| 290 |
return true; |
| 291 |
} catch (RemoteException e) { |
| 292 |
return false; |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
@AnyThread |
| 305 |
public boolean setSelection(int start, int end) { |
| 306 |
try { |
| 307 |
mIInputContext.setSelection(createHeader(), start, end); |
| 308 |
return true; |
| 309 |
} catch (RemoteException e) { |
| 310 |
return false; |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
@AnyThread |
| 322 |
public boolean performEditorAction(int actionCode) { |
| 323 |
try { |
| 324 |
mIInputContext.performEditorAction(createHeader(), actionCode); |
| 325 |
return true; |
| 326 |
} catch (RemoteException e) { |
| 327 |
return false; |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
@AnyThread |
| 339 |
public boolean performContextMenuAction(int id) { |
| 340 |
try { |
| 341 |
mIInputContext.performContextMenuAction(createHeader(), id); |
| 342 |
return true; |
| 343 |
} catch (RemoteException e) { |
| 344 |
return false; |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
@AnyThread |
| 357 |
public boolean setComposingRegion(int start, int end) { |
| 358 |
try { |
| 359 |
mIInputContext.setComposingRegion(createHeader(), start, end); |
| 360 |
return true; |
| 361 |
} catch (RemoteException e) { |
| 362 |
return false; |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
@AnyThread |
| 377 |
public boolean setComposingRegion(int start, int end, @Nullable TextAttribute textAttribute) { |
| 378 |
try { |
| 379 |
mIInputContext.setComposingRegionWithTextAttribute( |
| 380 |
createHeader(), start, end, textAttribute); |
| 381 |
return true; |
| 382 |
} catch (RemoteException e) { |
| 383 |
return false; |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
@AnyThread |
| 397 |
public boolean setComposingText(CharSequence text, int newCursorPosition) { |
| 398 |
try { |
| 399 |
mIInputContext.setComposingText(createHeader(), text, newCursorPosition); |
| 400 |
return true; |
| 401 |
} catch (RemoteException e) { |
| 402 |
return false; |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
@AnyThread |
| 417 |
public boolean setComposingText(CharSequence text, int newCursorPosition, |
| 418 |
@Nullable TextAttribute textAttribute) { |
| 419 |
try { |
| 420 |
mIInputContext.setComposingTextWithTextAttribute( |
| 421 |
createHeader(), text, newCursorPosition, textAttribute); |
| 422 |
return true; |
| 423 |
} catch (RemoteException e) { |
| 424 |
return false; |
| 425 |
} |
| 426 |
} |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
@AnyThread |
| 435 |
public boolean finishComposingText() { |
| 436 |
try { |
| 437 |
mIInputContext.finishComposingText(createHeader()); |
| 438 |
return true; |
| 439 |
} catch (RemoteException e) { |
| 440 |
return false; |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
@AnyThread |
| 451 |
public boolean beginBatchEdit() { |
| 452 |
try { |
| 453 |
mIInputContext.beginBatchEdit(createHeader()); |
| 454 |
return true; |
| 455 |
} catch (RemoteException e) { |
| 456 |
return false; |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
@AnyThread |
| 467 |
public boolean endBatchEdit() { |
| 468 |
try { |
| 469 |
mIInputContext.endBatchEdit(createHeader()); |
| 470 |
return true; |
| 471 |
} catch (RemoteException e) { |
| 472 |
return false; |
| 473 |
} |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
@AnyThread |
| 484 |
public boolean sendKeyEvent(KeyEvent event) { |
| 485 |
try { |
| 486 |
mIInputContext.sendKeyEvent(createHeader(), event); |
| 487 |
return true; |
| 488 |
} catch (RemoteException e) { |
| 489 |
return false; |
| 490 |
} |
| 491 |
} |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
@AnyThread |
| 501 |
public boolean clearMetaKeyStates(int states) { |
| 502 |
try { |
| 503 |
mIInputContext.clearMetaKeyStates(createHeader(), states); |
| 504 |
return true; |
| 505 |
} catch (RemoteException e) { |
| 506 |
return false; |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
@AnyThread |
| 519 |
public boolean deleteSurroundingText(int beforeLength, int afterLength) { |
| 520 |
try { |
| 521 |
mIInputContext.deleteSurroundingText(createHeader(), beforeLength, afterLength); |
| 522 |
return true; |
| 523 |
} catch (RemoteException e) { |
| 524 |
return false; |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
@AnyThread |
| 538 |
public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) { |
| 539 |
try { |
| 540 |
mIInputContext.deleteSurroundingTextInCodePoints(createHeader(), beforeLength, |
| 541 |
afterLength); |
| 542 |
return true; |
| 543 |
} catch (RemoteException e) { |
| 544 |
return false; |
| 545 |
} |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
@AnyThread |
| 555 |
public boolean performSpellCheck() { |
| 556 |
try { |
| 557 |
mIInputContext.performSpellCheck(createHeader()); |
| 558 |
return true; |
| 559 |
} catch (RemoteException e) { |
| 560 |
return false; |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
@AnyThread |
| 574 |
public boolean performPrivateCommand(String action, Bundle data) { |
| 575 |
try { |
| 576 |
mIInputContext.performPrivateCommand(createHeader(), action, data); |
| 577 |
return true; |
| 578 |
} catch (RemoteException e) { |
| 579 |
return false; |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
@AnyThread |
| 593 |
@NonNull |
| 594 |
public AndroidFuture<Boolean> requestCursorUpdates(int cursorUpdateMode, int imeDisplayId) { |
| 595 |
final AndroidFuture<Boolean> future = new AndroidFuture<>(); |
| 596 |
try { |
| 597 |
mIInputContext.requestCursorUpdates(createHeader(), cursorUpdateMode, imeDisplayId, |
| 598 |
future); |
| 599 |
} catch (RemoteException e) { |
| 600 |
future.completeExceptionally(e); |
| 601 |
} |
| 602 |
return future; |
| 603 |
} |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
@AnyThread |
| 616 |
@NonNull |
| 617 |
public AndroidFuture<Boolean> requestCursorUpdates(int cursorUpdateMode, int cursorUpdateFilter, |
| 618 |
int imeDisplayId) { |
| 619 |
final AndroidFuture<Boolean> future = new AndroidFuture<>(); |
| 620 |
try { |
| 621 |
mIInputContext.requestCursorUpdatesWithFilter(createHeader(), cursorUpdateMode, |
| 622 |
cursorUpdateFilter, imeDisplayId, future); |
| 623 |
} catch (RemoteException e) { |
| 624 |
future.completeExceptionally(e); |
| 625 |
} |
| 626 |
return future; |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
@AnyThread |
| 640 |
@NonNull |
| 641 |
public AndroidFuture<Boolean> commitContent(InputContentInfo inputContentInfo, int flags, |
| 642 |
Bundle opts) { |
| 643 |
final AndroidFuture<Boolean> future = new AndroidFuture<>(); |
| 644 |
try { |
| 645 |
mIInputContext.commitContent(createHeader(), inputContentInfo, flags, opts, future); |
| 646 |
} catch (RemoteException e) { |
| 647 |
future.completeExceptionally(e); |
| 648 |
} |
| 649 |
return future; |
| 650 |
} |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
@AnyThread |
| 660 |
public boolean setImeConsumesInput(boolean imeConsumesInput) { |
| 661 |
try { |
| 662 |
mIInputContext.setImeConsumesInput(createHeader(), imeConsumesInput); |
| 663 |
return true; |
| 664 |
} catch (RemoteException e) { |
| 665 |
return false; |
| 666 |
} |
| 667 |
} |
| 668 |
} |