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

Commit a94889dd authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Automerger Merge Worker
Browse files

Merge "Remove deprecated BroadcastOptions." into udc-dev am: 6bfff793

parents f3bf6a1a 6bfff793
Loading
Loading
Loading
Loading
+0 −49
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ public class BroadcastOptions extends ComponentOptions {
    private String[] mRequireNoneOfPermissions;
    private long mRequireCompatChangeId = CHANGE_INVALID;
    private long mIdForResponseEvent;
    private @Nullable IntentFilter mRemoveMatchingFilter;
    private @DeliveryGroupPolicy int mDeliveryGroupPolicy;
    private @Nullable String mDeliveryGroupMatchingKey;
    private @Nullable BundleMerger mDeliveryGroupExtrasMerger;
@@ -189,12 +188,6 @@ public class BroadcastOptions extends ComponentOptions {
    private static final String KEY_ID_FOR_RESPONSE_EVENT =
            "android:broadcast.idForResponseEvent";

    /**
     * Corresponds to {@link #setRemoveMatchingFilter}.
     */
    private static final String KEY_REMOVE_MATCHING_FILTER =
            "android:broadcast.removeMatchingFilter";

    /**
     * Corresponds to {@link #setDeliveryGroupPolicy(int)}.
     */
@@ -273,18 +266,6 @@ public class BroadcastOptions extends ComponentOptions {
        return opts;
    }

    /**
     * {@hide}
     * @deprecated use {@link #setDeliveryGroupMatchingFilter(IntentFilter)} instead.
     */
    @Deprecated
    public static @NonNull BroadcastOptions makeRemovingMatchingFilter(
            @NonNull IntentFilter removeMatchingFilter) {
        BroadcastOptions opts = new BroadcastOptions();
        opts.setRemoveMatchingFilter(removeMatchingFilter);
        return opts;
    }

    /**
     * Creates a new {@code BroadcastOptions} with no options initially set.
     */
@@ -315,8 +296,6 @@ public class BroadcastOptions extends ComponentOptions {
        mRequireNoneOfPermissions = opts.getStringArray(KEY_REQUIRE_NONE_OF_PERMISSIONS);
        mRequireCompatChangeId = opts.getLong(KEY_REQUIRE_COMPAT_CHANGE_ID, CHANGE_INVALID);
        mIdForResponseEvent = opts.getLong(KEY_ID_FOR_RESPONSE_EVENT);
        mRemoveMatchingFilter = opts.getParcelable(KEY_REMOVE_MATCHING_FILTER,
                IntentFilter.class);
        mDeliveryGroupPolicy = opts.getInt(KEY_DELIVERY_GROUP_POLICY,
                DELIVERY_GROUP_POLICY_ALL);
        mDeliveryGroupMatchingKey = opts.getString(KEY_DELIVERY_GROUP_KEY);
@@ -796,31 +775,6 @@ public class BroadcastOptions extends ComponentOptions {
        return (mFlags & FLAG_IS_DEFER_UNTIL_ACTIVE) != 0;
    }

    /**
     * When enqueuing this broadcast, remove all pending broadcasts previously
     * sent by this app which match the given filter.
     * <p>
     * For example, sending {@link Intent#ACTION_SCREEN_ON} would typically want
     * to remove any pending {@link Intent#ACTION_SCREEN_OFF} broadcasts.
     *
     * @hide
     * @deprecated use {@link #setDeliveryGroupMatchingFilter(IntentFilter)} instead.
     */
    @Deprecated
    public void setRemoveMatchingFilter(@NonNull IntentFilter removeMatchingFilter) {
        mRemoveMatchingFilter = Objects.requireNonNull(removeMatchingFilter);
    }

    /** @hide */
    public void clearRemoveMatchingFilter() {
        mRemoveMatchingFilter = null;
    }

    /** @hide */
    public @Nullable IntentFilter getRemoveMatchingFilter() {
        return mRemoveMatchingFilter;
    }

    /**
     * Set delivery group policy for this broadcast to specify how multiple broadcasts belonging to
     * the same delivery group has to be handled.
@@ -1092,9 +1046,6 @@ public class BroadcastOptions extends ComponentOptions {
        if (mIdForResponseEvent != 0) {
            b.putLong(KEY_ID_FOR_RESPONSE_EVENT, mIdForResponseEvent);
        }
        if (mRemoveMatchingFilter != null) {
            b.putParcelable(KEY_REMOVE_MATCHING_FILTER, mRemoveMatchingFilter);
        }
        if (mDeliveryGroupPolicy != DELIVERY_GROUP_POLICY_ALL) {
            b.putInt(KEY_DELIVERY_GROUP_POLICY, mDeliveryGroupPolicy);
        }
+17 −16
Original line number Diff line number Diff line
@@ -192,20 +192,21 @@ public final class BatteryService extends SystemService {
    private ArrayDeque<Bundle> mBatteryLevelsEventQueue;
    private long mLastBatteryLevelChangedSentMs;

    private Bundle mBatteryChangedOptions = BroadcastOptions.makeRemovingMatchingFilter(
            new IntentFilter(Intent.ACTION_BATTERY_CHANGED)).setDeferUntilActive(true)
    private Bundle mBatteryChangedOptions = BroadcastOptions.makeBasic()
            .setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT)
            .setDeferUntilActive(true)
            .toBundle();
    private Bundle mPowerConnectedOptions = BroadcastOptions.makeRemovingMatchingFilter(
            new IntentFilter(Intent.ACTION_POWER_DISCONNECTED)).setDeferUntilActive(true)
    /** Used for both connected/disconnected, so match using key */
    private Bundle mPowerOptions = BroadcastOptions.makeBasic()
            .setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT)
            .setDeliveryGroupMatchingKey("android", Intent.ACTION_POWER_CONNECTED)
            .setDeferUntilActive(true)
            .toBundle();
    private Bundle mPowerDisconnectedOptions = BroadcastOptions.makeRemovingMatchingFilter(
            new IntentFilter(Intent.ACTION_POWER_CONNECTED)).setDeferUntilActive(true)
            .toBundle();
    private Bundle mBatteryLowOptions = BroadcastOptions.makeRemovingMatchingFilter(
            new IntentFilter(Intent.ACTION_BATTERY_OKAY)).setDeferUntilActive(true)
            .toBundle();
    private Bundle mBatteryOkayOptions = BroadcastOptions.makeRemovingMatchingFilter(
            new IntentFilter(Intent.ACTION_BATTERY_LOW)).setDeferUntilActive(true)
    /** Used for both low/okay, so match using key */
    private Bundle mBatteryOptions = BroadcastOptions.makeBasic()
            .setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT)
            .setDeliveryGroupMatchingKey("android", Intent.ACTION_BATTERY_OKAY)
            .setDeferUntilActive(true)
            .toBundle();

    private MetricsLogger mMetricsLogger;
@@ -636,7 +637,7 @@ public final class BatteryService extends SystemService {
                    @Override
                    public void run() {
                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL, null,
                                mPowerConnectedOptions);
                                mPowerOptions);
                    }
                });
            }
