Merge "Remove fossilized upgrade code." into tm-dev am: c291627ea9 am: 4bb26ef6b0
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17591526
Change-Id: Ib30389f994e2ee273565951414af8b84e0c9ec6e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/services/core/java/com/android/server/pm/UserManagerInternal.java b/services/core/java/com/android/server/pm/UserManagerInternal.java
index 0e6d5e5..8dc9428 100644
--- a/services/core/java/com/android/server/pm/UserManagerInternal.java
+++ b/services/core/java/com/android/server/pm/UserManagerInternal.java
@@ -92,21 +92,6 @@
public abstract void setDevicePolicyUserRestrictions(int originatingUserId,
@Nullable Bundle global, @Nullable RestrictionsSet local, boolean isDeviceOwner);
- /**
- * Returns the "base" user restrictions.
- *
- * Used by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading
- * from MNC.
- */
- public abstract Bundle getBaseUserRestrictions(int userId);
-
- /**
- * Called by {@link com.android.server.devicepolicy.DevicePolicyManagerService} for upgrading
- * from MNC.
- */
- public abstract void setBaseUserRestrictionsByDpmsForMigration(int userId,
- Bundle baseRestrictions);
-
/** Return a user restriction. */
public abstract boolean getUserRestriction(int userId, String key);
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index cb08c79..358e71a 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -5900,33 +5900,6 @@
}
@Override
- public Bundle getBaseUserRestrictions(@UserIdInt int userId) {
- synchronized (mRestrictionsLock) {
- return mBaseUserRestrictions.getRestrictions(userId);
- }
- }
-
- @Override
- public void setBaseUserRestrictionsByDpmsForMigration(
- @UserIdInt int userId, Bundle baseRestrictions) {
- synchronized (mRestrictionsLock) {
- if (mBaseUserRestrictions.updateRestrictions(userId,
- new Bundle(baseRestrictions))) {
- invalidateEffectiveUserRestrictionsLR(userId);
- }
- }
-
- final UserData userData = getUserDataNoChecks(userId);
- synchronized (mPackagesLock) {
- if (userData != null) {
- writeUserLP(userData);
- } else {
- Slog.w(LOG_TAG, "UserInfo not found for " + userId);
- }
- }
- }
-
- @Override
public boolean getUserRestriction(@UserIdInt int userId, String key) {
return getUserRestrictions(userId).getBoolean(key);
}
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 35dbb15..18bffeb 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -382,8 +382,6 @@
import com.android.server.utils.Slogf;
import com.android.server.wm.ActivityTaskManagerInternal;
-import com.google.android.collect.Sets;
-
import org.xmlpull.v1.XmlPullParserException;
import java.io.ByteArrayInputStream;
@@ -2002,7 +2000,6 @@
synchronized (getLockObject()) {
mOwners.load();
setDeviceOwnershipSystemPropertyLocked();
- findOwnerComponentIfNecessaryLocked();
}
}
@@ -2387,139 +2384,6 @@
}
}
- private void findOwnerComponentIfNecessaryLocked() {
- if (!mOwners.hasDeviceOwner()) {
- return;
- }
- final ComponentName doComponentName = mOwners.getDeviceOwnerComponent();
-
- if (!TextUtils.isEmpty(doComponentName.getClassName())) {
- return; // Already a full component name.
- }
-
- final ComponentName doComponent = findAdminComponentWithPackageLocked(
- doComponentName.getPackageName(),
- mOwners.getDeviceOwnerUserId());
- if (doComponent == null) {
- Slogf.e(LOG_TAG, "Device-owner isn't registered as device-admin");
- } else {
- mOwners.setDeviceOwnerWithRestrictionsMigrated(
- doComponent,
- mOwners.getDeviceOwnerName(),
- mOwners.getDeviceOwnerUserId(),
- !mOwners.getDeviceOwnerUserRestrictionsNeedsMigration());
- mOwners.writeDeviceOwner();
- if (VERBOSE_LOG) {
- Slogf.v(LOG_TAG, "Device owner component filled in");
- }
- }
- }
-
- /**
- * We didn't use to persist user restrictions for each owners but only persisted in user
- * manager.
- */
- private void migrateUserRestrictionsIfNecessaryLocked() {
- boolean migrated = false;
- // Migrate for the DO. Basically all restrictions should be considered to be set by DO,
- // except for the "system controlled" ones.
- if (mOwners.getDeviceOwnerUserRestrictionsNeedsMigration()) {
- if (VERBOSE_LOG) {
- Slogf.v(LOG_TAG, "Migrating DO user restrictions");
- }
- migrated = true;
-
- // Migrate user 0 restrictions to DO.
- final ActiveAdmin deviceOwnerAdmin = getDeviceOwnerAdminLocked();
-
- migrateUserRestrictionsForUser(UserHandle.SYSTEM, deviceOwnerAdmin,
- /* exceptionList =*/ null, /* isDeviceOwner =*/ true);
-
- // Push DO user restrictions to user manager.
- pushUserRestrictions(UserHandle.USER_SYSTEM);
-
- mOwners.setDeviceOwnerUserRestrictionsMigrated();
- }
-
- // Migrate for POs.
-
- // The following restrictions can be set on secondary users by the device owner, so we
- // assume they're not from the PO.
- final Set<String> secondaryUserExceptionList = Sets.newArraySet(
- UserManager.DISALLOW_OUTGOING_CALLS,
- UserManager.DISALLOW_SMS);
-
- for (UserInfo ui : mUserManager.getUsers()) {
- final int userId = ui.id;
- if (mOwners.getProfileOwnerUserRestrictionsNeedsMigration(userId)) {
- if (VERBOSE_LOG) {
- Slogf.v(LOG_TAG, "Migrating PO user restrictions for user %d", userId);
- }
- migrated = true;
-
- final ActiveAdmin profileOwnerAdmin = getProfileOwnerAdminLocked(userId);
-
- final Set<String> exceptionList =
- (userId == UserHandle.USER_SYSTEM) ? null : secondaryUserExceptionList;
-
- migrateUserRestrictionsForUser(ui.getUserHandle(), profileOwnerAdmin,
- exceptionList, /* isDeviceOwner =*/ false);
-
- // Note if a secondary user has no PO but has a DA that disables camera, we
- // don't get here and won't push the camera user restriction to UserManager
- // here. That's okay because we'll push user restrictions anyway when a user
- // starts. But we still do it because we want to let user manager persist
- // upon migration.
- pushUserRestrictions(userId);
-
- mOwners.setProfileOwnerUserRestrictionsMigrated(userId);
- }
- }
- if (VERBOSE_LOG && migrated) {
- Slogf.v(LOG_TAG, "User restrictions migrated.");
- }
- }
-
- private void migrateUserRestrictionsForUser(UserHandle user, ActiveAdmin admin,
- Set<String> exceptionList, boolean isDeviceOwner) {
- final Bundle origRestrictions = mUserManagerInternal.getBaseUserRestrictions(
- user.getIdentifier());
-
- final Bundle newBaseRestrictions = new Bundle();
- final Bundle newOwnerRestrictions = new Bundle();
-
- for (String key : origRestrictions.keySet()) {
- if (!origRestrictions.getBoolean(key)) {
- continue;
- }
- final boolean canOwnerChange = isDeviceOwner
- ? UserRestrictionsUtils.canDeviceOwnerChange(key)
- : UserRestrictionsUtils.canProfileOwnerChange(key, user.getIdentifier());
-
- if (!canOwnerChange || (exceptionList!= null && exceptionList.contains(key))) {
- newBaseRestrictions.putBoolean(key, true);
- } else {
- newOwnerRestrictions.putBoolean(key, true);
- }
- }
-
- if (VERBOSE_LOG) {
- Slogf.v(LOG_TAG, "origRestrictions=%s", origRestrictions);
- Slogf.v(LOG_TAG, "newBaseRestrictions=%s", newBaseRestrictions);
- Slogf.v(LOG_TAG, "newOwnerRestrictions=%s", newOwnerRestrictions);
- }
- mUserManagerInternal.setBaseUserRestrictionsByDpmsForMigration(user.getIdentifier(),
- newBaseRestrictions);
-
- if (admin != null) {
- admin.ensureUserRestrictions().clear();
- admin.ensureUserRestrictions().putAll(newOwnerRestrictions);
- } else {
- Slogf.w(LOG_TAG, "ActiveAdmin for DO/PO not found. user=" + user.getIdentifier());
- }
- saveSettingsLocked(user.getIdentifier());
- }
-
/**
* Fix left-over restrictions and auto-time policy during COMP -> COPE migration.
*
@@ -2555,27 +2419,6 @@
}
}
- private ComponentName findAdminComponentWithPackageLocked(String packageName, int userId) {
- final DevicePolicyData policy = getUserData(userId);
- final int n = policy.mAdminList.size();
- ComponentName found = null;
- int nFound = 0;
- for (int i = 0; i < n; i++) {
- final ActiveAdmin admin = policy.mAdminList.get(i);
- if (packageName.equals(admin.info.getPackageName())) {
- // Found!
- if (nFound == 0) {
- found = admin.info.getComponent();
- }
- nFound++;
- }
- }
- if (nFound > 1) {
- Slogf.w(LOG_TAG, "Multiple DA found; assume the first one is DO.");
- }
- return found;
- }
-
/**
* Set an alarm for an upcoming event - expiration warning, expiration, or post-expiration
* reminders. Clears alarm if no expirations are configured.
@@ -3197,7 +3040,6 @@
private void onLockSettingsReady() {
synchronized (getLockObject()) {
- migrateUserRestrictionsIfNecessaryLocked();
fixupAutoTimeRestrictionDuringOrganizationOwnedDeviceMigration();
}
getUserData(UserHandle.USER_SYSTEM);
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/Owners.java b/services/devicepolicy/java/com/android/server/devicepolicy/Owners.java
index 37da7b4..859183c 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/Owners.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/Owners.java
@@ -79,8 +79,6 @@
private static final boolean DEBUG = false; // DO NOT SUBMIT WITH TRUE
- private static final String DEVICE_OWNER_XML_LEGACY = "device_owner.xml";
-
// XML storing device owner info, system update policy and pending OTA update information.
private static final String DEVICE_OWNER_XML = "device_owner_2.xml";
@@ -89,7 +87,6 @@
private static final String TAG_ROOT = "root";
private static final String TAG_DEVICE_OWNER = "device-owner";
- private static final String TAG_DEVICE_INITIALIZER = "device-initializer";
private static final String TAG_SYSTEM_UPDATE_POLICY = "system-update-policy";
private static final String TAG_FREEZE_PERIOD_RECORD = "freeze-record";
private static final String TAG_PENDING_OTA_INFO = "pending-ota-info";
@@ -107,7 +104,6 @@
private static final String ATTR_REMOTE_BUGREPORT_URI = "remoteBugreportUri";
private static final String ATTR_REMOTE_BUGREPORT_HASH = "remoteBugreportHash";
private static final String ATTR_USERID = "userId";
- private static final String ATTR_USER_RESTRICTIONS_MIGRATED = "userRestrictionsMigrated";
private static final String ATTR_FREEZE_RECORD_START = "start";
private static final String ATTR_FREEZE_RECORD_END = "end";
// Legacy attribute, its presence would mean the profile owner associated with it is
@@ -180,35 +176,14 @@
*/
void load() {
synchronized (mLock) {
- // First, try to read from the legacy file.
- final File legacy = getLegacyConfigFile();
-
final List<UserInfo> users = mUserManager.getAliveUsers();
- if (readLegacyOwnerFileLocked(legacy)) {
- if (DEBUG) {
- Log.d(TAG, "Legacy config file found.");
- }
+ new DeviceOwnerReadWriter().readFromFileLocked();
- // Legacy file exists, write to new files and remove the legacy one.
- writeDeviceOwner();
- for (int userId : getProfileOwnerKeys()) {
- writeProfileOwner(userId);
- }
- if (DEBUG) {
- Log.d(TAG, "Deleting legacy config file");
- }
- if (!legacy.delete()) {
- Slog.e(TAG, "Failed to remove the legacy setting file");
- }
- } else {
- // No legacy file, read from the new format files.
- new DeviceOwnerReadWriter().readFromFileLocked();
-
- for (UserInfo ui : users) {
- new ProfileOwnerReadWriter(ui.id).readFromFileLocked();
- }
+ for (UserInfo ui : users) {
+ new ProfileOwnerReadWriter(ui.id).readFromFileLocked();
}
+
mUserManagerInternal.setDeviceManaged(hasDeviceOwner());
for (UserInfo ui : users) {
mUserManagerInternal.setUserManaged(ui.id, hasProfileOwner(ui.id));
@@ -338,23 +313,11 @@
return;
}
synchronized (mLock) {
- // For a newly set DO, there's no need for migration.
- setDeviceOwnerWithRestrictionsMigrated(admin, ownerName, userId,
- /* userRestrictionsMigrated =*/ true);
- }
- }
-
- // Note this should be only called during migration. Normally when DO is set,
- // userRestrictionsMigrated should always be true.
- void setDeviceOwnerWithRestrictionsMigrated(ComponentName admin, String ownerName, int userId,
- boolean userRestrictionsMigrated) {
- synchronized (mLock) {
// A device owner is allowed to access device identifiers. Even though this flag
// is not currently checked for device owner, it is set to true here so that it is
// semantically compatible with the meaning of this flag.
- mDeviceOwner = new OwnerInfo(ownerName, admin, userRestrictionsMigrated,
- /* remoteBugreportUri =*/ null, /* remoteBugreportHash =*/
- null, /* isOrganizationOwnedDevice =*/true);
+ mDeviceOwner = new OwnerInfo(ownerName, admin, /* remoteBugreportUri =*/ null,
+ /* remoteBugreportHash =*/ null, /* isOrganizationOwnedDevice =*/ true);
mDeviceOwnerUserId = userId;
mUserManagerInternal.setDeviceManaged(true);
@@ -385,8 +348,8 @@
synchronized (mLock) {
// For a newly set PO, there's no need for migration.
mProfileOwners.put(userId, new OwnerInfo(ownerName, admin,
- /* userRestrictionsMigrated =*/ true, /* remoteBugreportUri =*/ null,
- /* remoteBugreportHash =*/ null, /* isOrganizationOwnedDevice =*/ false));
+ /* remoteBugreportUri =*/ null, /* remoteBugreportHash =*/ null,
+ /* isOrganizationOwnedDevice =*/ false));
mUserManagerInternal.setUserManaged(userId, true);
notifyChangeLocked();
}
@@ -404,8 +367,7 @@
synchronized (mLock) {
final OwnerInfo ownerInfo = mProfileOwners.get(userId);
final OwnerInfo newOwnerInfo = new OwnerInfo(target.getPackageName(), target,
- ownerInfo.userRestrictionsMigrated, ownerInfo.remoteBugreportUri,
- ownerInfo.remoteBugreportHash, /* isOrganizationOwnedDevice =*/
+ ownerInfo.remoteBugreportUri, ownerInfo.remoteBugreportHash,
ownerInfo.isOrganizationOwnedDevice);
mProfileOwners.put(userId, newOwnerInfo);
notifyChangeLocked();
@@ -423,10 +385,8 @@
}
// 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);
+ mDeviceOwner = new OwnerInfo(null, target, mDeviceOwner.remoteBugreportUri,
+ mDeviceOwner.remoteBugreportHash, mDeviceOwner.isOrganizationOwnedDevice);
if (previousDeviceOwnerType != null) {
mDeviceOwnerTypes.put(mDeviceOwner.packageName, previousDeviceOwnerType);
}
@@ -570,35 +530,6 @@
}
}
- /**
- * @return true if user restrictions need to be migrated for DO.
- */
- boolean getDeviceOwnerUserRestrictionsNeedsMigration() {
- synchronized (mLock) {
- return mDeviceOwner != null && !mDeviceOwner.userRestrictionsMigrated;
- }
- }
-
- /**
- * @return true if user restrictions need to be migrated for PO.
- */
- boolean getProfileOwnerUserRestrictionsNeedsMigration(int userId) {
- synchronized (mLock) {
- OwnerInfo profileOwner = mProfileOwners.get(userId);
- return profileOwner != null && !profileOwner.userRestrictionsMigrated;
- }
- }
-
- /** Sets the user restrictions migrated flag, and also writes to the file. */
- void setDeviceOwnerUserRestrictionsMigrated() {
- synchronized (mLock) {
- if (mDeviceOwner != null) {
- mDeviceOwner.userRestrictionsMigrated = true;
- }
- writeDeviceOwner();
- }
- }
-
/** Sets the remote bugreport uri and hash, and also writes to the file. */
void setDeviceOwnerRemoteBugreportUriAndHash(String remoteBugreportUri,
String remoteBugreportHash) {
@@ -611,17 +542,6 @@
}
}
- /** Sets the user restrictions migrated flag, and also writes to the file. */
- void setProfileOwnerUserRestrictionsMigrated(int userId) {
- synchronized (mLock) {
- OwnerInfo profileOwner = mProfileOwners.get(userId);
- if (profileOwner != null) {
- profileOwner.userRestrictionsMigrated = true;
- }
- writeProfileOwner(userId);
- }
- }
-
/** Set whether the profile owner manages an organization-owned device, then write to file. */
void setProfileOwnerOfOrganizationOwnedDevice(int userId, boolean isOrganizationOwnedDevice) {
synchronized (mLock) {
@@ -696,72 +616,6 @@
}
}
- private boolean readLegacyOwnerFileLocked(File file) {
- if (!file.exists()) {
- // Already migrated or the device has no owners.
- return false;
- }
- try {
- InputStream input = new AtomicFile(file).openRead();
- TypedXmlPullParser parser = Xml.resolvePullParser(input);
- int type;
- while ((type = parser.next()) != TypedXmlPullParser.END_DOCUMENT) {
- if (type != TypedXmlPullParser.START_TAG) {
- continue;
- }
-
- String tag = parser.getName();
- if (tag.equals(TAG_DEVICE_OWNER)) {
- String name = parser.getAttributeValue(null, ATTR_NAME);
- String packageName = parser.getAttributeValue(null, ATTR_PACKAGE);
- mDeviceOwner = new OwnerInfo(name, packageName,
- /* userRestrictionsMigrated =*/ false, /* remoteBugreportUri =*/ null,
- /* remoteBugreportHash =*/ null, /* isOrganizationOwnedDevice =*/ true);
- mDeviceOwnerUserId = UserHandle.USER_SYSTEM;
- } else if (tag.equals(TAG_DEVICE_INITIALIZER)) {
- // Deprecated tag
- } else if (tag.equals(TAG_PROFILE_OWNER)) {
- String profileOwnerPackageName = parser.getAttributeValue(null, ATTR_PACKAGE);
- String profileOwnerName = parser.getAttributeValue(null, ATTR_NAME);
- String profileOwnerComponentStr =
- parser.getAttributeValue(null, ATTR_COMPONENT_NAME);
- int userId = parser.getAttributeInt(null, ATTR_USERID);
- OwnerInfo profileOwnerInfo = null;
- if (profileOwnerComponentStr != null) {
- ComponentName admin = ComponentName.unflattenFromString(
- profileOwnerComponentStr);
- if (admin != null) {
- profileOwnerInfo = new OwnerInfo(profileOwnerName, admin,
- /* userRestrictionsMigrated =*/ false, null,
- null, /* isOrganizationOwnedDevice =*/ false);
- } else {
- // This shouldn't happen but switch from package name -> component name
- // might have written bad device owner files. b/17652534
- Slog.e(TAG, "Error parsing device-owner file. Bad component name " +
- profileOwnerComponentStr);
- }
- }
- if (profileOwnerInfo == null) {
- profileOwnerInfo = new OwnerInfo(profileOwnerName, profileOwnerPackageName,
- /* userRestrictionsMigrated =*/ false,
- /* remoteBugreportUri =*/ null, /* remoteBugreportHash =*/
- null, /* isOrganizationOwnedDevice =*/ false);
- }
- mProfileOwners.put(userId, profileOwnerInfo);
- } else if (TAG_SYSTEM_UPDATE_POLICY.equals(tag)) {
- mSystemUpdatePolicy = SystemUpdatePolicy.restoreFromXml(parser);
- } else {
- throw new XmlPullParserException(
- "Unexpected tag in device owner file: " + tag);
- }
- }
- input.close();
- } catch (XmlPullParserException | IOException e) {
- Slog.e(TAG, "Error parsing device-owner file", e);
- }
- return true;
- }
-
void writeDeviceOwner() {
synchronized (mLock) {
if (DEBUG) {
@@ -1047,9 +901,6 @@
mDeviceOwnerUserId);
break;
}
- case TAG_DEVICE_INITIALIZER:
- // Deprecated tag
- break;
case TAG_SYSTEM_UPDATE_POLICY:
mSystemUpdatePolicy = SystemUpdatePolicy.restoreFromXml(parser);
break;
@@ -1087,7 +938,6 @@
default:
Slog.e(TAG, "Unexpected tag: " + tag);
return false;
-
}
return true;
}
@@ -1136,30 +986,16 @@
public final String name;
public final String packageName;
public final ComponentName admin;
- public boolean userRestrictionsMigrated;
public String remoteBugreportUri;
public String remoteBugreportHash;
public boolean isOrganizationOwnedDevice;
- public OwnerInfo(String name, String packageName, boolean userRestrictionsMigrated,
- String remoteBugreportUri, String remoteBugreportHash,
- boolean isOrganizationOwnedDevice) {
- this.name = name;
- this.packageName = packageName;
- this.admin = new ComponentName(packageName, "");
- this.userRestrictionsMigrated = userRestrictionsMigrated;
- this.remoteBugreportUri = remoteBugreportUri;
- this.remoteBugreportHash = remoteBugreportHash;
- this.isOrganizationOwnedDevice = isOrganizationOwnedDevice;
- }
-
- public OwnerInfo(String name, ComponentName admin, boolean userRestrictionsMigrated,
+ OwnerInfo(String name, ComponentName admin,
String remoteBugreportUri, String remoteBugreportHash,
boolean isOrganizationOwnedDevice) {
this.name = name;
this.admin = admin;
this.packageName = admin.getPackageName();
- this.userRestrictionsMigrated = userRestrictionsMigrated;
this.remoteBugreportUri = remoteBugreportUri;
this.remoteBugreportHash = remoteBugreportHash;
this.isOrganizationOwnedDevice = isOrganizationOwnedDevice;
@@ -1167,14 +1003,12 @@
public void writeToXml(TypedXmlSerializer out, String tag) throws IOException {
out.startTag(null, tag);
- out.attribute(null, ATTR_PACKAGE, packageName);
if (name != null) {
out.attribute(null, ATTR_NAME, name);
}
if (admin != null) {
out.attribute(null, ATTR_COMPONENT_NAME, admin.flattenToString());
}
- out.attributeBoolean(null, ATTR_USER_RESTRICTIONS_MIGRATED, userRestrictionsMigrated);
if (remoteBugreportUri != null) {
out.attribute(null, ATTR_REMOTE_BUGREPORT_URI, remoteBugreportUri);
}
@@ -1189,14 +1023,9 @@
}
public static OwnerInfo readFromXml(TypedXmlPullParser parser) {
- final String packageName = parser.getAttributeValue(null, ATTR_PACKAGE);
final String name = parser.getAttributeValue(null, ATTR_NAME);
final String componentName =
parser.getAttributeValue(null, ATTR_COMPONENT_NAME);
- final String userRestrictionsMigratedStr =
- parser.getAttributeValue(null, ATTR_USER_RESTRICTIONS_MIGRATED);
- final boolean userRestrictionsMigrated =
- ("true".equals(userRestrictionsMigratedStr));
final String remoteBugreportUri = parser.getAttributeValue(null,
ATTR_REMOTE_BUGREPORT_URI);
final String remoteBugreportHash = parser.getAttributeValue(null,
@@ -1210,23 +1039,18 @@
final boolean isOrgOwnedDevice =
("true".equals(isOrgOwnedDeviceStr)) | canAccessDeviceIds;
- // Has component name? If so, return [name, component]
- if (componentName != null) {
- final ComponentName admin = ComponentName.unflattenFromString(componentName);
- if (admin != null) {
- return new OwnerInfo(name, admin, userRestrictionsMigrated,
- remoteBugreportUri, remoteBugreportHash, isOrgOwnedDevice);
- } else {
- // This shouldn't happen but switch from package name -> component name
- // might have written bad device owner files. b/17652534
- Slog.e(TAG, "Error parsing owner file. Bad component name " +
- componentName);
- }
+ if (componentName == null) {
+ Slog.e(TAG, "Owner component not found");
+ return null;
+ }
+ final ComponentName admin = ComponentName.unflattenFromString(componentName);
+ if (admin == null) {
+ Slog.e(TAG, "Owner component not parsable: " + componentName);
+ return null;
}
- // Else, build with [name, package]
- return new OwnerInfo(name, packageName, userRestrictionsMigrated, remoteBugreportUri,
- remoteBugreportHash, isOrgOwnedDevice);
+ return new OwnerInfo(
+ name, admin, remoteBugreportUri, remoteBugreportHash, isOrgOwnedDevice);
}
public void dump(IndentingPrintWriter pw) {
@@ -1284,11 +1108,6 @@
}
@VisibleForTesting
- File getLegacyConfigFile() {
- return new File(mInjector.environmentGetDataSystemDirectory(), DEVICE_OWNER_XML_LEGACY);
- }
-
- @VisibleForTesting
File getDeviceOwnerFile() {
return new File(mInjector.environmentGetDataSystemDirectory(), DEVICE_OWNER_XML);
}
diff --git a/services/tests/servicestests/assets/OwnersTest/device_owner_1.xml b/services/tests/servicestests/assets/OwnersTest/device_owner_1.xml
new file mode 100644
index 0000000..d150b29
--- /dev/null
+++ b/services/tests/servicestests/assets/OwnersTest/device_owner_1.xml
@@ -0,0 +1,6 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
+<root>
+ <device-owner package="com.afwsamples.testdpc" name="" component="com.afwsamples.testdpc/com.afwsamples.testdpc.DeviceAdminReceiver" isPoOrganizationOwnedDevice="true" />
+ <device-owner-context userId="0" />
+ <system-update-policy policy_type="2" install_window_start="0" install_window_end="540" />
+</root>
\ No newline at end of file
diff --git a/services/tests/servicestests/assets/OwnersTest/profile_owner_1.xml b/services/tests/servicestests/assets/OwnersTest/profile_owner_1.xml
new file mode 100644
index 0000000..1f78b71
--- /dev/null
+++ b/services/tests/servicestests/assets/OwnersTest/profile_owner_1.xml
@@ -0,0 +1,4 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
+<root>
+ <profile-owner package="com.afwsamples.testdpc" name="com.afwsamples.testdpc" component="com.afwsamples.testdpc/com.afwsamples.testdpc.DeviceAdminReceiver" />
+</root>
\ No newline at end of file
diff --git a/services/tests/servicestests/assets/OwnersTest/test01/input.xml b/services/tests/servicestests/assets/OwnersTest/test01/input.xml
deleted file mode 100644
index db3e974..0000000
--- a/services/tests/servicestests/assets/OwnersTest/test01/input.xml
+++ /dev/null
@@ -1 +0,0 @@
-<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
diff --git a/services/tests/servicestests/assets/OwnersTest/test02/input.xml b/services/tests/servicestests/assets/OwnersTest/test02/input.xml
deleted file mode 100644
index 321842b..0000000
--- a/services/tests/servicestests/assets/OwnersTest/test02/input.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
-<device-owner package="com.google.android.testdpc" />
diff --git a/services/tests/servicestests/assets/OwnersTest/test03/input.xml b/services/tests/servicestests/assets/OwnersTest/test03/input.xml
deleted file mode 100644
index 1bbfdadf..0000000
--- a/services/tests/servicestests/assets/OwnersTest/test03/input.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
-<profile-owner package="com.google.android.testdpc0" name="0" userId="10" component="com.google.android.testdpc/com.google.android.testdpc.DeviceAdminReceiver0" />
-<profile-owner package="com.google.android.testdpc1" name="1" userId="11" />
diff --git a/services/tests/servicestests/assets/OwnersTest/test04/input.xml b/services/tests/servicestests/assets/OwnersTest/test04/input.xml
deleted file mode 100644
index 8be51d9..0000000
--- a/services/tests/servicestests/assets/OwnersTest/test04/input.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
-<device-owner package="com.google.android.testdpc" />
-<profile-owner package="com.google.android.testdpc0" name="0" userId="10" component="com.google.android.testdpc/com.google.android.testdpc.DeviceAdminReceiver0" />
-<profile-owner package="com.google.android.testdpc1" name="1" userId="11" />
-<device-initializer package="com.google.android.testdpcx" name="di" component="com.google.android.testdpcx/receiver" />
-<system-update-policy policy_type="5" />
diff --git a/services/tests/servicestests/assets/OwnersTest/test05/input.xml b/services/tests/servicestests/assets/OwnersTest/test05/input.xml
deleted file mode 100644
index dbcb858..0000000
--- a/services/tests/servicestests/assets/OwnersTest/test05/input.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
-<device-initializer package="com.google.android.testdpcx" name="di" component="com.google.android.testdpcx/receiver" />
-
diff --git a/services/tests/servicestests/assets/OwnersTest/test06/input.xml b/services/tests/servicestests/assets/OwnersTest/test06/input.xml
deleted file mode 100644
index 794622b..0000000
--- a/services/tests/servicestests/assets/OwnersTest/test06/input.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
-<system-update-policy policy_type="5" />
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java
index 9ba7a9a..8bb619f 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerServiceMigrationTest.java
@@ -27,7 +27,6 @@
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -37,7 +36,6 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
-import android.os.Bundle;
import android.os.IpcDataCache;
import android.os.UserHandle;
import android.os.UserManager;
@@ -55,8 +53,6 @@
import org.junit.runner.RunWith;
import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
import java.util.Set;
@Presubmit
@@ -87,226 +83,9 @@
.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,
- UserManager.USER_TYPE_PROFILE_MANAGED);
- getServices().addUser(12, 0, USER_TYPE_EMPTY);
-
- setUpPackageManagerForAdmin(admin1, DpmMockContext.CALLER_SYSTEM_USER_UID);
- setUpPackageManagerForAdmin(admin2, UserHandle.getUid(10, 123));
- setUpPackageManagerForAdmin(admin3, UserHandle.getUid(11, 456));
-
- // Create the legacy owners & policies file.
- DpmTestUtils.writeToFile(
- (new File(getServices().dataDir, "device_owner.xml")).getAbsoluteFile(),
- DpmTestUtils.readAsset(mRealTestContext,
- "DevicePolicyManagerServiceMigrationTest/legacy_device_owner.xml"));
-
- DpmTestUtils.writeToFile(
- (new File(getServices().systemUserDataDir, "device_policies.xml")).getAbsoluteFile(),
- DpmTestUtils.readAsset(mRealTestContext,
- "DevicePolicyManagerServiceMigrationTest/legacy_device_policies.xml"));
-
- DpmTestUtils.writeToFile(
- (new File(user10dir, "device_policies.xml")).getAbsoluteFile(),
- DpmTestUtils.readAsset(mRealTestContext,
- "DevicePolicyManagerServiceMigrationTest/legacy_device_policies_10.xml"));
- DpmTestUtils.writeToFile(
- (new File(user11dir, "device_policies.xml")).getAbsoluteFile(),
- DpmTestUtils.readAsset(mRealTestContext,
- "DevicePolicyManagerServiceMigrationTest/legacy_device_policies_11.xml"));
-
- // Set up UserManager
- when(getServices().userManagerInternal.getBaseUserRestrictions(
- eq(USER_SYSTEM))).thenReturn(DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_ADD_USER,
- UserManager.DISALLOW_RECORD_AUDIO));
-
- when(getServices().userManagerInternal.getBaseUserRestrictions(
- eq(10))).thenReturn(DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_REMOVE_USER,
- UserManager.DISALLOW_ADD_USER,
- UserManager.DISALLOW_SMS,
- UserManager.DISALLOW_OUTGOING_CALLS,
- UserManager.DISALLOW_WALLPAPER,
- UserManager.DISALLOW_RECORD_AUDIO));
-
- when(getServices().userManagerInternal.getBaseUserRestrictions(
- eq(11))).thenReturn(DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_REMOVE_USER,
- UserManager.DISALLOW_ADD_USER,
- UserManager.DISALLOW_SMS,
- UserManager.DISALLOW_OUTGOING_CALLS,
- UserManager.DISALLOW_WALLPAPER,
- UserManager.DISALLOW_RECORD_AUDIO));
-
- final Map<Integer, Bundle> newBaseRestrictions = new HashMap<>();
-
- doAnswer(invocation -> {
- Integer userId = (Integer) invocation.getArguments()[0];
- Bundle bundle = (Bundle) invocation.getArguments()[1];
-
- newBaseRestrictions.put(userId, bundle);
-
- return null;
- }).when(getServices().userManagerInternal).setBaseUserRestrictionsByDpmsForMigration(
- anyInt(), any(Bundle.class));
-
- // Initialize DPM/DPMS and let it migrate the persisted information.
- // (Need clearCallingIdentity() to pass permission checks.)
-
- final DevicePolicyManagerServiceTestable dpms;
-
- final long ident = mContext.binder.clearCallingIdentity();
- try {
- dpms = new DevicePolicyManagerServiceTestable(getServices(), mContext);
-
- dpms.systemReady(SystemService.PHASE_LOCK_SETTINGS_READY);
- dpms.systemReady(SystemService.PHASE_BOOT_COMPLETED);
- } finally {
- mContext.binder.restoreCallingIdentity(ident);
- }
-
- 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.
- 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(
- DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_RECORD_AUDIO
- ),
- newBaseRestrictions.get(USER_SYSTEM));
-
- DpmTestUtils.assertRestrictions(
- DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_ADD_USER,
- UserManager.DISALLOW_SMS,
- UserManager.DISALLOW_OUTGOING_CALLS,
- UserManager.DISALLOW_RECORD_AUDIO,
- UserManager.DISALLOW_WALLPAPER
- ),
- newBaseRestrictions.get(10));
-
- DpmTestUtils.assertRestrictions(
- DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_ADD_USER,
- UserManager.DISALLOW_SMS,
- UserManager.DISALLOW_OUTGOING_CALLS,
- UserManager.DISALLOW_WALLPAPER,
- UserManager.DISALLOW_RECORD_AUDIO
- ),
- newBaseRestrictions.get(11));
-
- // Check the new owner restrictions.
- DpmTestUtils.assertRestrictions(
- DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_ADD_USER
- ),
- dpms.getDeviceOwnerAdminLocked().ensureUserRestrictions());
-
- DpmTestUtils.assertRestrictions(
- DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_REMOVE_USER
- ),
- dpms.getProfileOwnerAdminLocked(10).ensureUserRestrictions());
-
- DpmTestUtils.assertRestrictions(
- DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_REMOVE_USER
- ),
- dpms.getProfileOwnerAdminLocked(11).ensureUserRestrictions());
- }
-
- @Test
- public void testMigration2_profileOwnerOnUser0() throws Exception {
- setUpPackageManagerForAdmin(admin2, DpmMockContext.CALLER_SYSTEM_USER_UID);
-
- // Create the legacy owners & policies file.
- DpmTestUtils.writeToFile(
- (new File(getServices().dataDir, "device_owner.xml")).getAbsoluteFile(),
- DpmTestUtils.readAsset(mRealTestContext,
- "DevicePolicyManagerServiceMigrationTest2/legacy_device_owner.xml"));
-
- DpmTestUtils.writeToFile(
- (new File(getServices().systemUserDataDir, "device_policies.xml")).getAbsoluteFile(),
- DpmTestUtils.readAsset(mRealTestContext,
- "DevicePolicyManagerServiceMigrationTest2/legacy_device_policies.xml"));
-
- // Set up UserManager
- when(getServices().userManagerInternal.getBaseUserRestrictions(
- eq(USER_SYSTEM))).thenReturn(DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_ADD_USER,
- UserManager.DISALLOW_RECORD_AUDIO,
- UserManager.DISALLOW_SMS,
- UserManager.DISALLOW_OUTGOING_CALLS));
-
- final Map<Integer, Bundle> newBaseRestrictions = new HashMap<>();
-
- doAnswer(invocation -> {
- Integer userId = (Integer) invocation.getArguments()[0];
- Bundle bundle = (Bundle) invocation.getArguments()[1];
-
- newBaseRestrictions.put(userId, bundle);
-
- return null;
- }).when(getServices().userManagerInternal).setBaseUserRestrictionsByDpmsForMigration(
- anyInt(), any(Bundle.class));
-
- // Initialize DPM/DPMS and let it migrate the persisted information.
- // (Need clearCallingIdentity() to pass permission checks.)
-
- final DevicePolicyManagerServiceTestable dpms;
-
- final long ident = mContext.binder.clearCallingIdentity();
- try {
- dpms = new DevicePolicyManagerServiceTestable(getServices(), mContext);
-
- dpms.systemReady(SystemService.PHASE_LOCK_SETTINGS_READY);
- dpms.systemReady(SystemService.PHASE_BOOT_COMPLETED);
- } finally {
- mContext.binder.restoreCallingIdentity(ident);
- }
- assertThat(dpms.mOwners.hasDeviceOwner()).isFalse();
- assertThat(dpms.mOwners.hasProfileOwner(USER_SYSTEM)).isTrue();
-
- // Now all information should be migrated.
- assertThat(dpms.mOwners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
- assertThat(dpms.mOwners.getProfileOwnerUserRestrictionsNeedsMigration(USER_SYSTEM))
- .isFalse();
-
- // Check the new base restrictions.
- DpmTestUtils.assertRestrictions(
- DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_RECORD_AUDIO
- ),
- newBaseRestrictions.get(USER_SYSTEM));
-
- // Check the new owner restrictions.
- DpmTestUtils.assertRestrictions(
- DpmTestUtils.newRestrictions(
- UserManager.DISALLOW_ADD_USER,
- UserManager.DISALLOW_SMS,
- UserManager.DISALLOW_OUTGOING_CALLS
- ),
- dpms.getProfileOwnerAdminLocked(USER_SYSTEM).ensureUserRestrictions());
- }
-
// Test setting default restrictions for managed profile.
@Test
- public void testMigration3_managedProfileOwner() throws Exception {
+ public void testMigration_managedProfileOwner() throws Exception {
// Create a managed profile user.
final File user10dir = getServices().addUser(10, 0,
UserManager.USER_TYPE_PROFILE_MANAGED);
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
index 7b11876d0..45d101a 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
@@ -1665,39 +1665,6 @@
assertThat(deviceOwner.getUid()).isEqualTo(DpmMockContext.CALLER_SYSTEM_USER_UID);
}
- /**
- * This essentially tests
- * {@code DevicePolicyManagerService.findOwnerComponentIfNecessaryLocked()}. (which is
- * private.)
- *
- * We didn't use to persist the DO component class name, but now we do, and the above method
- * finds the right component from a package name upon migration.
- */
- @Test
- public void testDeviceOwnerMigration() throws Exception {
- checkDeviceOwnerWithMultipleDeviceAdmins();
-
- // Overwrite the device owner setting and clears the class name.
- dpms.mOwners.setDeviceOwner(
- new ComponentName(admin2.getPackageName(), ""),
- "owner-name", CALLER_USER_HANDLE);
- dpms.mOwners.writeDeviceOwner();
-
- // Make sure the DO component name doesn't have a class name.
- assertThat(dpms.getDeviceOwnerComponent(/* callingUserOnly= */ false).getClassName())
- .isEmpty();
-
- // Then create a new DPMS to have it load the settings from files.
- when(getServices().userManager.getUserRestrictions(any(UserHandle.class)))
- .thenReturn(new Bundle());
- initializeDpms();
-
- // Now the DO component name is a full name.
- // *BUT* because both admin1 and admin2 belong to the same package, we think admin1 is the
- // DO.
- assertThat(dpms.getDeviceOwnerComponent(/* callingUserOnly =*/ false)).isEqualTo(admin1);
- }
-
@Test
public void testSetGetApplicationRestriction() {
setAsProfileOwner(admin1);
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/OwnersTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/OwnersTest.java
index d1706f8..37ba8a4 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/OwnersTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/OwnersTest.java
@@ -18,29 +18,22 @@
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.SystemUpdatePolicy.TYPE_INSTALL_WINDOWED;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.verify;
-
import android.content.ComponentName;
import android.os.IpcDataCache;
-import android.os.UserHandle;
import android.test.suitebuilder.annotation.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.server.devicepolicy.DevicePolicyManagerServiceTestable.OwnersTestable;
-import com.google.android.collect.Lists;
-
import org.junit.Before;
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.
*
@@ -52,8 +45,7 @@
@RunWith(AndroidJUnit4.class)
public class OwnersTest extends DpmTestBase {
- private static final List<String> DEVICE_OWNER_PROTECTED_PACKAGES =
- Lists.newArrayList("package_1", "package_2");
+ private static final String TESTDPC_PACKAGE = "com.afwsamples.testdpc";
@Before
public void setUp() throws Exception {
@@ -63,572 +55,66 @@
}
@Test
- public void testUpgrade01() throws Exception {
- getServices().addUsers(10, 11, 20, 21);
-
- // First, migrate.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
-
- DpmTestUtils.writeToFile(owners.getLegacyConfigFile(),
- DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/test01/input.xml"));
-
- owners.load();
-
- // The legacy file should be removed.
- assertThat(owners.getLegacyConfigFile().exists()).isFalse();
-
- // File was empty, so no new files should be created.
- assertThat(owners.getDeviceOwnerFile().exists()).isFalse();
-
- assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(21).exists()).isFalse();
-
- assertThat(owners.hasDeviceOwner()).isFalse();
- assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
- assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
- DEVICE_OWNER_TYPE_DEFAULT);
- assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
- assertThat(owners.getSystemUpdatePolicy()).isNull();
- assertThat(owners.getProfileOwnerKeys()).isEmpty();
-
- assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
- assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isFalse();
- assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isFalse();
- assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
- assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
-
- owners.setDeviceOwnerType(owners.getDeviceOwnerPackageName(),
- DEVICE_OWNER_TYPE_FINANCED, /* isAdminTestOnly= */ false);
- // 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.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
- owners.load();
-
- assertThat(owners.hasDeviceOwner()).isFalse();
- assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
- assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
- DEVICE_OWNER_TYPE_DEFAULT);
- assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
- assertThat(owners.getSystemUpdatePolicy()).isNull();
- assertThat(owners.getProfileOwnerKeys()).isEmpty();
-
- 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);
-
- // First, migrate.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
-
- DpmTestUtils.writeToFile(owners.getLegacyConfigFile(),
- DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/test02/input.xml"));
-
- owners.load();
-
- // The legacy file should be removed.
- assertThat(owners.getLegacyConfigFile().exists()).isFalse();
-
- assertThat(owners.getDeviceOwnerFile().exists()).isTrue(); // TODO Check content
-
- assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(21).exists()).isFalse();
-
- assertThat(owners.hasDeviceOwner()).isTrue();
- 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.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
-
- assertThat(owners.getSystemUpdatePolicy()).isNull();
- assertThat(owners.getProfileOwnerKeys()).isEmpty();
-
- 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.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
- owners.load();
-
- assertThat(owners.hasDeviceOwner()).isTrue();
- 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.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
-
- assertThat(owners.getSystemUpdatePolicy()).isNull();
- assertThat(owners.getProfileOwnerKeys()).isEmpty();
-
- 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);
-
- // First, migrate.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
-
- DpmTestUtils.writeToFile(owners.getLegacyConfigFile(),
- DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/test03/input.xml"));
-
- owners.load();
-
- // The legacy file should be removed.
- assertThat(owners.getLegacyConfigFile().exists()).isFalse();
-
- assertThat(owners.getDeviceOwnerFile().exists()).isFalse();
-
- assertThat(owners.getProfileOwnerFile(10).exists()).isTrue();
- assertThat(owners.getProfileOwnerFile(11).exists()).isTrue();
- assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(21).exists()).isFalse();
-
- 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.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
-
- 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");
-
- 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");
-
- 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.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
- owners.load();
-
- 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.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
-
- 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");
-
- 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");
-
- assertThat(owners.getDeviceOwnerUserRestrictionsNeedsMigration()).isFalse();
- assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(10)).isTrue();
- assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(11)).isTrue();
- assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(20)).isFalse();
- assertThat(owners.getProfileOwnerUserRestrictionsNeedsMigration(21)).isFalse();
- }
- }
-
- /**
- * Note this also tests {@link Owners#setDeviceOwnerUserRestrictionsMigrated()}
- * and {@link Owners#setProfileOwnerUserRestrictionsMigrated(int)}.
- */
- @Test
- public void testUpgrade04() throws Exception {
- getServices().addUsers(10, 11, 20, 21);
-
- // First, migrate.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
-
- DpmTestUtils.writeToFile(owners.getLegacyConfigFile(),
- DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/test04/input.xml"));
-
- owners.load();
-
- // The legacy file should be removed.
- assertThat(owners.getLegacyConfigFile().exists()).isFalse();
-
- assertThat(owners.getDeviceOwnerFile().exists()).isTrue();
-
- assertThat(owners.getProfileOwnerFile(10).exists()).isTrue();
- assertThat(owners.getProfileOwnerFile(11).exists()).isTrue();
- assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(21).exists()).isFalse();
-
- assertThat(owners.hasDeviceOwner()).isTrue();
- 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.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
-
- assertThat(owners.getSystemUpdatePolicy()).isNotNull();
- assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(5);
-
- 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");
-
- 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");
-
- 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.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
- owners.load();
-
- assertThat(owners.hasDeviceOwner()).isTrue();
- 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.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
-
- assertThat(owners.getSystemUpdatePolicy()).isNotNull();
- assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(5);
-
- 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");
-
- 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");
-
- 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();
-
- owners.setDeviceOwnerType(owners.getDeviceOwnerPackageName(),
- DEVICE_OWNER_TYPE_FINANCED, /* isAdminTestOnly= */ false);
- assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
- DEVICE_OWNER_TYPE_FINANCED);
-
- owners.setDeviceOwnerProtectedPackages(
- owners.getDeviceOwnerPackageName(), DEVICE_OWNER_PROTECTED_PACKAGES);
- assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEqualTo(DEVICE_OWNER_PROTECTED_PACKAGES);
- verify(getServices().packageManagerInternal)
- .setDeviceOwnerProtectedPackages(
- owners.getDeviceOwnerPackageName(), DEVICE_OWNER_PROTECTED_PACKAGES);
- }
-
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
- owners.load();
-
- assertThat(owners.hasDeviceOwner()).isTrue();
- assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
- DEVICE_OWNER_TYPE_FINANCED);
- assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEqualTo(DEVICE_OWNER_PROTECTED_PACKAGES);
-
- 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);
-
- owners.setDeviceOwnerType(owners.getDeviceOwnerPackageName(),
- DEVICE_OWNER_TYPE_DEFAULT, /* isAdminTestOnly= */ false);
- // The previous device owner type should persist.
- assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
- DEVICE_OWNER_TYPE_FINANCED);
-
- owners.setDeviceOwnerProtectedPackages(
- owners.getDeviceOwnerPackageName(), new ArrayList<>());
- assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
- verify(getServices().packageManagerInternal)
- .setDeviceOwnerProtectedPackages(
- owners.getDeviceOwnerPackageName(), new ArrayList<>());
- }
-
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
- owners.load();
-
- assertThat(owners.hasDeviceOwner()).isTrue();
- assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
- DEVICE_OWNER_TYPE_FINANCED);
- assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
-
- 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);
-
- // First, migrate.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
-
- DpmTestUtils.writeToFile(owners.getLegacyConfigFile(),
- DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/test05/input.xml"));
-
- owners.load();
-
- // The legacy file should be removed.
- assertThat(owners.getLegacyConfigFile().exists()).isFalse();
-
- // Note device initializer is no longer supported. No need to write the DO file.
- assertThat(owners.getDeviceOwnerFile().exists()).isFalse();
-
- assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
-
- assertThat(owners.hasDeviceOwner()).isFalse();
- assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
- assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
- DEVICE_OWNER_TYPE_DEFAULT);
- assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
-
-
- assertThat(owners.getSystemUpdatePolicy()).isNull();
- assertThat(owners.getProfileOwnerKeys()).isEmpty();
-
- 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.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
- owners.load();
-
- assertThat(owners.hasDeviceOwner()).isFalse();
- assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
- assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
- DEVICE_OWNER_TYPE_DEFAULT);
- assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
-
-
- assertThat(owners.getSystemUpdatePolicy()).isNull();
- assertThat(owners.getProfileOwnerKeys()).isEmpty();
-
- 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);
-
- // First, migrate.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
-
- DpmTestUtils.writeToFile(owners.getLegacyConfigFile(),
- DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/test06/input.xml"));
-
- owners.load();
-
- // The legacy file should be removed.
- assertThat(owners.getLegacyConfigFile().exists()).isFalse();
-
- assertThat(owners.getDeviceOwnerFile().exists()).isTrue();
-
- assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(20).exists()).isFalse();
-
- assertThat(owners.hasDeviceOwner()).isFalse();
- assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
- assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
- DEVICE_OWNER_TYPE_DEFAULT);
- assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
- assertThat(owners.getProfileOwnerKeys()).isEmpty();
-
- assertThat(owners.getSystemUpdatePolicy()).isNotNull();
- assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(5);
-
- 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.
- {
- final OwnersTestable owners = new OwnersTestable(getServices());
- owners.load();
-
- assertThat(owners.hasDeviceOwner()).isFalse();
- assertThat(owners.getDeviceOwnerUserId()).isEqualTo(UserHandle.USER_NULL);
- assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
- DEVICE_OWNER_TYPE_DEFAULT);
- assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
- assertThat(owners.getProfileOwnerKeys()).isEmpty();
-
- assertThat(owners.getSystemUpdatePolicy()).isNotNull();
- assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(5);
-
- 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);
+ public void loadProfileOwner() throws Exception {
+ getServices().addUsers(10);
final OwnersTestable owners = new OwnersTestable(getServices());
- // First, migrate to create new-style config files.
- DpmTestUtils.writeToFile(owners.getLegacyConfigFile(),
- DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/test04/input.xml"));
+ DpmTestUtils.writeToFile(owners.getProfileOwnerFile(10),
+ DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/profile_owner_1.xml"));
owners.load();
- assertThat(owners.getLegacyConfigFile().exists()).isFalse();
+ assertThat(owners.hasDeviceOwner()).isFalse();
+ assertThat(owners.getSystemUpdatePolicy()).isNull();
- assertThat(owners.getDeviceOwnerFile().exists()).isTrue();
- assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
- DEVICE_OWNER_TYPE_DEFAULT);
- assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
- .isEmpty();
- assertThat(owners.getProfileOwnerFile(10).exists()).isTrue();
- assertThat(owners.getProfileOwnerFile(11).exists()).isTrue();
+ assertThat(owners.getProfileOwnerKeys()).hasSize(1);
+ assertThat(owners.getProfileOwnerComponent(10))
+ .isEqualTo(new ComponentName(TESTDPC_PACKAGE,
+ "com.afwsamples.testdpc.DeviceAdminReceiver"));
+ }
- String previousDeviceOwnerPackageName = owners.getDeviceOwnerPackageName();
- owners.setDeviceOwnerType(previousDeviceOwnerPackageName, DEVICE_OWNER_TYPE_FINANCED,
- /* isAdminTestOnly= */ false);
- assertThat(owners.getDeviceOwnerType(previousDeviceOwnerPackageName)).isEqualTo(
- DEVICE_OWNER_TYPE_FINANCED);
- owners.setDeviceOwnerProtectedPackages(
- previousDeviceOwnerPackageName, DEVICE_OWNER_PROTECTED_PACKAGES);
- assertThat(owners.getDeviceOwnerProtectedPackages(previousDeviceOwnerPackageName))
- .isEqualTo(DEVICE_OWNER_PROTECTED_PACKAGES);
- verify(getServices().packageManagerInternal)
- .setDeviceOwnerProtectedPackages(
- owners.getDeviceOwnerPackageName(), DEVICE_OWNER_PROTECTED_PACKAGES);
+ @Test
+ public void loadDeviceOwner() throws Exception {
+ final OwnersTestable owners = new OwnersTestable(getServices());
- // Then clear all information and save.
- owners.clearDeviceOwner();
- owners.clearSystemUpdatePolicy();
- owners.removeProfileOwner(10);
- owners.removeProfileOwner(11);
+ DpmTestUtils.writeToFile(owners.getDeviceOwnerFile(),
+ DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/device_owner_1.xml"));
- owners.writeDeviceOwner();
- owners.writeProfileOwner(10);
- owners.writeProfileOwner(11);
- owners.writeProfileOwner(20);
- owners.writeProfileOwner(21);
+ owners.load();
- // Now all files should be removed.
- assertThat(owners.getDeviceOwnerFile().exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
- assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
+ assertThat(owners.hasDeviceOwner()).isTrue();
- assertThat(owners.getDeviceOwnerType(previousDeviceOwnerPackageName)).isEqualTo(
- DEVICE_OWNER_TYPE_DEFAULT);
- assertThat(owners.getDeviceOwnerProtectedPackages(previousDeviceOwnerPackageName))
- .isEmpty();
- verify(getServices().packageManagerInternal)
- .setDeviceOwnerProtectedPackages(
- previousDeviceOwnerPackageName, new ArrayList<>());
+ assertThat(owners.getProfileOwnerKeys()).hasSize(0);
+ assertThat(owners.getDeviceOwnerComponent())
+ .isEqualTo(new ComponentName(TESTDPC_PACKAGE,
+ "com.afwsamples.testdpc.DeviceAdminReceiver"));
+
+ assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(TYPE_INSTALL_WINDOWED);
+ }
+
+ @Test
+ public void testDeviceOwnerType() throws Exception {
+ final OwnersTestable owners = new OwnersTestable(getServices());
+
+ DpmTestUtils.writeToFile(owners.getDeviceOwnerFile(),
+ DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/device_owner_1.xml"));
+
+ owners.load();
+
+ assertThat(owners.getDeviceOwnerType(TESTDPC_PACKAGE))
+ .isEqualTo(DEVICE_OWNER_TYPE_DEFAULT);
+
+ // Should be able to set DO type to "financed".
+ owners.setDeviceOwnerType(
+ TESTDPC_PACKAGE, DEVICE_OWNER_TYPE_FINANCED, /* isAdminTestOnly= */ false);
+ assertThat(owners.getDeviceOwnerType(TESTDPC_PACKAGE))
+ .isEqualTo(DEVICE_OWNER_TYPE_FINANCED);
+
+ // Once set, DO type cannot be changed.
+ owners.setDeviceOwnerType(
+ TESTDPC_PACKAGE, DEVICE_OWNER_TYPE_DEFAULT, /* isAdminTestOnly= */ false);
+ assertThat(owners.getDeviceOwnerType(TESTDPC_PACKAGE))
+ .isEqualTo(DEVICE_OWNER_TYPE_FINANCED);
}
}