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

Commit fd66d4d7 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

AML: Support concurrent launches

Now the transition info doesn't associate to windowing mode.
A consecutive launch is identified by checking if the caller
is existing in an active transition. Since the global states
and timestamps are moved to TransitionInfo, different
transitions can be tracked individually.

Bug: 123355661
Test: atest ActivityMetricsLaunchObserverTests
            ActivityMetricsLoggerTests

Change-Id: I07aeedd0d525b4bee94809e487aa84cdcb300cf3
parent ca7ad250
Loading
Loading
Loading
Loading
+417 −392

File changed.

Preview size limit exceeded, changes collapsed.

+7 −13
Original line number Original line Diff line number Diff line
@@ -312,7 +312,7 @@ import com.android.server.display.color.ColorDisplayService;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.protolog.common.ProtoLog;
import com.android.server.protolog.common.ProtoLog;
import com.android.server.uri.UriPermissionOwner;
import com.android.server.uri.UriPermissionOwner;
import com.android.server.wm.ActivityMetricsLogger.WindowingModeTransitionInfoSnapshot;
import com.android.server.wm.ActivityMetricsLogger.TransitionInfoSnapshot;
import com.android.server.wm.ActivityStack.ActivityState;
import com.android.server.wm.ActivityStack.ActivityState;
import com.android.server.wm.WindowManagerService.H;
import com.android.server.wm.WindowManagerService.H;
import com.android.server.wm.utils.InsetUtils;
import com.android.server.wm.utils.InsetUtils;
@@ -3010,6 +3010,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        getDisplayContent().mChangingApps.remove(this);
        getDisplayContent().mChangingApps.remove(this);
        getDisplayContent().mUnknownAppVisibilityController.appRemovedOrHidden(this);
        getDisplayContent().mUnknownAppVisibilityController.appRemovedOrHidden(this);
        mWmService.mTaskSnapshotController.onAppRemoved(this);
        mWmService.mTaskSnapshotController.onAppRemoved(this);
        mStackSupervisor.getActivityMetricsLogger().notifyActivityRemoved(this);
        waitingToShow = false;
        waitingToShow = false;
        if (getDisplayContent().mClosingApps.contains(this)) {
        if (getDisplayContent().mClosingApps.contains(this)) {
            delayed = true;
            delayed = true;
@@ -4985,7 +4986,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    }
    }


    void reportFullyDrawnLocked(boolean restoredFromBundle) {
    void reportFullyDrawnLocked(boolean restoredFromBundle) {
        final WindowingModeTransitionInfoSnapshot info = mStackSupervisor
        final TransitionInfoSnapshot info = mStackSupervisor
            .getActivityMetricsLogger().logAppTransitionReportedDrawn(this, restoredFromBundle);
            .getActivityMetricsLogger().logAppTransitionReportedDrawn(this, restoredFromBundle);
        if (info != null) {
        if (info != null) {
            mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this,
            mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this,
@@ -5017,8 +5018,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (!drawn) {
        if (!drawn) {
            return;
            return;
        }
        }
        final WindowingModeTransitionInfoSnapshot info = mStackSupervisor
        final TransitionInfoSnapshot info = mStackSupervisor
            .getActivityMetricsLogger().notifyWindowsDrawn(getWindowingMode(), timestampNs);
                .getActivityMetricsLogger().notifyWindowsDrawn(this, timestampNs);
        final int windowsDrawnDelayMs = info != null ? info.windowsDrawnDelayMs : INVALID_DELAY;
        final int windowsDrawnDelayMs = info != null ? info.windowsDrawnDelayMs : INVALID_DELAY;
        final @LaunchState int launchState = info != null ? info.getLaunchState() : -1;
        final @LaunchState int launchState = info != null ? info.getLaunchState() : -1;
        mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this,
        mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this,
@@ -5219,7 +5220,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                    }
                    }
                }
                }
            } else if (w.isDrawnLw()) {
            } else if (w.isDrawnLw()) {
                onStartingWindowDrawn(SystemClock.elapsedRealtimeNanos());
                // The starting window for this container is drawn.
                mStackSupervisor.getActivityMetricsLogger().notifyStartingWindowDrawn(this);
                startingDisplayed = true;
                startingDisplayed = true;
            }
            }
        }
        }
