Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2b83476a authored by Lan Wei's avatar Lan Wei
Browse files

API Review: InputConnection error handling is inconsistent

Make BaseInputConnection also throws IllegalArgumentException as API
defined.

Test: atest BaseInputConnectionTest#testInvalidGetTextBeforeOrAfterCursorRequest

BUG: 172313372
Change-Id: Ia99a7e0b6a652bc3995529780ba910fd370d3f5f
parent a401308a
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -43,6 +43,8 @@ import android.view.KeyEvent;
import android.view.OnReceiveContentCallback;
import android.view.OnReceiveContentCallback;
import android.view.View;
import android.view.View;


import com.android.internal.util.Preconditions;

class ComposingText implements NoCopySpan {
class ComposingText implements NoCopySpan {
}
}


@@ -504,7 +506,7 @@ public class BaseInputConnection implements InputConnection {
     */
     */
    @Nullable
    @Nullable
    public CharSequence getTextBeforeCursor(@IntRange(from = 0) int length, int flags) {
    public CharSequence getTextBeforeCursor(@IntRange(from = 0) int length, int flags) {
        if (length < 0) return null;
        Preconditions.checkArgumentNonnegative(length);


        final Editable content = getEditable();
        final Editable content = getEditable();
        if (content == null) return null;
        if (content == null) return null;
@@ -563,7 +565,7 @@ public class BaseInputConnection implements InputConnection {
     */
     */
    @Nullable
    @Nullable
    public CharSequence getTextAfterCursor(@IntRange(from = 0) int length, int flags) {
    public CharSequence getTextAfterCursor(@IntRange(from = 0) int length, int flags) {
        if (length < 0) return null;
        Preconditions.checkArgumentNonnegative(length);


        final Editable content = getEditable();
        final Editable content = getEditable();
        if (content == null) return null;
        if (content == null) return null;
@@ -600,7 +602,8 @@ public class BaseInputConnection implements InputConnection {
    @Nullable
    @Nullable
    public SurroundingText getSurroundingText(
    public SurroundingText getSurroundingText(
            @IntRange(from = 0) int beforeLength, @IntRange(from = 0)  int afterLength, int flags) {
            @IntRange(from = 0) int beforeLength, @IntRange(from = 0)  int afterLength, int flags) {
        if (beforeLength < 0 || afterLength < 0) return null;
        Preconditions.checkArgumentNonnegative(beforeLength);
        Preconditions.checkArgumentNonnegative(afterLength);


        final Editable content = getEditable();
        final Editable content = getEditable();
        if (content == null) return null;
        if (content == null) return null;