From 613c8f4eb5cda99681c6bc6303603ece9b4131e7 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Tue, 9 May 2023 10:42:34 +0100 Subject: [PATCH] Throw exception if can't set default sms app on profile Only allow settting default sms app on work profile, if all the subscriptions on the device are managed(TYPE_ALL_MANAGED_SUBSCRIPTIONS) Bug: 279560135 Test: atest android.devicepolicy.cts.DefaultSmsApplicationTest Change-Id: I3a96855f525a22f27e4ac95fd20d6a9206e1ccac --- core/java/android/app/admin/DevicePolicyManager.java | 3 +++ .../server/devicepolicy/DevicePolicyManagerService.java | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index e9fb8110b4b21..59b59784b7807 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -9862,6 +9862,9 @@ public class DevicePolicyManager { * profile owner of an organization-owned managed profile. * @throws IllegalArgumentException if called on the parent profile and the package * provided is not a pre-installed system package. + * @throws IllegalStateException while trying to set default sms app on the profile and + * {@link ManagedSubscriptionsPolicy#TYPE_ALL_MANAGED_SUBSCRIPTIONS} + * policy is not set. */ @RequiresPermission(value = MANAGE_DEVICE_POLICY_DEFAULT_SMS, conditional = true) public void setDefaultSmsApplication(@Nullable ComponentName admin, diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 86e564ec59b72..9d84f8366a23d 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -11564,6 +11564,15 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { Preconditions.checkCallAuthorization(isDefaultDeviceOwner(caller) || isProfileOwnerOfOrganizationOwnedDevice(caller)); } + + if (!parent && isManagedProfile(caller.getUserId()) + && getManagedSubscriptionsPolicy().getPolicyType() + != ManagedSubscriptionsPolicy.TYPE_ALL_MANAGED_SUBSCRIPTIONS) { + throw new IllegalStateException( + "Default sms application can only be set on the profile, when " + + "ManagedSubscriptions policy is set"); + } + if (parent) { userId = getProfileParentId(mInjector.userHandleGetCallingUserId()); mInjector.binderWithCleanCallingIdentity(() -> enforcePackageIsSystemPackage(