DevicePolicyManager unit test improvements:

- Use JUnit4 and Truth.
- Updated javadoc instructions to use atest.
- Add missing license header.
- Re-added @FlakyTests.
- Other minor improvements, like removing some redundant eq() calls.

Test: atest \
      FrameworksServicesTests:OwnersTest \
      FrameworksServicesTests:FactoryResetProtectionPolicyTest \
      FrameworksServicesTests:DevicePolicyConstantsTest \
      FrameworksServicesTests:DevicePolicyManagerServiceMigrationTest \
      FrameworksServicesTests:NetworkEventTest \
      FrameworksServicesTests:OverlayPackagesProviderTest \
      FrameworksServicesTests:SecurityEventTest \
      FrameworksServicesTests:SystemUpdatePolicyTest \
      FrameworksServicesTests:TransferOwnershipMetadataManagerTest \
      FrameworksServicesTests:DevicePolicyManagerTest

Bug: 171932723
Bug: 30839080

Change-Id: Ie50fa12032aa4c45636ce485d66507ddd4cac16b
This commit is contained in:
Felipe Leme
2020-10-28 18:58:25 -07:00
parent 1c4c42ff22
commit fd65c456b5
12 changed files with 1471 additions and 1142 deletions

View File

@@ -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
* <p>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);
}
}

View File

@@ -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);
}

View File

