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

Commit 196c0793 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Automerger Merge Worker
Browse files

Merge "Log broadcast type and delivery policy." into udc-dev am: 858a4798

parents 1642fbd7 858a4798
Loading
Loading
Loading
Loading
+9 −6
Original line number Original line Diff line number Diff line
@@ -264,7 +264,7 @@ public class BroadcastQueueImpl extends BroadcastQueue {
                if (oldRecord.resultTo != null) {
                if (oldRecord.resultTo != null) {
                    try {
                    try {
                        oldRecord.mIsReceiverAppRunning = true;
                        oldRecord.mIsReceiverAppRunning = true;
                        performReceiveLocked(oldRecord.resultToApp, oldRecord.resultTo,
                        performReceiveLocked(oldRecord, oldRecord.resultToApp, oldRecord.resultTo,
                                oldRecord.intent,
                                oldRecord.intent,
                                Activity.RESULT_CANCELED, null, null,
                                Activity.RESULT_CANCELED, null, null,
                                false, false, oldRecord.shareIdentity, oldRecord.userId,
                                false, false, oldRecord.shareIdentity, oldRecord.userId,
@@ -615,7 +615,9 @@ public class BroadcastQueueImpl extends BroadcastQueue {
                    finishTime - r.receiverTime,
                    finishTime - r.receiverTime,
                    packageState,
                    packageState,
                    r.curApp.info.packageName,
                    r.curApp.info.packageName,
                    r.callerPackage);
                    r.callerPackage,
                    r.calculateTypeForLogging(),
                    r.getDeliveryGroupPolicy());
        }
        }
        if (state == BroadcastRecord.IDLE) {
        if (state == BroadcastRecord.IDLE) {
            Slog.w(TAG_BROADCAST, "finishReceiver [" + mQueueName + "] called but state is IDLE");
            Slog.w(TAG_BROADCAST, "finishReceiver [" + mQueueName + "] called but state is IDLE");
@@ -742,7 +744,7 @@ public class BroadcastQueueImpl extends BroadcastQueue {
        }
        }
    }
    }


    public void performReceiveLocked(ProcessRecord app, IIntentReceiver receiver,
    public void performReceiveLocked(BroadcastRecord r, ProcessRecord app, IIntentReceiver receiver,
            Intent intent, int resultCode, String data, Bundle extras,
            Intent intent, int resultCode, String data, Bundle extras,
            boolean ordered, boolean sticky, boolean shareIdentity, int sendingUser,
            boolean ordered, boolean sticky, boolean shareIdentity, int sendingUser,
            int receiverUid, int callingUid, String callingPackage,
            int receiverUid, int callingUid, String callingPackage,
@@ -795,7 +797,8 @@ public class BroadcastQueueImpl extends BroadcastQueue {
                    BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM,
                    BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM,
                    dispatchDelay, receiveDelay, 0 /* finish_delay */,
                    dispatchDelay, receiveDelay, 0 /* finish_delay */,
                    SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL,
                    SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL,
                    app != null ? app.info.packageName : null, callingPackage);
                    app != null ? app.info.packageName : null, callingPackage,
                    r.calculateTypeForLogging(), r.getDeliveryGroupPolicy());
        }
        }
    }
    }


