Merge "Remove fossilized upgrade code." into tm-dev am: c291627ea9
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17591526 Change-Id: I8d1e6496d17c510803ddda6e790947cd0d96ea00 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -92,21 +92,6 @@ public abstract class UserManagerInternal {
|
|||||||
public abstract void setDevicePolicyUserRestrictions(int originatingUserId,
|
public abstract void setDevicePolicyUserRestrictions(int originatingUserId,
|
||||||
@Nullable Bundle global, @Nullable RestrictionsSet local, boolean isDeviceOwner);
|
@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. */
|
/** Return a user restriction. */
|
||||||
public abstract boolean getUserRestriction(int userId, String key);
|
public abstract boolean getUserRestriction(int userId, String key);
|
||||||
|
|
||||||
|
|||||||
@@ -5899,33 +5899,6 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
global, local, isDeviceOwner);
|
global, local, isDeviceOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
public boolean getUserRestriction(@UserIdInt int userId, String key) {
|
public boolean getUserRestriction(@UserIdInt int userId, String key) {
|
||||||
return getUserRestrictions(userId).getBoolean(key);
|
return getUserRestrictions(userId).getBoolean(key);
|
||||||
|
|||||||
@@ -382,8 +382,6 @@ import com.android.server.uri.UriGrantsManagerInternal;
|
|||||||
import com.android.server.utils.Slogf;
|
import com.android.server.utils.Slogf;
|
||||||
import com.android.server.wm.ActivityTaskManagerInternal;
|
import com.android.server.wm.ActivityTaskManagerInternal;
|
||||||
|
|
||||||
import com.google.android.collect.Sets;
|
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@@ -2002,7 +2000,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
|||||||
synchronized (getLockObject()) {
|
synchronized (getLockObject()) {
|
||||||
mOwners.load();
|
mOwners.load();
|
||||||
setDeviceOwnershipSystemPropertyLocked();
|
setDeviceOwnershipSystemPropertyLocked();
|
||||||
findOwnerComponentIfNecessaryLocked();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2387,139 +2384,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
* Fix left-over restrictions and auto-time policy during COMP -> COPE migration.
|
||||||
*
|
*
|
||||||
@@ -2555,27 +2419,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
* Set an alarm for an upcoming event - expiration warning, expiration, or post-expiration
|
||||||
* reminders. Clears alarm if no expirations are configured.
|
* reminders. Clears alarm if no expirations are configured.
|
||||||
@@ -3197,7 +3040,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
|
|||||||
|
|
||||||
private void onLockSettingsReady() {
|
private void onLockSettingsReady() {
|
||||||
synchronized (getLockObject()) {
|
synchronized (getLockObject()) {
|
||||||
migrateUserRestrictionsIfNecessaryLocked();
|
|
||||||
fixupAutoTimeRestrictionDuringOrganizationOwnedDeviceMigration();
|
fixupAutoTimeRestrictionDuringOrganizationOwnedDeviceMigration();
|
||||||
}
|
}
|
||||||
getUserData(UserHandle.USER_SYSTEM);
|
getUserData(UserHandle.USER_SYSTEM);
|
||||||
|
|||||||
@@ -79,8 +79,6 @@ class Owners {
|
|||||||
|
|
||||||
private static final boolean DEBUG = false; // DO NOT SUBMIT WITH TRUE
|
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.
|
// XML storing device owner info, system update policy and pending OTA update information.
|
||||||
private static final String DEVICE_OWNER_XML = "device_owner_2.xml";
|
private static final String DEVICE_OWNER_XML = "device_owner_2.xml";
|
||||||
|
|
||||||
@@ -89,7 +87,6 @@ class Owners {
|
|||||||
private static final String TAG_ROOT = "root";
|
private static final String TAG_ROOT = "root";
|
||||||
|
|
||||||
private static final String TAG_DEVICE_OWNER = "device-owner";
|
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_SYSTEM_UPDATE_POLICY = "system-update-policy";
|
||||||
private static final String TAG_FREEZE_PERIOD_RECORD = "freeze-record";
|
private static final String TAG_FREEZE_PERIOD_RECORD = "freeze-record";
|
||||||
private static final String TAG_PENDING_OTA_INFO = "pending-ota-info";
|
private static final String TAG_PENDING_OTA_INFO = "pending-ota-info";
|
||||||
@@ -107,7 +104,6 @@ class Owners {
|
|||||||
private static final String ATTR_REMOTE_BUGREPORT_URI = "remoteBugreportUri";
|
private static final String ATTR_REMOTE_BUGREPORT_URI = "remoteBugreportUri";
|
||||||
private static final String ATTR_REMOTE_BUGREPORT_HASH = "remoteBugreportHash";
|
private static final String ATTR_REMOTE_BUGREPORT_HASH = "remoteBugreportHash";
|
||||||
private static final String ATTR_USERID = "userId";
|
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_START = "start";
|
||||||
private static final String ATTR_FREEZE_RECORD_END = "end";
|
private static final String ATTR_FREEZE_RECORD_END = "end";
|
||||||
// Legacy attribute, its presence would mean the profile owner associated with it is
|
// Legacy attribute, its presence would mean the profile owner associated with it is
|
||||||
@@ -180,35 +176,14 @@ class Owners {
|
|||||||
*/
|
*/
|
||||||
void load() {
|
void load() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
// First, try to read from the legacy file.
|
|
||||||
final File legacy = getLegacyConfigFile();
|
|
||||||
|
|
||||||
final List<UserInfo> users = mUserManager.getAliveUsers();
|
final List<UserInfo> users = mUserManager.getAliveUsers();
|
||||||
|
|
||||||
if (readLegacyOwnerFileLocked(legacy)) {
|
new DeviceOwnerReadWriter().readFromFileLocked();
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "Legacy config file found.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Legacy file exists, write to new files and remove the legacy one.
|
for (UserInfo ui : users) {
|
||||||
writeDeviceOwner();
|
new ProfileOwnerReadWriter(ui.id).readFromFileLocked();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mUserManagerInternal.setDeviceManaged(hasDeviceOwner());
|
mUserManagerInternal.setDeviceManaged(hasDeviceOwner());
|
||||||
for (UserInfo ui : users) {
|
for (UserInfo ui : users) {
|
||||||
mUserManagerInternal.setUserManaged(ui.id, hasProfileOwner(ui.id));
|
mUserManagerInternal.setUserManaged(ui.id, hasProfileOwner(ui.id));
|
||||||
@@ -337,24 +312,12 @@ class Owners {
|
|||||||
Slog.e(TAG, "Invalid user id for device owner user: " + userId);
|
Slog.e(TAG, "Invalid user id for device owner user: " + userId);
|
||||||
return;
|
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) {
|
synchronized (mLock) {
|
||||||
// A device owner is allowed to access device identifiers. Even though this flag
|
// 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
|
// 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.
|
// semantically compatible with the meaning of this flag.
|
||||||
mDeviceOwner = new OwnerInfo(ownerName, admin, userRestrictionsMigrated,
|
mDeviceOwner = new OwnerInfo(ownerName, admin, /* remoteBugreportUri =*/ null,
|
||||||
/* remoteBugreportUri =*/ null, /* remoteBugreportHash =*/
|
/* remoteBugreportHash =*/ null, /* isOrganizationOwnedDevice =*/ true);
|
||||||
null, /* isOrganizationOwnedDevice =*/true);
|
|
||||||
mDeviceOwnerUserId = userId;
|
mDeviceOwnerUserId = userId;
|
||||||
|
|
||||||
mUserManagerInternal.setDeviceManaged(true);
|
mUserManagerInternal.setDeviceManaged(true);
|
||||||
@@ -385,8 +348,8 @@ class Owners {
|
|||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
// For a newly set PO, there's no need for migration.
|
// For a newly set PO, there's no need for migration.
|
||||||
mProfileOwners.put(userId, new OwnerInfo(ownerName, admin,
|
mProfileOwners.put(userId, new OwnerInfo(ownerName, admin,
|
||||||
/* userRestrictionsMigrated =*/ true, /* remoteBugreportUri =*/ null,
|
/* remoteBugreportUri =*/ null, /* remoteBugreportHash =*/ null,
|
||||||
/* remoteBugreportHash =*/ null, /* isOrganizationOwnedDevice =*/ false));
|
/* isOrganizationOwnedDevice =*/ false));
|
||||||
mUserManagerInternal.setUserManaged(userId, true);
|
mUserManagerInternal.setUserManaged(userId, true);
|
||||||
notifyChangeLocked();
|
notifyChangeLocked();
|
||||||
}
|
}
|
||||||
@@ -404,8 +367,7 @@ class Owners {
|
|||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
final OwnerInfo ownerInfo = mProfileOwners.get(userId);
|
final OwnerInfo ownerInfo = mProfileOwners.get(userId);
|
||||||
final OwnerInfo newOwnerInfo = new OwnerInfo(target.getPackageName(), target,
|
final OwnerInfo newOwnerInfo = new OwnerInfo(target.getPackageName(), target,
|
||||||
ownerInfo.userRestrictionsMigrated, ownerInfo.remoteBugreportUri,
|
ownerInfo.remoteBugreportUri, ownerInfo.remoteBugreportHash,
|
||||||
ownerInfo.remoteBugreportHash, /* isOrganizationOwnedDevice =*/
|
|
||||||
ownerInfo.isOrganizationOwnedDevice);
|
ownerInfo.isOrganizationOwnedDevice);
|
||||||
mProfileOwners.put(userId, newOwnerInfo);
|
mProfileOwners.put(userId, newOwnerInfo);
|
||||||
notifyChangeLocked();
|
notifyChangeLocked();
|
||||||
@@ -423,10 +385,8 @@ class Owners {
|
|||||||
}
|
}
|
||||||
// We don't set a name because it's not used anyway.
|
// We don't set a name because it's not used anyway.
|
||||||
// See DevicePolicyManagerService#getDeviceOwnerName
|
// See DevicePolicyManagerService#getDeviceOwnerName
|
||||||
mDeviceOwner = new OwnerInfo(null, target,
|
mDeviceOwner = new OwnerInfo(null, target, mDeviceOwner.remoteBugreportUri,
|
||||||
mDeviceOwner.userRestrictionsMigrated, mDeviceOwner.remoteBugreportUri,
|
mDeviceOwner.remoteBugreportHash, mDeviceOwner.isOrganizationOwnedDevice);
|
||||||
mDeviceOwner.remoteBugreportHash, /* isOrganizationOwnedDevice =*/
|
|
||||||
mDeviceOwner.isOrganizationOwnedDevice);
|
|
||||||
if (previousDeviceOwnerType != null) {
|
if (previousDeviceOwnerType != null) {
|
||||||
mDeviceOwnerTypes.put(mDeviceOwner.packageName, previousDeviceOwnerType);
|
mDeviceOwnerTypes.put(mDeviceOwner.packageName, previousDeviceOwnerType);
|
||||||
}
|
}
|
||||||
@@ -570,35 +530,6 @@ class Owners {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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. */
|
/** Sets the remote bugreport uri and hash, and also writes to the file. */
|
||||||
void setDeviceOwnerRemoteBugreportUriAndHash(String remoteBugreportUri,
|
void setDeviceOwnerRemoteBugreportUriAndHash(String remoteBugreportUri,
|
||||||
String remoteBugreportHash) {
|
String remoteBugreportHash) {
|
||||||
@@ -611,17 +542,6 @@ class Owners {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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. */
|
/** Set whether the profile owner manages an organization-owned device, then write to file. */
|
||||||
void setProfileOwnerOfOrganizationOwnedDevice(int userId, boolean isOrganizationOwnedDevice) {
|
void setProfileOwnerOfOrganizationOwnedDevice(int userId, boolean isOrganizationOwnedDevice) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
@@ -696,72 +616,6 @@ class Owners {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
void writeDeviceOwner() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -1047,9 +901,6 @@ class Owners {
|
|||||||
mDeviceOwnerUserId);
|
mDeviceOwnerUserId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TAG_DEVICE_INITIALIZER:
|
|
||||||
// Deprecated tag
|
|
||||||
break;
|
|
||||||
case TAG_SYSTEM_UPDATE_POLICY:
|
case TAG_SYSTEM_UPDATE_POLICY:
|
||||||
mSystemUpdatePolicy = SystemUpdatePolicy.restoreFromXml(parser);
|
mSystemUpdatePolicy = SystemUpdatePolicy.restoreFromXml(parser);
|
||||||
break;
|
break;
|
||||||
@@ -1087,7 +938,6 @@ class Owners {
|
|||||||
default:
|
default:
|
||||||
Slog.e(TAG, "Unexpected tag: " + tag);
|
Slog.e(TAG, "Unexpected tag: " + tag);
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1136,30 +986,16 @@ class Owners {
|
|||||||
public final String name;
|
public final String name;
|
||||||
public final String packageName;
|
public final String packageName;
|
||||||
public final ComponentName admin;
|
public final ComponentName admin;
|
||||||
public boolean userRestrictionsMigrated;
|
|
||||||
public String remoteBugreportUri;
|
public String remoteBugreportUri;
|
||||||
public String remoteBugreportHash;
|
public String remoteBugreportHash;
|
||||||
public boolean isOrganizationOwnedDevice;
|
public boolean isOrganizationOwnedDevice;
|
||||||
|
|
||||||
public OwnerInfo(String name, String packageName, boolean userRestrictionsMigrated,
|
OwnerInfo(String name, ComponentName admin,
|
||||||
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,
|
|
||||||
String remoteBugreportUri, String remoteBugreportHash,
|
String remoteBugreportUri, String remoteBugreportHash,
|
||||||
boolean isOrganizationOwnedDevice) {
|
boolean isOrganizationOwnedDevice) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.admin = admin;
|
this.admin = admin;
|
||||||
this.packageName = admin.getPackageName();
|
this.packageName = admin.getPackageName();
|
||||||
this.userRestrictionsMigrated = userRestrictionsMigrated;
|
|
||||||
this.remoteBugreportUri = remoteBugreportUri;
|
this.remoteBugreportUri = remoteBugreportUri;
|
||||||
this.remoteBugreportHash = remoteBugreportHash;
|
this.remoteBugreportHash = remoteBugreportHash;
|
||||||
this.isOrganizationOwnedDevice = isOrganizationOwnedDevice;
|
this.isOrganizationOwnedDevice = isOrganizationOwnedDevice;
|
||||||
@@ -1167,14 +1003,12 @@ class Owners {
|
|||||||
|
|
||||||
public void writeToXml(TypedXmlSerializer out, String tag) throws IOException {
|
public void writeToXml(TypedXmlSerializer out, String tag) throws IOException {
|
||||||
out.startTag(null, tag);
|
out.startTag(null, tag);
|
||||||
out.attribute(null, ATTR_PACKAGE, packageName);
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
out.attribute(null, ATTR_NAME, name);
|
out.attribute(null, ATTR_NAME, name);
|
||||||
}
|
}
|
||||||
if (admin != null) {
|
if (admin != null) {
|
||||||
out.attribute(null, ATTR_COMPONENT_NAME, admin.flattenToString());
|
out.attribute(null, ATTR_COMPONENT_NAME, admin.flattenToString());
|
||||||
}
|
}
|
||||||
out.attributeBoolean(null, ATTR_USER_RESTRICTIONS_MIGRATED, userRestrictionsMigrated);
|
|
||||||
if (remoteBugreportUri != null) {
|
if (remoteBugreportUri != null) {
|
||||||
out.attribute(null, ATTR_REMOTE_BUGREPORT_URI, remoteBugreportUri);
|
out.attribute(null, ATTR_REMOTE_BUGREPORT_URI, remoteBugreportUri);
|
||||||
}
|
}
|
||||||
@@ -1189,14 +1023,9 @@ class Owners {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static OwnerInfo readFromXml(TypedXmlPullParser parser) {
|
public static OwnerInfo readFromXml(TypedXmlPullParser parser) {
|
||||||
final String packageName = parser.getAttributeValue(null, ATTR_PACKAGE);
|
|
||||||
final String name = parser.getAttributeValue(null, ATTR_NAME);
|
final String name = parser.getAttributeValue(null, ATTR_NAME);
|
||||||
final String componentName =
|
final String componentName =
|
||||||
parser.getAttributeValue(null, ATTR_COMPONENT_NAME);
|
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,
|
final String remoteBugreportUri = parser.getAttributeValue(null,
|
||||||
ATTR_REMOTE_BUGREPORT_URI);
|
ATTR_REMOTE_BUGREPORT_URI);
|
||||||
final String remoteBugreportHash = parser.getAttributeValue(null,
|
final String remoteBugreportHash = parser.getAttributeValue(null,
|
||||||
@@ -1210,23 +1039,18 @@ class Owners {
|
|||||||
final boolean isOrgOwnedDevice =
|
final boolean isOrgOwnedDevice =
|
||||||
("true".equals(isOrgOwnedDeviceStr)) | canAccessDeviceIds;
|
("true".equals(isOrgOwnedDeviceStr)) | canAccessDeviceIds;
|
||||||
|
|
||||||
// Has component name? If so, return [name, component]
|
if (componentName == null) {
|
||||||
if (componentName != null) {
|
Slog.e(TAG, "Owner component not found");
|
||||||
final ComponentName admin = ComponentName.unflattenFromString(componentName);
|
return null;
|
||||||
if (admin != null) {
|
}
|
||||||
return new OwnerInfo(name, admin, userRestrictionsMigrated,
|
final ComponentName admin = ComponentName.unflattenFromString(componentName);
|
||||||
remoteBugreportUri, remoteBugreportHash, isOrgOwnedDevice);
|
if (admin == null) {
|
||||||
} else {
|
Slog.e(TAG, "Owner component not parsable: " + componentName);
|
||||||
// This shouldn't happen but switch from package name -> component name
|
return null;
|
||||||
// might have written bad device owner files. b/17652534
|
|
||||||
Slog.e(TAG, "Error parsing owner file. Bad component name " +
|
|
||||||
componentName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else, build with [name, package]
|
return new OwnerInfo(
|
||||||
return new OwnerInfo(name, packageName, userRestrictionsMigrated, remoteBugreportUri,
|
name, admin, remoteBugreportUri, remoteBugreportHash, isOrgOwnedDevice);
|
||||||
remoteBugreportHash, isOrgOwnedDevice);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump(IndentingPrintWriter pw) {
|
public void dump(IndentingPrintWriter pw) {
|
||||||
@@ -1283,11 +1107,6 @@ class Owners {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
File getLegacyConfigFile() {
|
|
||||||
return new File(mInjector.environmentGetDataSystemDirectory(), DEVICE_OWNER_XML_LEGACY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
File getDeviceOwnerFile() {
|
File getDeviceOwnerFile() {
|
||||||
return new File(mInjector.environmentGetDataSystemDirectory(), DEVICE_OWNER_XML);
|
return new File(mInjector.environmentGetDataSystemDirectory(), DEVICE_OWNER_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>
|
||||||
@@ -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>
|
||||||
@@ -1 +0,0 @@
|
|||||||
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
|
|
||||||
<device-owner package="com.google.android.testdpc" />
|
|
||||||
@@ -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" />
|
|
||||||
@@ -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" />
|
|
||||||
@@ -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" />
|
|
||||||
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
|
|
||||||
<system-update-policy policy_type="5" />
|
|
||||||
@@ -27,7 +27,6 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
|
|||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -37,7 +36,6 @@ import android.content.ComponentName;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.IpcDataCache;
|
import android.os.IpcDataCache;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
@@ -55,8 +53,6 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Presubmit
|
@Presubmit
|
||||||
@@ -87,226 +83,9 @@ public class DevicePolicyManagerServiceMigrationTest extends DpmTestBase {
|
|||||||
.thenReturn(true);
|
.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 setting default restrictions for managed profile.
|
||||||
@Test
|
@Test
|
||||||
public void testMigration3_managedProfileOwner() throws Exception {
|
public void testMigration_managedProfileOwner() throws Exception {
|
||||||
// Create a managed profile user.
|
// Create a managed profile user.
|
||||||
final File user10dir = getServices().addUser(10, 0,
|
final File user10dir = getServices().addUser(10, 0,
|
||||||
UserManager.USER_TYPE_PROFILE_MANAGED);
|
UserManager.USER_TYPE_PROFILE_MANAGED);
|
||||||
|
|||||||
@@ -1665,39 +1665,6 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
assertThat(deviceOwner.getUid()).isEqualTo(DpmMockContext.CALLER_SYSTEM_USER_UID);
|
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
|
@Test
|
||||||
public void testSetGetApplicationRestriction() {
|
public void testSetGetApplicationRestriction() {
|
||||||
setAsProfileOwner(admin1);
|
setAsProfileOwner(admin1);
|
||||||
|
|||||||
@@ -18,29 +18,22 @@ package com.android.server.devicepolicy;
|
|||||||
|
|
||||||
import static android.app.admin.DevicePolicyManager.DEVICE_OWNER_TYPE_DEFAULT;
|
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.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.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.os.IpcDataCache;
|
import android.os.IpcDataCache;
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
|
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.server.devicepolicy.DevicePolicyManagerServiceTestable.OwnersTestable;
|
import com.android.server.devicepolicy.DevicePolicyManagerServiceTestable.OwnersTestable;
|
||||||
|
|
||||||
import com.google.android.collect.Lists;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
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.
|
* Tests for the DeviceOwner object that saves & loads device and policy owner information.
|
||||||
*
|
*
|
||||||
@@ -52,8 +45,7 @@ import java.util.List;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class OwnersTest extends DpmTestBase {
|
public class OwnersTest extends DpmTestBase {
|
||||||
|
|
||||||
private static final List<String> DEVICE_OWNER_PROTECTED_PACKAGES =
|
private static final String TESTDPC_PACKAGE = "com.afwsamples.testdpc";
|
||||||
Lists.newArrayList("package_1", "package_2");
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@@ -63,572 +55,66 @@ public class OwnersTest extends DpmTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpgrade01() throws Exception {
|
public void loadProfileOwner() throws Exception {
|
||||||
getServices().addUsers(10, 11, 20, 21);
|
getServices().addUsers(10);
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
final OwnersTestable owners = new OwnersTestable(getServices());
|
final OwnersTestable owners = new OwnersTestable(getServices());
|
||||||
|
|
||||||
// First, migrate to create new-style config files.
|
DpmTestUtils.writeToFile(owners.getProfileOwnerFile(10),
|
||||||
DpmTestUtils.writeToFile(owners.getLegacyConfigFile(),
|
DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/profile_owner_1.xml"));
|
||||||
DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/test04/input.xml"));
|
|
||||||
|
|
||||||
owners.load();
|
owners.load();
|
||||||
|
|
||||||
assertThat(owners.getLegacyConfigFile().exists()).isFalse();
|
assertThat(owners.hasDeviceOwner()).isFalse();
|
||||||
|
assertThat(owners.getSystemUpdatePolicy()).isNull();
|
||||||
|
|
||||||
assertThat(owners.getDeviceOwnerFile().exists()).isTrue();
|
assertThat(owners.getProfileOwnerKeys()).hasSize(1);
|
||||||
assertThat(owners.getDeviceOwnerType(owners.getDeviceOwnerPackageName())).isEqualTo(
|
assertThat(owners.getProfileOwnerComponent(10))
|
||||||
DEVICE_OWNER_TYPE_DEFAULT);
|
.isEqualTo(new ComponentName(TESTDPC_PACKAGE,
|
||||||
assertThat(owners.getDeviceOwnerProtectedPackages(owners.getDeviceOwnerPackageName()))
|
"com.afwsamples.testdpc.DeviceAdminReceiver"));
|
||||||
.isEmpty();
|
}
|
||||||
assertThat(owners.getProfileOwnerFile(10).exists()).isTrue();
|
|
||||||
assertThat(owners.getProfileOwnerFile(11).exists()).isTrue();
|
|
||||||
|
|
||||||
String previousDeviceOwnerPackageName = owners.getDeviceOwnerPackageName();
|
@Test
|
||||||
owners.setDeviceOwnerType(previousDeviceOwnerPackageName, DEVICE_OWNER_TYPE_FINANCED,
|
public void loadDeviceOwner() throws Exception {
|
||||||
/* isAdminTestOnly= */ false);
|
final OwnersTestable owners = new OwnersTestable(getServices());
|
||||||
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);
|
|
||||||
|
|
||||||
// Then clear all information and save.
|
DpmTestUtils.writeToFile(owners.getDeviceOwnerFile(),
|
||||||
owners.clearDeviceOwner();
|
DpmTestUtils.readAsset(mRealTestContext, "OwnersTest/device_owner_1.xml"));
|
||||||
owners.clearSystemUpdatePolicy();
|
|
||||||
owners.removeProfileOwner(10);
|
|
||||||
owners.removeProfileOwner(11);
|
|
||||||
|
|
||||||
owners.writeDeviceOwner();
|
owners.load();
|
||||||
owners.writeProfileOwner(10);
|
|
||||||
owners.writeProfileOwner(11);
|
|
||||||
owners.writeProfileOwner(20);
|
|
||||||
owners.writeProfileOwner(21);
|
|
||||||
|
|
||||||
// Now all files should be removed.
|
assertThat(owners.hasDeviceOwner()).isTrue();
|
||||||
assertThat(owners.getDeviceOwnerFile().exists()).isFalse();
|
|
||||||
assertThat(owners.getProfileOwnerFile(10).exists()).isFalse();
|
|
||||||
assertThat(owners.getProfileOwnerFile(11).exists()).isFalse();
|
|
||||||
|
|
||||||
assertThat(owners.getDeviceOwnerType(previousDeviceOwnerPackageName)).isEqualTo(
|
assertThat(owners.getProfileOwnerKeys()).hasSize(0);
|
||||||
DEVICE_OWNER_TYPE_DEFAULT);
|
assertThat(owners.getDeviceOwnerComponent())
|
||||||
assertThat(owners.getDeviceOwnerProtectedPackages(previousDeviceOwnerPackageName))
|
.isEqualTo(new ComponentName(TESTDPC_PACKAGE,
|
||||||
.isEmpty();
|
"com.afwsamples.testdpc.DeviceAdminReceiver"));
|
||||||
verify(getServices().packageManagerInternal)
|
|
||||||
.setDeviceOwnerProtectedPackages(
|
assertThat(owners.getSystemUpdatePolicy().getPolicyType()).isEqualTo(TYPE_INSTALL_WINDOWED);
|
||||||
previousDeviceOwnerPackageName, new ArrayList<>());
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user