@@ -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<String> alreadySet =
dpms.getProfileOwnerAdminLocked(10).defaultEnabledRestrictionsAlreadySet;
assertEquals(alreadySet.size(), 1);
assertTrue(alreadySet.contains(UserManager.DISALLOW_BLUETOOTH_SHARING));
assertThat(alreadySet).hasSize(1);
assertThat(alreadySet.contains(UserManager.DISALLOW_BLUETOOTH_SHARING)).isTrue();
}
@SmallTest
@Test
public void testCompMigrationUnAffiliated_skipped() throws Exception {
prepareAdmin1AsDo();
prepareAdminAnotherPackageAsPo(COPE_PROFILE_USER_ID);
@@ -364,10 +375,11 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
final DevicePolicyManagerServiceTestable dpms = bootDpmsUp();
// DO should still be DO since no migration should happen.
assertTrue(dpms.mOwners.hasDeviceOwner());
assertThat(dpms.mOwners.hasDeviceOwner()).isTrue();
}
@SmallTest
@Test
public void testCompMigrationAffiliated() throws Exception {
prepareAdmin1AsDo();
prepareAdmin1AsPo(COPE_PROFILE_USER_ID, Build.VERSION_CODES.R);
@@ -378,48 +390,54 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
final DevicePolicyManagerServiceTestable dpms = bootDpmsUp();
// DO should cease to be DO.
assertFalse(dpms.mOwners.hasDeviceOwner());
assertThat(dpms.mOwners.hasDeviceOwner()).isFalse();
final DpmMockContext poContext = new DpmMockContext(getServices(), mRealTestContext);
poContext.binder.callingUid = UserHandle.getUid(COPE_PROFILE_USER_ID, COPE_ADMIN1_APP_ID);
runAsCaller(poContext, dpms, dpm -> {
assertEquals("Password history policy wasn't migrated to PO parent instance",
33, dpm.getParentProfileInstance(admin1).getPasswordHistoryLength(admin1));
assertEquals("Password history policy was put into non-parent PO instance",
0, dpm.getPasswordHistoryLength(admin1));
assertTrue("Screen capture restriction wasn't migrated to PO parent instance",
dpm.getParentProfileInstance(admin1).getScreenCaptureDisabled(admin1));
assertWithMessage("Password history policy wasn't migrated to PO parent instance")
.that(dpm.getParentProfileInstance(admin1).getPasswordHistoryLength(admin1))
.isEqualTo(33);
assertWithMessage("Password history policy was put into non-parent PO instance")
.that(dpm.getPasswordHistoryLength(admin1)).isEqualTo(0);
assertWithMessage("Screen capture restriction wasn't migrated to PO parent instance")
.that(dpm.getParentProfileInstance(admin1).getScreenCaptureDisabled(admin1))
.isTrue();
assertArrayEquals("Accounts with management disabled weren't migrated to PO parent",
new String[] {"com.google-primary"},
dpm.getParentProfileInstance(admin1).getAccountTypesWithManagementDisabled());
assertArrayEquals("Accounts with management disabled for profile were lost",
new String[] {"com.google-profile"},
dpm.getAccountTypesWithManagementDisabled());
assertWithMessage("Accounts with management disabled weren't migrated to PO parent")
.that(dpm.getParentProfileInstance(admin1)
.getAccountTypesWithManagementDisabled()).asList()
.containsExactly("com.google-primary");
assertTrue("User restriction wasn't migrated to PO parent instance",
dpm.getParentProfileInstance(admin1).getUserRestrictions(admin1)
.containsKey(UserManager.DISALLOW_BLUETOOTH));
assertFalse("User restriction was put into non-parent PO instance",
dpm.getUserRestrictions(admin1).containsKey(UserManager.DISALLOW_BLUETOOTH));
assertWithMessage("Accounts with management disabled for profile were lost")
.that(dpm.getAccountTypesWithManagementDisabled()).asList()
.containsExactly("com.google-profile");
assertTrue("User restriction wasn't migrated to PO parent instance",
dpms.getProfileOwnerAdminLocked(COPE_PROFILE_USER_ID)
.getParentActiveAdmin()
.getEffectiveRestrictions()
.containsKey(UserManager.DISALLOW_CONFIG_DATE_TIME));
assertFalse("User restriction was put into non-parent PO instance",
dpms.getProfileOwnerAdminLocked(COPE_PROFILE_USER_ID)
.getEffectiveRestrictions()
.containsKey(UserManager.DISALLOW_CONFIG_DATE_TIME));
assertEquals("Personal apps suspension wasn't migrated",
DevicePolicyManager.PERSONAL_APPS_NOT_SUSPENDED,
dpm.getPersonalAppsSuspendedReasons(admin1));
assertWithMessage("User restriction wasn't migrated to PO parent instance")
.that(dpm.getParentProfileInstance(admin1).getUserRestrictions(admin1).keySet())
.contains(UserManager.DISALLOW_BLUETOOTH);
assertWithMessage("User restriction was put into non-parent PO instance").that(
dpm.getUserRestrictions(admin1).keySet())
.doesNotContain(UserManager.DISALLOW_BLUETOOTH);
assertWithMessage("User restriction wasn't migrated to PO parent instance")
.that(dpms.getProfileOwnerAdminLocked(COPE_PROFILE_USER_ID)
.getParentActiveAdmin().getEffectiveRestrictions().keySet())
.contains(UserManager.DISALLOW_CONFIG_DATE_TIME);
assertWithMessage("User restriction was put into non-parent PO instance")
.that(dpms.getProfileOwnerAdminLocked(COPE_PROFILE_USER_ID)
.getEffectiveRestrictions().keySet())
.doesNotContain(UserManager.DISALLOW_CONFIG_DATE_TIME);
assertWithMessage("Personal apps suspension wasn't migrated")
.that(dpm.getPersonalAppsSuspendedReasons(admin1))
.isEqualTo(DevicePolicyManager.PERSONAL_APPS_NOT_SUSPENDED);
});
}
@SmallTest
@Test
public void testCompMigration_keepSuspendedAppsWhenDpcIsRPlus() throws Exception {
prepareAdmin1AsDo();
prepareAdmin1AsPo(COPE_PROFILE_USER_ID, Build.VERSION_CODES.R);
@@ -445,13 +463,14 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
poContext.binder.callingUid = UserHandle.getUid(COPE_PROFILE_USER_ID, COPE_ADMIN1_APP_ID);
runAsCaller(poContext, dpms, dpm -> {
assertEquals("Personal apps suspension wasn't migrated",
DevicePolicyManager.PERSONAL_APPS_SUSPENDED_EXPLICITLY,
dpm.getPersonalAppsSuspendedReasons(admin1));
assertWithMessage("Personal apps suspension wasn't migrated")
.that(dpm.getPersonalAppsSuspendedReasons(admin1))
.isEqualTo(DevicePolicyManager.PERSONAL_APPS_SUSPENDED_EXPLICITLY);
});
}
@SmallTest
@Test
public void testCompMigration_unsuspendAppsWhenDpcNotRPlus() throws Exception {
prepareAdmin1AsDo();
prepareAdmin1AsPo(COPE_PROFILE_USER_ID, Build.VERSION_CODES.Q);
@@ -470,9 +489,9 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
poContext.binder.callingUid = UserHandle.getUid(COPE_PROFILE_USER_ID, COPE_ADMIN1_APP_ID);
runAsCaller(poContext, dpms, dpm -> {
assertEquals("Personal apps weren't unsuspended",
DevicePolicyManager.PERSONAL_APPS_NOT_SUSPENDED,
dpm.getPersonalAppsSuspendedReasons(admin1));
assertWithMessage("Personal apps weren't unsuspended")
.that(dpm.getPersonalAppsSuspendedReasons(admin1))
.isEqualTo(DevicePolicyManager.PERSONAL_APPS_NOT_SUSPENDED);
});
}

