diff --git a/espresso/core/java/androidx/test/espresso/base/InputManagerEventInjectionStrategy.java b/espresso/core/java/androidx/test/espresso/base/InputManagerEventInjectionStrategy.java index 85a937dbb..fa28796ee 100644 --- a/espresso/core/java/androidx/test/espresso/base/InputManagerEventInjectionStrategy.java +++ b/espresso/core/java/androidx/test/espresso/base/InputManagerEventInjectionStrategy.java @@ -49,11 +49,6 @@ final class InputManagerEventInjectionStrategy implements EventInjectionStrategy new ReflectiveMethod<>( InputManager.class, "injectInputEvent", InputEvent.class, Integer.TYPE); - // only used on APIs < 23 - private final ReflectiveMethod getInstanceMethod = - new ReflectiveMethod<>(InputManager.class, "getInstance"); - ; - // hardcoded copies of private InputManager fields. // historically these were obtained via reflection, but that seems // wasteful as these values have not changed since they were introduced @@ -72,7 +67,9 @@ final class InputManagerEventInjectionStrategy implements EventInjectionStrategy public boolean injectKeyEvent(KeyEvent keyEvent) throws InjectEventSecurityException { try { return injectInputEventMethod.invoke( - getInputManager(), keyEvent, INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); + getContext().getSystemService(InputManager.class), + keyEvent, + INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH); } catch (ReflectionException e) { // annoyingly, ReflectiveMethod always rewraps the underlying exception Throwable cause = e.getCause().getCause(); @@ -104,7 +101,8 @@ private boolean innerInjectMotionEvent(MotionEvent motionEvent, boolean shouldRe } int eventMode = sync ? INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH : INJECT_INPUT_EVENT_MODE_ASYNC; - return injectInputEventMethod.invoke(getInputManager(), motionEvent, eventMode); + return injectInputEventMethod.invoke( + getContext().getSystemService(InputManager.class), motionEvent, eventMode); } catch (ReflectionException e) { Throwable cause = e.getCause().getCause(); if (cause instanceof SecurityException) { @@ -140,14 +138,6 @@ private static boolean isFromTouchpadInGlassDevice(MotionEvent motionEvent) { && ((motionEvent.getSource() & InputDevice.SOURCE_TOUCHPAD) != 0); } - private InputManager getInputManager() { - if (Build.VERSION.SDK_INT < 23) { - return getInstanceMethod.invokeStatic(); - } else { - return getContext().getSystemService(InputManager.class); - } - } - private static Context getContext() { try { return InstrumentationRegistry.getInstrumentation().getTargetContext(); diff --git a/espresso/core/java/androidx/test/espresso/matcher/ViewMatchers.java b/espresso/core/java/androidx/test/espresso/matcher/ViewMatchers.java index 4e58a336e..4246e8d2f 100644 --- a/espresso/core/java/androidx/test/espresso/matcher/ViewMatchers.java +++ b/espresso/core/java/androidx/test/espresso/matcher/ViewMatchers.java @@ -27,7 +27,6 @@ import android.content.res.Resources; import android.graphics.Color; import android.graphics.Rect; -import android.os.Build; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.View; @@ -1709,13 +1708,7 @@ public static Matcher hasTextColor(final int colorResId) { protected boolean matchesSafely(TextView textView, Description mismatchDescription) { context = textView.getContext(); int textViewColor = textView.getCurrentTextColor(); - int expectedColor; - - if (Build.VERSION.SDK_INT <= 22) { - expectedColor = context.getResources().getColor(colorResId); - } else { - expectedColor = context.getColor(colorResId); - } + int expectedColor = context.getColor(colorResId); mismatchDescription .appendText("textView.getCurrentTextColor() was ") @@ -1729,10 +1722,7 @@ protected void describeMoreTo(Description description) { if (context == null) { description.appendText("ID ").appendValue(colorResId); } else { - int color = - (Build.VERSION.SDK_INT <= 22) - ? context.getResources().getColor(colorResId) - : context.getColor(colorResId); + int color = context.getColor(colorResId); description.appendText("value " + getColorHex(color)); } } diff --git a/espresso/core/javatests/androidx/test/espresso/action/ClickActionIntegrationTest.java b/espresso/core/javatests/androidx/test/espresso/action/ClickActionIntegrationTest.java index ef9728bef..e8483f4d3 100644 --- a/espresso/core/javatests/androidx/test/espresso/action/ClickActionIntegrationTest.java +++ b/espresso/core/javatests/androidx/test/espresso/action/ClickActionIntegrationTest.java @@ -22,14 +22,12 @@ import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; -import static org.junit.Assert.assertTrue; import android.view.InputDevice; import android.view.MotionEvent; import androidx.test.ext.junit.rules.ActivityScenarioRule; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; -import androidx.test.filters.SdkSuppress; import androidx.test.ui.app.LargeViewActivity; import androidx.test.ui.app.R; import org.junit.Rule; @@ -60,17 +58,4 @@ public void rightClickTest() { onView(withText(R.string.context_item_2_text)).check(matches(isDisplayed())); onView(withText(R.string.context_item_3_text)).check(matches(isDisplayed())); } - - @Test - @SdkSuppress(maxSdkVersion = 13) - public void rightClickTest_unsupportedApiLevel() { - boolean exceptionThrown = false; - try { - onView(withId(R.id.large_view)).perform(click(0, 0)); - } catch (UnsupportedOperationException e) { - exceptionThrown = true; - } finally { - assertTrue(exceptionThrown); - } - } } diff --git a/espresso/core/javatests/androidx/test/espresso/matcher/ViewMatchers1Test.java b/espresso/core/javatests/androidx/test/espresso/matcher/ViewMatchers1Test.java index f921cc813..cc258f443 100644 --- a/espresso/core/javatests/androidx/test/espresso/matcher/ViewMatchers1Test.java +++ b/espresso/core/javatests/androidx/test/espresso/matcher/ViewMatchers1Test.java @@ -57,7 +57,6 @@ import android.graphics.Color; import android.graphics.Point; import android.graphics.Rect; -import android.os.Build; import android.text.SpannedString; import android.text.method.TransformationMethod; import android.view.View; @@ -576,13 +575,7 @@ public void hasTextColorTest() { TextView textView = new TextView(context); textView.setText("text"); - int color; - if (Build.VERSION.SDK_INT <= 22) { - color = context.getResources().getColor(R.color.green); - } else { - color = context.getColor(R.color.green); - } - + int color = context.getColor(R.color.green); textView.setTextColor(color); assertTrue(hasTextColor(R.color.green).matches(textView)); diff --git a/runner/android_junit_runner/javatests/androidx/test/runner/permission/PermissionRequesterTest.java b/runner/android_junit_runner/javatests/androidx/test/runner/permission/PermissionRequesterTest.java index 2195253c1..9ff6aba55 100644 --- a/runner/android_junit_runner/javatests/androidx/test/runner/permission/PermissionRequesterTest.java +++ b/runner/android_junit_runner/javatests/androidx/test/runner/permission/PermissionRequesterTest.java @@ -29,7 +29,6 @@ import android.content.Context; import android.os.Build; import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.filters.SdkSuppress; import androidx.test.filters.SmallTest; import androidx.test.runner.permission.RequestPermissionCallable.Result; import org.junit.Before; @@ -67,7 +66,6 @@ public void initMocks() { } @Test - @SdkSuppress(minSdkVersion = 23) public void permissionAddsPermissionToSet() { RequestPermissionCallable requestPermissionCallable1 = withGrantPermissionCallable(RUNTIME_PERMISSION1); @@ -90,14 +88,12 @@ public void permissionAddsPermissionToSet() { } @Test - @SdkSuppress(minSdkVersion = 23) public void duplicatePermissionThrows() { expected.expect(IllegalStateException.class); permissionRequester.addPermissions(RUNTIME_PERMISSION1, RUNTIME_PERMISSION1); } @Test - @SdkSuppress(minSdkVersion = 23) public void requestPermission_SuccessInGrantingPermissionRunsTest() throws Throwable { RequestPermissionCallable stubbedCallable = withStubbedCallable(Result.SUCCESS); @@ -107,7 +103,6 @@ public void requestPermission_SuccessInGrantingPermissionRunsTest() throws Throw } @Test - @SdkSuppress(minSdkVersion = 23) public void failureInGrantingPermissionFailsTest() throws Throwable { expected.expect(AssertionError.class); @@ -119,7 +114,6 @@ public void failureInGrantingPermissionFailsTest() throws Throwable { } @Test - @SdkSuppress(minSdkVersion = 23) public void callableThrowsExceptionFailsTest() throws Throwable { expected.expect(AssertionError.class); diff --git a/runner/android_junit_runner/javatests/androidx/test/runner/permission/UiAutomationShellCommandTest.java b/runner/android_junit_runner/javatests/androidx/test/runner/permission/UiAutomationShellCommandTest.java index bc8837cc4..779cba6e6 100644 --- a/runner/android_junit_runner/javatests/androidx/test/runner/permission/UiAutomationShellCommandTest.java +++ b/runner/android_junit_runner/javatests/androidx/test/runner/permission/UiAutomationShellCommandTest.java @@ -21,7 +21,6 @@ import static org.junit.Assert.assertTrue; import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.filters.SdkSuppress; import androidx.test.filters.SmallTest; import androidx.test.runner.permission.UiAutomationShellCommand.PmCommand; import org.junit.Test; @@ -36,13 +35,7 @@ public class UiAutomationShellCommandTest { private static final String RUNTIME_PERMISSION1 = "android.permission.PERMISSION1"; - // Placeholder test to avoid the 'empty test suite' error on < sdk 23. @Test - @SdkSuppress(maxSdkVersion = 22) - public void emptyTest() {} - - @Test - @SdkSuppress(minSdkVersion = 23) public void commandForPermission() { assertTrue(true); UiAutomationShellCommand shellCmdGrant = diff --git a/runner/rules/java/androidx/test/api/current_public.txt b/runner/rules/java/androidx/test/api/current_public.txt index 13716b976..10e704c71 100644 --- a/runner/rules/java/androidx/test/api/current_public.txt +++ b/runner/rules/java/androidx/test/api/current_public.txt @@ -61,7 +61,7 @@ package androidx.test.rule { package androidx.test.rule.logging { - @Deprecated @RequiresApi(21) public class AtraceLogger { + @Deprecated public class AtraceLogger { method @Deprecated public void atraceStart(java.util.Set!, int, int, java.io.File!, String!) throws java.io.IOException; method @Deprecated public void atraceStop() throws java.io.IOException, java.lang.InterruptedException; method @Deprecated public static androidx.test.rule.logging.AtraceLogger! getAtraceLoggerInstance(android.app.Instrumentation!); diff --git a/runner/rules/java/androidx/test/rule/logging/AtraceLogger.java b/runner/rules/java/androidx/test/rule/logging/AtraceLogger.java index b9765615f..ed17ed7e7 100644 --- a/runner/rules/java/androidx/test/rule/logging/AtraceLogger.java +++ b/runner/rules/java/androidx/test/rule/logging/AtraceLogger.java @@ -17,10 +17,8 @@ import android.app.Instrumentation; import android.app.UiAutomation; -import android.os.Build.VERSION; import android.os.ParcelFileDescriptor; import android.util.Log; -import androidx.annotation.RequiresApi; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -35,12 +33,8 @@ /** * Class contains helper methods to dump atrace info asynchronously while running the test case. * - *

