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

Commit 8fcf1d63 authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Add push messaging as a trigger for proc start

Adding identification for process starts when the trigger was a
push_message.
When the push_message was over quota it may be deferred, but counting it
separately is still useful, as it could still cause cold process starts.

Test: Manual:
Run `./out/host/linux-x86/bin/statsd_testdrive 169`
Then use a sample app to send it an FCM message when it is not running.

Bug: 242928495
Change-Id: I55c56601af4eb60173ae039d8de7f9e7916c81e8
Merged-In: I55c56601af4eb60173ae039d8de7f9e7916c81e8
(cherry picked from commit 84c7a05d)
parent 83327c47
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -528,6 +528,28 @@ public class BroadcastOptions extends ComponentOptions {
        return mIsAlarmBroadcast;
    }

    /**
     * Did this broadcast originate from a push message from the server?
     *
     * @return true if this broadcast is a push message, false otherwise.
     * @hide
     */
    public boolean isPushMessagingBroadcast() {
        return mTemporaryAppAllowlistReasonCode == PowerExemptionManager.REASON_PUSH_MESSAGING;
    }

    /**
     * Did this broadcast originate from a push message from the server which was over the allowed
     * quota?
     *
     * @return true if this broadcast is a push message over quota, false otherwise.
     * @hide
     */
    public boolean isPushMessagingOverQuotaBroadcast() {
        return mTemporaryAppAllowlistReasonCode
                == PowerExemptionManager.REASON_PUSH_MESSAGING_OVER_QUOTA;
    }

    /** {@hide} */
    public long getRequireCompatChangeId() {
        return mRequireCompatChangeId;
+11 −2
Original line number Diff line number Diff line
@@ -1921,8 +1921,7 @@ public final class BroadcastQueue {
                info.activityInfo.applicationInfo, true,
                r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND,
                new HostingRecord(HostingRecord.HOSTING_TYPE_BROADCAST, r.curComponent,
                        r.intent.getAction(), (r.alarm ? HostingRecord.TRIGGER_TYPE_ALARM
                        : HostingRecord.TRIGGER_TYPE_UNKNOWN)),
                        r.intent.getAction(), getHostingRecordTriggerType(r)),
                isActivityCapable ? ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE : ZYGOTE_POLICY_FLAG_EMPTY,
                (r.intent.getFlags() & Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false);
        if (r.curApp == null) {
@@ -1945,6 +1944,16 @@ public final class BroadcastQueue {
        mPendingBroadcastRecvIndex = recIdx;
    }

    private String getHostingRecordTriggerType(BroadcastRecord r) {
        if (r.alarm) {
            return HostingRecord.TRIGGER_TYPE_ALARM;
        } else if (r.pushMessage) {
            return HostingRecord.TRIGGER_TYPE_PUSH_MESSAGE;
        } else if (r.pushMessageOverQuota) {
            return HostingRecord.TRIGGER_TYPE_PUSH_MESSAGE_OVER_QUOTA;
        }
        return HostingRecord.TRIGGER_TYPE_UNKNOWN;
    }

    @Nullable
    private String getTargetPackage(BroadcastRecord r) {
+6 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ final class BroadcastRecord extends Binder {
    final boolean ordered;  // serialize the send to receivers?
    final boolean sticky;   // originated from existing sticky data?
    final boolean alarm;    // originated from an alarm triggering?
    final boolean pushMessage; // originated from a push message?
    final boolean pushMessageOverQuota; // originated from a push message which was over quota?
    final boolean initialSticky; // initial broadcast from register to sticky?
    final int userId;       // user id this broadcast was for
    final String resolvedType; // the resolved data type
@@ -309,6 +311,8 @@ final class BroadcastRecord extends Binder {
        mBackgroundActivityStartsToken = backgroundActivityStartsToken;
        this.timeoutExempt = timeoutExempt;
        alarm = options != null && options.isAlarmBroadcast();
        pushMessage = options != null && options.isPushMessagingBroadcast();
        pushMessageOverQuota = options != null && options.isPushMessagingOverQuotaBroadcast();
    }

    /**
@@ -362,6 +366,8 @@ final class BroadcastRecord extends Binder {
        mBackgroundActivityStartsToken = from.mBackgroundActivityStartsToken;
        timeoutExempt = from.timeoutExempt;
        alarm = from.alarm;
        pushMessage = from.pushMessage;
        pushMessageOverQuota = from.pushMessageOverQuota;
    }

    /**
+8 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HO
import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_SERVICE;
import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_SYSTEM;
import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__HOSTING_TYPE_ID__HOSTING_TYPE_TOP_ACTIVITY;
import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_PUSH_MESSAGE;
import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_PUSH_MESSAGE_OVER_QUOTA;
import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_ALARM;
import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_UNKNOWN;
import static com.android.internal.util.FrameworkStatsLog.PROCESS_START_TIME__TYPE__UNKNOWN;
@@ -93,6 +95,8 @@ public final class HostingRecord {

    public static final String TRIGGER_TYPE_UNKNOWN = "unknown";
    public static final String TRIGGER_TYPE_ALARM = "alarm";
    public static final String TRIGGER_TYPE_PUSH_MESSAGE = "push_message";
    public static final String TRIGGER_TYPE_PUSH_MESSAGE_OVER_QUOTA = "push_message_over_quota";

    @NonNull private final String mHostingType;
    private final String mHostingName;
@@ -308,6 +312,10 @@ public final class HostingRecord {
        switch(triggerType) {
            case TRIGGER_TYPE_ALARM:
                return PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_ALARM;
            case TRIGGER_TYPE_PUSH_MESSAGE:
                return PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_PUSH_MESSAGE;
            case TRIGGER_TYPE_PUSH_MESSAGE_OVER_QUOTA:
                return PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_PUSH_MESSAGE_OVER_QUOTA;
            default:
                return PROCESS_START_TIME__TRIGGER_TYPE__TRIGGER_TYPE_UNKNOWN;
        }