Make TestApis static.
Currently we create a TestApis in every test class but we don't actually
make use of the state so it's wasteful and makes our APIs more complex.
This is a big change but it should have no functional change.
Test: atest NeneTest
Test: atest TestAppTest
Test: atest HarrierTest
Test: atest RemoteDpcTest
Test: atest CtsDevicePolicyTestCases
Fixes: 200779840
Change-Id: I8f839d411e1bcd1b18fdd61c650a65fc37fc47fd
diff --git a/common/device-side/bedstead/TestParameterInjector b/common/device-side/bedstead/TestParameterInjector
deleted file mode 160000
index e65d6be..0000000
--- a/common/device-side/bedstead/TestParameterInjector
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit e65d6bebdba9df211b258fae996fe34b6eadb787
diff --git a/common/device-side/bedstead/eventlib/src/main/java/com/android/eventlib/RemoteEventQuerier.java b/common/device-side/bedstead/eventlib/src/main/java/com/android/eventlib/RemoteEventQuerier.java
index d394a56..92ba5f3 100644
--- a/common/device-side/bedstead/eventlib/src/main/java/com/android/eventlib/RemoteEventQuerier.java
+++ b/common/device-side/bedstead/eventlib/src/main/java/com/android/eventlib/RemoteEventQuerier.java
@@ -53,8 +53,7 @@
private static final int CONNECTION_TIMEOUT_SECONDS = 30;
private static final String LOG_TAG = "RemoteEventQuerier";
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private final String mPackageName;
private final EventLogsQuery<E, F> mEventLogsQuery;
@@ -174,9 +173,9 @@
AtomicBoolean didBind = new AtomicBoolean(false);
if (mEventLogsQuery.getUserHandle() != null
&& mEventLogsQuery.getUserHandle().getIdentifier()
- != sTestApis.users().instrumented().id()) {
+ != TestApis.users().instrumented().id()) {
try (PermissionContext p =
- sTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
didBind.set(sContext.bindServiceAsUser(
intent, connection, /* flags= */ BIND_AUTO_CREATE,
mEventLogsQuery.getUserHandle()));
@@ -193,15 +192,15 @@
}
} else {
User user = (mEventLogsQuery.getUserHandle() == null)
- ? sTestApis.users().instrumented().resolve()
- : sTestApis.users().find(mEventLogsQuery.getUserHandle()).resolve();
+ ? TestApis.users().instrumented().resolve()
+ : TestApis.users().find(mEventLogsQuery.getUserHandle()).resolve();
if (user == null) {
throw new AssertionError("Tried to bind to user " + mEventLogsQuery.getUserHandle() + " but does not exist");
}
if (user.state() != User.UserState.RUNNING_UNLOCKED) {
throw new AssertionError("Tried to bind to user " + user + " but they are not RUNNING_UNLOCKED");
}
- Package pkg = sTestApis.packages().find(mPackageName).resolve();
+ Package pkg = TestApis.packages().find(mPackageName).resolve();
if (pkg == null) {
throw new AssertionError("Tried to bind to package " + mPackageName + " but it is not installed on any user.");
}
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/EventLogsTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/EventLogsTest.java
index 0bdb45b..f6ed016 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/EventLogsTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/EventLogsTest.java
@@ -64,16 +64,15 @@
private boolean hasScheduledEventsOnTestApp = false;
private final ScheduledExecutorService mScheduledExecutorService =
Executors.newSingleThreadScheduledExecutor();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
- private static final UserReference sProfile = sTestApis.users().createUser()
- .parent(sTestApis.users().instrumented())
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ private static final Context sContext = TestApis.context().instrumentedContext();
+ private static final UserReference sProfile = TestApis.users().createUser()
+ .parent(TestApis.users().instrumented())
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
@BeforeClass
public static void setupClass() {
- sTestApis.packages().find(TEST_APP_PACKAGE_NAME).install(sProfile);
+ TestApis.packages().find(TEST_APP_PACKAGE_NAME).install(sProfile);
}
@AfterClass
@@ -629,7 +628,7 @@
}
private void logCustomEventOnTestApp(String tag, String data) {
- logCustomEventOnTestApp(sTestApis.users().instrumented(), tag, data);
+ logCustomEventOnTestApp(TestApis.users().instrumented(), tag, data);
}
private void logCustomEventOnTestApp() {
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/CustomEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/CustomEventTest.java
index 3ebc1a9..50c5bea 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/CustomEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/CustomEventTest.java
@@ -34,8 +34,7 @@
// TODO: We need a standard pattern for testing that events log correctly cross-process
// (when within the process serialization never happens)
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String TAG_1 = "TAG_1";
private static final String TAG_2 = "TAG_2";
private static final String DATA_1 = "DATA_1";
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityCreatedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityCreatedEventTest.java
index e0a11a0..712b927 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityCreatedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityCreatedEventTest.java
@@ -35,8 +35,7 @@
@RunWith(JUnit4.class)
public final class ActivityCreatedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_KEY = "Key";
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityDestroyedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityDestroyedEventTest.java
index 568129f..853451c 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityDestroyedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityDestroyedEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class ActivityDestroyedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String ACTIVITY_CLASS_NAME = ActivityContext.class.getName();
private static final ActivityInfo ACTIVITY_INFO = new ActivityInfo();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityPausedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityPausedEventTest.java
index 541466e..84208d9 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityPausedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityPausedEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class ActivityPausedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String ACTIVITY_CLASS_NAME = ActivityContext.class.getName();
private static final ActivityInfo ACTIVITY_INFO = new ActivityInfo();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityRestartedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityRestartedEventTest.java
index 8c379c7..6961ead 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityRestartedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityRestartedEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class ActivityRestartedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String ACTIVITY_CLASS_NAME = ActivityContext.class.getName();
private static final ActivityInfo ACTIVITY_INFO = new ActivityInfo();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityResumedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityResumedEventTest.java
index 51c5d55..a718405 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityResumedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityResumedEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class ActivityResumedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String ACTIVITY_CLASS_NAME = ActivityContext.class.getName();
private static final ActivityInfo ACTIVITY_INFO = new ActivityInfo();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityStartedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityStartedEventTest.java
index 5c3d070..715fe17 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityStartedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityStartedEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class ActivityStartedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String ACTIVITY_CLASS_NAME = ActivityContext.class.getName();
private static final ActivityInfo ACTIVITY_INFO = new ActivityInfo();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityStoppedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityStoppedEventTest.java
index 80475ab..c326b7c 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityStoppedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/activities/ActivityStoppedEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class ActivityStoppedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String ACTIVITY_CLASS_NAME = ActivityContext.class.getName();
private static final ActivityInfo ACTIVITY_INFO = new ActivityInfo();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/broadcastreceivers/BroadcastReceivedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/broadcastreceivers/BroadcastReceivedEventTest.java
index 1b1cec2..e663be7 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/broadcastreceivers/BroadcastReceivedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/broadcastreceivers/BroadcastReceivedEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class BroadcastReceivedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportFailedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportFailedEventTest.java
index 7944e72..45e867d 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportFailedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportFailedEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminBugreportFailedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent sIntent = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportSharedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportSharedEventTest.java
index 3e7bc54..fa362b4 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportSharedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportSharedEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminBugreportSharedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent sIntent = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportSharingDeclinedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportSharingDeclinedEventTest.java
index 34417ab..da162e8 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportSharingDeclinedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminBugreportSharingDeclinedEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminBugreportSharingDeclinedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminChoosePrivateKeyAliasEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminChoosePrivateKeyAliasEventTest.java
index b8dd015..daa633f 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminChoosePrivateKeyAliasEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminChoosePrivateKeyAliasEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminChoosePrivateKeyAliasEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminDisableRequestedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminDisableRequestedEventTest.java
index 436e667..bf2bd12 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminDisableRequestedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminDisableRequestedEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminDisableRequestedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminDisabledEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminDisabledEventTest.java
index ae525c3..757cea7 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminDisabledEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminDisabledEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminDisabledEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminEnabledEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminEnabledEventTest.java
index 193d279..9e714b0 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminEnabledEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminEnabledEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminEnabledEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminLockTaskModeEnteringEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminLockTaskModeEnteringEventTest.java
index 96e5f60..0290cb4 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminLockTaskModeEnteringEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminLockTaskModeEnteringEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminLockTaskModeEnteringEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminLockTaskModeExitingEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminLockTaskModeExitingEventTest.java
index 48760f1..527ad0e 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminLockTaskModeExitingEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminLockTaskModeExitingEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminLockTaskModeExitingEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminNetworkLogsAvailableEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminNetworkLogsAvailableEventTest.java
index 5c5e1eb..e01c13d 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminNetworkLogsAvailableEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminNetworkLogsAvailableEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminNetworkLogsAvailableEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminOperationSafetyStateChangedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminOperationSafetyStateChangedEventTest.java
index 8b5996b..cb1d7ba 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminOperationSafetyStateChangedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminOperationSafetyStateChangedEventTest.java
@@ -32,8 +32,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminOperationSafetyStateChangedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String DEFAULT_DEVICE_ADMIN_RECEIVER_CLASS_NAME =
TestDeviceAdminReceiver.class.getName();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordChangedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordChangedEventTest.java
index 2aad3ce..c4a6b35 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordChangedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordChangedEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminPasswordChangedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordExpiringEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordExpiringEventTest.java
index c991df9..2a1e2dc 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordExpiringEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordExpiringEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminPasswordExpiringEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordFailedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordFailedEventTest.java
index 6816038..1b0b90b 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordFailedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordFailedEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminPasswordFailedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordSucceededEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordSucceededEventTest.java
index bb17c4b..4b0c948 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordSucceededEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminPasswordSucceededEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminPasswordSucceededEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminProfileProvisioningCompleteEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminProfileProvisioningCompleteEventTest.java
index d841a8f..7cea89a 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminProfileProvisioningCompleteEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminProfileProvisioningCompleteEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminProfileProvisioningCompleteEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminReadyForUserInitializationEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminReadyForUserInitializationEventTest.java
index cf03e9e..9f3db19 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminReadyForUserInitializationEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminReadyForUserInitializationEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminReadyForUserInitializationEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminSecurityLogsAvailableEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminSecurityLogsAvailableEventTest.java
index 6deb471..94178e0 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminSecurityLogsAvailableEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminSecurityLogsAvailableEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminSecurityLogsAvailableEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminSystemUpdatePendingEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminSystemUpdatePendingEventTest.java
index d26c2f0..c087c25 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminSystemUpdatePendingEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminSystemUpdatePendingEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminSystemUpdatePendingEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminTransferAffiliatedProfileOwnershipCompleteEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminTransferAffiliatedProfileOwnershipCompleteEventTest.java
index 5bd04bd..aed9cb8 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminTransferAffiliatedProfileOwnershipCompleteEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminTransferAffiliatedProfileOwnershipCompleteEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminTransferAffiliatedProfileOwnershipCompleteEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String DEFAULT_DEVICE_ADMIN_RECEIVER_CLASS_NAME =
TestDeviceAdminReceiver.class.getName();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminTransferOwnershipCompleteEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminTransferOwnershipCompleteEventTest.java
index bd0309f..178ea7f 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminTransferOwnershipCompleteEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminTransferOwnershipCompleteEventTest.java
@@ -33,8 +33,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminTransferOwnershipCompleteEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserAddedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserAddedEventTest.java
index 28b08a3..6e38146 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserAddedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserAddedEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminUserAddedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserRemovedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserRemovedEventTest.java
index e636ac1..6928046 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserRemovedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserRemovedEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminUserRemovedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserStartedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserStartedEventTest.java
index 192f20b..f1c7a37 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserStartedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserStartedEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminUserStartedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserStoppedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserStoppedEventTest.java
index c1a91be..b58b7ae 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserStoppedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserStoppedEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminUserStoppedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserSwitchedEventTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserSwitchedEventTest.java
index f1dd5ce..6c2d3cb 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserSwitchedEventTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/events/deviceadminreceivers/DeviceAdminUserSwitchedEventTest.java
@@ -34,8 +34,7 @@
@RunWith(JUnit4.class)
public final class DeviceAdminUserSwitchedEventTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String STRING_VALUE = "Value";
private static final String DIFFERENT_STRING_VALUE = "Value2";
private static final Intent INTENT = new Intent();
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibActivityTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibActivityTest.java
index ad736f9..7358538 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibActivityTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibActivityTest.java
@@ -52,8 +52,7 @@
private static final Instrumentation sInstrumentation =
InstrumentationRegistry.getInstrumentation();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
@Before
public void setUp() {
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibAppComponentFactoryTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibAppComponentFactoryTest.java
index 08b9865..b8f688d 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibAppComponentFactoryTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibAppComponentFactoryTest.java
@@ -49,9 +49,8 @@
private static final String GENERATED_BROADCAST_RECEIVER_ACTION =
"com.android.eventlib.GENERATED_BROADCAST_RECEIVER";
- private static final TestApis sTestApis = new TestApis();
private static final Context sContext =
- sTestApis.context().instrumentedContext();
+ TestApis.context().instrumentedContext();
@Test
public void startActivity_activityDoesNotExist_startsLoggingActivity() {
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibBroadcastReceiverTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibBroadcastReceiverTest.java
index 21b9ee3..f18c4d1 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibBroadcastReceiverTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibBroadcastReceiverTest.java
@@ -46,8 +46,7 @@
private static final String GENERATED_BROADCAST_RECEIVER_ACTION =
"com.android.eventlib.GENERATED_BROADCAST_RECEIVER";
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
@Before
public void setUp() {
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibDeviceAdminReceiverTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibDeviceAdminReceiverTest.java
index 1145eca..990988e 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibDeviceAdminReceiverTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/premade/EventLibDeviceAdminReceiverTest.java
@@ -64,12 +64,11 @@
@RunWith(JUnit4.class)
public class EventLibDeviceAdminReceiverTest {
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final ComponentName DEVICE_ADMIN_COMPONENT =
new ComponentName(
sContext.getPackageName(), EventLibDeviceAdminReceiver.class.getName());
- private static final UserReference sUser = sTestApis.users().instrumented();
+ private static final UserReference sUser = TestApis.users().instrumented();
private static final Intent sIntent = new Intent();
private static final String PKG = "package";
private static final int UID = 1;
@@ -91,7 +90,7 @@
@Test
public void enableDeviceOwner_logsEnabledEvent() {
DeviceOwner deviceOwner =
- sTestApis.devicePolicy().setDeviceOwner(sUser, DEVICE_ADMIN_COMPONENT);
+ TestApis.devicePolicy().setDeviceOwner(sUser, DEVICE_ADMIN_COMPONENT);
try {
EventLogs<DeviceAdminEnabledEvent> eventLogs =
@@ -106,7 +105,7 @@
@Test
public void enableProfileOwner_logsEnabledEvent() {
ProfileOwner profileOwner =
- sTestApis.devicePolicy().setProfileOwner(sUser, DEVICE_ADMIN_COMPONENT);
+ TestApis.devicePolicy().setProfileOwner(sUser, DEVICE_ADMIN_COMPONENT);
try {
EventLogs<DeviceAdminEnabledEvent> eventLogs =
diff --git a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/truth/EventLogsSubjectTest.java b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/truth/EventLogsSubjectTest.java
index d7034be..8070ec2 100644
--- a/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/truth/EventLogsSubjectTest.java
+++ b/common/device-side/bedstead/eventlib/src/test/java/com/android/eventlib/truth/EventLogsSubjectTest.java
@@ -40,8 +40,7 @@
@RunWith(JUnit4.class)
public class EventLogsSubjectTest {
- private static final TestApis sTestApis = new TestApis();
- public static final Context sContext = sTestApis.context().instrumentedContext();
+ public static final Context sContext = TestApis.context().instrumentedContext();
@Before
public void setup() {
diff --git a/common/device-side/bedstead/harrier/src/main/java/com/android/bedstead/harrier/DeviceState.java b/common/device-side/bedstead/harrier/src/main/java/com/android/bedstead/harrier/DeviceState.java
index ed119fb..ef2b636 100644
--- a/common/device-side/bedstead/harrier/src/main/java/com/android/bedstead/harrier/DeviceState.java
+++ b/common/device-side/bedstead/harrier/src/main/java/com/android/bedstead/harrier/DeviceState.java
@@ -134,7 +134,6 @@
public static final String AFFILIATION_IDS = "affiliationIds";
private final Context mContext = ApplicationProvider.getApplicationContext();
- private static final TestApis sTestApis = new TestApis();
private static final String SKIP_TEST_TEARDOWN_KEY = "skip-test-teardown";
private static final String SKIP_CLASS_TEARDOWN_KEY = "skip-class-teardown";
private static final String SKIP_TESTS_REASON_KEY = "skip-tests-reason";
@@ -449,7 +448,7 @@
try {
if (permissionContext == null) {
- permissionContext = sTestApis.permissions().withPermission(
+ permissionContext = TestApis.permissions().withPermission(
ensureHasPermissionAnnotation.value());
} else {
permissionContext = permissionContext.withPermission(
@@ -468,7 +467,7 @@
try {
if (permissionContext == null) {
- permissionContext = sTestApis.permissions().withoutPermission(
+ permissionContext = TestApis.permissions().withoutPermission(
ensureDoesNotHavePermission.value());
} else {
permissionContext = permissionContext.withoutPermission(
@@ -650,7 +649,7 @@
}
private void requireRunOnUser(String[] userTypes, OptionalBoolean switchedToUser) {
- User instrumentedUser = sTestApis.users().instrumented().resolve();
+ User instrumentedUser = TestApis.users().instrumented().resolve();
assume().withMessage("This test only runs on users of type %s", Arrays.toString(userTypes))
.that(userTypes).asList().contains(instrumentedUser.type().name());
@@ -664,7 +663,7 @@
OptionalBoolean installInstrumentedAppInParent,
boolean hasProfileOwner, boolean dpcIsPrimary,
OptionalBoolean switchedToParentUser, Set<String> affiliationIds) {
- User instrumentedUser = sTestApis.users().instrumented().resolve();
+ User instrumentedUser = TestApis.users().instrumented().resolve();
assumeTrue("This test only runs on users of type " + userType,
instrumentedUser.type().name().equals(userType));
@@ -676,10 +675,10 @@
mProfiles.get(instrumentedUser.type()).put(instrumentedUser.parent(), instrumentedUser);
if (installInstrumentedAppInParent.equals(OptionalBoolean.TRUE)) {
- sTestApis.packages().find(sContext.getPackageName()).install(
+ TestApis.packages().find(sContext.getPackageName()).install(
instrumentedUser.parent());
} else if (installInstrumentedAppInParent.equals(OptionalBoolean.FALSE)) {
- sTestApis.packages().find(sContext.getPackageName()).uninstall(
+ TestApis.packages().find(sContext.getPackageName()).uninstall(
instrumentedUser.parent());
}
@@ -702,17 +701,17 @@
private void requireFeature(String feature, FailureMode failureMode) {
checkFailOrSkip("Device must have feature " + feature,
- sTestApis.packages().features().contains(feature), failureMode);
+ TestApis.packages().features().contains(feature), failureMode);
}
private void requireDoesNotHaveFeature(String feature, FailureMode failureMode) {
checkFailOrSkip("Device must not have feature " + feature,
- !sTestApis.packages().features().contains(feature), failureMode);
+ !TestApis.packages().features().contains(feature), failureMode);
}
private void requireNoGmsInstrumentation() {
boolean instrumentingGms =
- sTestApis.context().instrumentedContext().getPackageName().equals(GMS_PKG);
+ TestApis.context().instrumentedContext().getPackageName().equals(GMS_PKG);
checkFailOrSkip(
"This test never runs using gms instrumentation",
@@ -724,7 +723,7 @@
private void requireGmsInstrumentation(int min, int max) {
mHasRequireGmsInstrumentation = true;
boolean instrumentingGms =
- sTestApis.context().instrumentedContext().getPackageName().equals(GMS_PKG);
+ TestApis.context().instrumentedContext().getPackageName().equals(GMS_PKG);
if (meetsSdkVersionRequirements(min, max)) {
checkFailOrSkip(
@@ -762,11 +761,11 @@
private com.android.bedstead.nene.users.UserType requireUserSupported(
String userType, FailureMode failureMode) {
com.android.bedstead.nene.users.UserType resolvedUserType =
- sTestApis.users().supportedType(userType);
+ TestApis.users().supportedType(userType);
checkFailOrSkip(
"Device must support user type " + userType
- + " only supports: " + sTestApis.users().supportedTypes(),
+ + " only supports: " + TestApis.users().supportedTypes(),
resolvedUserType != null, failureMode);
return resolvedUserType;
@@ -805,7 +804,7 @@
private static final String LOG_TAG = "DeviceState";
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private final Map<com.android.bedstead.nene.users.UserType, UserReference> mUsers =
new HashMap<>();
@@ -898,7 +897,7 @@
*/
public UserReference profile(String profileType, UserReference forUser) {
com.android.bedstead.nene.users.UserType resolvedUserType =
- sTestApis.users().supportedType(profileType);
+ TestApis.users().supportedType(profileType);
if (resolvedUserType == null) {
throw new IllegalStateException("Can not have a profile of type " + profileType
@@ -923,7 +922,7 @@
}
if (!mProfiles.containsKey(userType) || !mProfiles.get(userType).containsKey(forUser)) {
- UserReference parentUser = sTestApis.users().instrumented().resolve().parent();
+ UserReference parentUser = TestApis.users().instrumented().resolve().parent();
if (parentUser != null) {
if (mProfiles.containsKey(userType)
@@ -980,7 +979,7 @@
* Get the user ID of the first human user on the device.
*/
public UserReference primaryUser() {
- return sTestApis.users().all()
+ return TestApis.users().all()
.stream().filter(User::isPrimary).findFirst()
.orElseThrow(IllegalStateException::new);
}
@@ -1007,7 +1006,7 @@
*/
public UserReference user(String userType) {
com.android.bedstead.nene.users.UserType resolvedUserType =
- sTestApis.users().supportedType(userType);
+ TestApis.users().supportedType(userType);
if (resolvedUserType == null) {
throw new IllegalStateException("Can not have a user of type " + userType
@@ -1052,7 +1051,7 @@
UserReference forUserReference = resolveUserTypeToUser(forUser);
UserReference profile =
- sTestApis.users().findProfileOfType(resolvedUserType, forUserReference);
+ TestApis.users().findProfileOfType(resolvedUserType, forUserReference);
if (profile == null) {
profile = createProfile(resolvedUserType, forUserReference);
}
@@ -1060,9 +1059,9 @@
profile.start();
if (installInstrumentedApp.equals(OptionalBoolean.TRUE)) {
- sTestApis.packages().find(sContext.getPackageName()).install(profile);
+ TestApis.packages().find(sContext.getPackageName()).install(profile);
} else if (installInstrumentedApp.equals(OptionalBoolean.FALSE)) {
- sTestApis.packages().find(sContext.getPackageName()).uninstall(profile);
+ TestApis.packages().find(sContext.getPackageName()).uninstall(profile);
}
if (!mProfiles.containsKey(resolvedUserType)) {
@@ -1083,7 +1082,7 @@
private void ensureHasNoProfile(String profileType, UserType forUser) {
UserReference forUserReference = resolveUserTypeToUser(forUser);
com.android.bedstead.nene.users.UserType resolvedProfileType =
- sTestApis.users().supportedType(profileType);
+ TestApis.users().supportedType(profileType);
if (resolvedProfileType == null) {
// These profile types don't exist so there can't be any
@@ -1091,7 +1090,7 @@
}
UserReference profile =
- sTestApis.users().findProfileOfType(
+ TestApis.users().findProfileOfType(
resolvedProfileType,
forUserReference);
if (profile != null) {
@@ -1105,7 +1104,7 @@
com.android.bedstead.nene.users.UserType resolvedUserType =
requireUserSupported(userType, FailureMode.SKIP);
- Collection<UserReference> users = sTestApis.users().findUsersOfType(resolvedUserType);
+ Collection<UserReference> users = TestApis.users().findUsersOfType(resolvedUserType);
UserReference user = users.isEmpty() ? createUser(resolvedUserType)
: users.iterator().next();
@@ -1113,9 +1112,9 @@
user.start();
if (installInstrumentedApp.equals(OptionalBoolean.TRUE)) {
- sTestApis.packages().find(sContext.getPackageName()).install(user);
+ TestApis.packages().find(sContext.getPackageName()).install(user);
} else if (installInstrumentedApp.equals(OptionalBoolean.FALSE)) {
- sTestApis.packages().find(sContext.getPackageName()).uninstall(user);
+ TestApis.packages().find(sContext.getPackageName()).uninstall(user);
}
ensureSwitchedToUser(switchedToUser, user);
@@ -1128,14 +1127,14 @@
*/
private void ensureHasNoUser(String userType) {
com.android.bedstead.nene.users.UserType resolvedUserType =
- sTestApis.users().supportedType(userType);
+ TestApis.users().supportedType(userType);
if (resolvedUserType == null) {
// These user types don't exist so there can't be any
return;
}
- for (UserReference secondaryUser : sTestApis.users().findUsersOfType(resolvedUserType)) {
+ for (UserReference secondaryUser : TestApis.users().findUsersOfType(resolvedUserType)) {
removeAndRecordUser(secondaryUser);
}
}
@@ -1150,7 +1149,7 @@
User user = userReference.resolve();
if (!mCreatedUsers.remove(user)) {
- mRemovedUsers.add(sTestApis.users().createUser()
+ mRemovedUsers.add(TestApis.users().createUser()
.name(user.name())
.type(user.type())
.parent(user.parent()));
@@ -1161,7 +1160,7 @@
public void requireCanSupportAdditionalUser() {
int maxUsers = getMaxNumberOfUsersSupported();
- int currentUsers = sTestApis.users().all().size();
+ int currentUsers = TestApis.users().all().size();
assumeTrue("The device does not have space for an additional user (" + currentUsers +
" current users, " + maxUsers + " max users)", currentUsers + 1 <= maxUsers);
@@ -1192,9 +1191,9 @@
private UserReference resolveUserTypeToUser(UserType userType) {
switch (userType) {
case SYSTEM_USER:
- return sTestApis.users().system();
+ return TestApis.users().system();
case CURRENT_USER:
- return sTestApis.users().instrumented();
+ return TestApis.users().instrumented();
case PRIMARY_USER:
return primaryUser();
case SECONDARY_USER:
@@ -1227,7 +1226,7 @@
Log.d(LOG_TAG, "Could not switch back to original user "
+ mOriginalSwitchedUser
+ " as it does not exist. Switching to system instead.");
- sTestApis.users().system().switchTo();
+ TestApis.users().system().switchTo();
} else {
mOriginalSwitchedUser.switchTo();
}
@@ -1241,7 +1240,7 @@
}
} else if (!mOriginalDeviceOwner.equals(mDeviceOwner)) {
mDeviceOwner.remove();
- sTestApis.devicePolicy().setDeviceOwner(
+ TestApis.devicePolicy().setDeviceOwner(
mOriginalDeviceOwner.user(), mOriginalDeviceOwner.componentName());
}
mHasChangedDeviceOwner = false;
@@ -1252,7 +1251,7 @@
mChangedProfileOwners.entrySet()) {
ProfileOwner currentProfileOwner =
- sTestApis.devicePolicy().getProfileOwner(originalProfileOwner.getKey());
+ TestApis.devicePolicy().getProfileOwner(originalProfileOwner.getKey());
if (Objects.equal(currentProfileOwner, originalProfileOwner.getValue())) {
continue; // No need to restore
@@ -1263,7 +1262,7 @@
}
if (originalProfileOwner.getValue() != null) {
- sTestApis.devicePolicy().setProfileOwner(originalProfileOwner.getKey(),
+ TestApis.devicePolicy().setProfileOwner(originalProfileOwner.getKey(),
originalProfileOwner.getValue().componentName());
}
}
@@ -1286,7 +1285,7 @@
com.android.bedstead.nene.users.UserType profileType, UserReference parent) {
requireCanSupportAdditionalUser();
try {
- UserReference user = sTestApis.users().createUser()
+ UserReference user = TestApis.users().createUser()
.parent(parent)
.type(profileType)
.createAndStart();
@@ -1300,7 +1299,7 @@
private UserReference createUser(com.android.bedstead.nene.users.UserType userType) {
requireCanSupportAdditionalUser();
try {
- UserReference user = sTestApis.users().createUser()
+ UserReference user = TestApis.users().createUser()
.type(userType)
.createAndStart();
mCreatedUsers.add(user);
@@ -1328,22 +1327,22 @@
if (isPrimary && mPrimaryDpc != null && !userReference.equals(mPrimaryDpc.user())) {
throw new IllegalStateException("Only one DPC can be marked as primary per test (current primary is " + mPrimaryDpc + ")");
}
- if (!userReference.equals(sTestApis.users().instrumented())) {
+ if (!userReference.equals(TestApis.users().instrumented())) {
// INTERACT_ACROSS_USERS_FULL is required for RemoteDPC
ensureCanGetPermission(INTERACT_ACROSS_USERS_FULL);
}
- DeviceOwner currentDeviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ DeviceOwner currentDeviceOwner = TestApis.devicePolicy().getDeviceOwner();
if (currentDeviceOwner != null
&& currentDeviceOwner.componentName().equals(RemoteDpc.DPC_COMPONENT_NAME)) {
mDeviceOwner = currentDeviceOwner;
} else {
- UserReference instrumentedUser = sTestApis.users().instrumented();
+ UserReference instrumentedUser = TestApis.users().instrumented();
if (!Versions.meetsMinimumSdkVersionRequirement(Build.VERSION_CODES.S)) {
// Prior to S we can't set device owner if there are other users on the device
- for (UserReference u : sTestApis.users().all()) {
+ for (UserReference u : TestApis.users().all()) {
if (u.equals(instrumentedUser)) {
continue;
}
@@ -1390,13 +1389,13 @@
throw new IllegalStateException("Only one DPC can be marked as primary per test");
}
- if (!user.equals(sTestApis.users().instrumented())) {
+ if (!user.equals(TestApis.users().instrumented())) {
// INTERACT_ACROSS_USERS_FULL is required for RemoteDPC
ensureCanGetPermission(INTERACT_ACROSS_USERS_FULL);
}
- ProfileOwner currentProfileOwner = sTestApis.devicePolicy().getProfileOwner(user);
- DeviceOwner currentDeviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ ProfileOwner currentProfileOwner = TestApis.devicePolicy().getProfileOwner(user);
+ DeviceOwner currentDeviceOwner = TestApis.devicePolicy().getDeviceOwner();
if (currentDeviceOwner != null && currentDeviceOwner.user().equals(user)) {
// Can't have DO and PO on the same user
@@ -1427,7 +1426,7 @@
}
private void ensureHasNoDeviceOwner() {
- DeviceOwner deviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ DeviceOwner deviceOwner = TestApis.devicePolicy().getDeviceOwner();
if (deviceOwner == null) {
return;
@@ -1450,7 +1449,7 @@
private void ensureHasNoProfileOwner(UserReference user) {
- ProfileOwner currentProfileOwner = sTestApis.devicePolicy().getProfileOwner(user);
+ ProfileOwner currentProfileOwner = TestApis.devicePolicy().getProfileOwner(user);
if (currentProfileOwner == null) {
return;
@@ -1460,7 +1459,7 @@
mChangedProfileOwners.put(user, currentProfileOwner);
}
- sTestApis.devicePolicy().getProfileOwner(user).remove();
+ TestApis.devicePolicy().getProfileOwner(user).remove();
mProfileOwners.remove(user);
}
@@ -1540,7 +1539,7 @@
private void requirePackageInstalled(
String packageName, UserType forUser, FailureMode failureMode) {
- Package pkg = sTestApis.packages().find(packageName).resolve();
+ Package pkg = TestApis.packages().find(packageName).resolve();
checkFailOrSkip(
packageName + " is required to be installed for " + forUser,
pkg != null,
@@ -1561,7 +1560,7 @@
private void requirePackageNotInstalled(
String packageName, UserType forUser, FailureMode failureMode) {
- Package pkg = sTestApis.packages().find(packageName).resolve();
+ Package pkg = TestApis.packages().find(packageName).resolve();
if (pkg == null) {
// Definitely not installed
return;
@@ -1583,7 +1582,7 @@
private void ensurePackageNotInstalled(
String packageName, UserType forUser) {
- Package pkg = sTestApis.packages().find(packageName).resolve();
+ Package pkg = TestApis.packages().find(packageName).resolve();
if (pkg == null) {
// Definitely not installed
return;
@@ -1618,9 +1617,9 @@
return RemoteDpc.forDevicePolicyController(mPrimaryDpc);
}
- if (mProfileOwners.containsKey(sTestApis.users().instrumented())) {
+ if (mProfileOwners.containsKey(TestApis.users().instrumented())) {
DevicePolicyController profileOwner =
- mProfileOwners.get(sTestApis.users().instrumented());
+ mProfileOwners.get(TestApis.users().instrumented());
if (profileOwner.componentName().equals(REMOTE_DPC_COMPONENT_NAME)) {
@@ -1653,7 +1652,7 @@
}
private void switchToUser(UserReference user) {
- UserReference currentUser = sTestApis.users().current();
+ UserReference currentUser = TestApis.users().current();
if (!currentUser.equals(user)) {
if (mOriginalSwitchedUser == null) {
mOriginalSwitchedUser = currentUser;
@@ -1663,14 +1662,14 @@
}
private void switchFromUser(UserReference user) {
- UserReference currentUser = sTestApis.users().current();
+ UserReference currentUser = TestApis.users().current();
if (!currentUser.equals(user)) {
return;
}
// We need to find a different user to switch to
// full users only, starting with lowest ID
- List<UserReference> users = new ArrayList<>(sTestApis.users().all());
+ List<UserReference> users = new ArrayList<>(TestApis.users().all());
users.sort(Comparator.comparingInt(u -> u.id()));
for (UserReference otherUser : users) {
diff --git a/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateClassAnnotationTest.java b/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateClassAnnotationTest.java
index f7860548..9181ec4 100644
--- a/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateClassAnnotationTest.java
+++ b/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateClassAnnotationTest.java
@@ -43,8 +43,6 @@
@Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
-
private static boolean sBeforeClassHasRun = false;
private static boolean sShadowedGrandparentWithoutBeforeClassInTestClassHasRun = false;
@@ -65,12 +63,12 @@
// We test here that ensureHasWorkProfile is processed before the test method
// but ensureHasSecondaryUser is not processed
- assertThat(sTestApis.users().findProfileOfType(
- sTestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
- sTestApis.users().instrumented())
+ assertThat(TestApis.users().findProfileOfType(
+ TestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
+ TestApis.users().instrumented())
).isNotNull();
- assertThat(sTestApis.users().findUserOfType(
- sTestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
+ assertThat(TestApis.users().findUserOfType(
+ TestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
).isNull();
// Test that the parent always runs before the child
@@ -97,26 +95,26 @@
@Test
public void ensureHasWorkProfileAnnotationOnClass_workProfileExists() {
- assertThat(sTestApis.users().findProfileOfType(
- sTestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
- sTestApis.users().instrumented())
+ assertThat(TestApis.users().findProfileOfType(
+ TestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
+ TestApis.users().instrumented())
).isNotNull();
}
@Test
@EnsureHasNoWorkProfile
public void ensureHasNoWorkProfileAnnotation_overridesClassAnnotation() {
- assertThat(sTestApis.users().findProfileOfType(
- sTestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
- sTestApis.users().instrumented())
+ assertThat(TestApis.users().findProfileOfType(
+ TestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
+ TestApis.users().instrumented())
).isNull();
}
@Test
@EnsureHasSecondaryUser
public void ensureHasSecondaryUserAnnotation_overridesClassAnnotation() {
- assertThat(sTestApis.users().findUserOfType(
- sTestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
+ assertThat(TestApis.users().findUserOfType(
+ TestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
).isNotNull();
}
}
diff --git a/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateClassAnnotationWithoutBedsteadJunit4Test.java b/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateClassAnnotationWithoutBedsteadJunit4Test.java
index 594a103..7874903 100644
--- a/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateClassAnnotationWithoutBedsteadJunit4Test.java
+++ b/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateClassAnnotationWithoutBedsteadJunit4Test.java
@@ -37,12 +37,10 @@
@Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
-
@Test
public void ensureHasSecondaryUserAnnotationOnClass_secondaryUserExists() {
- assertThat(sTestApis.users().findUserOfType(
- sTestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
+ assertThat(TestApis.users().findUserOfType(
+ TestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
).isNotNull();
}
}
diff --git a/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateTest.java b/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateTest.java
index be4b1ee..0774462 100644
--- a/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateTest.java
+++ b/common/device-side/bedstead/harrier/src/test/java/com/android/bedstead/harrier/DeviceStateTest.java
@@ -88,7 +88,6 @@
@Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
private static final String TV_PROFILE_TYPE_NAME = "com.android.tv.profile";
private static final String TEST_PERMISSION_1 = INTERACT_ACROSS_PROFILES;
@@ -109,7 +108,7 @@
@Test
@RequireRunOnWorkProfile
public void workProfile_runningOnWorkProfile_returnsCurrentProfile() {
- assertThat(sDeviceState.workProfile()).isEqualTo(sTestApis.users().instrumented());
+ assertThat(sDeviceState.workProfile()).isEqualTo(TestApis.users().instrumented());
}
@Test
@@ -122,9 +121,9 @@
@EnsureHasNoWorkProfile
@EnsureHasNoDeviceOwner
public void workProfile_createdWorkProfile_throwsException() {
- try (UserReference workProfile = sTestApis.users().createUser()
- .parent(sTestApis.users().instrumented())
- .type(sTestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME))
+ try (UserReference workProfile = TestApis.users().createUser()
+ .parent(TestApis.users().instrumented())
+ .type(TestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME))
.create()) {
assertThrows(IllegalStateException.class, sDeviceState::workProfile);
}
@@ -133,9 +132,9 @@
@Test
@EnsureHasWorkProfile
public void ensureHasWorkProfileAnnotation_workProfileExists() {
- assertThat(sTestApis.users().findProfileOfType(
- sTestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
- sTestApis.users().instrumented())
+ assertThat(TestApis.users().findProfileOfType(
+ TestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
+ TestApis.users().instrumented())
).isNotNull();
}
@@ -145,9 +144,9 @@
@Test
@EnsureHasNoWorkProfile
public void ensureHasNoWorkProfileAnnotation_workProfileDoesNotExist() {
- assertThat(sTestApis.users().findProfileOfType(
- sTestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
- sTestApis.users().instrumented())
+ assertThat(TestApis.users().findProfileOfType(
+ TestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
+ TestApis.users().instrumented())
).isNull();
}
@@ -160,7 +159,7 @@
@Test
@RequireRunOnTvProfile
public void tvProfile_runningOnTvProfile_returnsCurrentProfile() {
- assertThat(sDeviceState.tvProfile()).isEqualTo(sTestApis.users().instrumented());
+ assertThat(sDeviceState.tvProfile()).isEqualTo(TestApis.users().instrumented());
}
@Test
@@ -173,9 +172,9 @@
@RequireUserSupported(TV_PROFILE_TYPE_NAME)
@EnsureHasNoTvProfile
public void tvProfile_createdTvProfile_throwsException() {
- try (UserReference tvProfile = sTestApis.users().createUser()
- .parent(sTestApis.users().instrumented())
- .type(sTestApis.users().supportedType(TV_PROFILE_TYPE_NAME))
+ try (UserReference tvProfile = TestApis.users().createUser()
+ .parent(TestApis.users().instrumented())
+ .type(TestApis.users().supportedType(TV_PROFILE_TYPE_NAME))
.create()) {
assertThrows(IllegalStateException.class, sDeviceState::tvProfile);
}
@@ -184,9 +183,9 @@
@Test
@EnsureHasTvProfile
public void ensureHasTvProfileAnnotation_tvProfileExists() {
- assertThat(sTestApis.users().findProfileOfType(
- sTestApis.users().supportedType(TV_PROFILE_TYPE_NAME),
- sTestApis.users().instrumented())
+ assertThat(TestApis.users().findProfileOfType(
+ TestApis.users().supportedType(TV_PROFILE_TYPE_NAME),
+ TestApis.users().instrumented())
).isNotNull();
}
@@ -197,9 +196,9 @@
@RequireUserSupported(TV_PROFILE_TYPE_NAME)
@EnsureHasNoTvProfile
public void ensureHasNoTvProfileAnnotation_tvProfileDoesNotExist() {
- assertThat(sTestApis.users().findProfileOfType(
- sTestApis.users().supportedType(TV_PROFILE_TYPE_NAME),
- sTestApis.users().instrumented())
+ assertThat(TestApis.users().findProfileOfType(
+ TestApis.users().supportedType(TV_PROFILE_TYPE_NAME),
+ TestApis.users().instrumented())
).isNull();
}
@@ -218,7 +217,7 @@
@Test
@RequireRunOnSecondaryUser
public void secondaryUser_runningOnSecondaryUser_returnsCurrentUser() {
- assertThat(sDeviceState.secondaryUser()).isEqualTo(sTestApis.users().instrumented());
+ assertThat(sDeviceState.secondaryUser()).isEqualTo(TestApis.users().instrumented());
}
@Test
@@ -230,8 +229,8 @@
@Test
@EnsureHasNoSecondaryUser
public void secondaryUser_createdSecondaryUser_throwsException() {
- try (UserReference secondaryUser = sTestApis.users().createUser()
- .type(sTestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
+ try (UserReference secondaryUser = TestApis.users().createUser()
+ .type(TestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
.create()) {
assertThrows(IllegalStateException.class, sDeviceState::secondaryUser);
}
@@ -240,8 +239,8 @@
@Test
@EnsureHasSecondaryUser
public void ensureHasSecondaryUserAnnotation_secondaryUserExists() {
- assertThat(sTestApis.users().findUserOfType(
- sTestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
+ assertThat(TestApis.users().findUserOfType(
+ TestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
).isNotNull();
}
@@ -251,40 +250,40 @@
@Test
@EnsureHasNoSecondaryUser
public void ensureHasNoSecondaryUserAnnotation_secondaryUserDoesNotExist() {
- assertThat(sTestApis.users().findUserOfType(
- sTestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
+ assertThat(TestApis.users().findUserOfType(
+ TestApis.users().supportedType(SECONDARY_USER_TYPE_NAME))
).isNull();
}
@Test
@EnsureHasPermission(TEST_PERMISSION_1)
public void ensureHasPermission_permissionIsGranted() {
- assertThat(sTestApis.context().instrumentedContext()
+ assertThat(TestApis.context().instrumentedContext()
.checkSelfPermission(TEST_PERMISSION_1)).isEqualTo(PERMISSION_GRANTED);
}
@Test
@EnsureHasPermission({TEST_PERMISSION_1, TEST_PERMISSION_2})
public void ensureHasPermission_multiplePermissions_permissionsAreGranted() {
- assertThat(sTestApis.context().instrumentedContext()
+ assertThat(TestApis.context().instrumentedContext()
.checkSelfPermission(TEST_PERMISSION_1)).isEqualTo(PERMISSION_GRANTED);
- assertThat(sTestApis.context().instrumentedContext()
+ assertThat(TestApis.context().instrumentedContext()
.checkSelfPermission(TEST_PERMISSION_2)).isEqualTo(PERMISSION_GRANTED);
}
@Test
@EnsureDoesNotHavePermission(TEST_PERMISSION_1)
public void ensureDoesNotHavePermission_permissionIsDenied() {
- assertThat(sTestApis.context().instrumentedContext()
+ assertThat(TestApis.context().instrumentedContext()
.checkSelfPermission(TEST_PERMISSION_1)).isEqualTo(PERMISSION_DENIED);
}
@Test
@EnsureDoesNotHavePermission({TEST_PERMISSION_1, TEST_PERMISSION_2})
public void ensureDoesNotHavePermission_multiplePermissions_permissionsAreDenied() {
- assertThat(sTestApis.context().instrumentedContext()
+ assertThat(TestApis.context().instrumentedContext()
.checkSelfPermission(TEST_PERMISSION_1)).isEqualTo(PERMISSION_DENIED);
- assertThat(sTestApis.context().instrumentedContext()
+ assertThat(TestApis.context().instrumentedContext()
.checkSelfPermission(TEST_PERMISSION_2)).isEqualTo(PERMISSION_DENIED);
}
@@ -292,21 +291,21 @@
@EnsureHasPermission(TEST_PERMISSION_1)
@EnsureDoesNotHavePermission(TEST_PERMISSION_2)
public void ensureHasPermissionAndDoesNotHavePermission_permissionsAreCorrect() {
- assertThat(sTestApis.context().instrumentedContext()
+ assertThat(TestApis.context().instrumentedContext()
.checkSelfPermission(TEST_PERMISSION_1)).isEqualTo(PERMISSION_GRANTED);
- assertThat(sTestApis.context().instrumentedContext()
+ assertThat(TestApis.context().instrumentedContext()
.checkSelfPermission(TEST_PERMISSION_2)).isEqualTo(PERMISSION_DENIED);
}
@EnsureHasDeviceOwner
public void ensureHasDeviceOwnerAnnotation_deviceOwnerIsSet() {
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isNotNull();
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isNotNull();
}
@Test
@EnsureHasNoDeviceOwner
public void ensureHasNoDeviceOwnerAnnotation_deviceOwnerIsNotSet() {
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isNull();
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isNull();
}
@Test
@@ -324,28 +323,28 @@
@Test
@EnsureHasProfileOwner
public void ensureHasProfileOwnerAnnotation_defaultUser_profileOwnerIsSet() {
- assertThat(sTestApis.devicePolicy().getProfileOwner(sTestApis.users().instrumented()))
+ assertThat(TestApis.devicePolicy().getProfileOwner(TestApis.users().instrumented()))
.isNotNull();
}
@Test
@EnsureHasNoProfileOwner
public void ensureHasNoProfileOwnerAnnotation_defaultUser_profileOwnerIsNotSet() {
- assertThat(sTestApis.devicePolicy().getProfileOwner(sTestApis.users().instrumented()))
+ assertThat(TestApis.devicePolicy().getProfileOwner(TestApis.users().instrumented()))
.isNull();
}
@EnsureHasSecondaryUser
@EnsureHasProfileOwner(onUser = DeviceState.UserType.SECONDARY_USER)
public void ensureHasProfileOwnerAnnotation_otherUser_setsProfileOwner() {
- assertThat(sTestApis.devicePolicy().getProfileOwner(sDeviceState.secondaryUser()))
+ assertThat(TestApis.devicePolicy().getProfileOwner(sDeviceState.secondaryUser()))
.isNotNull();
}
@EnsureHasSecondaryUser
@EnsureHasNoProfileOwner(onUser = DeviceState.UserType.SECONDARY_USER)
public void ensureHasNoProfileOwnerAnnotation_otherUser_profileOwnerIsNotSet() {
- assertThat(sTestApis.devicePolicy().getProfileOwner(sDeviceState.secondaryUser())).isNull();
+ assertThat(TestApis.devicePolicy().getProfileOwner(sDeviceState.secondaryUser())).isNull();
}
@Test
@@ -357,7 +356,7 @@
@Test
@EnsureHasProfileOwner
public void profileOwner_defaultUser_profileOwnerIsSet_returnsProfileOwner() {
- assertThat(sTestApis.devicePolicy().getProfileOwner(sTestApis.users().instrumented()))
+ assertThat(TestApis.devicePolicy().getProfileOwner(TestApis.users().instrumented()))
.isNotNull();
}
@@ -389,7 +388,7 @@
@RequireRunOnWorkProfile
public void requireRunOnWorkProfileAnnotation_isRunningOnWorkProfile() {
assertThat(
- sTestApis.users().instrumented().resolve().type().name())
+ TestApis.users().instrumented().resolve().type().name())
.isEqualTo(MANAGED_PROFILE_TYPE_NAME);
}
@@ -397,7 +396,7 @@
@RequireRunOnWorkProfile
public void requireRunOnWorkProfileAnnotation_workProfileHasProfileOwner() {
assertThat(
- sTestApis.devicePolicy().getProfileOwner(sTestApis.users().instrumented())
+ TestApis.devicePolicy().getProfileOwner(TestApis.users().instrumented())
).isNotNull();
}
@@ -405,23 +404,23 @@
@RequireRunOnSecondaryUser
public void requireRunOnSecondaryUserAnnotation_isRunningOnSecondaryUser() {
assertThat(
- sTestApis.users().instrumented().resolve().type().name())
+ TestApis.users().instrumented().resolve().type().name())
.isEqualTo(SECONDARY_USER_TYPE_NAME);
}
@Test
@IncludeRunOnDeviceOwnerUser
public void includeRunOnDeviceOwnerUserAnnotation_isRunningOnDeviceOwnerUser() {
- assertThat(sTestApis.devicePolicy().getDeviceOwner().user())
- .isEqualTo(sTestApis.users().instrumented());
+ assertThat(TestApis.devicePolicy().getDeviceOwner().user())
+ .isEqualTo(TestApis.users().instrumented());
}
@Test
@IncludeRunOnNonAffiliatedDeviceOwnerSecondaryUser
public void includeRunOnNonAffiliatedDeviceOwnerSecondaryUserAnnotation_isRunningOnNonAffiliatedDeviceOwnerSecondaryUser() {
- assertThat(sTestApis.devicePolicy().getDeviceOwner().user())
- .isNotEqualTo(sTestApis.users().instrumented());
- assertThat(sTestApis.users().instrumented().resolve().type().name())
+ assertThat(TestApis.devicePolicy().getDeviceOwner().user())
+ .isNotEqualTo(TestApis.users().instrumented());
+ assertThat(TestApis.users().instrumented().resolve().type().name())
.isEqualTo(SECONDARY_USER_TYPE_NAME);
}
@@ -429,18 +428,18 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
public void includeRunOnProfileOwnerAnnotation_hasProfileOwner() {
assertThat(
- sTestApis.devicePolicy().getProfileOwner(sTestApis.users().instrumented())
+ TestApis.devicePolicy().getProfileOwner(TestApis.users().instrumented())
).isNotNull();
}
@Test
@IncludeRunOnSecondaryUserInDifferentProfileGroupToProfileOwnerProfile
public void includeRunOnSecondaryUserInDifferentProfileGroupToProfileOwnerAnnotation_isRunningOnSecondaryUserInDifferentProfileGroupToProfileOwner() {
- assertThat(sTestApis.users().instrumented().resolve().type().name())
+ assertThat(TestApis.users().instrumented().resolve().type().name())
.isEqualTo(SECONDARY_USER_TYPE_NAME);
assertThat(sDeviceState.workProfile(PRIMARY_USER))
- .isNotEqualTo(sTestApis.users().instrumented());
- assertThat(sTestApis.devicePolicy().getProfileOwner(sDeviceState.workProfile(PRIMARY_USER)))
+ .isNotEqualTo(TestApis.users().instrumented());
+ assertThat(TestApis.devicePolicy().getProfileOwner(sDeviceState.workProfile(PRIMARY_USER)))
.isNotNull();
// TODO(scottjonathan): Assert profile groups are different
@@ -448,31 +447,31 @@
@RequirePackageInstalled(value = GMS_CORE_PACKAGE, onUser = ANY)
public void requirePackageInstalledAnnotation_anyUser_packageIsInstalled() {
- assertThat(sTestApis.packages().find(GMS_CORE_PACKAGE).resolve()).isNotNull();
+ assertThat(TestApis.packages().find(GMS_CORE_PACKAGE).resolve()).isNotNull();
}
@Test
@RequirePackageInstalled(GMS_CORE_PACKAGE)
public void requirePackageInstalledAnnotation_currentUser_packageIsInstalled() {
- assertThat(sTestApis.packages().find(GMS_CORE_PACKAGE).resolve().installedOnUsers())
- .contains(sTestApis.users().instrumented());
+ assertThat(TestApis.packages().find(GMS_CORE_PACKAGE).resolve().installedOnUsers())
+ .contains(TestApis.users().instrumented());
}
@Test
@RequirePackageNotInstalled(value = GMS_CORE_PACKAGE, onUser = ANY)
public void requirePackageNotInstalledAnnotation_anyUser_packageIsNotInstalled() {
- assertThat(sTestApis.packages().find(GMS_CORE_PACKAGE).resolve()).isNull();
+ assertThat(TestApis.packages().find(GMS_CORE_PACKAGE).resolve()).isNull();
}
@Test
@RequirePackageNotInstalled(GMS_CORE_PACKAGE)
public void requirePackageNotInstalledAnnotation_currentUser_packageIsNotInstalled() {
- Package resolvedPackage = sTestApis.packages().find(GMS_CORE_PACKAGE).resolve();
+ Package resolvedPackage = TestApis.packages().find(GMS_CORE_PACKAGE).resolve();
if (resolvedPackage != null) {
assertThat(resolvedPackage.installedOnUsers())
- .doesNotContain(sTestApis.users().instrumented());
+ .doesNotContain(TestApis.users().instrumented());
}
}
@@ -480,56 +479,56 @@
@EnsurePackageNotInstalled(value = GMS_CORE_PACKAGE, onUser = ANY)
@Ignore // TODO(scottjonathan): Restore this with a package which can be uninstalled
public void ensurePackageNotInstalledAnnotation_anyUser_packageIsNotInstalled() {
- assertThat(sTestApis.packages().find(GMS_CORE_PACKAGE).resolve()).isNull();
+ assertThat(TestApis.packages().find(GMS_CORE_PACKAGE).resolve()).isNull();
}
@Test
@EnsurePackageNotInstalled(GMS_CORE_PACKAGE)
@Ignore // TODO(scottjonathan): Restore this with a package which can be uninstalled
public void ensurePackageNotInstalledAnnotation_currentUser_packageIsNotInstalled() {
- Package resolvedPackage = sTestApis.packages().find(GMS_CORE_PACKAGE).resolve();
+ Package resolvedPackage = TestApis.packages().find(GMS_CORE_PACKAGE).resolve();
if (resolvedPackage != null) {
assertThat(resolvedPackage.installedOnUsers())
- .doesNotContain(sTestApis.users().instrumented());
+ .doesNotContain(TestApis.users().instrumented());
}
}
@Test
@RequireAospBuild
public void requireAospBuildAnnotation_isRunningOnAospBuild() {
- assertThat(sTestApis.packages().find(GMS_CORE_PACKAGE).resolve()).isNull();
+ assertThat(TestApis.packages().find(GMS_CORE_PACKAGE).resolve()).isNull();
}
@Test
@RequireGmsBuild
public void requireGmsBuildAnnotation_isRunningOnGmsbuild() {
- assertThat(sTestApis.packages().find(GMS_CORE_PACKAGE).resolve()).isNotNull();
+ assertThat(TestApis.packages().find(GMS_CORE_PACKAGE).resolve()).isNotNull();
}
@Test
@RequireCnGmsBuild
public void requireCnGmsBuildAnnotation_isRunningOnCnGmsBuild() {
- assertThat(sTestApis.packages().features()).contains(CHINA_GOOGLE_SERVICES_FEATURE);
+ assertThat(TestApis.packages().features()).contains(CHINA_GOOGLE_SERVICES_FEATURE);
}
@Test
@RequireNotCnGmsBuild
public void requireNotCnGmsBuildAnnotation_isNotRunningOnCnGmsBuild() {
- assertThat(sTestApis.packages().features()).doesNotContain(CHINA_GOOGLE_SERVICES_FEATURE);
+ assertThat(TestApis.packages().features()).doesNotContain(CHINA_GOOGLE_SERVICES_FEATURE);
}
@Test
@RequireFeature(CHINA_GOOGLE_SERVICES_FEATURE)
public void requireHasFeatureAnnotation_doesNotHaveFeature() {
- assertThat(sTestApis.packages().features()).contains(CHINA_GOOGLE_SERVICES_FEATURE);
+ assertThat(TestApis.packages().features()).contains(CHINA_GOOGLE_SERVICES_FEATURE);
}
@Test
@RequireDoesNotHaveFeature(CHINA_GOOGLE_SERVICES_FEATURE)
public void requireDoesNotHaveFeatureAnnotation_doesNotHaveFeature() {
- assertThat(sTestApis.packages().features()).doesNotContain(CHINA_GOOGLE_SERVICES_FEATURE);
+ assertThat(TestApis.packages().features()).doesNotContain(CHINA_GOOGLE_SERVICES_FEATURE);
}
@Test
@@ -554,14 +553,14 @@
@Test
@RequireRunOnPrimaryUser
public void requireRunOnPrimaryUserAnnotation_isRunningOnPrimaryUser() {
- assertThat(sTestApis.users().instrumented().resolve().type().name())
+ assertThat(TestApis.users().instrumented().resolve().type().name())
.isEqualTo(SYSTEM_USER_TYPE_NAME);
}
@Test
@RequireRunOnTvProfile
public void requireRunOnTvProfileAnnotation_isRunningOnTvProfile() {
- assertThat(sTestApis.users().instrumented().resolve().type().name())
+ assertThat(TestApis.users().instrumented().resolve().type().name())
.isEqualTo(TV_PROFILE_TYPE_NAME);
}
@@ -574,103 +573,103 @@
@Test
@RequireRunOnPrimaryUser
public void requireRunOnUser_isCurrentUser() {
- assertThat(sTestApis.users().current()).isEqualTo(sDeviceState.primaryUser());
+ assertThat(TestApis.users().current()).isEqualTo(sDeviceState.primaryUser());
}
@Test
@RequireRunOnPrimaryUser(switchedToUser = FALSE)
public void requireRunOnUser_specifyNotSwitchedToUser_isNotCurrentUser() {
- assertThat(sTestApis.users().current()).isNotEqualTo(sDeviceState.primaryUser());
+ assertThat(TestApis.users().current()).isNotEqualTo(sDeviceState.primaryUser());
}
@Test
@EnsureHasSecondaryUser(switchedToUser = FALSE) // We don't test the default as it's ANY
public void ensureHasUser_specifyIsNotSwitchedToUser_isNotCurrentUser() {
- assertThat(sTestApis.users().current()).isNotEqualTo(sDeviceState.secondaryUser());
+ assertThat(TestApis.users().current()).isNotEqualTo(sDeviceState.secondaryUser());
}
@Test
@EnsureHasSecondaryUser(switchedToUser = TRUE)
public void ensureHasUser_specifySwitchedToUser_isCurrentUser() {
- assertThat(sTestApis.users().current()).isEqualTo(sDeviceState.secondaryUser());
+ assertThat(TestApis.users().current()).isEqualTo(sDeviceState.secondaryUser());
}
@Test
@RequireRunOnWorkProfile
public void requireRunOnProfile_parentIsCurrentUser() {
- assertThat(sTestApis.users().current()).isEqualTo(
+ assertThat(TestApis.users().current()).isEqualTo(
sDeviceState.workProfile().resolve().parent());
}
@Test
@RequireRunOnWorkProfile(switchedToParentUser = FALSE)
public void requireRunOnProfile_specifyNotSwitchedToParentUser_parentIsNotCurrentUser() {
- assertThat(sTestApis.users().current()).isNotEqualTo(
+ assertThat(TestApis.users().current()).isNotEqualTo(
sDeviceState.workProfile().resolve().parent());
}
@Test
@EnsureHasWorkProfile(switchedToParentUser = FALSE) // We don't test the default as it's ANY
public void ensureHasWorkProfile_specifyNotSwitchedToParentUser_parentIsNotCurrentUser() {
- assertThat(sTestApis.users().current()).isNotEqualTo(
+ assertThat(TestApis.users().current()).isNotEqualTo(
sDeviceState.workProfile().resolve().parent());
}
@Test
@EnsureHasWorkProfile(switchedToParentUser = TRUE)
public void ensureHasWorkProfile_specifySwitchedToParentUser_parentIsCurrentUser() {
- assertThat(sTestApis.users().current()).isEqualTo(
+ assertThat(TestApis.users().current()).isEqualTo(
sDeviceState.workProfile().resolve().parent());
}
@Test
@IncludeRunOnBackgroundDeviceOwnerUser
public void includeRunOnBackgroundDeviceOwnerUserAnnotation_isRunningOnDeviceOwnerUser() {
- assertThat(sTestApis.users().instrumented())
+ assertThat(TestApis.users().instrumented())
.isEqualTo(sDeviceState.dpc().devicePolicyController().user());
}
@Test
@IncludeRunOnBackgroundDeviceOwnerUser
public void includeRunOnBackgroundDeviceOwnerUserAnnotation_isNotCurrentUser() {
- assertThat(sTestApis.users().current())
- .isNotEqualTo(sTestApis.users().instrumented());
+ assertThat(TestApis.users().current())
+ .isNotEqualTo(TestApis.users().instrumented());
}
@Test
@EnsureHasNoProfileOwner
public void ensureHasNoProfileOwnerAnnotation_currentUserHasNoProfileOwner() {
- assertThat(sTestApis.devicePolicy()
- .getProfileOwner(sTestApis.users().instrumented()))
+ assertThat(TestApis.devicePolicy()
+ .getProfileOwner(TestApis.users().instrumented()))
.isNull();
}
@Test
@EnsureHasNoDeviceOwner
public void ensureHasNoDeviceOwnerAnnotation_noDeviceOwner() {
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isNull();
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isNull();
}
@Test
@EnsureHasNoDpc
public void ensureHasNoDpcAnnotation_currentUserHasNoProfileOwner() {
- assertThat(sTestApis.devicePolicy()
- .getProfileOwner(sTestApis.users().instrumented()))
+ assertThat(TestApis.devicePolicy()
+ .getProfileOwner(TestApis.users().instrumented()))
.isNull();
}
@Test
@EnsureHasNoDpc
public void ensureHasNoDpcAnnotation_noDeviceOwner() {
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isNull();
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isNull();
}
@Test
@EnsureHasNoDpc
public void ensureHasNoDpcAnnotation_workProfileDoesNotExist() {
- assertThat(sTestApis.users().findProfileOfType(
- sTestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
- sTestApis.users().instrumented())
+ assertThat(TestApis.users().findProfileOfType(
+ TestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME),
+ TestApis.users().instrumented())
).isNull();
}
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/TestApis.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/TestApis.java
index 9f8d6aa..ff82550 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/TestApis.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/TestApis.java
@@ -29,47 +29,45 @@
* Entry point to Nene Test APIs.
*/
public final class TestApis {
- private final Context mContext = new Context(this);
- private final Users mUsers = new Users(this);
- private final Packages mPackages = new Packages(this);
- private final DevicePolicy mDevicePolicy = new DevicePolicy(this);
- private final Activities mActivities = new Activities(this);
-
/** Access Test APIs related to Users. */
- public Users users() {
- return mUsers;
+ public static Users users() {
+ return Users.sInstance;
}
/** Access Test APIs related to Packages. */
- public Packages packages() {
- return mPackages;
+ public static Packages packages() {
+ return Packages.sInstance;
}
/** Access Test APIs related to device policy. */
- public DevicePolicy devicePolicy() {
- return mDevicePolicy;
+ public static DevicePolicy devicePolicy() {
+ return DevicePolicy.sInstance;
}
/** Access Test APIs related to permissions. */
- public Permissions permissions() {
+ public static Permissions permissions() {
return Permissions.sInstance;
}
/** Access Test APIs related to context. */
- public Context context() {
- return mContext;
+ public static Context context() {
+ return Context.sInstance;
}
/** Access Test APIs relating to Settings. */
- public Settings settings() {
+ public static Settings settings() {
return Settings.sInstance;
}
/** Access Test APIs related to activities. */
- // TODO(scottjonathan): Consider if Activities requires a top-level nene API or if it can go
- // inside packages
@Experimental
- public Activities activities() {
- return mActivities;
+ public static Activities activities() {
+ return Activities.sInstance;
+ }
+
+ /** @deprecated Use statically */
+ @Deprecated()
+ public TestApis() {
+
}
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/Activities.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/Activities.java
index 8cf99ec..fb86fd7 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/Activities.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/Activities.java
@@ -29,31 +29,30 @@
public final class Activities {
- private final TestApis mTestApis;
+ public static final Activities sInstance = new Activities();
- public Activities(TestApis testApis) {
- mTestApis = testApis;
+ private Activities() {
}
/**
* Wrap the given {@link NeneActivityDirect} to use Nene APIs.
*/
public Activity<NeneActivityDirect> wrap(NeneActivity activity) {
- return new Activity<>(mTestApis, activity, activity);
+ return new Activity<>(activity, activity);
}
/**
* Wrap the given {@link NeneActivityDirect} subclass to use Nene APIs.
*/
public <E extends NeneActivity> Activity<E> wrap(Class<E> clazz, E activity) {
- return new Activity<>(mTestApis, activity, activity);
+ return new Activity<>(activity, activity);
}
/**
* Wrap the given {@link android.app.Activity} to use Nene APIs.
*/
public LocalActivity wrap(android.app.Activity activity) {
- return new LocalActivity(mTestApis, activity);
+ return new LocalActivity(activity);
}
/**
@@ -61,16 +60,16 @@
*/
@Experimental
public ComponentReference foregroundActivity() {
- try (PermissionContext p = mTestApis.permissions().withPermission(REAL_GET_TASKS)) {
+ try (PermissionContext p = TestApis.permissions().withPermission(REAL_GET_TASKS)) {
ActivityManager activityManager =
- mTestApis.context().instrumentedContext().getSystemService(
+ TestApis.context().instrumentedContext().getSystemService(
ActivityManager.class);
List<ActivityManager.RunningTaskInfo> runningTasks = activityManager.getRunningTasks(1);
if (runningTasks.isEmpty()) {
return null;
}
- return new ComponentReference(mTestApis, runningTasks.get(0).topActivity);
+ return new ComponentReference(runningTasks.get(0).topActivity);
}
}
@@ -83,7 +82,7 @@
@Experimental
public int getLockTaskModeState() {
ActivityManager activityManager =
- mTestApis.context().instrumentedContext().getSystemService(
+ TestApis.context().instrumentedContext().getSystemService(
ActivityManager.class);
return activityManager.getLockTaskModeState();
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/Activity.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/Activity.java
index e78173b..47ae4a6 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/Activity.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/Activity.java
@@ -45,12 +45,10 @@
* {@link LocalActivity}.
*/
- private final TestApis mTestApis;
private final E mActivityInstance;
private final NeneActivity mActivity;
- Activity(TestApis testApis, E activityInstance, NeneActivity activity) {
- mTestApis = testApis;
+ Activity(E activityInstance, NeneActivity activity) {
mActivityInstance = activityInstance;
mActivity = activity;
}
@@ -67,7 +65,7 @@
// TODO(scottjonathan): What if we're already in lock task mode when we start it here?
// find another thing to poll on
PollingCheck.waitFor(
- () -> mTestApis.activities().getLockTaskModeState() != LOCK_TASK_MODE_NONE);
+ () -> TestApis.activities().getLockTaskModeState() != LOCK_TASK_MODE_NONE);
}
/**
@@ -82,7 +80,7 @@
// TODO(scottjonathan): What if we're already in lock task mode when we start it here?
// find another thing to poll on
PollingCheck.waitFor(
- () -> mTestApis.activities().getLockTaskModeState() == LOCK_TASK_MODE_NONE);
+ () -> TestApis.activities().getLockTaskModeState() == LOCK_TASK_MODE_NONE);
}
/**
@@ -96,14 +94,15 @@
public void startActivity(Intent intent) {
Log.d(TAG, "startActivity(): " + intent);
if (intent.getComponent() == null) {
- ComponentReference startActivity = mTestApis.activities().foregroundActivity();
+ ComponentReference startActivity = TestApis.activities().foregroundActivity();
mActivity.startActivity(intent);
PollingCheck.waitFor(() -> !Objects.equals(startActivity,
- mTestApis.activities().foregroundActivity()));
+ TestApis.activities().foregroundActivity()));
} else {
mActivity.startActivity(intent);
- ComponentReference component = new ComponentReference(mTestApis, intent.getComponent());
- PollingCheck.waitFor(() -> component.equals(mTestApis.activities().foregroundActivity()));
+ ComponentReference component = new ComponentReference(intent.getComponent());
+ PollingCheck.waitFor(
+ () -> component.equals(TestApis.activities().foregroundActivity()));
}
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/ActivityReference.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/ActivityReference.java
index fa76cf4..bf3f647 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/ActivityReference.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/ActivityReference.java
@@ -18,7 +18,6 @@
import android.content.ComponentName;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.nene.packages.ComponentReference;
import com.android.bedstead.nene.packages.PackageReference;
@@ -26,16 +25,16 @@
* A representation of an activity on device which may or may not exist.
*/
public final class ActivityReference extends ComponentReference {
- public ActivityReference(TestApis testApis, PackageReference packageName, String className) {
- super(testApis, packageName, className);
+ public ActivityReference(PackageReference packageName, String className) {
+ super(packageName, className);
}
- public ActivityReference(TestApis testApis, ComponentName component) {
- super(testApis, component);
+ public ActivityReference(ComponentName component) {
+ super(component);
}
- public ActivityReference(TestApis testApis, ComponentReference component) {
- super(testApis, component.componentName());
+ public ActivityReference(ComponentReference component) {
+ super(component.componentName());
}
@Override
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/LocalActivity.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/LocalActivity.java
index f706f56..35dd6d1 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/LocalActivity.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/activities/LocalActivity.java
@@ -16,11 +16,9 @@
package com.android.bedstead.nene.activities;
-import com.android.bedstead.nene.TestApis;
-
public class LocalActivity extends Activity<android.app.Activity> {
- LocalActivity(TestApis testApis, android.app.Activity activity) {
- super(testApis, activity, new ActivityWrapper(activity));
+ LocalActivity(android.app.Activity activity) {
+ super(activity, new ActivityWrapper(activity));
}
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/context/Context.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/context/Context.java
index becd320..0df8293 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/context/Context.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/context/Context.java
@@ -20,7 +20,6 @@
import androidx.test.platform.app.InstrumentationRegistry;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.nene.exceptions.NeneException;
import com.android.bedstead.nene.users.UserReference;
@@ -33,10 +32,11 @@
InstrumentationRegistry.getInstrumentation().getTargetContext();
private static final android.content.Context sInstrumentationContext =
InstrumentationRegistry.getInstrumentation().getContext();
- private final TestApis mTestApis;
- public Context(TestApis testApis) {
- mTestApis = testApis;
+ public static final Context sInstance = new Context();
+
+ private Context() {
+
}
/**
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/AdbDevicePolicyParser.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/AdbDevicePolicyParser.java
index 505f306..f17f113 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/AdbDevicePolicyParser.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/AdbDevicePolicyParser.java
@@ -19,7 +19,6 @@
import android.annotation.TargetApi;
import android.os.Build;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.nene.exceptions.AdbParseException;
import com.android.bedstead.nene.users.UserReference;
@@ -32,8 +31,8 @@
/**
* Get the {@link AdbDevicePolicyParser} for the given version.
*/
- static AdbDevicePolicyParser get(TestApis testApis, int sdkVersion) {
- return new AdbDevicePolicyParser27(testApis);
+ static AdbDevicePolicyParser get(int sdkVersion) {
+ return new AdbDevicePolicyParser27();
}
/**
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/AdbDevicePolicyParser27.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/AdbDevicePolicyParser27.java
index de24e0d..ccb1a00 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/AdbDevicePolicyParser27.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/AdbDevicePolicyParser27.java
@@ -35,10 +35,7 @@
static final int DEFAULT_INDENTATION = 2;
- private final TestApis mTestApis;
-
- AdbDevicePolicyParser27(TestApis testApis) {
- mTestApis = testApis;
+ AdbDevicePolicyParser27() {
}
@Override
@@ -71,8 +68,8 @@
"ComponentInfo\\{", 2)[1].split("\\}", 2)[0]);
int userId = Integer.parseInt(deviceOwnerSection.split(
"User ID: ", 2)[1].split("\n", 2)[0]);
- return new DeviceOwner(mTestApis, mTestApis.users().find(userId),
- mTestApis.packages().find(componentName.getPackageName()), componentName);
+ return new DeviceOwner(TestApis.users().find(userId),
+ TestApis.packages().find(componentName.getPackageName()), componentName);
}
String getDeviceOwnerSection(Set<String> devicePolicySections) {
@@ -114,7 +111,7 @@
"ComponentInfo\\{", 2)[1].split("\\}", 2)[0]);
int userId = Integer.parseInt(
profileOwnerSection.split("\\(User ", 2)[1].split("\\)", 2)[0]);
- return new ProfileOwner(mTestApis, mTestApis.users().find(userId),
- mTestApis.packages().find(componentName.getPackageName()), componentName);
+ return new ProfileOwner(TestApis.users().find(userId),
+ TestApis.packages().find(componentName.getPackageName()), componentName);
}
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DeviceOwner.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DeviceOwner.java
index 28941d4..6f586d1 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DeviceOwner.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DeviceOwner.java
@@ -39,11 +39,10 @@
*/
public final class DeviceOwner extends DevicePolicyController {
- DeviceOwner(TestApis testApis,
- UserReference user,
+ DeviceOwner(UserReference user,
PackageReference pkg,
ComponentName componentName) {
- super(testApis, user, pkg, componentName);
+ super(user, pkg, componentName);
}
@Override
@@ -65,11 +64,11 @@
}
DevicePolicyManager devicePolicyManager =
- mTestApis.context().androidContextAsUser(mUser).getSystemService(
+ TestApis.context().androidContextAsUser(mUser).getSystemService(
DevicePolicyManager.class);
try (PermissionContext p =
- mTestApis.permissions().withPermission(MANAGE_PROFILE_AND_DEVICE_OWNERS)) {
+ TestApis.permissions().withPermission(MANAGE_PROFILE_AND_DEVICE_OWNERS)) {
devicePolicyManager.forceRemoveActiveAdmin(mComponentName, mUser.id());
}
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DevicePolicy.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DevicePolicy.java
index 68aa6b2..6bf0331 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DevicePolicy.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DevicePolicy.java
@@ -63,23 +63,19 @@
*/
public final class DevicePolicy {
+ public static final DevicePolicy sInstance = new DevicePolicy();
+
private static final String LOG_TAG = "DevicePolicy";
private static final String USER_SETUP_COMPLETE_KEY = "user_setup_complete";
- private final TestApis mTestApis;
private final AdbDevicePolicyParser mParser;
private DeviceOwner mCachedDeviceOwner;
private Map<UserReference, ProfileOwner> mCachedProfileOwners;
- public DevicePolicy(TestApis testApis) {
- if (testApis == null) {
- throw new NullPointerException();
- }
-
- mTestApis = testApis;
- mParser = AdbDevicePolicyParser.get(mTestApis, SDK_INT);
+ private DevicePolicy() {
+ mParser = AdbDevicePolicyParser.get(SDK_INT);
}
/**
@@ -102,8 +98,8 @@
() -> command.executeOrThrowNeneException("Could not set profile owner for user "
+ user + " component " + profileOwnerComponent),
() -> checkForTerminalProfileOwnerFailures(user, profileOwnerComponent));
- return new ProfileOwner(mTestApis, user,
- mTestApis.packages().find(
+ return new ProfileOwner(user,
+ TestApis.packages().find(
profileOwnerComponent.getPackageName()), profileOwnerComponent);
}
@@ -119,9 +115,9 @@
+ " as a profile owner is already set: " + profileOwner);
}
- PackageReference pkg = mTestApis.packages().find(
+ PackageReference pkg = TestApis.packages().find(
profileOwnerComponent.getPackageName());
- if (!mTestApis.packages().installedForUser(user).contains(pkg)) {
+ if (!TestApis.packages().installedForUser(user).contains(pkg)) {
throw new NeneException(
"Could not set profile owner for user " + user
+ " as the package " + pkg + " is not installed");
@@ -157,7 +153,7 @@
}
DevicePolicyManager devicePolicyManager =
- mTestApis.context().instrumentedContext()
+ TestApis.context().instrumentedContext()
.getSystemService(DevicePolicyManager.class);
boolean userSetupComplete = getUserSetupComplete();
@@ -166,7 +162,7 @@
setUserSetupComplete(false);
try (PermissionContext p =
- mTestApis.permissions().withPermission(
+ TestApis.permissions().withPermission(
MANAGE_PROFILE_AND_DEVICE_OWNERS, MANAGE_DEVICE_ADMINS,
INTERACT_ACROSS_USERS_FULL, INTERACT_ACROSS_USERS, CREATE_USERS)) {
devicePolicyManager.setActiveAdmin(deviceOwnerComponent,
@@ -187,8 +183,8 @@
setUserSetupComplete(userSetupComplete);
}
- return new DeviceOwner(mTestApis, user,
- mTestApis.packages().find(
+ return new DeviceOwner(user,
+ TestApis.packages().find(
deviceOwnerComponent.getPackageName()), deviceOwnerComponent);
}
@@ -198,9 +194,9 @@
*/
public void clearOrganizationId(UserReference user) {
try (PermissionContext p =
- mTestApis.permissions().withPermission(MANAGE_PROFILE_AND_DEVICE_OWNERS)) {
+ TestApis.permissions().withPermission(MANAGE_PROFILE_AND_DEVICE_OWNERS)) {
DevicePolicyManager devicePolicyManager =
- mTestApis.context().instrumentedContextAsUser(user)
+ TestApis.context().instrumentedContextAsUser(user)
.getSystemService(DevicePolicyManager.class);
devicePolicyManager.clearOrganizationId();
}
@@ -247,21 +243,21 @@
private void setUserSetupComplete(boolean complete) {
DevicePolicyManager devicePolicyManager =
- mTestApis.context().instrumentedContext()
+ TestApis.context().instrumentedContext()
.getSystemService(DevicePolicyManager.class);
- try (PermissionContext p = mTestApis.permissions().withPermission(
+ try (PermissionContext p = TestApis.permissions().withPermission(
WRITE_SECURE_SETTINGS, MANAGE_PROFILE_AND_DEVICE_OWNERS,
INTERACT_ACROSS_USERS_FULL)) {
- Settings.Secure.putInt(mTestApis.context().androidContextAsUser(
- mTestApis.users().system()).getContentResolver(),
+ Settings.Secure.putInt(TestApis.context().androidContextAsUser(
+ TestApis.users().system()).getContentResolver(),
USER_SETUP_COMPLETE_KEY, complete ? 1 : 0);
- devicePolicyManager.forceUpdateUserSetupComplete(mTestApis.users().system().id());
+ devicePolicyManager.forceUpdateUserSetupComplete(TestApis.users().system().id());
}
}
private boolean getUserSetupComplete() {
return Settings.Secure.getInt(
- mTestApis.context().instrumentedContext().getContentResolver(),
+ TestApis.context().instrumentedContext().getContentResolver(),
USER_SETUP_COMPLETE_KEY, /* def= */ 0) == 1;
}
@@ -280,8 +276,8 @@
() -> checkForTerminalDeviceOwnerFailures(
user, deviceOwnerComponent, /* allowAdditionalUsers= */ false));
- return new DeviceOwner(mTestApis, user,
- mTestApis.packages().find(
+ return new DeviceOwner(user,
+ TestApis.packages().find(
deviceOwnerComponent.getPackageName()), deviceOwnerComponent);
}
@@ -297,9 +293,9 @@
+ " as a device owner is already set: " + deviceOwner);
}
- PackageReference pkg = mTestApis.packages().find(
+ PackageReference pkg = TestApis.packages().find(
deviceOwnerComponent.getPackageName());
- if (!mTestApis.packages().installedForUser(user).contains(pkg)) {
+ if (!TestApis.packages().installedForUser(user).contains(pkg)) {
throw new NeneException(
"Could not set device owner for user " + user
+ " as the package " + pkg + " is not installed");
@@ -311,7 +307,7 @@
}
if (!allowAdditionalUsers) {
- Collection<User> users = mTestApis.users().all();
+ Collection<User> users = TestApis.users().all();
if (users.size() > 1) {
throw new NeneException("Could not set device owner for user "
@@ -324,12 +320,12 @@
private boolean componentCanBeSetAsDeviceAdmin(ComponentName component, UserReference user) {
PackageManager packageManager =
- mTestApis.context().instrumentedContext().getPackageManager();
+ TestApis.context().instrumentedContext().getPackageManager();
Intent intent = new Intent("android.app.action.DEVICE_ADMIN_ENABLED");
intent.setComponent(component);
try (PermissionContext p =
- mTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
List<ResolveInfo> r =
packageManager.queryBroadcastReceiversAsUser(
intent, /* flags= */ 0, user.userHandle());
@@ -374,8 +370,8 @@
/** See {@link android.app.admin.DevicePolicyManager#getPolicyExemptApps()}. */
@Experimental
public Set<String> getPolicyExemptApps() {
- try (PermissionContext p = mTestApis.permissions().withPermission(MANAGE_DEVICE_ADMINS)) {
- return mTestApis.context()
+ try (PermissionContext p = TestApis.permissions().withPermission(MANAGE_DEVICE_ADMINS)) {
+ return TestApis.context()
.instrumentedContext()
.getSystemService(DevicePolicyManager.class)
.getPolicyExemptApps();
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DevicePolicyController.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DevicePolicyController.java
index 059712f..9a8aff3 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DevicePolicyController.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/DevicePolicyController.java
@@ -19,7 +19,6 @@
import android.app.admin.DeviceAdminReceiver;
import android.content.ComponentName;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.nene.packages.PackageReference;
import com.android.bedstead.nene.users.UserReference;
@@ -30,18 +29,15 @@
*/
public abstract class DevicePolicyController implements AutoCloseable {
- protected final TestApis mTestApis;
protected final UserReference mUser;
protected final PackageReference mPackage;
protected final ComponentName mComponentName;
- DevicePolicyController(TestApis testApis,
- UserReference user, PackageReference pkg, ComponentName componentName) {
- if (testApis == null || user == null || pkg == null || componentName == null) {
+ DevicePolicyController(UserReference user, PackageReference pkg, ComponentName componentName) {
+ if (user == null || pkg == null || componentName == null) {
throw new NullPointerException();
}
- mTestApis = testApis;
mUser = user;
mPackage = pkg;
mComponentName = componentName;
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/ProfileOwner.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/ProfileOwner.java
index 3b6d17f..66e48b5 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/ProfileOwner.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/devicepolicy/ProfileOwner.java
@@ -39,11 +39,10 @@
*/
public final class ProfileOwner extends DevicePolicyController {
- ProfileOwner(TestApis testApis,
- UserReference user,
+ ProfileOwner(UserReference user,
PackageReference pkg,
ComponentName componentName) {
- super(testApis, user, pkg, componentName);
+ super(user, pkg, componentName);
}
@Override
@@ -54,11 +53,11 @@
}
DevicePolicyManager devicePolicyManager =
- mTestApis.context().androidContextAsUser(mUser).getSystemService(
+ TestApis.context().androidContextAsUser(mUser).getSystemService(
DevicePolicyManager.class);
try (PermissionContext p =
- mTestApis.permissions().withPermission(MANAGE_PROFILE_AND_DEVICE_OWNERS)) {
+ TestApis.permissions().withPermission(MANAGE_PROFILE_AND_DEVICE_OWNERS)) {
devicePolicyManager.forceRemoveActiveAdmin(mComponentName, mUser.id());
}
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/AdbPackageParser.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/AdbPackageParser.java
index 7ab4681..266736d 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/AdbPackageParser.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/AdbPackageParser.java
@@ -19,7 +19,6 @@
import android.annotation.TargetApi;
import android.os.Build;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.nene.exceptions.AdbParseException;
import java.util.Map;
@@ -29,8 +28,8 @@
@TargetApi(Build.VERSION_CODES.O)
interface AdbPackageParser {
- static AdbPackageParser get(TestApis testApis, int sdkVersion) {
- return new AdbPackageParser26(testApis);
+ static AdbPackageParser get(int sdkVersion) {
+ return new AdbPackageParser26();
}
/**
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/AdbPackageParser26.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/AdbPackageParser26.java
index 2b1a6a8..bf267b0 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/AdbPackageParser26.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/AdbPackageParser26.java
@@ -44,13 +44,7 @@
private static final int PACKAGE_LIST_BASE_INDENTATION = 2;
- private final TestApis mTestApis;
-
- AdbPackageParser26(TestApis testApis) {
- if (testApis == null) {
- throw new NullPointerException();
- }
- mTestApis = testApis;
+ AdbPackageParser26() {
}
@Override
@@ -84,7 +78,7 @@
Set<String> packageStrings = extractPackageStrings(packagesList);
Map<String, Package> packages = new HashMap<>();
for (String packageString : packageStrings) {
- Package pkg = new Package(mTestApis, parsePackage(packageString));
+ Package pkg = new Package(parsePackage(packageString));
packages.put(pkg.packageName(), pkg);
}
return packages;
@@ -155,7 +149,7 @@
return;
}
- UserReference user = mTestApis.users().find(userId);
+ UserReference user = TestApis.users().find(userId);
Package.MutableUserPackage userPackage = new Package.MutableUserPackage();
userPackage.mGrantedPermissions = new HashSet<>();
pkg.mInstalledOnUsers.put(user, userPackage);
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/ComponentReference.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/ComponentReference.java
index 1ac1168..57eec3b 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/ComponentReference.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/ComponentReference.java
@@ -31,20 +31,16 @@
@Experimental
public class ComponentReference {
- final TestApis mTestApis;
final PackageReference mPackage;
final String mClassName;
- public ComponentReference(TestApis testApis, PackageReference packageName, String className) {
- mTestApis = testApis;
+ public ComponentReference(PackageReference packageName, String className) {
mPackage = packageName;
mClassName = className;
}
- public ComponentReference(TestApis testApis, ComponentName component) {
- this(testApis,
- new UnresolvedPackage(testApis, component.getPackageName()),
- component.getClassName());
+ public ComponentReference(ComponentName component) {
+ this(new UnresolvedPackage(component.getPackageName()), component.getClassName());
}
/**
@@ -87,7 +83,7 @@
* Enable this component for the instrumented user.
*/
public ComponentReference enable() {
- return enable(mTestApis.users().instrumented());
+ return enable(TestApis.users().instrumented());
}
/**
@@ -109,7 +105,7 @@
* Disable this component for the instrumented user.
*/
public ComponentReference disable() {
- return disable(mTestApis.users().instrumented());
+ return disable(TestApis.users().instrumented());
}
@Override
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/KeepUninstalledPackagesBuilder.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/KeepUninstalledPackagesBuilder.java
index 7069aaa..55c0c13 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/KeepUninstalledPackagesBuilder.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/KeepUninstalledPackagesBuilder.java
@@ -41,10 +41,8 @@
public final class KeepUninstalledPackagesBuilder {
private final List<String> mPackages = new ArrayList<>();
- private final TestApis mTestApis;
- KeepUninstalledPackagesBuilder(TestApis testApis) {
- mTestApis = testApis;
+ KeepUninstalledPackagesBuilder() {
}
/**
@@ -58,10 +56,10 @@
// APK files and keeping them (either as a file or in memory) until needed to resolve or
// re-install
PackageManager packageManager =
- mTestApis.context().instrumentedContext().getPackageManager();
+ TestApis.context().instrumentedContext().getPackageManager();
try (PermissionContext p =
- mTestApis.permissions().withPermission(KEEP_UNINSTALLED_PACKAGES)) {
+ TestApis.permissions().withPermission(KEEP_UNINSTALLED_PACKAGES)) {
packageManager.setKeepUninstalledPackages(mPackages);
}
}
@@ -91,7 +89,7 @@
*/
@CheckResult
public KeepUninstalledPackagesBuilder add(String pkg) {
- return add(mTestApis.packages().find(pkg));
+ return add(TestApis.packages().find(pkg));
}
/**
@@ -111,6 +109,6 @@
@CheckResult
public KeepUninstalledPackagesBuilder addPackageNames(Collection<String> packages) {
return add(packages.stream().map(
- (s) -> mTestApis.packages().find(s)).collect(Collectors.toSet()));
+ (s) -> TestApis.packages().find(s)).collect(Collectors.toSet()));
}
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/Package.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/Package.java
index 0deddc5..367e9be 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/Package.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/Package.java
@@ -20,7 +20,6 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
-import android.util.Log;
import com.android.bedstead.nene.TestApis;
import com.android.bedstead.nene.users.UserReference;
@@ -56,11 +55,11 @@
private final MutablePackage mMutablePackage;
private final Set<String> mRequestedPermissions;
- Package(TestApis testApis, MutablePackage mutablePackage) {
- super(testApis, mutablePackage.mPackageName);
+ Package(MutablePackage mutablePackage) {
+ super(mutablePackage.mPackageName);
mMutablePackage = mutablePackage;
mRequestedPermissions = new HashSet<>();
- mPackageManager = testApis.context().instrumentedContext().getPackageManager();
+ mPackageManager = TestApis.context().instrumentedContext().getPackageManager();
try {
PackageInfo packageInfo = mPackageManager.getPackageInfo(
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/PackageReference.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/PackageReference.java
index 3ecda00..8fdd8df 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/PackageReference.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/PackageReference.java
@@ -49,16 +49,14 @@
* <p>To resolve the package into a {@link Package}, see {@link #resolve()}.
*/
public abstract class PackageReference {
- private final TestApis mTestApis;
private final String mPackageName;
private static final int PIDS_PER_USER_ID = 100000;
private final PackageManager mPackageManager;
- PackageReference(TestApis testApis, String packageName) {
- mTestApis = testApis;
- mPackageManager = mTestApis.context().instrumentedContext().getPackageManager();
+ PackageReference(String packageName) {
+ mPackageManager = TestApis.context().instrumentedContext().getPackageManager();
mPackageName = packageName;
}
@@ -73,7 +71,7 @@
*/
@Nullable
public Package resolve() {
- return mTestApis.packages().fetchPackage(mPackageName);
+ return TestApis.packages().fetchPackage(mPackageName);
}
/**
@@ -136,11 +134,11 @@
// This is outside of the try because we don't want to await if the package isn't installed
BlockingBroadcastReceiver broadcastReceiver = BlockingBroadcastReceiver.create(
- mTestApis.context().androidContextAsUser(user),
+ TestApis.context().androidContextAsUser(user),
packageRemovedIntentFilter);
try {
- try (PermissionContext p = mTestApis.permissions().withPermission(
+ try (PermissionContext p = TestApis.permissions().withPermission(
INTERACT_ACROSS_USERS_FULL)) {
broadcastReceiver.register();
}
@@ -187,7 +185,7 @@
*/
@Experimental
public PackageReference enable() {
- return enable(mTestApis.users().instrumented());
+ return enable(TestApis.users().instrumented());
}
/**
@@ -211,7 +209,7 @@
*/
@Experimental
public PackageReference disable() {
- return disable(mTestApis.users().instrumented());
+ return disable(TestApis.users().instrumented());
}
/**
@@ -221,7 +219,7 @@
*/
@Experimental
public ComponentReference component(String componentName) {
- return new ComponentReference(mTestApis, this, componentName);
+ return new ComponentReference(this, componentName);
}
/**
@@ -266,8 +264,8 @@
// There is no readable output upon failure so we need to check ourselves
checkCanGrantOrRevokePermission(user, permission);
- if (packageName().equals(mTestApis.context().instrumentedContext().getPackageName())
- && user.equals(mTestApis.users().instrumented())) {
+ if (packageName().equals(TestApis.context().instrumentedContext().getPackageName())
+ && user.equals(TestApis.users().instrumented())) {
Package resolved = resolve();
if (!resolved.grantedPermissions(user).contains(permission)) {
return this; // Already denied
@@ -339,7 +337,7 @@
.addOperand("-n")
.executeAndParseOutput(o -> parsePsOutput(o).stream()
.filter(p -> p.mPackageName.equals(mPackageName))
- .map(p -> new ProcessReference(this, p.mPid, mTestApis.users().find(p.mUserId))))
+ .map(p -> new ProcessReference(this, p.mPid, TestApis.users().find(p.mUserId))))
.collect(Collectors.toSet());
} catch (AdbException e) {
throw new NeneException("Error getting running processes ", e);
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/Packages.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/Packages.java
index 4c880ea..7c701f7 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/Packages.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/Packages.java
@@ -144,24 +144,21 @@
}
}
+ public static final Packages sInstance = new Packages();
+
private Map<String, Package> mCachedPackages = null;
private Set<String> mFeatures = null;
private final AdbPackageParser mParser;
- final TestApis mTestApis;
private final Context mInstrumentedContext;
private final IntentFilter mPackageAddedIntentFilter =
new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
- public Packages(TestApis testApis) {
- if (testApis == null) {
- throw new NullPointerException();
- }
+ public Packages() {
mPackageAddedIntentFilter.addDataScheme("package");
- mTestApis = testApis;
- mParser = AdbPackageParser.get(mTestApis, SDK_INT);
- mInstrumentedContext = mTestApis.context().instrumentedContext();
+ mParser = AdbPackageParser.get(SDK_INT);
+ mInstrumentedContext = TestApis.context().instrumentedContext();
}
@@ -258,7 +255,7 @@
// the same time...
String installedPackageName = intent.getDataString().split(":", 2)[1];
- return mTestApis.packages().find(installedPackageName);
+ return TestApis.packages().find(installedPackageName);
}
// TODO: Move this somewhere reusable (in utils)
@@ -302,11 +299,11 @@
try {
PackageManager packageManager =
- mTestApis.context().androidContextAsUser(user).getPackageManager();
+ TestApis.context().androidContextAsUser(user).getPackageManager();
PackageInstaller packageInstaller = packageManager.getPackageInstaller();
int sessionId;
- try (PermissionContext p = mTestApis.permissions().withPermission(
+ try (PermissionContext p = TestApis.permissions().withPermission(
INTERACT_ACROSS_USERS_FULL, INTERACT_ACROSS_USERS, INSTALL_TEST_ONLY_PACKAGE)) {
PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(
MODE_FULL_INSTALL);
@@ -323,7 +320,7 @@
try (BlockingIntentSender intentSender = BlockingIntentSender.create()) {
try (PermissionContext p =
- mTestApis.permissions().withPermission(INSTALL_PACKAGES)) {
+ TestApis.permissions().withPermission(INSTALL_PACKAGES)) {
session.commit(intentSender.intentSender());
session.close();
@@ -350,7 +347,7 @@
private PackageReference installPreS(UserReference user, byte[] apkFile) {
// Prior to S we cannot pass bytes to stdin so we write it to a temp file first
- File outputDir = mTestApis.context().instrumentedContext().getCacheDir();
+ File outputDir = TestApis.context().instrumentedContext().getCacheDir();
File outputFile = null;
try {
outputFile = File.createTempFile("tmp", ".apk", outputDir);
@@ -410,16 +407,16 @@
private BlockingBroadcastReceiver registerPackageInstalledBroadcastReceiver(
UserReference user) {
BlockingBroadcastReceiver broadcastReceiver = BlockingBroadcastReceiver.create(
- mTestApis.context().androidContextAsUser(user),
+ TestApis.context().androidContextAsUser(user),
mPackageAddedIntentFilter);
- if (user.equals(mTestApis.users().instrumented())) {
+ if (user.equals(TestApis.users().instrumented())) {
broadcastReceiver.register();
} else {
// TODO(scottjonathan): If this is cross-user then it needs _FULL, but older versions
// cannot get full - so we'll need to poll
try (PermissionContext p =
- mTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
broadcastReceiver.register();
}
}
@@ -438,7 +435,7 @@
public KeepUninstalledPackagesBuilder keepUninstalledPackages() {
Versions.requireMinimumVersion(Build.VERSION_CODES.S);
- return new KeepUninstalledPackagesBuilder(mTestApis);
+ return new KeepUninstalledPackagesBuilder();
}
@Nullable
@@ -460,7 +457,7 @@
if (packageName == null) {
throw new NullPointerException();
}
- return new UnresolvedPackage(mTestApis, packageName);
+ return new UnresolvedPackage(packageName);
}
/**
@@ -474,7 +471,7 @@
throw new NullPointerException();
}
- return new ComponentReference(mTestApis,
+ return new ComponentReference(
find(componentName.getPackageName()), componentName.getClassName());
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/UnresolvedPackage.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/UnresolvedPackage.java
index d314565..2f689bf 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/UnresolvedPackage.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/packages/UnresolvedPackage.java
@@ -16,14 +16,12 @@
package com.android.bedstead.nene.packages;
-import com.android.bedstead.nene.TestApis;
-
/**
* Default implementation of {@link PackageReference} used when we haven't fetched information from
* the device.
*/
public final class UnresolvedPackage extends PackageReference {
- UnresolvedPackage(TestApis testApis, String packageName) {
- super(testApis, packageName);
+ UnresolvedPackage(String packageName) {
+ super(packageName);
}
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser.java
index a4110ca..93f2229 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser.java
@@ -21,7 +21,6 @@
import androidx.annotation.Nullable;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.nene.exceptions.AdbParseException;
import java.util.Map;
@@ -32,14 +31,14 @@
@TargetApi(Build.VERSION_CODES.O)
interface AdbUserParser {
- static AdbUserParser get(TestApis testApis, int sdkVersion) {
+ static AdbUserParser get(int sdkVersion) {
if (sdkVersion >= 31) {
- return new AdbUserParser31(testApis);
+ return new AdbUserParser31();
}
if (sdkVersion >= 30) {
- return new AdbUserParser30(testApis);
+ return new AdbUserParser30();
}
- return new AdbUserParser26(testApis);
+ return new AdbUserParser26();
}
/**
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser26.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser26.java
index b045921..78a70b7 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser26.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser26.java
@@ -22,7 +22,6 @@
import androidx.annotation.RequiresApi;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.nene.exceptions.AdbParseException;
import java.util.HashMap;
@@ -89,13 +88,7 @@
public class AdbUserParser26 implements AdbUserParser {
static final int USER_LIST_BASE_INDENTATION = 2;
- final TestApis mTestApis;
-
- AdbUserParser26(TestApis testApis) {
- if (testApis == null) {
- throw new NullPointerException();
- }
- mTestApis = testApis;
+ AdbUserParser26() {
}
@Override
@@ -110,7 +103,7 @@
Set<String> userStrings = extractUserStrings(usersList);
Map<Integer, User> users = new HashMap<>();
for (String userString : userStrings) {
- User user = new User(mTestApis, parseUser(userString));
+ User user = new User(parseUser(userString));
users.put(user.id(), user);
}
return users;
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser30.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser30.java
index 64fe4f1..588c9b5 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser30.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser30.java
@@ -22,7 +22,6 @@
import androidx.annotation.RequiresApi;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.nene.exceptions.AdbParseException;
import java.util.HashMap;
@@ -257,8 +256,8 @@
private Map<String, UserType> mUserTypes;
- AdbUserParser30(TestApis testApis) {
- super(testApis);
+ AdbUserParser30() {
+ super();
}
@Override
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser31.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser31.java
index 4b1b385..e472d21 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser31.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/AdbUserParser31.java
@@ -35,8 +35,8 @@
// TODO(scottjonathan): Replace ADB calls for S with test apis
public class AdbUserParser31 extends AdbUserParser30 {
- AdbUserParser31(TestApis testApis) {
- super(testApis);
+ AdbUserParser31() {
+ super();
}
@Override
@@ -45,7 +45,7 @@
if (user.mType.baseType().contains(UserType.BaseType.PROFILE)) {
try {
- user.mParent = mTestApis.users().find(
+ user.mParent = TestApis.users().find(
Integer.parseInt(userString.split("parentId=")[1].split("[ \n]")[0]));
} catch (IndexOutOfBoundsException e) {
throw new AdbParseException("Error parsing user", userString, e);
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UnresolvedUser.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UnresolvedUser.java
index 726c6e6..1845ee6 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UnresolvedUser.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UnresolvedUser.java
@@ -16,16 +16,14 @@
package com.android.bedstead.nene.users;
-import com.android.bedstead.nene.TestApis;
-
/**
* Default implementation of {@link UserReference}.
*
* <p>Represents the abstract idea of a {@link User}, which may or may not exist.
*/
public final class UnresolvedUser extends UserReference {
- UnresolvedUser(TestApis testApis, int id) {
- super(testApis, id);
+ UnresolvedUser(int id) {
+ super(id);
}
@Override
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/User.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/User.java
index e55a09e..f06b004 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/User.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/User.java
@@ -20,8 +20,6 @@
import androidx.annotation.Nullable;
-import com.android.bedstead.nene.TestApis;
-
/**
* Representation of a user on an Android device.
*
@@ -72,8 +70,8 @@
final MutableUser mMutableUser;
- User(TestApis testApis, MutableUser mutableUser) {
- super(testApis, mutableUser.mId);
+ User(MutableUser mutableUser) {
+ super(mutableUser.mId);
mMutableUser = mutableUser;
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UserBuilder.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UserBuilder.java
index 3172c86..6aca593 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UserBuilder.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UserBuilder.java
@@ -25,7 +25,6 @@
import androidx.annotation.CheckResult;
import androidx.annotation.Nullable;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.nene.exceptions.AdbException;
import com.android.bedstead.nene.exceptions.NeneException;
import com.android.bedstead.nene.utils.ShellCommand;
@@ -38,13 +37,11 @@
*/
public class UserBuilder {
- private final TestApis mTestApis;
private String mName;
private @Nullable UserType mType;
private @Nullable UserReference mParent;
- UserBuilder(TestApis testApis) {
- mTestApis = testApis;
+ UserBuilder() {
}
/**
@@ -141,7 +138,7 @@
commandBuilder.validate(ShellCommandUtils::startsWithSuccess)
.executeAndParseOutput(
(output) -> Integer.parseInt(output.split("id ")[1].trim()));
- return new UnresolvedUser(mTestApis, userId);
+ return new UnresolvedUser(userId);
} catch (AdbException e) {
throw new NeneException("Could not create user " + this, e);
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UserReference.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UserReference.java
index 619cc6c..123d941 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UserReference.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/UserReference.java
@@ -41,14 +41,9 @@
*/
public abstract class UserReference implements AutoCloseable {
- private final TestApis mTestApis;
private final int mId;
- UserReference(TestApis testApis, int id) {
- if (testApis == null) {
- throw new NullPointerException();
- }
- mTestApis = testApis;
+ UserReference(int id) {
mId = id;
}
@@ -69,7 +64,7 @@
*/
@Nullable
public final User resolve() {
- return mTestApis.users().fetchUser(mId);
+ return TestApis.users().fetchUser(mId);
}
/**
@@ -87,7 +82,7 @@
.addOperand(mId)
.validate(ShellCommandUtils::startsWithSuccess)
.execute();
- mTestApis.users().waitForUserToNotExistOrMatch(this, User::isRemoving);
+ TestApis.users().waitForUserToNotExistOrMatch(this, User::isRemoving);
} catch (AdbException e) {
throw new NeneException("Could not remove user " + this, e);
}
@@ -111,7 +106,7 @@
.addOperand("-w")
.validate(ShellCommandUtils::startsWithSuccess)
.execute();
- User waitedUser = mTestApis.users().waitForUserToNotExistOrMatch(
+ User waitedUser = TestApis.users().waitForUserToNotExistOrMatch(
this, (user) -> user.state() == UserState.RUNNING_UNLOCKED);
if (waitedUser == null) {
throw new NeneException("User does not exist " + this);
@@ -137,7 +132,7 @@
.allowEmptyOutput(true)
.validate(String::isEmpty)
.execute();
- User waitedUser = mTestApis.users().waitForUserToNotExistOrMatch(
+ User waitedUser = TestApis.users().waitForUserToNotExistOrMatch(
this, (user) -> user.state() == UserState.NOT_RUNNING);
if (waitedUser == null) {
throw new NeneException("User does not exist " + this);
@@ -156,7 +151,7 @@
// This is created outside of the try because we don't want to wait for the broadcast
// on versions less than Q
BlockingBroadcastReceiver broadcastReceiver =
- new BlockingBroadcastReceiver(mTestApis.context().instrumentedContext(),
+ new BlockingBroadcastReceiver(TestApis.context().instrumentedContext(),
Intent.ACTION_USER_FOREGROUND,
(intent) ->((UserHandle)
intent.getParcelableExtra(Intent.EXTRA_USER))
@@ -165,7 +160,7 @@
try {
if (Versions.meetsMinimumSdkVersionRequirement(Q)) {
try (PermissionContext p =
- mTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
broadcastReceiver.registerForAllUsers();
}
}
diff --git a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/Users.java b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/Users.java
index 6e3bc11..0275fc3 100644
--- a/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/Users.java
+++ b/common/device-side/bedstead/nene/src/main/java/com/android/bedstead/nene/users/Users.java
@@ -60,11 +60,11 @@
private Map<String, UserType> mCachedUserTypes = null;
private Set<UserType> mCachedUserTypeValues = null;
private final AdbUserParser mParser;
- private final TestApis mTestApis;
- public Users(TestApis testApis) {
- mTestApis = testApis;
- mParser = AdbUserParser.get(mTestApis, SDK_INT);
+ public static final Users sInstance = new Users();
+
+ private Users() {
+ mParser = AdbUserParser.get(SDK_INT);
}
/** Get all {@link User}s on the device. */
@@ -78,7 +78,7 @@
public UserReference current() {
if (Versions.meetsMinimumSdkVersionRequirement(Q)) {
try (PermissionContext p =
- mTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
return find(ActivityManager.getCurrentUser());
}
}
@@ -103,12 +103,12 @@
/** Get a {@link UserReference} by {@code id}. */
public UserReference find(int id) {
- return new UnresolvedUser(mTestApis, id);
+ return new UnresolvedUser(id);
}
/** Get a {@link UserReference} by {@code userHandle}. */
public UserReference find(UserHandle userHandle) {
- return new UnresolvedUser(mTestApis, userHandle.getIdentifier());
+ return new UnresolvedUser(userHandle.getIdentifier());
}
@Nullable
@@ -265,7 +265,7 @@
*/
@CheckResult
public UserBuilder createUser() {
- return new UserBuilder(mTestApis);
+ return new UserBuilder();
}
/**
@@ -279,7 +279,7 @@
id++;
}
- return new UnresolvedUser(mTestApis, id);
+ return new UnresolvedUser(id);
}
private void fillCache() {
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/TestApisTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/TestApisTest.java
index db10699..7779c0a 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/TestApisTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/TestApisTest.java
@@ -16,8 +16,6 @@
package com.android.bedstead.nene;
-import static com.google.common.truth.Truth.assertThat;
-
import com.google.common.truth.Truth;
import org.junit.Test;
@@ -27,15 +25,13 @@
@RunWith(JUnit4.class)
public class TestApisTest {
- private final TestApis mTestApis = new TestApis();
-
@Test
public void users_returnsInstance() {
- Truth.assertThat(mTestApis.users()).isNotNull();
+ Truth.assertThat(TestApis.users()).isNotNull();
}
@Test
public void users_multipleCalls_returnsSameInstance() {
- Truth.assertThat(mTestApis.users()).isEqualTo(mTestApis.users());
+ Truth.assertThat(TestApis.users()).isEqualTo(TestApis.users());
}
}
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/DeviceOwnerTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/DeviceOwnerTest.java
index 38ff4aa..4f2c4f0 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/DeviceOwnerTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/DeviceOwnerTest.java
@@ -42,8 +42,7 @@
new ComponentName(DEVICE_ADMIN_TESTAPP_PACKAGE_NAME,
EventLibDeviceAdminReceiver.class.getName());
- private static final TestApis sTestApis = new TestApis();
- private static final UserReference sUser = sTestApis.users().instrumented();
+ private static final UserReference sUser = TestApis.users().instrumented();
private static TestApp sTestApp;
private static DeviceOwner sDeviceOwner;
@@ -56,7 +55,7 @@
sTestApp.install(sUser);
- sDeviceOwner = sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME);
+ sDeviceOwner = TestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME);
}
@AfterClass
@@ -84,9 +83,9 @@
public void remove_removesDeviceOwner() {
sDeviceOwner.remove();
try {
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isNull();
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isNull();
} finally {
- sDeviceOwner = sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME);
+ sDeviceOwner = TestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME);
}
}
}
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/DevicePolicyTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/DevicePolicyTest.java
index cc28e5c..efce051 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/DevicePolicyTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/DevicePolicyTest.java
@@ -68,9 +68,8 @@
new ComponentName(DEVICE_ADMIN_TESTAPP_PACKAGE_NAME,
"incorrect.class.name");
- private static final TestApis sTestApis = new TestApis();
- private static final UserReference sUser = sTestApis.users().instrumented();
- private static final UserReference NON_EXISTENT_USER = sTestApis.users().find(99999);
+ private static final UserReference sUser = TestApis.users().instrumented();
+ private static final UserReference NON_EXISTENT_USER = TestApis.users().find(99999);
private static TestApp sTestApp;
@@ -92,17 +91,17 @@
@EnsureHasNoDeviceOwner
@EnsureHasNoWorkProfile
public void setProfileOwner_profileOwnerIsSet() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
sTestApp.install(profile);
ProfileOwner profileOwner =
- sTestApis.devicePolicy().setProfileOwner(profile, DPC_COMPONENT_NAME);
+ TestApis.devicePolicy().setProfileOwner(profile, DPC_COMPONENT_NAME);
try {
- assertThat(sTestApis.devicePolicy().getProfileOwner(profile)).isEqualTo(profileOwner);
+ assertThat(TestApis.devicePolicy().getProfileOwner(profile)).isEqualTo(profileOwner);
} finally {
profile.remove();
}
@@ -112,17 +111,17 @@
@EnsureHasNoDeviceOwner
@EnsureHasNoWorkProfile
public void setProfileOwner_profileOwnerIsAlreadySet_throwsException() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
sTestApp.install(profile);
- sTestApis.devicePolicy().setProfileOwner(profile, DPC_COMPONENT_NAME);
+ TestApis.devicePolicy().setProfileOwner(profile, DPC_COMPONENT_NAME);
assertThrows(NeneException.class,
- () -> sTestApis.devicePolicy().setProfileOwner(profile, DPC_COMPONENT_NAME));
+ () -> TestApis.devicePolicy().setProfileOwner(profile, DPC_COMPONENT_NAME));
} finally {
profile.remove();
}
@@ -132,13 +131,13 @@
@EnsureHasNoDeviceOwner
@EnsureHasNoWorkProfile
public void setProfileOwner_componentNameNotInstalled_throwsException() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
assertThrows(NeneException.class,
- () -> sTestApis.devicePolicy().setProfileOwner(
+ () -> TestApis.devicePolicy().setProfileOwner(
profile, NON_EXISTING_DPC_COMPONENT_NAME));
} finally {
profile.remove();
@@ -150,7 +149,7 @@
@EnsureHasNoProfileOwner
public void setProfileOwner_componentNameIsNotDPC_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.devicePolicy().setProfileOwner(sUser, NOT_DPC_COMPONENT_NAME));
+ () -> TestApis.devicePolicy().setProfileOwner(sUser, NOT_DPC_COMPONENT_NAME));
}
@Test
@@ -158,7 +157,7 @@
@EnsureHasNoProfileOwner
public void setProfileOwner_nullUser_throwsException() {
assertThrows(NullPointerException.class,
- () -> sTestApis.devicePolicy().setProfileOwner(
+ () -> TestApis.devicePolicy().setProfileOwner(
/* user= */ null, DPC_COMPONENT_NAME));
}
@@ -167,7 +166,7 @@
@EnsureHasNoProfileOwner
public void setProfileOwner_nullComponentName_throwsException() {
assertThrows(NullPointerException.class,
- () -> sTestApis.devicePolicy().setProfileOwner(
+ () -> TestApis.devicePolicy().setProfileOwner(
sUser, /* profileOwnerComponent= */ null));
}
@@ -176,7 +175,7 @@
@EnsureHasNoProfileOwner
public void setProfileOwner_userDoesNotExist_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.devicePolicy().setProfileOwner(
+ () -> TestApis.devicePolicy().setProfileOwner(
NON_EXISTENT_USER, DPC_COMPONENT_NAME));
}
@@ -184,17 +183,17 @@
@EnsureHasNoDeviceOwner
@EnsureHasNoWorkProfile
public void getProfileOwner_returnsProfileOwner() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
sTestApp.install(profile);
ProfileOwner profileOwner =
- sTestApis.devicePolicy().setProfileOwner(profile, DPC_COMPONENT_NAME);
+ TestApis.devicePolicy().setProfileOwner(profile, DPC_COMPONENT_NAME);
- assertThat(sTestApis.devicePolicy().getProfileOwner(profile)).isEqualTo(profileOwner);
+ assertThat(TestApis.devicePolicy().getProfileOwner(profile)).isEqualTo(profileOwner);
} finally {
profile.remove();
}
@@ -204,13 +203,13 @@
@EnsureHasNoDeviceOwner
@EnsureHasNoWorkProfile
public void getProfileOwner_noProfileOwner_returnsNull() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
- assertThat(sTestApis.devicePolicy().getProfileOwner(profile)).isNull();
+ assertThat(TestApis.devicePolicy().getProfileOwner(profile)).isNull();
} finally {
profile.remove();
}
@@ -220,7 +219,7 @@
@Test
public void getProfileOwner_nullUser_throwsException() {
assertThrows(NullPointerException.class,
- () -> sTestApis.devicePolicy().getProfileOwner(null));
+ () -> TestApis.devicePolicy().getProfileOwner(null));
}
@Test
@@ -228,10 +227,11 @@
@EnsureHasNoProfileOwner
public void setDeviceOwner_deviceOwnerIsSet() {
DeviceOwner deviceOwner =
- sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME);
+ TestApis.devicePolicy()
+ .setDeviceOwner(TestApis.users().system(), DPC_COMPONENT_NAME);
try {
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isEqualTo(deviceOwner);
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isEqualTo(deviceOwner);
} finally {
deviceOwner.remove();
}
@@ -241,7 +241,8 @@
@EnsureHasDeviceOwner
public void setDeviceOwner_deviceOwnerIsAlreadySet_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME));
+ () -> TestApis.devicePolicy()
+ .setDeviceOwner(TestApis.users().system(), DPC_COMPONENT_NAME));
}
@Test
@@ -250,8 +251,8 @@
public void setDeviceOwner_componentNameNotInstalled_throwsException() {
try {
assertThrows(NeneException.class,
- () -> sTestApis.devicePolicy().setDeviceOwner(
- sUser, NON_EXISTING_DPC_COMPONENT_NAME));
+ () -> TestApis.devicePolicy().setDeviceOwner(
+ TestApis.users().system(), NON_EXISTING_DPC_COMPONENT_NAME));
} finally {
sTestApp.install(sUser);
}
@@ -262,7 +263,8 @@
@EnsureHasNoProfileOwner
public void setDeviceOwner_componentNameIsNotDPC_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.devicePolicy().setDeviceOwner(sUser, NOT_DPC_COMPONENT_NAME));
+ () -> TestApis.devicePolicy()
+ .setDeviceOwner(TestApis.users().system(), NOT_DPC_COMPONENT_NAME));
}
@Test
@@ -274,7 +276,8 @@
Versions.meetsMinimumSdkVersionRequirement(Build.VERSION_CODES.S));
assertThrows(NeneException.class,
- () -> sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME));
+ () -> TestApis.devicePolicy()
+ .setDeviceOwner(TestApis.users().system(), DPC_COMPONENT_NAME));
}
@Test
@@ -286,10 +289,11 @@
Versions.meetsMinimumSdkVersionRequirement(Build.VERSION_CODES.S));
DeviceOwner deviceOwner =
- sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME);
+ TestApis.devicePolicy()
+ .setDeviceOwner(TestApis.users().system(), DPC_COMPONENT_NAME);
try {
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isNotNull();
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isNotNull();
} finally {
deviceOwner.remove();
}
@@ -305,7 +309,7 @@
@EnsureHasNoProfileOwner
public void setDeviceOwner_nullUser_throwsException() {
assertThrows(NullPointerException.class,
- () -> sTestApis.devicePolicy().setDeviceOwner(
+ () -> TestApis.devicePolicy().setDeviceOwner(
/* user= */ null, DPC_COMPONENT_NAME));
}
@@ -314,8 +318,8 @@
@EnsureHasNoProfileOwner
public void setDeviceOwner_nullComponentName_throwsException() {
assertThrows(NullPointerException.class,
- () -> sTestApis.devicePolicy().setDeviceOwner(
- sUser, /* deviceOwnerComponent= */ null));
+ () -> TestApis.devicePolicy().setDeviceOwner(
+ TestApis.users().system(), /* deviceOwnerComponent= */ null));
}
@Test
@@ -323,7 +327,7 @@
@EnsureHasNoProfileOwner
public void setDeviceOwner_userDoesNotExist_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.devicePolicy().setDeviceOwner(
+ () -> TestApis.devicePolicy().setDeviceOwner(
NON_EXISTENT_USER, DPC_COMPONENT_NAME));
}
@@ -335,10 +339,11 @@
@EnsureHasNoWorkProfile
public void getDeviceOwner_returnsDeviceOwner() {
DeviceOwner deviceOwner =
- sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME);
+ TestApis.devicePolicy().setDeviceOwner(
+ TestApis.users().system(), DPC_COMPONENT_NAME);
try {
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isEqualTo(deviceOwner);
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isEqualTo(deviceOwner);
} finally {
deviceOwner.remove();
}
@@ -347,7 +352,7 @@
@Test
@EnsureHasNoDeviceOwner
public void getDeviceOwner_noDeviceOwner_returnsNull() {
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isNull();
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isNull();
}
@Test
@@ -355,11 +360,11 @@
@EnsureHasNoProfileOwner
public void profileOwner_autoclose_removesProfileOwner() {
try (ProfileOwner profileOwner =
- sTestApis.devicePolicy().setProfileOwner(sUser, DPC_COMPONENT_NAME)) {
+ TestApis.devicePolicy().setProfileOwner(sUser, DPC_COMPONENT_NAME)) {
// We intentionally don't do anything here, just rely on the auto-close behaviour
}
- assertThat(sTestApis.devicePolicy().getProfileOwner(sUser)).isNull();
+ assertThat(TestApis.devicePolicy().getProfileOwner(sUser)).isNull();
}
@Test
@@ -367,54 +372,59 @@
@EnsureHasNoProfileOwner
public void deviceOwner_autoclose_removesDeviceOwner() {
try (DeviceOwner deviceOwner =
- sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME)) {
+ TestApis.devicePolicy().setDeviceOwner(
+ TestApis.users().system(), DPC_COMPONENT_NAME)) {
// We intentionally don't do anything here, just rely on the auto-close behaviour
}
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isNull();
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isNull();
}
@Test
@EnsureHasNoDeviceOwner
@EnsureHasNoProfileOwner
public void setDeviceOwner_recentlyUnsetProfileOwner_sets() {
- sTestApis.devicePolicy().setProfileOwner(sUser, DPC_COMPONENT_NAME).remove();
+ TestApis.devicePolicy().setProfileOwner(sUser, DPC_COMPONENT_NAME).remove();
- sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME);
+ TestApis.devicePolicy().setDeviceOwner(
+ TestApis.users().system(), DPC_COMPONENT_NAME);
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isNotNull();
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isNotNull();
}
@Test
@EnsureHasNoDeviceOwner
@EnsureHasNoProfileOwner
public void setDeviceOwner_recentlyUnsetDeviceOwner_sets() {
- sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME).remove();
+ TestApis.devicePolicy()
+ .setDeviceOwner(TestApis.users().system(), DPC_COMPONENT_NAME)
+ .remove();
- sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME);
+ TestApis.devicePolicy().setDeviceOwner(TestApis.users().system(), DPC_COMPONENT_NAME);
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isNotNull();
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isNotNull();
}
@Test
@EnsureHasNoDeviceOwner
@EnsureHasNoProfileOwner
public void setProfileOwner_recentlyUnsetProfileOwner_sets() {
- sTestApis.devicePolicy().setProfileOwner(sUser, DPC_COMPONENT_NAME).remove();
+ TestApis.devicePolicy().setProfileOwner(sUser, DPC_COMPONENT_NAME).remove();
- sTestApis.devicePolicy().setProfileOwner(sUser, DPC_COMPONENT_NAME);
+ TestApis.devicePolicy().setProfileOwner(sUser, DPC_COMPONENT_NAME);
- assertThat(sTestApis.devicePolicy().getProfileOwner(sUser)).isNotNull();
+ assertThat(TestApis.devicePolicy().getProfileOwner(sUser)).isNotNull();
}
@Test
@EnsureHasNoDeviceOwner
@EnsureHasNoProfileOwner
public void setProfileOwner_recentlyUnsetDeviceOwner_sets() {
- sTestApis.devicePolicy().setDeviceOwner(sUser, DPC_COMPONENT_NAME).remove();
+ TestApis.devicePolicy().setDeviceOwner(TestApis.users().system(), DPC_COMPONENT_NAME)
+ .remove();
- sTestApis.devicePolicy().setProfileOwner(sUser, DPC_COMPONENT_NAME);
+ TestApis.devicePolicy().setProfileOwner(sUser, DPC_COMPONENT_NAME);
- assertThat(sTestApis.devicePolicy().getProfileOwner(sUser)).isNotNull();
+ assertThat(TestApis.devicePolicy().getProfileOwner(sUser)).isNotNull();
}
}
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/ProfileOwnerTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/ProfileOwnerTest.java
index 650d83a..3d8548b 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/ProfileOwnerTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/devicepolicy/ProfileOwnerTest.java
@@ -42,19 +42,16 @@
private static final ComponentName DPC_COMPONENT_NAME =
new ComponentName(DEVICE_ADMIN_TESTAPP_PACKAGE_NAME,
EventLibDeviceAdminReceiver.class.getName());
-
- private static final TestApis sTestApis = new TestApis();
- private static final UserReference sUser = sTestApis.users().instrumented();
+ private static final UserReference sUser = TestApis.users().instrumented();
private static UserReference sProfile;
-
private static TestApp sTestApp;
private static ProfileOwner sProfileOwner;
@BeforeClass
public static void setupClass() {
- sProfile = sTestApis.users().createUser()
+ sProfile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
sTestApp = new TestAppProvider().query()
@@ -63,7 +60,7 @@
sTestApp.install(sProfile);
- sProfileOwner = sTestApis.devicePolicy().setProfileOwner(sProfile, DPC_COMPONENT_NAME);
+ sProfileOwner = TestApis.devicePolicy().setProfileOwner(sProfile, DPC_COMPONENT_NAME);
}
@AfterClass
@@ -90,9 +87,9 @@
public void remove_removesProfileOwner() {
sProfileOwner.remove();
try {
- assertThat(sTestApis.devicePolicy().getProfileOwner(sProfile)).isNull();
+ assertThat(TestApis.devicePolicy().getProfileOwner(sProfile)).isNull();
} finally {
- sProfileOwner = sTestApis.devicePolicy().setProfileOwner(sProfile, DPC_COMPONENT_NAME);
+ sProfileOwner = TestApis.devicePolicy().setProfileOwner(sProfile, DPC_COMPONENT_NAME);
}
}
}
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackageReferenceTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackageReferenceTest.java
index bceea8f..334b7de 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackageReferenceTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackageReferenceTest.java
@@ -36,14 +36,12 @@
@RunWith(JUnit4.class)
public class PackageReferenceTest {
-
- private static final TestApis sTestApis = new TestApis();
- private static final UserReference sUser = sTestApis.users().instrumented();
+ private static final UserReference sUser = TestApis.users().instrumented();
private static final String NON_EXISTING_PACKAGE_NAME = "com.package.does.not.exist";
private static final String PACKAGE_NAME = NON_EXISTING_PACKAGE_NAME;
private static final String EXISTING_PACKAGE_NAME = "com.android.providers.telephony";
private final PackageReference mTestAppReference =
- sTestApis.packages().find(TEST_APP_PACKAGE_NAME);
+ TestApis.packages().find(TEST_APP_PACKAGE_NAME);
// Controlled by AndroidTest.xml
private static final String TEST_APP_PACKAGE_NAME =
@@ -51,11 +49,11 @@
private static final File TEST_APP_APK_FILE =
new File("/data/local/tmp/NeneTestApp1.apk");
private static final Context sContext =
- sTestApis.context().instrumentedContext();
- private static final UserReference sOtherUser = sTestApis.users().createUser().createAndStart();
+ TestApis.context().instrumentedContext();
+ private static final UserReference sOtherUser = TestApis.users().createUser().createAndStart();
private static final PackageReference sInstrumentedPackage =
- sTestApis.packages().find(sContext.getPackageName());
+ TestApis.packages().find(sContext.getPackageName());
// Relies on this being declared by AndroidManifest.xml
// TODO(scottjonathan): Replace with TestApp
@@ -75,17 +73,17 @@
@Test
public void packageName_returnsPackageName() {
- sTestApis.packages().find(PACKAGE_NAME).packageName().equals(PACKAGE_NAME);
+ TestApis.packages().find(PACKAGE_NAME).packageName().equals(PACKAGE_NAME);
}
@Test
public void resolve_nonExistingPackage_returnsNull() {
- assertThat(sTestApis.packages().find(NON_EXISTING_PACKAGE_NAME).resolve()).isNull();
+ assertThat(TestApis.packages().find(NON_EXISTING_PACKAGE_NAME).resolve()).isNull();
}
@Test
public void resolve_existingPackage_returnsPackage() {
- assertThat(sTestApis.packages().find(EXISTING_PACKAGE_NAME).resolve()).isNotNull();
+ assertThat(TestApis.packages().find(EXISTING_PACKAGE_NAME).resolve()).isNotNull();
}
@Test
@@ -101,9 +99,9 @@
@Test
public void uninstallForAllUsers_isUninstalledForAllUsers() {
- PackageReference pkg = sTestApis.packages().install(sUser, TEST_APP_APK_FILE);
+ PackageReference pkg = TestApis.packages().install(sUser, TEST_APP_APK_FILE);
try {
- sTestApis.packages().install(sOtherUser, TEST_APP_APK_FILE);
+ TestApis.packages().install(sOtherUser, TEST_APP_APK_FILE);
mTestAppReference.uninstallFromAllUsers();
@@ -120,9 +118,9 @@
@Test
public void uninstall_packageIsInstalledForDifferentUser_isUninstalledForUser() {
- PackageReference pkg = sTestApis.packages().install(sUser, TEST_APP_APK_FILE);
+ PackageReference pkg = TestApis.packages().install(sUser, TEST_APP_APK_FILE);
try {
- sTestApis.packages().install(sOtherUser, TEST_APP_APK_FILE);
+ TestApis.packages().install(sOtherUser, TEST_APP_APK_FILE);
mTestAppReference.uninstall(sUser);
@@ -135,7 +133,7 @@
@Test
public void uninstall_packageIsUninstalled() {
- sTestApis.packages().install(sUser, TEST_APP_APK_FILE);
+ TestApis.packages().install(sUser, TEST_APP_APK_FILE);
mTestAppReference.uninstall(sUser);
@@ -149,7 +147,7 @@
@Test
public void uninstall_packageNotInstalledForUser_doesNotThrowException() {
- sTestApis.packages().install(sUser, TEST_APP_APK_FILE);
+ TestApis.packages().install(sUser, TEST_APP_APK_FILE);
try {
mTestAppReference.uninstall(sOtherUser);
@@ -160,7 +158,7 @@
@Test
public void uninstall_packageDoesNotExist_doesNotThrowException() {
- PackageReference packageReference = sTestApis.packages().find(NON_EXISTING_PACKAGE_NAME);
+ PackageReference packageReference = TestApis.packages().find(NON_EXISTING_PACKAGE_NAME);
packageReference.uninstall(sUser);
}
@@ -168,14 +166,14 @@
@Test
public void grantPermission_installPermission_throwsException() {
assertThrows(NeneException.class, () ->
- sTestApis.packages().find(sContext.getPackageName()).grantPermission(sUser,
+ TestApis.packages().find(sContext.getPackageName()).grantPermission(sUser,
INSTALL_PERMISSION));
}
@Test
public void grantPermission_nonDeclaredPermission_throwsException() {
assertThrows(NeneException.class, () ->
- sTestApis.packages().find(sContext.getPackageName()).grantPermission(sUser,
+ TestApis.packages().find(sContext.getPackageName()).grantPermission(sUser,
UNDECLARED_RUNTIME_PERMISSION));
}
@@ -195,7 +193,7 @@
@Test
public void grantPermission_permissionIsUserSpecific_permissionIsGrantedOnlyForThatUser() {
// Permissions are auto-granted on the current user so we need to test against new users
- try (UserReference newUser = sTestApis.users().createUser().create()) {
+ try (UserReference newUser = TestApis.users().createUser().create()) {
sInstrumentedPackage.install(sOtherUser);
sInstrumentedPackage.install(newUser);
@@ -214,14 +212,14 @@
@Test
public void grantPermission_packageDoesNotExist_throwsException() {
assertThrows(NeneException.class, () ->
- sTestApis.packages().find(NON_EXISTING_PACKAGE_NAME).grantPermission(sUser,
+ TestApis.packages().find(NON_EXISTING_PACKAGE_NAME).grantPermission(sUser,
DECLARED_RUNTIME_PERMISSION));
}
@Test
public void grantPermission_permissionDoesNotExist_throwsException() {
assertThrows(NeneException.class, () ->
- sTestApis.packages().find(sContext.getPackageName()).grantPermission(sUser,
+ TestApis.packages().find(sContext.getPackageName()).grantPermission(sUser,
NON_EXISTING_PERMISSION));
}
@@ -237,14 +235,14 @@
@Test
@Ignore("Cannot be tested because all runtime permissions are granted by default")
public void denyPermission_ownPackage_permissionIsNotGranted_doesNotThrowException() {
- PackageReference packageReference = sTestApis.packages().find(sContext.getPackageName());
+ PackageReference packageReference = TestApis.packages().find(sContext.getPackageName());
packageReference.denyPermission(sUser, USER_SPECIFIC_PERMISSION);
}
@Test
public void denyPermission_ownPackage_permissionIsGranted_throwsException() {
- PackageReference packageReference = sTestApis.packages().find(sContext.getPackageName());
+ PackageReference packageReference = TestApis.packages().find(sContext.getPackageName());
packageReference.grantPermission(sUser, USER_SPECIFIC_PERMISSION);
assertThrows(NeneException.class, () ->
@@ -269,14 +267,14 @@
@Test
public void denyPermission_packageDoesNotExist_throwsException() {
assertThrows(NeneException.class, () ->
- sTestApis.packages().find(NON_EXISTING_PACKAGE_NAME).denyPermission(sUser,
+ TestApis.packages().find(NON_EXISTING_PACKAGE_NAME).denyPermission(sUser,
DECLARED_RUNTIME_PERMISSION));
}
@Test
public void denyPermission_permissionDoesNotExist_throwsException() {
assertThrows(NeneException.class, () ->
- sTestApis.packages().find(sContext.getPackageName()).denyPermission(sUser,
+ TestApis.packages().find(sContext.getPackageName()).denyPermission(sUser,
NON_EXISTING_PERMISSION));
}
@@ -303,7 +301,7 @@
@Test
public void denyPermission_nonDeclaredPermission_throwsException() {
assertThrows(NeneException.class, () ->
- sTestApis.packages().find(sContext.getPackageName()).denyPermission(sUser,
+ TestApis.packages().find(sContext.getPackageName()).denyPermission(sUser,
UNDECLARED_RUNTIME_PERMISSION));
}
@@ -324,7 +322,7 @@
@Test
public void denyPermission_permissionIsUserSpecific_permissionIsDeniedOnlyForThatUser() {
// Permissions are auto-granted on the current user so we need to test against new users
- try (UserReference newUser = sTestApis.users().createUser().create()) {
+ try (UserReference newUser = TestApis.users().createUser().create()) {
sInstrumentedPackage.install(sOtherUser);
sInstrumentedPackage.install(newUser);
sInstrumentedPackage.grantPermission(sOtherUser, USER_SPECIFIC_PERMISSION);
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackageTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackageTest.java
index 4794762..7b6eb2d 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackageTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackageTest.java
@@ -41,14 +41,13 @@
private static final String ACCESS_NETWORK_STATE_PERMISSION =
"android.permission.ACCESS_NETWORK_STATE";
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
- private static final UserReference sUser = sTestApis.users().instrumented();
+ private static final Context sContext = TestApis.context().instrumentedContext();
+ private static final UserReference sUser = TestApis.users().instrumented();
@Test
public void installedOnUsers_includesUserWithPackageInstalled() {
- sTestApis.packages().install(sUser, TEST_APP_APK_FILE);
- PackageReference packageReference = sTestApis.packages().find(TEST_APP_PACKAGE_NAME);
+ TestApis.packages().install(sUser, TEST_APP_APK_FILE);
+ PackageReference packageReference = TestApis.packages().find(TEST_APP_PACKAGE_NAME);
try {
assertThat(packageReference.resolve().installedOnUsers()).contains(sUser);
@@ -59,9 +58,9 @@
@Test
public void installedOnUsers_doesNotIncludeUserWithoutPackageInstalled() {
- UserReference user = sTestApis.users().createUser().create();
- sTestApis.packages().install(sUser, TEST_APP_APK_FILE);
- PackageReference packageReference = sTestApis.packages().find(TEST_APP_PACKAGE_NAME);
+ UserReference user = TestApis.users().createUser().create();
+ TestApis.packages().install(sUser, TEST_APP_APK_FILE);
+ PackageReference packageReference = TestApis.packages().find(TEST_APP_PACKAGE_NAME);
try {
assertThat(packageReference.resolve().installedOnUsers()).doesNotContain(user);
@@ -75,7 +74,7 @@
public void grantedPermission_includesKnownInstallPermission() {
// TODO(scottjonathan): This relies on the fact that the instrumented app declares
// ACCESS_NETWORK_STATE - this should be replaced with TestApp with a useful query
- PackageReference packageReference = sTestApis.packages().find(sContext.getPackageName());
+ PackageReference packageReference = TestApis.packages().find(sContext.getPackageName());
assertThat(packageReference.resolve().grantedPermissions(sUser))
.contains(ACCESS_NETWORK_STATE_PERMISSION);
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackagesTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackagesTest.java
index c02f84a..c75bbd1 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackagesTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/packages/PackagesTest.java
@@ -51,15 +51,14 @@
new File("/data/local/tmp/ThisApkDoesNotExist.apk");
private static final byte[] TEST_APP_BYTES = loadBytes(TEST_APP_APK_FILE);
- private final TestApis mTestApis = new TestApis();
- private final UserReference mUser = mTestApis.users().instrumented();
+ private final UserReference mUser = TestApis.users().instrumented();
private final PackageReference mExistingPackage =
- mTestApis.packages().find("com.android.providers.telephony");
+ TestApis.packages().find("com.android.providers.telephony");
private final PackageReference mTestAppReference =
- mTestApis.packages().find(TEST_APP_PACKAGE_NAME);
+ TestApis.packages().find(TEST_APP_PACKAGE_NAME);
private final PackageReference mDifferentTestAppReference =
- mTestApis.packages().find(NON_EXISTING_PACKAGE);
- private final UserReference mNonExistingUser = mTestApis.users().find(99999);
+ TestApis.packages().find(NON_EXISTING_PACKAGE);
+ private final UserReference mNonExistingUser = TestApis.users().find(99999);
private final File mApkFile = new File("");
private static byte[] loadBytes(File file) {
@@ -71,52 +70,47 @@
}
@Test
- public void construct_nullTestApis_throwsException() {
- assertThrows(NullPointerException.class, () -> new Packages(/* testApis= */ null));
- }
-
- @Test
public void construct_constructs() {
- new Packages(mTestApis); // Doesn't throw any exceptions
+ new Packages(); // Doesn't throw any exceptions
}
@Test
public void features_noUserSpecified_containsKnownFeature() {
- assertThat(mTestApis.packages().features()).contains(INPUT_METHODS_FEATURE);
+ assertThat(TestApis.packages().features()).contains(INPUT_METHODS_FEATURE);
}
@Test
public void all_containsKnownPackage() {
- assertThat(mTestApis.packages().all()).contains(mExistingPackage);
+ assertThat(TestApis.packages().all()).contains(mExistingPackage);
}
@Test
public void find_nullPackageName_throwsException() {
- assertThrows(NullPointerException.class, () -> mTestApis.packages().find(null));
+ assertThrows(NullPointerException.class, () -> TestApis.packages().find(null));
}
@Test
public void find_existingPackage_returnsPackageReference() {
- assertThat(mTestApis.packages().find(mExistingPackage.packageName())).isNotNull();
+ assertThat(TestApis.packages().find(mExistingPackage.packageName())).isNotNull();
}
@Test
public void find_nonExistingPackage_returnsPackageReference() {
- assertThat(mTestApis.packages().find(NON_EXISTING_PACKAGE)).isNotNull();
+ assertThat(TestApis.packages().find(NON_EXISTING_PACKAGE)).isNotNull();
}
@Test
public void installedForUser_nullUserReference_throwsException() {
assertThrows(NullPointerException.class,
- () -> mTestApis.packages().installedForUser(/* user= */ null));
+ () -> TestApis.packages().installedForUser(/* user= */ null));
}
@Test
public void installedForUser_containsPackageInstalledForUser() {
- PackageReference packageReference = mTestApis.packages().install(mUser, TEST_APP_APK_FILE);
+ PackageReference packageReference = TestApis.packages().install(mUser, TEST_APP_APK_FILE);
try {
- assertThat(mTestApis.packages().installedForUser(mUser)).contains(packageReference);
+ assertThat(TestApis.packages().installedForUser(mUser)).contains(packageReference);
} finally {
packageReference.uninstall(mUser);
}
@@ -124,10 +118,10 @@
@Test
public void installedForUser_doesNotContainPackageNotInstalledForUser() {
- PackageReference packageReference = mTestApis.packages().install(mUser, TEST_APP_APK_FILE);
+ PackageReference packageReference = TestApis.packages().install(mUser, TEST_APP_APK_FILE);
- try (UserReference otherUser = mTestApis.users().createUser().create()) {
- assertThat(mTestApis.packages().installedForUser(otherUser))
+ try (UserReference otherUser = TestApis.users().createUser().create()) {
+ assertThat(TestApis.packages().installedForUser(otherUser))
.doesNotContain(packageReference);
} finally {
packageReference.uninstall(mUser);
@@ -137,64 +131,64 @@
@Test
public void install_nonExistingPackage_throwsException() {
assertThrows(NeneException.class,
- () -> mTestApis.packages().install(mUser, NON_EXISTING_APK_FILE));
+ () -> TestApis.packages().install(mUser, NON_EXISTING_APK_FILE));
}
@Test
public void install_nullUser_throwsException() {
assertThrows(NullPointerException.class,
- () -> mTestApis.packages().install(/* user= */ null, mApkFile));
+ () -> TestApis.packages().install(/* user= */ null, mApkFile));
}
@Test
public void install_byteArray_nullUser_throwsException() {
assertThrows(NullPointerException.class,
- () -> mTestApis.packages().install(/* user= */ null, TEST_APP_BYTES));
+ () -> TestApis.packages().install(/* user= */ null, TEST_APP_BYTES));
}
@Test
public void install_nullApkFile_throwsException() {
assertThrows(NullPointerException.class,
- () -> mTestApis.packages().install(mUser, (File) /* apkFile= */ null));
+ () -> TestApis.packages().install(mUser, (File) /* apkFile= */ null));
}
@Test
public void install_nullByteArray_throwsException() {
assertThrows(NullPointerException.class,
- () -> mTestApis.packages().install(mUser, (byte[]) /* apkFile= */ null));
+ () -> TestApis.packages().install(mUser, (byte[]) /* apkFile= */ null));
}
@Test
public void install_instrumentedUser_isInstalled() {
PackageReference packageReference =
- mTestApis.packages().install(mTestApis.users().instrumented(), TEST_APP_APK_FILE);
+ TestApis.packages().install(TestApis.users().instrumented(), TEST_APP_APK_FILE);
try {
assertThat(packageReference.resolve().installedOnUsers())
- .contains(mTestApis.users().instrumented());
+ .contains(TestApis.users().instrumented());
} finally {
- packageReference.uninstall(mTestApis.users().instrumented());
+ packageReference.uninstall(TestApis.users().instrumented());
}
}
@Test
public void install_byteArray_instrumentedUser_isInstalled() {
PackageReference packageReference =
- mTestApis.packages().install(mTestApis.users().instrumented(), TEST_APP_BYTES);
+ TestApis.packages().install(TestApis.users().instrumented(), TEST_APP_BYTES);
try {
assertThat(packageReference.resolve().installedOnUsers())
- .contains(mTestApis.users().instrumented());
+ .contains(TestApis.users().instrumented());
} finally {
- packageReference.uninstall(mTestApis.users().instrumented());
+ packageReference.uninstall(TestApis.users().instrumented());
}
}
@Test
public void install_differentUser_isInstalled() {
- UserReference user = mTestApis.users().createUser().createAndStart();
+ UserReference user = TestApis.users().createUser().createAndStart();
PackageReference packageReference =
- mTestApis.packages().install(user, TEST_APP_APK_FILE);
+ TestApis.packages().install(user, TEST_APP_APK_FILE);
try {
assertThat(packageReference.resolve().installedOnUsers()).contains(user);
@@ -205,8 +199,8 @@
@Test
public void install_byteArray_differentUser_isInstalled() {
- UserReference user = mTestApis.users().createUser().createAndStart();
- PackageReference packageReference = mTestApis.packages().install(user, TEST_APP_BYTES);
+ UserReference user = TestApis.users().createUser().createAndStart();
+ PackageReference packageReference = TestApis.packages().install(user, TEST_APP_BYTES);
try {
assertThat(packageReference.resolve().installedOnUsers()).contains(user);
@@ -217,18 +211,18 @@
@Test
public void install_userNotStarted_throwsException() {
- try (UserReference user = mTestApis.users().createUser().create().stop()) {
- assertThrows(NeneException.class, () -> mTestApis.packages().install(user,
+ try (UserReference user = TestApis.users().createUser().create().stop()) {
+ assertThrows(NeneException.class, () -> TestApis.packages().install(user,
TEST_APP_APK_FILE));
}
}
@Test
public void install_byteArray_userNotStarted_throwsException() {
- UserReference user = mTestApis.users().createUser().create().stop();
+ UserReference user = TestApis.users().createUser().create().stop();
try {
- assertThrows(NeneException.class, () -> mTestApis.packages().install(user,
+ assertThrows(NeneException.class, () -> TestApis.packages().install(user,
TEST_APP_BYTES));
} finally {
user.remove();
@@ -237,22 +231,22 @@
@Test
public void install_userDoesNotExist_throwsException() {
- assertThrows(NeneException.class, () -> mTestApis.packages().install(mNonExistingUser,
+ assertThrows(NeneException.class, () -> TestApis.packages().install(mNonExistingUser,
TEST_APP_APK_FILE));
}
@Test
public void install_byteArray_userDoesNotExist_throwsException() {
- assertThrows(NeneException.class, () -> mTestApis.packages().install(mNonExistingUser,
+ assertThrows(NeneException.class, () -> TestApis.packages().install(mNonExistingUser,
TEST_APP_BYTES));
}
@Test
public void install_alreadyInstalledForUser_installs() {
- PackageReference packageReference = mTestApis.packages().install(mUser, TEST_APP_APK_FILE);
+ PackageReference packageReference = TestApis.packages().install(mUser, TEST_APP_APK_FILE);
try {
- packageReference = mTestApis.packages().install(mUser, TEST_APP_APK_FILE);
+ packageReference = TestApis.packages().install(mUser, TEST_APP_APK_FILE);
assertThat(packageReference.resolve().installedOnUsers()).contains(mUser);
} finally {
packageReference.uninstall(mUser);
@@ -261,10 +255,10 @@
@Test
public void install_byteArray_alreadyInstalledForUser_installs() {
- PackageReference packageReference = mTestApis.packages().install(mUser, TEST_APP_BYTES);
+ PackageReference packageReference = TestApis.packages().install(mUser, TEST_APP_BYTES);
try {
- packageReference = mTestApis.packages().install(mUser, TEST_APP_BYTES);
+ packageReference = TestApis.packages().install(mUser, TEST_APP_BYTES);
assertThat(packageReference.resolve().installedOnUsers()).contains(mUser);
} finally {
packageReference.uninstall(mUser);
@@ -275,11 +269,11 @@
public void install_alreadyInstalledOnOtherUser_installs() {
PackageReference packageReference = null;
- try (UserReference otherUser = mTestApis.users().createUser().createAndStart()) {
- mTestApis.packages().install(otherUser, TEST_APP_APK_FILE);
+ try (UserReference otherUser = TestApis.users().createUser().createAndStart()) {
+ TestApis.packages().install(otherUser, TEST_APP_APK_FILE);
packageReference =
- mTestApis.packages().install(mUser, TEST_APP_APK_FILE);
+ TestApis.packages().install(mUser, TEST_APP_APK_FILE);
assertThat(packageReference.resolve().installedOnUsers()).contains(mUser);
} finally {
@@ -293,10 +287,10 @@
public void install_byteArray_alreadyInstalledOnOtherUser_installs() {
PackageReference packageReference = null;
- try (UserReference otherUser = mTestApis.users().createUser().createAndStart()) {
- mTestApis.packages().install(otherUser, TEST_APP_BYTES);
+ try (UserReference otherUser = TestApis.users().createUser().createAndStart()) {
+ TestApis.packages().install(otherUser, TEST_APP_BYTES);
- packageReference = mTestApis.packages().install(mUser, TEST_APP_BYTES);
+ packageReference = TestApis.packages().install(mUser, TEST_APP_BYTES);
assertThat(packageReference.resolve().installedOnUsers()).contains(mUser);
} finally {
@@ -311,8 +305,8 @@
assumeTrue("keepUninstalledPackages is only supported on S+",
Versions.meetsMinimumSdkVersionRequirement(Build.VERSION_CODES.S));
- mTestApis.packages().install(mUser, TEST_APP_APK_FILE);
- mTestApis.packages().keepUninstalledPackages()
+ TestApis.packages().install(mUser, TEST_APP_APK_FILE);
+ TestApis.packages().keepUninstalledPackages()
.add(mTestAppReference)
.commit();
@@ -321,7 +315,7 @@
assertThat(mTestAppReference.resolve()).isNotNull();
} finally {
- mTestApis.packages().keepUninstalledPackages().clear();
+ TestApis.packages().keepUninstalledPackages().clear();
}
}
@@ -331,11 +325,11 @@
assumeTrue("keepUninstalledPackages is only supported on S+",
Versions.meetsMinimumSdkVersionRequirement(Build.VERSION_CODES.S));
- mTestApis.packages().install(mUser, TEST_APP_APK_FILE);
- mTestApis.packages().keepUninstalledPackages()
+ TestApis.packages().install(mUser, TEST_APP_APK_FILE);
+ TestApis.packages().keepUninstalledPackages()
.add(mTestAppReference)
.commit();
- mTestApis.packages().keepUninstalledPackages()
+ TestApis.packages().keepUninstalledPackages()
.add(mDifferentTestAppReference)
.commit();
@@ -344,7 +338,7 @@
assertThat(mTestAppReference.resolve()).isNull();
} finally {
- mTestApis.packages().keepUninstalledPackages().clear();
+ TestApis.packages().keepUninstalledPackages().clear();
}
}
@@ -354,19 +348,19 @@
assumeTrue("keepUninstalledPackages is only supported on S+",
Versions.meetsMinimumSdkVersionRequirement(Build.VERSION_CODES.S));
- mTestApis.packages().install(mUser, TEST_APP_APK_FILE);
+ TestApis.packages().install(mUser, TEST_APP_APK_FILE);
- mTestApis.packages().keepUninstalledPackages()
+ TestApis.packages().keepUninstalledPackages()
.add(mTestAppReference)
.commit();
- mTestApis.packages().keepUninstalledPackages().clear();
+ TestApis.packages().keepUninstalledPackages().clear();
try {
mTestAppReference.uninstall(mUser);
assertThat(mTestAppReference.resolve()).isNull();
} finally {
- mTestApis.packages().keepUninstalledPackages().clear();
+ TestApis.packages().keepUninstalledPackages().clear();
}
}
@@ -376,15 +370,15 @@
assumeTrue("keepUninstalledPackages is only supported on S+",
Versions.meetsMinimumSdkVersionRequirement(Build.VERSION_CODES.S));
- mTestApis.packages().install(mUser, TEST_APP_APK_FILE);
- mTestApis.packages().keepUninstalledPackages().add(mTestAppReference).commit();
+ TestApis.packages().install(mUser, TEST_APP_APK_FILE);
+ TestApis.packages().keepUninstalledPackages().add(mTestAppReference).commit();
mTestAppReference.uninstall(mUser);
- mTestApis.packages().keepUninstalledPackages().add(mDifferentTestAppReference).commit();
+ TestApis.packages().keepUninstalledPackages().add(mDifferentTestAppReference).commit();
try {
assertThat(mTestAppReference.resolve()).isNull();
} finally {
- mTestApis.packages().keepUninstalledPackages().clear();
+ TestApis.packages().keepUninstalledPackages().clear();
}
}
}
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/permissions/PermissionsTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/permissions/PermissionsTest.java
index 4dff77e..5548531 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/permissions/PermissionsTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/permissions/PermissionsTest.java
@@ -44,8 +44,7 @@
"android.permission.INTERACT_ACROSS_PROFILES";
private static final String DIFFERENT_PERMISSION_HELD_BY_SHELL =
"android.permission.INTERACT_ACROSS_USERS_FULL";
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String NON_EXISTING_PERMISSION = "permissionWhichDoesNotExist";
@@ -68,7 +67,7 @@
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q);
try (PermissionContext p =
- sTestApis.permissions().withPermission(PERMISSION_HELD_BY_SHELL)) {
+ TestApis.permissions().withPermission(PERMISSION_HELD_BY_SHELL)) {
assertThat(sContext.checkSelfPermission(PERMISSION_HELD_BY_SHELL))
.isEqualTo(PERMISSION_GRANTED);
}
@@ -80,7 +79,7 @@
Build.VERSION.SDK_INT < Build.VERSION_CODES.Q);
assertThrows(NeneException.class,
- () -> sTestApis.permissions().withoutPermission(
+ () -> TestApis.permissions().withoutPermission(
DECLARED_PERMISSION_NOT_HELD_BY_SHELL_PRE_S));
}
@@ -89,8 +88,8 @@
assumeTrue("assume shell identity is only available on Q+",
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q);
- try (PermissionContext p = sTestApis.permissions().withPermission(PERMISSION_HELD_BY_SHELL);
- PermissionContext p2 = sTestApis.permissions().withoutPermission(
+ try (PermissionContext p = TestApis.permissions().withPermission(PERMISSION_HELD_BY_SHELL);
+ PermissionContext p2 = TestApis.permissions().withoutPermission(
PERMISSION_HELD_BY_SHELL)) {
assertThat(sContext.checkSelfPermission(PERMISSION_HELD_BY_SHELL))
@@ -104,9 +103,9 @@
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q);
try (PermissionContext p =
- sTestApis.permissions().withPermission(PERMISSION_HELD_BY_SHELL)) {
+ TestApis.permissions().withPermission(PERMISSION_HELD_BY_SHELL)) {
try (PermissionContext p2 =
- sTestApis.permissions().withoutPermission(PERMISSION_HELD_BY_SHELL)) {
+ TestApis.permissions().withoutPermission(PERMISSION_HELD_BY_SHELL)) {
// Intentionally empty as we're testing that autoclosing restores the permission
}
@@ -121,7 +120,7 @@
Build.VERSION.SDK_INT < Build.VERSION_CODES.Q);
assertThrows(NeneException.class,
- () -> sTestApis.permissions().withoutPermission(INSTALL_PERMISSION));
+ () -> TestApis.permissions().withoutPermission(INSTALL_PERMISSION));
}
@Test
@@ -132,7 +131,7 @@
Versions.meetsMinimumSdkVersionRequirement(Build.VERSION_CODES.S));
try (PermissionContext p =
- sTestApis.permissions().withoutPermission(
+ TestApis.permissions().withoutPermission(
DECLARED_PERMISSION_NOT_HELD_BY_SHELL_PRE_S)) {
assertThat(
sContext.checkSelfPermission(DECLARED_PERMISSION_NOT_HELD_BY_SHELL_PRE_S))
@@ -146,14 +145,14 @@
Build.VERSION.SDK_INT < Build.VERSION_CODES.Q);
assertThrows(NeneException.class,
- () -> sTestApis.permissions().withoutPermission(
+ () -> TestApis.permissions().withoutPermission(
DECLARED_PERMISSION_NOT_HELD_BY_SHELL_PRE_S));
}
@Test
public void withPermission_permissionIsAlreadyGrantedInInstrumentedApp_permissionIsGranted() {
try (PermissionContext p =
- sTestApis.permissions().withPermission(
+ TestApis.permissions().withPermission(
DECLARED_PERMISSION_NOT_HELD_BY_SHELL_PRE_S)) {
assertThat(
sContext.checkSelfPermission(DECLARED_PERMISSION_NOT_HELD_BY_SHELL_PRE_S))
@@ -164,20 +163,20 @@
@Test
public void withPermission_nonExistingPermission_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.permissions().withPermission(NON_EXISTING_PERMISSION));
+ () -> TestApis.permissions().withPermission(NON_EXISTING_PERMISSION));
}
@Test
public void withoutPermission_nonExistingPermission_doesNotThrowException() {
try (PermissionContext p =
- sTestApis.permissions().withoutPermission(NON_EXISTING_PERMISSION)) {
+ TestApis.permissions().withoutPermission(NON_EXISTING_PERMISSION)) {
// Intentionally empty
}
}
@Test
public void withPermissionAndWithoutPermission_bothApplied() {
- try (PermissionContext p = sTestApis.permissions().withPermission(PERMISSION_HELD_BY_SHELL)
+ try (PermissionContext p = TestApis.permissions().withPermission(PERMISSION_HELD_BY_SHELL)
.withoutPermission(DIFFERENT_PERMISSION_HELD_BY_SHELL)) {
assertThat(sContext.checkSelfPermission(PERMISSION_HELD_BY_SHELL))
@@ -189,7 +188,7 @@
@Test
public void withoutPermissionAndWithPermission_bothApplied() {
- try (PermissionContext p = sTestApis.permissions()
+ try (PermissionContext p = TestApis.permissions()
.withoutPermission(DIFFERENT_PERMISSION_HELD_BY_SHELL)
.withPermission(PERMISSION_HELD_BY_SHELL)) {
@@ -202,14 +201,14 @@
@Test
public void withPermissionAndWithoutPermission_contradictoryPermissions_throwsException() {
- assertThrows(NeneException.class, () -> sTestApis.permissions()
+ assertThrows(NeneException.class, () -> TestApis.permissions()
.withPermission(PERMISSION_HELD_BY_SHELL)
.withoutPermission(PERMISSION_HELD_BY_SHELL));
}
@Test
public void withoutPermissionAndWithPermission_contradictoryPermissions_throwsException() {
- assertThrows(NeneException.class, () -> sTestApis.permissions()
+ assertThrows(NeneException.class, () -> TestApis.permissions()
.withoutPermission(PERMISSION_HELD_BY_SHELL)
.withPermission(PERMISSION_HELD_BY_SHELL));
}
@@ -223,7 +222,7 @@
try {
PermissionContext p =
- sTestApis.permissions()
+ TestApis.permissions()
.withoutPermission(PERMISSION_HELD_BY_SHELL);
p.close();
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/settings/GlobalSettingsTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/settings/GlobalSettingsTest.java
index 98a8fc5..e1a2787 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/settings/GlobalSettingsTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/settings/GlobalSettingsTest.java
@@ -48,8 +48,7 @@
@Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String KEY = "key";
private static final String INVALID_KEY = "noKey";
private static final int INT_VALUE = 123;
@@ -57,12 +56,12 @@
@After
public void resetGlobalSettings() {
- sTestApis.settings().global().reset();
+ TestApis.settings().global().reset();
}
@Test
public void putInt_putsIntIntoGlobalSettingsOnInstrumentedUser() throws Exception {
- sTestApis.settings().global().putInt(KEY, INT_VALUE);
+ TestApis.settings().global().putInt(KEY, INT_VALUE);
assertThat(android.provider.Settings.Global.getInt(sContext.getContentResolver(), KEY))
.isEqualTo(INT_VALUE);
@@ -71,7 +70,7 @@
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void putIntWithContentResolver_putsIntIntoGlobalSettings() throws Exception {
- sTestApis.settings().global().putInt(sContext.getContentResolver(), KEY, INT_VALUE);
+ TestApis.settings().global().putInt(sContext.getContentResolver(), KEY, INT_VALUE);
assertThat(android.provider.Settings.Global.getInt(sContext.getContentResolver(), KEY))
.isEqualTo(INT_VALUE);
@@ -81,13 +80,13 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void putIntWithContentResolver_preS_throwsException() throws Exception {
assertThrows(UnsupportedOperationException.class, () ->
- sTestApis.settings().global().putInt(
+ TestApis.settings().global().putInt(
sContext.getContentResolver(), KEY, INT_VALUE));
}
@Test
public void putIntWithUser_instrumentedUser_putsIntIntoGlobalSettings() throws Exception {
- sTestApis.settings().global().putInt(sTestApis.users().instrumented(), KEY, INT_VALUE);
+ TestApis.settings().global().putInt(TestApis.users().instrumented(), KEY, INT_VALUE);
assertThat(android.provider.Settings.Global.getInt(sContext.getContentResolver(), KEY))
.isEqualTo(INT_VALUE);
@@ -97,12 +96,12 @@
@EnsureHasSecondaryUser
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void putIntWithUser_differentUser_putsIntIntoGlobalSettings() throws Exception {
- sTestApis.settings().global().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
+ TestApis.settings().global().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
try (PermissionContext p =
- sTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
assertThat(android.provider.Settings.Global.getInt(
- sTestApis.context().androidContextAsUser(sDeviceState.secondaryUser())
+ TestApis.context().androidContextAsUser(sDeviceState.secondaryUser())
.getContentResolver(), KEY)).isEqualTo(INT_VALUE);
}
}
@@ -112,36 +111,36 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void putIntWithUser_differentUser_preS_throwsException() throws Exception {
assertThrows(UnsupportedOperationException.class, () ->
- sTestApis.settings().global().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE));
+ TestApis.settings().global().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE));
}
@Test
public void getInt_getsIntFromGlobalSettingsOnInstrumentedUser() {
- sTestApis.settings().global().putInt(KEY, INT_VALUE);
+ TestApis.settings().global().putInt(KEY, INT_VALUE);
- assertThat(sTestApis.settings().global().getInt(KEY)).isEqualTo(INT_VALUE);
+ assertThat(TestApis.settings().global().getInt(KEY)).isEqualTo(INT_VALUE);
}
@Test
public void getInt_invalidKey_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.settings().global().getInt(INVALID_KEY));
+ () -> TestApis.settings().global().getInt(INVALID_KEY));
}
@Test
public void getInt_invalidKey_withDefault_returnsDefault() {
- assertThat(sTestApis.settings().global().getInt(INVALID_KEY, INT_VALUE)).isEqualTo(
+ assertThat(TestApis.settings().global().getInt(INVALID_KEY, INT_VALUE)).isEqualTo(
INT_VALUE);
}
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void getIntWithContentResolver_getsIntFromGlobalSettings() {
- sTestApis.settings().global().putInt(
- sTestApis.context().instrumentedContext().getContentResolver(), KEY, INT_VALUE);
+ TestApis.settings().global().putInt(
+ TestApis.context().instrumentedContext().getContentResolver(), KEY, INT_VALUE);
- assertThat(sTestApis.settings().global().getInt(
- sTestApis.context().instrumentedContext().getContentResolver(), KEY))
+ assertThat(TestApis.settings().global().getInt(
+ TestApis.context().instrumentedContext().getContentResolver(), KEY))
.isEqualTo(INT_VALUE);
}
@@ -149,47 +148,47 @@
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void getIntWithContentResolver_invalidKey_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.settings().global().getInt(
- sTestApis.context().instrumentedContext().getContentResolver(),
+ () -> TestApis.settings().global().getInt(
+ TestApis.context().instrumentedContext().getContentResolver(),
INVALID_KEY));
}
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void getIntWithContentResolver_invalidKey_withDefault_returnsDefault() {
- assertThat(sTestApis.settings().global().getInt(
- sTestApis.context().instrumentedContext().getContentResolver(),
+ assertThat(TestApis.settings().global().getInt(
+ TestApis.context().instrumentedContext().getContentResolver(),
INVALID_KEY, INT_VALUE)).isEqualTo(INT_VALUE);
}
@Test
public void getIntWithUser_instrumentedUser_getsIntFromGlobalSettings() {
- sTestApis.settings().global().putInt(KEY, INT_VALUE);
+ TestApis.settings().global().putInt(KEY, INT_VALUE);
- assertThat(sTestApis.settings().global().getInt(sTestApis.users().instrumented(), KEY))
+ assertThat(TestApis.settings().global().getInt(TestApis.users().instrumented(), KEY))
.isEqualTo(INT_VALUE);
}
@Test
public void getIntWithUser_invalidKey_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.settings().global().getInt(
- sTestApis.users().instrumented(), INVALID_KEY));
+ () -> TestApis.settings().global().getInt(
+ TestApis.users().instrumented(), INVALID_KEY));
}
@Test
public void getIntWithUser_invalidKey_withDefault_returnsDefault() {
- assertThat(sTestApis.settings().global().getInt(
- sTestApis.users().instrumented(), INVALID_KEY, INT_VALUE)).isEqualTo(INT_VALUE);
+ assertThat(TestApis.settings().global().getInt(
+ TestApis.users().instrumented(), INVALID_KEY, INT_VALUE)).isEqualTo(INT_VALUE);
}
@Test
@EnsureHasSecondaryUser
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void getIntWithUser_differentUser_getsIntFromGlobalSettings() {
- sTestApis.settings().global().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
+ TestApis.settings().global().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
- assertThat(sTestApis.settings().global().getInt(
+ assertThat(TestApis.settings().global().getInt(
sDeviceState.secondaryUser(), KEY)).isEqualTo(INT_VALUE);
}
@@ -198,14 +197,14 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void getIntWithUser_differentUser_preS_throwsException() {
assertThrows(UnsupportedOperationException.class, () -> {
- sTestApis.settings().global().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
+ TestApis.settings().global().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
});
}
@Test
public void putString_putsStringIntoGlobalSettingsOnInstrumentedUser() throws Exception {
- sTestApis.settings().global().putString(KEY, STRING_VALUE);
+ TestApis.settings().global().putString(KEY, STRING_VALUE);
assertThat(android.provider.Settings.Global.getString(sContext.getContentResolver(), KEY))
.isEqualTo(STRING_VALUE);
@@ -214,7 +213,7 @@
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void putStringWithContentResolver_putsStringIntoGlobalSettings() throws Exception {
- sTestApis.settings().global().putString(sContext.getContentResolver(), KEY, STRING_VALUE);
+ TestApis.settings().global().putString(sContext.getContentResolver(), KEY, STRING_VALUE);
assertThat(android.provider.Settings.Global.getString(sContext.getContentResolver(), KEY))
.isEqualTo(STRING_VALUE);
@@ -224,14 +223,14 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void putStringWithContentResolver_preS_throwsException() throws Exception {
assertThrows(UnsupportedOperationException.class, () ->
- sTestApis.settings().global().putString(
+ TestApis.settings().global().putString(
sContext.getContentResolver(), KEY, STRING_VALUE));
}
@Test
public void putStringWithUser_instrumentedUser_putsStringIntoGlobalSettings() throws Exception {
- sTestApis.settings().global().putString(
- sTestApis.users().instrumented(), KEY, STRING_VALUE);
+ TestApis.settings().global().putString(
+ TestApis.users().instrumented(), KEY, STRING_VALUE);
assertThat(android.provider.Settings.Global.getString(sContext.getContentResolver(), KEY))
.isEqualTo(STRING_VALUE);
@@ -241,12 +240,12 @@
@EnsureHasSecondaryUser
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void putStringWithUser_differentUser_putsStringIntoGlobalSettings() throws Exception {
- sTestApis.settings().global().putString(sDeviceState.secondaryUser(), KEY, STRING_VALUE);
+ TestApis.settings().global().putString(sDeviceState.secondaryUser(), KEY, STRING_VALUE);
try (PermissionContext p =
- sTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
assertThat(android.provider.Settings.Global.getString(
- sTestApis.context().androidContextAsUser(sDeviceState.secondaryUser())
+ TestApis.context().androidContextAsUser(sDeviceState.secondaryUser())
.getContentResolver(), KEY)).isEqualTo(STRING_VALUE);
}
}
@@ -256,33 +255,33 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void putStringWithUser_differentUser_preS_throwsException() throws Exception {
assertThrows(UnsupportedOperationException.class,
- () -> sTestApis.settings().global().putString(sDeviceState.secondaryUser(), KEY,
+ () -> TestApis.settings().global().putString(sDeviceState.secondaryUser(), KEY,
STRING_VALUE));
}
@Test
public void getString_getsStringFromGlobalSettingsOnInstrumentedUser() {
- sTestApis.settings().global().putString(KEY, STRING_VALUE);
+ TestApis.settings().global().putString(KEY, STRING_VALUE);
- assertThat(sTestApis.settings().global().getString(KEY)).isEqualTo(STRING_VALUE);
+ assertThat(TestApis.settings().global().getString(KEY)).isEqualTo(STRING_VALUE);
}
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void getIntWithContentResolver_getsStringFromGlobalSettings() {
- sTestApis.settings().global().putString(
- sTestApis.context().instrumentedContext().getContentResolver(), KEY, STRING_VALUE);
+ TestApis.settings().global().putString(
+ TestApis.context().instrumentedContext().getContentResolver(), KEY, STRING_VALUE);
- assertThat(sTestApis.settings().global().getString(
- sTestApis.context().instrumentedContext().getContentResolver(), KEY))
+ assertThat(TestApis.settings().global().getString(
+ TestApis.context().instrumentedContext().getContentResolver(), KEY))
.isEqualTo(STRING_VALUE);
}
@Test
public void getStringWithUser_instrumentedUser_getsStringFromGlobalSettings() {
- sTestApis.settings().global().putString(KEY, STRING_VALUE);
+ TestApis.settings().global().putString(KEY, STRING_VALUE);
- assertThat(sTestApis.settings().global().getString(sTestApis.users().instrumented(), KEY))
+ assertThat(TestApis.settings().global().getString(TestApis.users().instrumented(), KEY))
.isEqualTo(STRING_VALUE);
}
@@ -290,9 +289,9 @@
@EnsureHasSecondaryUser
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void getStringWithUser_differentUser_getsStringFromGlobalSettings() {
- sTestApis.settings().global().putString(sDeviceState.secondaryUser(), KEY, STRING_VALUE);
+ TestApis.settings().global().putString(sDeviceState.secondaryUser(), KEY, STRING_VALUE);
- assertThat(sTestApis.settings().global().getString(
+ assertThat(TestApis.settings().global().getString(
sDeviceState.secondaryUser(), KEY)).isEqualTo(STRING_VALUE);
}
@@ -301,37 +300,37 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void getStringWithUser_differentUser_preS_throwsException() {
assertThrows(UnsupportedOperationException.class, () -> {
- sTestApis.settings().global().putString(sDeviceState.secondaryUser(), KEY,
+ TestApis.settings().global().putString(sDeviceState.secondaryUser(), KEY,
STRING_VALUE);
});
}
@Test
public void reset_resetsGlobalSettings() {
- sTestApis.settings().global().putInt(KEY, INT_VALUE);
- sTestApis.settings().global().putString(KEY, STRING_VALUE);
+ TestApis.settings().global().putInt(KEY, INT_VALUE);
+ TestApis.settings().global().putString(KEY, STRING_VALUE);
- sTestApis.settings().global().reset();
+ TestApis.settings().global().reset();
- assertThrows(NeneException.class, () -> sTestApis.settings().global().getInt(KEY));
- assertThat(sTestApis.settings().global().getString(KEY)).isNotEqualTo(STRING_VALUE);
+ assertThrows(NeneException.class, () -> TestApis.settings().global().getInt(KEY));
+ assertThat(TestApis.settings().global().getString(KEY)).isNotEqualTo(STRING_VALUE);
}
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void resetWithContentResolver_resetsGlobalSettings() {
ContentResolver contentResolver =
- sTestApis.context().instrumentedContext().getContentResolver();
- sTestApis.settings().global().putInt(contentResolver, KEY, INT_VALUE);
- sTestApis.settings().global().putString(contentResolver, KEY, STRING_VALUE);
+ TestApis.context().instrumentedContext().getContentResolver();
+ TestApis.settings().global().putInt(contentResolver, KEY, INT_VALUE);
+ TestApis.settings().global().putString(contentResolver, KEY, STRING_VALUE);
- sTestApis.settings().global().reset(contentResolver);
+ TestApis.settings().global().reset(contentResolver);
assertThrows(NeneException.class,
- () -> sTestApis.settings().global().getInt(
+ () -> TestApis.settings().global().getInt(
contentResolver,
KEY));
- assertThat(sTestApis.settings().global().getString(contentResolver, KEY))
+ assertThat(TestApis.settings().global().getString(contentResolver, KEY))
.isNotEqualTo(STRING_VALUE);
}
@@ -339,24 +338,24 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void resetWithContentResolver_preS_throwsException() {
ContentResolver contentResolver =
- sTestApis.context().instrumentedContext().getContentResolver();
+ TestApis.context().instrumentedContext().getContentResolver();
assertThrows(UnsupportedOperationException.class,
- () -> sTestApis.settings().global().reset(contentResolver));
+ () -> TestApis.settings().global().reset(contentResolver));
}
@Test
public void resetWithUser_instrumentedUser_resetsGlobalSettings() {
- sTestApis.settings().global().putInt(sTestApis.users().instrumented(), KEY, INT_VALUE);
- sTestApis.settings().global().putString(sTestApis.users().instrumented(), KEY,
+ TestApis.settings().global().putInt(TestApis.users().instrumented(), KEY, INT_VALUE);
+ TestApis.settings().global().putString(TestApis.users().instrumented(), KEY,
STRING_VALUE);
- sTestApis.settings().global().reset(sTestApis.users().instrumented());
+ TestApis.settings().global().reset(TestApis.users().instrumented());
assertThrows(NeneException.class,
- () -> sTestApis.settings().global().getInt(
- sTestApis.users().instrumented(), KEY));
- assertThat(sTestApis.settings().global().getString(sTestApis.users().instrumented(),
+ () -> TestApis.settings().global().getInt(
+ TestApis.users().instrumented(), KEY));
+ assertThat(TestApis.settings().global().getString(TestApis.users().instrumented(),
KEY)).isNotEqualTo(STRING_VALUE);
}
@@ -365,14 +364,14 @@
@RequireSdkVersion(min = Build.VERSION_CODES.S)
@Ignore("b/194669450")
public void resetWithUser_differentUser_resetsGlobalSettings() {
- sTestApis.settings().global().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
- sTestApis.settings().global().putString(sDeviceState.secondaryUser(), KEY, STRING_VALUE);
+ TestApis.settings().global().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
+ TestApis.settings().global().putString(sDeviceState.secondaryUser(), KEY, STRING_VALUE);
- sTestApis.settings().global().reset(sDeviceState.secondaryUser());
+ TestApis.settings().global().reset(sDeviceState.secondaryUser());
- assertThrows(NeneException.class, () -> sTestApis.settings().global().getInt(
+ assertThrows(NeneException.class, () -> TestApis.settings().global().getInt(
sDeviceState.secondaryUser(), KEY));
- assertThat(sTestApis.settings().global().getString(sTestApis.settings().global()
+ assertThat(TestApis.settings().global().getString(TestApis.settings().global()
.getString(sDeviceState.secondaryUser(), KEY))).isNotEqualTo(STRING_VALUE);
}
@@ -381,6 +380,6 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void resetWithUser_differentUser_preS_throwsException() {
assertThrows(UnsupportedOperationException.class,
- () -> sTestApis.settings().global().reset(sDeviceState.secondaryUser()));
+ () -> TestApis.settings().global().reset(sDeviceState.secondaryUser()));
}
}
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/settings/SecureSettingsTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/settings/SecureSettingsTest.java
index bf4aa8b..6622a1a 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/settings/SecureSettingsTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/settings/SecureSettingsTest.java
@@ -47,20 +47,19 @@
@ClassRule @Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final String KEY = "key";
private static final String INVALID_KEY = "noKey";
private static final int INT_VALUE = 123;
@After
public void resetSecureSettings() {
- sTestApis.settings().secure().reset();
+ TestApis.settings().secure().reset();
}
@Test
public void putInt_putsIntIntoSecureSettingsOnInstrumentedUser() throws Exception {
- sTestApis.settings().secure().putInt(KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(KEY, INT_VALUE);
assertThat(android.provider.Settings.Secure.getInt(sContext.getContentResolver(), KEY))
.isEqualTo(INT_VALUE);
@@ -69,7 +68,7 @@
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void putIntWithContentResolver_putsIntIntoSecureSettings() throws Exception {
- sTestApis.settings().secure().putInt(sContext.getContentResolver(), KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(sContext.getContentResolver(), KEY, INT_VALUE);
assertThat(android.provider.Settings.Secure.getInt(sContext.getContentResolver(), KEY))
.isEqualTo(INT_VALUE);
@@ -78,13 +77,13 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void putIntWithContentResolver_preS_throwsException() throws Exception {
assertThrows(UnsupportedOperationException.class, () ->
- sTestApis.settings().secure().putInt(
+ TestApis.settings().secure().putInt(
sContext.getContentResolver(), KEY, INT_VALUE));
}
@Test
public void putIntWithUser_instrumentedUser_putsIntIntoSecureSettings() throws Exception {
- sTestApis.settings().secure().putInt(sTestApis.users().instrumented(), KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(TestApis.users().instrumented(), KEY, INT_VALUE);
assertThat(android.provider.Settings.Secure.getInt(sContext.getContentResolver(), KEY))
.isEqualTo(INT_VALUE);
@@ -94,12 +93,12 @@
@EnsureHasSecondaryUser
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void putIntWithUser_differentUser_putsIntIntoSecureSettings() throws Exception {
- sTestApis.settings().secure().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
try (PermissionContext p =
- sTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
assertThat(android.provider.Settings.Secure.getInt(
- sTestApis.context().androidContextAsUser(sDeviceState.secondaryUser())
+ TestApis.context().androidContextAsUser(sDeviceState.secondaryUser())
.getContentResolver(), KEY)).isEqualTo(INT_VALUE);
}
}
@@ -109,91 +108,91 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void putIntWithUser_differentUser_preS_throwsException() throws Exception {
assertThrows(UnsupportedOperationException.class, () ->
- sTestApis.settings().secure().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE));
+ TestApis.settings().secure().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE));
}
@Test
public void getInt_getsIntFromSecureSettingsOnInstrumentedUser() {
- sTestApis.settings().secure().putInt(KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(KEY, INT_VALUE);
- assertThat(sTestApis.settings().secure().getInt(KEY)).isEqualTo(INT_VALUE);
+ assertThat(TestApis.settings().secure().getInt(KEY)).isEqualTo(INT_VALUE);
}
@Test
public void getInt_invalidKey_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.settings().secure().getInt(INVALID_KEY));
+ () -> TestApis.settings().secure().getInt(INVALID_KEY));
}
@Test
public void getInt_invalidKey_withDefault_returnsDefault() {
- assertThat(sTestApis.settings().secure().getInt(INVALID_KEY, INT_VALUE)).isEqualTo(
+ assertThat(TestApis.settings().secure().getInt(INVALID_KEY, INT_VALUE)).isEqualTo(
INT_VALUE);
}
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void getIntWithContentResolver_getsIntFromSecureSettings() {
- sTestApis.settings().secure().putInt(
- sTestApis.context().instrumentedContext().getContentResolver(), KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(
+ TestApis.context().instrumentedContext().getContentResolver(), KEY, INT_VALUE);
- assertThat(sTestApis.settings().secure().getInt(
- sTestApis.context().instrumentedContext().getContentResolver(), KEY))
+ assertThat(TestApis.settings().secure().getInt(
+ TestApis.context().instrumentedContext().getContentResolver(), KEY))
.isEqualTo(INT_VALUE);
}
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void getIntWithContentResolver_preS_throwsException() {
- assertThrows(NeneException.class, () -> sTestApis.settings().secure().getInt(
- sTestApis.context().instrumentedContext().getContentResolver(), KEY));
+ assertThrows(NeneException.class, () -> TestApis.settings().secure().getInt(
+ TestApis.context().instrumentedContext().getContentResolver(), KEY));
}
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void getIntWithContentResolver_invalidKey_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.settings().secure().getInt(
- sTestApis.context().instrumentedContext().getContentResolver(),
+ () -> TestApis.settings().secure().getInt(
+ TestApis.context().instrumentedContext().getContentResolver(),
INVALID_KEY));
}
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void getIntWithContentResolver_invalidKey_withDefault_returnsDefault() {
- assertThat(sTestApis.settings().secure().getInt(
- sTestApis.context().instrumentedContext().getContentResolver(),
+ assertThat(TestApis.settings().secure().getInt(
+ TestApis.context().instrumentedContext().getContentResolver(),
INVALID_KEY, INT_VALUE)).isEqualTo(INT_VALUE);
}
@Test
public void getIntWithUser_instrumentedUser_getsIntFromSecureSettings() {
- sTestApis.settings().secure().putInt(KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(KEY, INT_VALUE);
- assertThat(sTestApis.settings().secure().getInt(sTestApis.users().instrumented(), KEY))
+ assertThat(TestApis.settings().secure().getInt(TestApis.users().instrumented(), KEY))
.isEqualTo(INT_VALUE);
}
@Test
public void getIntWithUser_invalidKey_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.settings().secure().getInt(
- sTestApis.users().instrumented(), INVALID_KEY));
+ () -> TestApis.settings().secure().getInt(
+ TestApis.users().instrumented(), INVALID_KEY));
}
@Test
public void getIntWithUser_invalidKey_withDefault_returnsDefault() {
- assertThat(sTestApis.settings().secure().getInt(
- sTestApis.users().instrumented(), INVALID_KEY, INT_VALUE)).isEqualTo(INT_VALUE);
+ assertThat(TestApis.settings().secure().getInt(
+ TestApis.users().instrumented(), INVALID_KEY, INT_VALUE)).isEqualTo(INT_VALUE);
}
@Test
@EnsureHasSecondaryUser
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void getIntWithUser_differentUser_getsIntFromSecureSettings() {
- sTestApis.settings().secure().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
- assertThat(sTestApis.settings().secure().getInt(
+ assertThat(TestApis.settings().secure().getInt(
sDeviceState.secondaryUser(), KEY)).isEqualTo(INT_VALUE);
}
@@ -202,31 +201,31 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void getIntWithUser_differentUser_preS_throwsException() {
assertThrows(UnsupportedOperationException.class, () -> {
- sTestApis.settings().secure().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
});
}
@Test
public void reset_resetsSecureSettings() {
- sTestApis.settings().secure().putInt(KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(KEY, INT_VALUE);
- sTestApis.settings().secure().reset();
+ TestApis.settings().secure().reset();
- assertThrows(NeneException.class, () -> sTestApis.settings().secure().getInt(KEY));
+ assertThrows(NeneException.class, () -> TestApis.settings().secure().getInt(KEY));
}
@Test
@RequireSdkVersion(min = Build.VERSION_CODES.S)
public void resetWithContentResolver_resetsSecureSettings() {
ContentResolver contentResolver =
- sTestApis.context().instrumentedContext().getContentResolver();
- sTestApis.settings().secure().putInt(contentResolver, KEY, INT_VALUE);
+ TestApis.context().instrumentedContext().getContentResolver();
+ TestApis.settings().secure().putInt(contentResolver, KEY, INT_VALUE);
- sTestApis.settings().secure().reset(contentResolver);
+ TestApis.settings().secure().reset(contentResolver);
assertThrows(NeneException.class,
- () -> sTestApis.settings().secure().getInt(
+ () -> TestApis.settings().secure().getInt(
contentResolver,
KEY));
}
@@ -235,21 +234,21 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void resetWithContentResolver_preS_throwsException() {
ContentResolver contentResolver =
- sTestApis.context().instrumentedContext().getContentResolver();
+ TestApis.context().instrumentedContext().getContentResolver();
assertThrows(UnsupportedOperationException.class,
- () -> sTestApis.settings().secure().reset(contentResolver));
+ () -> TestApis.settings().secure().reset(contentResolver));
}
@Test
public void resetWithUser_instrumentedUser_resetsSecureSettings() {
- sTestApis.settings().secure().putInt(sTestApis.users().instrumented(), KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(TestApis.users().instrumented(), KEY, INT_VALUE);
- sTestApis.settings().secure().reset(sTestApis.users().instrumented());
+ TestApis.settings().secure().reset(TestApis.users().instrumented());
assertThrows(NeneException.class,
- () -> sTestApis.settings().secure().getInt(
- sTestApis.users().instrumented(),
+ () -> TestApis.settings().secure().getInt(
+ TestApis.users().instrumented(),
KEY));
}
@@ -258,12 +257,12 @@
@RequireSdkVersion(min = Build.VERSION_CODES.S)
@Ignore("b/194669450")
public void resetWithUser_differentUser_resetsSecureSettings() {
- sTestApis.settings().secure().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
+ TestApis.settings().secure().putInt(sDeviceState.secondaryUser(), KEY, INT_VALUE);
- sTestApis.settings().secure().reset(sDeviceState.secondaryUser());
+ TestApis.settings().secure().reset(sDeviceState.secondaryUser());
assertThrows(NeneException.class,
- () -> sTestApis.settings().secure().getInt(
+ () -> TestApis.settings().secure().getInt(
sDeviceState.secondaryUser(),
KEY));
}
@@ -273,6 +272,6 @@
@RequireSdkVersion(max = Build.VERSION_CODES.R)
public void resetWithUser_differentUser_preS_throwsException() {
assertThrows(UnsupportedOperationException.class,
- () -> sTestApis.settings().secure().reset(sDeviceState.secondaryUser()));
+ () -> TestApis.settings().secure().reset(sDeviceState.secondaryUser()));
}
}
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UserReferenceTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UserReferenceTest.java
index 7a87d1a..52a9b99 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UserReferenceTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UserReferenceTest.java
@@ -47,7 +47,6 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
@RunWith(BedsteadJUnit4.class)
public class UserReferenceTest {
@@ -56,25 +55,24 @@
private static final String USER_NAME = "userName";
private static final String TEST_ACTIVITY_NAME = "com.android.bedstead.nene.test.Activity";
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
@ClassRule @Rule
public static final DeviceState sDeviceState = new DeviceState();
@Test
public void id_returnsId() {
- assertThat(sTestApis.users().find(USER_ID).id()).isEqualTo(USER_ID);
+ assertThat(TestApis.users().find(USER_ID).id()).isEqualTo(USER_ID);
}
@Test
public void userHandle_referencesId() {
- assertThat(sTestApis.users().find(USER_ID).userHandle().getIdentifier()).isEqualTo(USER_ID);
+ assertThat(TestApis.users().find(USER_ID).userHandle().getIdentifier()).isEqualTo(USER_ID);
}
@Test
public void resolve_doesNotExist_returnsNull() {
- assertThat(sTestApis.users().find(NON_EXISTING_USER_ID).resolve()).isNull();
+ assertThat(TestApis.users().find(NON_EXISTING_USER_ID).resolve()).isNull();
}
@Test
@@ -84,10 +82,11 @@
}
@Test
- @EnsureHasNoSecondaryUser // TODO(scottjonathan): We should specify that we can create a new user
+ // TODO(scottjonathan): We should specify that we can create a new user
+ @EnsureHasNoSecondaryUser
@EnsureHasNoWorkProfile
public void resolve_doesExist_userHasCorrectDetails() {
- UserReference userReference = sTestApis.users().createUser().name(USER_NAME).create();
+ UserReference userReference = TestApis.users().createUser().name(USER_NAME).create();
try {
User user = userReference.resolve();
@@ -99,27 +98,27 @@
@Test
public void remove_userDoesNotExist_throwsException() {
- assertThrows(NeneException.class, () -> sTestApis.users().find(USER_ID).remove());
+ assertThrows(NeneException.class, () -> TestApis.users().find(USER_ID).remove());
}
@Test
public void remove_userExists_removesUser() {
- UserReference user = sTestApis.users().createUser().create();
+ UserReference user = TestApis.users().createUser().create();
user.remove();
- assertThat(sTestApis.users().all()).doesNotContain(user);
+ assertThat(TestApis.users().all()).doesNotContain(user);
}
@Test
public void start_userDoesNotExist_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.users().find(NON_EXISTING_USER_ID).start());
+ () -> TestApis.users().find(NON_EXISTING_USER_ID).start());
}
@Test
public void start_userNotStarted_userIsStarted() {
- UserReference user = sTestApis.users().createUser().create().stop();
+ UserReference user = TestApis.users().createUser().create().stop();
user.start();
@@ -144,7 +143,7 @@
@Test
public void stop_userDoesNotExist_throwsException() {
assertThrows(NeneException.class,
- () -> sTestApis.users().find(NON_EXISTING_USER_ID).stop());
+ () -> TestApis.users().find(NON_EXISTING_USER_ID).stop());
}
@Test
@@ -152,7 +151,8 @@
public void stop_userStarted_userIsStopped() {
sDeviceState.secondaryUser().stop();
- assertThat(sDeviceState.secondaryUser().resolve().state()).isEqualTo(User.UserState.NOT_RUNNING);
+ assertThat(sDeviceState.secondaryUser().resolve().state())
+ .isEqualTo(User.UserState.NOT_RUNNING);
}
@Test
@@ -173,9 +173,10 @@
"INTERACT_ACROSS_USERS_FULL is only usable by tests on Q+",
SDK_INT >= Build.VERSION_CODES.Q);
try (PermissionContext p =
- sTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
- sTestApis.packages().find(sContext.getPackageName()).install(sDeviceState.secondaryUser());
+ TestApis.packages().find(sContext.getPackageName())
+ .install(sDeviceState.secondaryUser());
sDeviceState.secondaryUser().switchTo();
Intent intent = new Intent();
@@ -191,7 +192,7 @@
.onUser(sDeviceState.secondaryUser());
assertThat(logs.poll()).isNotNull();
} finally {
- sTestApis.users().system().switchTo();
+ TestApis.users().system().switchTo();
}
}
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UserTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UserTest.java
index 0cc4398..4289f47 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UserTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UserTest.java
@@ -36,13 +36,11 @@
private static final UserType USER_TYPE = new UserType(new UserType.MutableUserType());
private static final String USER_NAME = "userName";
- private final TestApis mTestApis = new TestApis();
-
@Test
public void id_returnsId() {
User.MutableUser mutableUser = createValidMutableUser();
mutableUser.mId = USER_ID;
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.id()).isEqualTo(USER_ID);
}
@@ -52,14 +50,14 @@
User.MutableUser mutableUser = createValidMutableUser();
mutableUser.mId = null;
- assertThrows(NullPointerException.class, () -> new User(mTestApis, mutableUser));
+ assertThrows(NullPointerException.class, () -> new User(mutableUser));
}
@Test
public void serialNo_returnsSerialNo() {
User.MutableUser mutableUser = createValidMutableUser();
mutableUser.mSerialNo = SERIAL_NO;
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.serialNo()).isEqualTo(SERIAL_NO);
}
@@ -67,7 +65,7 @@
@Test
public void serialNo_notSet_returnsNull() {
User.MutableUser mutableUser = createValidMutableUser();
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.serialNo()).isNull();
}
@@ -76,7 +74,7 @@
public void name_returnsName() {
User.MutableUser mutableUser = createValidMutableUser();
mutableUser.mName = USER_NAME;
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.name()).isEqualTo(USER_NAME);
}
@@ -84,7 +82,7 @@
@Test
public void name_notSet_returnsNull() {
User.MutableUser mutableUser = createValidMutableUser();
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.name()).isNull();
}
@@ -93,7 +91,7 @@
public void type_returnsName() {
User.MutableUser mutableUser = createValidMutableUser();
mutableUser.mType = USER_TYPE;
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.type()).isEqualTo(USER_TYPE);
}
@@ -101,7 +99,7 @@
@Test
public void type_notSet_returnsNull() {
User.MutableUser mutableUser = createValidMutableUser();
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.type()).isNull();
}
@@ -110,7 +108,7 @@
public void hasProfileOwner_returnsHasProfileOwner() {
User.MutableUser mutableUser = createValidMutableUser();
mutableUser.mHasProfileOwner = true;
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.hasProfileOwner()).isTrue();
}
@@ -118,7 +116,7 @@
@Test
public void hasProfileOwner_notSet_returnsNull() {
User.MutableUser mutableUser = createValidMutableUser();
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.hasProfileOwner()).isNull();
}
@@ -127,7 +125,7 @@
public void isPrimary_returnsIsPrimary() {
User.MutableUser mutableUser = createValidMutableUser();
mutableUser.mIsPrimary = true;
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.isPrimary()).isTrue();
}
@@ -135,14 +133,14 @@
@Test
public void isPrimary_notSet_returnsNull() {
User.MutableUser mutableUser = createValidMutableUser();
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.isPrimary()).isNull();
}
@Test
public void state_userNotStarted_returnsState() {
- UserReference user = mTestApis.users().createUser().create();
+ UserReference user = TestApis.users().createUser().create();
user.stop();
try {
@@ -155,7 +153,7 @@
@Test
@Ignore("TODO: Ensure we can enter the user locked state")
public void state_userLocked_returnsState() {
- UserReference user = mTestApis.users().createUser().createAndStart();
+ UserReference user = TestApis.users().createUser().createAndStart();
try {
assertThat(user.resolve().state()).isEqualTo(User.UserState.RUNNING_LOCKED);
@@ -166,7 +164,7 @@
@Test
public void state_userUnlocked_returnsState() {
- UserReference user = mTestApis.users().createUser().createAndStart();
+ UserReference user = TestApis.users().createUser().createAndStart();
try {
assertThat(user.resolve().state()).isEqualTo(User.UserState.RUNNING_UNLOCKED);
@@ -177,23 +175,23 @@
@Test
public void parent_returnsParent() {
- UserReference parentUser = new User(mTestApis, createValidMutableUser());
+ UserReference parentUser = new User(createValidMutableUser());
User.MutableUser mutableUser = createValidMutableUser();
mutableUser.mParent = parentUser;
- User user = new User(mTestApis, mutableUser);
+ User user = new User(mutableUser);
assertThat(user.parent()).isEqualTo(parentUser);
}
@Test
public void autoclose_removesUser() {
- int numUsers = mTestApis.users().all().size();
+ int numUsers = TestApis.users().all().size();
- try (UserReference user = mTestApis.users().createUser().create()) {
+ try (UserReference user = TestApis.users().createUser().create()) {
// We intentionally don't do anything here, just rely on the auto-close behaviour
}
- assertThat(mTestApis.users().all()).hasSize(numUsers);
+ assertThat(TestApis.users().all()).hasSize(numUsers);
}
private User.MutableUser createValidMutableUser() {
diff --git a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UsersTest.java b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UsersTest.java
index 93d76d8..5430d0c 100644
--- a/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UsersTest.java
+++ b/common/device-side/bedstead/nene/src/test/java/com/android/bedstead/nene/users/UsersTest.java
@@ -60,12 +60,11 @@
private static final int USER_ID = NON_EXISTING_USER_ID;
private static final String USER_NAME = "userName";
- private final TestApis mTestApis = new TestApis();
private final UserType mSecondaryUserType =
- mTestApis.users().supportedType(SECONDARY_USER_TYPE_NAME);
+ TestApis.users().supportedType(SECONDARY_USER_TYPE_NAME);
private final UserType mManagedProfileType =
- mTestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME);
- private final UserReference mInstrumentedUser = mTestApis.users().instrumented();
+ TestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME);
+ private final UserReference mInstrumentedUser = TestApis.users().instrumented();
@ClassRule
@Rule
@@ -77,7 +76,7 @@
@Test
public void supportedTypes_containsManagedProfile() {
UserType managedProfileUserType =
- mTestApis.users().supportedTypes().stream().filter(
+ TestApis.users().supportedTypes().stream().filter(
(ut) -> ut.name().equals(MANAGED_PROFILE_TYPE_NAME)).findFirst().get();
assertThat(managedProfileUserType.baseType()).containsExactly(UserType.BaseType.PROFILE);
@@ -90,7 +89,7 @@
@Test
public void supportedTypes_containsSystemUser() {
UserType systemUserType =
- mTestApis.users().supportedTypes().stream().filter(
+ TestApis.users().supportedTypes().stream().filter(
(ut) -> ut.name().equals(SYSTEM_USER_TYPE_NAME)).findFirst().get();
assertThat(systemUserType.baseType()).containsExactly(
@@ -103,7 +102,7 @@
@Test
public void supportedType_validType_returnsType() {
UserType managedProfileUserType =
- mTestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME);
+ TestApis.users().supportedType(MANAGED_PROFILE_TYPE_NAME);
assertThat(managedProfileUserType.baseType()).containsExactly(UserType.BaseType.PROFILE);
assertThat(managedProfileUserType.enabled()).isTrue();
@@ -114,15 +113,15 @@
@Test
public void supportedType_invalidType_returnsNull() {
- assertThat(mTestApis.users().supportedType(INVALID_TYPE_NAME)).isNull();
+ assertThat(TestApis.users().supportedType(INVALID_TYPE_NAME)).isNull();
}
@Test
public void all_containsCreatedUser() {
- UserReference user = mTestApis.users().createUser().create();
+ UserReference user = TestApis.users().createUser().create();
try {
- assertThat(mTestApis.users().all()).contains(user);
+ assertThat(TestApis.users().all()).contains(user);
} finally {
user.remove();
}
@@ -130,12 +129,12 @@
@Test
public void all_userAddedSinceLastCallToUsers_containsNewUser() {
- UserReference user = mTestApis.users().createUser().create();
- mTestApis.users().all();
- UserReference user2 = mTestApis.users().createUser().create();
+ UserReference user = TestApis.users().createUser().create();
+ TestApis.users().all();
+ UserReference user2 = TestApis.users().createUser().create();
try {
- assertThat(mTestApis.users().all()).contains(user2);
+ assertThat(TestApis.users().all()).contains(user2);
} finally {
user.remove();
user2.remove();
@@ -144,18 +143,18 @@
@Test
public void all_userRemovedSinceLastCallToUsers_doesNotContainRemovedUser() {
- UserReference user = mTestApis.users().createUser().create();
- mTestApis.users().all();
+ UserReference user = TestApis.users().createUser().create();
+ TestApis.users().all();
user.remove();
- assertThat(mTestApis.users().all()).doesNotContain(user);
+ assertThat(TestApis.users().all()).doesNotContain(user);
}
@Test
public void find_userExists_returnsUserReference() {
- UserReference user = mTestApis.users().createUser().create();
+ UserReference user = TestApis.users().createUser().create();
try {
- assertThat(mTestApis.users().find(user.id())).isEqualTo(user);
+ assertThat(TestApis.users().find(user.id())).isEqualTo(user);
} finally {
user.remove();
}
@@ -163,33 +162,33 @@
@Test
public void find_userDoesNotExist_returnsUserReference() {
- assertThat(mTestApis.users().find(NON_EXISTING_USER_ID)).isNotNull();
+ assertThat(TestApis.users().find(NON_EXISTING_USER_ID)).isNotNull();
}
@Test
public void find_fromUserHandle_referencesCorrectId() {
- assertThat(mTestApis.users().find(UserHandle.of(USER_ID)).id()).isEqualTo(USER_ID);
+ assertThat(TestApis.users().find(UserHandle.of(USER_ID)).id()).isEqualTo(USER_ID);
}
@Test
public void find_constructedReferenceReferencesCorrectId() {
- assertThat(mTestApis.users().find(USER_ID).id()).isEqualTo(USER_ID);
+ assertThat(TestApis.users().find(USER_ID).id()).isEqualTo(USER_ID);
}
@Test
public void createUser_additionalSystemUser_throwsException() {
assertThrows(NeneException.class, () ->
- mTestApis.users().createUser()
- .type(mTestApis.users().supportedType(SYSTEM_USER_TYPE_NAME))
+ TestApis.users().createUser()
+ .type(TestApis.users().supportedType(SYSTEM_USER_TYPE_NAME))
.create());
}
@Test
public void createUser_userIsCreated() {
- UserReference user = mTestApis.users().createUser().create();
+ UserReference user = TestApis.users().createUser().create();
try {
- assertThat(mTestApis.users().all()).contains(user);
+ assertThat(TestApis.users().all()).contains(user);
} finally {
user.remove();
}
@@ -197,7 +196,7 @@
@Test
public void createUser_createdUserHasCorrectName() {
- UserReference userReference = mTestApis.users().createUser()
+ UserReference userReference = TestApis.users().createUser()
.name(USER_NAME)
.create();
@@ -210,7 +209,7 @@
@Test
public void createUser_createdUserHasCorrectTypeName() {
- UserReference userReference = mTestApis.users().createUser()
+ UserReference userReference = TestApis.users().createUser()
.type(mSecondaryUserType)
.create();
@@ -223,15 +222,15 @@
@Test
public void createUser_specifiesNullUserType_throwsException() {
- UserBuilder userBuilder = mTestApis.users().createUser();
+ UserBuilder userBuilder = TestApis.users().createUser();
assertThrows(NullPointerException.class, () -> userBuilder.type(null));
}
@Test
public void createUser_specifiesSystemUserType_throwsException() {
- UserType type = mTestApis.users().supportedType(SYSTEM_USER_TYPE_NAME);
- UserBuilder userBuilder = mTestApis.users().createUser()
+ UserType type = TestApis.users().supportedType(SYSTEM_USER_TYPE_NAME);
+ UserBuilder userBuilder = TestApis.users().createUser()
.type(type);
assertThrows(NeneException.class, userBuilder::create);
@@ -239,7 +238,7 @@
@Test
public void createUser_specifiesSecondaryUserType_createsUser() {
- UserReference user = mTestApis.users().createUser().type(mSecondaryUserType).create();
+ UserReference user = TestApis.users().createUser().type(mSecondaryUserType).create();
try {
assertThat(user.resolve()).isNotNull();
@@ -251,8 +250,8 @@
@Test
@EnsureHasNoDeviceOwner // Device Owners can disable managed profiles
public void createUser_specifiesManagedProfileUserType_createsUser() {
- UserReference systemUser = mTestApis.users().system();
- UserReference user = mTestApis.users().createUser()
+ UserReference systemUser = TestApis.users().system();
+ UserReference user = TestApis.users().createUser()
.type(mManagedProfileType).parent(systemUser).create();
try {
@@ -264,12 +263,12 @@
@Test
public void createUser_createsProfile_parentIsSet() {
- UserReference systemUser = mTestApis.users().system();
- UserReference user = mTestApis.users().createUser()
+ UserReference systemUser = TestApis.users().system();
+ UserReference user = TestApis.users().createUser()
.type(mManagedProfileType).parent(systemUser).create();
try {
- assertThat(user.resolve().parent()).isEqualTo(mTestApis.users().system());
+ assertThat(user.resolve().parent()).isEqualTo(TestApis.users().system());
} finally {
user.remove();
}
@@ -277,8 +276,8 @@
@Test
public void createUser_specifiesParentOnNonProfileType_throwsException() {
- UserReference systemUser = mTestApis.users().system();
- UserBuilder userBuilder = mTestApis.users().createUser()
+ UserReference systemUser = TestApis.users().system();
+ UserBuilder userBuilder = TestApis.users().createUser()
.type(mSecondaryUserType).parent(systemUser);
assertThrows(NeneException.class, userBuilder::create);
@@ -286,7 +285,7 @@
@Test
public void createUser_specifiesProfileTypeWithoutParent_throwsException() {
- UserBuilder userBuilder = mTestApis.users().createUser()
+ UserBuilder userBuilder = TestApis.users().createUser()
.type(mManagedProfileType);
assertThrows(NeneException.class, userBuilder::create);
@@ -297,10 +296,10 @@
assumeTrue("After Android S, managed profiles may be a profile of a non-system user",
SDK_INT < Build.VERSION_CODES.S);
- UserReference nonSystemUser = mTestApis.users().createUser().create();
+ UserReference nonSystemUser = TestApis.users().createUser().create();
try {
- UserBuilder userBuilder = mTestApis.users().createUser()
+ UserBuilder userBuilder = TestApis.users().createUser()
.type(mManagedProfileType)
.parent(nonSystemUser);
@@ -315,7 +314,7 @@
User user = null;
try {
- user = mTestApis.users().createUser().name(USER_NAME).createAndStart().resolve();
+ user = TestApis.users().createUser().name(USER_NAME).createAndStart().resolve();
assertThat(user.state()).isEqualTo(User.UserState.RUNNING_UNLOCKED);
} finally {
if (user != null) {
@@ -326,25 +325,25 @@
@Test
public void system_hasId0() {
- assertThat(mTestApis.users().system().id()).isEqualTo(0);
+ assertThat(TestApis.users().system().id()).isEqualTo(0);
}
@Test
public void instrumented_hasCurrentProccessId() {
- assertThat(mTestApis.users().instrumented().id())
+ assertThat(TestApis.users().instrumented().id())
.isEqualTo(android.os.Process.myUserHandle().getIdentifier());
}
@Test
@EnsureHasNoSecondaryUser
public void findUsersOfType_noMatching_returnsEmptySet() {
- assertThat(mTestApis.users().findUsersOfType(mSecondaryUserType)).isEmpty();
+ assertThat(TestApis.users().findUsersOfType(mSecondaryUserType)).isEmpty();
}
@Test
public void findUsersOfType_nullType_throwsException() {
assertThrows(NullPointerException.class,
- () -> mTestApis.users().findUsersOfType(null));
+ () -> TestApis.users().findUsersOfType(null));
}
@Test
@@ -352,8 +351,8 @@
@Ignore("TODO: Re-enable when harrier .secondaryUser() only"
+ " returns the harrier-managed secondary user")
public void findUsersOfType_returnsUsers() {
- try (UserReference additionalUser = mTestApis.users().createUser().create()) {
- assertThat(mTestApis.users().findUsersOfType(mSecondaryUserType))
+ try (UserReference additionalUser = TestApis.users().createUser().create()) {
+ assertThat(TestApis.users().findUsersOfType(mSecondaryUserType))
.containsExactly(sDeviceState.secondaryUser(), additionalUser);
}
}
@@ -361,60 +360,60 @@
@Test
public void findUsersOfType_profileType_throwsException() {
assertThrows(NeneException.class,
- () -> mTestApis.users().findUsersOfType(mManagedProfileType));
+ () -> TestApis.users().findUsersOfType(mManagedProfileType));
}
@Test
@EnsureHasNoSecondaryUser
public void findUserOfType_noMatching_returnsNull() {
- assertThat(mTestApis.users().findUserOfType(mSecondaryUserType)).isNull();
+ assertThat(TestApis.users().findUserOfType(mSecondaryUserType)).isNull();
}
@Test
public void findUserOfType_nullType_throwsException() {
assertThrows(NullPointerException.class,
- () -> mTestApis.users().findUserOfType(null));
+ () -> TestApis.users().findUserOfType(null));
}
@Test
@EnsureHasSecondaryUser
public void findUserOfType_multipleMatchingUsers_throwsException() {
- try (UserReference additionalUser = mTestApis.users().createUser().create()) {
+ try (UserReference additionalUser = TestApis.users().createUser().create()) {
assertThrows(NeneException.class,
- () -> mTestApis.users().findUserOfType(mSecondaryUserType));
+ () -> TestApis.users().findUserOfType(mSecondaryUserType));
}
}
@Test
@EnsureHasSecondaryUser // TODO(scottjonathan): This should have a way of specifying exactly 1
public void findUserOfType_oneMatchingUser_returnsUser() {
- assertThat(mTestApis.users().findUserOfType(mSecondaryUserType)).isNotNull();
+ assertThat(TestApis.users().findUserOfType(mSecondaryUserType)).isNotNull();
}
@Test
public void findUserOfType_profileType_throwsException() {
assertThrows(NeneException.class,
- () -> mTestApis.users().findUserOfType(mManagedProfileType));
+ () -> TestApis.users().findUserOfType(mManagedProfileType));
}
@Test
@EnsureHasNoWorkProfile
public void findProfilesOfType_noMatching_returnsEmptySet() {
- assertThat(mTestApis.users().findProfilesOfType(mManagedProfileType, mInstrumentedUser))
+ assertThat(TestApis.users().findProfilesOfType(mManagedProfileType, mInstrumentedUser))
.isEmpty();
}
@Test
public void findProfilesOfType_nullType_throwsException() {
assertThrows(NullPointerException.class,
- () -> mTestApis.users().findProfilesOfType(
+ () -> TestApis.users().findProfilesOfType(
/* userType= */ null, mInstrumentedUser));
}
@Test
public void findProfilesOfType_nullParent_throwsException() {
assertThrows(NullPointerException.class,
- () -> mTestApis.users().findProfilesOfType(
+ () -> TestApis.users().findProfilesOfType(
mManagedProfileType, /* parent= */ null));
}
@@ -423,44 +422,44 @@
@Test
@EnsureHasNoWorkProfile
public void findProfileOfType_noMatching_returnsNull() {
- assertThat(mTestApis.users().findProfileOfType(mManagedProfileType, mInstrumentedUser))
+ assertThat(TestApis.users().findProfileOfType(mManagedProfileType, mInstrumentedUser))
.isNull();
}
@Test
public void findProfilesOfType_nonProfileType_throwsException() {
assertThrows(NeneException.class,
- () -> mTestApis.users().findProfilesOfType(mSecondaryUserType, mInstrumentedUser));
+ () -> TestApis.users().findProfilesOfType(mSecondaryUserType, mInstrumentedUser));
}
@Test
public void findProfileOfType_nullType_throwsException() {
assertThrows(NullPointerException.class,
- () -> mTestApis.users().findProfileOfType(/* userType= */ null, mInstrumentedUser));
+ () -> TestApis.users().findProfileOfType(/* userType= */ null, mInstrumentedUser));
}
@Test
public void findProfileOfType_nonProfileType_throwsException() {
assertThrows(NeneException.class,
- () -> mTestApis.users().findProfileOfType(mSecondaryUserType, mInstrumentedUser));
+ () -> TestApis.users().findProfileOfType(mSecondaryUserType, mInstrumentedUser));
}
@Test
public void findProfileOfType_nullParent_throwsException() {
assertThrows(NullPointerException.class,
- () -> mTestApis.users().findProfileOfType(mManagedProfileType, /* parent= */ null));
+ () -> TestApis.users().findProfileOfType(mManagedProfileType, /* parent= */ null));
}
@Test
@EnsureHasWorkProfile // TODO(scottjonathan): This should have a way of specifying exactly 1
public void findProfileOfType_oneMatchingUser_returnsUser() {
- assertThat(mTestApis.users().findProfileOfType(mManagedProfileType, mInstrumentedUser))
+ assertThat(TestApis.users().findProfileOfType(mManagedProfileType, mInstrumentedUser))
.isNotNull();
}
@Test
public void nonExisting_userDoesNotExist() {
- UserReference userReference = mTestApis.users().nonExisting();
+ UserReference userReference = TestApis.users().nonExisting();
assertThat(userReference.resolve()).isNull();
}
@@ -468,12 +467,12 @@
@Test
@EnsureHasSecondaryUser(switchedToUser = TRUE)
public void currentUser_secondaryUser_returnsCurrentUser() {
- assertThat(mTestApis.users().current()).isEqualTo(sDeviceState.secondaryUser());
+ assertThat(TestApis.users().current()).isEqualTo(sDeviceState.secondaryUser());
}
@Test
@RequireRunOnPrimaryUser(switchedToUser = TRUE)
public void currentUser_primaryUser_returnsCurrentUser() {
- assertThat(mTestApis.users().current()).isEqualTo(sDeviceState.primaryUser());
+ assertThat(TestApis.users().current()).isEqualTo(sDeviceState.primaryUser());
}
}
diff --git a/common/device-side/bedstead/remotedpc/src/main/java/com/android/bedstead/remotedpc/RemoteDpc.java b/common/device-side/bedstead/remotedpc/src/main/java/com/android/bedstead/remotedpc/RemoteDpc.java
index ce0cdc0..01317e3 100644
--- a/common/device-side/bedstead/remotedpc/src/main/java/com/android/bedstead/remotedpc/RemoteDpc.java
+++ b/common/device-side/bedstead/remotedpc/src/main/java/com/android/bedstead/remotedpc/RemoteDpc.java
@@ -34,9 +34,8 @@
/** Entry point to RemoteDPC. */
public final class RemoteDpc extends TestAppInstanceReference {
- private static final TestApis sTestApis = new TestApis();
// This must be instrumentation not instrumented to access the resources
- private static final Context sContext = sTestApis.context().instrumentationContext();
+ private static final Context sContext = TestApis.context().instrumentationContext();
public static final ComponentName DPC_COMPONENT_NAME = new ComponentName(
"com.android.RemoteDPC",
@@ -55,7 +54,7 @@
*/
@Nullable
public static RemoteDpc deviceOwner() {
- DeviceOwner deviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ DeviceOwner deviceOwner = TestApis.devicePolicy().getDeviceOwner();
if (deviceOwner == null || !deviceOwner.componentName().equals(DPC_COMPONENT_NAME)) {
return null;
}
@@ -70,7 +69,7 @@
*/
@Nullable
public static RemoteDpc profileOwner() {
- return profileOwner(sTestApis.users().instrumented());
+ return profileOwner(TestApis.users().instrumented());
}
/**
@@ -84,7 +83,7 @@
throw new NullPointerException();
}
- return profileOwner(sTestApis.users().find(profile));
+ return profileOwner(TestApis.users().find(profile));
}
/**
@@ -98,7 +97,7 @@
throw new NullPointerException();
}
- ProfileOwner profileOwner = sTestApis.devicePolicy().getProfileOwner(profile);
+ ProfileOwner profileOwner = TestApis.devicePolicy().getProfileOwner(profile);
if (profileOwner == null || !profileOwner.componentName().equals(DPC_COMPONENT_NAME)) {
return null;
}
@@ -114,7 +113,7 @@
*/
@Nullable
public static RemoteDpc any() {
- return any(sTestApis.users().instrumented());
+ return any(TestApis.users().instrumented());
}
/**
@@ -129,7 +128,7 @@
throw new NullPointerException();
}
- return any(sTestApis.users().find(user));
+ return any(TestApis.users().find(user));
}
/**
@@ -169,7 +168,7 @@
if (user == null) {
throw new NullPointerException();
}
- return setAsDeviceOwner(sTestApis.users().find(user));
+ return setAsDeviceOwner(TestApis.users().find(user));
}
/**
@@ -180,7 +179,7 @@
throw new NullPointerException();
}
- DeviceOwner deviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ DeviceOwner deviceOwner = TestApis.devicePolicy().getDeviceOwner();
if (deviceOwner != null) {
if (deviceOwner.componentName().equals(DPC_COMPONENT_NAME)) {
return new RemoteDpc(deviceOwner); // Already set
@@ -189,7 +188,7 @@
}
ensureInstalled(user);
- return new RemoteDpc(sTestApis.devicePolicy().setDeviceOwner(user, DPC_COMPONENT_NAME));
+ return new RemoteDpc(TestApis.devicePolicy().setDeviceOwner(user, DPC_COMPONENT_NAME));
}
/**
@@ -199,7 +198,7 @@
if (user == null) {
throw new NullPointerException();
}
- return setAsProfileOwner(sTestApis.users().find(user));
+ return setAsProfileOwner(TestApis.users().find(user));
}
/**
@@ -210,7 +209,7 @@
throw new NullPointerException();
}
- ProfileOwner profileOwner = sTestApis.devicePolicy().getProfileOwner(user);
+ ProfileOwner profileOwner = TestApis.devicePolicy().getProfileOwner(user);
if (profileOwner != null) {
if (profileOwner.componentName().equals(DPC_COMPONENT_NAME)) {
return new RemoteDpc(profileOwner); // Already set
@@ -219,7 +218,7 @@
}
ensureInstalled(user);
- return new RemoteDpc(sTestApis.devicePolicy().setProfileOwner(user, DPC_COMPONENT_NAME));
+ return new RemoteDpc(TestApis.devicePolicy().setProfileOwner(user, DPC_COMPONENT_NAME));
}
private static void ensureInstalled(UserReference user) {
@@ -245,7 +244,7 @@
*/
public void remove() {
mDevicePolicyController.remove();
- sTestApis.packages().find(DPC_COMPONENT_NAME.getPackageName())
+ TestApis.packages().find(DPC_COMPONENT_NAME.getPackageName())
.uninstall(mDevicePolicyController.user());
}
diff --git a/common/device-side/bedstead/remotedpc/src/test/java/com/android/bedstead/remotedpc/RemoteDpcTest.java b/common/device-side/bedstead/remotedpc/src/test/java/com/android/bedstead/remotedpc/RemoteDpcTest.java
index a421df0..81e2ea4 100644
--- a/common/device-side/bedstead/remotedpc/src/test/java/com/android/bedstead/remotedpc/RemoteDpcTest.java
+++ b/common/device-side/bedstead/remotedpc/src/test/java/com/android/bedstead/remotedpc/RemoteDpcTest.java
@@ -55,11 +55,10 @@
@ClassRule @Rule
public static DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
private static TestApp sNonRemoteDpcTestApp;
- private static final UserReference sUser = sTestApis.users().instrumented();
+ private static final UserReference sUser = TestApis.users().instrumented();
private static final UserReference NON_EXISTING_USER_REFERENCE =
- sTestApis.users().find(99999);
+ TestApis.users().find(99999);
private static final UserHandle NON_EXISTING_USER_HANDLE =
NON_EXISTING_USER_REFERENCE.userHandle();
@@ -87,7 +86,7 @@
@Test
public void deviceOwner_nonRemoteDpcDeviceOwner_returnsNull() {
DeviceOwner deviceOwner =
- sTestApis.devicePolicy().setDeviceOwner(sUser, NON_REMOTE_DPC_COMPONENT);
+ TestApis.devicePolicy().setDeviceOwner(sUser, NON_REMOTE_DPC_COMPONENT);
try {
assertThat(RemoteDpc.deviceOwner()).isNull();
} finally {
@@ -114,7 +113,7 @@
@Test
public void profileOwner_nonRemoteDpcProfileOwner_returnsNull() {
ProfileOwner profileOwner =
- sTestApis.devicePolicy().setProfileOwner(sUser, NON_REMOTE_DPC_COMPONENT);
+ TestApis.devicePolicy().setProfileOwner(sUser, NON_REMOTE_DPC_COMPONENT);
try {
assertThat(RemoteDpc.profileOwner()).isNull();
} finally {
@@ -140,9 +139,9 @@
@Test
@EnsureHasNoDeviceOwner
public void profileOwner_userHandle_noProfileOwner_returnsNull() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
assertThat(RemoteDpc.profileOwner(profile.userHandle())).isNull();
@@ -154,13 +153,13 @@
@Test
@EnsureHasNoDeviceOwner
public void profileOwner_userHandle_nonRemoteDpcProfileOwner_returnsNull() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
sNonRemoteDpcTestApp.install(profile);
try {
- sTestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
+ TestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
assertThat(RemoteDpc.profileOwner(profile.userHandle())).isNull();
} finally {
@@ -171,9 +170,9 @@
@Test
@EnsureHasNoDeviceOwner
public void profileOwner_userHandle_remoteDpcProfileOwner_returnsInstance() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
RemoteDpc.setAsProfileOwner(profile);
try {
@@ -192,9 +191,9 @@
@Test
@EnsureHasNoDeviceOwner
public void profileOwner_userReference_noProfileOwner_returnsNull() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
assertThat(RemoteDpc.profileOwner(profile)).isNull();
@@ -206,13 +205,13 @@
@Test
@EnsureHasNoDeviceOwner
public void profileOwner_userReference_nonRemoteDpcProfileOwner_returnsNull() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
sNonRemoteDpcTestApp.install(profile);
try {
- sTestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
+ TestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
assertThat(RemoteDpc.profileOwner(profile)).isNull();
} finally {
@@ -223,9 +222,9 @@
@Test
@EnsureHasNoDeviceOwner
public void profileOwner_userReference_remoteDpcProfileOwner_returnsInstance() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
RemoteDpc.setAsProfileOwner(profile);
try {
@@ -242,7 +241,7 @@
@Test
public void any_noDeviceOwner_nonRemoteDpcProfileOwner_returnsNull() {
- ProfileOwner profileOwner = sTestApis.devicePolicy().setProfileOwner(sUser,
+ ProfileOwner profileOwner = TestApis.devicePolicy().setProfileOwner(sUser,
NON_REMOTE_DPC_COMPONENT);
try {
@@ -254,7 +253,7 @@
@Test
public void any_nonRemoteDpcDeviceOwner_noProfileOwner_returnsNull() {
- DeviceOwner deviceOwner = sTestApis.devicePolicy().setDeviceOwner(sUser,
+ DeviceOwner deviceOwner = TestApis.devicePolicy().setDeviceOwner(sUser,
NON_REMOTE_DPC_COMPONENT);
try {
@@ -299,13 +298,13 @@
@Test
@EnsureHasNoDeviceOwner
public void any_userHandle_noDeviceOwner_nonRemoteDpcProfileOwner_returnsNull() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
sNonRemoteDpcTestApp.install(profile);
try {
- sTestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
+ TestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
assertThat(RemoteDpc.any(profile.userHandle())).isNull();
} finally {
@@ -315,7 +314,7 @@
@Test
public void any_userHandle_nonRemoteDpcDeviceOwner_noProfileOwner_returnsNull() {
- DeviceOwner deviceOwner = sTestApis.devicePolicy().setDeviceOwner(sUser,
+ DeviceOwner deviceOwner = TestApis.devicePolicy().setDeviceOwner(sUser,
NON_REMOTE_DPC_COMPONENT);
try {
@@ -339,9 +338,9 @@
@Test
@EnsureHasNoDeviceOwner
public void any_userHandle_remoteDpcProfileOwner_returnsProfileOwner() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
RemoteDpc profileOwner = RemoteDpc.setAsProfileOwner(profile);
@@ -365,13 +364,13 @@
@Test
@EnsureHasNoDeviceOwner
public void any_userReference_noDeviceOwner_nonRemoteDpcProfileOwner_returnsNull() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
sNonRemoteDpcTestApp.install(profile);
try {
- sTestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
+ TestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
assertThat(RemoteDpc.any(profile)).isNull();
} finally {
@@ -381,7 +380,7 @@
@Test
public void any_userReference_nonRemoteDpcDeviceOwner_noProfileOwner_returnsNull() {
- DeviceOwner deviceOwner = sTestApis.devicePolicy().setDeviceOwner(sUser,
+ DeviceOwner deviceOwner = TestApis.devicePolicy().setDeviceOwner(sUser,
NON_REMOTE_DPC_COMPONENT);
try {
@@ -405,9 +404,9 @@
@Test
@EnsureHasNoDeviceOwner
public void any_userReference_remoteDpcProfileOwner_returnsProfileOwner() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
RemoteDpc profileOwner = RemoteDpc.setAsProfileOwner(profile);
@@ -434,11 +433,11 @@
public void setAsDeviceOwner_userHandle_alreadySet_doesNothing() {
RemoteDpc.setAsDeviceOwner(sUser.userHandle());
- DeviceOwner deviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ DeviceOwner deviceOwner = TestApis.devicePolicy().getDeviceOwner();
try {
RemoteDpc.setAsDeviceOwner(sUser.userHandle());
- deviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ deviceOwner = TestApis.devicePolicy().getDeviceOwner();
assertThat(deviceOwner).isNotNull();
} finally {
if (deviceOwner != null) {
@@ -449,15 +448,15 @@
@Test
public void setAsDeviceOwner_userHandle_alreadyHasDeviceOwner_replacesDeviceOwner() {
- sTestApis.devicePolicy().setDeviceOwner(sUser, NON_REMOTE_DPC_COMPONENT);
+ TestApis.devicePolicy().setDeviceOwner(sUser, NON_REMOTE_DPC_COMPONENT);
try {
RemoteDpc remoteDPC = RemoteDpc.setAsDeviceOwner(sUser.userHandle());
- DeviceOwner deviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ DeviceOwner deviceOwner = TestApis.devicePolicy().getDeviceOwner();
assertThat(deviceOwner).isEqualTo(remoteDPC.devicePolicyController());
} finally {
- sTestApis.devicePolicy().getDeviceOwner().remove();
+ TestApis.devicePolicy().getDeviceOwner().remove();
}
}
@@ -465,7 +464,7 @@
public void setAsDeviceOwner_userHandle_doesNotHaveDeviceOwner_setsDeviceOwner() {
RemoteDpc.setAsDeviceOwner(sUser.userHandle());
- DeviceOwner deviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ DeviceOwner deviceOwner = TestApis.devicePolicy().getDeviceOwner();
try {
assertThat(deviceOwner).isNotNull();
} finally {
@@ -491,11 +490,11 @@
public void setAsDeviceOwner_userReference_alreadySet_doesNothing() {
RemoteDpc.setAsDeviceOwner(sUser);
- DeviceOwner deviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ DeviceOwner deviceOwner = TestApis.devicePolicy().getDeviceOwner();
try {
RemoteDpc.setAsDeviceOwner(sUser);
- deviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ deviceOwner = TestApis.devicePolicy().getDeviceOwner();
assertThat(deviceOwner).isNotNull();
} finally {
if (deviceOwner != null) {
@@ -506,15 +505,15 @@
@Test
public void setAsDeviceOwner_userReference_alreadyHasDeviceOwner_replacesDeviceOwner() {
- sTestApis.devicePolicy().setDeviceOwner(sUser, NON_REMOTE_DPC_COMPONENT);
+ TestApis.devicePolicy().setDeviceOwner(sUser, NON_REMOTE_DPC_COMPONENT);
try {
RemoteDpc remoteDPC = RemoteDpc.setAsDeviceOwner(sUser);
- DeviceOwner deviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ DeviceOwner deviceOwner = TestApis.devicePolicy().getDeviceOwner();
assertThat(deviceOwner).isEqualTo(remoteDPC.devicePolicyController());
} finally {
- sTestApis.devicePolicy().getDeviceOwner().remove();
+ TestApis.devicePolicy().getDeviceOwner().remove();
}
}
@@ -522,7 +521,7 @@
public void setAsDeviceOwner_userReference_doesNotHaveDeviceOwner_setsDeviceOwner() {
RemoteDpc.setAsDeviceOwner(sUser);
- DeviceOwner deviceOwner = sTestApis.devicePolicy().getDeviceOwner();
+ DeviceOwner deviceOwner = TestApis.devicePolicy().getDeviceOwner();
try {
assertThat(deviceOwner).isNotNull();
} finally {
@@ -547,16 +546,16 @@
@Test
@EnsureHasNoDeviceOwner
public void setAsProfileOwner_userHandle_alreadySet_doesNothing() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
RemoteDpc.setAsProfileOwner(profile.userHandle());
RemoteDpc.setAsProfileOwner(profile.userHandle());
- assertThat(sTestApis.devicePolicy().getProfileOwner(profile)).isNotNull();
+ assertThat(TestApis.devicePolicy().getProfileOwner(profile)).isNotNull();
} finally {
profile.remove();
}
@@ -565,17 +564,17 @@
@Test
@EnsureHasNoDeviceOwner
public void setAsProfileOwner_userHandle_alreadyHasProfileOwner_replacesProfileOwner() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
sNonRemoteDpcTestApp.install(profile);
try {
- sTestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
+ TestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
RemoteDpc remoteDPC = RemoteDpc.setAsProfileOwner(profile.userHandle());
- assertThat(sTestApis.devicePolicy().getProfileOwner(profile))
+ assertThat(TestApis.devicePolicy().getProfileOwner(profile))
.isEqualTo(remoteDPC.devicePolicyController());
} finally {
profile.remove();
@@ -585,14 +584,14 @@
@Test
@EnsureHasNoDeviceOwner
public void setAsProfileOwner_userHandle_doesNotHaveProfileOwner_setsProfileOwner() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
RemoteDpc.setAsProfileOwner(profile.userHandle());
- assertThat(sTestApis.devicePolicy().getProfileOwner(profile)).isNotNull();
+ assertThat(TestApis.devicePolicy().getProfileOwner(profile)).isNotNull();
} finally {
profile.remove();
}
@@ -613,16 +612,16 @@
@Test
@EnsureHasNoDeviceOwner
public void setAsProfileOwner_userReference_alreadySet_doesNothing() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
RemoteDpc.setAsProfileOwner(profile);
RemoteDpc.setAsProfileOwner(profile);
- assertThat(sTestApis.devicePolicy().getProfileOwner(profile)).isNotNull();
+ assertThat(TestApis.devicePolicy().getProfileOwner(profile)).isNotNull();
} finally {
profile.remove();
}
@@ -631,17 +630,17 @@
@Test
@EnsureHasNoDeviceOwner
public void setAsProfileOwner_userReference_alreadyHasProfileOwner_replacesProfileOwner() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
sNonRemoteDpcTestApp.install(profile);
try {
- sTestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
+ TestApis.devicePolicy().setProfileOwner(profile, NON_REMOTE_DPC_COMPONENT);
RemoteDpc remoteDPC = RemoteDpc.setAsProfileOwner(profile);
- assertThat(sTestApis.devicePolicy().getProfileOwner(profile))
+ assertThat(TestApis.devicePolicy().getProfileOwner(profile))
.isEqualTo(remoteDPC.devicePolicyController());
} finally {
profile.remove();
@@ -651,14 +650,14 @@
@Test
@EnsureHasNoDeviceOwner
public void setAsProfileOwner_userReference_doesNotHaveProfileOwner_setsProfileOwner() {
- UserReference profile = sTestApis.users().createUser()
+ UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart();
try {
RemoteDpc.setAsProfileOwner(profile);
- assertThat(sTestApis.devicePolicy().getProfileOwner(profile)).isNotNull();
+ assertThat(TestApis.devicePolicy().getProfileOwner(profile)).isNotNull();
} finally {
profile.remove();
}
@@ -670,7 +669,7 @@
try {
assertThat(remoteDPC.devicePolicyController())
- .isEqualTo(sTestApis.devicePolicy().getDeviceOwner());
+ .isEqualTo(TestApis.devicePolicy().getDeviceOwner());
} finally {
remoteDPC.remove();
}
@@ -682,21 +681,21 @@
remoteDPC.remove();
- assertThat(sTestApis.devicePolicy().getDeviceOwner()).isNull();
+ assertThat(TestApis.devicePolicy().getDeviceOwner()).isNull();
}
@Test
@EnsureHasNoDeviceOwner
public void remove_profileOwner_removes() {
- try (UserReference profile = sTestApis.users().createUser()
+ try (UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart()) {
RemoteDpc remoteDPC = RemoteDpc.setAsProfileOwner(profile);
remoteDPC.remove();
- assertThat(sTestApis.devicePolicy().getProfileOwner(profile)).isNull();
+ assertThat(TestApis.devicePolicy().getProfileOwner(profile)).isNull();
}
}
@@ -719,9 +718,9 @@
@Test
@EnsureHasNoDeviceOwner
public void frameworkCall_onProfile_makesCall() {
- try (UserReference profile = sTestApis.users().createUser()
+ try (UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart()) {
RemoteDpc remoteDPC = RemoteDpc.setAsProfileOwner(profile);
@@ -750,7 +749,7 @@
@Test
public void forDevicePolicyController_nonRemoteDpcDevicePolicyController_throwsException() {
- DeviceOwner deviceOwner = sTestApis.devicePolicy().setDeviceOwner(sUser,
+ DeviceOwner deviceOwner = TestApis.devicePolicy().setDeviceOwner(sUser,
NON_REMOTE_DPC_COMPONENT);
try {
@@ -775,9 +774,9 @@
@Test
public void getParentProfileInstance_returnsUsableInstance() {
- try (UserReference profile = sTestApis.users().createUser()
+ try (UserReference profile = TestApis.users().createUser()
.parent(sUser)
- .type(sTestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
+ .type(TestApis.users().supportedType(UserType.MANAGED_PROFILE_TYPE_NAME))
.createAndStart()) {
RemoteDpc remoteDpc = RemoteDpc.setAsProfileOwner(profile);
diff --git a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestApp.java b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestApp.java
index dd4edd3..a15062b 100644
--- a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestApp.java
+++ b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestApp.java
@@ -27,6 +27,7 @@
import com.android.bedstead.nene.packages.Package;
import com.android.bedstead.nene.packages.PackageReference;
import com.android.bedstead.nene.users.UserReference;
+import com.android.bedstead.nene.users.Users;
import com.android.bedstead.testapp.processor.annotations.TestAppSender;
import com.android.queryable.info.ActivityInfo;
@@ -39,10 +40,8 @@
/** Represents a single test app which can be installed and interacted with. */
@TestAppSender
public class TestApp {
-
- private static final TestApis sTestApis = new TestApis();
// Must be instrumentation context to access resources
- private static final Context sContext = sTestApis.context().instrumentationContext();
+ private static final Context sContext = TestApis.context().instrumentationContext();
private final TestAppDetails mDetails;
TestApp(TestAppDetails details) {
@@ -58,7 +57,7 @@
* <p>This will only be resolvable after the app is installed.
*/
public PackageReference reference() {
- return sTestApis.packages().find(packageName());
+ return TestApis.packages().find(packageName());
}
/**
@@ -69,6 +68,15 @@
}
/**
+ * Install the {@link TestApp} on the device for the instrumented user.
+ *
+ * <p>See {@link Users#instrumented()}
+ */
+ public TestAppInstanceReference install() {
+ return install(TestApis.users().instrumented());
+ }
+
+ /**
* Install the {@link TestApp} on the device for the given {@link UserReference}.
*/
public TestAppInstanceReference install(UserReference user) {
@@ -76,7 +84,7 @@
reference().install(user);
} else {
try {
- sTestApis.packages().install(user, apkBytes());
+ TestApis.packages().install(user, apkBytes());
} catch (NeneException e) {
throw new NeneException("Error while installing TestApp " + this, e);
}
@@ -89,11 +97,20 @@
* Install the {@link TestApp} on the device for the given {@link UserHandle}.
*/
public TestAppInstanceReference install(UserHandle user) {
- install(sTestApis.users().find(user));
+ install(TestApis.users().find(user));
return instance(user);
}
/**
+ * Uninstall the {@link TestApp} on the device from the instrumented user.
+ *
+ * <p>See {@link Users#instrumented()}
+ */
+ public void uninstall() {
+ uninstall(TestApis.users().instrumented());
+ }
+
+ /**
* Uninstall the {@link TestApp} on the device from the given {@link UserReference}.
*/
public void uninstall(UserReference user) {
@@ -104,7 +121,7 @@
* Uninstall the {@link TestApp} on the device from the given {@link UserHandle}.
*/
public void uninstall(UserHandle user) {
- uninstall(sTestApis.users().find(user));
+ uninstall(TestApis.users().find(user));
}
/**
@@ -113,7 +130,7 @@
* <p>This does not check if the user exists, or if the test app is installed on the user.
*/
public TestAppInstanceReference instance(UserHandle user) {
- return instance(sTestApis.users().find(user));
+ return instance(TestApis.users().find(user));
}
/**
diff --git a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivities.java b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivities.java
index 3281a28..5654213 100644
--- a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivities.java
+++ b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivities.java
@@ -30,8 +30,6 @@
*/
public final class TestAppActivities {
- private static final TestApis sTestApis = new TestApis();
-
final TestAppInstanceReference mInstance;
private Set<ActivityInfo> mActivities = null;
@@ -52,7 +50,7 @@
mActivities = new HashSet<>();
- PackageManager p = sTestApis.context().instrumentedContext().getPackageManager();
+ PackageManager p = TestApis.context().instrumentedContext().getPackageManager();
try {
PackageInfo packageInfo = p.getPackageInfo(
mInstance.testApp().packageName(), /* flags= */ PackageManager.GET_ACTIVITIES);
diff --git a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivitiesQueryBuilder.java b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivitiesQueryBuilder.java
index c3131f6..3eb3633 100644
--- a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivitiesQueryBuilder.java
+++ b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivitiesQueryBuilder.java
@@ -30,8 +30,6 @@
*/
public final class TestAppActivitiesQueryBuilder implements Queryable {
- private static final TestApis sTestApis = new TestApis();
-
private final TestAppActivities mTestAppActivities;
private ActivityQueryHelper<TestAppActivitiesQueryBuilder> mActivity =
new ActivityQueryHelper<>(this);
@@ -55,7 +53,7 @@
if (ActivityQueryHelper.matches(mActivity, activity)) {
activityIterator.remove();
return new UnresolvedTestAppActivity(mTestAppActivities.mInstance,
- sTestApis.packages().component(
+ TestApis.packages().component(
new ComponentName(
mTestAppActivities.mInstance.testApp().packageName(),
activity.className())));
diff --git a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivityReference.java b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivityReference.java
index 070e604..1b1140a 100644
--- a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivityReference.java
+++ b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppActivityReference.java
@@ -33,8 +33,6 @@
*/
public abstract class TestAppActivityReference {
- static final TestApis sTestApis = new TestApis();
-
final TestAppInstanceReference mInstance;
final ComponentReference mComponent;
@@ -65,13 +63,13 @@
intent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
try (PermissionContext p =
- sTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
- sTestApis.context().instrumentedContext().startActivity(intent);
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.context().instrumentedContext().startActivity(intent);
}
events().activityStarted().waitForEvent();
- return sTestApis.activities().wrap(
+ return TestApis.activities().wrap(
TestAppActivity.class, new TestAppActivityImpl(mInstance, mComponent));
}
@@ -84,13 +82,13 @@
intent.setComponent(mComponent.componentName());
intent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
try (PermissionContext p =
- sTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
- sTestApis.context().instrumentedContext().startActivity(intent, options);
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.context().instrumentedContext().startActivity(intent, options);
}
events().activityStarted().waitForEvent();
- return sTestApis.activities().wrap(
+ return TestApis.activities().wrap(
TestAppActivity.class, new TestAppActivityImpl(mInstance, mComponent));
}
diff --git a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppBinder.java b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppBinder.java
index 68d12dd..53af98c 100644
--- a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppBinder.java
+++ b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppBinder.java
@@ -36,8 +36,6 @@
private static final String LOG_TAG = TestAppBinder.class.getName();
- private static final TestApis sTestApis = new TestApis();
-
private final TestAppInstanceReference mTestAppInstance;
public TestAppBinder(TestAppInstanceReference testAppInstance) {
@@ -60,7 +58,7 @@
Log.i(LOG_TAG, "Attempting to bind to " + bindIntent);
try (PermissionContext p =
- sTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
return context.bindServiceAsUser(bindIntent,
connection, /* flags= */ BIND_AUTO_CREATE,
mTestAppInstance.user().userHandle());
diff --git a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppInstanceReference.java b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppInstanceReference.java
index d9f087d..a1194c6 100644
--- a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppInstanceReference.java
+++ b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppInstanceReference.java
@@ -59,8 +59,6 @@
*/
public class TestAppInstanceReference implements AutoCloseable, ConnectionListener {
- private static final TestApis sTestApis = new TestApis();
-
private final TestApp mTestApp;
private final UserReference mUser;
private final CrossProfileConnector mConnector;
@@ -79,7 +77,7 @@
}
mTestApp = testApp;
mUser = user;
- mConnector = CrossProfileConnector.builder(sTestApis.context().instrumentedContext())
+ mConnector = CrossProfileConnector.builder(TestApis.context().instrumentedContext())
.setBinder(new TestAppBinder(this))
.build();
mConnector.registerConnectionListener(this);
diff --git a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppProvider.java b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppProvider.java
index 86eaabb..5e7e9de 100644
--- a/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppProvider.java
+++ b/common/device-side/bedstead/testapp/src/library/main/java/com/android/bedstead/testapp/TestAppProvider.java
@@ -32,9 +32,8 @@
private static final String TAG = TestAppProvider.class.getSimpleName();
- private static final TestApis sTestApis = new TestApis();
// Must be instrumentation context to access resources
- private static final Context sContext = sTestApis.context().instrumentationContext();
+ private static final Context sContext = TestApis.context().instrumentationContext();
private boolean mTestAppsInitialised = false;
private final Set<TestAppDetails> mTestApps = new HashSet<>();
diff --git a/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppActivitiesTest.java b/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppActivitiesTest.java
index 175fdba..a4bc029 100644
--- a/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppActivitiesTest.java
+++ b/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppActivitiesTest.java
@@ -39,8 +39,7 @@
@ClassRule @Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
- private static final UserReference sUser = sTestApis.users().instrumented();
+ private static final UserReference sUser = TestApis.users().instrumented();
private static final String EXISTING_ACTIVITY = "android.testapp.activity";
private static final String NON_EXISTING_ACTIVITY = "non.existing.activity";
diff --git a/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppActivityReferenceTest.java b/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppActivityReferenceTest.java
index 72066c2..93276b8 100644
--- a/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppActivityReferenceTest.java
+++ b/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppActivityReferenceTest.java
@@ -36,8 +36,7 @@
@RunWith(BedsteadJUnit4.class)
public class TestAppActivityReferenceTest {
- private static final TestApis sTestApis = new TestApis();
- private static final UserReference sUser = sTestApis.users().instrumented();
+ private static final UserReference sUser = TestApis.users().instrumented();
@ClassRule @Rule
public static final DeviceState sDeviceState = new DeviceState();
@@ -58,7 +57,7 @@
try (TestAppInstanceReference testAppInstance = testApp.install(sUser)) {
Activity<TestAppActivity> activity = testAppInstance.activities().any().start();
- assertThat(sTestApis.activities().foregroundActivity()).isEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isEqualTo(
activity.activity().component());
}
}
diff --git a/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppAppComponentFactoryTest.java b/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppAppComponentFactoryTest.java
index 74743d8..2e21db8 100644
--- a/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppAppComponentFactoryTest.java
+++ b/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppAppComponentFactoryTest.java
@@ -52,9 +52,8 @@
private static final String GENERATED_BROADCAST_RECEIVER_ACTION =
"com.android.testapp.GENERATED_BROADCAST_RECEIVER";
- private static final TestApis sTestApis = new TestApis();
private static final Context sContext =
- sTestApis.context().instrumentedContext();
+ TestApis.context().instrumentedContext();
@Test
public void startActivity_activityDoesNotExist_startsLoggingActivity() {
diff --git a/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppInstanceReferenceTest.java b/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppInstanceReferenceTest.java
index 6617214..2690617 100644
--- a/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppInstanceReferenceTest.java
+++ b/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppInstanceReferenceTest.java
@@ -50,9 +50,8 @@
@ClassRule @Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
- private static final UserReference sUser = sTestApis.users().instrumented();
+ private static final Context sContext = TestApis.context().instrumentedContext();
+ private static final UserReference sUser = TestApis.users().instrumented();
private TestAppProvider mTestAppProvider;
@@ -102,7 +101,7 @@
testAppInstance.uninstall();
- Package pkg = sTestApis.packages().find(testApp.packageName()).resolve();
+ Package pkg = TestApis.packages().find(testApp.packageName()).resolve();
if (pkg != null) {
assertThat(pkg.installedOnUsers()).doesNotContain(sUser);
}
@@ -115,7 +114,7 @@
// Intentionally empty
}
- Package pkg = sTestApis.packages().find(testApp.packageName()).resolve();
+ Package pkg = TestApis.packages().find(testApp.packageName()).resolve();
if (pkg != null) {
assertThat(pkg.installedOnUsers()).doesNotContain(sUser);
}
diff --git a/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppTest.java b/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppTest.java
index c2c29ac..b82a406 100644
--- a/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppTest.java
+++ b/common/device-side/bedstead/testapp/src/test/java/com/android/bedstead/testapp/TestAppTest.java
@@ -36,13 +36,11 @@
@RunWith(JUnit4.class)
public class TestAppTest {
-
- private static final TestApis sTestApis = new TestApis();
- private static final UserReference sUser = sTestApis.users().instrumented();
+ private static final UserReference sUser = TestApis.users().instrumented();
private static final UserHandle sUserHandle = sUser.userHandle();
- private static final UserReference sNonExistingUser = sTestApis.users().find(9999);
+ private static final UserReference sNonExistingUser = TestApis.users().find(9999);
private static final UserHandle sNonExistingUserHandle = sNonExistingUser.userHandle();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private TestAppProvider mTestAppProvider;
@@ -55,7 +53,7 @@
public void reference_returnsNeneReference() {
TestApp testApp = mTestAppProvider.any();
- assertThat(testApp.reference()).isEqualTo(sTestApis.packages().find(testApp.packageName()));
+ assertThat(testApp.reference()).isEqualTo(TestApis.packages().find(testApp.packageName()));
}
@Test
@@ -73,6 +71,19 @@
}
@Test
+ public void install_noUserSpecified_installsInInstrumentedUser() {
+ TestApp testApp = mTestAppProvider.any();
+
+ testApp.install();
+
+ try {
+ assertThat(testApp.resolve().installedOnUsers()).contains(sUser);
+ } finally {
+ testApp.uninstall(sUser);
+ }
+ }
+
+ @Test
public void install_userReference_installs() {
TestApp testApp = mTestAppProvider.any();
@@ -239,6 +250,19 @@
}
@Test
+ public void uninstall_noUserSpecified_uninstallsFromInstrumentedUser() {
+ TestApp testApp = mTestAppProvider.any();
+ testApp.install(sUser);
+
+ testApp.uninstall();
+
+ Package testAppPackage = testApp.reference().resolve();
+ if (testAppPackage != null) {
+ assertThat(testAppPackage.installedOnUsers()).doesNotContain(sUser);
+ }
+ }
+
+ @Test
public void uninstall_userHandle_uninstalls() {
TestApp testApp = mTestAppProvider.any();
testApp.install(sUser);
diff --git a/hostsidetests/packagemanager/domainverification/device/multiuser/src/com/android/cts/packagemanager/verify/domain/device/multiuser/DomainVerificationWorkProfileTestsBase.kt b/hostsidetests/packagemanager/domainverification/device/multiuser/src/com/android/cts/packagemanager/verify/domain/device/multiuser/DomainVerificationWorkProfileTestsBase.kt
index 7fd0319..dff94b8 100644
--- a/hostsidetests/packagemanager/domainverification/device/multiuser/src/com/android/cts/packagemanager/verify/domain/device/multiuser/DomainVerificationWorkProfileTestsBase.kt
+++ b/hostsidetests/packagemanager/domainverification/device/multiuser/src/com/android/cts/packagemanager/verify/domain/device/multiuser/DomainVerificationWorkProfileTestsBase.kt
@@ -64,7 +64,6 @@
@Rule
val deviceState = DeviceState()
- private val testApis = TestApis()
private val TARGET_INTENT = Intent(Intent.ACTION_VIEW, Uri.parse("https://$DOMAIN_1"))
private val BROWSER_INTENT =
Intent(Intent.ACTION_VIEW, Uri.parse("https://$DOMAIN_UNHANDLED"))
@@ -105,7 +104,7 @@
workUser = deviceState.workProfile(DeviceState.UserType.PRIMARY_USER)
personalBrowsers = collectBrowsers(personalUser)
workBrowsers = collectBrowsers(workUser)
- testApis.packages().run {
+ TestApis.packages().run {
install(personalUser, Packages.JavaResource.javaResource(DECLARING_PKG_APK_1.value))
install(workUser, Packages.JavaResource.javaResource(DECLARING_PKG_APK_2.value))
}
@@ -114,14 +113,14 @@
@JvmStatic
@AfterClass
fun uninstallApks() {
- testApis.packages().run {
+ TestApis.packages().run {
find(PERSONAL_APP).uninstallFromAllUsers()
find(WORK_APP).uninstallFromAllUsers()
}
}
private fun collectBrowsers(user: UserReference) =
- testApis.withUserContext(user) { context ->
+ withUserContext(user) { context ->
context.packageManager
.queryIntentActivities(BROWSER_INTENT, PackageManager.MATCH_DEFAULT_ONLY)
.map { it.activityInfo }
@@ -135,7 +134,7 @@
@JvmStatic
protected fun assertResolvesTo(components: Collection<ComponentName>) {
- val results = testApis.context()
+ val results = TestApis.context()
.instrumentedContext()
.packageManager
.queryIntentActivities(TARGET_INTENT, PackageManager.MATCH_DEFAULT_ONLY)
@@ -156,7 +155,7 @@
@After
fun resetState() {
listOf(personalUser, workUser).forEach {
- testApis.withUserContext(it) {
+ withUserContext(it) {
SharedVerifications.reset(it, resetEnable = true)
}
}
diff --git a/hostsidetests/packagemanager/domainverification/device/multiuser/src/com/android/cts/packagemanager/verify/domain/device/multiuser/DomainVerificationWorkUtils.kt b/hostsidetests/packagemanager/domainverification/device/multiuser/src/com/android/cts/packagemanager/verify/domain/device/multiuser/DomainVerificationWorkUtils.kt
index 2719b85..3038849 100644
--- a/hostsidetests/packagemanager/domainverification/device/multiuser/src/com/android/cts/packagemanager/verify/domain/device/multiuser/DomainVerificationWorkUtils.kt
+++ b/hostsidetests/packagemanager/domainverification/device/multiuser/src/com/android/cts/packagemanager/verify/domain/device/multiuser/DomainVerificationWorkUtils.kt
@@ -40,7 +40,7 @@
profileOwner(workProfile(DeviceState.UserType.PRIMARY_USER))!!
.app().devicePolicyManager()
-internal fun <T> TestApis.withUserContext(user: UserReference, block: (context: Context) -> T) =
- permissions()
+internal fun <T> withUserContext(user: UserReference, block: (context: Context) -> T) =
+ TestApis.permissions()
.withPermission("android.permission.INTERACT_ACROSS_USERS_FULL")
- .use { block(context().androidContextAsUser(user)) }
+ .use { block(TestApis.context().androidContextAsUser(user)) }
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/AccountManagementTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/AccountManagementTest.java
index ffc7a84..6111003 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/AccountManagementTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/AccountManagementTest.java
@@ -18,6 +18,8 @@
import static org.junit.Assert.assertThrows;
+import static com.google.common.truth.Truth.assertThat;
+
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
@@ -41,8 +43,6 @@
import com.android.bedstead.testapp.TestAppInstanceReference;
import com.android.bedstead.testapp.TestAppProvider;
-import static com.google.common.truth.Truth.*;
-
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
@@ -58,8 +58,7 @@
@Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final TestAppProvider sTestAppProvider = new TestAppProvider();
private static final TestApp sAccountManagementApp = sTestAppProvider
.query()
@@ -158,8 +157,7 @@
@CanSetPolicyTest(policy = AccountManagement.class)
public void addAccount_fromDpcWithAccountManagementDisabled_accountAdded()
throws OperationCanceledException, AuthenticatorException, IOException {
- try (TestAppInstanceReference accountAuthenticatorApp =
- sAccountManagementApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference accountAuthenticatorApp = sAccountManagementApp.install()) {
mDpm.setAccountManagementDisabled(mAdmin, EXISTING_ACCOUNT_TYPE, /* disabled= */ true);
// Management is disabled, but the DO/PO is still allowed to use the APIs
@@ -182,8 +180,7 @@
@CanSetPolicyTest(policy = AccountManagement.class)
public void addAccount_fromDpcWithDisallowModifyAccountsRestriction_accountAdded()
throws OperationCanceledException, AuthenticatorException, IOException {
- try (TestAppInstanceReference accountAuthenticatorApp =
- sAccountManagementApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference accountAuthenticatorApp = sAccountManagementApp.install()) {
mDpm.addUserRestriction(mAdmin, UserManager.DISALLOW_MODIFY_ACCOUNTS);
// Management is disabled, but the DO/PO is still allowed to use the APIs
@@ -206,8 +203,7 @@
@CanSetPolicyTest(policy = AccountManagement.class)
public void removeAccount_fromDpcWithDisallowModifyAccountsRestriction_accountRemoved()
throws OperationCanceledException, AuthenticatorException, IOException {
- try (TestAppInstanceReference accountAuthenticatorApp =
- sAccountManagementApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference accountAuthenticatorApp = sAccountManagementApp.install()) {
mDpm.addUserRestriction(mAdmin, UserManager.DISALLOW_MODIFY_ACCOUNTS);
// Management is disabled, but the DO/PO is still allowed to use the APIs
@@ -227,8 +223,7 @@
@CanSetPolicyTest(policy = AccountManagement.class)
public void addAccount_withDisallowModifyAccountsRestriction_throwsException()
throws OperationCanceledException, AuthenticatorException, IOException {
- try (TestAppInstanceReference accountAuthenticatorApp =
- sAccountManagementApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference accountAuthenticatorApp = sAccountManagementApp.install()) {
mDpm.addUserRestriction(mAdmin, UserManager.DISALLOW_MODIFY_ACCOUNTS);
assertThrows(OperationCanceledException.class, () ->
@@ -244,8 +239,7 @@
public void removeAccount_withDisallowModifyAccountsRestriction_throwsException()
throws OperationCanceledException, AuthenticatorException, IOException,
InterruptedException {
- try (TestAppInstanceReference accountAuthenticatorApp =
- sAccountManagementApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference accountAuthenticatorApp = sAccountManagementApp.install()) {
addAccountWithType(EXISTING_ACCOUNT_TYPE);
mDpm.addUserRestriction(mAdmin, UserManager.DISALLOW_MODIFY_ACCOUNTS);
@@ -262,8 +256,7 @@
@CanSetPolicyTest(policy = AccountManagement.class)
public void addAccount_withAccountManagementDisabled_throwsException()
throws OperationCanceledException, AuthenticatorException, IOException {
- try (TestAppInstanceReference accountAuthenticatorApp =
- sAccountManagementApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference accountAuthenticatorApp = sAccountManagementApp.install()) {
mDpm.setAccountManagementDisabled(mAdmin, EXISTING_ACCOUNT_TYPE, /* disabled= */ true);
assertThrows(OperationCanceledException.class, () ->
@@ -279,8 +272,7 @@
public void removeAccount_withAccountManagementDisabled_throwsException()
throws OperationCanceledException, AuthenticatorException, IOException,
InterruptedException {
- try (TestAppInstanceReference accountAuthenticatorApp =
- sAccountManagementApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference accountAuthenticatorApp = sAccountManagementApp.install()) {
addAccountWithType(EXISTING_ACCOUNT_TYPE);
mDpm.setAccountManagementDisabled(mAdmin, EXISTING_ACCOUNT_TYPE, /* disabled= */ true);
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/ApplicationRestrictionsTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/ApplicationRestrictionsTest.java
index 609227b..6685e5f 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/ApplicationRestrictionsTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/ApplicationRestrictionsTest.java
@@ -31,7 +31,6 @@
import com.android.bedstead.harrier.annotations.enterprise.NegativePolicyTest;
import com.android.bedstead.harrier.annotations.enterprise.PositivePolicyTest;
import com.android.bedstead.harrier.policies.ApplicationRestrictions;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.testapp.TestApp;
import com.android.bedstead.testapp.TestAppInstanceReference;
import com.android.bedstead.testapp.TestAppProvider;
@@ -62,7 +61,6 @@
public static final DeviceState sDeviceState = new DeviceState();
private static final TestAppProvider sTestAppProvider = new TestAppProvider();
- private static final TestApis sTestApis = new TestApis();
private static final TestApp sTestApp = sTestAppProvider.any();
private static final TestApp sDifferentTestApp = sTestAppProvider.any();
@@ -76,8 +74,7 @@
.getApplicationRestrictions(
sDeviceState.dpc().componentName(), sTestApp.packageName());
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
sDeviceState.dpc().devicePolicyManager()
.setApplicationRestrictions(
sDeviceState.dpc().componentName(), sTestApp.packageName(),
@@ -126,8 +123,7 @@
.getApplicationRestrictions(
sDeviceState.dpc().componentName(), sTestApp.packageName());
- try (TestAppInstanceReference differentTestApp =
- sDifferentTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference differentTestApp = sDifferentTestApp.install()) {
sDeviceState.dpc().devicePolicyManager()
.setApplicationRestrictions(
sDeviceState.dpc().componentName(), sTestApp.packageName(),
@@ -152,8 +148,7 @@
.getApplicationRestrictions(
sDeviceState.dpc().componentName(), sTestApp.packageName());
- try (TestAppInstanceReference differentTestApp =
- sDifferentTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference differentTestApp = sDifferentTestApp.install()) {
sDeviceState.dpc().devicePolicyManager()
.setApplicationRestrictions(
sDeviceState.dpc().componentName(), sTestApp.packageName(),
@@ -176,8 +171,7 @@
sDeviceState.dpc().devicePolicyManager().getApplicationRestrictions(
sDeviceState.dpc().componentName(), sTestApp.packageName());
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
sDeviceState.dpc().devicePolicyManager()
.setApplicationRestrictions(
sDeviceState.dpc().componentName(), sTestApp.packageName(),
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/CreateAndManageUserTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/CreateAndManageUserTest.java
index 59d1ac0..b329718 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/CreateAndManageUserTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/CreateAndManageUserTest.java
@@ -47,8 +47,6 @@
private static final String TAG = "CreateAndManageUserTest";
- private static final TestApis sTestApis = new TestApis();
-
@ClassRule
@Rule
public static final DeviceState sDeviceState = new DeviceState();
@@ -72,8 +70,8 @@
@CanSetPolicyTest(policy = CreateAndManageUser.class)
public void createAndManageUser_lowStorage_throwOperationException() {
try {
- sTestApis.settings().global().putInt(SYS_STORAGE_THRESHOLD_PERCENTAGE, 100);
- sTestApis.settings().global().putString(SYS_STORAGE_THRESHOLD_MAX_BYTES,
+ TestApis.settings().global().putInt(SYS_STORAGE_THRESHOLD_PERCENTAGE, 100);
+ TestApis.settings().global().putString(SYS_STORAGE_THRESHOLD_MAX_BYTES,
String.valueOf(Long.MAX_VALUE));
UserManager.UserOperationException e = expectThrows(
@@ -81,7 +79,7 @@
assertThat(e.getUserOperationResult()).isEqualTo(USER_OPERATION_ERROR_LOW_STORAGE);
} finally {
- sTestApis.settings().global().reset();
+ TestApis.settings().global().reset();
}
}
@@ -98,7 +96,7 @@
private void removeUser(UserHandle userHandle) {
if (userHandle != null) {
- sTestApis.users().find(userHandle).remove();
+ TestApis.users().find(userHandle).remove();
}
}
}
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/CredentialManagementAppTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/CredentialManagementAppTest.java
index f9d4d78..40b8e63 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/CredentialManagementAppTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/CredentialManagementAppTest.java
@@ -75,7 +75,6 @@
private static final Certificate CERTIFICATE =
getCertificate(FakeKeys.FAKE_RSA_1.caCertificate);
private static final Certificate[] CERTIFICATES = new Certificate[]{CERTIFICATE};
- private static final TestApis sTestApis = new TestApis();
private static final Context CONTEXT = ApplicationProvider.getApplicationContext();
private static final String MANAGE_CREDENTIALS = "android:manage_credentials";
@@ -325,7 +324,7 @@
// TODO (b/174677062): Move this into infrastructure
private void setCredentialManagementApp() throws Exception {
- try (PermissionContext p = sTestApis.permissions().withPermission(
+ try (PermissionContext p = TestApis.permissions().withPermission(
MANAGE_CREDENTIAL_MANAGEMENT_APP_PERMISSION)){
assertTrue("Unable to set credential management app",
KeyChain.setCredentialManagementApp(CONTEXT, PACKAGE_NAME,
@@ -339,7 +338,7 @@
// TODO (b/174677062): Move this into infrastructure
private void removeCredentialManagementApp() throws Exception {
- try (PermissionContext p = sTestApis.permissions().withPermission(
+ try (PermissionContext p = TestApis.permissions().withPermission(
MANAGE_CREDENTIAL_MANAGEMENT_APP_PERMISSION)){
assertTrue("Unable to remove credential management app",
KeyChain.removeCredentialManagementApp(CONTEXT));
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/CrossProfileSharingTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/CrossProfileSharingTest.java
index e166831..8586d26 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/CrossProfileSharingTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/CrossProfileSharingTest.java
@@ -61,8 +61,7 @@
@Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final TestAppProvider sTestAppProvider = new TestAppProvider();
// TODO(b/198420874): rather than querying by package name, query apps by intents they need to
@@ -204,7 +203,7 @@
}
private ResolveInfo getCrossProfileIntentForwarder(Intent intent) {
- List<ResolveInfo> result = sTestApis.context().instrumentedContext().getPackageManager()
+ List<ResolveInfo> result = TestApis.context().instrumentedContext().getPackageManager()
.queryIntentActivities(intent, MATCH_DEFAULT_ONLY);
assertWithMessage("Failed to get intent forwarder component")
.that(result.size()).isEqualTo(1);
@@ -217,9 +216,9 @@
private void setSharingIntoProfileEnabled(boolean enabled) {
RemoteDpc remoteDpc = sDeviceState.profileOwner(WORK_PROFILE);
IntentFilter filter = new IntentFilter(ACTION_DATA_SHARING_RESTRICTION_APPLIED);
- Context remoteCtx = sTestApis.context().androidContextAsUser(remoteDpc.user());
+ Context remoteCtx = TestApis.context().androidContextAsUser(remoteDpc.user());
try (PermissionContext permissionContext =
- sTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL);
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL);
BlockingBroadcastReceiver receiver =
BlockingBroadcastReceiver.create(remoteCtx, filter).register()) {
if (enabled) {
@@ -235,7 +234,7 @@
private void assertCrossProfileIntentsResolvability(
Intent[] intents, ResolveInfo expectedForwarder, boolean expectForwardable) {
for (Intent intent : intents) {
- List<ResolveInfo> resolveInfoList = sTestApis.context().instrumentedContext()
+ List<ResolveInfo> resolveInfoList = TestApis.context().instrumentedContext()
.getPackageManager().queryIntentActivities(intent, MATCH_DEFAULT_ONLY);
if (expectForwardable) {
assertWithMessage(String.format(
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/DefaultSmsApplicationTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/DefaultSmsApplicationTest.java
index e2c8aac..227ea18 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/DefaultSmsApplicationTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/DefaultSmsApplicationTest.java
@@ -55,8 +55,7 @@
@Rule
public static DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final TestAppProvider sTestAppProvider = new TestAppProvider();
private static final TestApp sSmsApp = sTestAppProvider
.query()
@@ -85,8 +84,7 @@
public void setDefaultSmsApplication_works() {
assumeTrue(mTelephonyManager.isSmsCapable());
String previousSmsAppName = getDefaultSmsPackage();
- try (TestAppInstanceReference smsApp =
- sSmsApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference smsApp = sSmsApp.install()) {
mDpm.setDefaultSmsApplication(mAdmin, smsApp.testApp().packageName());
assertThat(getDefaultSmsPackage()).isEqualTo(smsApp.testApp().packageName());
@@ -102,8 +100,7 @@
public void setDefaultSmsApplication_unchanged() {
assumeTrue(mTelephonyManager.isSmsCapable());
String previousSmsAppName = getDefaultSmsPackage();
- try (TestAppInstanceReference smsApp =
- sSmsApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference smsApp = sSmsApp.install()) {
mDpm.setDefaultSmsApplication(mAdmin, smsApp.testApp().packageName());
assertThat(getDefaultSmsPackage()).isEqualTo(previousSmsAppName);
@@ -133,8 +130,7 @@
@Postsubmit(reason = "new test")
@CanSetPolicyTest(policy = DefaultSmsApplication.class)
public void setDefaultSmsApplication_nullAdmin_throwsException() {
- try (TestAppInstanceReference smsApp =
- sSmsApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference smsApp = sSmsApp.install()) {
assertThrows(NullPointerException.class, () ->
mDpm.setDefaultSmsApplication(
@@ -149,8 +145,7 @@
public void setDefaultSmsApplication_notSmsCapable_unchanged() {
assumeTrue(!mTelephonyManager.isSmsCapable());
String previousSmsAppName = getDefaultSmsPackage();
- try (TestAppInstanceReference smsApp =
- sSmsApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference smsApp = sSmsApp.install()) {
mDpm.setDefaultSmsApplication(mAdmin, smsApp.testApp().packageName());
assertThat(getDefaultSmsPackage()).isEqualTo(previousSmsAppName);
@@ -163,8 +158,7 @@
@Postsubmit(reason = "new test")
@CannotSetPolicyTest(policy = DefaultSmsApplication.class)
public void setDefaultSmsApplication_invalidAdmin_throwsException() {
- try (TestAppInstanceReference smsApp =
- sSmsApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference smsApp = sSmsApp.install()) {
assertThrows(SecurityException.class, () ->
mDpm.setDefaultSmsApplication(mAdmin, smsApp.testApp().packageName()));
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/DevicePolicyManagerTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/DevicePolicyManagerTest.java
index 0d44133..98e193e 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/DevicePolicyManagerTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/DevicePolicyManagerTest.java
@@ -75,7 +75,6 @@
private static final UserManager sUserManager = sContext.getSystemService(UserManager.class);
private static final SharedPreferences sSharedPreferences =
sContext.getSharedPreferences("required-apps.txt", Context.MODE_PRIVATE);
- private static final TestApis sTestApis = new TestApis();
private static final ComponentName DEVICE_ADMIN_COMPONENT_NAME =
DeviceAdminApp.deviceAdminComponentName(sContext);
@@ -124,7 +123,7 @@
assertThat(profile).isNotNull();
} finally {
if (profile != null) {
- sTestApis.users().find(profile).remove();
+ TestApis.users().find(profile).remove();
}
}
}
@@ -145,7 +144,7 @@
assertThat(sUserManager.isManagedProfile(profile.getIdentifier())).isTrue();
} finally {
if (profile != null) {
- sTestApis.users().find(profile).remove();
+ TestApis.users().find(profile).remove();
}
}
}
@@ -168,7 +167,7 @@
.isEqualTo(DEVICE_ADMIN_COMPONENT_NAME);
} finally {
if (profile != null) {
- sTestApis.users().find(profile).remove();
+ TestApis.users().find(profile).remove();
}
}
}
@@ -190,7 +189,7 @@
assertThat(profileDpm.isProfileOwnerApp(sContext.getPackageName())).isTrue();
} finally {
if (profile != null) {
- sTestApis.users().find(profile).remove();
+ TestApis.users().find(profile).remove();
}
}
}
@@ -215,7 +214,7 @@
assertThat(hasTestAccount(profile)).isTrue();
} finally {
if (profile != null) {
- sTestApis.users().find(profile).remove();
+ TestApis.users().find(profile).remove();
}
}
}
@@ -240,7 +239,7 @@
assertThat(hasTestAccount(sContext.getUser())).isFalse();
} finally {
if (profile != null) {
- sTestApis.users().find(profile).remove();
+ TestApis.users().find(profile).remove();
}
}
}
@@ -266,7 +265,7 @@
assertThat(hasTestAccount(sContext.getUser())).isTrue();
} finally {
if (profile != null) {
- sTestApis.users().find(profile).remove();
+ TestApis.users().find(profile).remove();
}
}
}
@@ -292,7 +291,7 @@
assertThat(getInstalledPackagesOnUser(nonRequiredApps, profile)).isEmpty();
} finally {
if (profile != null) {
- sTestApis.users().find(profile).remove();
+ TestApis.users().find(profile).remove();
}
}
}
@@ -317,7 +316,7 @@
}
} finally {
if (profile != null) {
- sTestApis.users().find(profile).remove();
+ TestApis.users().find(profile).remove();
}
}
}
@@ -382,11 +381,11 @@
}
private boolean isPackageInstalledOnUser(String packageName, UserHandle user) {
- Package resolvedPackage = sTestApis.packages().find(packageName).resolve();
+ Package resolvedPackage = TestApis.packages().find(packageName).resolve();
if (resolvedPackage == null) {
return false;
}
- return resolvedPackage.installedOnUsers().contains(sTestApis.users().find(user));
+ return resolvedPackage.installedOnUsers().contains(TestApis.users().find(user));
}
private Set<String> getConfigurableDefaultCrossProfilePackages() {
@@ -406,7 +405,7 @@
return sContext;
}
try (PermissionContext p =
- sTestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
+ TestApis.permissions().withPermission(INTERACT_ACROSS_USERS_FULL)) {
return sContext.createContextAsUser(user, /* flags= */ 0);
}
}
@@ -540,14 +539,14 @@
}
private void resetUserSetupCompletedFlag() {
- try (PermissionContext p = sTestApis.permissions().withPermission(WRITE_SECURE_SETTINGS)) {
+ try (PermissionContext p = TestApis.permissions().withPermission(WRITE_SECURE_SETTINGS)) {
Settings.Secure.putInt(sContext.getContentResolver(), USER_SETUP_COMPLETE_KEY, 0);
}
sDevicePolicyManager.forceUpdateUserSetupComplete(sContext.getUserId());
}
private void setUserSetupCompletedFlag() {
- try (PermissionContext p = sTestApis.permissions().withPermission(WRITE_SECURE_SETTINGS)) {
+ try (PermissionContext p = TestApis.permissions().withPermission(WRITE_SECURE_SETTINGS)) {
Settings.Secure.putInt(sContext.getContentResolver(), USER_SETUP_COMPLETE_KEY, 1);
}
sDevicePolicyManager.forceUpdateUserSetupComplete(sContext.getUserId());
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/EnrollmentSpecificIdTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/EnrollmentSpecificIdTest.java
index 8ef673f..7242892 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/EnrollmentSpecificIdTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/EnrollmentSpecificIdTest.java
@@ -36,7 +36,6 @@
import com.android.bedstead.harrier.annotations.enterprise.PositivePolicyTest;
import com.android.bedstead.harrier.policies.EnrollmentSpecificId;
import com.android.bedstead.nene.TestApis;
-import com.android.bedstead.testapp.TestAppProvider;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -60,9 +59,7 @@
@Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestAppProvider sTestAppProvider = new TestAppProvider();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
@Test
@Postsubmit(reason = "New test")
@@ -83,7 +80,7 @@
() -> sDeviceState.dpc().devicePolicyManager()
.setOrganizationId(DIFFERENT_ORGANIZATION_ID));
} finally {
- sTestApis.devicePolicy().clearOrganizationId(sDeviceState.dpc().user());
+ TestApis.devicePolicy().clearOrganizationId(sDeviceState.dpc().user());
}
}
@@ -106,7 +103,7 @@
assertThat(esidFromDpm).isEqualTo(calculatedEsid);
} finally {
- sTestApis.devicePolicy().clearOrganizationId(sDeviceState.dpc().user());
+ TestApis.devicePolicy().clearOrganizationId(sDeviceState.dpc().user());
}
}
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/LockTaskTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/LockTaskTest.java
index c2f3402..6af921e 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/LockTaskTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/LockTaskTest.java
@@ -87,10 +87,8 @@
@ClassRule @Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
-
private static final DevicePolicyManager sLocalDevicePolicyManager =
- sTestApis.context().instrumentedContext().getSystemService(DevicePolicyManager.class);
+ TestApis.context().instrumentedContext().getSystemService(DevicePolicyManager.class);
private static final int[] INDIVIDUALLY_SETTABLE_FLAGS = new int[] {
LOCK_TASK_FEATURE_SYSTEM_INFO,
@@ -118,7 +116,7 @@
sTestAppProvider.query().whereActivities().isNotEmpty().get();
private static final ComponentReference BLOCKED_ACTIVITY_COMPONENT =
- sTestApis.packages().component(new ComponentName(
+ TestApis.packages().component(new ComponentName(
"android", "com.android.internal.app.BlockedAppActivity"));
private static final String ACTION_EMERGENCY_DIAL = "com.android.phone.EmergencyDialer.DIAL";
@@ -153,7 +151,7 @@
.getLockTaskPackages(DPC_COMPONENT_NAME);
try (EnterpriseMetricsRecorder metrics = EnterpriseMetricsRecorder.create();
- TestAppInstanceReference testApp = sTestApp.install(sTestApis.users().instrumented())){
+ TestAppInstanceReference testApp = sTestApp.install()) {
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
Activity<TestAppActivity> activity = testApp.activities().any().start();
@@ -210,7 +208,7 @@
@PositivePolicyTest(policy = LockTask.class)
@Postsubmit(reason = "b/181993922 automatically marked flaky")
public void setLockTaskPackages_includesPolicyExemptApp_lockTaskPackagesIsSet() {
- Set<String> policyExemptApps = sTestApis.devicePolicy().getPolicyExemptApps();
+ Set<String> policyExemptApps = TestApis.devicePolicy().getPolicyExemptApps();
assumeFalse("OEM does not define any policy-exempt apps",
policyExemptApps.isEmpty());
String[] originalLockTaskPackages =
@@ -300,7 +298,7 @@
@PositivePolicyTest(policy = LockTask.class)
@Postsubmit(reason = "b/181993922 automatically marked flaky")
public void isLockTaskPermitted_includesPolicyExemptApps() {
- Set<String> policyExemptApps = sTestApis.devicePolicy().getPolicyExemptApps();
+ Set<String> policyExemptApps = TestApis.devicePolicy().getPolicyExemptApps();
// TODO(b/188035301): Add a unit test which ensures this actually gets tested
assumeFalse("OEM does not define any policy-exempt apps",
policyExemptApps.isEmpty());
@@ -436,16 +434,15 @@
.getLockTaskPackages(DPC_COMPONENT_NAME);
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
Activity<TestAppActivity> activity = testApp.activities().any().start();
activity.startLockTask();
try {
- assertThat(sTestApis.activities().foregroundActivity()).isEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isEqualTo(
activity.activity().component());
- assertThat(sTestApis.activities().getLockTaskModeState()).isEqualTo(
+ assertThat(TestApis.activities().getLockTaskModeState()).isEqualTo(
LOCK_TASK_MODE_LOCKED);
} finally {
activity.stopLockTask();
@@ -465,16 +462,15 @@
.getLockTaskPackages(DPC_COMPONENT_NAME);
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{});
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
Activity<TestAppActivity> activity = testApp.activities().any().start();
activity.activity().startLockTask();
try {
- assertThat(sTestApis.activities().foregroundActivity()).isEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isEqualTo(
activity.activity().component());
- assertThat(sTestApis.activities().getLockTaskModeState()).isNotEqualTo(
+ assertThat(TestApis.activities().getLockTaskModeState()).isNotEqualTo(
LOCK_TASK_MODE_LOCKED);
} finally {
activity.stopLockTask();
@@ -493,16 +489,15 @@
.getLockTaskPackages(DPC_COMPONENT_NAME);
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
Activity<TestAppActivity> activity = testApp.activities().any().start();
activity.activity().startLockTask();
try {
- assertThat(sTestApis.activities().foregroundActivity()).isEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isEqualTo(
activity.activity().component());
- assertThat(sTestApis.activities().getLockTaskModeState()).isNotEqualTo(
+ assertThat(TestApis.activities().getLockTaskModeState()).isNotEqualTo(
LOCK_TASK_MODE_LOCKED);
} finally {
activity.stopLockTask();
@@ -522,8 +517,7 @@
.getLockTaskPackages(DPC_COMPONENT_NAME);
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
Activity<TestAppActivity> activity = testApp.activities().any().start();
activity.startLockTask();
@@ -532,9 +526,9 @@
try {
// We don't actually watch for the Destroyed event because that'd be waiting for a
// non occurrence of an event which is slow
- assertThat(sTestApis.activities().foregroundActivity()).isEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isEqualTo(
activity.activity().component());
- assertThat(sTestApis.activities().getLockTaskModeState()).isEqualTo(
+ assertThat(TestApis.activities().getLockTaskModeState()).isEqualTo(
LOCK_TASK_MODE_LOCKED);
} finally {
activity.stopLockTask();
@@ -554,8 +548,7 @@
.getLockTaskPackages(DPC_COMPONENT_NAME);
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
Activity<TestAppActivity> activity = testApp.activities().any().start();
activity.startLockTask();
activity.stopLockTask();
@@ -563,7 +556,7 @@
activity.activity().finish();
assertThat(activity.activity().events().activityDestroyed()).eventOccurred();
- assertThat(sTestApis.activities().foregroundActivity()).isNotEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isNotEqualTo(
activity.activity().component());
} finally {
sDeviceState.dpc().devicePolicyManager()
@@ -580,8 +573,7 @@
.getLockTaskPackages(DPC_COMPONENT_NAME);
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
Activity<TestAppActivity> activity = testApp.activities().any().start();
activity.startLockTask();
@@ -589,7 +581,7 @@
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{});
assertThat(activity.activity().events().activityDestroyed()).eventOccurred();
- assertThat(sTestApis.activities().foregroundActivity()).isNotEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isNotEqualTo(
activity.activity().component());
} finally {
sDeviceState.dpc().devicePolicyManager()
@@ -606,10 +598,8 @@
.getLockTaskPackages(DPC_COMPONENT_NAME);
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName(), sSecondTestApp.packageName()});
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented());
- TestAppInstanceReference testApp2 =
- sSecondTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install();
+ TestAppInstanceReference testApp2 = sSecondTestApp.install()) {
Activity<TestAppActivity> activity = testApp.activities().any().start();
activity.startLockTask();
Activity<TestAppActivity> activity2 = testApp2.activities().any().start();
@@ -620,9 +610,9 @@
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
assertThat(activity2.activity().events().activityDestroyed()).eventOccurred();
- assertThat(sTestApis.activities().getLockTaskModeState()).isEqualTo(
+ assertThat(TestApis.activities().getLockTaskModeState()).isEqualTo(
LOCK_TASK_MODE_LOCKED);
- assertThat(sTestApis.activities().foregroundActivity()).isEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isEqualTo(
activity.activity().component());
} finally {
activity.stopLockTask();
@@ -640,10 +630,8 @@
String[] originalLockTaskPackages =
sDeviceState.dpc().devicePolicyManager()
.getLockTaskPackages(DPC_COMPONENT_NAME);
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented());
- TestAppInstanceReference testApp2 =
- sSecondTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install();
+ TestAppInstanceReference testApp2 = sSecondTestApp.install()) {
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
Activity<TestAppActivity> firstActivity = testApp.activities().any().start();
@@ -656,7 +644,8 @@
firstActivity.startActivity(secondActivityIntent);
assertThat(secondActivity.events().activityStarted()).eventOccurred();
- assertThat(sTestApis.activities().foregroundActivity()).isEqualTo(secondActivity.component());
+ assertThat(TestApis.activities().foregroundActivity())
+ .isEqualTo(secondActivity.component());
} finally {
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, originalLockTaskPackages);
@@ -673,10 +662,8 @@
int originalLockTaskFeatures =
sDeviceState.dpc().devicePolicyManager()
.getLockTaskFeatures(DPC_COMPONENT_NAME);
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented());
- TestAppInstanceReference testApp2 =
- sSecondTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install();
+ TestAppInstanceReference testApp2 = sSecondTestApp.install()) {
try {
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
@@ -691,7 +678,7 @@
firstActivity.activity().startActivity(secondActivityIntent);
- assertThat(sTestApis.activities().foregroundActivity())
+ assertThat(TestApis.activities().foregroundActivity())
.isEqualTo(BLOCKED_ACTIVITY_COMPONENT);
} finally {
sDeviceState.dpc().devicePolicyManager()
@@ -712,10 +699,8 @@
int originalLockTaskFeatures =
sDeviceState.dpc().devicePolicyManager()
.getLockTaskFeatures(DPC_COMPONENT_NAME);
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented());
- TestAppInstanceReference testApp2 =
- sSecondTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install();
+ TestAppInstanceReference testApp2 = sSecondTestApp.install()) {
try {
sDeviceState.dpc().devicePolicyManager()
.setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
@@ -731,7 +716,7 @@
firstActivity.activity().startActivity(secondActivityIntent);
- assertThat(sTestApis.activities().foregroundActivity())
+ assertThat(TestApis.activities().foregroundActivity())
.isEqualTo(BLOCKED_ACTIVITY_COMPONENT);
} finally {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, originalLockTaskPackages);
@@ -748,10 +733,8 @@
String[] originalLockTaskPackages =
sDeviceState.dpc().devicePolicyManager().getLockTaskPackages(DPC_COMPONENT_NAME);
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented());
- TestAppInstanceReference testApp2 =
- sSecondTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install();
+ TestAppInstanceReference testApp2 = sSecondTestApp.install()) {
try {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName(), sSecondTestApp.packageName()});
Activity<TestAppActivity> firstActivity = testApp.activities().any().start();
@@ -763,7 +746,7 @@
firstActivity.startActivity(secondActivityIntent);
- assertThat(sTestApis.activities().foregroundActivity())
+ assertThat(TestApis.activities().foregroundActivity())
.isEqualTo(secondActivity.component());
} finally {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, originalLockTaskPackages);
@@ -778,10 +761,8 @@
String[] originalLockTaskPackages =
sDeviceState.dpc().devicePolicyManager().getLockTaskPackages(DPC_COMPONENT_NAME);
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented());
- TestAppInstanceReference testApp2 =
- sSecondTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install();
+ TestAppInstanceReference testApp2 = sSecondTestApp.install()) {
try {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
Activity<TestAppActivity> firstActivity = testApp.activities().any().start();
@@ -793,7 +774,7 @@
firstActivity.activity().startActivity(secondActivityIntent);
- assertThat(sTestApis.activities().foregroundActivity())
+ assertThat(TestApis.activities().foregroundActivity())
.isEqualTo(firstActivity.activity().component());
} finally {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, originalLockTaskPackages);
@@ -808,17 +789,16 @@
String[] originalLockTaskPackages =
sDeviceState.dpc().devicePolicyManager().getLockTaskPackages(DPC_COMPONENT_NAME);
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
try {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sTestApp.packageName()});
Bundle options = ActivityOptions.makeBasic().setLockTaskEnabled(true).toBundle();
Activity<TestAppActivity> activity = testApp.activities().any().start(options);
try {
- assertThat(sTestApis.activities().foregroundActivity()).isEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isEqualTo(
activity.activity().component());
- assertThat(sTestApis.activities().getLockTaskModeState()).isEqualTo(
+ assertThat(TestApis.activities().getLockTaskModeState()).isEqualTo(
LOCK_TASK_MODE_LOCKED);
} finally {
activity.stopLockTask();
@@ -836,8 +816,7 @@
String[] originalLockTaskPackages =
sDeviceState.dpc().devicePolicyManager().getLockTaskPackages(DPC_COMPONENT_NAME);
- try (TestAppInstanceReference testApp =
- sTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
try {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{});
Bundle options = ActivityOptions.makeBasic().setLockTaskEnabled(true).toBundle();
@@ -858,8 +837,7 @@
String[] originalLockTaskPackages =
sDeviceState.dpc().devicePolicyManager().getLockTaskPackages(DPC_COMPONENT_NAME);
- try (TestAppInstanceReference testApp =
- sLockTaskTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sLockTaskTestApp.install()) {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sLockTaskTestApp.packageName()});
Activity<TestAppActivity> activity = testApp.activities().query()
.whereActivity().activityClass().simpleName().isEqualTo("ifwhitelistedactivity")
@@ -868,9 +846,9 @@
.get().start();
try {
- assertThat(sTestApis.activities().foregroundActivity()).isEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isEqualTo(
activity.activity().component());
- assertThat(sTestApis.activities().getLockTaskModeState()).isEqualTo(
+ assertThat(TestApis.activities().getLockTaskModeState()).isEqualTo(
LOCK_TASK_MODE_LOCKED);
} finally {
activity.stopLockTask();
@@ -887,8 +865,7 @@
String[] originalLockTaskPackages =
sDeviceState.dpc().devicePolicyManager().getLockTaskPackages(DPC_COMPONENT_NAME);
- try (TestAppInstanceReference testApp =
- sLockTaskTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sLockTaskTestApp.install()) {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{});
Activity<TestAppActivity> activity = testApp.activities().query()
.whereActivity().activityClass().simpleName().isEqualTo("ifwhitelistedactivity")
@@ -897,9 +874,9 @@
.get().start();
try {
- assertThat(sTestApis.activities().foregroundActivity()).isEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isEqualTo(
activity.activity().component());
- assertThat(sTestApis.activities().getLockTaskModeState()).isEqualTo(
+ assertThat(TestApis.activities().getLockTaskModeState()).isEqualTo(
LOCK_TASK_MODE_NONE);
} finally {
activity.stopLockTask();
@@ -917,8 +894,7 @@
String[] originalLockTaskPackages =
sDeviceState.dpc().devicePolicyManager().getLockTaskPackages(DPC_COMPONENT_NAME);
- try (TestAppInstanceReference testApp =
- sLockTaskTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sLockTaskTestApp.install()) {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sLockTaskTestApp.packageName()});
Activity<TestAppActivity> activity = testApp.activities().query()
.whereActivity().activityClass().simpleName().isEqualTo("ifwhitelistedactivity")
@@ -931,9 +907,9 @@
try {
// We don't actually watch for the Destroyed event because that'd be waiting for a
// non occurrence of an event which is slow
- assertThat(sTestApis.activities().foregroundActivity()).isEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isEqualTo(
activity.activity().component());
- assertThat(sTestApis.activities().getLockTaskModeState()).isEqualTo(
+ assertThat(TestApis.activities().getLockTaskModeState()).isEqualTo(
LOCK_TASK_MODE_LOCKED);
} finally {
activity.stopLockTask();
@@ -950,8 +926,7 @@
String[] originalLockTaskPackages =
sDeviceState.dpc().devicePolicyManager().getLockTaskPackages(DPC_COMPONENT_NAME);
- try (TestAppInstanceReference testApp =
- sLockTaskTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sLockTaskTestApp.install()) {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sLockTaskTestApp.packageName()});
Activity<TestAppActivity> activity = testApp.activities().query()
.whereActivity().activityClass().simpleName().isEqualTo("ifwhitelistedactivity")
@@ -962,7 +937,7 @@
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{});
assertThat(activity.activity().events().activityDestroyed()).eventOccurred();
- assertThat(sTestApis.activities().foregroundActivity()).isNotEqualTo(
+ assertThat(TestApis.activities().foregroundActivity()).isNotEqualTo(
activity.activity().component());
} finally {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(
@@ -979,7 +954,7 @@
String[] originalLockTaskPackages =
sDeviceState.dpc().devicePolicyManager().getLockTaskPackages(DPC_COMPONENT_NAME);
TelecomManager telecomManager =
- sTestApis.context().instrumentedContext().getSystemService(TelecomManager.class);
+ TestApis.context().instrumentedContext().getSystemService(TelecomManager.class);
String dialerPackage = telecomManager.getSystemDialerPackage();
try {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{dialerPackage});
@@ -989,16 +964,16 @@
intent.setPackage(dialerPackage);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
- sTestApis.context().instrumentedContext().startActivity(intent, options);
+ TestApis.context().instrumentedContext().startActivity(intent, options);
PollingCheck.waitFor(() -> {
- PackageReference pkg = sTestApis.activities().foregroundActivity().pkg();
+ PackageReference pkg = TestApis.activities().foregroundActivity().pkg();
if (pkg == null) {
return false;
}
return pkg.packageName().equals(dialerPackage);
});
- assertThat(sTestApis.activities().getLockTaskModeState()).isEqualTo(
+ assertThat(TestApis.activities().getLockTaskModeState()).isEqualTo(
LOCK_TASK_MODE_LOCKED);
} finally {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(
@@ -1017,8 +992,7 @@
sDeviceState.dpc().devicePolicyManager().getLockTaskFeatures(DPC_COMPONENT_NAME);
String emergencyDialerPackageName = getEmergencyDialerPackageName();
assumeFalse(emergencyDialerPackageName == null);
- try (TestAppInstanceReference testApp =
- sLockTaskTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sLockTaskTestApp.install()) {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(DPC_COMPONENT_NAME, new String[]{sLockTaskTestApp.packageName()});
sDeviceState.dpc().devicePolicyManager()
.setLockTaskFeatures(DPC_COMPONENT_NAME, 0);
@@ -1031,8 +1005,8 @@
activity.activity().startActivity(intent);
- if (sTestApis.activities().foregroundActivity() != null) {
- assertThat(sTestApis.activities().foregroundActivity().pkg()).isNotEqualTo(
+ if (TestApis.activities().foregroundActivity() != null) {
+ assertThat(TestApis.activities().foregroundActivity().pkg()).isNotEqualTo(
emergencyDialerPackageName);
}
} finally {
@@ -1056,8 +1030,7 @@
sDeviceState.dpc().devicePolicyManager().getLockTaskFeatures(DPC_COMPONENT_NAME);
String emergencyDialerPackageName = getEmergencyDialerPackageName();
assumeFalse(emergencyDialerPackageName == null);
- try (TestAppInstanceReference testApp =
- sLockTaskTestApp.install(sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sLockTaskTestApp.install()) {
sDeviceState.dpc().devicePolicyManager().setLockTaskPackages(
DPC_COMPONENT_NAME, new String[]{sLockTaskTestApp.packageName()});
sDeviceState.dpc().devicePolicyManager().setLockTaskFeatures(DPC_COMPONENT_NAME, LOCK_TASK_FEATURE_KEYGUARD);
@@ -1069,9 +1042,9 @@
activity.startActivity(intent);
- assertThat(sTestApis.activities().foregroundActivity().pkg())
- .isEqualTo(sTestApis.packages().find(emergencyDialerPackageName));
- assertThat(sTestApis.activities().getLockTaskModeState()).isEqualTo(
+ assertThat(TestApis.activities().foregroundActivity().pkg())
+ .isEqualTo(TestApis.packages().find(emergencyDialerPackageName));
+ assertThat(TestApis.activities().getLockTaskModeState()).isEqualTo(
LOCK_TASK_MODE_LOCKED);
} finally {
activity.stopLockTask();
@@ -1086,7 +1059,7 @@
private String getEmergencyDialerPackageName() {
PackageManager packageManager =
- sTestApis.context().instrumentedContext().getPackageManager();
+ TestApis.context().instrumentedContext().getPackageManager();
Intent intent = new Intent(ACTION_EMERGENCY_DIAL).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ResolveInfo dialerInfo =
packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/NetworkResetTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/NetworkResetTest.java
index ab6d411..1e10db7 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/NetworkResetTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/NetworkResetTest.java
@@ -53,8 +53,7 @@
@ClassRule @Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final UserManager sUserManager = sContext.getSystemService(UserManager.class);
private static final ConnectivityManager sConnectivityManager =
sContext.getSystemService(ConnectivityManager.class);
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/PreferentialNetworkServiceTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/PreferentialNetworkServiceTest.java
index e64fdbc..3d5f7ef 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/PreferentialNetworkServiceTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/PreferentialNetworkServiceTest.java
@@ -63,8 +63,7 @@
private final long NO_CALLBACK_TIMEOUT_MS = 100L;
private final String TAG = PreferentialNetworkServiceTest.class.getSimpleName();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final ConnectivityManager sCm =
sContext.getSystemService(ConnectivityManager.class);
private final HandlerThread mHandlerThread = new HandlerThread(TAG + " handler thread");
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/ResetPasswordWithTokenTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/ResetPasswordWithTokenTest.java
index 13e2bce..1487dfe 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/ResetPasswordWithTokenTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/ResetPasswordWithTokenTest.java
@@ -77,8 +77,7 @@
private static final String RESET_PASSWORD_TOKEN_DISABLED =
"Cannot reset password token as it is disabled for the primary user";
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private final KeyguardManager sLocalKeyguardManager =
sContext.getSystemService(KeyguardManager.class);
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/RingtoneTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/RingtoneTest.java
index 6193a51..f7ef7b2 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/RingtoneTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/RingtoneTest.java
@@ -46,8 +46,7 @@
@ClassRule @Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
- private static final Context sContext = sTestApis.context().instrumentedContext();
+ private static final Context sContext = TestApis.context().instrumentedContext();
private static final Uri RINGTONE_URI = Uri.parse("http://uri.does.not.matter");
@@ -97,24 +96,24 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void setActualDefaultRingtoneUri_ringtone_setsSyncParentSoundsToFalse() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE);
try {
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE, RINGTONE_URI);
assertWithMessage("SYNC_PARENT_SOUNDS is false because a ringtone"
+ " has been set on the profile")
- .that(sTestApis.settings().secure().getInt(
+ .that(TestApis.settings().secure().getInt(
SYNC_PARENT_SOUNDS)).isEqualTo(0);
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
@@ -122,7 +121,7 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void getActualDefaultRingtoneUri_ringtone_syncParentSoundsIsFalse_returnsSetRingtone() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE);
try {
@@ -135,7 +134,7 @@
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
@@ -143,20 +142,20 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void getActualDefaultRingtoneUri_ringtone_syncParentSoundsIsTrue_returnsDefaultRingtone() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE);
try {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE, RINGTONE_URI);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
assertThat(RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE)).isEqualTo(originalUri);
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
@@ -164,21 +163,21 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void getActualDefaultRingtoneUri_ringtone_syncParentSoundsIsFalseAndUriWasPreviouslySet_returnsPreviouslySetRingtone() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE);
try {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE, RINGTONE_URI);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 0);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 0);
assertThat(RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE)).isEqualTo(RINGTONE_URI);
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_RINGTONE, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
@@ -186,23 +185,23 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void setActualDefaultRingtoneUri_notification_setsSyncParentSoundsToFalse() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION);
try {
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION, RINGTONE_URI);
assertWithMessage("SYNC_PARENT_SOUNDS is false because a ringtone has been set on the profile")
- .that(sTestApis.settings().secure().getInt(
+ .that(TestApis.settings().secure().getInt(
SYNC_PARENT_SOUNDS)).isEqualTo(0);
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
@@ -210,7 +209,7 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void getActualDefaultRingtoneUri_notification_syncParentSoundsIsFalse_returnsSetRingtone() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION);
try {
@@ -223,7 +222,7 @@
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
@@ -231,20 +230,20 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void getActualDefaultRingtoneUri_notification_syncParentSoundsIsTrue_returnsDefaultRingtone() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION);
try {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION, RINGTONE_URI);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
assertThat(RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION)).isEqualTo(originalUri);
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
@@ -252,21 +251,21 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void getActualDefaultRingtoneUri_notification_syncParentSoundsIsFalseAndUriWasPreviouslySet_returnsPreviouslySetRingtone() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION);
try {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION, RINGTONE_URI);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 0);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 0);
assertThat(RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION)).isEqualTo(RINGTONE_URI);
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_NOTIFICATION, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
@@ -274,24 +273,24 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void setActualDefaultRingtoneUri_alarm_setsSyncParentSoundsToFalse() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM);
try {
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM, RINGTONE_URI);
assertWithMessage(
"SYNC_PARENT_SOUNDS is false because a ringtone has been set on the profile")
- .that(sTestApis.settings().secure().getInt(
+ .that(TestApis.settings().secure().getInt(
SYNC_PARENT_SOUNDS)).isEqualTo(0);
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
@@ -299,7 +298,7 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void getActualDefaultRingtoneUri_alarm_syncParentSoundsIsFalse_returnsSetRingtone() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM);
try {
@@ -312,7 +311,7 @@
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
@@ -320,20 +319,20 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void getActualDefaultRingtoneUri_alarm_syncParentSoundsIsTrue_returnsDefaultRingtone() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM);
try {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM, RINGTONE_URI);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
assertThat(RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM)).isEqualTo(originalUri);
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
@@ -341,21 +340,21 @@
@IncludeRunOnProfileOwnerProfileWithNoDeviceOwner
@EnsureHasPermission(WRITE_SETTINGS)
public void getActualDefaultRingtoneUri_alarm_syncParentSoundsIsFalseAndUriWasPreviouslySet_returnsPreviouslySetRingtone() {
- int originalSyncParentSounds = sTestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
+ int originalSyncParentSounds = TestApis.settings().secure().getInt(SYNC_PARENT_SOUNDS);
Uri originalUri = RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM);
try {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM, RINGTONE_URI);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 0);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 1);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, 0);
assertThat(RingtoneManager.getActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM)).isEqualTo(RINGTONE_URI);
} finally {
RingtoneManager.setActualDefaultRingtoneUri(
sContext, RingtoneManager.TYPE_ALARM, originalUri);
- sTestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
+ TestApis.settings().secure().putInt(SYNC_PARENT_SOUNDS, originalSyncParentSounds);
}
}
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/ScreenCaptureDisabledTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/ScreenCaptureDisabledTest.java
index c50621e..9e8eb6f 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/ScreenCaptureDisabledTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/ScreenCaptureDisabledTest.java
@@ -39,7 +39,6 @@
import com.android.bedstead.harrier.annotations.enterprise.PositivePolicyTest;
import com.android.bedstead.harrier.policies.ScreenCaptureDisabled;
import com.android.bedstead.metricsrecorder.EnterpriseMetricsRecorder;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.testapp.TestApp;
import com.android.bedstead.testapp.TestAppInstanceReference;
import com.android.bedstead.testapp.TestAppProvider;
@@ -62,7 +61,6 @@
@Rule
public static final DeviceState sDeviceState = new DeviceState();
- private static final TestApis sTestApis = new TestApis();
private static final TestAppProvider sTestAppProvider = new TestAppProvider();
private static final TestApp sTestApp =
sTestAppProvider.query().whereActivities().isNotEmpty().get();
@@ -189,8 +187,7 @@
}
private Bitmap takeScreenshotExpectingFailure() {
- try (TestAppInstanceReference testApp = sTestApp.install(
- sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
testApp.activities().any().start();
return PollingCheck.waitFor(WAIT_IN_MILLISECOND, mUiAutomation::takeScreenshot,
Objects::isNull);
@@ -198,8 +195,7 @@
}
private Bitmap takeScreenshotExpectingSuccess() {
- try (TestAppInstanceReference testApp = sTestApp.install(
- sTestApis.users().instrumented())) {
+ try (TestAppInstanceReference testApp = sTestApp.install()) {
testApp.activities().any().start();
return PollingCheck.waitFor(WAIT_IN_MILLISECOND, mUiAutomation::takeScreenshot,
Objects::nonNull);
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/StartProfilesTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/StartProfilesTest.java
index c1806ee..c6fcd6b 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/StartProfilesTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/StartProfilesTest.java
@@ -26,14 +26,12 @@
import static org.testng.Assert.assertThrows;
import android.app.ActivityManager;
-import android.app.UiAutomation;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.UserManager;
import androidx.test.core.app.ApplicationProvider;
-import androidx.test.platform.app.InstrumentationRegistry;
import com.android.bedstead.harrier.BedsteadJUnit4;
import com.android.bedstead.harrier.DeviceState;
@@ -45,7 +43,6 @@
import com.android.bedstead.harrier.annotations.Postsubmit;
import com.android.bedstead.harrier.annotations.RequireFeature;
import com.android.bedstead.harrier.annotations.RequireRunOnPrimaryUser;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.nene.users.UserReference;
import com.android.compatibility.common.util.BlockingBroadcastReceiver;
@@ -63,10 +60,6 @@
private static final ActivityManager sActivityManager =
sContext.getSystemService(ActivityManager.class);
- private UiAutomation mUiAutomation =
- InstrumentationRegistry.getInstrumentation().getUiAutomation();
- private final TestApis mTestApis = new TestApis();
-
@ClassRule @Rule
public static final DeviceState sDeviceState = new DeviceState();
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/SupportMessageTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/SupportMessageTest.java
index 8dc4c71..f3873bb 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/SupportMessageTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/SupportMessageTest.java
@@ -31,7 +31,6 @@
import com.android.bedstead.harrier.annotations.enterprise.PositivePolicyTest;
import com.android.bedstead.harrier.policies.SupportMessage;
import com.android.bedstead.metricsrecorder.EnterpriseMetricsRecorder;
-import com.android.bedstead.nene.TestApis;
import com.android.bedstead.remotedpc.RemoteDpc;
import org.junit.After;
@@ -62,7 +61,6 @@
new String(new char[LONG_SUPPORT_MESSAGE_REASONABLE_LENGTH])
.replace('\0', 'A');
private static final String EMPTY_SUPPORT_MESSAGE = "";
- private static final TestApis sTestApis = new TestApis();
private RemoteDevicePolicyManager mDevicePolicyManager;
private ComponentName mAdmin;
diff --git a/tests/devicepolicy/src/android/devicepolicy/cts/UserControlDisabledPackagesTest.java b/tests/devicepolicy/src/android/devicepolicy/cts/UserControlDisabledPackagesTest.java
index cbaa6aa..0c9bc14 100644
--- a/tests/devicepolicy/src/android/devicepolicy/cts/UserControlDisabledPackagesTest.java
+++ b/tests/devicepolicy/src/android/devicepolicy/cts/UserControlDisabledPackagesTest.java
@@ -61,15 +61,14 @@
public class UserControlDisabledPackagesTest {
private static final String TAG = "UserControlDisabledPackagesTest";
- private static final TestApis sTestApis = new TestApis();
private static final TestAppProvider sTestAppProvider = new TestAppProvider();
private static final TestApp sTestApp =
sTestAppProvider.query().whereActivities().isNotEmpty().get();
private static final ActivityManager sActivityManager =
- sTestApis.context().instrumentedContext().getSystemService(ActivityManager.class);
+ TestApis.context().instrumentedContext().getSystemService(ActivityManager.class);
private static final PackageManager sPackageManager =
- sTestApis.context().instrumentedContext().getPackageManager();
+ TestApis.context().instrumentedContext().getPackageManager();
private static final String PACKAGE_NAME = "com.android.foo.bar.baz";
@@ -184,7 +183,7 @@
List<String> originalDisabledPackages =
sDeviceState.dpc().devicePolicyManager().getUserControlDisabledPackages(
DPC_COMPONENT_NAME);
- UserReference currentRunningUserOnTest = sTestApis.users().instrumented();
+ UserReference currentRunningUserOnTest = TestApis.users().instrumented();
int currentRunningUserId = currentRunningUserOnTest.id();
String testAppPackageName = sTestApp.packageName();