Push profile owners into DeviceStateCache on boot

Fixes: 271996196
Test: atest com.android.server.devicepolicy.OwnersTest
Change-Id: I6dab9c717349545ab9be27ea12a251dcd5ce6025
This commit is contained in:
Pavel Grafov
2023-03-07 15:02:15 +00:00
parent 1edbb3a04e
commit c0273b49b7
2 changed files with 14 additions and 3 deletions

View File

@@ -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) {

View File

@@ -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