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

Commit 8e30eb3a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix transition delay tracking when starting activity from recents" into nyc-dev

parents 0cb1cc74 1e630c08
Loading
Loading
Loading
Loading
+44 −1
Original line number Original line Diff line number Diff line
@@ -18,6 +18,8 @@ import android.util.Slog;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.internal.logging.MetricsProto.MetricsEvent;


import java.util.ArrayList;

/**
/**
 * Handles logging into Tron.
 * Handles logging into Tron.
 */
 */
@@ -98,6 +100,47 @@ class ActivityMetricsLogger {
        mCurrentTransitionStartTime = System.currentTimeMillis();
        mCurrentTransitionStartTime = System.currentTimeMillis();
    }
    }


    /**
     * Notifies the tracker that the activity is actually launching.
     *
     * @param resultCode one of the ActivityManager.START_* flags, indicating the result of the
     *                   launch
     * @param launchedActivity the activity that is being launched
     */
    void notifyActivityLaunched(int resultCode, ActivityRecord launchedActivity) {
        final ProcessRecord processRecord = launchedActivity != null
                ? mSupervisor.mService.mProcessNames.get(launchedActivity.processName,
                        launchedActivity.appInfo.uid)
                : null;
        final boolean processRunning = processRecord != null;
        final String componentName = launchedActivity != null
                ? launchedActivity.shortComponentName
                : null;

        // We consider this a "process switch" if the process of the activity that gets launched
        // didn't have an activity that was in started state. In this case, we assume that lot
        // of caches might be purged so the time until it produces the first frame is very
        // interesting.
        final boolean processSwitch = processRecord == null
                || !hasStartedActivity(processRecord, launchedActivity);

        notifyActivityLaunched(resultCode, componentName, processRunning, processSwitch);
    }

    private boolean hasStartedActivity(ProcessRecord record, ActivityRecord launchedActivity) {
        final ArrayList<ActivityRecord> activities = record.activities;
        for (int i = activities.size() - 1; i >= 0; i--) {
            final ActivityRecord activity = activities.get(i);
            if (launchedActivity == activity) {
                continue;
            }
            if (!activity.stopped) {
                return true;
            }
        }
        return false;
    }

    /**
    /**
     * Notifies the tracker the the activity is actually launching.
     * Notifies the tracker the the activity is actually launching.
     *
     *
@@ -109,7 +152,7 @@ class ActivityMetricsLogger {
     *                      activity that was stopped, i.e. the started activity is "switching"
     *                      activity that was stopped, i.e. the started activity is "switching"
     *                      processes
     *                      processes
     */
     */
    void notifyActivityLaunched(int resultCode, @Nullable String componentName,
    private void notifyActivityLaunched(int resultCode, @Nullable String componentName,
            boolean processRunning, boolean processSwitch) {
            boolean processRunning, boolean processSwitch) {


        if (resultCode < 0 || componentName == null || !processSwitch) {
        if (resultCode < 0 || componentName == null || !processSwitch) {
+2 −0
Original line number Original line Diff line number Diff line
@@ -4423,6 +4423,8 @@ public final class ActivityStackSupervisor implements DisplayListener {
                && task.getRootActivity() != null) {
                && task.getRootActivity() != null) {
            mActivityMetricsLogger.notifyActivityLaunching();
            mActivityMetricsLogger.notifyActivityLaunching();
            mService.moveTaskToFrontLocked(task.taskId, 0, bOptions);
            mService.moveTaskToFrontLocked(task.taskId, 0, bOptions);
            mActivityMetricsLogger.notifyActivityLaunched(ActivityManager.START_TASK_TO_FRONT,
                    task.getTopActivity());


            // If we are launching the task in the docked stack, put it into resizing mode so
            // If we are launching the task in the docked stack, put it into resizing mode so
            // the window renders full-screen with the background filling the void. Also only
            // the window renders full-screen with the background filling the void. Also only
+1 −30
Original line number Original line Diff line number Diff line
@@ -846,42 +846,13 @@ class ActivityStarter {
                }
                }
            }
            }


            final String componentName = outRecord[0] != null ? outRecord[0].shortComponentName
                    : null;
            final ActivityRecord launchedActivity = mReusedActivity != null
            final ActivityRecord launchedActivity = mReusedActivity != null
                    ? mReusedActivity : outRecord[0];
                    ? mReusedActivity : outRecord[0];
            final ProcessRecord processRecord = launchedActivity != null
            mSupervisor.mActivityMetricsLogger.notifyActivityLaunched(res, launchedActivity);
                    ? mService.mProcessNames.get(launchedActivity.processName,
                            launchedActivity.appInfo.uid)
                    : null;
            final boolean processRunning = processRecord != null;

            // We consider this a "process switch" if the process of the activity that gets launched
            // didn't have an activity that was in started state. In this case, we assume that lot
            // of caches might be purged so the time until it produces the first frame is very
            // interesting.
            final boolean processSwitch = processRecord == null
                    || !hasStartedActivity(processRecord, launchedActivity);
            mSupervisor.mActivityMetricsLogger.notifyActivityLaunched(res, componentName,
                    processRunning, processSwitch);
            return res;
            return res;
        }
        }
    }
    }


    final boolean hasStartedActivity(ProcessRecord record, ActivityRecord launchedActivity) {
        final ArrayList<ActivityRecord> activities = record.activities;
        for (int i = activities.size() - 1; i >= 0; i--) {
            final ActivityRecord activity = activities.get(i);
            if (launchedActivity == activity) {
                continue;
            }
            if (!activity.stopped) {
                return true;
            }
        }
        return false;
    }

    final int startActivities(IApplicationThread caller, int callingUid, String callingPackage,
    final int startActivities(IApplicationThread caller, int callingUid, String callingPackage,
            Intent[] intents, String[] resolvedTypes, IBinder resultTo,
            Intent[] intents, String[] resolvedTypes, IBinder resultTo,
            Bundle bOptions, int userId) {
            Bundle bOptions, int userId) {