Supported only for minsdk version 21 and above because of UiAutomation#executeShellCommand - * availability. - * * @deprecated unsupported. Consider running trace from host such as via Android Studio */ -@RequiresApi(21) @Deprecated public class AtraceLogger { @@ -70,9 +64,6 @@ private AtraceLogger(Instrumentation instrumentation) { * @return instance of the AtraceLogger */ public static AtraceLogger getAtraceLoggerInstance(Instrumentation instrumentation) { - if (VERSION.SDK_INT < 21) { - throw new UnsupportedOperationException("AtraceLogger is only supported on APIs >= 21"); - } if (loggerInstance == null) { synchronized (AtraceLogger.class) { if (loggerInstance == null) { diff --git a/services/shellexecutor/javatests/androidx/test/services/shellexecutor/ShellCommandLocalSocketExecutorServerTest.kt b/services/shellexecutor/javatests/androidx/test/services/shellexecutor/ShellCommandLocalSocketExecutorServerTest.kt index 230ea9820..506ecc02a 100644 --- a/services/shellexecutor/javatests/androidx/test/services/shellexecutor/ShellCommandLocalSocketExecutorServerTest.kt +++ b/services/shellexecutor/javatests/androidx/test/services/shellexecutor/ShellCommandLocalSocketExecutorServerTest.kt @@ -1,7 +1,6 @@ package androidx.test.services.shellexecutor import android.net.LocalSocket -import android.os.Build import androidx.test.services.shellexecutor.LocalSocketProtocol.addressFromBinderKey import androidx.test.services.shellexecutor.LocalSocketProtocol.hasExited import androidx.test.services.shellexecutor.LocalSocketProtocol.readResponse @@ -37,23 +36,16 @@ class ShellCommandLocalSocketExecutorServerTest { } while (!responses.last().hasExited()) server.stop(100.milliseconds) } - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { - // On API 21 and 22, echo only exists as a shell builtin! - assertThat(responses).hasSize(1) - assertThat(responses[0].exitCode).isEqualTo(-1) - assertThat(responses[0].buffer.toStringUtf8()).contains("Permission denied") - } else { - // On rare occasions, the output of the command will come back in two packets! So to keep - // this test from being 1% flaky: - val stdout = buildString { - for (response in responses) { - if (response.buffer.size() > 0) append(response.buffer.toStringUtf8()) - } + // On rare occasions, the output of the command will come back in two packets! So to keep + // this test from being 1% flaky: + val stdout = buildString { + for (response in responses) { + if (response.buffer.size() > 0) append(response.buffer.toStringUtf8()) } - assertThat(stdout).isEqualTo("\${POTRZEBIE}\n") - assertThat(responses.last().hasExited()).isTrue() - assertThat(responses.last().exitCode).isEqualTo(0) } + assertThat(stdout).isEqualTo("\${POTRZEBIE}\n") + assertThat(responses.last().hasExited()).isTrue() + assertThat(responses.last().exitCode).isEqualTo(0) } @Test diff --git a/services/storage/java/androidx/test/services/storage/file/HostedFile.java b/services/storage/java/androidx/test/services/storage/file/HostedFile.java index 70893c7d6..2f331a290 100644 --- a/services/storage/java/androidx/test/services/storage/file/HostedFile.java +++ b/services/storage/java/androidx/test/services/storage/file/HostedFile.java @@ -17,7 +17,6 @@ import android.content.Context; import android.net.Uri; -import android.os.Build.VERSION; import android.os.Environment; import android.os.UserManager; import android.provider.OpenableColumns; @@ -154,9 +153,7 @@ public static File getInputRootDirectory(Context context) { public static File getOutputRootDirectory(Context context) { UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE); - if (VERSION.SDK_INT < 23) { - return Environment.getExternalStorageDirectory(); - } else if (userManager.isSystemUser()) { + if (userManager.isSystemUser()) { return Environment.getExternalStorageDirectory(); } else { // using legacy external storage for output in automotive devices where tests run as diff --git a/services/storage/javatests/androidx/test/services/storage/TestStorageTest.java b/services/storage/javatests/androidx/test/services/storage/TestStorageTest.java index 5822ea016..da8377501 100644 --- a/services/storage/javatests/androidx/test/services/storage/TestStorageTest.java +++ b/services/storage/javatests/androidx/test/services/storage/TestStorageTest.java @@ -23,7 +23,6 @@ import android.content.Context; import android.net.Uri; -import android.os.Build; import android.os.UserManager; import androidx.test.services.storage.file.HostedFile; import androidx.test.services.storage.internal.TestStorageUtil; @@ -122,13 +121,10 @@ public void writeInternalFile() throws IOException { } private static boolean isSystemUser() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { - return true; - } else { + UserManager um = ((UserManager) getApplicationContext().getSystemService(Context.USER_SERVICE)); return um.isSystemUser(); - } } @Test diff --git a/testapps/ui_testapp/javatests/androidx/test/ui/app/ChatHeadActivityTest.java b/testapps/ui_testapp/javatests/androidx/test/ui/app/ChatHeadActivityTest.java index 4f8e7b768..bd5625131 100644 --- a/testapps/ui_testapp/javatests/androidx/test/ui/app/ChatHeadActivityTest.java +++ b/testapps/ui_testapp/javatests/androidx/test/ui/app/ChatHeadActivityTest.java @@ -17,13 +17,10 @@ package androidx.test.ui.app; import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.Espresso.pressBackUnconditionally; import static androidx.test.espresso.action.ViewActions.click; -import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.RootMatchers.withDecorView; import static androidx.test.espresso.matcher.ViewMatchers.isFocusable; import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withTagValue; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertTrue; import static org.hamcrest.Matchers.allOf; @@ -35,11 +32,9 @@ import android.util.Log; import android.view.View; import androidx.test.InstrumentationRegistry; -import androidx.test.filters.SdkSuppress; import androidx.test.filters.SmallTest; import androidx.test.rule.ActivityTestRule; import androidx.test.runner.AndroidJUnit4; -import org.hamcrest.Matchers; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -67,72 +62,6 @@ public void setUp() { public void tearDown() { } - @SdkSuppress(maxSdkVersion = 22) // Requires special permission to draw over other apps - @Test - public void testFindingRootViewWithNotFocusableFlagSetOnTheWindowManager() - throws InterruptedException { - // Create a chat head - onView(withId(R.id.create_chat_head_btn)).perform(click()); - - // Verify chat head changed color - onView(withId(R.id.chat_head_btn_id)) - .inRoot(withDecorView(not(is(activity.getWindow().getDecorView())))) - .check(matches(withTagValue((Matchers.is((Object) "red"))))); - - // Preform a click on the chat head button - Log.d(TAG, "click on chat chat head..."); - clickOnChatHead(); - Log.d(TAG, "click on chat chat head..."); - clickOnChatHead(); - Log.d(TAG, "click on chat chat head..."); - clickOnChatHead(); - - // Verify chat head changed color - onView(withId(R.id.chat_head_btn_id)) - .inRoot(withDecorView(not(is(activity.getWindow().getDecorView())))) - .check(matches(withTagValue((Matchers.is((Object) "blue"))))); - - // Preform a click on the chat head button - Log.d(TAG, "click on chat chat head..."); - clickOnChatHead(); - - // Verify chat head changed color - onView(withId(R.id.chat_head_btn_id)) - .inRoot(withDecorView(not(is(activity.getWindow().getDecorView())))) - .check(matches(withTagValue((Matchers.is((Object) "red"))))); - - // Destroy chat head - onView(withId(R.id.destroy_chat_head_btn)).perform(click()); - } - - @SdkSuppress(maxSdkVersion = 22) // Requires special permission to draw over other apps - @Test - public void testNoActivityApi() throws InterruptedException { - // Create a chat head - onView(withId(R.id.create_chat_head_btn)).perform(click()); - - // Verify chat head changed color - Log.d(TAG, "Varying chat head color is red"); - onView(withId(R.id.chat_head_btn_id)) - .inRoot(withDecorView(not(is(activity.getWindow().getDecorView())))) - .check(matches(withTagValue((Matchers.is((Object) "red"))))); - - Log.d(TAG, "click on chat chat head..."); - clickOnChatHead(); - - Log.d(TAG, "pressBack"); - pressBackUnconditionally(); - - Log.d(TAG, "click on chat chat head..."); - onView(withId(R.id.chat_head_btn_id)).noActivity().perform(click()); - - // Verify chat head changed color - Log.d(TAG, "Varying chat head color is red"); - onView(withId(R.id.chat_head_btn_id)) - .noActivity() - .check(matches(withTagValue((Matchers.is((Object) "red"))))); - } - /** Helper method to click on the chat head */ private void clickOnChatHead() { onView(withId(R.id.chat_head_btn_id)) diff --git a/testapps/ui_testapp/javatests/androidx/test/ui/app/DrawerActionsTest.java b/testapps/ui_testapp/javatests/androidx/test/ui/app/DrawerActionsTest.java index f9664ba73..c09fb5b8f 100644 --- a/testapps/ui_testapp/javatests/androidx/test/ui/app/DrawerActionsTest.java +++ b/testapps/ui_testapp/javatests/androidx/test/ui/app/DrawerActionsTest.java @@ -34,7 +34,6 @@ import androidx.test.espresso.contrib.DrawerActions; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; -import androidx.test.filters.SdkSuppress; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,7 +49,6 @@ public void setUp() throws Exception { } @Test - @SdkSuppress(minSdkVersion = 20) // b/26957451 public void testOpenAndCloseDrawer() { // Drawer should not be open to start. onView(withId(R.id.drawer_layout)).check(matches(isClosed())); @@ -67,7 +65,6 @@ public void testOpenAndCloseDrawer() { } @Test - @SdkSuppress(minSdkVersion = 20) // b/26957451 public void testDrawerOpenAndClick() { openDrawer(R.id.drawer_layout); diff --git a/testapps/ui_testapp/javatests/androidx/test/ui/app/TransitionActivityMainTest.java b/testapps/ui_testapp/javatests/androidx/test/ui/app/TransitionActivityMainTest.java index 7321edade..8f34e117b 100644 --- a/testapps/ui_testapp/javatests/androidx/test/ui/app/TransitionActivityMainTest.java +++ b/testapps/ui_testapp/javatests/androidx/test/ui/app/TransitionActivityMainTest.java @@ -30,7 +30,6 @@ import androidx.test.core.app.ActivityScenario.ActivityAction; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; -import androidx.test.filters.SdkSuppress; import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; @@ -48,10 +47,7 @@ public void setUp() throws Exception { activityScenario = ActivityScenario.launch(TransitionActivityMain.class); } - // This test only applies to Lollipop+ - // b/29833613 @Test - @SdkSuppress(minSdkVersion = 21) public void testTransition() throws InterruptedException { onView(withId(R.id.grid)).check(matches(isDisplayed())); onData(Matchers.anything()).atPosition(0).perform(click()); @@ -62,7 +58,6 @@ public void testTransition() throws InterruptedException { } @Test - @SdkSuppress(minSdkVersion = 21) public void testInterruptedBackDoesntExit() { // Set a flag in the activity to intercept the back button. activityScenario.onActivity(