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

Commit ac3d80dc authored by Martijn Coenen's avatar Martijn Coenen
Browse files

Add package state in service/broadcast/cp/activity atoms.

So we can tell what state the package was in when these events happen.
This will allow us to measure effectivity of the various stopped states
in the system.

Bug: 267277359
Test: statsd_testdrive 48
Test: statsd_testdrive 475
Test: statsd_testdrive 476
Test: statsd_testdrive 477

Change-Id: I971c14bdccf14c8a036041a2d6c906900c45ee1b
parent 0c4b4183
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ import static com.android.internal.util.FrameworkStatsLog.FOREGROUND_SERVICE_STA
import static com.android.internal.util.FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER;
import static com.android.internal.util.FrameworkStatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__EXIT;
import static com.android.internal.util.FrameworkStatsLog.SERVICE_REQUEST_EVENT_REPORTED;
import static com.android.internal.util.FrameworkStatsLog.SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL;
import static com.android.internal.util.FrameworkStatsLog.SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_STOPPED;
import static com.android.internal.util.FrameworkStatsLog.SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD;
import static com.android.internal.util.FrameworkStatsLog.SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_HOT;
import static com.android.internal.util.FrameworkStatsLog.SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM;
@@ -1269,6 +1271,10 @@ public final class ActiveServices {
            return new ComponentName("!!", error);
        }

        final boolean wasStopped = (r.appInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0;
        final int packageState = wasStopped
                ? SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_STOPPED
                : SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL;
        FrameworkStatsLog.write(SERVICE_REQUEST_EVENT_REPORTED, uid, callingUid,
                service.getAction(),
                SERVICE_REQUEST_EVENT_REPORTED__REQUEST_TYPE__START, false,
@@ -1278,7 +1284,8 @@ public final class ActiveServices {
                ? SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_HOT
                : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM),
                getShortProcessNameForStats(callingUid, callingProcessName),
                getShortServiceNameForStats(r));
                getShortServiceNameForStats(r),
                packageState);

        if (r.startRequested && addToStarting) {
            boolean first = smap.mStartingBackground.size() == 0;
@@ -3405,6 +3412,7 @@ public final class ActiveServices {
                mAm.requireAllowedAssociationsLocked(s.appInfo.packageName);
            }

            final boolean wasStopped = (s.appInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0;
            final boolean wasStartRequested = s.startRequested;
            final boolean hadConnections = !s.getConnections().isEmpty();
            mAm.startAssociationLocked(callerApp.uid, callerApp.processName,
@@ -3491,6 +3499,9 @@ public final class ActiveServices {
                mAm.updateOomAdjPendingTargetsLocked(OomAdjuster.OOM_ADJ_REASON_BIND_SERVICE);
            }

            final int packageState = wasStopped
                    ? SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_STOPPED
                    : SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL;
            FrameworkStatsLog.write(SERVICE_REQUEST_EVENT_REPORTED, s.appInfo.uid, callingUid,
                    ActivityManagerService.getShortAction(service.getAction()),
                    SERVICE_REQUEST_EVENT_REPORTED__REQUEST_TYPE__BIND, false,
@@ -3500,7 +3511,8 @@ public final class ActiveServices {
                    ? SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_HOT
                    : SERVICE_REQUEST_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM),
                    getShortProcessNameForStats(callingUid, callerApp.processName),
                    getShortServiceNameForStats(s));
                    getShortServiceNameForStats(s),
                    packageState);

            if (DEBUG_SERVICE) Slog.v(TAG_SERVICE, "Bind " + s + " with " + b
                    + ": received=" + b.intent.received
+15 −0
Original line number Diff line number Diff line
@@ -154,6 +154,12 @@ class BroadcastProcessQueue {
     */
    private boolean mActiveViaColdStart;

    /**
     * Flag indicating that the currently active broadcast is being dispatched
     * to a package that was in the stopped state.
     */
    private boolean mActiveWasStopped;

    /**
     * Number of consecutive urgent broadcasts that have been dispatched
     * since the last non-urgent dispatch.
@@ -454,10 +460,18 @@ class BroadcastProcessQueue {
        mActiveViaColdStart = activeViaColdStart;
    }

    public void setActiveWasStopped(boolean activeWasStopped) {
        mActiveWasStopped = activeWasStopped;
    }

    public boolean getActiveViaColdStart() {
        return mActiveViaColdStart;
    }

    public boolean getActiveWasStopped() {
        return mActiveWasStopped;
    }

    /**
     * Get package name of the first application loaded into this process.
     */
@@ -477,6 +491,7 @@ class BroadcastProcessQueue {
        final boolean wouldBeSkipped = (next.argi2 == 1);
        mActiveCountSinceIdle++;
        mActiveViaColdStart = false;
        mActiveWasStopped = false;
        next.recycle();
        onBroadcastDequeued(mActive, mActiveIndex, wouldBeSkipped);
    }
+16 −2
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVE
import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM;
import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__MANIFEST;
import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__RUNTIME;
import static com.android.internal.util.FrameworkStatsLog.SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL;
import static com.android.internal.util.FrameworkStatsLog.SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_STOPPED;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BROADCAST;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BROADCAST_DEFERRAL;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BROADCAST_LIGHT;
@@ -51,6 +53,7 @@ import android.content.ContentResolver;
import android.content.IIntentReceiver;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
@@ -588,6 +591,11 @@ public class BroadcastQueueImpl extends BroadcastQueue {
        final long elapsed = finishTime - r.receiverTime;
        r.state = BroadcastRecord.IDLE;
        final int curIndex = r.nextReceiver - 1;

        final int packageState = r.mWasReceiverAppStopped
                ? SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_STOPPED
                : SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL;

        if (curIndex >= 0 && curIndex < r.receivers.size() && r.curApp != null) {
            final Object curReceiver = r.receivers.get(curIndex);
            FrameworkStatsLog.write(BROADCAST_DELIVERY_EVENT_REPORTED, r.curApp.uid,
@@ -601,7 +609,8 @@ public class BroadcastQueueImpl extends BroadcastQueue {
                    : BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_COLD,
                    r.dispatchTime - r.enqueueTime,
                    r.receiverTime - r.dispatchTime,
                    finishTime - r.receiverTime);
                    finishTime - r.receiverTime,
                    packageState);
        }
        if (state == BroadcastRecord.IDLE) {
            Slog.w(TAG_BROADCAST, "finishReceiver [" + mQueueName + "] called but state is IDLE");
@@ -664,6 +673,7 @@ public class BroadcastQueueImpl extends BroadcastQueue {
        r.curReceiver = null;
        r.curApp = null;
        r.curFilteredExtras = null;
        r.mWasReceiverAppStopped = false;
        mPendingBroadcast = null;

        r.resultCode = resultCode;
@@ -778,7 +788,8 @@ public class BroadcastQueueImpl extends BroadcastQueue {
                    intent.getAction(),
                    BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__RUNTIME,
                    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);
        }
    }

@@ -1436,6 +1447,9 @@ public class BroadcastQueueImpl extends BroadcastQueue {
            // restart the application.
        }

        // Registered whether we're bringing this package out of a stopped state
        r.mWasReceiverAppStopped =
                (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0;
        // Not running -- get it started, to be executed when the app comes up.
        if (DEBUG_BROADCAST)  Slog.v(TAG_BROADCAST,
                "Need to start app ["
+12 −2
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVE
import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVENT_REPORTED__PROC_START_TYPE__PROCESS_START_TYPE_WARM;
import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__MANIFEST;
import static com.android.internal.util.FrameworkStatsLog.BROADCAST_DELIVERY_EVENT_REPORTED__RECEIVER_TYPE__RUNTIME;
import static com.android.internal.util.FrameworkStatsLog.SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL;
import static com.android.internal.util.FrameworkStatsLog.SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_STOPPED;
import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BROADCAST;
import static com.android.server.am.BroadcastProcessQueue.insertIntoRunnableList;
import static com.android.server.am.BroadcastProcessQueue.reasonToString;
@@ -755,6 +757,9 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
        final ApplicationInfo info = ((ResolveInfo) receiver).activityInfo.applicationInfo;
        final ComponentName component = ((ResolveInfo) receiver).activityInfo.getComponentName();

        if ((info.flags & ApplicationInfo.FLAG_STOPPED) != 0) {
            queue.setActiveWasStopped(true);
        }
        final int intentFlags = r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND;
        final HostingRecord hostingRecord = new HostingRecord(HostingRecord.HOSTING_TYPE_BROADCAST,
                component, r.intent.getAction(), r.getHostingRecordTriggerType());
@@ -1768,8 +1773,13 @@ class BroadcastQueueModernImpl extends BroadcastQueue {
        final long dispatchDelay = r.scheduledTime[index] - r.enqueueTime;
        final long receiveDelay = 0;
        final long finishDelay = r.terminalTime[index] - r.scheduledTime[index];
        if (queue != null) {
            final int packageState = queue.getActiveWasStopped()
                    ? SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_STOPPED
                    : SERVICE_REQUEST_EVENT_REPORTED__PACKAGE_STOPPED_STATE__PACKAGE_STATE_NORMAL;
            FrameworkStatsLog.write(BROADCAST_DELIVERY_EVENT_REPORTED, uid, senderUid, actionName,
                receiverType, type, dispatchDelay, receiveDelay, finishDelay);
                    receiverType, type, dispatchDelay, receiveDelay, finishDelay, packageState);
        }

        final boolean recordFinished = (r.terminalCount == r.receivers.size());
        if (recordFinished) {
+2 −0
Original line number Diff line number Diff line
@@ -220,6 +220,8 @@ final class BroadcastRecord extends Binder {

    boolean mIsReceiverAppRunning; // Was the receiver's app already running.

    boolean mWasReceiverAppStopped; // Was the receiver app stopped prior to starting

    // Private refcount-management bookkeeping; start > 0
    static AtomicInteger sNextToken = new AtomicInteger(1);

Loading