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
d5d530ad63
Bug: 241503197
Fix: 279960381
Fix: 281150084
Test: atest FrameworksCoreTests:InputConnectionWrapperTest
Change-Id: I02a3549f72bf969812bb924a51c18fc81a2668af
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user