diff options
| author | Yohei Yukawa <yukawa@google.com> | 2021-09-15 10:03:20 -0700 |
|---|---|---|
| committer | Yohei Yukawa <yukawa@google.com> | 2021-09-15 10:03:20 -0700 |
| commit | e8424ef6004ac39c5ba6af458b863d2e110ce8f9 (patch) | |
| tree | 5ada5b8c97244a60b4575d84af961bf82ea9afbb /core/java/android/inputmethodservice/RemoteInputConnection.java | |
| parent | 37118263f951f9753bfdbf4dc049f4727bcd6553 (diff) | |
Deprecate MissingMethodFlags to preserve invocation order
This CL effectively replaces my previous CL [1], which made
unimplemented methods in InputConnection not fatal errors, with a
simplified implementation that still gracefully take care of
unimplemented methods without causing app crashes.
Instead of propagating missing method information from the IME client
to the IME process, this CL will simply catch AbstractMethodError in
the IME client process. Doing so enables us to
1. preserve the strict invocation order of InputConnection APIs, and
2. achieve the same goal with fewer lines of code.
The additional cost of throwing (and catching) AbstractMethodError
every time the IME calls an unimplemented InputConnection API can be
justified as it is really an exceptional scenario, and avoiding it
would require extra maintenance cost as seen in
InputConnectionInspector.
The above overhead (and complexity) due to AbstractMethodError can be
avoided by adding default implementations to those InputConnection
APIs, but doing so requires API signature update hence API council
approval to go ahead, which is to be discussed in Bug 199934664.
[1]: I3c58fadd924fad72cb984f0c23d3099fd0295c64
19a80a1e807acd00bec999eaac7812da6ffce954
Bug: 27407234
Bug: 27642734
Bug: 27650039
Bug: 194110780
Test: atest CtsInputMethodTestCases
Change-Id: I9e801e92496a6e16cee37664870c97ed096f1413
Diffstat (limited to 'core/java/android/inputmethodservice/RemoteInputConnection.java')
| -rw-r--r-- | core/java/android/inputmethodservice/RemoteInputConnection.java | 48 |
1 files changed, 2 insertions, 46 deletions
diff --git a/core/java/android/inputmethodservice/RemoteInputConnection.java b/core/java/android/inputmethodservice/RemoteInputConnection.java index 589dd7255a62..657f8428179f 100644 --- a/core/java/android/inputmethodservice/RemoteInputConnection.java +++ b/core/java/android/inputmethodservice/RemoteInputConnection.java @@ -29,8 +29,6 @@ import android.view.inputmethod.CorrectionInfo; import android.view.inputmethod.ExtractedText; import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.InputConnection; -import android.view.inputmethod.InputConnectionInspector; -import android.view.inputmethod.InputConnectionInspector.MissingMethodFlags; import android.view.inputmethod.InputContentInfo; import android.view.inputmethod.SurroundingText; @@ -87,9 +85,6 @@ final class RemoteInputConnection implements InputConnection { @NonNull private final InputMethodServiceInternalHolder mImsInternal; - @MissingMethodFlags - private final int mMissingMethods; - /** * Signaled when the system decided to take away IME focus from the target app. * @@ -101,11 +96,9 @@ final class RemoteInputConnection implements InputConnection { RemoteInputConnection( @NonNull WeakReference<InputMethodServiceInternal> inputMethodService, - IInputContext inputContext, @MissingMethodFlags int missingMethods, - @NonNull CancellationGroup cancellationGroup) { + IInputContext inputContext, @NonNull CancellationGroup cancellationGroup) { mImsInternal = new InputMethodServiceInternalHolder(inputMethodService); mInvoker = IInputContextInvoker.create(inputContext); - mMissingMethods = missingMethods; mCancellationGroup = cancellationGroup; } @@ -163,10 +156,6 @@ final class RemoteInputConnection implements InputConnection { return null; } - if (isMethodMissing(MissingMethodFlags.GET_SELECTED_TEXT)) { - // This method is not implemented. - return null; - } final CompletableFuture<CharSequence> value = mInvoker.getSelectedText(flags); final CharSequence result = CompletableFutureUtil.getResultOrNull( value, TAG, "getSelectedText()", mCancellationGroup, MAX_WAIT_TIME_MILLIS); @@ -200,10 +189,6 @@ final class RemoteInputConnection implements InputConnection { return null; } - if (isMethodMissing(MissingMethodFlags.GET_SURROUNDING_TEXT)) { - // This method is not implemented. - return null; - } final CompletableFuture<SurroundingText> value = mInvoker.getSurroundingText(beforeLength, afterLength, flags); final SurroundingText result = CompletableFutureUtil.getResultOrNull( @@ -284,10 +269,6 @@ final class RemoteInputConnection implements InputConnection { @AnyThread public boolean commitCorrection(CorrectionInfo correctionInfo) { - if (isMethodMissing(MissingMethodFlags.COMMIT_CORRECTION)) { - // This method is not implemented. - return false; - } return mInvoker.commitCorrection(correctionInfo); } @@ -308,10 +289,6 @@ final class RemoteInputConnection implements InputConnection { @AnyThread public boolean setComposingRegion(int start, int end) { - if (isMethodMissing(MissingMethodFlags.SET_COMPOSING_REGION)) { - // This method is not implemented. - return false; - } return mInvoker.setComposingRegion(start, end); } @@ -360,10 +337,6 @@ final class RemoteInputConnection implements InputConnection { @AnyThread public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) { - if (isMethodMissing(MissingMethodFlags.DELETE_SURROUNDING_TEXT_IN_CODE_POINTS)) { - // This method is not implemented. - return false; - } return mInvoker.deleteSurroundingTextInCodePoints(beforeLength, afterLength); } @@ -389,11 +362,6 @@ final class RemoteInputConnection implements InputConnection { return false; } - if (isMethodMissing(MissingMethodFlags.REQUEST_CURSOR_UPDATES)) { - // This method is not implemented. - return false; - } - final InputMethodServiceInternal ims = mImsInternal.getAndWarnIfNull(); if (ims == null) { return false; @@ -423,11 +391,6 @@ final class RemoteInputConnection implements InputConnection { return false; } - if (isMethodMissing(MissingMethodFlags.COMMIT_CONTENT)) { - // This method is not implemented. - return false; - } - if ((flags & InputConnection.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) { final InputMethodServiceInternal imsInternal = mImsInternal.getAndWarnIfNull(); if (imsInternal == null) { @@ -451,16 +414,9 @@ final class RemoteInputConnection implements InputConnection { } @AnyThread - private boolean isMethodMissing(@MissingMethodFlags final int methodFlag) { - return (mMissingMethods & methodFlag) == methodFlag; - } - - @AnyThread @Override public String toString() { return "RemoteInputConnection{idHash=#" - + Integer.toHexString(System.identityHashCode(this)) - + " mMissingMethods=" - + InputConnectionInspector.getMissingMethodFlagsAsString(mMissingMethods) + "}"; + + Integer.toHexString(System.identityHashCode(this)) + "}"; } } |
