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

Commit 5e0e7796 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Consolidate mDrawn and reportedDrawn

These states mean the same thing. It was left over from merging
ActivityRecord and AppWindowToken.

Bug: 163976519
Test: WmTests
Change-Id: I4c92d293c61c9863b9f5d71874551d45a9e2cc2d
parent 393fe8b1
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -542,7 +542,7 @@ class ActivityMetricsLogger {
                    + " processSwitch=" + processSwitch + " info=" + info);
                    + " processSwitch=" + processSwitch + " info=" + info);
        }
        }


        if (launchedActivity.mDrawn) {
        if (launchedActivity.isReportedDrawn()) {
            // Launched activity is already visible. We cannot measure windows drawn delay.
            // Launched activity is already visible. We cannot measure windows drawn delay.
            abort(info, "launched activity already visible");
            abort(info, "launched activity already visible");
            return;
            return;
@@ -681,7 +681,7 @@ class ActivityMetricsLogger {


    /** @return {@code true} if the given task has an activity will be drawn. */
    /** @return {@code true} if the given task has an activity will be drawn. */
    private static boolean hasActivityToBeDrawn(Task t) {
    private static boolean hasActivityToBeDrawn(Task t) {
        return t.forAllActivities((r) -> r.mVisibleRequested && !r.mDrawn && !r.finishing);
        return t.forAllActivities(r -> r.mVisibleRequested && !r.isReportedDrawn() && !r.finishing);
    }
    }


    private void checkVisibility(Task t, ActivityRecord r) {
    private void checkVisibility(Task t, ActivityRecord r) {
+15 −15
Original line number Original line Diff line number Diff line
@@ -499,7 +499,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                                           // and reporting to the client that it is hidden.
                                           // and reporting to the client that it is hidden.
    private boolean mSetToSleep; // have we told the activity to sleep?
    private boolean mSetToSleep; // have we told the activity to sleep?
    boolean nowVisible;     // is this activity's window visible?
    boolean nowVisible;     // is this activity's window visible?
    boolean mDrawn;          // is this activity's window drawn?
    boolean mClientVisibilityDeferred;// was the visibility change message to client deferred?
    boolean mClientVisibilityDeferred;// was the visibility change message to client deferred?
    boolean idle;           // has the activity gone idle?
    boolean idle;           // has the activity gone idle?
    boolean hasBeenLaunched;// has this activity ever been launched?
    boolean hasBeenLaunched;// has this activity ever been launched?
@@ -564,8 +563,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    private boolean mClientVisible;
    private boolean mClientVisible;


    boolean firstWindowDrawn;
    boolean firstWindowDrawn;
    // Last drawn state we reported to the app token.
    /** Whether the visible window(s) of this activity is drawn. */
    private boolean reportedDrawn;
    private boolean mReportedDrawn;
    private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
    private final WindowState.UpdateReportedVisibilityResults mReportedVisibilityResults =
            new WindowState.UpdateReportedVisibilityResults();
            new WindowState.UpdateReportedVisibilityResults();


@@ -927,7 +926,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        pw.println(prefix + "mVisibleRequested=" + mVisibleRequested
        pw.println(prefix + "mVisibleRequested=" + mVisibleRequested
                + " mVisible=" + mVisible + " mClientVisible=" + mClientVisible
                + " mVisible=" + mVisible + " mClientVisible=" + mClientVisible
                + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
                + ((mDeferHidingClient) ? " mDeferHidingClient=" + mDeferHidingClient : "")
                + " reportedDrawn=" + reportedDrawn + " reportedVisible=" + reportedVisible);
                + " reportedDrawn=" + mReportedDrawn + " reportedVisible=" + reportedVisible);
        if (paused) {
        if (paused) {
            pw.print(prefix); pw.print("paused="); pw.println(paused);
            pw.print(prefix); pw.print("paused="); pw.println(paused);
        }
        }
@@ -1591,7 +1590,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        keysPaused = false;
        keysPaused = false;
        inHistory = false;
        inHistory = false;
        nowVisible = false;
        nowVisible = false;
        mDrawn = false;
        mClientVisible = true;
        mClientVisible = true;
        idle = false;
        idle = false;
        hasBeenLaunched = false;
        hasBeenLaunched = false;
@@ -5404,11 +5402,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
    }
    }


    /** Called when the windows associated app window container are drawn. */
    /** Called when the windows associated app window container are drawn. */
    void onWindowsDrawn(boolean drawn, long timestampNs) {
    private void onWindowsDrawn(long timestampNs) {
        mDrawn = drawn;
        if (!drawn) {
            return;
        }
        final TransitionInfoSnapshot info = mStackSupervisor
        final TransitionInfoSnapshot info = mStackSupervisor
                .getActivityMetricsLogger().notifyWindowsDrawn(this, timestampNs);
                .getActivityMetricsLogger().notifyWindowsDrawn(this, timestampNs);
        final boolean validInfo = info != null;
        final boolean validInfo = info != null;
@@ -5514,7 +5508,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (!nowGone) {
        if (!nowGone) {
            // If the app is not yet gone, then it can only become visible/drawn.
            // If the app is not yet gone, then it can only become visible/drawn.
            if (!nowDrawn) {
            if (!nowDrawn) {
                nowDrawn = reportedDrawn;
                nowDrawn = mReportedDrawn;
            }
            }
            if (!nowVisible) {
            if (!nowVisible) {
                nowVisible = reportedVisible;
                nowVisible = reportedVisible;
@@ -5522,9 +5516,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        }
        if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
        if (DEBUG_VISIBILITY) Slog.v(TAG, "VIS " + this + ": interesting="
                + numInteresting + " visible=" + numVisible);
                + numInteresting + " visible=" + numVisible);
        if (nowDrawn != reportedDrawn) {
        if (nowDrawn != mReportedDrawn) {
            onWindowsDrawn(nowDrawn, SystemClock.elapsedRealtimeNanos());
            if (nowDrawn) {
            reportedDrawn = nowDrawn;
                onWindowsDrawn(SystemClock.elapsedRealtimeNanos());
            }
            mReportedDrawn = nowDrawn;
        }
        }
        if (nowVisible != reportedVisible) {
        if (nowVisible != reportedVisible) {
            if (DEBUG_VISIBILITY) Slog.v(TAG,
            if (DEBUG_VISIBILITY) Slog.v(TAG,
@@ -5538,6 +5534,10 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        }
    }
    }


    boolean isReportedDrawn() {
        return mReportedDrawn;
    }

    boolean isClientVisible() {
    boolean isClientVisible() {
        return mClientVisible;
        return mClientVisible;
    }
    }
@@ -7677,7 +7677,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        proto.write(VISIBLE_REQUESTED, mVisibleRequested);
        proto.write(VISIBLE_REQUESTED, mVisibleRequested);
        proto.write(CLIENT_VISIBLE, mClientVisible);
        proto.write(CLIENT_VISIBLE, mClientVisible);
        proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
        proto.write(DEFER_HIDING_CLIENT, mDeferHidingClient);
        proto.write(REPORTED_DRAWN, reportedDrawn);
        proto.write(REPORTED_DRAWN, mReportedDrawn);
        proto.write(REPORTED_VISIBLE, reportedVisible);
        proto.write(REPORTED_VISIBLE, reportedVisible);
        proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
        proto.write(NUM_INTERESTING_WINDOWS, mNumInterestingWindows);
        proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
        proto.write(NUM_DRAWN_WINDOWS, mNumDrawnWindows);
+6 −6
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.ActivityManager.START_SUCCESS;
import static android.app.ActivityManager.START_TASK_TO_FRONT;
import static android.app.ActivityManager.START_TASK_TO_FRONT;
import static android.content.ComponentName.createRelative;
import static android.content.ComponentName.createRelative;


import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyNoMoreInteractions;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyNoMoreInteractions;
@@ -176,7 +177,8 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase {
    public void testOnActivityLaunchCancelled_hasDrawn() {
    public void testOnActivityLaunchCancelled_hasDrawn() {
        onActivityLaunched(mTopActivity);
        onActivityLaunched(mTopActivity);


        mTopActivity.mVisibleRequested = mTopActivity.mDrawn = true;
        mTopActivity.mVisibleRequested = true;
        doReturn(true).when(mTopActivity).isReportedDrawn();


        // Cannot time already-visible activities.
        // Cannot time already-visible activities.
        notifyActivityLaunched(START_TASK_TO_FRONT, mTopActivity);
        notifyActivityLaunched(START_TASK_TO_FRONT, mTopActivity);
@@ -187,16 +189,14 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase {


    @Test
    @Test
    public void testOnActivityLaunchCancelled_finishedBeforeDrawn() {
    public void testOnActivityLaunchCancelled_finishedBeforeDrawn() {
        mTopActivity.mVisibleRequested = mTopActivity.mDrawn = true;
        mTopActivity.mVisibleRequested = true;
        doReturn(true).when(mTopActivity).isReportedDrawn();


        // Suppress resume when creating the record because we want to notify logger manually.
        mSupervisor.beginDeferResume();
        // Create an activity with different process that meets process switch.
        // Create an activity with different process that meets process switch.
        final ActivityRecord noDrawnActivity = new ActivityBuilder(mAtm)
        final ActivityRecord noDrawnActivity = new ActivityBuilder(mAtm)
                .setTask(mTopActivity.getTask())
                .setTask(mTopActivity.getTask())
                .setProcessName("other")
                .setProcessName("other")
                .build();
                .build();
        mSupervisor.readyToResume();


        notifyActivityLaunching(noDrawnActivity.intent);
        notifyActivityLaunching(noDrawnActivity.intent);
        notifyActivityLaunched(START_SUCCESS, noDrawnActivity);
        notifyActivityLaunched(START_SUCCESS, noDrawnActivity);
@@ -294,7 +294,7 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase {
    public void testOnActivityLaunchCancelledTrampoline() {
    public void testOnActivityLaunchCancelledTrampoline() {
        onActivityLaunchedTrampoline();
        onActivityLaunchedTrampoline();


        mTopActivity.mDrawn = true;
        doReturn(true).when(mTopActivity).isReportedDrawn();


        // Cannot time already-visible activities.
        // Cannot time already-visible activities.
        notifyActivityLaunched(START_TASK_TO_FRONT, mTopActivity);
        notifyActivityLaunched(START_TASK_TO_FRONT, mTopActivity);