View File

@@ -16,6 +16,8 @@
package com.android.server.devicepolicy;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
@@ -35,18 +37,28 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.UserHandle;
import android.test.AndroidTestCase;
import androidx.test.InstrumentationRegistry;
import org.junit.Before;
import java.io.InputStream;
import java.util.List;
public abstract class DpmTestBase extends AndroidTestCase {
/**
* Temporary copy of DpmTestBase using JUnit 4 - once all tests extend it, it should be renamed
* back to DpmTestBase (with the temporary methods removed.
*
*/
public abstract class DpmTestBase {
public static final String TAG = "DpmTest";
protected Context mRealTestContext;
protected final Context mRealTestContext = InstrumentationRegistry.getTargetContext();
protected DpmMockContext mMockContext;
private MockSystemServices mServices;
// Attributes below are public so they don't need to be prefixed with m
public ComponentName admin1;
public ComponentName admin2;
public ComponentName admin3;
@@ -54,12 +66,8 @@ public abstract class DpmTestBase extends AndroidTestCase {
public ComponentName adminNoPerm;
public ComponentName delegateCertInstaller;
@Override
protected void setUp() throws Exception {
super.setUp();
mRealTestContext = super.getContext();
@Before
public void setFixtures() throws Exception {
mServices = new MockSystemServices(mRealTestContext, "test-data");
mMockContext = new DpmMockContext(mServices, mRealTestContext);
@@ -74,8 +82,7 @@ public abstract class DpmTestBase extends AndroidTestCase {
mockSystemPropertiesToReturnDefault();
}
@Override
public DpmMockContext getContext() {
protected DpmMockContext getContext() {
return mMockContext;
}
@@ -136,20 +143,15 @@ public abstract class DpmTestBase extends AndroidTestCase {
final PackageInfo pi = DpmTestUtils.cloneParcelable(
mRealTestContext.getPackageManager().getPackageInfo(
mRealTestContext.getPackageName(), 0));
assertTrue(pi.applicationInfo.flags != 0);
assertThat(pi.applicationInfo.flags).isNotEqualTo(0);
if (ai != null) {
pi.applicationInfo = ai;
}
doReturn(pi).when(mServices.ipackageManager).getPackageInfo(
eq(packageName),
eq(0),
eq(userId));
doReturn(pi).when(mServices.ipackageManager).getPackageInfo(packageName, 0, userId);
doReturn(ai.uid).when(mServices.packageManager).getPackageUidAsUser(
eq(packageName),
eq(userId));
doReturn(ai.uid).when(mServices.packageManager).getPackageUidAsUser(packageName, userId);
}
protected void markDelegatedCertInstallerAsInstalled() throws Exception {
@@ -230,8 +232,8 @@ public abstract class DpmTestBase extends AndroidTestCase {
mRealTestContext.getPackageManager().queryBroadcastReceivers(
resolveIntent,
PackageManager.GET_META_DATA);
assertNotNull(realResolveInfo);
assertEquals(1, realResolveInfo.size());
assertThat(realResolveInfo).isNotNull();
assertThat(realResolveInfo).hasSize(1);
// We need to change AI, so set a clone.
realResolveInfo.set(0, DpmTestUtils.cloneParcelable(realResolveInfo.get(0)));

View File

@@ -16,8 +16,8 @@
package com.android.server.devicepolicy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -100,7 +100,7 @@ public class FactoryResetProtectionPolicyTest {
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);
assertPoliciesAreEqual(policy, policy.readFromXml(parser));
}
@@ -114,7 +114,7 @@ public class FactoryResetProtectionPolicyTest {
parser.setInput(new InputStreamReader(inStream));
// If deserialization fails, then null is returned.
assertNull(policy.readFromXml(parser));
assertThat(policy.readFromXml(parser)).isNull();
}
private ByteArrayOutputStream serialize(FactoryResetProtectionPolicy policy)
@@ -133,17 +133,17 @@ public class FactoryResetProtectionPolicyTest {
private void assertPoliciesAreEqual(FactoryResetProtectionPolicy expectedPolicy,
FactoryResetProtectionPolicy actualPolicy) {
assertEquals(expectedPolicy.isFactoryResetProtectionEnabled(),
actualPolicy.isFactoryResetProtectionEnabled());
assertThat(actualPolicy.isFactoryResetProtectionEnabled())
.isEqualTo(expectedPolicy.isFactoryResetProtectionEnabled());
assertAccountsAreEqual(expectedPolicy.getFactoryResetProtectionAccounts(),
actualPolicy.getFactoryResetProtectionAccounts());
}
private void assertAccountsAreEqual(List<String> expectedAccounts,
List<String> actualAccounts) {
assertEquals(expectedAccounts.size(), actualAccounts.size());
assertThat(actualAccounts.size()).isEqualTo(expectedAccounts.size());
for (int i = 0; i < expectedAccounts.size(); i++) {
assertEquals(expectedAccounts.get(i), actualAccounts.get(i));
assertThat(actualAccounts.get(i)).isEqualTo(expectedAccounts.get(i));
}
}

View File

@@ -17,6 +17,9 @@ package com.android.server.devicepolicy;
import static com.android.server.devicepolicy.NetworkLoggingHandler.LOG_NETWORK_EVENT_MSG;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy;
@@ -37,8 +40,9 @@ import android.os.test.TestLooper;
import android.test.suitebuilder.annotation.SmallTest;
import com.android.server.LocalServices;
import com.android.server.SystemService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import java.util.List;
@@ -50,9 +54,8 @@ public class NetworkEventTest extends DpmTestBase {
private DpmMockContext mSpiedDpmMockContext;
private DevicePolicyManagerServiceTestable mDpmTestable;
@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
mSpiedDpmMockContext = spy(mMockContext);
mSpiedDpmMockContext.callerPermissions.add(
android.Manifest.permission.MANAGE_DEVICE_ADMINS);
@@ -64,6 +67,7 @@ public class NetworkEventTest extends DpmTestBase {
mDpmTestable.setActiveAdmin(admin1, true, DpmMockContext.CALLER_USER_HANDLE);
}
@Test
public void testNetworkEventId_monotonicallyIncreasing() throws Exception {
// GIVEN the handler has not processed any events.
long startingId = 0;
@@ -72,17 +76,20 @@ public class NetworkEventTest extends DpmTestBase {
List<NetworkEvent> events = fillHandlerWithFullBatchOfEvents(startingId);
// THEN the events are in a batch.
assertTrue("Batch not at the returned token.",
events != null && events.size() == MAX_EVENTS_PER_BATCH);
assertWithMessage("Batch not at the returned token.").that(events).isNotNull();
assertWithMessage("Batch not at the returned token.").that(events)
.hasSize(MAX_EVENTS_PER_BATCH);
// THEN event ids are monotonically increasing.
long expectedId = startingId;
for (int i = 0; i < MAX_EVENTS_PER_BATCH; i++) {
assertEquals("At index " + i + ", the event has the wrong id.", expectedId,
events.get(i).getId());
assertWithMessage("At index %s, the event has the wrong id.", i)
.that(events.get(i).getId()).isEqualTo(expectedId);
expectedId++;
}
}
@Test
public void testNetworkEventId_wrapsAround() throws Exception {
// GIVEN the handler has almost processed Long.MAX_VALUE events.
int gap = 5;
@@ -92,24 +99,25 @@ public class NetworkEventTest extends DpmTestBase {
List<NetworkEvent> events = fillHandlerWithFullBatchOfEvents(startingId);
// THEN the events are in a batch.
assertTrue("Batch not at the returned token.",
events != null && events.size() == MAX_EVENTS_PER_BATCH);
assertWithMessage("Batch not at the returned token.").that(events).isNotNull();
assertWithMessage("Batch not at the returned token.").that(events)
.hasSize(MAX_EVENTS_PER_BATCH);
// THEN event ids are monotonically increasing.
long expectedId = startingId;
for (int i = 0; i < gap; i++) {
assertEquals("At index " + i + ", the event has the wrong id.", expectedId,
events.get(i).getId());
assertWithMessage("At index %s, the event has the wrong id.", i)
.that(events.get(i).getId()).isEqualTo(expectedId);
expectedId++;
}
// THEN event ids are reset when the id reaches the maximum possible value.
assertEquals("Event was not assigned the maximum id value.", Long.MAX_VALUE,
events.get(gap).getId());
assertEquals("Event id was not reset.", 0, events.get(gap + 1).getId());
assertWithMessage("Event was not assigned the maximum id value.")
.that(events.get(gap).getId()).isEqualTo(Long.MAX_VALUE);
assertWithMessage("Event id was not reset.").that(events.get(gap + 1).getId()).isEqualTo(0);
// THEN event ids are monotonically increasing.
expectedId = 0;
for (int i = gap + 1; i < MAX_EVENTS_PER_BATCH; i++) {
assertEquals("At index " + i + ", the event has the wrong id.", expectedId,
events.get(i).getId());
assertWithMessage("At index %s, the event has the wrong id.", i)
.that(events.get(i).getId()).isEqualTo(expectedId);
expectedId++;
}
}
@@ -134,8 +142,8 @@ public class NetworkEventTest extends DpmTestBase {
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mSpiedDpmMockContext).sendBroadcastAsUser(intentCaptor.capture(),
any(UserHandle.class));
assertEquals(intentCaptor.getValue().getAction(),
DeviceAdminReceiver.ACTION_NETWORK_LOGS_AVAILABLE);
assertThat(DeviceAdminReceiver.ACTION_NETWORK_LOGS_AVAILABLE)
.isEqualTo(intentCaptor.getValue().getAction());
long token = intentCaptor.getValue().getExtras().getLong(
DeviceAdminReceiver.EXTRA_NETWORK_LOGS_TOKEN, 0);
return handler.retrieveFullLogBatch(token);
@@ -144,6 +152,7 @@ public class NetworkEventTest extends DpmTestBase {
/**
* Test parceling and unparceling of a ConnectEvent.
*/
@Test
public void testConnectEventParceling() {
ConnectEvent event = new ConnectEvent("127.0.0.1", 80, "com.android.whateverdude", 100000);
event.setId(5L);
@@ -152,16 +161,17 @@ public class NetworkEventTest extends DpmTestBase {
p.setDataPosition(0);
ConnectEvent unparceledEvent = p.readParcelable(NetworkEventTest.class.getClassLoader());
p.recycle();
assertEquals(event.getInetAddress(), unparceledEvent.getInetAddress());
assertEquals(event.getPort(), unparceledEvent.getPort());
assertEquals(event.getPackageName(), unparceledEvent.getPackageName());
assertEquals(event.getTimestamp(), unparceledEvent.getTimestamp());
assertEquals(event.getId(), unparceledEvent.getId());
assertThat(unparceledEvent.getInetAddress()).isEqualTo(event.getInetAddress());
assertThat(unparceledEvent.getPort()).isEqualTo(event.getPort());
assertThat(unparceledEvent.getPackageName()).isEqualTo(event.getPackageName());
assertThat(unparceledEvent.getTimestamp()).isEqualTo(event.getTimestamp());
assertThat(unparceledEvent.getId()).isEqualTo(event.getId());
}
/**
* Test parceling and unparceling of a DnsEvent.
*/
@Test
public void testDnsEventParceling() {
DnsEvent event = new DnsEvent("d.android.com", new String[]{"192.168.0.1", "127.0.0.1"}, 2,
"com.android.whateverdude", 100000);
@@ -171,13 +181,15 @@ public class NetworkEventTest extends DpmTestBase {
p.setDataPosition(0);
DnsEvent unparceledEvent = p.readParcelable(NetworkEventTest.class.getClassLoader());
p.recycle();
assertEquals(event.getHostname(), unparceledEvent.getHostname());
assertEquals(event.getInetAddresses().get(0), unparceledEvent.getInetAddresses().get(0));
assertEquals(event.getInetAddresses().get(1), unparceledEvent.getInetAddresses().get(1));
assertEquals(event.getTotalResolvedAddressCount(),
unparceledEvent.getTotalResolvedAddressCount());
assertEquals(event.getPackageName(), unparceledEvent.getPackageName());
assertEquals(event.getTimestamp(), unparceledEvent.getTimestamp());
assertEquals(event.getId(), unparceledEvent.getId());
assertThat(unparceledEvent.getHostname()).isEqualTo(event.getHostname());
assertThat(unparceledEvent.getInetAddresses().get(0))
.isEqualTo(event.getInetAddresses().get(0));
assertThat(unparceledEvent.getInetAddresses().get(1))
.isEqualTo(event.getInetAddresses().get(1));
assertThat(unparceledEvent.getTotalResolvedAddressCount())
.isEqualTo(event.getTotalResolvedAddressCount());
assertThat(unparceledEvent.getPackageName()).isEqualTo(event.getPackageName());
assertThat(unparceledEvent.getTimestamp()).isEqualTo(event.getTimestamp());
assertThat(unparceledEvent.getId()).isEqualTo(event.getId());
}
}

View File

@@ -20,6 +20,9 @@ import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_DEV
import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_PROFILE;
import static android.app.admin.DevicePolicyManager.ACTION_PROVISION_MANAGED_USER;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.when;
@@ -32,16 +35,17 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.test.mock.MockPackageManager;
import android.view.inputmethod.InputMethodInfo;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -51,18 +55,23 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class OverlayPackagesProviderTest extends AndroidTestCase {
/**
* Run this test with:
*
* {@code atest FrameworksServicesTests:com.android.server.devicepolicy.OwnersTest}
*
*/
@RunWith(AndroidJUnit4.class)
public class OverlayPackagesProviderTest {
private static final String TEST_DPC_PACKAGE_NAME = "dpc.package.name";
private static final ComponentName TEST_MDM_COMPONENT_NAME = new ComponentName(
TEST_DPC_PACKAGE_NAME, "pc.package.name.DeviceAdmin");
private static final int TEST_USER_ID = 123;
private @Mock
Resources mResources;
@Mock
private OverlayPackagesProvider.Injector mInjector;
private @Mock
Context mTestContext;
private @Mock Resources mResources;
private @Mock OverlayPackagesProvider.Injector mInjector;
private @Mock Context mTestContext;
private Resources mRealResources;
private FakePackageManager mPackageManager;
@@ -256,12 +265,12 @@ public class OverlayPackagesProviderTest extends AndroidTestCase {
ArrayList<String> required = getStringArrayInRealResources(requiredId);
ArrayList<String> disallowed = getStringArrayInRealResources(disallowedId);
required.retainAll(disallowed);
assertTrue(required.isEmpty());
assertThat(required.isEmpty()).isTrue();
}
private void verifyAppsAreNonRequired(String action, String... appArray) {
assertEquals(setFromArray(appArray),
mHelper.getNonRequiredApps(TEST_MDM_COMPONENT_NAME, TEST_USER_ID, action));
assertThat(mHelper.getNonRequiredApps(TEST_MDM_COMPONENT_NAME, TEST_USER_ID, action))
.containsExactlyElementsIn(setFromArray(appArray));
}
private void setRequiredAppsManagedDevice(String... apps) {
@@ -348,19 +357,19 @@ public class OverlayPackagesProviderTest extends AndroidTestCase {
class FakePackageManager extends MockPackageManager {
@Override
public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent, int flags, int userId) {
assertTrue("Expected an intent with action ACTION_MAIN",
Intent.ACTION_MAIN.equals(intent.getAction()));
assertEquals("Expected an intent with category CATEGORY_LAUNCHER",
setFromArray(Intent.CATEGORY_LAUNCHER), intent.getCategories());
assertTrue("Expected the flag MATCH_UNINSTALLED_PACKAGES",
(flags & PackageManager.MATCH_UNINSTALLED_PACKAGES) != 0);
assertTrue("Expected the flag MATCH_DISABLED_COMPONENTS",
(flags & PackageManager.MATCH_DISABLED_COMPONENTS) != 0);
assertTrue("Expected the flag MATCH_DIRECT_BOOT_AWARE",
(flags & PackageManager.MATCH_DIRECT_BOOT_AWARE) != 0);
assertTrue("Expected the flag MATCH_DIRECT_BOOT_UNAWARE",
(flags & PackageManager.MATCH_DIRECT_BOOT_UNAWARE) != 0);
assertEquals(userId, TEST_USER_ID);
assertWithMessage("Expected an intent with action ACTION_MAIN")
.that(Intent.ACTION_MAIN.equals(intent.getAction())).isTrue();
assertWithMessage("Expected an intent with category CATEGORY_LAUNCHER")
.that(intent.getCategories()).containsExactly(Intent.CATEGORY_LAUNCHER);
assertWithMessage("Expected the flag MATCH_UNINSTALLED_PACKAGES")
.that((flags & PackageManager.MATCH_UNINSTALLED_PACKAGES)).isNotEqualTo(0);
assertWithMessage("Expected the flag MATCH_DISABLED_COMPONENTS")
.that((flags & PackageManager.MATCH_DISABLED_COMPONENTS)).isNotEqualTo(0);
assertWithMessage("Expected the flag MATCH_DIRECT_BOOT_AWARE")
.that((flags & PackageManager.MATCH_DIRECT_BOOT_AWARE)).isNotEqualTo(0);
assertWithMessage("Expected the flag MATCH_DIRECT_BOOT_UNAWARE")
.that((flags & PackageManager.MATCH_DIRECT_BOOT_UNAWARE)).isNotEqualTo(0);
assertThat(TEST_USER_ID).isEqualTo(userId);
List<ResolveInfo> result = new ArrayList<>();
if (mSystemAppsWithLauncher == null) {
return result;

View File

@@ -16,25 +16,32 @@
package com.android.server.devicepolicy;
import static com.google.common.truth.Truth.assertThat;
import android.content.ComponentName;
import android.os.UserHandle;
import android.test.suitebuilder.annotation.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.server.devicepolicy.DevicePolicyManagerServiceTestable.OwnersTestable;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests for the DeviceOwner object that saves & loads device and policy owner information.
* run this test with:
m FrameworksServicesTests &&
adb install \
-r out/target/product/hammerhead/data/app/FrameworksServicesTests/FrameworksServicesTests.apk &&
adb shell am instrument -e class com.android.server.devicepolicy.OwnersTest \
-w com.android.frameworks.servicestests/androidx.test.runner.AndroidJUnitRunner
(mmma frameworks/base/services/tests/servicestests/ for non-ninja build)
*
* <p>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();
}
}

View File

@@ -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.
*
* <p>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();
}

View File

@@ -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
* <p>NOTE: Throughout this test, we use {@code "MM-DD"} format to denote dates without year.
*
* <p>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<FreezePeriod> expectedPeriods) {
int i = 0;
for (FreezePeriod period : policy.getFreezePeriods()) {
assertEquals(expectedPeriods.get(i).getStart(), period.getStart());
assertEquals(expectedPeriods.get(i).getEnd(), period.getEnd());
assertThat(period.getStart()).isEqualTo(expectedPeriods.get(i).getStart());
assertThat(period.getEnd()).isEqualTo(expectedPeriods.get(i).getEnd());
i++;
}
}

View File

@@ -25,14 +25,13 @@ import static com.android.server.devicepolicy.TransferOwnershipMetadataManager.T
import static com.android.server.devicepolicy.TransferOwnershipMetadataManager.TAG_TARGET_COMPONENT;
import static com.android.server.devicepolicy.TransferOwnershipMetadataManager.TAG_USER_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static com.google.common.truth.Truth.assertThat;
import android.os.Environment;
import androidx.test.runner.AndroidJUnit4;
import android.util.Log;
import androidx.test.runner.AndroidJUnit4;
import com.android.server.devicepolicy.TransferOwnershipMetadataManager.Injector;
import com.android.server.devicepolicy.TransferOwnershipMetadataManager.Metadata;
@@ -51,12 +50,14 @@ import java.nio.file.Paths;
/**
* Unit tests for {@link TransferOwnershipMetadataManager}.
*
* bit FrameworksServicesTests:com.android.server.devicepolicy.TransferOwnershipMetadataManagerTest
* runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/devicepolicy/TransferOwnershipMetadataManagerTest.java
* */
* <p>Run this test with:
*
* <pre><code>
atest FrameworksServicesTests:com.android.server.devicepolicy.TransferOwnershipMetadataManagerTest
* </code></pre>
*/
@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(
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\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(
"<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\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