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

Commit 9397e311 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Push profile owners into DeviceStateCache on boot" into udc-dev

parents 16c14463 c0273b49
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -120,7 +120,9 @@ class Owners {
                } else {
                    mDeviceStateCache.setDeviceOwnerType(NO_DEVICE_OWNER);
                }

                for (int userId : usersIds) {
                    mDeviceStateCache.setHasProfileOwner(userId, hasProfileOwner(userId));
                }
            } else {
                mUserManagerInternal.setDeviceManaged(hasDeviceOwner());
                for (int userId : usersIds) {
+11 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;
import static android.app.admin.SystemUpdatePolicy.TYPE_INSTALL_WINDOWED;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import android.content.ComponentName;
import android.os.IpcDataCache;
@@ -43,6 +44,7 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class OwnersTest extends DpmTestBase {

    private static final int TEST_PO_USER = 10;
    private static final String TESTDPC_PACKAGE = "com.afwsamples.testdpc";
    private final DeviceStateCacheImpl mDeviceStateCache = new DeviceStateCacheImpl();

@@ -55,11 +57,11 @@ public class OwnersTest extends DpmTestBase {

    @Test
    public void loadProfileOwner() throws Exception {
        getServices().addUsers(10);
        getServices().addUsers(TEST_PO_USER);

        final Owners owners = makeOwners();

        DpmTestUtils.writeToFile(owners.getProfileOwnerFile(10),
        DpmTestUtils.writeToFile(owners.getProfileOwnerFile(TEST_PO_USER),
                DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/profile_owner_1.xml"));

        owners.load();
@@ -71,6 +73,9 @@ public class OwnersTest extends DpmTestBase {
        assertThat(owners.getProfileOwnerComponent(10))
                .isEqualTo(new ComponentName(TESTDPC_PACKAGE,
                        "com.afwsamples.testdpc.DeviceAdminReceiver"));

        assertWithMessage("Profile owner data in DeviceStateCache wasn't populated")
                .that(mDeviceStateCache.isUserOrganizationManaged(TEST_PO_USER)).isTrue();
    }

    @Test
@@ -90,6 +95,10 @@ public class OwnersTest extends DpmTestBase {
                        "com.afwsamples.testdpc.DeviceAdminReceiver"));

        assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(TYPE_INSTALL_WINDOWED);

        assertWithMessage("Device owner data in DeviceStateCache wasn't populated")
                .that(mDeviceStateCache.isUserOrganizationManaged(owners.getDeviceOwnerUserId()))
                .isTrue();
    }

    @Test