@@ -648,7 +649,7 @@ public final class BatteryService extends SystemService {
                    @Override
                    public void run() {
                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL, null,
                                mPowerDisconnectedOptions);
                                mPowerOptions);
                    }
                });
            }
@@ -662,7 +663,7 @@ public final class BatteryService extends SystemService {
                    @Override
                    public void run() {
                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL, null,
                                mBatteryLowOptions);
                                mBatteryOptions);
                    }
                });
            } else if (mSentLowBatteryBroadcast &&
@@ -675,7 +676,7 @@ public final class BatteryService extends SystemService {
                    @Override
                    public void run() {
                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL, null,
                                mBatteryOkayOptions);
                                mBatteryOptions);
                    }
                });
            }
+3 −2
Original line number Diff line number Diff line
@@ -18179,8 +18179,9 @@ public class ActivityManagerService extends IActivityManager.Stub
                    bOptions.setTemporaryAppAllowlist(mInternal.getBootTimeTempAllowListDuration(),
                            TEMPORARY_ALLOW_LIST_TYPE_FOREGROUND_SERVICE_ALLOWED,
                            PowerExemptionManager.REASON_LOCALE_CHANGED, "");
                    bOptions.setRemoveMatchingFilter(
                            new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
                    bOptions.setDeliveryGroupPolicy(
                            BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT);
                    bOptions.setDeferUntilActive(true);
                    broadcastIntentLocked(null, null, null, intent, null, null, 0, null, null, null,
                            null, null, OP_NONE, bOptions.toBundle(), false, false, MY_PID,
                            SYSTEM_UID, Binder.getCallingUid(), Binder.getCallingPid(),
+0 −12
Original line number Diff line number Diff line
@@ -597,18 +597,6 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
        final int cookie = traceBegin("enqueueBroadcast");
        r.applySingletonPolicy(mService);

        final IntentFilter removeMatchingFilter = (r.options != null)
                ? r.options.getRemoveMatchingFilter() : null;
        if (removeMatchingFilter != null) {
            final Predicate<Intent> removeMatching = removeMatchingFilter.asPredicate();
            forEachMatchingBroadcast(QUEUE_PREDICATE_ANY, (testRecord, testIndex) -> {
                // We only allow caller to remove broadcasts they enqueued
                return (r.callingUid == testRecord.callingUid)
                        && (r.userId == testRecord.userId)
                        && removeMatching.test(testRecord.intent);
            }, mBroadcastConsumerSkipAndCanceled, true);
        }

        applyDeliveryGroupPolicy(r);

        r.enqueueTime = SystemClock.uptimeMillis();
+0 −34
Original line number Diff line number Diff line
@@ -758,40 +758,6 @@ public final class BroadcastQueueModernImplTest {
                queue.getActive().intent.getAction());
    }

    /**
     * Verify that sending a broadcast that removes any matching pending
     * broadcasts is applied as expected.
     */
    @Test
    public void testRemoveMatchingFilter() {
        final Intent screenOn = new Intent(Intent.ACTION_SCREEN_ON);
        final BroadcastOptions optionsOn = BroadcastOptions.makeBasic();
        optionsOn.setRemoveMatchingFilter(new IntentFilter(Intent.ACTION_SCREEN_OFF));

        final Intent screenOff = new Intent(Intent.ACTION_SCREEN_OFF);
        final BroadcastOptions optionsOff = BroadcastOptions.makeBasic();
        optionsOff.setRemoveMatchingFilter(new IntentFilter(Intent.ACTION_SCREEN_ON));

        // Halt all processing so that we get a consistent view
        mHandlerThread.getLooper().getQueue().postSyncBarrier();

        mImpl.enqueueBroadcastLocked(makeBroadcastRecord(screenOn, optionsOn));
        mImpl.enqueueBroadcastLocked(makeBroadcastRecord(screenOff, optionsOff));
        mImpl.enqueueBroadcastLocked(makeBroadcastRecord(screenOn, optionsOn));
        mImpl.enqueueBroadcastLocked(makeBroadcastRecord(screenOff, optionsOff));

        // While we're here, give our health check some test coverage
        mImpl.checkHealthLocked();

        // Marching through the queue we should only have one SCREEN_OFF
        // broadcast, since that's the last state we dispatched
        final BroadcastProcessQueue queue = mImpl.getProcessQueue(PACKAGE_GREEN,
                getUidForPackage(PACKAGE_GREEN));
        queue.makeActiveNextPending();
        assertEquals(Intent.ACTION_SCREEN_OFF, queue.getActive().intent.getAction());
        assertTrue(queue.isEmpty());
    }

    /**
     * Verify that sending a broadcast with DELIVERY_GROUP_POLICY_MOST_RECENT works as expected.
     */