diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyConstantsTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyConstantsTest.java index be05245deea1a..9660d6ba2f745 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyConstantsTest.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyConstantsTest.java @@ -15,33 +15,33 @@ */ package com.android.server.devicepolicy; -import android.test.AndroidTestCase; +import static com.google.common.truth.Truth.assertThat; + import android.test.suitebuilder.annotation.SmallTest; +import org.junit.Test; + /** * Test for {@link DevicePolicyConstants}. * - m FrameworksServicesTests && - adb install \ - -r ${ANDROID_PRODUCT_OUT}/data/app/FrameworksServicesTests/FrameworksServicesTests.apk && - adb shell am instrument -e class com.android.server.devicepolicy.DevicePolicyConstantsTest \ - -w com.android.frameworks.servicestests - - - -w com.android.frameworks.servicestests/androidx.test.runner.AndroidJUnitRunner + *
Run this test with:
+ *
+ * {@code atest FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyConstantsTest}
*/
@SmallTest
-public class DevicePolicyConstantsTest extends AndroidTestCase {
+public class DevicePolicyConstantsTest {
private static final String TAG = "DevicePolicyConstantsTest";
+ @Test
public void testDefaultValues() throws Exception {
final DevicePolicyConstants constants = DevicePolicyConstants.loadFromString("");
- assertEquals(1 * 60 * 60, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC);
- assertEquals(24 * 60 * 60, constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC);
- assertEquals(2.0, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE);
+ assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC).isEqualTo(1 * 60 * 60);
+ assertThat(constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC).isEqualTo(24 * 60 * 60);
+ assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE).isWithin(1.0e-10).of(2.0);
}
+ @Test
public void testCustomValues() throws Exception {
final DevicePolicyConstants constants = DevicePolicyConstants.loadFromString(
"das_died_service_reconnect_backoff_sec=10,"
@@ -49,11 +49,13 @@ public class DevicePolicyConstantsTest extends AndroidTestCase {
+ "das_died_service_reconnect_max_backoff_sec=15"
);
- assertEquals(10, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC);
- assertEquals(15, constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC);
- assertEquals(1.25, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE);
+ assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC).isEqualTo(10);
+ assertThat(constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC).isEqualTo(15);
+ assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE).isWithin(1.0e-10)
+ .of(1.25);
}
+ @Test
public void testMinMax() throws Exception {
final DevicePolicyConstants constants = DevicePolicyConstants.loadFromString(
"das_died_service_reconnect_backoff_sec=3,"
@@ -61,8 +63,8 @@ public class DevicePolicyConstantsTest extends AndroidTestCase {
+ "das_died_service_reconnect_max_backoff_sec=1"
);
- assertEquals(5, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC);
- assertEquals(5, constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC);
- assertEquals(1.0, constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE);
+ assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_SEC).isEqualTo(5);
+ assertThat(constants.DAS_DIED_SERVICE_RECONNECT_MAX_BACKOFF_SEC).isEqualTo(5);
+ assertThat(constants.DAS_DIED_SERVICE_RECONNECT_BACKOFF_INCREASE).isWithin(1.0e-10).of(1.0);
}
}
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyEventLoggerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyEventLoggerTest.java
index b24bca8fc050d..350b390a21304 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyEventLoggerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyEventLoggerTest.java
@@ -46,8 +46,8 @@ public class DevicePolicyEventLoggerTest {
.setTimePeriod(1234L);
assertThat(eventLogger.getEventId()).isEqualTo(5);
assertThat(eventLogger.getBoolean()).isTrue();
- assertThat(eventLogger.getStringArray())
- .isEqualTo(new String[] {"string1", "string2", "string3"});
+ assertThat(eventLogger.getStringArray()).asList()
+ .containsExactly("string1", "string2", "string3");
assertThat(eventLogger.getAdminPackageName()).isEqualTo("com.test.package");
assertThat(eventLogger.getInt()).isEqualTo(4321);
assertThat(eventLogger.getTimePeriod()).isEqualTo(1234L);
@@ -57,23 +57,22 @@ public class DevicePolicyEventLoggerTest {
public void testStrings() {
assertThat(DevicePolicyEventLogger
.createEvent(0)
- .setStrings("string1", "string2", "string3").getStringArray())
- .isEqualTo(new String[] {"string1", "string2", "string3"});
+ .setStrings("string1", "string2", "string3").getStringArray()).asList()
+ .containsExactly("string1", "string2", "string3").inOrder();
assertThat(DevicePolicyEventLogger
.createEvent(0)
.setStrings("string1", new String[] {"string2", "string3"}).getStringArray())
- .isEqualTo(new String[] {"string1", "string2", "string3"});
+ .asList().containsExactly("string1", "string2", "string3").inOrder();
assertThat(DevicePolicyEventLogger
.createEvent(0)
.setStrings("string1", "string2", new String[] {"string3"}).getStringArray())
- .isEqualTo(new String[] {"string1", "string2", "string3"});
-
+ .asList().containsExactly("string1", "string2", "string3").inOrder();
assertThat(DevicePolicyEventLogger
.createEvent(0)
- .setStrings((String) null).getStringArray())
- .isEqualTo(new String[] {null});
+ .setStrings((String) null).getStringArray()).asList()
+ .containsExactly((String) null);
assertThat(DevicePolicyEventLogger
.createEvent(0)
@@ -106,8 +105,8 @@ public class DevicePolicyEventLoggerTest {
.createEvent(0);
assertThat(eventLogger.getEventId()).isEqualTo(0);
assertThat(eventLogger.getBoolean()).isFalse();
- assertThat(eventLogger.getStringArray()).isEqualTo(null);
- assertThat(eventLogger.getAdminPackageName()).isEqualTo(null);
+ assertThat(eventLogger.getStringArray()).isNull();
+ assertThat(eventLogger.getAdminPackageName()).isNull();
assertThat(eventLogger.getInt()).isEqualTo(0);
assertThat(eventLogger.getTimePeriod()).isEqualTo(0L);
}
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java
index 3167820f0a482..fa3f45c08202b 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java
@@ -20,7 +20,9 @@ import static android.os.UserHandle.USER_SYSTEM;
import static com.android.server.devicepolicy.DpmTestUtils.writeInputStreamToFile;
import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;
-import static org.junit.Assert.assertArrayEquals;
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
+
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
@@ -43,17 +45,23 @@ import android.platform.test.annotations.Presubmit;
import android.provider.Settings;
import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
import com.android.frameworks.servicestests.R;
import com.android.server.LocalServices;
import com.android.server.SystemService;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@Presubmit
+@RunWith(AndroidJUnit4.class)
public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
private static final String USER_TYPE_EMPTY = "";
@@ -63,9 +71,8 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
private DpmMockContext mContext;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
mContext = getContext();
@@ -77,6 +84,7 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
.thenReturn(true);
}
+ @Test
public void testMigration() throws Exception {
final File user10dir = getServices().addUser(10, 0, USER_TYPE_EMPTY);
final File user11dir = getServices().addUser(11, 0,
@@ -160,19 +168,19 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
mContext.binder.restoreCallingIdentity(ident);
}
- assertTrue(dpms.mOwners.hasDeviceOwner());
- assertFalse(dpms.mOwners.hasProfileOwner(USER_SYSTEM));
- assertTrue(dpms.mOwners.hasProfileOwner(10));
- assertTrue(dpms.mOwners.hasProfileOwner(11));
- assertFalse(dpms.mOwners.hasProfileOwner(12));
+ assertThat(dpms.mOwners.hasDeviceOwner()).isTrue();
+ assertThat(dpms.mOwners.hasProfileOwner(USER_SYSTEM)).isFalse();
+ assertThat(dpms.mOwners.hasProfileOwner(10)).isTrue();
+ assertThat(dpms.mOwners.hasProfileOwner(11)).isTrue();
+ assertThat(dpms.mOwners.hasProfileOwner(12)).isFalse();
// Now all information should be migrated.
- assertFalse(dpms.mOwners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertFalse(dpms.mOwners.getProfileOwnerUserRestrictionsNeedsMigration(
- USER_SYSTEM));
- assertFalse(dpms.mOwners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertFalse(dpms.mOwners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(dpms.mOwners.getProfileOwnerUserRestrictionsNeedsMigration(12));
+ assertThat(dpms.mOwners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(dpms.mOwners.getProfileOwnerUserRestrictionsNeedsMigration(USER_SYSTEM))
+ .isFalse();
+ assertThat(dpms.mOwners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isFalse();
+ assertThat(dpms.mOwners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
+ assertThat(dpms.mOwners.getProfileOwnerUserRestrictionsNeedsMigration(12)).isFalse();
// Check the new base restrictions.
DpmTestUtils.assertRestrictions(
@@ -221,6 +229,7 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
dpms.getProfileOwnerAdminLocked(11).ensureUserRestrictions());
}
+ @Test
public void testMigration2_profileOwnerOnUser0() throws Exception {
setUpPackageManagerForAdmin(admin2, DpmMockContext.CALLER_SYSTEM_USER_UID);
@@ -271,13 +280,13 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
} finally {
mContext.binder.restoreCallingIdentity(ident);
}
- assertFalse(dpms.mOwners.hasDeviceOwner());
- assertTrue(dpms.mOwners.hasProfileOwner(USER_SYSTEM));
+ assertThat(dpms.mOwners.hasDeviceOwner()).isFalse();
+ assertThat(dpms.mOwners.hasProfileOwner(USER_SYSTEM)).isTrue();
// Now all information should be migrated.
- assertFalse(dpms.mOwners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertFalse(dpms.mOwners.getProfileOwnerUserRestrictionsNeedsMigration(
- USER_SYSTEM));
+ assertThat(dpms.mOwners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(dpms.mOwners.getProfileOwnerUserRestrictionsNeedsMigration(USER_SYSTEM))
+ .isFalse();
// Check the new base restrictions.
DpmTestUtils.assertRestrictions(
@@ -297,6 +306,7 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
}
// Test setting default restrictions for managed profile.
+ @Test
public void testMigration3_managedProfileOwner() throws Exception {
// Create a managed profile user.
final File user10dir = getServices().addUser(10, 0,
@@ -339,8 +349,8 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
mContext.binder.restoreCallingIdentity(ident);
}
- assertFalse(dpms.mOwners.hasDeviceOwner());
- assertTrue(dpms.mOwners.hasProfileOwner(10));
+ assertThat(dpms.mOwners.hasDeviceOwner()).isFalse();
+ assertThat(dpms.mOwners.hasProfileOwner(10)).isTrue();
// Check that default restrictions were applied.
DpmTestUtils.assertRestrictions(
@@ -352,11 +362,12 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
final Set Run this test with:
+ *
+ * {@code atest FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest}
+ *
*/
@SmallTest
@Presubmit
@@ -205,9 +205,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
private static final String PROFILE_OFF_SUSPENSION_TEXT = "suspension_text";
private static final String PROFILE_OFF_SUSPENSION_SOON_TEXT = "suspension_tomorrow_text";
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
mContext = getContext();
mServiceContext = mContext;
@@ -251,11 +250,10 @@ public class DevicePolicyManagerTest extends DpmTestBase {
return dpms.mTransferOwnershipMetadataManager;
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
flushTasks(dpms);
getMockTransferMetadataManager().deleteMetadataFile();
- super.tearDown();
}
private void initializeDpms() {
@@ -336,14 +334,15 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// PO needs to be a DA.
dpm.setActiveAdmin(admin, /*replace=*/ false);
// Fire!
- assertTrue(dpm.setProfileOwner(admin, "owner-name", CALLER_USER_HANDLE));
+ assertThat(dpm.setProfileOwner(admin, "owner-name", CALLER_USER_HANDLE)).isTrue();
// Check
- assertEquals(admin, dpm.getProfileOwnerAsUser(CALLER_USER_HANDLE));
+ assertThat(dpm.getProfileOwnerAsUser(CALLER_USER_HANDLE)).isEqualTo(admin);
});
mServiceContext.binder.restoreCallingIdentity(ident);
}
+ @Test
public void testHasNoFeature() throws Exception {
when(getServices().packageManager.hasSystemFeature(eq(PackageManager.FEATURE_DEVICE_ADMIN)))
.thenReturn(false);
@@ -352,9 +351,10 @@ public class DevicePolicyManagerTest extends DpmTestBase {
new DevicePolicyManagerServiceTestable(getServices(), mContext);
// If the device has no DPMS feature, it shouldn't register the local service.
- assertNull(LocalServices.getService(DevicePolicyManagerInternal.class));
+ assertThat(LocalServices.getService(DevicePolicyManagerInternal.class)).isNull();
}
+ @Test
public void testLoadAdminData() throws Exception {
// Device owner in SYSTEM_USER
setDeviceOwner();
@@ -365,7 +365,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
final int ANOTHER_UID = UserHandle.getUid(CALLER_USER_HANDLE, 1306);
setUpPackageManagerForFakeAdmin(adminAnotherPackage, ANOTHER_UID, admin2);
dpm.setActiveAdmin(adminAnotherPackage, /* replace =*/ false, CALLER_USER_HANDLE);
- assertTrue(dpm.isAdminActiveAsUser(adminAnotherPackage, CALLER_USER_HANDLE));
+ assertThat(dpm.isAdminActiveAsUser(adminAnotherPackage, CALLER_USER_HANDLE)).isTrue();
initializeDpms();
@@ -381,6 +381,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().networkPolicyManagerInternal).onAdminDataAvailable();
}
+ @Test
public void testLoadAdminData_noAdmins() throws Exception {
final int ANOTHER_USER_ID = 15;
getServices().addUser(ANOTHER_USER_ID, 0, "");
@@ -399,6 +400,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
/**
* Caller doesn't have proper permissions.
*/
+ @Test
public void testSetActiveAdmin_SecurityException() {
// 1. Failure cases.
@@ -422,6 +424,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
* {@link DevicePolicyManager#getActiveAdmins}
* {@link DevicePolicyManager#getActiveAdminsAsUser}
*/
+ @Test
public void testSetActiveAdmin() throws Exception {
// 1. Make sure the caller has proper permissions.
mContext.callerPermissions.add(android.Manifest.permission.MANAGE_DEVICE_ADMINS);
@@ -456,9 +459,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// TODO Verify other calls too.
// Make sure it's active admin1.
- assertTrue(dpm.isAdminActive(admin1));
- assertFalse(dpm.isAdminActive(admin2));
- assertFalse(dpm.isAdminActive(admin3));
+ assertThat(dpm.isAdminActive(admin1)).isTrue();
+ assertThat(dpm.isAdminActive(admin2)).isFalse();
+ assertThat(dpm.isAdminActive(admin3)).isFalse();
// But not admin1 for a different user.
@@ -466,8 +469,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// (Because we're checking a different user's status from CALLER_USER_HANDLE.)
mContext.callerPermissions.add("android.permission.INTERACT_ACROSS_USERS_FULL");
- assertFalse(dpm.isAdminActiveAsUser(admin1, CALLER_USER_HANDLE + 1));
- assertFalse(dpm.isAdminActiveAsUser(admin2, CALLER_USER_HANDLE + 1));
+ assertThat(dpm.isAdminActiveAsUser(admin1, CALLER_USER_HANDLE + 1)).isFalse();
+ assertThat(dpm.isAdminActiveAsUser(admin2, CALLER_USER_HANDLE + 1)).isFalse();
mContext.callerPermissions.remove("android.permission.INTERACT_ACROSS_USERS_FULL");
@@ -479,9 +482,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
dpm.setActiveAdmin(admin2, /* replace =*/ false);
// Now we have two admins.
- assertTrue(dpm.isAdminActive(admin1));
- assertTrue(dpm.isAdminActive(admin2));
- assertFalse(dpm.isAdminActive(admin3));
+ assertThat(dpm.isAdminActive(admin1)).isTrue();
+ assertThat(dpm.isAdminActive(admin2)).isTrue();
+ assertThat(dpm.isAdminActive(admin3)).isFalse();
// Admin2 was already enabled, so setApplicationEnabledSetting() shouldn't have called
// again. (times(1) because it was previously called for admin1)
@@ -508,9 +511,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// 6. Test getActiveAdmins()
List Run this test with:
+ *
+ * {@code atest FrameworksServicesTests:com.android.server.devicepolicy.OwnersTest}
+ *
*/
@SmallTest
+@RunWith(AndroidJUnit4.class)
public class OwnersTest extends DpmTestBase {
+
+ @Test
public void testUpgrade01() throws Exception {
getServices().addUsers(10, 11, 20, 21);
@@ -48,26 +55,26 @@ public class OwnersTest extends DpmTestBase {
owners.load();
// The legacy file should be removed.
- assertFalse(owners.getLegacyConfigFile().exists());
+ assertThat(owners.getLegacyConfigFile().exists()).isFalse();
// File was empty, so no new files should be created.
- assertFalse(owners.getDeviceOwnerFile().exists());
+ assertThat(owners.getDeviceOwnerFile().exists()).isFalse();
- assertFalse(owners.getProfileOwnerFile(10).exists());
- assertFalse(owners.getProfileOwnerFile(11).exists());
- assertFalse(owners.getProfileOwnerFile(20).exists());
- assertFalse(owners.getProfileOwnerFile(21).exists());
+ assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(21).exists()).isFalse();
- assertFalse(owners.hasDeviceOwner());
- assertEquals(UserHandle.USER_NULL, owners.getDeviceOwnerUserId());
- assertNull(owners.getSystemUpdatePolicy());
- assertEquals(0, owners.getProfileOwnerKeys().size());
+ assertThat(owners.hasDeviceOwner()).isFalse();
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
+ assertThat(owners.getSystemUpdatePolicy()).isNull();
+ assertThat(owners.getProfileOwnerKeys()).isEmpty();
- assertFalse(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
}
// Then re-read and check.
@@ -75,19 +82,20 @@ public class OwnersTest extends DpmTestBase {
final OwnersTestable owners = new OwnersTestable(getServices());
owners.load();
- assertFalse(owners.hasDeviceOwner());
- assertEquals(UserHandle.USER_NULL, owners.getDeviceOwnerUserId());
- assertNull(owners.getSystemUpdatePolicy());
- assertEquals(0, owners.getProfileOwnerKeys().size());
+ assertThat(owners.hasDeviceOwner()).isFalse();
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
+ assertThat(owners.getSystemUpdatePolicy()).isNull();
+ assertThat(owners.getProfileOwnerKeys()).isEmpty();
- assertFalse(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
}
}
+ @Test
public void testUpgrade02() throws Exception {
getServices().addUsers(10, 11, 20, 21);
@@ -101,28 +109,28 @@ public class OwnersTest extends DpmTestBase {
owners.load();
// The legacy file should be removed.
- assertFalse(owners.getLegacyConfigFile().exists());
+ assertThat(owners.getLegacyConfigFile().exists()).isFalse();
- assertTrue(owners.getDeviceOwnerFile().exists()); // TODO Check content
+ assertThat(owners.getDeviceOwnerFile().exists()).isTrue(); // TODO Check content
- assertFalse(owners.getProfileOwnerFile(10).exists());
- assertFalse(owners.getProfileOwnerFile(11).exists());
- assertFalse(owners.getProfileOwnerFile(20).exists());
- assertFalse(owners.getProfileOwnerFile(21).exists());
+ assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(21).exists()).isFalse();
- assertTrue(owners.hasDeviceOwner());
- assertEquals(null, owners.getDeviceOwnerName());
- assertEquals("com.google.android.testdpc", owners.getDeviceOwnerPackageName());
- assertEquals(UserHandle.USER_SYSTEM, owners.getDeviceOwnerUserId());
+ assertThat(owners.hasDeviceOwner()).isTrue();
+ assertThat(owners.getDeviceOwnerName()).isEqualTo(null);
+ assertThat(owners.getDeviceOwnerPackageName()).isEqualTo("com.google.android.testdpc");
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_SYSTEM);
- assertNull(owners.getSystemUpdatePolicy());
- assertEquals(0, owners.getProfileOwnerKeys().size());
+ assertThat(owners.getSystemUpdatePolicy()).isNull();
+ assertThat(owners.getProfileOwnerKeys()).isEmpty();
- assertTrue(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
}
// Then re-read and check.
@@ -130,22 +138,23 @@ public class OwnersTest extends DpmTestBase {
final OwnersTestable owners = new OwnersTestable(getServices());
owners.load();
- assertTrue(owners.hasDeviceOwner());
- assertEquals(null, owners.getDeviceOwnerName());
- assertEquals("com.google.android.testdpc", owners.getDeviceOwnerPackageName());
- assertEquals(UserHandle.USER_SYSTEM, owners.getDeviceOwnerUserId());
+ assertThat(owners.hasDeviceOwner()).isTrue();
+ assertThat(owners.getDeviceOwnerName()).isEqualTo(null);
+ assertThat(owners.getDeviceOwnerPackageName()).isEqualTo("com.google.android.testdpc");
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_SYSTEM);
- assertNull(owners.getSystemUpdatePolicy());
- assertEquals(0, owners.getProfileOwnerKeys().size());
+ assertThat(owners.getSystemUpdatePolicy()).isNull();
+ assertThat(owners.getProfileOwnerKeys()).isEmpty();
- assertTrue(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
}
}
+ @Test
public void testUpgrade03() throws Exception {
getServices().addUsers(10, 11, 20, 21);
@@ -159,36 +168,36 @@ public class OwnersTest extends DpmTestBase {
owners.load();
// The legacy file should be removed.
- assertFalse(owners.getLegacyConfigFile().exists());
+ assertThat(owners.getLegacyConfigFile().exists()).isFalse();
- assertFalse(owners.getDeviceOwnerFile().exists());
+ assertThat(owners.getDeviceOwnerFile().exists()).isFalse();
- assertTrue(owners.getProfileOwnerFile(10).exists());
- assertTrue(owners.getProfileOwnerFile(11).exists());
- assertFalse(owners.getProfileOwnerFile(20).exists());
- assertFalse(owners.getProfileOwnerFile(21).exists());
+ assertThat(owners.getProfileOwnerFile(10).exists()).isTrue();
+ assertThat(owners.getProfileOwnerFile(11).exists()).isTrue();
+ assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(21).exists()).isFalse();
- assertFalse(owners.hasDeviceOwner());
- assertEquals(UserHandle.USER_NULL, owners.getDeviceOwnerUserId());
- assertNull(owners.getSystemUpdatePolicy());
+ assertThat(owners.hasDeviceOwner()).isFalse();
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
+ assertThat(owners.getSystemUpdatePolicy()).isNull();
- assertEquals(2, owners.getProfileOwnerKeys().size());
- assertEquals(new ComponentName("com.google.android.testdpc",
- "com.google.android.testdpc.DeviceAdminReceiver0"),
- owners.getProfileOwnerComponent(10));
- assertEquals("0", owners.getProfileOwnerName(10));
- assertEquals("com.google.android.testdpc", owners.getProfileOwnerPackage(10));
+ assertThat(owners.getProfileOwnerKeys()).hasSize(2);
+ assertThat(owners.getProfileOwnerComponent(10))
+ .isEqualTo(new ComponentName("com.google.android.testdpc",
+ "com.google.android.testdpc.DeviceAdminReceiver0"));
+ assertThat(owners.getProfileOwnerName(10)).isEqualTo("0");
+ assertThat(owners.getProfileOwnerPackage(10)).isEqualTo("com.google.android.testdpc");
- assertEquals(new ComponentName("com.google.android.testdpc1", ""),
- owners.getProfileOwnerComponent(11));
- assertEquals("1", owners.getProfileOwnerName(11));
- assertEquals("com.google.android.testdpc1", owners.getProfileOwnerPackage(11));
+ assertThat(owners.getProfileOwnerComponent(11))
+ .isEqualTo(new ComponentName("com.google.android.testdpc1", ""));
+ assertThat(owners.getProfileOwnerName(11)).isEqualTo("1");
+ assertThat(owners.getProfileOwnerPackage(11)).isEqualTo("com.google.android.testdpc1");
- assertFalse(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertTrue(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertTrue(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
}
// Then re-read and check.
@@ -196,27 +205,27 @@ public class OwnersTest extends DpmTestBase {
final OwnersTestable owners = new OwnersTestable(getServices());
owners.load();
- assertFalse(owners.hasDeviceOwner());
- assertEquals(UserHandle.USER_NULL, owners.getDeviceOwnerUserId());
- assertNull(owners.getSystemUpdatePolicy());
+ assertThat(owners.hasDeviceOwner()).isFalse();
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
+ assertThat(owners.getSystemUpdatePolicy()).isNull();
- assertEquals(2, owners.getProfileOwnerKeys().size());
- assertEquals(new ComponentName("com.google.android.testdpc",
- "com.google.android.testdpc.DeviceAdminReceiver0"),
- owners.getProfileOwnerComponent(10));
- assertEquals("0", owners.getProfileOwnerName(10));
- assertEquals("com.google.android.testdpc", owners.getProfileOwnerPackage(10));
+ assertThat(owners.getProfileOwnerKeys()).hasSize(2);
+ assertThat(owners.getProfileOwnerComponent(10))
+ .isEqualTo(new ComponentName("com.google.android.testdpc",
+ "com.google.android.testdpc.DeviceAdminReceiver0"));
+ assertThat(owners.getProfileOwnerName(10)).isEqualTo("0");
+ assertThat(owners.getProfileOwnerPackage(10)).isEqualTo("com.google.android.testdpc");
- assertEquals(new ComponentName("com.google.android.testdpc1", ""),
- owners.getProfileOwnerComponent(11));
- assertEquals("1", owners.getProfileOwnerName(11));
- assertEquals("com.google.android.testdpc1", owners.getProfileOwnerPackage(11));
+ assertThat(owners.getProfileOwnerComponent(11))
+ .isEqualTo(new ComponentName("com.google.android.testdpc1", ""));
+ assertThat(owners.getProfileOwnerName(11)).isEqualTo("1");
+ assertThat(owners.getProfileOwnerPackage(11)).isEqualTo("com.google.android.testdpc1");
- assertFalse(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertTrue(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertTrue(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
}
}
@@ -224,6 +233,7 @@ public class OwnersTest extends DpmTestBase {
* Note this also tests {@link Owners#setDeviceOwnerUserRestrictionsMigrated()}
* and {@link Owners#setProfileOwnerUserRestrictionsMigrated(int)}.
*/
+ @Test
public void testUpgrade04() throws Exception {
getServices().addUsers(10, 11, 20, 21);
@@ -237,40 +247,40 @@ public class OwnersTest extends DpmTestBase {
owners.load();
// The legacy file should be removed.
- assertFalse(owners.getLegacyConfigFile().exists());
+ assertThat(owners.getLegacyConfigFile().exists()).isFalse();
- assertTrue(owners.getDeviceOwnerFile().exists());
+ assertThat(owners.getDeviceOwnerFile().exists()).isTrue();
- assertTrue(owners.getProfileOwnerFile(10).exists());
- assertTrue(owners.getProfileOwnerFile(11).exists());
- assertFalse(owners.getProfileOwnerFile(20).exists());
- assertFalse(owners.getProfileOwnerFile(21).exists());
+ assertThat(owners.getProfileOwnerFile(10).exists()).isTrue();
+ assertThat(owners.getProfileOwnerFile(11).exists()).isTrue();
+ assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(21).exists()).isFalse();
- assertTrue(owners.hasDeviceOwner());
- assertEquals(null, owners.getDeviceOwnerName());
- assertEquals("com.google.android.testdpc", owners.getDeviceOwnerPackageName());
- assertEquals(UserHandle.USER_SYSTEM, owners.getDeviceOwnerUserId());
+ assertThat(owners.hasDeviceOwner()).isTrue();
+ assertThat(owners.getDeviceOwnerName()).isEqualTo(null);
+ assertThat(owners.getDeviceOwnerPackageName()).isEqualTo("com.google.android.testdpc");
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_SYSTEM);
- assertNotNull(owners.getSystemUpdatePolicy());
- assertEquals(5, owners.getSystemUpdatePolicy().getPolicyType());
+ assertThat(owners.getSystemUpdatePolicy()).isNotNull();
+ assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(5);
- assertEquals(2, owners.getProfileOwnerKeys().size());
- assertEquals(new ComponentName("com.google.android.testdpc",
- "com.google.android.testdpc.DeviceAdminReceiver0"),
- owners.getProfileOwnerComponent(10));
- assertEquals("0", owners.getProfileOwnerName(10));
- assertEquals("com.google.android.testdpc", owners.getProfileOwnerPackage(10));
+ assertThat(owners.getProfileOwnerKeys()).hasSize(2);
+ assertThat(owners.getProfileOwnerComponent(10))
+ .isEqualTo(new ComponentName("com.google.android.testdpc",
+ "com.google.android.testdpc.DeviceAdminReceiver0"));
+ assertThat(owners.getProfileOwnerName(10)).isEqualTo("0");
+ assertThat(owners.getProfileOwnerPackage(10)).isEqualTo("com.google.android.testdpc");
- assertEquals(new ComponentName("com.google.android.testdpc1", ""),
- owners.getProfileOwnerComponent(11));
- assertEquals("1", owners.getProfileOwnerName(11));
- assertEquals("com.google.android.testdpc1", owners.getProfileOwnerPackage(11));
+ assertThat(owners.getProfileOwnerComponent(11))
+ .isEqualTo(new ComponentName("com.google.android.testdpc1", ""));
+ assertThat(owners.getProfileOwnerName(11)).isEqualTo("1");
+ assertThat(owners.getProfileOwnerPackage(11)).isEqualTo("com.google.android.testdpc1");
- assertTrue(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertTrue(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertTrue(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
}
// Then re-read and check.
@@ -278,31 +288,31 @@ public class OwnersTest extends DpmTestBase {
final OwnersTestable owners = new OwnersTestable(getServices());
owners.load();
- assertTrue(owners.hasDeviceOwner());
- assertEquals(null, owners.getDeviceOwnerName());
- assertEquals("com.google.android.testdpc", owners.getDeviceOwnerPackageName());
- assertEquals(UserHandle.USER_SYSTEM, owners.getDeviceOwnerUserId());
+ assertThat(owners.hasDeviceOwner()).isTrue();
+ assertThat(owners.getDeviceOwnerName()).isEqualTo(null);
+ assertThat(owners.getDeviceOwnerPackageName()).isEqualTo("com.google.android.testdpc");
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_SYSTEM);
- assertNotNull(owners.getSystemUpdatePolicy());
- assertEquals(5, owners.getSystemUpdatePolicy().getPolicyType());
+ assertThat(owners.getSystemUpdatePolicy()).isNotNull();
+ assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(5);
- assertEquals(2, owners.getProfileOwnerKeys().size());
- assertEquals(new ComponentName("com.google.android.testdpc",
- "com.google.android.testdpc.DeviceAdminReceiver0"),
- owners.getProfileOwnerComponent(10));
- assertEquals("0", owners.getProfileOwnerName(10));
- assertEquals("com.google.android.testdpc", owners.getProfileOwnerPackage(10));
+ assertThat(owners.getProfileOwnerKeys()).hasSize(2);
+ assertThat(owners.getProfileOwnerComponent(10))
+ .isEqualTo(new ComponentName("com.google.android.testdpc",
+ "com.google.android.testdpc.DeviceAdminReceiver0"));
+ assertThat(owners.getProfileOwnerName(10)).isEqualTo("0");
+ assertThat(owners.getProfileOwnerPackage(10)).isEqualTo("com.google.android.testdpc");
- assertEquals(new ComponentName("com.google.android.testdpc1", ""),
- owners.getProfileOwnerComponent(11));
- assertEquals("1", owners.getProfileOwnerName(11));
- assertEquals("com.google.android.testdpc1", owners.getProfileOwnerPackage(11));
+ assertThat(owners.getProfileOwnerComponent(11))
+ .isEqualTo(new ComponentName("com.google.android.testdpc1", ""));
+ assertThat(owners.getProfileOwnerName(11)).isEqualTo("1");
+ assertThat(owners.getProfileOwnerPackage(11)).isEqualTo("com.google.android.testdpc1");
- assertTrue(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertTrue(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertTrue(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
owners.setDeviceOwnerUserRestrictionsMigrated();
}
@@ -311,11 +321,11 @@ public class OwnersTest extends DpmTestBase {
final OwnersTestable owners = new OwnersTestable(getServices());
owners.load();
- assertFalse(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertTrue(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertTrue(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
owners.setProfileOwnerUserRestrictionsMigrated(11);
}
@@ -324,16 +334,17 @@ public class OwnersTest extends DpmTestBase {
final OwnersTestable owners = new OwnersTestable(getServices());
owners.load();
- assertFalse(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertTrue(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isTrue();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
owners.setProfileOwnerUserRestrictionsMigrated(11);
}
}
+ @Test
public void testUpgrade05() throws Exception {
getServices().addUsers(10, 11, 20, 21);
@@ -347,27 +358,27 @@ public class OwnersTest extends DpmTestBase {
owners.load();
// The legacy file should be removed.
- assertFalse(owners.getLegacyConfigFile().exists());
+ assertThat(owners.getLegacyConfigFile().exists()).isFalse();
// Note device initializer is no longer supported. No need to write the DO file.
- assertFalse(owners.getDeviceOwnerFile().exists());
+ assertThat(owners.getDeviceOwnerFile().exists()).isFalse();
- assertFalse(owners.getProfileOwnerFile(10).exists());
- assertFalse(owners.getProfileOwnerFile(11).exists());
- assertFalse(owners.getProfileOwnerFile(20).exists());
+ assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
- assertFalse(owners.hasDeviceOwner());
- assertEquals(UserHandle.USER_NULL, owners.getDeviceOwnerUserId());
+ assertThat(owners.hasDeviceOwner()).isFalse();
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
- assertNull(owners.getSystemUpdatePolicy());
- assertEquals(0, owners.getProfileOwnerKeys().size());
+ assertThat(owners.getSystemUpdatePolicy()).isNull();
+ assertThat(owners.getProfileOwnerKeys()).isEmpty();
- assertFalse(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
}
// Then re-read and check.
@@ -375,21 +386,22 @@ public class OwnersTest extends DpmTestBase {
final OwnersTestable owners = new OwnersTestable(getServices());
owners.load();
- assertFalse(owners.hasDeviceOwner());
- assertEquals(UserHandle.USER_NULL, owners.getDeviceOwnerUserId());
+ assertThat(owners.hasDeviceOwner()).isFalse();
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
- assertNull(owners.getSystemUpdatePolicy());
- assertEquals(0, owners.getProfileOwnerKeys().size());
+ assertThat(owners.getSystemUpdatePolicy()).isNull();
+ assertThat(owners.getProfileOwnerKeys()).isEmpty();
- assertFalse(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
}
}
+ @Test
public void testUpgrade06() throws Exception {
getServices().addUsers(10, 11, 20, 21);
@@ -403,26 +415,26 @@ public class OwnersTest extends DpmTestBase {
owners.load();
// The legacy file should be removed.
- assertFalse(owners.getLegacyConfigFile().exists());
+ assertThat(owners.getLegacyConfigFile().exists()).isFalse();
- assertTrue(owners.getDeviceOwnerFile().exists());
+ assertThat(owners.getDeviceOwnerFile().exists()).isTrue();
- assertFalse(owners.getProfileOwnerFile(10).exists());
- assertFalse(owners.getProfileOwnerFile(11).exists());
- assertFalse(owners.getProfileOwnerFile(20).exists());
+ assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
- assertFalse(owners.hasDeviceOwner());
- assertEquals(UserHandle.USER_NULL, owners.getDeviceOwnerUserId());
- assertEquals(0, owners.getProfileOwnerKeys().size());
+ assertThat(owners.hasDeviceOwner()).isFalse();
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
+ assertThat(owners.getProfileOwnerKeys()).isEmpty();
- assertNotNull(owners.getSystemUpdatePolicy());
- assertEquals(5, owners.getSystemUpdatePolicy().getPolicyType());
+ assertThat(owners.getSystemUpdatePolicy()).isNotNull();
+ assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(5);
- assertFalse(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
}
// Then re-read and check.
@@ -430,21 +442,22 @@ public class OwnersTest extends DpmTestBase {
final OwnersTestable owners = new OwnersTestable(getServices());
owners.load();
- assertFalse(owners.hasDeviceOwner());
- assertEquals(UserHandle.USER_NULL, owners.getDeviceOwnerUserId());
- assertEquals(0, owners.getProfileOwnerKeys().size());
+ assertThat(owners.hasDeviceOwner()).isFalse();
+ assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
+ assertThat(owners.getProfileOwnerKeys()).isEmpty();
- assertNotNull(owners.getSystemUpdatePolicy());
- assertEquals(5, owners.getSystemUpdatePolicy().getPolicyType());
+ assertThat(owners.getSystemUpdatePolicy()).isNotNull();
+ assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(5);
- assertFalse(owners.getDeviceOwnerUserRestrictionsNeedsMigration());
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(10));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(11));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(20));
- assertFalse(owners.getProfileOwnerUserRestrictionsNeedsMigration(21));
+ assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
+ assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
}
}
+ @Test
public void testRemoveExistingFiles() throws Exception {
getServices().addUsers(10, 11, 20, 21);
@@ -456,11 +469,11 @@ public class OwnersTest extends DpmTestBase {
owners.load();
- assertFalse(owners.getLegacyConfigFile().exists());
+ assertThat(owners.getLegacyConfigFile().exists()).isFalse();
- assertTrue(owners.getDeviceOwnerFile().exists());
- assertTrue(owners.getProfileOwnerFile(10).exists());
- assertTrue(owners.getProfileOwnerFile(11).exists());
+ assertThat(owners.getDeviceOwnerFile().exists()).isTrue();
+ assertThat(owners.getProfileOwnerFile(10).exists()).isTrue();
+ assertThat(owners.getProfileOwnerFile(11).exists()).isTrue();
// Then clear all information and save.
owners.clearDeviceOwner();
@@ -475,8 +488,8 @@ public class OwnersTest extends DpmTestBase {
owners.writeProfileOwner(21);
// Now all files should be removed.
- assertFalse(owners.getDeviceOwnerFile().exists());
- assertFalse(owners.getProfileOwnerFile(10).exists());
- assertFalse(owners.getProfileOwnerFile(11).exists());
+ assertThat(owners.getDeviceOwnerFile().exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
+ assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
}
}
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/SecurityEventTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/SecurityEventTest.java
index 8dcf21f9fe77b..6cefaebbff7a6 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/SecurityEventTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/SecurityEventTest.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.android.server.devicepolicy;
import static android.app.admin.SecurityLog.TAG_ADB_SHELL_CMD;
@@ -11,6 +26,8 @@ import static android.app.admin.SecurityLog.TAG_KEY_INTEGRITY_VIOLATION;
import static android.app.admin.SecurityLog.TAG_MEDIA_MOUNT;
import static android.app.admin.SecurityLog.TAG_MEDIA_UNMOUNT;
+import static com.google.common.truth.Truth.assertThat;
+
import android.app.admin.SecurityLog.SecurityEvent;
import android.os.Parcel;
import android.os.UserHandle;
@@ -18,21 +35,37 @@ import android.text.TextUtils;
import android.util.EventLog;
import android.util.EventLog.Event;
+import androidx.test.runner.AndroidJUnit4;
+
import junit.framework.AssertionFailedError;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import java.util.ArrayList;
import java.util.List;
+/**
+ * Tests for the DeviceOwner object that saves & loads device and policy owner information.
+ *
+ * Run this test with:
+ *
+ * {@code atest FrameworksServicesTests:com.android.server.devicepolicy.SecurityEventTest}
+ *
+ */
+@RunWith(AndroidJUnit4.class)
public class SecurityEventTest extends DpmTestBase {
+ @Test
public void testSecurityEventId() throws Exception {
SecurityEvent event = createEvent(() -> {
EventLog.writeEvent(TAG_ADB_SHELL_CMD, 0);
}, TAG_ADB_SHELL_CMD);
event.setId(20);
- assertEquals(20, event.getId());
+ assertThat(event.getId()).isEqualTo(20);
}
+ @Test
public void testSecurityEventParceling() throws Exception {
// GIVEN an event.
SecurityEvent event = createEvent(() -> {
@@ -45,12 +78,13 @@ public class SecurityEventTest extends DpmTestBase {
SecurityEvent unparceledEvent = p.readParcelable(SecurityEventTest.class.getClassLoader());
p.recycle();
// THEN the event state is preserved.
- assertEquals(event.getTag(), unparceledEvent.getTag());
- assertEquals(event.getData(), unparceledEvent.getData());
- assertEquals(event.getTimeNanos(), unparceledEvent.getTimeNanos());
- assertEquals(event.getId(), unparceledEvent.getId());
+ assertThat(unparceledEvent.getTag()).isEqualTo(event.getTag());
+ assertThat(unparceledEvent.getData()).isEqualTo(event.getData());
+ assertThat(unparceledEvent.getTimeNanos()).isEqualTo(event.getTimeNanos());
+ assertThat(unparceledEvent.getId()).isEqualTo(event.getId());
}
+ @Test
public void testSecurityEventRedaction() throws Exception {
SecurityEvent event;
@@ -58,75 +92,75 @@ public class SecurityEventTest extends DpmTestBase {
event = createEvent(() -> {
EventLog.writeEvent(TAG_ADB_SHELL_CMD, "command");
}, TAG_ADB_SHELL_CMD);
- assertFalse(TextUtils.isEmpty((String) event.getData()));
+ assertThat(TextUtils.isEmpty((String) event.getData())).isFalse();
// TAG_MEDIA_MOUNT will have the volume label redacted (second data)
event = createEvent(() -> {
EventLog.writeEvent(TAG_MEDIA_MOUNT, new Object[] {"path", "label"});
}, TAG_MEDIA_MOUNT);
- assertFalse(TextUtils.isEmpty(event.getStringData(1)));
- assertTrue(TextUtils.isEmpty(event.redact(0).getStringData(1)));
+ assertThat(TextUtils.isEmpty(event.getStringData(1))).isFalse();
+ assertThat(TextUtils.isEmpty(event.redact(0).getStringData(1))).isTrue();
// TAG_MEDIA_UNMOUNT will have the volume label redacted (second data)
event = createEvent(() -> {
EventLog.writeEvent(TAG_MEDIA_UNMOUNT, new Object[] {"path", "label"});
}, TAG_MEDIA_UNMOUNT);
- assertFalse(TextUtils.isEmpty(event.getStringData(1)));
- assertTrue(TextUtils.isEmpty(event.redact(0).getStringData(1)));
+ assertThat(TextUtils.isEmpty(event.getStringData(1))).isFalse();
+ assertThat(TextUtils.isEmpty(event.redact(0).getStringData(1))).isTrue();
// TAG_APP_PROCESS_START will be fully redacted if user does not match
event = createEvent(() -> {
EventLog.writeEvent(TAG_APP_PROCESS_START, new Object[] {"process", 12345L,
UserHandle.getUid(10, 123), 456, "seinfo", "hash"});
}, TAG_APP_PROCESS_START);
- assertNotNull(event.redact(10));
- assertNull(event.redact(11));
+ assertThat(event.redact(10)).isNotNull();
+ assertThat(event.redact(11)).isNull();
// TAG_CERT_AUTHORITY_INSTALLED will be fully redacted if user does not match
event = createEvent(() -> {
EventLog.writeEvent(TAG_CERT_AUTHORITY_INSTALLED, new Object[] {1, "subject", 10});
}, TAG_CERT_AUTHORITY_INSTALLED);
- assertNotNull(event.redact(10));
- assertNull(event.redact(11));
+ assertThat(event.redact(10)).isNotNull();
+ assertThat(event.redact(11)).isNull();
// TAG_CERT_AUTHORITY_REMOVED will be fully redacted if user does not match
event = createEvent(() -> {
EventLog.writeEvent(TAG_CERT_AUTHORITY_REMOVED, new Object[] {1, "subject", 20});
}, TAG_CERT_AUTHORITY_REMOVED);
- assertNotNull(event.redact(20));
- assertNull(event.redact(0));
+ assertThat(event.redact(20)).isNotNull();
+ assertThat(event.redact(0)).isNull();
// TAG_KEY_GENERATED will be fully redacted if user does not match
event = createEvent(() -> {
EventLog.writeEvent(TAG_KEY_GENERATED,
new Object[] {1, "alias", UserHandle.getUid(0, 123)});
}, TAG_KEY_GENERATED);
- assertNotNull(event.redact(0));
- assertNull(event.redact(10));
+ assertThat(event.redact(0)).isNotNull();
+ assertThat(event.redact(10)).isNull();
// TAG_KEY_IMPORT will be fully redacted if user does not match
event = createEvent(() -> {
EventLog.writeEvent(TAG_KEY_IMPORT,
new Object[] {1, "alias", UserHandle.getUid(1, 123)});
}, TAG_KEY_IMPORT);
- assertNotNull(event.redact(1));
- assertNull(event.redact(10));
+ assertThat(event.redact(1)).isNotNull();
+ assertThat(event.redact(10)).isNull();
// TAG_KEY_DESTRUCTION will be fully redacted if user does not match
event = createEvent(() -> {
EventLog.writeEvent(TAG_KEY_DESTRUCTION,
new Object[] {1, "alias", UserHandle.getUid(2, 123)});
}, TAG_KEY_DESTRUCTION);
- assertNotNull(event.redact(2));
- assertNull(event.redact(10));
+ assertThat(event.redact(2)).isNotNull();
+ assertThat(event.redact(10)).isNull();
// TAG_KEY_INTEGRITY_VIOLATION will be fully redacted if user does not match
event = createEvent(() -> {
EventLog.writeEvent(TAG_KEY_INTEGRITY_VIOLATION,
new Object[] {"alias", UserHandle.getUid(2, 123)});
}, TAG_KEY_INTEGRITY_VIOLATION);
- assertNotNull(event.redact(2));
- assertNull(event.redact(10));
+ assertThat(event.redact(2)).isNotNull();
+ assertThat(event.redact(10)).isNull();
}
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/SystemUpdatePolicyTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/SystemUpdatePolicyTest.java
index e51859b5c8299..0a9aad771ff04 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/SystemUpdatePolicyTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/SystemUpdatePolicyTest.java
@@ -21,8 +21,9 @@ import static android.app.admin.SystemUpdatePolicy.ValidationFailedException.ERR
import static android.app.admin.SystemUpdatePolicy.ValidationFailedException.ERROR_NEW_FREEZE_PERIOD_TOO_CLOSE;
import static android.app.admin.SystemUpdatePolicy.ValidationFailedException.ERROR_NEW_FREEZE_PERIOD_TOO_LONG;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
+
import static org.junit.Assert.fail;
import android.app.admin.FreezePeriod;
@@ -53,10 +54,12 @@ import java.util.concurrent.TimeUnit;
/**
* Unit tests for {@link android.app.admin.SystemUpdatePolicy}.
- * Throughout this test, we use "MM-DD" format to denote dates without year.
*
- * atest com.android.server.devicepolicy.SystemUpdatePolicyTest
- * runtest -c com.android.server.devicepolicy.SystemUpdatePolicyTest frameworks-services
+ * NOTE: Throughout this test, we use {@code "MM-DD"} format to denote dates without year.
+ *
+ * Run this test with:
+ *
+ * {@code atest FrameworksServicesTests:com.android.server.devicepolicy.SystemUpdatePolicyTest}
*/
@RunWith(AndroidJUnit4.class)
public final class SystemUpdatePolicyTest {
@@ -224,37 +227,37 @@ public final class SystemUpdatePolicyTest {
@Test
public void testDistanceWithoutLeapYear() {
- assertEquals(364, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2016, 12, 31), LocalDate.of(2016, 1, 1)));
- assertEquals(365, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2017, 1, 1), LocalDate.of(2016, 1, 1)));
- assertEquals(365, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2017, 2, 28), LocalDate.of(2016, 2, 29)));
- assertEquals(-365, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2016, 1, 1), LocalDate.of(2017, 1, 1)));
- assertEquals(1, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2016, 3, 1), LocalDate.of(2016, 2, 29)));
- assertEquals(1, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2016, 3, 1), LocalDate.of(2016, 2, 28)));
- assertEquals(0, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2016, 2, 29), LocalDate.of(2016, 2, 28)));
- assertEquals(0, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2016, 2, 28), LocalDate.of(2016, 2, 28)));
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2016, 12, 31), LocalDate.of(2016, 1, 1))).isEqualTo(364);
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2017, 1, 1), LocalDate.of(2016, 1, 1))).isEqualTo(365);
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2017, 2, 28), LocalDate.of(2016, 2, 29))).isEqualTo(365);
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2016, 1, 1), LocalDate.of(2017, 1, 1))).isEqualTo(-365);
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2016, 3, 1), LocalDate.of(2016, 2, 29))).isEqualTo(1);
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2016, 3, 1), LocalDate.of(2016, 2, 28))).isEqualTo(1);
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2016, 2, 29), LocalDate.of(2016, 2, 28))).isEqualTo(0);
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2016, 2, 28), LocalDate.of(2016, 2, 28))).isEqualTo(0);
- assertEquals(59, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2016, 3, 1), LocalDate.of(2016, 1, 1)));
- assertEquals(59, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2017, 3, 1), LocalDate.of(2017, 1, 1)));
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2016, 3, 1), LocalDate.of(2016, 1, 1))).isEqualTo(59);
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2017, 3, 1), LocalDate.of(2017, 1, 1))).isEqualTo(59);
- assertEquals(365 * 40, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2040, 1, 1), LocalDate.of(2000, 1, 1)));
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2040, 1, 1), LocalDate.of(2000, 1, 1))).isEqualTo(365 * 40);
- assertEquals(365 * 2, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2019, 3, 1), LocalDate.of(2017, 3, 1)));
- assertEquals(365 * 2, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2018, 3, 1), LocalDate.of(2016, 3, 1)));
- assertEquals(365 * 2, FreezePeriod.distanceWithoutLeapYear(
- LocalDate.of(2017, 3, 1), LocalDate.of(2015, 3, 1)));
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2019, 3, 1), LocalDate.of(2017, 3, 1))).isEqualTo(365 * 2);
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2018, 3, 1), LocalDate.of(2016, 3, 1))).isEqualTo(365 * 2);
+ assertThat(FreezePeriod.distanceWithoutLeapYear(
+ LocalDate.of(2017, 3, 1), LocalDate.of(2015, 3, 1))).isEqualTo(365 * 2);
}
@@ -395,8 +398,8 @@ public final class SystemUpdatePolicyTest {
private void assertInstallationOption(int expectedType, long expectedTime, long now,
SystemUpdatePolicy p) {
- assertEquals(expectedType, p.getInstallationOptionAt(now).getType());
- assertEquals(expectedTime, p.getInstallationOptionAt(now).getEffectiveTime());
+ assertThat(p.getInstallationOptionAt(now).getType()).isEqualTo(expectedType);
+ assertThat(p.getInstallationOptionAt(now).getEffectiveTime()).isEqualTo(expectedTime);
}
private void testFreezePeriodsSucceeds(String...dates) throws Exception {
@@ -410,8 +413,8 @@ public final class SystemUpdatePolicyTest {
setFreezePeriods(p, dates);
fail("Invalid periods (" + expectedError + ") not flagged: " + String.join(" ", dates));
} catch (SystemUpdatePolicy.ValidationFailedException e) {
- assertTrue("Exception not expected: " + e.getMessage(),
- e.getErrorCode() == expectedError);
+ assertWithMessage("Exception not expected: %s", e.getMessage()).that(e.getErrorCode())
+ .isEqualTo(expectedError);
}
}
@@ -426,8 +429,8 @@ public final class SystemUpdatePolicyTest {
createPrevFreezePeriod(prevStart, prevEnd, now, dates);
fail("Invalid period (" + expectedError + ") not flagged: " + String.join(" ", dates));
} catch (SystemUpdatePolicy.ValidationFailedException e) {
- assertTrue("Exception not expected: " + e.getMessage(),
- e.getErrorCode() == expectedError);
+ assertWithMessage("Exception not expected: %s", e.getMessage()).that(e.getErrorCode())
+ .isEqualTo(expectedError);
}
}
@@ -480,7 +483,7 @@ public final class SystemUpdatePolicyTest {
ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
XmlPullParser parser = Xml.newPullParser();
parser.setInput(new InputStreamReader(inStream));
- assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertThat(parser.next()).isEqualTo(XmlPullParser.START_TAG);
checkFreezePeriods(SystemUpdatePolicy.restoreFromXml(parser), expectedPeriods);
}
@@ -488,8 +491,8 @@ public final class SystemUpdatePolicyTest {
List Run this test with:
+ *
+ * >) invocation -> Collections.singletonList(
@@ -2626,51 +2688,53 @@ public class DevicePolicyManagerTest extends DpmTestBase {
eq(UserManager.DISALLOW_ADJUST_VOLUME),
eq(UserHandle.of(UserHandle.myUserId())));
intent = dpm.createAdminSupportIntent(UserManager.DISALLOW_ADJUST_VOLUME);
- assertNotNull(intent);
- assertEquals(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS, intent.getAction());
- assertEquals(UserHandle.getUserId(DpmMockContext.CALLER_SYSTEM_USER_UID),
- intent.getIntExtra(Intent.EXTRA_USER_ID, -1));
- assertEquals(admin1, intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN));
- assertEquals(UserManager.DISALLOW_ADJUST_VOLUME,
- intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION));
+ assertThat(intent).isNotNull();
+ assertThat(intent.getAction()).isEqualTo(Settings.ACTION_SHOW_ADMIN_SUPPORT_DETAILS);
+ assertThat(intent.getIntExtra(Intent.EXTRA_USER_ID, -1))
+ .isEqualTo(UserHandle.getUserId(DpmMockContext.CALLER_SYSTEM_USER_UID));
+ assertThat(
+ (ComponentName) intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN))
+ .isEqualTo(admin1);
+ assertThat(intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION))
+ .isEqualTo(UserManager.DISALLOW_ADJUST_VOLUME);
// Try with POLICY_DISABLE_CAMERA and POLICY_DISABLE_SCREEN_CAPTURE, which are not
// user restrictions
// Camera is not disabled
intent = dpm.createAdminSupportIntent(DevicePolicyManager.POLICY_DISABLE_CAMERA);
- assertNull(intent);
+ assertThat(intent).isNull();
// Camera is disabled
dpm.setCameraDisabled(admin1, true);
intent = dpm.createAdminSupportIntent(DevicePolicyManager.POLICY_DISABLE_CAMERA);
- assertNotNull(intent);
- assertEquals(DevicePolicyManager.POLICY_DISABLE_CAMERA,
- intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION));
+ assertThat(intent).isNotNull();
+ assertThat(intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION))
+ .isEqualTo(DevicePolicyManager.POLICY_DISABLE_CAMERA);
// Screen capture is not disabled
intent = dpm.createAdminSupportIntent(DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE);
- assertNull(intent);
+ assertThat(intent).isNull();
// Screen capture is disabled
dpm.setScreenCaptureDisabled(admin1, true);
intent = dpm.createAdminSupportIntent(DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE);
- assertNotNull(intent);
- assertEquals(DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE,
- intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION));
+ assertThat(intent).isNotNull();
+ assertThat(intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION))
+ .isEqualTo(DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE);
// Same checks for different user
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
// Camera should be disabled by device owner
intent = dpm.createAdminSupportIntent(DevicePolicyManager.POLICY_DISABLE_CAMERA);
- assertNotNull(intent);
- assertEquals(DevicePolicyManager.POLICY_DISABLE_CAMERA,
- intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION));
- assertEquals(UserHandle.getUserId(DpmMockContext.CALLER_SYSTEM_USER_UID),
- intent.getIntExtra(Intent.EXTRA_USER_ID, -1));
+ assertThat(intent).isNotNull();
+ assertThat(intent.getStringExtra(DevicePolicyManager.EXTRA_RESTRICTION))
+ .isEqualTo(DevicePolicyManager.POLICY_DISABLE_CAMERA);
+ assertThat(intent.getIntExtra(Intent.EXTRA_USER_ID, -1))
+ .isEqualTo(UserHandle.getUserId(DpmMockContext.CALLER_SYSTEM_USER_UID));
// ScreenCapture should not be disabled by device owner
intent = dpm.createAdminSupportIntent(DevicePolicyManager.POLICY_DISABLE_SCREEN_CAPTURE);
- assertNull(intent);
+ assertThat(intent).isNull();
}
/**
@@ -2679,6 +2743,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
* {@link DevicePolicyManager#getAffiliationIds}
* {@link DevicePolicyManager#isAffiliatedUser}
*/
+ @Test
public void testUserAffiliation() throws Exception {
mContext.callerPermissions.add(permission.MANAGE_DEVICE_ADMINS);
mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
@@ -2686,20 +2751,20 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// Check that the system user is unaffiliated.
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
- assertFalse(dpm.isAffiliatedUser());
+ assertThat(dpm.isAffiliatedUser()).isFalse();
// Set a device owner on the system user. Check that the system user becomes affiliated.
setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
dpm.setActiveAdmin(admin1, /* replace =*/ false);
- assertTrue(dpm.setDeviceOwner(admin1, "owner-name"));
- assertTrue(dpm.isAffiliatedUser());
- assertTrue(dpm.getAffiliationIds(admin1).isEmpty());
+ assertThat(dpm.setDeviceOwner(admin1, "owner-name")).isTrue();
+ assertThat(dpm.isAffiliatedUser()).isTrue();
+ assertThat(dpm.getAffiliationIds(admin1).isEmpty()).isTrue();
// Install a profile owner. Check that the test user is unaffiliated.
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
setAsProfileOwner(admin2);
- assertFalse(dpm.isAffiliatedUser());
- assertTrue(dpm.getAffiliationIds(admin2).isEmpty());
+ assertThat(dpm.isAffiliatedUser()).isFalse();
+ assertThat(dpm.getAffiliationIds(admin2).isEmpty()).isTrue();
// Have the profile owner specify a set of affiliation ids. Check that the test user remains
// unaffiliated.
@@ -2709,7 +2774,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
userAffiliationIds.add("blue");
dpm.setAffiliationIds(admin2, userAffiliationIds);
MoreAsserts.assertContentsInAnyOrder(dpm.getAffiliationIds(admin2), "red", "green", "blue");
- assertFalse(dpm.isAffiliatedUser());
+ assertThat(dpm.isAffiliatedUser()).isFalse();
// Have the device owner specify a set of affiliation ids that do not intersect with those
// specified by the profile owner. Check that the test user remains unaffiliated.
@@ -2722,7 +2787,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
MoreAsserts.assertContentsInAnyOrder(
dpm.getAffiliationIds(admin1), "cyan", "yellow", "magenta");
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
- assertFalse(dpm.isAffiliatedUser());
+ assertThat(dpm.isAffiliatedUser()).isFalse();
// Have the profile owner specify a set of affiliation ids that intersect with those
// specified by the device owner. Check that the test user becomes affiliated.
@@ -2730,33 +2795,36 @@ public class DevicePolicyManagerTest extends DpmTestBase {
dpm.setAffiliationIds(admin2, userAffiliationIds);
MoreAsserts.assertContentsInAnyOrder(
dpm.getAffiliationIds(admin2), "red", "green", "blue", "yellow");
- assertTrue(dpm.isAffiliatedUser());
+ assertThat(dpm.isAffiliatedUser()).isTrue();
// Clear affiliation ids for the profile owner. The user becomes unaffiliated.
dpm.setAffiliationIds(admin2, Collections.emptySet());
- assertTrue(dpm.getAffiliationIds(admin2).isEmpty());
- assertFalse(dpm.isAffiliatedUser());
+ assertThat(dpm.getAffiliationIds(admin2).isEmpty()).isTrue();
+ assertThat(dpm.isAffiliatedUser()).isFalse();
// Set affiliation ids again, then clear PO to check that the user becomes unaffiliated
dpm.setAffiliationIds(admin2, userAffiliationIds);
- assertTrue(dpm.isAffiliatedUser());
+ assertThat(dpm.isAffiliatedUser()).isTrue();
dpm.clearProfileOwner(admin2);
- assertFalse(dpm.isAffiliatedUser());
+ assertThat(dpm.isAffiliatedUser()).isFalse();
// Check that the system user remains affiliated.
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
- assertTrue(dpm.isAffiliatedUser());
+ assertThat(dpm.isAffiliatedUser()).isTrue();
// Clear the device owner - the user becomes unaffiliated.
clearDeviceOwner();
- assertFalse(dpm.isAffiliatedUser());
+ assertThat(dpm.isAffiliatedUser()).isFalse();
}
+ @Test
public void testGetUserProvisioningState_defaultResult() {
mContext.callerPermissions.add(permission.MANAGE_USERS);
- assertEquals(DevicePolicyManager.STATE_USER_UNMANAGED, dpm.getUserProvisioningState());
+ assertThat(dpm.getUserProvisioningState())
+ .isEqualTo(DevicePolicyManager.STATE_USER_UNMANAGED);
}
+ @Test
public void testSetUserProvisioningState_permission() throws Exception {
setupProfileOwner();
@@ -2764,6 +2832,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.STATE_USER_SETUP_FINALIZED);
}
+ @Test
public void testSetUserProvisioningState_unprivileged() throws Exception {
setupProfileOwner();
assertExpectException(SecurityException.class, /* messageRegex =*/ null,
@@ -2771,6 +2840,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
CALLER_USER_HANDLE));
}
+ @Test
public void testSetUserProvisioningState_noManagement() {
mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
mContext.callerPermissions.add(permission.MANAGE_USERS);
@@ -2778,9 +2848,11 @@ public class DevicePolicyManagerTest extends DpmTestBase {
/* messageRegex= */ "change provisioning state unless a .* owner is set",
() -> dpm.setUserProvisioningState(DevicePolicyManager.STATE_USER_SETUP_FINALIZED,
CALLER_USER_HANDLE));
- assertEquals(DevicePolicyManager.STATE_USER_UNMANAGED, dpm.getUserProvisioningState());
+ assertThat(dpm.getUserProvisioningState())
+ .isEqualTo(DevicePolicyManager.STATE_USER_UNMANAGED);
}
+ @Test
public void testSetUserProvisioningState_deviceOwnerFromSetupWizard() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -2790,6 +2862,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.STATE_USER_SETUP_FINALIZED);
}
+ @Test
public void testSetUserProvisioningState_deviceOwnerFromSetupWizardAlternative()
throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
@@ -2800,6 +2873,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.STATE_USER_SETUP_FINALIZED);
}
+ @Test
public void testSetUserProvisioningState_deviceOwnerWithoutSetupWizard() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -2808,6 +2882,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.STATE_USER_SETUP_FINALIZED);
}
+ @Test
public void testSetUserProvisioningState_managedProfileFromSetupWizard_primaryUser()
throws Exception {
setupProfileOwner();
@@ -2817,6 +2892,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.STATE_USER_PROFILE_FINALIZED);
}
+ @Test
public void testSetUserProvisioningState_managedProfileFromSetupWizard_managedProfile()
throws Exception {
setupProfileOwner();
@@ -2826,6 +2902,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.STATE_USER_SETUP_FINALIZED);
}
+ @Test
public void testSetUserProvisioningState_managedProfileWithoutSetupWizard() throws Exception {
setupProfileOwner();
@@ -2833,6 +2910,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.STATE_USER_SETUP_FINALIZED);
}
+ @Test
public void testSetUserProvisioningState_illegalTransitionOutOfFinalized1() throws Exception {
setupProfileOwner();
@@ -2843,6 +2921,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.STATE_USER_UNMANAGED));
}
+ @Test
public void testSetUserProvisioningState_illegalTransitionToAnotherInProgressState()
throws Exception {
setupProfileOwner();
@@ -2858,10 +2937,11 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
mContext.callerPermissions.add(permission.MANAGE_USERS);
- assertEquals(DevicePolicyManager.STATE_USER_UNMANAGED, dpm.getUserProvisioningState());
+ assertThat(dpm.getUserProvisioningState())
+ .isEqualTo(DevicePolicyManager.STATE_USER_UNMANAGED);
for (int state : states) {
dpm.setUserProvisioningState(state, userId);
- assertEquals(state, dpm.getUserProvisioningState());
+ assertThat(dpm.getUserProvisioningState()).isEqualTo(state);
}
}
@@ -2870,7 +2950,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_UID);
dpm.setActiveAdmin(admin1, false);
- assertTrue(dpm.setProfileOwner(admin1, null, CALLER_USER_HANDLE));
+ assertThat(dpm.setProfileOwner(admin1, null, CALLER_USER_HANDLE)).isTrue();
mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS);
}
@@ -2880,7 +2960,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
setUpPackageManagerForAdmin(admin1, DpmMockContext.SYSTEM_UID);
dpm.setActiveAdmin(admin1, false);
- assertTrue(dpm.setProfileOwner(admin1, null, UserHandle.USER_SYSTEM));
+ assertThat(dpm.setProfileOwner(admin1, null, UserHandle.USER_SYSTEM)).isTrue();
mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS);
}
@@ -2890,11 +2970,12 @@ public class DevicePolicyManagerTest extends DpmTestBase {
setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
dpm.setActiveAdmin(admin1, false);
- assertTrue(dpm.setDeviceOwner(admin1, null, UserHandle.USER_SYSTEM));
+ assertThat(dpm.setDeviceOwner(admin1, null, UserHandle.USER_SYSTEM)).isTrue();
mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS);
}
+ @Test
public void testSetMaximumTimeToLock() {
mContext.callerPermissions.add(android.Manifest.permission.MANAGE_DEVICE_ADMINS);
@@ -2956,6 +3037,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verifyStayOnWhilePluggedCleared(false);
}
+ @Test
public void testIsActiveSupervisionApp() throws Exception {
when(mServiceContext.resources
.getString(R.string.config_defaultSupervisionProfileOwnerComponent))
@@ -2968,11 +3050,12 @@ public class DevicePolicyManagerTest extends DpmTestBase {
final DevicePolicyManagerInternal dpmi =
LocalServices.getService(DevicePolicyManagerInternal.class);
- assertTrue(dpmi.isActiveSupervisionApp(PROFILE_ADMIN));
+ assertThat(dpmi.isActiveSupervisionApp(PROFILE_ADMIN)).isTrue();
}
// Test if lock timeout on managed profile is handled correctly depending on whether profile
// uses separate challenge.
+ @Test
public void testSetMaximumTimeToLockProfile() throws Exception {
final int PROFILE_USER = 15;
final int PROFILE_ADMIN = UserHandle.getUid(PROFILE_USER, 19436);
@@ -3039,6 +3122,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verifyScreenTimeoutCall(Long.MAX_VALUE, UserHandle.USER_SYSTEM);
}
+ @Test
public void testSetRequiredStrongAuthTimeout_DeviceOwner() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -3055,8 +3139,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
getServices().buildMock.isDebuggable = false;
dpm.setRequiredStrongAuthTimeout(admin1, MAX_MINUS_ONE_MINUTE);
- assertEquals(dpm.getRequiredStrongAuthTimeout(admin1), MAX_MINUS_ONE_MINUTE);
- assertEquals(dpm.getRequiredStrongAuthTimeout(null), MAX_MINUS_ONE_MINUTE);
+ assertThat(MAX_MINUS_ONE_MINUTE).isEqualTo(dpm.getRequiredStrongAuthTimeout(admin1));
+ assertThat(MAX_MINUS_ONE_MINUTE).isEqualTo(dpm.getRequiredStrongAuthTimeout(null));
verify(getServices().systemProperties, never()).getLong(anyString(), anyLong());
@@ -3067,45 +3151,47 @@ public class DevicePolicyManagerTest extends DpmTestBase {
dpm.setRequiredStrongAuthTimeout(admin1, 0);
// aggregation should be the default if unset by any admin
- assertEquals(dpm.getRequiredStrongAuthTimeout(null),
- DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS);
+ assertThat(DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS)
+ .isEqualTo(dpm.getRequiredStrongAuthTimeout(null));
// admin not participating by default
- assertEquals(dpm.getRequiredStrongAuthTimeout(admin1), 0);
+ assertThat(dpm.getRequiredStrongAuthTimeout(admin1)).isEqualTo(0);
//clamping from the top
dpm.setRequiredStrongAuthTimeout(admin1,
DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS + ONE_MINUTE);
- assertEquals(dpm.getRequiredStrongAuthTimeout(admin1),
- DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS);
- assertEquals(dpm.getRequiredStrongAuthTimeout(null),
- DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS);
+ assertThat(DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS)
+ .isEqualTo(dpm.getRequiredStrongAuthTimeout(admin1));
+ assertThat(DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS)
+ .isEqualTo(dpm.getRequiredStrongAuthTimeout(null));
// 0 means the admin is not participating, so default should be returned
dpm.setRequiredStrongAuthTimeout(admin1, 0);
- assertEquals(dpm.getRequiredStrongAuthTimeout(admin1), 0);
- assertEquals(dpm.getRequiredStrongAuthTimeout(null),
- DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS);
+ assertThat(dpm.getRequiredStrongAuthTimeout(admin1)).isEqualTo(0);
+ assertThat(DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS)
+ .isEqualTo(dpm.getRequiredStrongAuthTimeout(null));
// clamping from the bottom
dpm.setRequiredStrongAuthTimeout(admin1, MINIMUM_STRONG_AUTH_TIMEOUT_MS - ONE_MINUTE);
- assertEquals(dpm.getRequiredStrongAuthTimeout(admin1), MINIMUM_STRONG_AUTH_TIMEOUT_MS);
- assertEquals(dpm.getRequiredStrongAuthTimeout(null), MINIMUM_STRONG_AUTH_TIMEOUT_MS);
+ assertThat(dpm.getRequiredStrongAuthTimeout(admin1))
+ .isEqualTo(MINIMUM_STRONG_AUTH_TIMEOUT_MS);
+ assertThat(dpm.getRequiredStrongAuthTimeout(null))
+ .isEqualTo(MINIMUM_STRONG_AUTH_TIMEOUT_MS);
// values within range
dpm.setRequiredStrongAuthTimeout(admin1, MIN_PLUS_ONE_MINUTE);
- assertEquals(dpm.getRequiredStrongAuthTimeout(admin1), MIN_PLUS_ONE_MINUTE);
- assertEquals(dpm.getRequiredStrongAuthTimeout(null), MIN_PLUS_ONE_MINUTE);
+ assertThat(dpm.getRequiredStrongAuthTimeout(admin1)).isEqualTo(MIN_PLUS_ONE_MINUTE);
+ assertThat(dpm.getRequiredStrongAuthTimeout(null)).isEqualTo(MIN_PLUS_ONE_MINUTE);
dpm.setRequiredStrongAuthTimeout(admin1, MAX_MINUS_ONE_MINUTE);
- assertEquals(dpm.getRequiredStrongAuthTimeout(admin1), MAX_MINUS_ONE_MINUTE);
- assertEquals(dpm.getRequiredStrongAuthTimeout(null), MAX_MINUS_ONE_MINUTE);
+ assertThat(dpm.getRequiredStrongAuthTimeout(admin1)).isEqualTo(MAX_MINUS_ONE_MINUTE);
+ assertThat(dpm.getRequiredStrongAuthTimeout(null)).isEqualTo(MAX_MINUS_ONE_MINUTE);
// reset to default
dpm.setRequiredStrongAuthTimeout(admin1, 0);
- assertEquals(dpm.getRequiredStrongAuthTimeout(admin1), 0);
- assertEquals(dpm.getRequiredStrongAuthTimeout(null),
- DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS);
+ assertThat(dpm.getRequiredStrongAuthTimeout(admin1)).isEqualTo(0);
+ assertThat(DevicePolicyManager.DEFAULT_STRONG_AUTH_TIMEOUT_MS)
+ .isEqualTo(dpm.getRequiredStrongAuthTimeout(null));
// negative value
assertExpectException(IllegalArgumentException.class, /* messageRegex= */ null,
@@ -3130,8 +3216,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
private void setup_DeviceAdminFeatureOff() throws Exception {
when(getServices().packageManager.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN))
.thenReturn(false);
- when(getServices().ipackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0))
- .thenReturn(false);
+ when(getServices().ipackageManager
+ .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(false);
initializeDpms();
when(getServices().userManagerForMock.isSplitSystemUser()).thenReturn(false);
when(getServices().userManager.canAddMoreManagedProfiles(UserHandle.USER_SYSTEM, true))
@@ -3141,6 +3227,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
}
+ @Test
public void testIsProvisioningAllowed_DeviceAdminFeatureOff() throws Exception {
setup_DeviceAdminFeatureOff();
mContext.packageName = admin1.getPackageName();
@@ -3153,6 +3240,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
assertProvisioningAllowed(DevicePolicyManager.ACTION_PROVISION_MANAGED_USER, false);
}
+ @Test
public void testCheckProvisioningPreCondition_DeviceAdminFeatureOff() throws Exception {
setup_DeviceAdminFeatureOff();
mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
@@ -3170,8 +3258,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
}
private void setup_ManagedProfileFeatureOff() throws Exception {
- when(getServices().ipackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0))
- .thenReturn(false);
+ when(getServices().ipackageManager
+ .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(false);
initializeDpms();
when(getServices().userManagerForMock.isSplitSystemUser()).thenReturn(false);
when(getServices().userManager.canAddMoreManagedProfiles(UserHandle.USER_SYSTEM, true))
@@ -3181,6 +3269,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
}
+ @Test
public void testIsProvisioningAllowed_ManagedProfileFeatureOff() throws Exception {
setup_ManagedProfileFeatureOff();
mContext.packageName = admin1.getPackageName();
@@ -3202,6 +3291,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
assertProvisioningAllowed(DevicePolicyManager.ACTION_PROVISION_MANAGED_USER, false);
}
+ @Test
public void testCheckProvisioningPreCondition_ManagedProfileFeatureOff() throws Exception {
setup_ManagedProfileFeatureOff();
mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
@@ -3233,8 +3323,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
}
private void setup_nonSplitUser_firstBoot_primaryUser() throws Exception {
- when(getServices().ipackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0))
- .thenReturn(true);
+ when(getServices().ipackageManager
+ .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(true);
when(getServices().userManagerForMock.isSplitSystemUser()).thenReturn(false);
when(getServices().userManager.canAddMoreManagedProfiles(UserHandle.USER_SYSTEM, true))
.thenReturn(true);
@@ -3244,6 +3334,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
}
+ @Test
public void testIsProvisioningAllowed_nonSplitUser_firstBoot_primaryUser() throws Exception {
setup_nonSplitUser_firstBoot_primaryUser();
mContext.packageName = admin1.getPackageName();
@@ -3257,6 +3348,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
false /* because of non-split user */);
}
+ @Test
public void testCheckProvisioningPreCondition_nonSplitUser_firstBoot_primaryUser()
throws Exception {
setup_nonSplitUser_firstBoot_primaryUser();
@@ -3275,8 +3367,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
}
private void setup_nonSplitUser_afterDeviceSetup_primaryUser() throws Exception {
- when(getServices().ipackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0))
- .thenReturn(true);
+ when(getServices().ipackageManager
+ .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(true);
when(getServices().userManagerForMock.isSplitSystemUser()).thenReturn(false);
when(getServices().userManager.canAddMoreManagedProfiles(UserHandle.USER_SYSTEM, true))
.thenReturn(true);
@@ -3302,6 +3394,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
true)).thenReturn(true);
}
+ @Test
public void testIsProvisioningAllowed_nonSplitUser_afterDeviceSetup_primaryUser()
throws Exception {
setup_nonSplitUser_afterDeviceSetup_primaryUser();
@@ -3318,6 +3411,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
false/* because of non-split user */);
}
+ @Test
public void testCheckProvisioningPreCondition_nonSplitUser_afterDeviceSetup_primaryUser()
throws Exception {
setup_nonSplitUser_afterDeviceSetup_primaryUser();
@@ -3335,6 +3429,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.CODE_NOT_SYSTEM_USER_SPLIT);
}
+ @Test
public void testProvisioning_nonSplitUser_withDo_primaryUser() throws Exception {
setup_nonSplitUser_withDo_primaryUser();
mContext.packageName = admin1.getPackageName();
@@ -3361,6 +3456,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DpmMockContext.ANOTHER_PACKAGE_NAME, DpmMockContext.ANOTHER_UID);
}
+ @Test
public void testProvisioning_nonSplitUser_withDo_primaryUser_restrictedBySystem()
throws Exception {
setup_nonSplitUser_withDo_primaryUser();
@@ -3388,6 +3484,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DpmMockContext.ANOTHER_PACKAGE_NAME, DpmMockContext.ANOTHER_UID);
}
+ @Test
public void testCheckCannotSetProfileOwnerWithDeviceOwner() throws Exception {
setup_nonSplitUser_withDo_primaryUser();
final int managedProfileUserId = 18;
@@ -3399,10 +3496,11 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.callerPermissions.addAll(OWNER_SETUP_PERMISSIONS);
setUpPackageManagerForFakeAdmin(admin1, managedProfileAdminUid, admin1);
dpm.setActiveAdmin(admin1, false, userId);
- assertFalse(dpm.setProfileOwner(admin1, null, userId));
+ assertThat(dpm.setProfileOwner(admin1, null, userId)).isFalse();
mContext.callerPermissions.removeAll(OWNER_SETUP_PERMISSIONS);
}
+ @Test
public void testCheckProvisioningPreCondition_nonSplitUser_attemptingComp() throws Exception {
setup_nonSplitUser_withDo_primaryUser_ManagedProfile();
mContext.packageName = admin1.getPackageName();
@@ -3420,6 +3518,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DpmMockContext.ANOTHER_PACKAGE_NAME, DpmMockContext.ANOTHER_UID);
}
+ @Test
public void testCheckProvisioningPreCondition_nonSplitUser_comp_cannot_remove_profile()
throws Exception {
setup_nonSplitUser_withDo_primaryUser_ManagedProfile();
@@ -3449,8 +3548,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
}
private void setup_splitUser_firstBoot_systemUser() throws Exception {
- when(getServices().ipackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0))
- .thenReturn(true);
+ when(getServices().ipackageManager
+ .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(true);
when(getServices().userManagerForMock.isSplitSystemUser()).thenReturn(true);
when(getServices().userManager.canAddMoreManagedProfiles(UserHandle.USER_SYSTEM, true))
.thenReturn(false);
@@ -3459,6 +3558,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
}
+ @Test
public void testIsProvisioningAllowed_splitUser_firstBoot_systemUser() throws Exception {
setup_splitUser_firstBoot_systemUser();
mContext.packageName = admin1.getPackageName();
@@ -3473,6 +3573,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
false/* because calling uid is system user */);
}
+ @Test
public void testCheckProvisioningPreCondition_splitUser_firstBoot_systemUser()
throws Exception {
setup_splitUser_firstBoot_systemUser();
@@ -3491,8 +3592,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
}
private void setup_splitUser_afterDeviceSetup_systemUser() throws Exception {
- when(getServices().ipackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0))
- .thenReturn(true);
+ when(getServices().ipackageManager
+ .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(true);
when(getServices().userManagerForMock.isSplitSystemUser()).thenReturn(true);
when(getServices().userManager.canAddMoreManagedProfiles(UserHandle.USER_SYSTEM, true))
.thenReturn(false);
@@ -3501,6 +3602,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
}
+ @Test
public void testIsProvisioningAllowed_splitUser_afterDeviceSetup_systemUser() throws Exception {
setup_splitUser_afterDeviceSetup_systemUser();
mContext.packageName = admin1.getPackageName();
@@ -3517,6 +3619,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
false/* because calling uid is system user */);
}
+ @Test
public void testCheckProvisioningPreCondition_splitUser_afterDeviceSetup_systemUser()
throws Exception {
setup_splitUser_afterDeviceSetup_systemUser();
@@ -3535,8 +3638,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
}
private void setup_splitUser_firstBoot_primaryUser() throws Exception {
- when(getServices().ipackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0))
- .thenReturn(true);
+ when(getServices().ipackageManager
+ .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(true);
when(getServices().userManagerForMock.isSplitSystemUser()).thenReturn(true);
when(getServices().userManager.canAddMoreManagedProfiles(CALLER_USER_HANDLE,
true)).thenReturn(true);
@@ -3545,6 +3648,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
}
+ @Test
public void testIsProvisioningAllowed_splitUser_firstBoot_primaryUser() throws Exception {
setup_splitUser_firstBoot_primaryUser();
mContext.packageName = admin1.getPackageName();
@@ -3557,6 +3661,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
assertProvisioningAllowed(DevicePolicyManager.ACTION_PROVISION_MANAGED_USER, true);
}
+ @Test
public void testCheckProvisioningPreCondition_splitUser_firstBoot_primaryUser()
throws Exception {
setup_splitUser_firstBoot_primaryUser();
@@ -3575,8 +3680,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
}
private void setup_splitUser_afterDeviceSetup_primaryUser() throws Exception {
- when(getServices().ipackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0))
- .thenReturn(true);
+ when(getServices().ipackageManager
+ .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(true);
when(getServices().userManagerForMock.isSplitSystemUser()).thenReturn(true);
when(getServices().userManager.canAddMoreManagedProfiles(CALLER_USER_HANDLE,
true)).thenReturn(true);
@@ -3585,6 +3690,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
}
+ @Test
public void testIsProvisioningAllowed_splitUser_afterDeviceSetup_primaryUser()
throws Exception {
setup_splitUser_afterDeviceSetup_primaryUser();
@@ -3601,6 +3707,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
false/* because user setup completed */);
}
+ @Test
public void testCheckProvisioningPreCondition_splitUser_afterDeviceSetup_primaryUser()
throws Exception {
setup_splitUser_afterDeviceSetup_primaryUser();
@@ -3621,8 +3728,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
private void setup_provisionManagedProfileWithDeviceOwner_systemUser() throws Exception {
setDeviceOwner();
- when(getServices().ipackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0))
- .thenReturn(true);
+ when(getServices().ipackageManager
+ .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(true);
when(getServices().userManagerForMock.isSplitSystemUser()).thenReturn(true);
when(getServices().userManager.canAddMoreManagedProfiles(UserHandle.USER_SYSTEM, true))
.thenReturn(false);
@@ -3631,6 +3738,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
}
+ @Test
public void testIsProvisioningAllowed_provisionManagedProfileWithDeviceOwner_systemUser()
throws Exception {
setup_provisionManagedProfileWithDeviceOwner_systemUser();
@@ -3640,6 +3748,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
false /* can't provision managed profile on system user */);
}
+ @Test
public void testCheckProvisioningPreCondition_provisionManagedProfileWithDeviceOwner_systemUser()
throws Exception {
setup_provisionManagedProfileWithDeviceOwner_systemUser();
@@ -3651,8 +3760,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
private void setup_provisionManagedProfileWithDeviceOwner_primaryUser() throws Exception {
setDeviceOwner();
- when(getServices().ipackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0))
- .thenReturn(true);
+ when(getServices().ipackageManager
+ .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(true);
when(getServices().userManagerForMock.isSplitSystemUser()).thenReturn(false);
when(getServices().userManager.getProfileParent(CALLER_USER_HANDLE))
.thenReturn(new UserInfo(UserHandle.USER_SYSTEM, "user system", 0));
@@ -3663,6 +3772,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.ANOTHER_UID;
}
+ @Test
public void testIsProvisioningAllowed_provisionManagedProfileWithDeviceOwner_primaryUser()
throws Exception {
setup_provisionManagedProfileWithDeviceOwner_primaryUser();
@@ -3671,6 +3781,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
assertProvisioningAllowed(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE, false);
}
+ @Test
public void testCheckProvisioningPreCondition_provisionManagedProfileWithDeviceOwner_primaryUser()
throws Exception {
setup_provisionManagedProfileWithDeviceOwner_primaryUser();
@@ -3684,8 +3795,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
private void setup_provisionManagedProfileCantRemoveUser_primaryUser() throws Exception {
setDeviceOwner();
- when(getServices().ipackageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0))
- .thenReturn(true);
+ when(getServices().ipackageManager
+ .hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS, 0)).thenReturn(true);
when(getServices().userManagerForMock.isSplitSystemUser()).thenReturn(true);
when(getServices().userManager.hasUserRestriction(
eq(UserManager.DISALLOW_REMOVE_MANAGED_PROFILE),
@@ -3700,6 +3811,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
}
+ @Test
public void testIsProvisioningAllowed_provisionManagedProfileCantRemoveUser_primaryUser()
throws Exception {
setup_provisionManagedProfileCantRemoveUser_primaryUser();
@@ -3708,6 +3820,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
assertProvisioningAllowed(DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE, false);
}
+ @Test
public void testCheckProvisioningPreCondition_provisionManagedProfileCantRemoveUser_primaryUser()
throws Exception {
setup_provisionManagedProfileCantRemoveUser_primaryUser();
@@ -3716,6 +3829,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.CODE_CANNOT_ADD_MANAGED_PROFILE);
}
+ @Test
public void testCheckProvisioningPreCondition_permission() {
// GIVEN the permission MANAGE_PROFILE_AND_DEVICE_OWNERS is not granted
assertExpectException(SecurityException.class, /* messageRegex =*/ null,
@@ -3723,12 +3837,14 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE, "some.package"));
}
+ @Test
public void testForceUpdateUserSetupComplete_permission() {
// GIVEN the permission MANAGE_PROFILE_AND_DEVICE_OWNERS is not granted
assertExpectException(SecurityException.class, /* messageRegex =*/ null,
() -> dpm.forceUpdateUserSetupComplete());
}
+ @Test
public void testForceUpdateUserSetupComplete_systemUser() {
mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
// GIVEN calling from user 20
@@ -3737,6 +3853,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
() -> dpm.forceUpdateUserSetupComplete());
}
+ @Test
public void testForceUpdateUserSetupComplete_userbuild() {
mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
@@ -3753,14 +3870,15 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// GIVEN it's user build
getServices().buildMock.isDebuggable = false;
- assertTrue(dpms.hasUserSetupCompleted());
+ assertThat(dpms.hasUserSetupCompleted()).isTrue();
dpm.forceUpdateUserSetupComplete();
// THEN the state in dpms is not changed
- assertTrue(dpms.hasUserSetupCompleted());
+ assertThat(dpms.hasUserSetupCompleted()).isTrue();
}
+ @Test
public void testForceUpdateUserSetupComplete_userDebugbuild() {
mContext.callerPermissions.add(permission.MANAGE_PROFILE_AND_DEVICE_OWNERS);
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
@@ -3777,12 +3895,12 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// GIVEN it's userdebug build
getServices().buildMock.isDebuggable = true;
- assertTrue(dpms.hasUserSetupCompleted());
+ assertThat(dpms.hasUserSetupCompleted()).isTrue();
dpm.forceUpdateUserSetupComplete();
// THEN the state in dpms is not changed
- assertFalse(dpms.hasUserSetupCompleted());
+ assertThat(dpms.hasUserSetupCompleted()).isFalse();
}
private void clearDeviceOwner() throws Exception {
@@ -3795,6 +3913,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
});
}
+ @Test
public void testGetLastSecurityLogRetrievalTime() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -3806,7 +3925,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
.thenReturn(true);
// No logs were retrieved so far.
- assertEquals(-1, dpm.getLastSecurityLogRetrievalTime());
+ assertThat(dpm.getLastSecurityLogRetrievalTime()).isEqualTo(-1);
// Enabling logging should not change the timestamp.
dpm.setSecurityLoggingEnabled(admin1, true);
@@ -3814,55 +3933,56 @@ public class DevicePolicyManagerTest extends DpmTestBase {
.securityLogSetLoggingEnabledProperty(true);
when(getServices().settings.securityLogGetLoggingEnabledProperty())
.thenReturn(true);
- assertEquals(-1, dpm.getLastSecurityLogRetrievalTime());
+ assertThat(dpm.getLastSecurityLogRetrievalTime()).isEqualTo(-1);
// Retrieving the logs should update the timestamp.
final long beforeRetrieval = System.currentTimeMillis();
dpm.retrieveSecurityLogs(admin1);
final long firstSecurityLogRetrievalTime = dpm.getLastSecurityLogRetrievalTime();
final long afterRetrieval = System.currentTimeMillis();
- assertTrue(firstSecurityLogRetrievalTime >= beforeRetrieval);
- assertTrue(firstSecurityLogRetrievalTime <= afterRetrieval);
+ assertThat(firstSecurityLogRetrievalTime >= beforeRetrieval).isTrue();
+ assertThat(firstSecurityLogRetrievalTime <= afterRetrieval).isTrue();
// Retrieving the pre-boot logs should update the timestamp.
Thread.sleep(2);
dpm.retrievePreRebootSecurityLogs(admin1);
final long secondSecurityLogRetrievalTime = dpm.getLastSecurityLogRetrievalTime();
- assertTrue(secondSecurityLogRetrievalTime > firstSecurityLogRetrievalTime);
+ assertThat(secondSecurityLogRetrievalTime > firstSecurityLogRetrievalTime).isTrue();
// Checking the timestamp again should not change it.
Thread.sleep(2);
- assertEquals(secondSecurityLogRetrievalTime, dpm.getLastSecurityLogRetrievalTime());
+ assertThat(dpm.getLastSecurityLogRetrievalTime()).isEqualTo(secondSecurityLogRetrievalTime);
// Retrieving the logs again should update the timestamp.
dpm.retrieveSecurityLogs(admin1);
final long thirdSecurityLogRetrievalTime = dpm.getLastSecurityLogRetrievalTime();
- assertTrue(thirdSecurityLogRetrievalTime > secondSecurityLogRetrievalTime);
+ assertThat(thirdSecurityLogRetrievalTime > secondSecurityLogRetrievalTime).isTrue();
// Disabling logging should not change the timestamp.
Thread.sleep(2);
dpm.setSecurityLoggingEnabled(admin1, false);
- assertEquals(thirdSecurityLogRetrievalTime, dpm.getLastSecurityLogRetrievalTime());
+ assertThat(dpm.getLastSecurityLogRetrievalTime()).isEqualTo(thirdSecurityLogRetrievalTime);
// Restarting the DPMS should not lose the timestamp.
initializeDpms();
- assertEquals(thirdSecurityLogRetrievalTime, dpm.getLastSecurityLogRetrievalTime());
+ assertThat(dpm.getLastSecurityLogRetrievalTime()).isEqualTo(thirdSecurityLogRetrievalTime);
// Any uid holding MANAGE_USERS permission can retrieve the timestamp.
mContext.binder.callingUid = 1234567;
mContext.callerPermissions.add(permission.MANAGE_USERS);
- assertEquals(thirdSecurityLogRetrievalTime, dpm.getLastSecurityLogRetrievalTime());
+ assertThat(dpm.getLastSecurityLogRetrievalTime()).isEqualTo(thirdSecurityLogRetrievalTime);
mContext.callerPermissions.remove(permission.MANAGE_USERS);
// System can retrieve the timestamp.
mContext.binder.clearCallingIdentity();
- assertEquals(thirdSecurityLogRetrievalTime, dpm.getLastSecurityLogRetrievalTime());
+ assertThat(dpm.getLastSecurityLogRetrievalTime()).isEqualTo(thirdSecurityLogRetrievalTime);
// Removing the device owner should clear the timestamp.
clearDeviceOwner();
- assertEquals(-1, dpm.getLastSecurityLogRetrievalTime());
+ assertThat(dpm.getLastSecurityLogRetrievalTime()).isEqualTo(-1);
}
+ @Test
public void testSetConfiguredNetworksLockdownStateWithDO() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -3875,6 +3995,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, 0);
}
+ @Test
public void testSetConfiguredNetworksLockdownStateWithPO() throws Exception {
setupProfileOwner();
assertExpectException(SecurityException.class, null,
@@ -3883,6 +4004,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, 0);
}
+ @Test
public void testSetConfiguredNetworksLockdownStateWithPOOfOrganizationOwnedDevice()
throws Exception {
setupProfileOwner();
@@ -3896,6 +4018,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN, 0);
}
+ @Test
public void testSetSystemSettingFailWithNonWhitelistedSettings() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -3903,6 +4026,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
dpm.setSystemSetting(admin1, Settings.System.SCREEN_BRIGHTNESS_FOR_VR, "0"));
}
+ @Test
public void testSetSystemSettingWithDO() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -3911,6 +4035,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
Settings.System.SCREEN_BRIGHTNESS, "0", UserHandle.USER_SYSTEM);
}
+ @Test
public void testSetSystemSettingWithPO() throws Exception {
setupProfileOwner();
dpm.setSystemSetting(admin1, Settings.System.SCREEN_BRIGHTNESS, "0");
@@ -3918,6 +4043,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
Settings.System.SCREEN_BRIGHTNESS, "0", CALLER_USER_HANDLE);
}
+ @Test
public void testSetAutoTimeEnabledModifiesSetting() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -3928,6 +4054,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME, 0);
}
+ @Test
public void testSetAutoTimeEnabledWithPOOnUser0() throws Exception {
mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
setupProfileOwnerOnUser0();
@@ -3938,6 +4065,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME, 0);
}
+ @Test
public void testSetAutoTimeEnabledFailWithPONotOnUser0() throws Exception {
setupProfileOwner();
assertExpectException(SecurityException.class, null,
@@ -3945,6 +4073,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().settings, never()).settingsGlobalPutInt(Settings.Global.AUTO_TIME, 0);
}
+ @Test
public void testSetAutoTimeEnabledWithPOOfOrganizationOwnedDevice() throws Exception {
setupProfileOwner();
configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE);
@@ -3956,6 +4085,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME, 0);
}
+ @Test
public void testSetAutoTimeZoneEnabledModifiesSetting() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -3966,6 +4096,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME_ZONE, 0);
}
+ @Test
public void testSetAutoTimeZoneEnabledWithPOOnUser0() throws Exception {
mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
setupProfileOwnerOnUser0();
@@ -3976,6 +4107,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME_ZONE, 0);
}
+ @Test
public void testSetAutoTimeZoneEnabledFailWithPONotOnUser0() throws Exception {
setupProfileOwner();
assertExpectException(SecurityException.class, null,
@@ -3984,6 +4116,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
0);
}
+ @Test
public void testSetAutoTimeZoneEnabledWithPOOfOrganizationOwnedDevice() throws Exception {
setupProfileOwner();
configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE);
@@ -3995,12 +4128,13 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME_ZONE, 0);
}
+ @Test
public void testIsOrganizationOwnedDevice() throws Exception {
// Set up the user manager to return correct user info
addManagedProfile(admin1, DpmMockContext.CALLER_UID, admin1);
// Any caller should be able to call this method.
- assertFalse(dpm.isOrganizationOwnedDeviceWithManagedProfile());
+ assertThat(dpm.isOrganizationOwnedDeviceWithManagedProfile()).isFalse();
configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE);
verify(getServices().userManager).setUserRestriction(
@@ -4008,13 +4142,14 @@ public class DevicePolicyManagerTest extends DpmTestBase {
eq(true),
eq(UserHandle.of(UserHandle.USER_SYSTEM)));
- assertTrue(dpm.isOrganizationOwnedDeviceWithManagedProfile());
+ assertThat(dpm.isOrganizationOwnedDeviceWithManagedProfile()).isTrue();
// A random caller from another user should also be able to get the right result.
mContext.binder.callingUid = DpmMockContext.ANOTHER_UID;
- assertTrue(dpm.isOrganizationOwnedDeviceWithManagedProfile());
+ assertThat(dpm.isOrganizationOwnedDeviceWithManagedProfile()).isTrue();
}
+ @Test
public void testMarkOrganizationOwnedDevice_baseRestrictionsAdded() throws Exception {
addManagedProfile(admin1, DpmMockContext.CALLER_UID, admin1);
@@ -4044,6 +4179,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
parentDpm.clearUserRestriction(admin1, UserManager.DISALLOW_ADD_USER));
}
+ @Test
public void testSetTime() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -4051,11 +4187,13 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().alarmManager).setTime(0);
}
+ @Test
public void testSetTimeFailWithPO() throws Exception {
setupProfileOwner();
assertExpectException(SecurityException.class, null, () -> dpm.setTime(admin1, 0));
}
+ @Test
public void testSetTimeWithPOOfOrganizationOwnedDevice() throws Exception {
setupProfileOwner();
configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE);
@@ -4063,14 +4201,16 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().alarmManager).setTime(0);
}
+ @Test
public void testSetTimeWithAutoTimeOn() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
when(getServices().settings.settingsGlobalGetInt(Settings.Global.AUTO_TIME, 0))
.thenReturn(1);
- assertFalse(dpm.setTime(admin1, 0));
+ assertThat(dpm.setTime(admin1, 0)).isFalse();
}
+ @Test
public void testSetTimeZone() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -4078,12 +4218,14 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().alarmManager).setTimeZone("Asia/Shanghai");
}
+ @Test
public void testSetTimeZoneFailWithPO() throws Exception {
setupProfileOwner();
assertExpectException(SecurityException.class, null,
() -> dpm.setTimeZone(admin1, "Asia/Shanghai"));
}
+ @Test
public void testSetTimeZoneWithPOOfOrganizationOwnedDevice() throws Exception {
setupProfileOwner();
configureProfileOwnerOfOrgOwnedDevice(admin1, CALLER_USER_HANDLE);
@@ -4091,14 +4233,16 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().alarmManager).setTimeZone("Asia/Shanghai");
}
+ @Test
public void testSetTimeZoneWithAutoTimeZoneOn() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
when(getServices().settings.settingsGlobalGetInt(Settings.Global.AUTO_TIME_ZONE, 0))
.thenReturn(1);
- assertFalse(dpm.setTimeZone(admin1, "Asia/Shanghai"));
+ assertThat(dpm.setTimeZone(admin1, "Asia/Shanghai")).isFalse();
}
+ @Test
public void testGetLastBugReportRequestTime() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -4115,39 +4259,40 @@ public class DevicePolicyManagerTest extends DpmTestBase {
getServices().removeUser(CALLER_USER_HANDLE);
// No bug reports were requested so far.
- assertEquals(-1, dpm.getLastBugReportRequestTime());
+ assertThat(dpm.getLastBugReportRequestTime()).isEqualTo(-1);
// Requesting a bug report should update the timestamp.
final long beforeRequest = System.currentTimeMillis();
dpm.requestBugreport(admin1);
final long bugReportRequestTime = dpm.getLastBugReportRequestTime();
final long afterRequest = System.currentTimeMillis();
- assertTrue(bugReportRequestTime >= beforeRequest);
- assertTrue(bugReportRequestTime <= afterRequest);
+ assertThat(bugReportRequestTime).isAtLeast(beforeRequest);
+ assertThat(bugReportRequestTime).isAtMost(afterRequest);
// Checking the timestamp again should not change it.
Thread.sleep(2);
- assertEquals(bugReportRequestTime, dpm.getLastBugReportRequestTime());
+ assertThat(dpm.getLastBugReportRequestTime()).isEqualTo(bugReportRequestTime);
// Restarting the DPMS should not lose the timestamp.
initializeDpms();
- assertEquals(bugReportRequestTime, dpm.getLastBugReportRequestTime());
+ assertThat(dpm.getLastBugReportRequestTime()).isEqualTo(bugReportRequestTime);
// Any uid holding MANAGE_USERS permission can retrieve the timestamp.
mContext.binder.callingUid = 1234567;
mContext.callerPermissions.add(permission.MANAGE_USERS);
- assertEquals(bugReportRequestTime, dpm.getLastBugReportRequestTime());
+ assertThat(dpm.getLastBugReportRequestTime()).isEqualTo(bugReportRequestTime);
mContext.callerPermissions.remove(permission.MANAGE_USERS);
// System can retrieve the timestamp.
mContext.binder.clearCallingIdentity();
- assertEquals(bugReportRequestTime, dpm.getLastBugReportRequestTime());
+ assertThat(dpm.getLastBugReportRequestTime()).isEqualTo(bugReportRequestTime);
// Removing the device owner should clear the timestamp.
clearDeviceOwner();
- assertEquals(-1, dpm.getLastBugReportRequestTime());
+ assertThat(dpm.getLastBugReportRequestTime()).isEqualTo(-1);
}
+ @Test
public void testGetLastNetworkLogRetrievalTime() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -4165,57 +4310,58 @@ public class DevicePolicyManagerTest extends DpmTestBase {
.thenReturn(true);
// No logs were retrieved so far.
- assertEquals(-1, dpm.getLastNetworkLogRetrievalTime());
+ assertThat(dpm.getLastNetworkLogRetrievalTime()).isEqualTo(-1);
// Attempting to retrieve logs without enabling logging should not change the timestamp.
dpm.retrieveNetworkLogs(admin1, 0 /* batchToken */);
- assertEquals(-1, dpm.getLastNetworkLogRetrievalTime());
+ assertThat(dpm.getLastNetworkLogRetrievalTime()).isEqualTo(-1);
// Enabling logging should not change the timestamp.
dpm.setNetworkLoggingEnabled(admin1, true);
- assertEquals(-1, dpm.getLastNetworkLogRetrievalTime());
+ assertThat(dpm.getLastNetworkLogRetrievalTime()).isEqualTo(-1);
// Retrieving the logs should update the timestamp.
final long beforeRetrieval = System.currentTimeMillis();
dpm.retrieveNetworkLogs(admin1, 0 /* batchToken */);
final long firstNetworkLogRetrievalTime = dpm.getLastNetworkLogRetrievalTime();
final long afterRetrieval = System.currentTimeMillis();
- assertTrue(firstNetworkLogRetrievalTime >= beforeRetrieval);
- assertTrue(firstNetworkLogRetrievalTime <= afterRetrieval);
+ assertThat(firstNetworkLogRetrievalTime >= beforeRetrieval).isTrue();
+ assertThat(firstNetworkLogRetrievalTime <= afterRetrieval).isTrue();
// Checking the timestamp again should not change it.
Thread.sleep(2);
- assertEquals(firstNetworkLogRetrievalTime, dpm.getLastNetworkLogRetrievalTime());
+ assertThat(dpm.getLastNetworkLogRetrievalTime()).isEqualTo(firstNetworkLogRetrievalTime);
// Retrieving the logs again should update the timestamp.
dpm.retrieveNetworkLogs(admin1, 0 /* batchToken */);
final long secondNetworkLogRetrievalTime = dpm.getLastNetworkLogRetrievalTime();
- assertTrue(secondNetworkLogRetrievalTime > firstNetworkLogRetrievalTime);
+ assertThat(secondNetworkLogRetrievalTime > firstNetworkLogRetrievalTime).isTrue();
// Disabling logging should not change the timestamp.
Thread.sleep(2);
dpm.setNetworkLoggingEnabled(admin1, false);
- assertEquals(secondNetworkLogRetrievalTime, dpm.getLastNetworkLogRetrievalTime());
+ assertThat(dpm.getLastNetworkLogRetrievalTime()).isEqualTo(secondNetworkLogRetrievalTime);
// Restarting the DPMS should not lose the timestamp.
initializeDpms();
- assertEquals(secondNetworkLogRetrievalTime, dpm.getLastNetworkLogRetrievalTime());
+ assertThat(dpm.getLastNetworkLogRetrievalTime()).isEqualTo(secondNetworkLogRetrievalTime);
// Any uid holding MANAGE_USERS permission can retrieve the timestamp.
mContext.binder.callingUid = 1234567;
mContext.callerPermissions.add(permission.MANAGE_USERS);
- assertEquals(secondNetworkLogRetrievalTime, dpm.getLastNetworkLogRetrievalTime());
+ assertThat(dpm.getLastNetworkLogRetrievalTime()).isEqualTo(secondNetworkLogRetrievalTime);
mContext.callerPermissions.remove(permission.MANAGE_USERS);
// System can retrieve the timestamp.
mContext.binder.clearCallingIdentity();
- assertEquals(secondNetworkLogRetrievalTime, dpm.getLastNetworkLogRetrievalTime());
+ assertThat(dpm.getLastNetworkLogRetrievalTime()).isEqualTo(secondNetworkLogRetrievalTime);
// Removing the device owner should clear the timestamp.
clearDeviceOwner();
- assertEquals(-1, dpm.getLastNetworkLogRetrievalTime());
+ assertThat(dpm.getLastNetworkLogRetrievalTime()).isEqualTo(-1);
}
+ @Test
public void testGetBindDeviceAdminTargetUsers() throws Exception {
// Setup device owner.
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
@@ -4268,9 +4414,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
dpm.setLockTaskPackages(who, packages);
MoreAsserts.assertEquals(packages, dpm.getLockTaskPackages(who));
for (String p : packages) {
- assertTrue(dpm.isLockTaskPermitted(p));
+ assertThat(dpm.isLockTaskPermitted(p)).isTrue();
}
- assertFalse(dpm.isLockTaskPermitted("anotherPackage"));
+ assertThat(dpm.isLockTaskPermitted("anotherPackage")).isFalse();
// Test to see if set lock task features can be set
dpm.setLockTaskFeatures(who, flags);
verifyLockTaskState(userId, packages, flags);
@@ -4283,11 +4429,12 @@ public class DevicePolicyManagerTest extends DpmTestBase {
() -> dpm.setLockTaskPackages(who, packages));
assertExpectException(SecurityException.class, /* messageRegex =*/ null,
() -> dpm.getLockTaskPackages(who));
- assertFalse(dpm.isLockTaskPermitted("doPackage1"));
+ assertThat(dpm.isLockTaskPermitted("doPackage1")).isFalse();
assertExpectException(SecurityException.class, /* messageRegex =*/ null,
() -> dpm.setLockTaskFeatures(who, flags));
}
+ @Test
public void testLockTaskPolicyForProfileOwner() throws Exception {
// Setup a PO
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
@@ -4315,9 +4462,11 @@ public class DevicePolicyManagerTest extends DpmTestBase {
final int mpoFlags = DevicePolicyManager.LOCK_TASK_FEATURE_NOTIFICATIONS
| DevicePolicyManager.LOCK_TASK_FEATURE_HOME
| DevicePolicyManager.LOCK_TASK_FEATURE_OVERVIEW;
- verifyCanNotSetLockTask(MANAGED_PROFILE_ADMIN_UID, adminDifferentPackage, mpoPackages, mpoFlags);
+ verifyCanNotSetLockTask(MANAGED_PROFILE_ADMIN_UID, adminDifferentPackage, mpoPackages,
+ mpoFlags);
}
+ @Test
public void testLockTaskFeatures_IllegalArgumentException() throws Exception {
// Setup a device owner.
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
@@ -4332,12 +4481,13 @@ public class DevicePolicyManagerTest extends DpmTestBase {
() -> dpm.setLockTaskFeatures(admin1, flags));
}
+ @Test
public void testSecondaryLockscreen_profileOwner() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
// Initial state is disabled.
- assertFalse(dpm.isSecondaryLockscreenEnabled(UserHandle.of(
- CALLER_USER_HANDLE)));
+ assertThat(dpm.isSecondaryLockscreenEnabled(UserHandle.of(
+ CALLER_USER_HANDLE))).isFalse();
// Profile owner can set enabled state.
setAsProfileOwner(admin1);
@@ -4345,8 +4495,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
.getString(R.string.config_defaultSupervisionProfileOwnerComponent))
.thenReturn(admin1.flattenToString());
dpm.setSecondaryLockscreenEnabled(admin1, true);
- assertTrue(dpm.isSecondaryLockscreenEnabled(UserHandle.of(
- CALLER_USER_HANDLE)));
+ assertThat(dpm.isSecondaryLockscreenEnabled(UserHandle.of(
+ CALLER_USER_HANDLE))).isTrue();
// Managed profile managed by different package is unaffiliated - cannot set enabled.
final int managedProfileUserId = 15;
@@ -4359,11 +4509,13 @@ public class DevicePolicyManagerTest extends DpmTestBase {
() -> dpm.setSecondaryLockscreenEnabled(adminDifferentPackage, false));
}
+ @Test
public void testSecondaryLockscreen_deviceOwner() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
// Initial state is disabled.
- assertFalse(dpm.isSecondaryLockscreenEnabled(UserHandle.of(UserHandle.USER_SYSTEM)));
+ assertThat(dpm.isSecondaryLockscreenEnabled(UserHandle.of(UserHandle.USER_SYSTEM)))
+ .isFalse();
// Device owners can set enabled state.
setupDeviceOwner();
@@ -4371,14 +4523,16 @@ public class DevicePolicyManagerTest extends DpmTestBase {
.getString(R.string.config_defaultSupervisionProfileOwnerComponent))
.thenReturn(admin1.flattenToString());
dpm.setSecondaryLockscreenEnabled(admin1, true);
- assertTrue(dpm.isSecondaryLockscreenEnabled(UserHandle.of(UserHandle.USER_SYSTEM)));
+ assertThat(dpm.isSecondaryLockscreenEnabled(UserHandle.of(UserHandle.USER_SYSTEM)))
+ .isTrue();
}
+ @Test
public void testSecondaryLockscreen_nonOwner() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
// Initial state is disabled.
- assertFalse(dpm.isSecondaryLockscreenEnabled(UserHandle.of(CALLER_USER_HANDLE)));
+ assertThat(dpm.isSecondaryLockscreenEnabled(UserHandle.of(CALLER_USER_HANDLE))).isFalse();
// Non-DO/PO cannot set enabled state.
when(mServiceContext.resources
@@ -4386,9 +4540,10 @@ public class DevicePolicyManagerTest extends DpmTestBase {
.thenReturn(admin1.flattenToString());
assertExpectException(SecurityException.class, /* messageRegex= */ null,
() -> dpm.setSecondaryLockscreenEnabled(admin1, true));
- assertFalse(dpm.isSecondaryLockscreenEnabled(UserHandle.of(CALLER_USER_HANDLE)));
+ assertThat(dpm.isSecondaryLockscreenEnabled(UserHandle.of(CALLER_USER_HANDLE))).isFalse();
}
+ @Test
public void testSecondaryLockscreen_nonSupervisionApp() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
@@ -4403,13 +4558,13 @@ public class DevicePolicyManagerTest extends DpmTestBase {
eq(CALLER_USER_HANDLE));
// Initial state is disabled.
- assertFalse(dpm.isSecondaryLockscreenEnabled(UserHandle.of(CALLER_USER_HANDLE)));
+ assertThat(dpm.isSecondaryLockscreenEnabled(UserHandle.of(CALLER_USER_HANDLE))).isFalse();
// Caller is Profile Owner, but no supervision app is configured.
setAsProfileOwner(admin1);
assertExpectException(SecurityException.class, "is not the default supervision component",
() -> dpm.setSecondaryLockscreenEnabled(admin1, true));
- assertFalse(dpm.isSecondaryLockscreenEnabled(UserHandle.of(CALLER_USER_HANDLE)));
+ assertThat(dpm.isSecondaryLockscreenEnabled(UserHandle.of(CALLER_USER_HANDLE))).isFalse();
// Caller is Profile Owner, but is not the default configured supervision app.
when(mServiceContext.resources
@@ -4417,22 +4572,23 @@ public class DevicePolicyManagerTest extends DpmTestBase {
.thenReturn(admin2.flattenToString());
assertExpectException(SecurityException.class, "is not the default supervision component",
() -> dpm.setSecondaryLockscreenEnabled(admin1, true));
- assertFalse(dpm.isSecondaryLockscreenEnabled(UserHandle.of(CALLER_USER_HANDLE)));
+ assertThat(dpm.isSecondaryLockscreenEnabled(UserHandle.of(CALLER_USER_HANDLE))).isFalse();
}
+ @Test
public void testIsDeviceManaged() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
// The device owner itself, any uid holding MANAGE_USERS permission and the system can
// find out that the device has a device owner.
- assertTrue(dpm.isDeviceManaged());
+ assertThat(dpm.isDeviceManaged()).isTrue();
mContext.binder.callingUid = 1234567;
mContext.callerPermissions.add(permission.MANAGE_USERS);
- assertTrue(dpm.isDeviceManaged());
+ assertThat(dpm.isDeviceManaged()).isTrue();
mContext.callerPermissions.remove(permission.MANAGE_USERS);
mContext.binder.clearCallingIdentity();
- assertTrue(dpm.isDeviceManaged());
+ assertThat(dpm.isDeviceManaged()).isTrue();
clearDeviceOwner();
@@ -4440,12 +4596,13 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// not have a device owner.
mContext.binder.callingUid = 1234567;
mContext.callerPermissions.add(permission.MANAGE_USERS);
- assertFalse(dpm.isDeviceManaged());
+ assertThat(dpm.isDeviceManaged()).isFalse();
mContext.callerPermissions.remove(permission.MANAGE_USERS);
mContext.binder.clearCallingIdentity();
- assertFalse(dpm.isDeviceManaged());
+ assertThat(dpm.isDeviceManaged()).isFalse();
}
+ @Test
public void testDeviceOwnerOrganizationName() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -4453,23 +4610,24 @@ public class DevicePolicyManagerTest extends DpmTestBase {
dpm.setOrganizationName(admin1, "organization");
// Device owner can retrieve organization managing the device.
- assertEquals("organization", dpm.getDeviceOwnerOrganizationName());
+ assertThat(dpm.getDeviceOwnerOrganizationName()).isEqualTo("organization");
// Any uid holding MANAGE_USERS permission can retrieve organization managing the device.
mContext.binder.callingUid = 1234567;
mContext.callerPermissions.add(permission.MANAGE_USERS);
- assertEquals("organization", dpm.getDeviceOwnerOrganizationName());
+ assertThat(dpm.getDeviceOwnerOrganizationName()).isEqualTo("organization");
mContext.callerPermissions.remove(permission.MANAGE_USERS);
// System can retrieve organization managing the device.
mContext.binder.clearCallingIdentity();
- assertEquals("organization", dpm.getDeviceOwnerOrganizationName());
+ assertThat(dpm.getDeviceOwnerOrganizationName()).isEqualTo("organization");
// Removing the device owner clears the organization managing the device.
clearDeviceOwner();
- assertNull(dpm.getDeviceOwnerOrganizationName());
+ assertThat(dpm.getDeviceOwnerOrganizationName()).isNull();
}
+ @Test
public void testWipeDataManagedProfile() throws Exception {
final int MANAGED_PROFILE_USER_ID = 15;
final int MANAGED_PROFILE_ADMIN_UID = UserHandle.getUid(MANAGED_PROFILE_USER_ID, 19436);
@@ -4489,6 +4647,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
MANAGED_PROFILE_USER_ID);
}
+ @Test
public void testWipeDataManagedProfileDisallowed() throws Exception {
final int MANAGED_PROFILE_USER_ID = 15;
final int MANAGED_PROFILE_ADMIN_UID = UserHandle.getUid(MANAGED_PROFILE_USER_ID, 19436);
@@ -4512,6 +4671,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
() -> dpm.wipeData(0));
}
+ @Test
public void testWipeDataDeviceOwner() throws Exception {
setDeviceOwner();
when(getServices().userManager.getUserRestrictionSource(
@@ -4527,6 +4687,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
/*wipeEuicc=*/ eq(false));
}
+ @Test
public void testWipeEuiccDataEnabled() throws Exception {
setDeviceOwner();
when(getServices().userManager.getUserRestrictionSource(
@@ -4542,6 +4703,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
/*wipeEuicc=*/ eq(true));
}
+ @Test
public void testWipeDataDeviceOwnerDisallowed() throws Exception {
setDeviceOwner();
when(getServices().userManager.getUserRestrictionSource(
@@ -4556,6 +4718,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
() -> dpm.wipeData(0));
}
+ @Test
public void testMaximumFailedPasswordAttemptsReachedManagedProfile() throws Exception {
final int MANAGED_PROFILE_USER_ID = 15;
final int MANAGED_PROFILE_ADMIN_UID = UserHandle.getUid(MANAGED_PROFILE_USER_ID, 19436);
@@ -4588,6 +4751,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verifyZeroInteractions(getServices().recoverySystem);
}
+ @Test
public void testMaximumFailedPasswordAttemptsReachedManagedProfileDisallowed()
throws Exception {
final int MANAGED_PROFILE_USER_ID = 15;
@@ -4621,6 +4785,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verifyZeroInteractions(getServices().recoverySystem);
}
+ @Test
public void testMaximumFailedPasswordAttemptsReachedDeviceOwner() throws Exception {
setDeviceOwner();
when(getServices().userManager.getUserRestrictionSource(
@@ -4643,6 +4808,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
/*wipeEuicc=*/ eq(false));
}
+ @Test
public void testMaximumFailedPasswordAttemptsReachedDeviceOwnerDisallowed() throws Exception {
setDeviceOwner();
when(getServices().userManager.getUserRestrictionSource(
@@ -4664,6 +4830,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
.removeUserEvenWhenDisallowed(anyInt());
}
+ @Test
public void testMaximumFailedDevicePasswordAttemptsReachedOrgOwnedManagedProfile()
throws Exception {
final int MANAGED_PROFILE_USER_ID = 15;
@@ -4679,16 +4846,16 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = MANAGED_PROFILE_ADMIN_UID;
dpm.setMaximumFailedPasswordsForWipe(admin1, 3);
- assertEquals(3, dpm.getMaximumFailedPasswordsForWipe(admin1));
- assertEquals(3, dpm.getMaximumFailedPasswordsForWipe(null));
+ assertThat(dpm.getMaximumFailedPasswordsForWipe(admin1)).isEqualTo(3);
+ assertThat(dpm.getMaximumFailedPasswordsForWipe(null)).isEqualTo(3);
mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
mContext.callerPermissions.add(permission.BIND_DEVICE_ADMIN);
- assertEquals(3, dpm.getMaximumFailedPasswordsForWipe(null, UserHandle.USER_SYSTEM));
+ assertThat(dpm.getMaximumFailedPasswordsForWipe(null, UserHandle.USER_SYSTEM)).isEqualTo(3);
// Check that primary will be wiped as a result of failed primary user unlock attempts.
- assertEquals(UserHandle.USER_SYSTEM,
- dpm.getProfileWithMinimumFailedPasswordsForWipe(UserHandle.USER_SYSTEM));
+ assertThat(dpm.getProfileWithMinimumFailedPasswordsForWipe(UserHandle.USER_SYSTEM))
+ .isEqualTo(UserHandle.USER_SYSTEM);
// Failed password attempts on the parent user are taken into account, as there isn't a
// separate work challenge.
@@ -4702,6 +4869,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
/*wipeEuicc=*/ eq(false));
}
+ @Test
public void testMaximumFailedProfilePasswordAttemptsReachedOrgOwnedManagedProfile()
throws Exception {
final int MANAGED_PROFILE_USER_ID = 15;
@@ -4724,14 +4892,15 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
mContext.callerPermissions.add(permission.BIND_DEVICE_ADMIN);
- assertEquals(0, dpm.getMaximumFailedPasswordsForWipe(null, UserHandle.USER_SYSTEM));
- assertEquals(3, dpm.getMaximumFailedPasswordsForWipe(null, MANAGED_PROFILE_USER_ID));
+ assertThat(dpm.getMaximumFailedPasswordsForWipe(null, UserHandle.USER_SYSTEM)).isEqualTo(0);
+ assertThat(dpm.getMaximumFailedPasswordsForWipe(null, MANAGED_PROFILE_USER_ID))
+ .isEqualTo(3);
// Check that the policy is not affecting primary profile challenge.
- assertEquals(UserHandle.USER_NULL,
- dpm.getProfileWithMinimumFailedPasswordsForWipe(UserHandle.USER_SYSTEM));
+ assertThat(dpm.getProfileWithMinimumFailedPasswordsForWipe(UserHandle.USER_SYSTEM))
+ .isEqualTo(UserHandle.USER_NULL);
// Check that primary will be wiped as a result of failed profile unlock attempts.
- assertEquals(UserHandle.USER_SYSTEM,
- dpm.getProfileWithMinimumFailedPasswordsForWipe(MANAGED_PROFILE_USER_ID));
+ assertThat(dpm.getProfileWithMinimumFailedPasswordsForWipe(MANAGED_PROFILE_USER_ID))
+ .isEqualTo(UserHandle.USER_SYSTEM);
// Simulate three failed attempts at solving the separate challenge.
dpm.reportFailedPasswordAttempt(MANAGED_PROFILE_USER_ID);
@@ -4744,6 +4913,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
/*wipeEuicc=*/ eq(false));
}
+ @Test
public void testGetPermissionGrantState() throws Exception {
final String permission = "some.permission";
final String app1 = "com.example.app1";
@@ -4766,10 +4936,10 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// System can retrieve permission grant state.
mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
mContext.packageName = "android";
- assertEquals(DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED,
- dpm.getPermissionGrantState(null, app1, permission));
- assertEquals(DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT,
- dpm.getPermissionGrantState(null, app2, permission));
+ assertThat(dpm.getPermissionGrantState(null, app1, permission))
+ .isEqualTo(DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED);
+ assertThat(dpm.getPermissionGrantState(null, app2, permission))
+ .isEqualTo(DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT);
// A regular app cannot retrieve permission grant state.
mContext.binder.callingUid = setupPackageInPackageManager(app1, 1);
@@ -4781,12 +4951,13 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
mContext.packageName = admin1.getPackageName();
setAsProfileOwner(admin1);
- assertEquals(DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED,
- dpm.getPermissionGrantState(admin1, app1, permission));
- assertEquals(DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT,
- dpm.getPermissionGrantState(admin1, app2, permission));
+ assertThat(dpm.getPermissionGrantState(admin1, app1, permission))
+ .isEqualTo(DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED);
+ assertThat(dpm.getPermissionGrantState(admin1, app2, permission))
+ .isEqualTo(DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT);
}
+ @Test
public void testResetPasswordWithToken() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
setupDeviceOwner();
@@ -4801,27 +4972,26 @@ public class DevicePolicyManagerTest extends DpmTestBase {
when(getServices().lockPatternUtils.addEscrowToken(eq(token), eq(UserHandle.USER_SYSTEM),
nullable(EscrowTokenStateChangeCallback.class)))
.thenReturn(handle);
- assertTrue(dpm.setResetPasswordToken(admin1, token));
+ assertThat(dpm.setResetPasswordToken(admin1, token)).isTrue();
// test password activation
- when(getServices().lockPatternUtils.isEscrowTokenActive(eq(handle), eq(UserHandle.USER_SYSTEM)))
- .thenReturn(true);
- assertTrue(dpm.isResetPasswordTokenActive(admin1));
+ when(getServices().lockPatternUtils.isEscrowTokenActive(handle, UserHandle.USER_SYSTEM))
+ .thenReturn(true);
+ assertThat(dpm.isResetPasswordTokenActive(admin1)).isTrue();
// test reset password with token
when(getServices().lockPatternUtils.setLockCredentialWithToken(
- eq(LockscreenCredential.createPassword(password)),
- eq(handle), eq(token),
- eq(UserHandle.USER_SYSTEM)))
- .thenReturn(true);
- assertTrue(dpm.resetPasswordWithToken(admin1, password, token, 0));
+ LockscreenCredential.createPassword(password), handle, token,
+ UserHandle.USER_SYSTEM)).thenReturn(true);
+ assertThat(dpm.resetPasswordWithToken(admin1, password, token, 0)).isTrue();
// test removing a token
- when(getServices().lockPatternUtils.removeEscrowToken(eq(handle), eq(UserHandle.USER_SYSTEM)))
+ when(getServices().lockPatternUtils.removeEscrowToken(handle, UserHandle.USER_SYSTEM))
.thenReturn(true);
- assertTrue(dpm.clearResetPasswordToken(admin1));
+ assertThat(dpm.clearResetPasswordToken(admin1)).isTrue();
}
+ @Test
public void testIsActivePasswordSufficient() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
mContext.packageName = admin1.getPackageName();
@@ -4841,11 +5011,11 @@ public class DevicePolicyManagerTest extends DpmTestBase {
PasswordMetrics passwordMetricsNoSymbols = computeForPassword("abcdXYZ5".getBytes());
setActivePasswordState(passwordMetricsNoSymbols);
- assertTrue(dpm.isActivePasswordSufficient());
+ assertThat(dpm.isActivePasswordSufficient()).isTrue();
initializeDpms();
reset(mContext.spiedContext);
- assertTrue(dpm.isActivePasswordSufficient());
+ assertThat(dpm.isActivePasswordSufficient()).isTrue();
// This call simulates the user entering the password for the first time after a reboot.
// This causes password metrics to be reloaded into memory. Until this happens,
@@ -4854,23 +5024,24 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// requirements. This is a known limitation of the current implementation of
// isActivePasswordSufficient() - see b/34218769.
setActivePasswordState(passwordMetricsNoSymbols);
- assertTrue(dpm.isActivePasswordSufficient());
+ assertThat(dpm.isActivePasswordSufficient()).isTrue();
dpm.setPasswordMinimumSymbols(admin1, 1);
// This assertion would fail if we had not called setActivePasswordState() again after
// initializeDpms() - see previous comment.
- assertFalse(dpm.isActivePasswordSufficient());
+ assertThat(dpm.isActivePasswordSufficient()).isFalse();
initializeDpms();
reset(mContext.spiedContext);
- assertFalse(dpm.isActivePasswordSufficient());
+ assertThat(dpm.isActivePasswordSufficient()).isFalse();
PasswordMetrics passwordMetricsWithSymbols = computeForPassword("abcd.XY5".getBytes());
setActivePasswordState(passwordMetricsWithSymbols);
- assertTrue(dpm.isActivePasswordSufficient());
+ assertThat(dpm.isActivePasswordSufficient()).isTrue();
}
+ @Test
public void testIsActivePasswordSufficient_noLockScreen() throws Exception {
// If there is no lock screen, the password is considered empty no matter what, because
// it provides no security.
@@ -4885,7 +5056,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
.thenReturn(new PasswordMetrics(CREDENTIAL_TYPE_NONE));
// If no password requirements are set, isActivePasswordSufficient should succeed.
- assertTrue(dpm.isActivePasswordSufficient());
+ assertThat(dpm.isActivePasswordSufficient()).isTrue();
// Now set some password quality requirements.
dpm.setPasswordQuality(admin1, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
@@ -4900,9 +5071,10 @@ public class DevicePolicyManagerTest extends DpmTestBase {
MockUtils.checkUserHandle(userHandle));
// The active (nonexistent) password doesn't comply with the requirements.
- assertFalse(dpm.isActivePasswordSufficient());
+ assertThat(dpm.isActivePasswordSufficient()).isFalse();
}
+ @Test
public void testIsPasswordSufficientAfterProfileUnification() throws Exception {
final int managedProfileUserId = CALLER_USER_HANDLE;
final int managedProfileAdminUid =
@@ -4921,13 +5093,13 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// Numeric password is compliant with current requirement (QUALITY_NUMERIC set explicitly
// on the parent admin)
- assertTrue(dpm.isPasswordSufficientAfterProfileUnification(UserHandle.USER_SYSTEM,
- UserHandle.USER_NULL));
+ assertThat(dpm.isPasswordSufficientAfterProfileUnification(UserHandle.USER_SYSTEM,
+ UserHandle.USER_NULL)).isTrue();
// Numeric password is not compliant if profile is to be unified: the profile has a
// QUALITY_ALPHABETIC policy on itself which will be enforced on the password after
// unification.
- assertFalse(dpm.isPasswordSufficientAfterProfileUnification(UserHandle.USER_SYSTEM,
- managedProfileUserId));
+ assertThat(dpm.isPasswordSufficientAfterProfileUnification(UserHandle.USER_SYSTEM,
+ managedProfileUserId)).isFalse();
}
private void setActivePasswordState(PasswordMetrics passwordMetrics)
@@ -4961,6 +5133,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
mContext.binder.restoreCallingIdentity(ident);
}
+ @Test
public void testIsCurrentInputMethodSetByOwnerForDeviceOwner() throws Exception {
final String currentIme = Settings.Secure.DEFAULT_INPUT_METHOD;
final Uri currentImeUri = Settings.Secure.getUriFor(currentIme);
@@ -4976,70 +5149,71 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// First and second user set IMEs manually.
mContext.binder.callingUid = firstUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
mContext.binder.callingUid = secondUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
// Device owner changes IME for first user.
mContext.binder.callingUid = deviceOwnerUid;
- when(getServices().settings.settingsSecureGetStringForUser(currentIme, UserHandle.USER_SYSTEM))
- .thenReturn("ime1");
+ when(getServices().settings.settingsSecureGetStringForUser(currentIme,
+ UserHandle.USER_SYSTEM)).thenReturn("ime1");
dpm.setSecureSetting(admin1, currentIme, "ime2");
verify(getServices().settings).settingsSecurePutStringForUser(currentIme, "ime2",
UserHandle.USER_SYSTEM);
reset(getServices().settings);
dpms.notifyChangeToContentObserver(currentImeUri, UserHandle.USER_SYSTEM);
mContext.binder.callingUid = firstUserSystemUid;
- assertTrue(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isTrue();
mContext.binder.callingUid = secondUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
// Second user changes IME manually.
dpms.notifyChangeToContentObserver(currentImeUri, CALLER_USER_HANDLE);
mContext.binder.callingUid = firstUserSystemUid;
- assertTrue(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isTrue();
mContext.binder.callingUid = secondUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
// First user changes IME manually.
dpms.notifyChangeToContentObserver(currentImeUri, UserHandle.USER_SYSTEM);
mContext.binder.callingUid = firstUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
mContext.binder.callingUid = secondUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
// Device owner changes IME for first user again.
mContext.binder.callingUid = deviceOwnerUid;
- when(getServices().settings.settingsSecureGetStringForUser(currentIme, UserHandle.USER_SYSTEM))
- .thenReturn("ime2");
+ when(getServices().settings.settingsSecureGetStringForUser(currentIme,
+ UserHandle.USER_SYSTEM)).thenReturn("ime2");
dpm.setSecureSetting(admin1, currentIme, "ime3");
verify(getServices().settings).settingsSecurePutStringForUser(currentIme, "ime3",
UserHandle.USER_SYSTEM);
dpms.notifyChangeToContentObserver(currentImeUri, UserHandle.USER_SYSTEM);
mContext.binder.callingUid = firstUserSystemUid;
- assertTrue(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isTrue();
mContext.binder.callingUid = secondUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
// Restarting the DPMS should not lose information.
initializeDpms();
mContext.binder.callingUid = firstUserSystemUid;
- assertTrue(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isTrue();
mContext.binder.callingUid = secondUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
// Device owner can find out whether it set the current IME itself.
mContext.binder.callingUid = deviceOwnerUid;
- assertTrue(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isTrue();
// Removing the device owner should clear the information that it set the current IME.
clearDeviceOwner();
mContext.binder.callingUid = firstUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
mContext.binder.callingUid = secondUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
}
+ @Test
public void testIsCurrentInputMethodSetByOwnerForProfileOwner() throws Exception {
final String currentIme = Settings.Secure.DEFAULT_INPUT_METHOD;
final Uri currentImeUri = Settings.Secure.getUriFor(currentIme);
@@ -5055,9 +5229,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
// First and second user set IMEs manually.
mContext.binder.callingUid = firstUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
mContext.binder.callingUid = secondUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
// Profile owner changes IME for second user.
mContext.binder.callingUid = profileOwnerUid;
@@ -5069,23 +5243,23 @@ public class DevicePolicyManagerTest extends DpmTestBase {
reset(getServices().settings);
dpms.notifyChangeToContentObserver(currentImeUri, CALLER_USER_HANDLE);
mContext.binder.callingUid = firstUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
mContext.binder.callingUid = secondUserSystemUid;
- assertTrue(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isTrue();
// First user changes IME manually.
dpms.notifyChangeToContentObserver(currentImeUri, UserHandle.USER_SYSTEM);
mContext.binder.callingUid = firstUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
mContext.binder.callingUid = secondUserSystemUid;
- assertTrue(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isTrue();
// Second user changes IME manually.
dpms.notifyChangeToContentObserver(currentImeUri, CALLER_USER_HANDLE);
mContext.binder.callingUid = firstUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
mContext.binder.callingUid = secondUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
// Profile owner changes IME for second user again.
mContext.binder.callingUid = profileOwnerUid;
@@ -5096,29 +5270,30 @@ public class DevicePolicyManagerTest extends DpmTestBase {
CALLER_USER_HANDLE);
dpms.notifyChangeToContentObserver(currentImeUri, CALLER_USER_HANDLE);
mContext.binder.callingUid = firstUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
mContext.binder.callingUid = secondUserSystemUid;
- assertTrue(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isTrue();
// Restarting the DPMS should not lose information.
initializeDpms();
mContext.binder.callingUid = firstUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
mContext.binder.callingUid = secondUserSystemUid;
- assertTrue(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isTrue();
// Profile owner can find out whether it set the current IME itself.
mContext.binder.callingUid = profileOwnerUid;
- assertTrue(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isTrue();
// Removing the profile owner should clear the information that it set the current IME.
dpm.clearProfileOwner(admin1);
mContext.binder.callingUid = firstUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
mContext.binder.callingUid = secondUserSystemUid;
- assertFalse(dpm.isCurrentInputMethodSetByOwner());
+ assertThat(dpm.isCurrentInputMethodSetByOwner()).isFalse();
}
+ @Test
public void testSetPermittedCrossProfileNotificationListeners_unavailableForDo()
throws Exception {
// Set up a device owner.
@@ -5127,6 +5302,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
assertSetPermittedCrossProfileNotificationListenersUnavailable(mContext.binder.callingUid);
}
+ @Test
public void testSetPermittedCrossProfileNotificationListeners_unavailableForPoOnUser()
throws Exception {
// Set up a profile owner.
@@ -5141,23 +5317,24 @@ public class DevicePolicyManagerTest extends DpmTestBase {
final int userId = UserHandle.getUserId(adminUid);
final String packageName = "some.package";
- assertFalse(dpms.setPermittedCrossProfileNotificationListeners(
- admin1, Collections.singletonList(packageName)));
- assertNull(dpms.getPermittedCrossProfileNotificationListeners(admin1));
+ assertThat(dpms.setPermittedCrossProfileNotificationListeners(
+ admin1, Collections.singletonList(packageName))).isFalse();
+ assertThat(dpms.getPermittedCrossProfileNotificationListeners(admin1)).isNull();
mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
- assertTrue(dpms.isNotificationListenerServicePermitted(packageName, userId));
+ assertThat(dpms.isNotificationListenerServicePermitted(packageName, userId)).isTrue();
// Attempt to set to empty list (which means no listener is allowlisted)
mContext.binder.callingUid = adminUid;
- assertFalse(dpms.setPermittedCrossProfileNotificationListeners(
- admin1, Collections.emptyList()));
- assertNull(dpms.getPermittedCrossProfileNotificationListeners(admin1));
+ assertThat(dpms.setPermittedCrossProfileNotificationListeners(
+ admin1, Collections.emptyList())).isFalse();
+ assertThat(dpms.getPermittedCrossProfileNotificationListeners(admin1)).isNull();
mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
- assertTrue(dpms.isNotificationListenerServicePermitted(packageName, userId));
+ assertThat(dpms.isNotificationListenerServicePermitted(packageName, userId)).isTrue();
}
+ @Test
public void testIsNotificationListenerServicePermitted_onlySystemCanCall() throws Exception {
// Set up a managed profile
final int MANAGED_PROFILE_USER_ID = 15;
@@ -5171,8 +5348,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
UserHandle.USER_SYSTEM, // We check the packageInfo from the primary user.
/*appId=*/ 12345, /*flags=*/ 0);
- assertTrue(dpms.setPermittedCrossProfileNotificationListeners(
- admin1, Collections.singletonList(permittedListener)));
+ assertThat(dpms.setPermittedCrossProfileNotificationListeners(
+ admin1, Collections.singletonList(permittedListener))).isTrue();
// isNotificationListenerServicePermitted should throw if not called from System.
assertExpectException(SecurityException.class, /* messageRegex= */ null,
@@ -5180,10 +5357,11 @@ public class DevicePolicyManagerTest extends DpmTestBase {
permittedListener, MANAGED_PROFILE_USER_ID));
mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
- assertTrue(dpms.isNotificationListenerServicePermitted(
- permittedListener, MANAGED_PROFILE_USER_ID));
+ assertThat(dpms.isNotificationListenerServicePermitted(
+ permittedListener, MANAGED_PROFILE_USER_ID)).isTrue();
}
+ @Test
public void testSetPermittedCrossProfileNotificationListeners_managedProfile()
throws Exception {
// Set up a managed profile
@@ -5212,63 +5390,64 @@ public class DevicePolicyManagerTest extends DpmTestBase {
++appId, ApplicationInfo.FLAG_SYSTEM);
// By default all packages are allowed
- assertNull(dpms.getPermittedCrossProfileNotificationListeners(admin1));
+ assertThat(dpms.getPermittedCrossProfileNotificationListeners(admin1)).isNull();
mContext.binder.callingUid = DpmMockContext.SYSTEM_UID;
- assertTrue(dpms.isNotificationListenerServicePermitted(
- permittedListener, MANAGED_PROFILE_USER_ID));
- assertTrue(dpms.isNotificationListenerServicePermitted(
- notPermittedListener, MANAGED_PROFILE_USER_ID));
- assertTrue(dpms.isNotificationListenerServicePermitted(
- systemListener, MANAGED_PROFILE_USER_ID));
+ assertThat(dpms.isNotificationListenerServicePermitted(
+ permittedListener, MANAGED_PROFILE_USER_ID)).isTrue();
+ assertThat(dpms.isNotificationListenerServicePermitted(
+ notPermittedListener, MANAGED_PROFILE_USER_ID)).isTrue();
+ assertThat(dpms.isNotificationListenerServicePermitted(
+ systemListener, MANAGED_PROFILE_USER_ID)).isTrue();
// Setting only one package in the allowlist
mContext.binder.callingUid = MANAGED_PROFILE_ADMIN_UID;
- assertTrue(dpms.setPermittedCrossProfileNotificationListeners(
- admin1, Collections.singletonList(permittedListener)));
+ assertThat(dpms.setPermittedCrossProfileNotificationListeners(
+ admin1, Collections.singletonList(permittedListener))).isTrue();
final List
+ */
@RunWith(AndroidJUnit4.class)
-public class TransferOwnershipMetadataManagerTest {
+public final class TransferOwnershipMetadataManagerTest {
private final static String TAG = TransferOwnershipMetadataManagerTest.class.getName();
private final static String SOURCE_COMPONENT =
"com.dummy.admin.package/com.dummy.admin.package.SourceClassName";
@@ -77,28 +78,27 @@ public class TransferOwnershipMetadataManagerTest {
@Test
public void testSave() {
TransferOwnershipMetadataManager paramsManager = getOwnerTransferParams();
- assertTrue(paramsManager.saveMetadataFile(TEST_PARAMS));
- assertTrue(paramsManager.metadataFileExists());
+ assertThat(paramsManager.saveMetadataFile(TEST_PARAMS)).isTrue();
+ assertThat(paramsManager.metadataFileExists()).isTrue();
}
@Test
public void testFileContentValid() {
TransferOwnershipMetadataManager paramsManager = getOwnerTransferParams();
- assertTrue(paramsManager.saveMetadataFile(TEST_PARAMS));
+ assertThat(paramsManager.saveMetadataFile(TEST_PARAMS)).isTrue();
Path path = Paths.get(new File(mMockInjector.getOwnerTransferMetadataDir(),
OWNER_TRANSFER_METADATA_XML).getAbsolutePath());
try {
String contents = new String(Files.readAllBytes(path), Charset.forName("UTF-8"));
- assertEquals(
- "\n"
- + "<" + TAG_USER_ID + ">" + USER_ID + "" + TAG_USER_ID + ">\n"
- + "<" + TAG_SOURCE_COMPONENT + ">" + SOURCE_COMPONENT + ""
- + TAG_SOURCE_COMPONENT + ">\n"
- + "<" + TAG_TARGET_COMPONENT + ">" + TARGET_COMPONENT + ""
- + TAG_TARGET_COMPONENT + ">\n"
- + "<" + TAG_ADMIN_TYPE + ">" + ADMIN_TYPE_DEVICE_OWNER + ""
- + TAG_ADMIN_TYPE + ">\n",
- contents);
+ assertThat(contents).isEqualTo(
+ "\n"
+ + "<" + TAG_USER_ID + ">" + USER_ID + "" + TAG_USER_ID + ">\n"
+ + "<" + TAG_SOURCE_COMPONENT + ">" + SOURCE_COMPONENT + ""
+ + TAG_SOURCE_COMPONENT + ">\n"
+ + "<" + TAG_TARGET_COMPONENT + ">" + TARGET_COMPONENT + ""
+ + TAG_TARGET_COMPONENT + ">\n"
+ + "<" + TAG_ADMIN_TYPE + ">" + ADMIN_TYPE_DEVICE_OWNER + ""
+ + TAG_ADMIN_TYPE + ">\n");
} catch (IOException e) {
e.printStackTrace();
}
@@ -124,7 +124,7 @@ public class TransferOwnershipMetadataManagerTest {
Log.d(TAG, "testLoad: failed to get canonical file");
}
paramsManager.saveMetadataFile(TEST_PARAMS);
- assertEquals(TEST_PARAMS, paramsManager.loadMetadataFile());
+ assertThat(paramsManager.loadMetadataFile()).isEqualTo(TEST_PARAMS);
}
@Test
@@ -132,7 +132,7 @@ public class TransferOwnershipMetadataManagerTest {
TransferOwnershipMetadataManager paramsManager = getOwnerTransferParams();
paramsManager.saveMetadataFile(TEST_PARAMS);
paramsManager.deleteMetadataFile();
- assertFalse(paramsManager.metadataFileExists());
+ assertThat(paramsManager.metadataFileExists()).isFalse();
}
@After
+ atest FrameworksServicesTests:com.android.server.devicepolicy.TransferOwnershipMetadataManagerTest
+ *