Merge "Add API to set device owner type for a managed device" into sc-dev

This commit is contained in:
Rajeev Kumar
2021-02-25 00:21:51 +00:00
committed by Android (Google) Code Review
7 changed files with 310 additions and 1 deletions

View File

@@ -2746,6 +2746,32 @@ public class DevicePolicyManager {
@Retention(RetentionPolicy.SOURCE)
public @interface PersonalAppsSuspensionReason {}
/**
* The default device owner type for a managed device.
*
* @hide
*/
public static final int DEVICE_OWNER_TYPE_DEFAULT = 0;
/**
* The device owner type for a financed device.
*
* @hide
*/
public static final int DEVICE_OWNER_TYPE_FINANCED = 1;
/**
* Different device owner types for a managed device.
*
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = { "DEVICE_OWNER_TYPE_" }, value = {
DEVICE_OWNER_TYPE_DEFAULT,
DEVICE_OWNER_TYPE_FINANCED
})
public @interface DeviceOwnerType {}
/** @hide */
@TestApi
public static final int OPERATION_LOCK_NOW = 1;
@@ -13459,6 +13485,57 @@ public class DevicePolicyManager {
}
}
/**
* Sets the device owner type for a managed device (e.g. financed device).
*
* @param admin The {@link DeviceAdminReceiver} that is the device owner.
* @param deviceOwnerType The device owner type is set to. Use
* {@link #DEVICE_OWNER_TYPE_DEFAULT} for the default device owner type. Use
* {@link #DEVICE_OWNER_TYPE_FINANCED} for the financed device owner type.
*
* @throws IllegalStateException When admin is not the device owner, or there is no device
* owner, or attempting to set the device owner type again for the same admin.
* @throws SecurityException If the caller does not have the permission
* {@link permission#MANAGE_PROFILE_AND_DEVICE_OWNERS}.
*
* @hide
*/
public void setDeviceOwnerType(@NonNull ComponentName admin,
@DeviceOwnerType int deviceOwnerType) {
throwIfParentInstance("setDeviceOwnerType");
if (mService != null) {
try {
mService.setDeviceOwnerType(admin, deviceOwnerType);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
}
}
/**
* Returns the device owner type for the admin used in
* {@link #setDeviceOwnerType(ComponentName, int)}. {@link #DEVICE_OWNER_TYPE_DEFAULT}
* would be returned when the device owner type is not set for the device owner admin.
*
* @param admin The {@link DeviceAdminReceiver} that is the device owner.
*
* @throws IllegalStateException When admin is not the device owner or there is no device owner.
*
* @hide
*/
@DeviceOwnerType
public int getDeviceOwnerType(@NonNull ComponentName admin) {
throwIfParentInstance("getDeviceOwnerType");
if (mService != null) {
try {
return mService.getDeviceOwnerType(admin);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
}
return DEVICE_OWNER_TYPE_DEFAULT;
}
/**
* Called by device owner or profile owner of an organization-owned managed profile to
* enable or disable USB data signaling for the device. When disabled, USB data connections

View File

@@ -503,6 +503,9 @@ interface IDevicePolicyManager {
UserHandle createAndProvisionManagedProfile(in ManagedProfileProvisioningParams provisioningParams, in String callerPackage);
void provisionFullyManagedDevice(in FullyManagedDeviceProvisioningParams provisioningParams, in String callerPackage);
void setDeviceOwnerType(in ComponentName admin, in int deviceOwnerType);
int getDeviceOwnerType(in ComponentName admin);
void resetDefaultCrossProfileIntentFilters(int userId);
boolean canAdminGrantSensorsPermissionsForUser(int userId);

View File

@@ -129,6 +129,15 @@ abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub {
FullyManagedDeviceProvisioningParams provisioningParams, String callerPackage) {
}
@Override
public void setDeviceOwnerType(@NonNull ComponentName admin, int deviceOwnerType) {
}
@Override
public int getDeviceOwnerType(@NonNull ComponentName admin) {
return 0;
}
public void resetDefaultCrossProfileIntentFilters(@UserIdInt int userId) {}
public boolean canAdminGrantSensorsPermissionsForUser(int userId) {

View File

@@ -156,6 +156,7 @@ import android.app.admin.DeviceAdminReceiver;
import android.app.admin.DevicePolicyCache;
import android.app.admin.DevicePolicyEventLogger;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManager.DeviceOwnerType;
import android.app.admin.DevicePolicyManager.DevicePolicyOperation;
import android.app.admin.DevicePolicyManager.OperationSafetyReason;
import android.app.admin.DevicePolicyManager.PasswordComplexity;
@@ -16751,6 +16752,37 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
return mPolicyCache.canAdminGrantSensorsPermissionsForUser(userId);
}
@Override
public void setDeviceOwnerType(@NonNull ComponentName admin,
@DeviceOwnerType int deviceOwnerType) {
Preconditions.checkCallAuthorization(hasCallingOrSelfPermission(
permission.MANAGE_PROFILE_AND_DEVICE_OWNERS));
verifyDeviceOwnerTypePreconditions(admin);
final String packageName = admin.getPackageName();
Preconditions.checkState(!mOwners.isDeviceOwnerTypeSetForDeviceOwner(packageName),
"The device owner type has already been set for " + packageName);
synchronized (getLockObject()) {
mOwners.setDeviceOwnerType(packageName, deviceOwnerType);
}
}
@Override
@DeviceOwnerType
public int getDeviceOwnerType(@NonNull ComponentName admin) {
verifyDeviceOwnerTypePreconditions(admin);
synchronized (getLockObject()) {
return mOwners.getDeviceOwnerType(admin.getPackageName());
}
}
private void verifyDeviceOwnerTypePreconditions(@NonNull ComponentName admin) {
Preconditions.checkState(mOwners.hasDeviceOwner(), "there is no device owner");
Preconditions.checkState(mOwners.getDeviceOwnerComponent().equals(admin),
"admin is not the device owner");
}
@Override
public void setUsbDataSignalingEnabled(String packageName, boolean enabled) {
Objects.requireNonNull(packageName, "Admin package name must be provided");

View File

@@ -16,10 +16,13 @@
package com.android.server.devicepolicy;
import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_DEFAULT;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManagerInternal;
import android.app.AppOpsManagerInternal;
import android.app.admin.DevicePolicyManager.DeviceOwnerType;
import android.app.admin.SystemUpdateInfo;
import android.app.admin.SystemUpdatePolicy;
import android.content.ComponentName;
@@ -93,6 +96,7 @@ class Owners {
private static final String TAG_PROFILE_OWNER = "profile-owner";
// Holds "context" for device-owner, this must not be show up before device-owner.
private static final String TAG_DEVICE_OWNER_CONTEXT = "device-owner-context";
private static final String TAG_DEVICE_OWNER_TYPE = "device-owner-type";
private static final String ATTR_NAME = "name";
private static final String ATTR_PACKAGE = "package";
@@ -109,6 +113,7 @@ class Owners {
// New attribute for profile owner of organization-owned device.
private static final String ATTR_PROFILE_OWNER_OF_ORG_OWNED_DEVICE =
"isPoOrganizationOwnedDevice";
private static final String ATTR_DEVICE_OWNER_TYPE_VALUE = "value";
private final UserManager mUserManager;
private final UserManagerInternal mUserManagerInternal;
@@ -121,6 +126,9 @@ class Owners {
// Internal state for the device owner package.
private OwnerInfo mDeviceOwner;
// Device owner type for a managed device.
private final ArrayMap<String, Integer> mDeviceOwnerTypes = new ArrayMap<>();
private int mDeviceOwnerUserId = UserHandle.USER_NULL;
// Internal state for the profile owner packages.
@@ -334,6 +342,7 @@ class Owners {
void clearDeviceOwner() {
synchronized (mLock) {
mDeviceOwnerTypes.remove(mDeviceOwner.packageName);
mDeviceOwner = null;
mDeviceOwnerUserId = UserHandle.USER_NULL;
@@ -384,12 +393,16 @@ class Owners {
void transferDeviceOwnership(ComponentName target) {
synchronized (mLock) {
Integer previousDeviceOwnerType = mDeviceOwnerTypes.remove(mDeviceOwner.packageName);
// We don't set a name because it's not used anyway.
// See DevicePolicyManagerService#getDeviceOwnerName
mDeviceOwner = new OwnerInfo(null, target,
mDeviceOwner.userRestrictionsMigrated, mDeviceOwner.remoteBugreportUri,
mDeviceOwner.remoteBugreportHash, /* isOrganizationOwnedDevice =*/
mDeviceOwner.isOrganizationOwnedDevice);
if (previousDeviceOwnerType != null) {
mDeviceOwnerTypes.put(mDeviceOwner.packageName, previousDeviceOwnerType);
}
pushToPackageManagerLocked();
pushToActivityTaskManagerLocked();
pushToActivityManagerLocked();
@@ -596,6 +609,37 @@ class Owners {
}
}
void setDeviceOwnerType(String packageName, @DeviceOwnerType int deviceOwnerType) {
synchronized (mLock) {
if (!hasDeviceOwner()) {
Slog.e(TAG, "Attempting to set a device owner type when there is no device owner");
return;
} else if (isDeviceOwnerTypeSetForDeviceOwner(packageName)) {
Slog.e(TAG, "Device owner type for " + packageName + " has already been set");
return;
}
mDeviceOwnerTypes.put(packageName, deviceOwnerType);
writeDeviceOwner();
}
}
@DeviceOwnerType
int getDeviceOwnerType(String packageName) {
synchronized (mLock) {
if (isDeviceOwnerTypeSetForDeviceOwner(packageName)) {
return mDeviceOwnerTypes.get(packageName);
}
return DEVICE_OWNER_TYPE_DEFAULT;
}
}
boolean isDeviceOwnerTypeSetForDeviceOwner(String packageName) {
synchronized (mLock) {
return !mDeviceOwnerTypes.isEmpty() && mDeviceOwnerTypes.containsKey(packageName);
}
}
private boolean readLegacyOwnerFileLocked(File file) {
if (!file.exists()) {
// Already migrated or the device has no owners.
@@ -880,6 +924,16 @@ class Owners {
out.startTag(null, TAG_DEVICE_OWNER_CONTEXT);
out.attributeInt(null, ATTR_USERID, mDeviceOwnerUserId);
out.endTag(null, TAG_DEVICE_OWNER_CONTEXT);
}
if (!mDeviceOwnerTypes.isEmpty()) {
for (ArrayMap.Entry<String, Integer> entry : mDeviceOwnerTypes.entrySet()) {
out.startTag(null, TAG_DEVICE_OWNER_TYPE);
out.attribute(null, ATTR_PACKAGE, entry.getKey());
out.attributeInt(null, ATTR_DEVICE_OWNER_TYPE_VALUE, entry.getValue());
out.endTag(null, TAG_DEVICE_OWNER_TYPE);
}
}
if (mSystemUpdatePolicy != null) {
@@ -942,6 +996,12 @@ class Owners {
}
}
break;
case TAG_DEVICE_OWNER_TYPE:
String packageName = parser.getAttributeValue(null, ATTR_PACKAGE);
int deviceOwnerType = parser.getAttributeInt(null, ATTR_DEVICE_OWNER_TYPE_VALUE,
DEVICE_OWNER_TYPE_DEFAULT);
mDeviceOwnerTypes.put(packageName, deviceOwnerType);
break;
default:
Slog.e(TAG, "Unexpected tag: " + tag);
return false;

View File

@@ -20,6 +20,8 @@ import static android.app.Notification.EXTRA_TITLE;
import static android.app.admin.DevicePolicyManager.ACTION_CHECK_POLICY_COMPLIANCE;
import static android.app.admin.DevicePolicyManager.DELEGATION_APP_RESTRICTIONS;
import static android.app.admin.DevicePolicyManager.DELEGATION_CERT_INSTALL;
import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_DEFAULT;
import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;
import static android.app.admin.DevicePolicyManager.ID_TYPE_BASE_INFO;
import static android.app.admin.DevicePolicyManager.ID_TYPE_IMEI;
import static android.app.admin.DevicePolicyManager.ID_TYPE_MEID;
@@ -7027,6 +7029,71 @@ public class DevicePolicyManagerTest extends DpmTestBase {
DevicePolicyManager.PASSWORD_QUALITY_COMPLEX));
}
@Test
public void testSetDeviceOwnerType_throwsExceptionWhenCallerNotAuthorized() {
assertThrows(SecurityException.class,
() -> dpm.setDeviceOwnerType(admin1, DEVICE_OWNER_TYPE_DEFAULT));
}
@Test
public void testSetDeviceOwnerType_throwsExceptionWhenThereIsNoDeviceOwner() {
mContext.binder.clearCallingIdentity();
assertThrows(IllegalStateException.class,
() -> dpm.setDeviceOwnerType(admin1, DEVICE_OWNER_TYPE_DEFAULT));
}
@Test
public void testSetDeviceOwnerType_throwsExceptionWhenNotAsDeviceOwnerAdmin() throws Exception {
setDeviceOwner();
assertThrows(IllegalStateException.class,
() -> dpm.setDeviceOwnerType(admin2, DEVICE_OWNER_TYPE_FINANCED));
}
@Test
public void testSetDeviceOwnerType_asDeviceOwner_toFinancedDevice() throws Exception {
setDeviceOwner();
dpm.setDeviceOwnerType(admin1, DEVICE_OWNER_TYPE_FINANCED);
int returnedDeviceOwnerType = dpm.getDeviceOwnerType(admin1);
assertThat(dpms.mOwners.hasDeviceOwner()).isTrue();
assertThat(returnedDeviceOwnerType).isEqualTo(DEVICE_OWNER_TYPE_FINANCED);
initializeDpms();
returnedDeviceOwnerType = dpm.getDeviceOwnerType(admin1);
assertThat(dpms.mOwners.hasDeviceOwner()).isTrue();
assertThat(returnedDeviceOwnerType).isEqualTo(DEVICE_OWNER_TYPE_FINANCED);
}
@Test
public void testSetDeviceOwnerType_asDeviceOwner_throwsExceptionWhenSetDeviceOwnerTypeAgain()
throws Exception {
setDeviceOwner();
dpm.setDeviceOwnerType(admin1, DEVICE_OWNER_TYPE_FINANCED);
int returnedDeviceOwnerType = dpm.getDeviceOwnerType(admin1);
assertThat(dpms.mOwners.hasDeviceOwner()).isTrue();
assertThat(returnedDeviceOwnerType).isEqualTo(DEVICE_OWNER_TYPE_FINANCED);
assertThrows(IllegalStateException.class,
() -> dpm.setDeviceOwnerType(admin1, DEVICE_OWNER_TYPE_DEFAULT));
}
@Test
public void testGetDeviceOwnerType_throwsExceptionWhenThereIsNoDeviceOwner() {
assertThrows(IllegalStateException.class, () -> dpm.getDeviceOwnerType(admin1));
}
@Test
public void testGetDeviceOwnerType_throwsExceptionWhenNotAsDeviceOwnerAdmin() throws Exception {
setDeviceOwner();
assertThrows(IllegalStateException.class, () -> dpm.getDeviceOwnerType(admin2));
}
@Test
public void testSetUsbDataSignalingEnabled_noDeviceOwnerOrPoOfOrgOwnedDevice() {
assertThrows(SecurityException.class,

View File

@@ -16,6 +16,9 @@
package com.android.server.devicepolicy;
import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_DEFAULT;
import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_FINANCED;
import static com.google.common.truth.Truth.assertThat;
import android.content.ComponentName;
@@ -35,7 +38,6 @@ import org.junit.runner.RunWith;
* <p>Run this test with:
*
* {@code atest FrameworksServicesTests:com.android.server.devicepolicy.OwnersTest}
*
*/
@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -67,6 +69,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.hasDeviceOwner()).isFalse();
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getSystemUpdatePolicy()).isNull();
assertThat(owners.getProfileOwnerKeys()).isEmpty();
@@ -75,6 +79,12 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
owners.setDeviceOwnerType(owners.getDeviceOwnerPackageName(),
DEVICE_OWNER_TYPE_FINANCED);
// There is no device owner, so the default owner type should be returned.
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
}
// Then re-read and check.
@@ -84,6 +94,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.hasDeviceOwner()).isFalse();
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getSystemUpdatePolicy()).isNull();
assertThat(owners.getProfileOwnerKeys()).isEmpty();
@@ -122,6 +134,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.getDeviceOwnerName()).isEqualTo(null);
assertThat(owners.getDeviceOwnerPackageName()).isEqualTo("com.google.android.testdpc");
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_SYSTEM);
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getSystemUpdatePolicy()).isNull();
assertThat(owners.getProfileOwnerKeys()).isEmpty();
@@ -142,6 +156,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.getDeviceOwnerName()).isEqualTo(null);
assertThat(owners.getDeviceOwnerPackageName()).isEqualTo("com.google.android.testdpc");
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_SYSTEM);
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getSystemUpdatePolicy()).isNull();
assertThat(owners.getProfileOwnerKeys()).isEmpty();
@@ -180,6 +196,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.hasDeviceOwner()).isFalse();
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
assertThat(owners.getSystemUpdatePolicy()).isNull();
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getProfileOwnerKeys()).hasSize(2);
assertThat(owners.getProfileOwnerComponent(10))
@@ -208,6 +226,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.hasDeviceOwner()).isFalse();
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
assertThat(owners.getSystemUpdatePolicy()).isNull();
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getProfileOwnerKeys()).hasSize(2);
assertThat(owners.getProfileOwnerComponent(10))
@@ -260,6 +280,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.getDeviceOwnerName()).isEqualTo(null);
assertThat(owners.getDeviceOwnerPackageName()).isEqualTo("com.google.android.testdpc");
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_SYSTEM);
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getSystemUpdatePolicy()).isNotNull();
assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(5);
@@ -292,6 +314,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.getDeviceOwnerName()).isEqualTo(null);
assertThat(owners.getDeviceOwnerPackageName()).isEqualTo("com.google.android.testdpc");
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_SYSTEM);
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getSystemUpdatePolicy()).isNotNull();
assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(5);
@@ -315,12 +339,21 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
owners.setDeviceOwnerUserRestrictionsMigrated();
owners.setDeviceOwnerType(owners.getDeviceOwnerPackageName(),
DEVICE_OWNER_TYPE_FINANCED);
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_FINANCED);
}
{
final OwnersTestable owners = new OwnersTestable(getServices());
owners.load();
assertThat(owners.hasDeviceOwner()).isTrue();
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_FINANCED);
assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isTrue();
assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isTrue();
@@ -328,12 +361,22 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
owners.setProfileOwnerUserRestrictionsMigrated(11);
owners.setDeviceOwnerType(owners.getDeviceOwnerPackageName(),
DEVICE_OWNER_TYPE_DEFAULT);
// The previous device owner type should persist.
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_FINANCED);
}
{
final OwnersTestable owners = new OwnersTestable(getServices());
owners.load();
assertThat(owners.hasDeviceOwner()).isTrue();
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_FINANCED);
assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isTrue();
assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
@@ -369,6 +412,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.hasDeviceOwner()).isFalse();
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getSystemUpdatePolicy()).isNull();
@@ -388,6 +433,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.hasDeviceOwner()).isFalse();
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getSystemUpdatePolicy()).isNull();
@@ -425,6 +472,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.hasDeviceOwner()).isFalse();
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getProfileOwnerKeys()).isEmpty();
assertThat(owners.getSystemUpdatePolicy()).isNotNull();
@@ -444,6 +493,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.hasDeviceOwner()).isFalse();
assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getProfileOwnerKeys()).isEmpty();
assertThat(owners.getSystemUpdatePolicy()).isNotNull();
@@ -472,9 +523,16 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.getLegacyConfigFile().exists()).isFalse();
assertThat(owners.getDeviceOwnerFile().exists()).isTrue();
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
assertThat(owners.getProfileOwnerFile(10).exists()).isTrue();
assertThat(owners.getProfileOwnerFile(11).exists()).isTrue();
String previousDeviceOwnerPackageName = owners.getDeviceOwnerPackageName();
owners.setDeviceOwnerType(previousDeviceOwnerPackageName, DEVICE_OWNER_TYPE_FINANCED);
assertThat(owners.getDeviceOwnerType(previousDeviceOwnerPackageName)).isEqualTo(
DEVICE_OWNER_TYPE_FINANCED);
// Then clear all information and save.
owners.clearDeviceOwner();
owners.clearSystemUpdatePolicy();
@@ -491,5 +549,8 @@ public class OwnersTest extends DpmTestBase {
assertThat(owners.getDeviceOwnerFile().exists()).isFalse();
assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
assertThat(owners.getDeviceOwnerType(previousDeviceOwnerPackageName)).isEqualTo(
DEVICE_OWNER_TYPE_DEFAULT);
}
}