summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yohei Yukawa <yukawa@google.com> 2023-05-09 16:13:33 +0000
committer Yohei Yukawa <yukawa@google.com> 2023-05-09 16:13:33 +0000
commit2fdfaa2a07534752d16e9dbc43fa45926b627fc5 (patch)
treeaa84921a7e8f1e100e9151ef10a6e0375ee426a4
parent7c8d60cd6630f45b233de2729f1cf5a89870ce2b (diff)
Implement InputConnectionWrapper#replaceText()
This is a follow up CL to our previous CL [1], which forgot to implement InputConnectionWrapper#replaceText(). As a result, it has alreays fallen back to the slow path even if the wrapped InputConnection does have more efficient implementation of InputConnection#replaceText(). With this CL, wrapped InputConnection can also start taking advantage of the optimized version of InputConnection#replaceText() if available. This CL also adds InputConnectionWrapperTest#verifyAllMethodsWrapped() to verify that tall the default methods defined in InputConnection are implemented in InputConnectionWrapper. [1]: Ia0e42270cfae112fcf19205a7151e4ab4ac4afdd d5d530ad63dbabc92125213b4823235b0edc6aa9 Bug: 241503197 Fix: 279960381 Fix: 281150084 Test: atest FrameworksCoreTests:InputConnectionWrapperTest Change-Id: I02a3549f72bf969812bb924a51c18fc81a2668af
-rw-r--r--core/java/android/view/inputmethod/InputConnectionWrapper.java14
-rw-r--r--core/tests/coretests/src/com/android/internal/inputmethod/InputConnectionWrapperTest.java45
2 files changed, 59 insertions, 0 deletions
diff --git a/core/java/android/view/inputmethod/InputConnectionWrapper.java b/core/java/android/view/inputmethod/InputConnectionWrapper.java
index 62f3c909dd4f..9c3067ce8d63 100644
--- a/core/java/android/view/inputmethod/InputConnectionWrapper.java
+++ b/core/java/android/view/inputmethod/InputConnectionWrapper.java
@@ -440,4 +440,18 @@ public class InputConnectionWrapper implements InputConnection {
public TextSnapshot takeSnapshot() {
return mTarget.takeSnapshot();
}
+
+ /**
+ * {@inheritDoc}
+ * @throws NullPointerException if the target is {@code null}.
+ */
+ @Override
+ public boolean replaceText(
+ @IntRange(from = 0) int start,
+ @IntRange(from = 0) int end,
+ @NonNull CharSequence text,
+ int newCursorPosition,
+ @Nullable TextAttribute textAttribute) {
+ return mTarget.replaceText(start, end, text, newCursorPosition, textAttribute);
+ }
}
diff --git a/core/tests/coretests/src/com/android/internal/inputmethod/InputConnectionWrapperTest.java b/core/tests/coretests/src/com/android/internal/inputmethod/InputConnectionWrapperTest.java
new file mode 100644
index 000000000000..a6262944e8b0
--- /dev/null
+++ b/core/tests/coretests/src/com/android/internal/inputmethod/InputConnectionWrapperTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.inputmethod;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.platform.test.annotations.Presubmit;
+import android.view.inputmethod.InputConnection;
+import android.view.inputmethod.InputConnectionWrapper;
+
+import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+@SmallTest
+@Presubmit
+@RunWith(AndroidJUnit4.class)
+public class InputConnectionWrapperTest {
+ @Test
+ public void verifyAllMethodsWrapped() {
+ final var notWrapped = Arrays.stream(InputConnectionWrapper.class.getMethods()).filter(
+ method -> method.isDefault() && method.getDeclaringClass() == InputConnection.class
+ ).collect(Collectors.toList());
+ assertThat(notWrapped).isEmpty();
+ }
+}