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

Commit 6ce5ad93 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Add APIs to allow clients to pass in the bcast trigger event timestamps.

Bug: 325136414
Test: atest tests/app/src/android/app/cts/BroadcastOptionsTest.java
Change-Id: I681cf8b1ecafabc062192652fbe1e6adc3482fc5
parent 1684475d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -5460,11 +5460,15 @@ package android.app {
    method public int getDeferralPolicy();
    method @Nullable public String getDeliveryGroupMatchingKey();
    method public int getDeliveryGroupPolicy();
    method @FlaggedApi("android.app.bcast_event_timestamps") public long getEventTriggerTimestampMillis();
    method @FlaggedApi("android.app.bcast_event_timestamps") public long getRemoteEventTriggerTimestampMillis();
    method public boolean isShareIdentityEnabled();
    method @NonNull public static android.app.BroadcastOptions makeBasic();
    method @NonNull public android.app.BroadcastOptions setDeferralPolicy(int);
    method @NonNull public android.app.BroadcastOptions setDeliveryGroupMatchingKey(@NonNull String, @NonNull String);
    method @NonNull public android.app.BroadcastOptions setDeliveryGroupPolicy(int);
    method @FlaggedApi("android.app.bcast_event_timestamps") public void setEventTriggerTimestampMillis(long);
    method @FlaggedApi("android.app.bcast_event_timestamps") public void setRemoteEventTriggerTimestampMillis(long);
    method @NonNull public android.app.BroadcastOptions setShareIdentityEnabled(boolean);
    method @NonNull public android.os.Bundle toBundle();
    field public static final int DEFERRAL_POLICY_DEFAULT = 0; // 0x0
+78 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.app;

import android.annotation.CurrentTimeMillisLong;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
@@ -65,6 +67,8 @@ public class BroadcastOptions extends ComponentOptions {
    private @Nullable BundleMerger mDeliveryGroupExtrasMerger;
    private @Nullable IntentFilter mDeliveryGroupMatchingFilter;
    private @DeferralPolicy int mDeferralPolicy;
    private @CurrentTimeMillisLong long mEventTriggerTimestampMillis;
    private @CurrentTimeMillisLong long mRemoteEventTriggerTimestampMillis;

    /** @hide */
    @IntDef(flag = true, prefix = { "FLAG_" }, value = {
@@ -189,6 +193,18 @@ public class BroadcastOptions extends ComponentOptions {
    private static final String KEY_ID_FOR_RESPONSE_EVENT =
            "android:broadcast.idForResponseEvent";

    /**
     * Corresponds to {@link #setEventTriggerTimestampMillis(long)}.
     */
    private static final String KEY_EVENT_TRIGGER_TIMESTAMP =
            "android:broadcast.eventTriggerTimestamp";

    /**
     * Corresponds to {@link #setRemoteEventTriggerTimestampMillis(long)}.
     */
    private static final String KEY_REMOTE_EVENT_TRIGGER_TIMESTAMP =
            "android:broadcast.remoteEventTriggerTimestamp";

    /**
     * Corresponds to {@link #setDeliveryGroupPolicy(int)}.
     */
@@ -341,6 +357,8 @@ 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);
        mEventTriggerTimestampMillis = opts.getLong(KEY_EVENT_TRIGGER_TIMESTAMP);
        mRemoteEventTriggerTimestampMillis = opts.getLong(KEY_REMOTE_EVENT_TRIGGER_TIMESTAMP);
        mDeliveryGroupPolicy = opts.getInt(KEY_DELIVERY_GROUP_POLICY,
                DELIVERY_GROUP_POLICY_ALL);
        mDeliveryGroupMatchingNamespaceFragment = opts.getString(KEY_DELIVERY_GROUP_NAMESPACE);
@@ -786,6 +804,60 @@ public class BroadcastOptions extends ComponentOptions {
        return mIdForResponseEvent;
    }

    /**
     * Set the timestamp for the event that triggered this broadcast, in
     * {@link System#currentTimeMillis()} timebase.
     *
     * <p> For instance, if this broadcast is for a push message, then this timestamp
     * could correspond to when the device received the message.
     *
     * @param timestampMillis the timestamp in {@link System#currentTimeMillis()} timebase that
     *                        correspond to the event that triggered this broadcast.
     */
    @FlaggedApi(android.app.Flags.FLAG_BCAST_EVENT_TIMESTAMPS)
    public void setEventTriggerTimestampMillis(@CurrentTimeMillisLong long timestampMillis) {
        mEventTriggerTimestampMillis = timestampMillis;
    }

    /**
     * Return the timestamp for the event that triggered this broadcast, in
     * {@link System#currentTimeMillis()} timebase.
     *
     * @return the timestamp in {@link System#currentTimeMillis()} timebase that was previously
     *         set using {@link #setEventTriggerTimestampMillis(long)}.
     */
    @FlaggedApi(android.app.Flags.FLAG_BCAST_EVENT_TIMESTAMPS)
    public @CurrentTimeMillisLong long getEventTriggerTimestampMillis() {
        return mEventTriggerTimestampMillis;
    }

    /**
     * Set the timestamp for the remote event, if any, that triggered this broadcast, in
     * {@link System#currentTimeMillis()} timebase.
     *
     * <p> For instance, if this broadcast is for a push message, then this timestamp
     * could correspond to when the message originated remotely.
     *
     * @param timestampMillis the timestamp in {@link System#currentTimeMillis()} timebase that
     *                        correspond to the remote event that triggered this broadcast.
     */
    @FlaggedApi(android.app.Flags.FLAG_BCAST_EVENT_TIMESTAMPS)
    public void setRemoteEventTriggerTimestampMillis(@CurrentTimeMillisLong long timestampMillis) {
        mRemoteEventTriggerTimestampMillis = timestampMillis;
    }

    /**
     * Return the timestamp for the remote event that triggered this broadcast, in
     * {@link System#currentTimeMillis()} timebase.
     *
     * @return the timestamp in {@link System#currentTimeMillis()} timebase that was previously
     *         set using {@link #setRemoteEventTriggerTimestampMillis(long)}}.
     */
    @FlaggedApi(android.app.Flags.FLAG_BCAST_EVENT_TIMESTAMPS)
    public @CurrentTimeMillisLong long getRemoteEventTriggerTimestampMillis() {
        return mRemoteEventTriggerTimestampMillis;
    }

    /**
     * Sets deferral policy for this broadcast that specifies how this broadcast
     * can be deferred for delivery at some future point.
@@ -1120,6 +1192,12 @@ public class BroadcastOptions extends ComponentOptions {
        if (mIdForResponseEvent != 0) {
            b.putLong(KEY_ID_FOR_RESPONSE_EVENT, mIdForResponseEvent);
        }
        if (mEventTriggerTimestampMillis > 0) {
            b.putLong(KEY_EVENT_TRIGGER_TIMESTAMP, mEventTriggerTimestampMillis);
        }
        if (mRemoteEventTriggerTimestampMillis > 0) {
            b.putLong(KEY_REMOTE_EVENT_TRIGGER_TIMESTAMP, mRemoteEventTriggerTimestampMillis);
        }
        if (mDeliveryGroupPolicy != DELIVERY_GROUP_POLICY_ALL) {
            b.putInt(KEY_DELIVERY_GROUP_POLICY, mDeliveryGroupPolicy);
        }
+7 −0
Original line number Diff line number Diff line
@@ -34,3 +34,10 @@ flag {
     description: "Add a new callback in Service to indicate a FGS has reached its timeout."
     bug: "317799821"
}

flag {
    name: "bcast_event_timestamps"
    namespace: "backstage_power"
    description: "Add APIs for clients to provide broadcast event trigger timestamps"
    bug: "325136414"
}