Remove OwnersInfo.name field

Owner name no longer used so remove field from ownerInfo. Modify owner
setters to not take owner name as a parameter and remove owner getters
which retrieve owner name.

Bug: 240562947
Test: atest com.android.server.devicepolicy.DevicePolicyManagerTest
Change-Id: I6967eccff5fc8545160a65d78cac939874016023
This commit is contained in:
Eghosa Ewansiha-Vlachavas
2022-08-19 14:47:55 +00:00
parent a61c60e9ca
commit 2ab0e95a6a
3 changed files with 14 additions and 33 deletions

View File

@@ -8363,6 +8363,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
+ PackageManager.FEATURE_DEVICE_ADMIN + " feature.");
}
// TODO(b/240562946): Remove owner name from API parameters.
@Override
public boolean setDeviceOwner(ComponentName admin, String ownerName, int userId,
boolean setProfileOwnerOnCurrentUserIfNecessary) {
@@ -8397,7 +8398,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
.write();
}
mOwners.setDeviceOwner(admin, ownerName, userId);
mOwners.setDeviceOwner(admin, userId);
mOwners.writeDeviceOwner();
setDeviceOwnershipSystemPropertyLocked();
@@ -8649,6 +8650,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
}
// TODO(b/240562946): Remove api as owner name is not used.
/**
* Returns the "name" of the device owner. It'll work for non-DO users too, but requires
* MANAGE_USERS.
@@ -8819,6 +8821,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
});
}
// TODO(b/240562946): Remove owner name from API parameters.
@Override
public boolean setProfileOwner(ComponentName who, String ownerName, int userHandle) {
if (!mHasFeature) {
@@ -8866,7 +8869,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
// Shutting down backup manager service permanently.
toggleBackupServiceActive(userHandle, /* makeActive= */ false);
mOwners.setProfileOwner(who, ownerName, userHandle);
mOwners.setProfileOwner(who, userHandle);
mOwners.writeProfileOwner(userHandle);
Slogf.i(LOG_TAG, "Profile owner set: " + who + " on user " + userHandle);
@@ -9337,6 +9340,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
return who.getPackageName().equals(configPackage);
}
// TODO(b/240562946): Remove api as owner name is not used.
@Override
public String getProfileOwnerName(int userHandle) {
if (!mHasFeature) {

View File

@@ -193,12 +193,6 @@ class Owners {
}
}
String getDeviceOwnerName() {
synchronized (mData) {
return mData.mDeviceOwner != null ? mData.mDeviceOwner.name : null;
}
}
ComponentName getDeviceOwnerComponent() {
synchronized (mData) {
return mData.mDeviceOwner != null ? mData.mDeviceOwner.admin : null;
@@ -217,7 +211,7 @@ class Owners {
}
}
void setDeviceOwner(ComponentName admin, String ownerName, int userId) {
void setDeviceOwner(ComponentName admin, int userId) {
if (userId < 0) {
Slog.e(TAG, "Invalid user id for device owner user: " + userId);
return;
@@ -226,7 +220,7 @@ class Owners {
// 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.
mData.mDeviceOwner = new OwnerInfo(ownerName, admin, /* remoteBugreportUri =*/ null,
mData.mDeviceOwner = new OwnerInfo(admin, /* remoteBugreportUri =*/ null,
/* remoteBugreportHash =*/ null, /* isOrganizationOwnedDevice =*/ true);
mData.mDeviceOwnerUserId = userId;
@@ -248,10 +242,10 @@ class Owners {
}
}
void setProfileOwner(ComponentName admin, String ownerName, int userId) {
void setProfileOwner(ComponentName admin, int userId) {
synchronized (mData) {
// For a newly set PO, there's no need for migration.
mData.mProfileOwners.put(userId, new OwnerInfo(ownerName, admin,
mData.mProfileOwners.put(userId, new OwnerInfo(admin,
/* remoteBugreportUri =*/ null, /* remoteBugreportHash =*/ null,
/* isOrganizationOwnedDevice =*/ false));
mUserManagerInternal.setUserManaged(userId, true);
@@ -270,7 +264,7 @@ class Owners {
void transferProfileOwner(ComponentName target, int userId) {
synchronized (mData) {
final OwnerInfo ownerInfo = mData.mProfileOwners.get(userId);
final OwnerInfo newOwnerInfo = new OwnerInfo(target.getPackageName(), target,
final OwnerInfo newOwnerInfo = new OwnerInfo(target,
ownerInfo.remoteBugreportUri, ownerInfo.remoteBugreportHash,
ownerInfo.isOrganizationOwnedDevice);
mData.mProfileOwners.put(userId, newOwnerInfo);
@@ -282,9 +276,7 @@ class Owners {
synchronized (mData) {
Integer previousDeviceOwnerType = mData.mDeviceOwnerTypes.remove(
mData.mDeviceOwner.packageName);
// We don't set a name because it's not used anyway.
// See DevicePolicyManagerService#getDeviceOwnerName
mData.mDeviceOwner = new OwnerInfo(null, target,
mData.mDeviceOwner = new OwnerInfo(target,
mData.mDeviceOwner.remoteBugreportUri,
mData.mDeviceOwner.remoteBugreportHash,
mData.mDeviceOwner.isOrganizationOwnedDevice);
@@ -305,13 +297,6 @@ class Owners {
}
}
String getProfileOwnerName(int userId) {
synchronized (mData) {
OwnerInfo profileOwner = mData.mProfileOwners.get(userId);
return profileOwner != null ? profileOwner.name : null;
}
}
String getProfileOwnerPackage(int userId) {
synchronized (mData) {
OwnerInfo profileOwner = mData.mProfileOwners.get(userId);

View File

@@ -493,16 +493,14 @@ class OwnersData {
}
static class OwnerInfo {
public final String name;
public final String packageName;
public final ComponentName admin;
public String remoteBugreportUri;
public String remoteBugreportHash;
public boolean isOrganizationOwnedDevice;
OwnerInfo(String name, ComponentName admin, String remoteBugreportUri,
OwnerInfo(ComponentName admin, String remoteBugreportUri,
String remoteBugreportHash, boolean isOrganizationOwnedDevice) {
this.name = name;
this.admin = admin;
this.packageName = admin.getPackageName();
this.remoteBugreportUri = remoteBugreportUri;
@@ -512,9 +510,6 @@ class OwnersData {
public void writeToXml(TypedXmlSerializer out, String tag) throws IOException {
out.startTag(null, tag);
if (name != null) {
out.attribute(null, ATTR_NAME, name);
}
if (admin != null) {
out.attribute(null, ATTR_COMPONENT_NAME, admin.flattenToString());
}
@@ -532,7 +527,6 @@ class OwnersData {
}
public static OwnerInfo readFromXml(TypedXmlPullParser parser) {
final String name = parser.getAttributeValue(null, ATTR_NAME);
final String componentName = parser.getAttributeValue(null, ATTR_COMPONENT_NAME);
final String remoteBugreportUri =
parser.getAttributeValue(null, ATTR_REMOTE_BUGREPORT_URI);
@@ -556,13 +550,11 @@ class OwnersData {
return null;
}
return new OwnerInfo(
name, admin, remoteBugreportUri, remoteBugreportHash, isOrgOwnedDevice);
return new OwnerInfo(admin, remoteBugreportUri, remoteBugreportHash, isOrgOwnedDevice);
}
public void dump(IndentingPrintWriter pw) {
pw.println("admin=" + admin);
pw.println("name=" + name);
pw.println("package=" + packageName);
pw.println("isOrganizationOwnedDevice=" + isOrganizationOwnedDevice);
}