Merge "Allow device owner to configure preferential network service" into tm-dev

This commit is contained in:
Sooraj Sasindran
2022-05-06 18:50:35 +00:00
committed by Android (Google) Code Review

View File

@@ -8513,6 +8513,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
} }
} }
private boolean isDeviceOwnerUserId(int userId) {
synchronized (getLockObject()) {
return mOwners.getDeviceOwnerComponent() != null
&& mOwners.getDeviceOwnerUserId() == userId;
}
}
private boolean isDeviceOwnerPackage(String packageName, int userId) { private boolean isDeviceOwnerPackage(String packageName, int userId) {
synchronized (getLockObject()) { synchronized (getLockObject()) {
return mOwners.hasDeviceOwner() return mOwners.hasDeviceOwner()
@@ -12117,10 +12124,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
return; return;
} }
final CallerIdentity caller = getCallerIdentity(); final CallerIdentity caller = getCallerIdentity();
Preconditions.checkCallAuthorization(isProfileOwner(caller) Preconditions.checkCallAuthorization((isProfileOwner(caller)
&& isManagedProfile(caller.getUserId()))
|| isDefaultDeviceOwner(caller), || isDefaultDeviceOwner(caller),
"Caller is not profile owner or device owner;" "Caller is not managed profile owner or device owner;"
+ " only profile owner or device owner may control the preferential" + " only managed profile owner or device owner may control the preferential"
+ " network service"); + " network service");
synchronized (getLockObject()) { synchronized (getLockObject()) {
final ActiveAdmin requiredAdmin = getDeviceOrProfileOwnerAdminLocked( final ActiveAdmin requiredAdmin = getDeviceOrProfileOwnerAdminLocked(
@@ -12147,11 +12155,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
} }
final CallerIdentity caller = getCallerIdentity(); final CallerIdentity caller = getCallerIdentity();
Preconditions.checkCallAuthorization(isProfileOwner(caller) Preconditions.checkCallAuthorization((isProfileOwner(caller)
&& isManagedProfile(caller.getUserId()))
|| isDefaultDeviceOwner(caller), || isDefaultDeviceOwner(caller),
"Caller is not profile owner or device owner;" "Caller is not managed profile owner or device owner;"
+ " only profile owner or device owner may retrieve the preferential" + " only managed profile owner or device owner may retrieve the "
+ " network service configurations"); + "preferential network service configurations");
synchronized (getLockObject()) { synchronized (getLockObject()) {
final ActiveAdmin requiredAdmin = getDeviceOrProfileOwnerAdminLocked( final ActiveAdmin requiredAdmin = getDeviceOrProfileOwnerAdminLocked(
caller.getUserId()); caller.getUserId());
@@ -18266,7 +18275,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
private void updateNetworkPreferenceForUser(int userId, private void updateNetworkPreferenceForUser(int userId,
List<PreferentialNetworkServiceConfig> preferentialNetworkServiceConfigs) { List<PreferentialNetworkServiceConfig> preferentialNetworkServiceConfigs) {
if (!isManagedProfile(userId)) { if (!isManagedProfile(userId) && !isDeviceOwnerUserId(userId)) {
return; return;
} }
List<ProfileNetworkPreference> preferences = new ArrayList<>(); List<ProfileNetworkPreference> preferences = new ArrayList<>();