Throw exception if can't set default sms app on profile am: 613c8f4eb5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23106936

Change-Id: I6e3636b482b97584fc1d0e3a48aa185885551881
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ayush Sharma
2023-05-12 14:52:06 +00:00
committed by Automerger Merge Worker
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

@@ -11569,6 +11569,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(