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

Commit 3f3932fa authored by Yisroel Forta's avatar Yisroel Forta
Browse files

Modify AppStartInfo logic for setting state

Now that first frame drawn timestamp is being reported, use this to determine
done state rather than onActivityFinished which is prior to first frame drawn.
This ensures that timestamps will all be added, as well as that the callback
will occur on a fully complete with timestmaps object.

Bug: 338125667
Test: manually check timestamps and state for various starts
Flag: android.app.app_start_info_timestamps
Change-Id: I889345bb1120273d1d6e6f86848dd12f789da721
parent 59fd0f3c
Loading
Loading
Loading
Loading
+28 −7
Original line number Diff line number Diff line
@@ -294,11 +294,13 @@ public final class AppStartInfoTracker {
                mInProgRecords.removeAt(index);
                return;
            }
            info.setStartupState(ApplicationStartInfo.STARTUP_STATE_FIRST_FRAME_DRAWN);
            info.setLaunchMode(launchMode);
            if (!android.app.Flags.appStartInfoTimestamps()) {
                info.setStartupState(ApplicationStartInfo.STARTUP_STATE_FIRST_FRAME_DRAWN);
                checkCompletenessAndCallback(info);
            }
        }
    }

    void onReportFullyDrawn(long id, long timestampNanos) {
        synchronized (mLock) {
@@ -539,9 +541,9 @@ public final class AppStartInfoTracker {
    }

    /**
     * Called whenever data is added to a {@link ApplicationStartInfo} object. Checks for
     * completeness and triggers callback if a callback has been registered and the object
     * is complete.
     * Called whenever a potentially final piece of data is added to a {@link ApplicationStartInfo}
     * object. Checks for completeness and triggers callback if a callback has been registered and
     * the object is complete.
     */
    private void checkCompletenessAndCallback(ApplicationStartInfo startInfo) {
        synchronized (mLock) {
@@ -1124,10 +1126,23 @@ public final class AppStartInfoTracker {
                    Long.compare(getStartTimestamp(b), getStartTimestamp(a)));
        }

        /**
         * Add the provided key/timestamp to the most recent start record, if it is currently
         * accepting new timestamps.
         *
         * Will also update the start records startup state and trigger the completion listener when
         * appropriate.
         */
        @GuardedBy("mLock")
        void addTimestampToStartLocked(int key, long timestampNs) {
            if (mInfos.isEmpty()) {
                if (DEBUG) Slog.d(TAG, "No records to add to.");
                return;
            }

            // Records are sorted newest to oldest, grab record at index 0.
            int startupState = mInfos.get(0).getStartupState();
            ApplicationStartInfo startInfo = mInfos.get(0);
            int startupState = startInfo.getStartupState();

            // If startup state is error then don't accept any further timestamps.
            if (startupState == ApplicationStartInfo.STARTUP_STATE_ERROR) {
@@ -1145,7 +1160,13 @@ public final class AppStartInfoTracker {
                return;
            }

            mInfos.get(0).addStartupTimestamp(key, timestampNs);
            startInfo.addStartupTimestamp(key, timestampNs);

            if (key == ApplicationStartInfo.START_TIMESTAMP_FIRST_FRAME
                    && android.app.Flags.appStartInfoTimestamps()) {
                startInfo.setStartupState(ApplicationStartInfo.STARTUP_STATE_FIRST_FRAME_DRAWN);
                checkCompletenessAndCallback(startInfo);
            }
        }

        @GuardedBy("mLock")