Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 613c8f4e authored by Ayush Sharma's avatar Ayush Sharma
Browse files

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
parent a95583ab
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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,
+9 −0
Original line number Diff line number Diff line
@@ -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(