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

Commit 1d823047 authored by Pavel Grafov's avatar Pavel Grafov
Browse files

Set broadcast policy for suspension and quiet mode

These implicit broadcasts aren't protected by permission and can
be abused to keep the app active. With this change cached app won't
be receiving these broadcasts and if several of them are queued, they
will get merged.

Bug: 269595559
Test: manual with TestDPC
Change-Id: I209ab41b618fd9bfdcb1dd2c321cb49fe5197e64
parent a7259ae1
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.app.BroadcastOptions;
import android.app.IActivityManager;
import android.app.admin.DevicePolicyManagerInternal;
import android.content.Intent;
@@ -620,12 +621,15 @@ public final class SuspendPackageHelper {
        extras.putStringArray(Intent.EXTRA_CHANGED_PACKAGE_LIST, pkgList);
        extras.putIntArray(Intent.EXTRA_CHANGED_UID_LIST, uidList);
        final int flags = Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND;
        final Bundle options = new BroadcastOptions()
                .setDeferralPolicy(BroadcastOptions.DEFERRAL_POLICY_UNTIL_ACTIVE)
                .toBundle();
        handler.post(() -> mBroadcastHelper.sendPackageBroadcast(intent, null /* pkg */,
                extras, flags, null /* targetPkg */, null /* finishedReceiver */,
                new int[]{userId}, null /* instantUserIds */, null /* broadcastAllowList */,
                (callingUid, intentExtras) -> BroadcastHelper.filterExtrasChangedPackageList(
                        mPm.snapshotComputer(), callingUid, intentExtras),
                null /* bOptions */));
                options));
    }

    /**
+9 −1
Original line number Diff line number Diff line
@@ -1276,7 +1276,15 @@ public class UserManagerService extends IUserManager.Stub {
        getDevicePolicyManagerInternal().broadcastIntentToManifestReceivers(
                intent, parentHandle, /* requiresPermission= */ true);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
        mContext.sendBroadcastAsUser(intent, parentHandle);
        final Bundle options = new BroadcastOptions()
                .setDeferralPolicy(BroadcastOptions.DEFERRAL_POLICY_UNTIL_ACTIVE)
                .setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT)
                // Both actions use single namespace because only the final state matters.
                .setDeliveryGroupMatchingKey(
                        Intent.ACTION_MANAGED_PROFILE_AVAILABLE /* namespace */,
                        String.valueOf(profileHandle.getIdentifier()) /* key */)
                .toBundle();
        mContext.sendBroadcastAsUser(intent, parentHandle, /* receiverPermission= */ null, options);
    }

    @Override