Skip to content

Commit 68dec77

Browse files
brettchabotcopybara-androidxtest
authored andcommitted
Remove all remaining special case handling for SDKs < 23.
Now that minSdkVersion is 23, remove all special case handling for SDKs less than that. PiperOrigin-RevId: 789852908
1 parent a2f40ad commit 68dec77

File tree

14 files changed

+19
-177
lines changed

14 files changed

+19
-177
lines changed

espresso/core/java/androidx/test/espresso/base/InputManagerEventInjectionStrategy.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ final class InputManagerEventInjectionStrategy implements EventInjectionStrategy
4949
new ReflectiveMethod<>(
5050
InputManager.class, "injectInputEvent", InputEvent.class, Integer.TYPE);
5151

52-
// only used on APIs < 23
53-
private final ReflectiveMethod<InputManager> getInstanceMethod =
54-
new ReflectiveMethod<>(InputManager.class, "getInstance");
55-
;
56-
5752
// hardcoded copies of private InputManager fields.
5853
// historically these were obtained via reflection, but that seems
5954
// wasteful as these values have not changed since they were introduced
@@ -72,7 +67,9 @@ final class InputManagerEventInjectionStrategy implements EventInjectionStrategy
7267
public boolean injectKeyEvent(KeyEvent keyEvent) throws InjectEventSecurityException {
7368
try {
7469
return injectInputEventMethod.invoke(
75-
getInputManager(), keyEvent, INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
70+
getContext().getSystemService(InputManager.class),
71+
keyEvent,
72+
INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
7673
} catch (ReflectionException e) {
7774
// annoyingly, ReflectiveMethod always rewraps the underlying exception
7875
Throwable cause = e.getCause().getCause();
@@ -104,7 +101,8 @@ private boolean innerInjectMotionEvent(MotionEvent motionEvent, boolean shouldRe
104101
}
105102
int eventMode =
106103
sync ? INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH : INJECT_INPUT_EVENT_MODE_ASYNC;
107-
return injectInputEventMethod.invoke(getInputManager(), motionEvent, eventMode);
104+
return injectInputEventMethod.invoke(
105+
getContext().getSystemService(InputManager.class), motionEvent, eventMode);
108106
} catch (ReflectionException e) {
109107
Throwable cause = e.getCause().getCause();
110108
if (cause instanceof SecurityException) {
@@ -140,14 +138,6 @@ private static boolean isFromTouchpadInGlassDevice(MotionEvent motionEvent) {
140138
&& ((motionEvent.getSource() & InputDevice.SOURCE_TOUCHPAD) != 0);
141139
}
142140

143-
private InputManager getInputManager() {
144-
if (Build.VERSION.SDK_INT < 23) {
145-
return getInstanceMethod.invokeStatic();
146-
} else {
147-
return getContext().getSystemService(InputManager.class);
148-
}
149-
}
150-
151141
private static Context getContext() {
152142
try {
153143
return InstrumentationRegistry.getInstrumentation().getTargetContext();

espresso/core/java/androidx/test/espresso/matcher/ViewMatchers.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import android.content.res.Resources;
2828
import android.graphics.Color;
2929
import android.graphics.Rect;
30-
import android.os.Build;
3130
import android.util.DisplayMetrics;
3231
import android.util.TypedValue;
3332
import android.view.View;
@@ -1709,13 +1708,7 @@ public static Matcher<View> hasTextColor(final int colorResId) {
17091708
protected boolean matchesSafely(TextView textView, Description mismatchDescription) {
17101709
context = textView.getContext();
17111710
int textViewColor = textView.getCurrentTextColor();
1712-
int expectedColor;
1713-
1714-
if (Build.VERSION.SDK_INT <= 22) {
1715-
expectedColor = context.getResources().getColor(colorResId);
1716-
} else {
1717-
expectedColor = context.getColor(colorResId);
1718-
}
1711+
int expectedColor = context.getColor(colorResId);
17191712

17201713
mismatchDescription
17211714
.appendText("textView.getCurrentTextColor() was ")
@@ -1729,10 +1722,7 @@ protected void describeMoreTo(Description description) {
17291722
if (context == null) {
17301723
description.appendText("ID ").appendValue(colorResId);
17311724
} else {
1732-
int color =
1733-
(Build.VERSION.SDK_INT <= 22)
1734-
? context.getResources().getColor(colorResId)
1735-
: context.getColor(colorResId);
1725+
int color = context.getColor(colorResId);
17361726
description.appendText("value " + getColorHex(color));
17371727
}
17381728
}

espresso/core/javatests/androidx/test/espresso/action/ClickActionIntegrationTest.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
2323
import static androidx.test.espresso.matcher.ViewMatchers.withId;
2424
import static androidx.test.espresso.matcher.ViewMatchers.withText;
25-
import static org.junit.Assert.assertTrue;
2625

2726
import android.view.InputDevice;
2827
import android.view.MotionEvent;
2928
import androidx.test.ext.junit.rules.ActivityScenarioRule;
3029
import androidx.test.ext.junit.runners.AndroidJUnit4;
3130
import androidx.test.filters.LargeTest;
32-
import androidx.test.filters.SdkSuppress;
3331
import androidx.test.ui.app.LargeViewActivity;
3432
import androidx.test.ui.app.R;
3533
import org.junit.Rule;
@@ -60,17 +58,4 @@ public void rightClickTest() {
6058
onView(withText(R.string.context_item_2_text)).check(matches(isDisplayed()));
6159
onView(withText(R.string.context_item_3_text)).check(matches(isDisplayed()));
6260
}
63-
64-
@Test
65-
@SdkSuppress(maxSdkVersion = 13)
66-
public void rightClickTest_unsupportedApiLevel() {
67-
boolean exceptionThrown = false;
68-
try {
69-
onView(withId(R.id.large_view)).perform(click(0, 0));
70-
} catch (UnsupportedOperationException e) {
71-
exceptionThrown = true;
72-
} finally {
73-
assertTrue(exceptionThrown);
74-
}
75-
}
7661
}

espresso/core/javatests/androidx/test/espresso/matcher/ViewMatchers1Test.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import android.graphics.Color;
5858
import android.graphics.Point;
5959
import android.graphics.Rect;
60-
import android.os.Build;
6160
import android.text.SpannedString;
6261
import android.text.method.TransformationMethod;
6362
import android.view.View;
@@ -576,13 +575,7 @@ public void hasTextColorTest() {
576575
TextView textView = new TextView(context);
577576
textView.setText("text");
578577

579-
int color;
580-
if (Build.VERSION.SDK_INT <= 22) {
581-
color = context.getResources().getColor(R.color.green);
582-
} else {
583-
color = context.getColor(R.color.green);
584-
}
585-
578+
int color = context.getColor(R.color.green);
586579
textView.setTextColor(color);
587580

588581
assertTrue(hasTextColor(R.color.green).matches(textView));

runner/android_junit_runner/javatests/androidx/test/runner/permission/PermissionRequesterTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import android.content.Context;
3030
import android.os.Build;
3131
import androidx.test.ext.junit.runners.AndroidJUnit4;
32-
import androidx.test.filters.SdkSuppress;
3332
import androidx.test.filters.SmallTest;
3433
import androidx.test.runner.permission.RequestPermissionCallable.Result;
3534
import org.junit.Before;
@@ -67,7 +66,6 @@ public void initMocks() {
6766
}
6867

6968
@Test
70-
@SdkSuppress(minSdkVersion = 23)
7169
public void permissionAddsPermissionToSet() {
7270
RequestPermissionCallable requestPermissionCallable1 =
7371
withGrantPermissionCallable(RUNTIME_PERMISSION1);
@@ -90,14 +88,12 @@ public void permissionAddsPermissionToSet() {
9088
}
9189

9290
@Test
93-
@SdkSuppress(minSdkVersion = 23)
9491
public void duplicatePermissionThrows() {
9592
expected.expect(IllegalStateException.class);
9693
permissionRequester.addPermissions(RUNTIME_PERMISSION1, RUNTIME_PERMISSION1);
9794
}
9895

9996
@Test
100-
@SdkSuppress(minSdkVersion = 23)
10197
public void requestPermission_SuccessInGrantingPermissionRunsTest() throws Throwable {
10298
RequestPermissionCallable stubbedCallable = withStubbedCallable(Result.SUCCESS);
10399

@@ -107,7 +103,6 @@ public void requestPermission_SuccessInGrantingPermissionRunsTest() throws Throw
107103
}
108104

109105
@Test
110-
@SdkSuppress(minSdkVersion = 23)
111106
public void failureInGrantingPermissionFailsTest() throws Throwable {
112107
expected.expect(AssertionError.class);
113108

@@ -119,7 +114,6 @@ public void failureInGrantingPermissionFailsTest() throws Throwable {
119114
}
120115

121116
@Test
122-
@SdkSuppress(minSdkVersion = 23)
123117
public void callableThrowsExceptionFailsTest() throws Throwable {
124118
expected.expect(AssertionError.class);
125119

runner/android_junit_runner/javatests/androidx/test/runner/permission/UiAutomationShellCommandTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.junit.Assert.assertTrue;
2222

2323
import androidx.test.ext.junit.runners.AndroidJUnit4;
24-
import androidx.test.filters.SdkSuppress;
2524
import androidx.test.filters.SmallTest;
2625
import androidx.test.runner.permission.UiAutomationShellCommand.PmCommand;
2726
import org.junit.Test;
@@ -36,13 +35,7 @@ public class UiAutomationShellCommandTest {
3635

3736
private static final String RUNTIME_PERMISSION1 = "android.permission.PERMISSION1";
3837

39-
// Placeholder test to avoid the 'empty test suite' error on < sdk 23.
4038
@Test
41-
@SdkSuppress(maxSdkVersion = 22)
42-
public void emptyTest() {}
43-
44-
@Test
45-
@SdkSuppress(minSdkVersion = 23)
4639
public void commandForPermission() {
4740
assertTrue(true);
4841
UiAutomationShellCommand shellCmdGrant =

runner/rules/java/androidx/test/api/current_public.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ package androidx.test.rule {
6161

6262
package androidx.test.rule.logging {
6363

64-
@Deprecated @RequiresApi(21) public class AtraceLogger {
64+
@Deprecated public class AtraceLogger {
6565
method @Deprecated public void atraceStart(java.util.Set<java.lang.String!>!, int, int, java.io.File!, String!) throws java.io.IOException;
6666
method @Deprecated public void atraceStop() throws java.io.IOException, java.lang.InterruptedException;
6767
method @Deprecated public static androidx.test.rule.logging.AtraceLogger! getAtraceLoggerInstance(android.app.Instrumentation!);

runner/rules/java/androidx/test/rule/logging/AtraceLogger.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717

1818
import android.app.Instrumentation;
1919
import android.app.UiAutomation;
20-
import android.os.Build.VERSION;
2120
import android.os.ParcelFileDescriptor;
2221
import android.util.Log;
23-
import androidx.annotation.RequiresApi;
2422
import java.io.ByteArrayOutputStream;
2523
import java.io.File;
2624
import java.io.FileOutputStream;
@@ -35,12 +33,8 @@
3533
/**
3634
* Class contains helper methods to dump atrace info asynchronously while running the test case.
3735
*
38-
* <p>Supported only for minsdk version 21 and above because of UiAutomation#executeShellCommand
39-
* availability.
40-
*
4136
* @deprecated unsupported. Consider running trace from host such as via Android Studio
4237
*/
43-
@RequiresApi(21)
4438
@Deprecated
4539
public class AtraceLogger {
4640

@@ -70,9 +64,6 @@ private AtraceLogger(Instrumentation instrumentation) {
7064
* @return instance of the AtraceLogger
7165
*/
7266
public static AtraceLogger getAtraceLoggerInstance(Instrumentation instrumentation) {
73-
if (VERSION.SDK_INT < 21) {
74-
throw new UnsupportedOperationException("AtraceLogger is only supported on APIs >= 21");
75-
}
7667
if (loggerInstance == null) {
7768
synchronized (AtraceLogger.class) {
7869
if (loggerInstance == null) {

services/shellexecutor/javatests/androidx/test/services/shellexecutor/ShellCommandLocalSocketExecutorServerTest.kt

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package androidx.test.services.shellexecutor
22

33
import android.net.LocalSocket
4-
import android.os.Build
54
import androidx.test.services.shellexecutor.LocalSocketProtocol.addressFromBinderKey
65
import androidx.test.services.shellexecutor.LocalSocketProtocol.hasExited
76
import androidx.test.services.shellexecutor.LocalSocketProtocol.readResponse
@@ -37,23 +36,16 @@ class ShellCommandLocalSocketExecutorServerTest {
3736
} while (!responses.last().hasExited())
3837
server.stop(100.milliseconds)
3938
}
40-
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
41-
// On API 21 and 22, echo only exists as a shell builtin!
42-
assertThat(responses).hasSize(1)
43-
assertThat(responses[0].exitCode).isEqualTo(-1)
44-
assertThat(responses[0].buffer.toStringUtf8()).contains("Permission denied")
45-
} else {
46-
// On rare occasions, the output of the command will come back in two packets! So to keep
47-
// this test from being 1% flaky:
48-
val stdout = buildString {
49-
for (response in responses) {
50-
if (response.buffer.size() > 0) append(response.buffer.toStringUtf8())
51-
}
39+
// On rare occasions, the output of the command will come back in two packets! So to keep
40+
// this test from being 1% flaky:
41+
val stdout = buildString {
42+
for (response in responses) {
43+
if (response.buffer.size() > 0) append(response.buffer.toStringUtf8())
5244
}
53-
assertThat(stdout).isEqualTo("\${POTRZEBIE}\n")
54-
assertThat(responses.last().hasExited()).isTrue()
55-
assertThat(responses.last().exitCode).isEqualTo(0)
5645
}
46+
assertThat(stdout).isEqualTo("\${POTRZEBIE}\n")
47+
assertThat(responses.last().hasExited()).isTrue()
48+
assertThat(responses.last().exitCode).isEqualTo(0)
5749
}
5850

5951
@Test

services/storage/java/androidx/test/services/storage/file/HostedFile.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import android.content.Context;
1919
import android.net.Uri;
20-
import android.os.Build.VERSION;
2120
import android.os.Environment;
2221
import android.os.UserManager;
2322
import android.provider.OpenableColumns;
@@ -154,9 +153,7 @@ public static File getInputRootDirectory(Context context) {
154153

155154
public static File getOutputRootDirectory(Context context) {
156155
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
157-
if (VERSION.SDK_INT < 23) {
158-
return Environment.getExternalStorageDirectory();
159-
} else if (userManager.isSystemUser()) {
156+
if (userManager.isSystemUser()) {
160157
return Environment.getExternalStorageDirectory();
161158
} else {
162159
// using legacy external storage for output in automotive devices where tests run as

0 commit comments

Comments
 (0)