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
This commit is contained in:
Ayush Sharma
2023-05-09 10:42:34 +01:00
parent a95583ab86
commit 613c8f4eb5
2 changed files with 12 additions and 0 deletions

View File

@@ -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,

View File

@@ -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(