@@ -5227,14 +5229,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return isInterestingAndDrawn;
        return isInterestingAndDrawn;
    }
    }


    /** Called when the starting window for this container is drawn. */
    private void onStartingWindowDrawn(long timestampNs) {
        synchronized (mAtmService.mGlobalLock) {
            mAtmService.mStackSupervisor.getActivityMetricsLogger().notifyStartingWindowDrawn(
                    getWindowingMode(), timestampNs);
        }
    }

    /**
    /**
     * Called when the key dispatching to a window associated with the app window container
     * Called when the key dispatching to a window associated with the app window container
     * timed-out.
     * timed-out.
+7 −7
Original line number Original line Diff line number Diff line
@@ -142,6 +142,7 @@ import com.android.internal.util.function.pooled.PooledConsumer;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.server.am.ActivityManagerService;
import com.android.server.am.ActivityManagerService;
import com.android.server.am.UserState;
import com.android.server.am.UserState;
import com.android.server.wm.ActivityMetricsLogger.LaunchingState;


import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.IOException;
@@ -443,8 +444,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
        mInitialized = true;
        mInitialized = true;
        setRunningTasks(new RunningTasks());
        setRunningTasks(new RunningTasks());


        mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext,
        mActivityMetricsLogger = new ActivityMetricsLogger(this, mHandler.getLooper());
                mHandler.getLooper());
        mKeyguardController = new KeyguardController(mService, this);
        mKeyguardController = new KeyguardController(mService, this);


        mPersisterQueue = new PersisterQueue();
        mPersisterQueue = new PersisterQueue();
@@ -576,8 +576,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
    }
    }


    void stopWaitingForActivityVisible(ActivityRecord r) {
    void stopWaitingForActivityVisible(ActivityRecord r) {
        stopWaitingForActivityVisible(r,
        stopWaitingForActivityVisible(r, getActivityMetricsLogger().getLastDrawnDelayMs(r));
                getActivityMetricsLogger().getLastDrawnDelayMs(r.getWindowingMode()));
    }
    }


    void stopWaitingForActivityVisible(ActivityRecord r, long totalTime) {
    void stopWaitingForActivityVisible(ActivityRecord r, long totalTime) {
@@ -2762,6 +2761,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {


                mRootActivityContainer.sendPowerHintForLaunchStartIfNeeded(
                mRootActivityContainer.sendPowerHintForLaunchStartIfNeeded(
                        true /* forceSend */, targetActivity);
                        true /* forceSend */, targetActivity);
                final LaunchingState launchingState =
                        mActivityMetricsLogger.notifyActivityLaunching(task.intent);
                        mActivityMetricsLogger.notifyActivityLaunching(task.intent);
                try {
                try {
                    mService.moveTaskToFrontLocked(null /* appThread */, null /* callingPackage */,
                    mService.moveTaskToFrontLocked(null /* appThread */, null /* callingPackage */,
@@ -2770,8 +2770,8 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
                    // the override pending app transition will be applied immediately.
                    // the override pending app transition will be applied immediately.
                    targetActivity.applyOptionsLocked();
                    targetActivity.applyOptionsLocked();
                } finally {
                } finally {
                    mActivityMetricsLogger.notifyActivityLaunched(START_TASK_TO_FRONT,
                    mActivityMetricsLogger.notifyActivityLaunched(launchingState,
                            targetActivity);
                            START_TASK_TO_FRONT, targetActivity);
                }
                }


                mService.getActivityStartController().postStartActivityProcessingForLastStarter(
                mService.getActivityStartController().postStartActivityProcessingForLastStarter(
+13 −5
Original line number Original line Diff line number Diff line
@@ -121,6 +121,7 @@ import com.android.internal.app.HeavyWeightSwitcherActivity;
import com.android.internal.app.IVoiceInteractor;
import com.android.internal.app.IVoiceInteractor;
import com.android.server.am.PendingIntentRecord;
import com.android.server.am.PendingIntentRecord;
import com.android.server.pm.InstantAppResolver;
import com.android.server.pm.InstantAppResolver;
import com.android.server.wm.ActivityMetricsLogger.LaunchingState;
import com.android.server.wm.ActivityStackSupervisor.PendingActivityLaunch;
import com.android.server.wm.ActivityStackSupervisor.PendingActivityLaunch;
import com.android.server.wm.LaunchParamsController.LaunchParams;
import com.android.server.wm.LaunchParamsController.LaunchParams;


@@ -572,15 +573,16 @@ class ActivityStarter {
            IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
            IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
            int startFlags, boolean doResume, ActivityOptions options, Task inTask) {
            int startFlags, boolean doResume, ActivityOptions options, Task inTask) {
        try {
        try {
            mSupervisor.getActivityMetricsLogger().notifyActivityLaunching(r.intent);
            final LaunchingState launchingState = mSupervisor.getActivityMetricsLogger()
                    .notifyActivityLaunching(r.intent, r.resultTo);
            mLastStartReason = "startResolvedActivity";
            mLastStartReason = "startResolvedActivity";
            mLastStartActivityTimeMs = System.currentTimeMillis();
            mLastStartActivityTimeMs = System.currentTimeMillis();
            mLastStartActivityRecord = r;
            mLastStartActivityRecord = r;
            mLastStartActivityResult = startActivityUnchecked(r, sourceRecord, voiceSession,
            mLastStartActivityResult = startActivityUnchecked(r, sourceRecord, voiceSession,
                    voiceInteractor, startFlags, doResume, options, inTask,
                    voiceInteractor, startFlags, doResume, options, inTask,
                    false /* restrictedBgActivity */);
                    false /* restrictedBgActivity */);
            mSupervisor.getActivityMetricsLogger().notifyActivityLaunched(mLastStartActivityResult,
            mSupervisor.getActivityMetricsLogger().notifyActivityLaunched(launchingState,
                    mLastStartActivityRecord);
                    mLastStartActivityResult, mLastStartActivityRecord);
        } finally {
        } finally {
            onExecutionComplete();
            onExecutionComplete();
        }
        }
@@ -598,8 +600,14 @@ class ActivityStarter {
                throw new IllegalArgumentException("File descriptors passed in Intent");
                throw new IllegalArgumentException("File descriptors passed in Intent");
            }
            }


            mSupervisor.getActivityMetricsLogger().notifyActivityLaunching(mRequest.intent);
            final LaunchingState launchingState;
            synchronized (mService.mGlobalLock) {
                final ActivityRecord caller = ActivityRecord.forTokenLocked(mRequest.resultTo);
                launchingState = mSupervisor.getActivityMetricsLogger().notifyActivityLaunching(
                        mRequest.intent, caller);
            }


            // Do not lock the resolving to avoid potential deadlock.
            if (mRequest.activityInfo == null) {
            if (mRequest.activityInfo == null) {
                mRequest.resolveActivity(mSupervisor);
                mRequest.resolveActivity(mSupervisor);
            }
            }
@@ -643,7 +651,7 @@ class ActivityStarter {
                // Notify ActivityMetricsLogger that the activity has launched.
                // Notify ActivityMetricsLogger that the activity has launched.
                // ActivityMetricsLogger will then wait for the windows to be drawn and populate
                // ActivityMetricsLogger will then wait for the windows to be drawn and populate
                // WaitResult.
                // WaitResult.
                mSupervisor.getActivityMetricsLogger().notifyActivityLaunched(res,
                mSupervisor.getActivityMetricsLogger().notifyActivityLaunched(launchingState, res,
                        mLastStartActivityRecord);
                        mLastStartActivityRecord);
                return getExternalResult(mRequest.waitResult == null ? res
                return getExternalResult(mRequest.waitResult == null ? res
                        : waitForResult(res, mLastStartActivityRecord));
                        : waitForResult(res, mLastStartActivityRecord));
+0 −13
Original line number Original line Diff line number Diff line
@@ -32,9 +32,7 @@ import android.content.res.CompatibilityInfo;
import android.os.Bundle;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SystemClock;
import android.service.voice.IVoiceInteractionSession;
import android.service.voice.IVoiceInteractionSession;
import android.util.SparseIntArray;
import android.util.proto.ProtoOutputStream;
import android.util.proto.ProtoOutputStream;


import com.android.internal.app.IVoiceInteractor;
import com.android.internal.app.IVoiceInteractor;
@@ -153,17 +151,6 @@ public abstract class ActivityTaskManagerInternal {
            IVoiceInteractionSession mSession,
            IVoiceInteractionSession mSession,
            IVoiceInteractor mInteractor);
            IVoiceInteractor mInteractor);


    /**
     * Callback for window manager to let activity manager know that we are finally starting the
     * app transition;
     *
     * @param reasons A map from windowing mode to a reason integer why the transition was started,
     *                which must be one of the APP_TRANSITION_* values.
     * @param timestampNs The time at which the app transition started in
     *                  {@link SystemClock#elapsedRealtimeNs()} ()} timebase.
     */
    public abstract void notifyAppTransitionStarting(SparseIntArray reasons, long timestampNs);

    /**
    /**
     * Callback for window manager to let activity manager know that the app transition was
     * Callback for window manager to let activity manager know that the app transition was
     * cancelled.
     * cancelled.
Loading