Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 133c627f authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Fix UserManagerTest#testGetUserCreationTime.

Fixes: 31152306
Test: adb shell am instrument -e class com.android.server.pm.UserManagerTest -w com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I80de0899390d3dd9d7cd058cd9598665cb1f767b
parent 34a752d4
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@ import java.util.List;

/** Test {@link UserManager} functionality. */
public class UserManagerTest extends AndroidTestCase {
    // Taken from UserManagerService
    private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // 30 years

    private static final int REMOVE_CHECK_INTERVAL_MILLIS = 500; // 0.5 seconds
    private static final int REMOVE_TIMEOUT_MILLIS = 60 * 1000; // 60 seconds
    private static final int SWITCH_USER_TIMEOUT_MILLIS = 40 * 1000; // 40 seconds
@@ -204,18 +207,28 @@ public class UserManagerTest extends AndroidTestCase {
    @MediumTest
    public void testGetUserCreationTime() throws Exception {
        final int primaryUserId = mUserManager.getPrimaryUser().id;
        final long startTime = System.currentTimeMillis();
        UserInfo profile = createProfileForUser("Managed 1",
                UserInfo.FLAG_MANAGED_PROFILE, primaryUserId);
        final long endTime = System.currentTimeMillis();
        assertNotNull(profile);
        if (System.currentTimeMillis() > EPOCH_PLUS_30_YEARS) {
            assertTrue("creationTime must be set when the profile is created",
                profile.creationTime > 0);
                    profile.creationTime >= startTime && profile.creationTime <= endTime);
        } else {
            assertTrue("creationTime must be 0 if the time is not > EPOCH_PLUS_30_years",
                    profile.creationTime == 0);
        }
        assertEquals(profile.creationTime, mUserManager.getUserCreationTime(
                new UserHandle(profile.id)));

        long ownerCreationTime = mUserManager.getUserInfo(primaryUserId).creationTime;
        assertEquals(ownerCreationTime, mUserManager.getUserCreationTime(
                new UserHandle(primaryUserId)));
    }

    @SmallTest
    public void testGetUserCreationTime_nonExistentUser() throws Exception {
        try {
            int noSuchUserId = 100500;
            mUserManager.getUserCreationTime(new UserHandle(noSuchUserId));
@@ -224,7 +237,10 @@ public class UserManagerTest extends AndroidTestCase {
            assertTrue("SecurityException should be thrown for nonexistent user, but was: " + e,
                    e instanceof SecurityException);
        }
    }

    @SmallTest
    public void testGetUserCreationTime_otherUser() throws Exception {
        UserInfo user = createUser("User 1", 0);
        try {
            mUserManager.getUserCreationTime(new UserHandle(user.id));