@@ -871,7 +874,7 @@ public class BroadcastQueueImpl extends BroadcastQueue {
                maybeAddBackgroundStartPrivileges(filter.receiverList.app, r);
                maybeAddBackgroundStartPrivileges(filter.receiverList.app, r);
                maybeScheduleTempAllowlistLocked(filter.owningUid, r, r.options);
                maybeScheduleTempAllowlistLocked(filter.owningUid, r, r.options);
                maybeReportBroadcastDispatchedEventLocked(r, filter.owningUid);
                maybeReportBroadcastDispatchedEventLocked(r, filter.owningUid);
                performReceiveLocked(filter.receiverList.app, filter.receiverList.receiver,
                performReceiveLocked(r, filter.receiverList.app, filter.receiverList.receiver,
                        prepareReceiverIntent(r.intent, filteredExtras), r.resultCode, r.resultData,
                        prepareReceiverIntent(r.intent, filteredExtras), r.resultCode, r.resultData,
                        r.resultExtras, r.ordered, r.initialSticky, r.shareIdentity, r.userId,
                        r.resultExtras, r.ordered, r.initialSticky, r.shareIdentity, r.userId,
                        filter.receiverList.uid, r.callingUid, r.callerPackage,
                        filter.receiverList.uid, r.callingUid, r.callerPackage,
@@ -1162,7 +1165,7 @@ public class BroadcastQueueImpl extends BroadcastQueue {
                                r.dispatchTime = now;
                                r.dispatchTime = now;
                            }
                            }
                            r.mIsReceiverAppRunning = true;
                            r.mIsReceiverAppRunning = true;
                            performReceiveLocked(r.resultToApp, r.resultTo,
                            performReceiveLocked(r, r.resultToApp, r.resultTo,
                                    new Intent(r.intent), r.resultCode,
                                    new Intent(r.intent), r.resultCode,
                                    r.resultData, r.resultExtras, false, false, r.shareIdentity,
                                    r.resultData, r.resultExtras, false, false, r.shareIdentity,
                                    r.userId, r.callingUid, r.callingUid, r.callerPackage,
                                    r.userId, r.callingUid, r.callingUid, r.callerPackage,
+3 −3
Original line number Original line Diff line number Diff line
@@ -731,8 +731,7 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
        if (mService.shouldIgnoreDeliveryGroupPolicy(r.intent.getAction())) {
        if (mService.shouldIgnoreDeliveryGroupPolicy(r.intent.getAction())) {
            return;
            return;
        }
        }
        final int policy = (r.options != null)
        final int policy = r.getDeliveryGroupPolicy();
                ? r.options.getDeliveryGroupPolicy() : BroadcastOptions.DELIVERY_GROUP_POLICY_ALL;
        final BroadcastConsumer broadcastConsumer;
        final BroadcastConsumer broadcastConsumer;
        switch (policy) {
        switch (policy) {
            case BroadcastOptions.DELIVERY_GROUP_POLICY_ALL:
            case BroadcastOptions.DELIVERY_GROUP_POLICY_ALL:
@@ -1932,7 +1931,8 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
                    : SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL;
                    : SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL;
            FrameworkStatsLog.write(BROADCAST_DELIVERY_EVENT_REPORTED, uid, senderUid, actionName,
            FrameworkStatsLog.write(BROADCAST_DELIVERY_EVENT_REPORTED, uid, senderUid, actionName,
                    receiverType, type, dispatchDelay, receiveDelay, finishDelay, packageState,
                    receiverType, type, dispatchDelay, receiveDelay, finishDelay, packageState,
                    app != null ? app.info.packageName : null, r.callerPackage);
                    app != null ? app.info.packageName : null, r.callerPackage,
                    r.calculateTypeForLogging(), r.getDeliveryGroupPolicy());
        }
        }
    }
    }


+60 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,19 @@
package com.android.server.am;
package com.android.server.am;


import static android.app.ActivityManager.RESTRICTION_LEVEL_BACKGROUND_RESTRICTED;
import static android.app.ActivityManager.RESTRICTION_LEVEL_BACKGROUND_RESTRICTED;
import static android.app.AppProtoEnums.BROADCAST_TYPE_ALARM;
import static android.app.AppProtoEnums.BROADCAST_TYPE_BACKGROUND;
import static android.app.AppProtoEnums.BROADCAST_TYPE_DEFERRABLE_UNTIL_ACTIVE;
import static android.app.AppProtoEnums.BROADCAST_TYPE_FOREGROUND;
import static android.app.AppProtoEnums.BROADCAST_TYPE_INITIAL_STICKY;
import static android.app.AppProtoEnums.BROADCAST_TYPE_INTERACTIVE;
import static android.app.AppProtoEnums.BROADCAST_TYPE_NONE;
import static android.app.AppProtoEnums.BROADCAST_TYPE_ORDERED;
import static android.app.AppProtoEnums.BROADCAST_TYPE_PRIORITIZED;
import static android.app.AppProtoEnums.BROADCAST_TYPE_PUSH_MESSAGE;
import static android.app.AppProtoEnums.BROADCAST_TYPE_PUSH_MESSAGE_OVER_QUOTA;
import static android.app.AppProtoEnums.BROADCAST_TYPE_RESULT_TO;
import static android.app.AppProtoEnums.BROADCAST_TYPE_STICKY;


import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_ALL;
import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_ALL;
import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_BACKGROUND_RESTRICTED_ONLY;
import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_BACKGROUND_RESTRICTED_ONLY;
@@ -35,6 +48,7 @@ import android.app.ActivityManagerInternal;
import android.app.AppOpsManager;
import android.app.AppOpsManager;
import android.app.BackgroundStartPrivileges;
import android.app.BackgroundStartPrivileges;
import android.app.BroadcastOptions;
import android.app.BroadcastOptions;
import android.app.BroadcastOptions.DeliveryGroupPolicy;
import android.app.compat.CompatChanges;
import android.app.compat.CompatChanges;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.IIntentReceiver;
import android.content.IIntentReceiver;
@@ -1018,6 +1032,46 @@ final class BroadcastRecord extends Binder {
        }
        }
    }
    }


    int calculateTypeForLogging() {
        int type = BROADCAST_TYPE_NONE;
        if (isForeground()) {
            type |= BROADCAST_TYPE_FOREGROUND;
        } else {
            type |= BROADCAST_TYPE_BACKGROUND;
        }
        if (alarm) {
            type |= BROADCAST_TYPE_ALARM;
        }
        if (interactive) {
            type |= BROADCAST_TYPE_INTERACTIVE;
        }
        if (ordered) {
            type |= BROADCAST_TYPE_ORDERED;
        }
        if (prioritized) {
            type |= BROADCAST_TYPE_PRIORITIZED;
        }
        if (resultTo != null) {
            type |= BROADCAST_TYPE_RESULT_TO;
        }
        if (deferUntilActive) {
            type |= BROADCAST_TYPE_DEFERRABLE_UNTIL_ACTIVE;
        }
        if (pushMessage) {
            type |= BROADCAST_TYPE_PUSH_MESSAGE;
        }
        if (pushMessageOverQuota) {
            type |= BROADCAST_TYPE_PUSH_MESSAGE_OVER_QUOTA;
        }
        if (sticky) {
            type |= BROADCAST_TYPE_STICKY;
        }
        if (initialSticky) {
            type |= BROADCAST_TYPE_INITIAL_STICKY;
        }
        return type;
    }

    public BroadcastRecord maybeStripForHistory() {
    public BroadcastRecord maybeStripForHistory() {
        if (!intent.canStripForHistory()) {
        if (!intent.canStripForHistory()) {
            return this;
            return this;
@@ -1113,6 +1167,12 @@ final class BroadcastRecord extends Binder {
        return true;
        return true;
    }
    }


    @DeliveryGroupPolicy
    int getDeliveryGroupPolicy() {
        return (options != null) ? options.getDeliveryGroupPolicy()
                : BroadcastOptions.DELIVERY_GROUP_POLICY_ALL;
    }

    boolean matchesDeliveryGroup(@NonNull BroadcastRecord other) {
    boolean matchesDeliveryGroup(@NonNull BroadcastRecord other) {
        return matchesDeliveryGroup(this, other);
        return matchesDeliveryGroup(this, other);
    }
    }
+2 −1
Original line number Original line Diff line number Diff line
@@ -1406,7 +1406,8 @@ public final class BroadcastQueueModernImplTest {
                eq(getUidForPackage(PACKAGE_GREEN)), anyInt(), eq(Intent.ACTION_TIME_TICK),
                eq(getUidForPackage(PACKAGE_GREEN)), anyInt(), eq(Intent.ACTION_TIME_TICK),
                eq(BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__MANIFEST),
                eq(BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__MANIFEST),
                eq(BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD),
                eq(BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD),
                anyLong(), anyLong(), anyLong(), anyInt(), nullable(String.class), anyString()),
                anyLong(), anyLong(), anyLong(), anyInt(), nullable(String.class),
                anyString(), anyInt(), anyInt()),
                times(1));
                times(1));
    }
    }