Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<InputManager> 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
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1709,13 +1708,7 @@ public static Matcher<View> 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 ")
Expand All @@ -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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,7 +66,6 @@ public void initMocks() {
}

@Test
@SdkSuppress(minSdkVersion = 23)
public void permissionAddsPermissionToSet() {
RequestPermissionCallable requestPermissionCallable1 =
withGrantPermissionCallable(RUNTIME_PERMISSION1);
Expand All @@ -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);

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

@Test
@SdkSuppress(minSdkVersion = 23)
public void failureInGrantingPermissionFailsTest() throws Throwable {
expected.expect(AssertionError.class);

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

@Test
@SdkSuppress(minSdkVersion = 23)
public void callableThrowsExceptionFailsTest() throws Throwable {
expected.expect(AssertionError.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion runner/rules/java/androidx/test/api/current_public.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<java.lang.String!>!, 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!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,12 +33,8 @@
/**
* Class contains helper methods to dump atrace info asynchronously while running the test case.
*
* <p>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 {

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading