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

Commit cc8b5187 authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille
Browse files

Send MANAGED_PROFILE_* broadcasts to apps with MODIFY_QUIET_MODE.

Allow apps with MODIFY_QUIET_MODE permission to register
broadcast receivers for MANAGED_PROFILE_* in their manifest.

Test: atest 'com.android.cts.devicepolicy.QuietModeHostsideTest#testBroadcastManagedProfileAvailable_withCrossProfileAppsOp'
Test: atest 'com.android.cts.devicepolicy.QuietModeHostsideTest#testBroadcastManagedProfileAvailable_withoutCrossProfileAppsOp'
Change-Id: I39746c5b3ff3c49f8a903fc52091fcb8d3607c84
parent eb8b12b2
Loading
Loading
Loading
Loading
+23 −1
Original line number Original line Diff line number Diff line
@@ -12675,7 +12675,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                for (ResolveInfo receiver : receivers) {
                for (ResolveInfo receiver : receivers) {
                    final String packageName = receiver.getComponentInfo().packageName;
                    final String packageName = receiver.getComponentInfo().packageName;
                    if (checkCrossProfilePackagePermissions(packageName, userId,
                    if (checkCrossProfilePackagePermissions(packageName, userId,
                            requiresPermission)) {
                            requiresPermission)
                            || checkModifyQuietModePermission(packageName, userId)) {
                        Slog.i(LOG_TAG,
                        Slog.i(LOG_TAG,
                                String.format("Sending %s broadcast to %s.", intent.getAction(),
                                String.format("Sending %s broadcast to %s.", intent.getAction(),
                                        packageName));
                                        packageName));
@@ -12692,6 +12693,27 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            }
            }
        }
        }
        /**
         * Checks whether the package {@code packageName} has the {@code MODIFY_QUIET_MODE}
         * permission granted for the user {@code userId}.
         */
        private boolean checkModifyQuietModePermission(String packageName, @UserIdInt int userId) {
            try {
                final int uid = Objects.requireNonNull(
                        mInjector.getPackageManager().getApplicationInfoAsUser(
                                Objects.requireNonNull(packageName), /* flags= */ 0, userId)).uid;
                return PackageManager.PERMISSION_GRANTED
                        == ActivityManager.checkComponentPermission(
                        android.Manifest.permission.MODIFY_QUIET_MODE, uid, /* owningUid= */
                        -1, /* exported= */ true);
            } catch (NameNotFoundException ex) {
                Slog.w(LOG_TAG,
                        String.format("Cannot find the package %s to check for permissions.",
                                packageName));
                return false;
            }
        }
        /**
        /**
         * Checks whether the package {@code packageName} has the required permissions to receive
         * Checks whether the package {@code packageName} has the required permissions to receive
         * cross-profile broadcasts on behalf of the user {@code userId}.
         * cross-profile broadcasts on behalf of the user {@code userId}.