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

Commit 5e27aac3 authored by Shivangi Dubey's avatar Shivangi Dubey Committed by Android (Google) Code Review
Browse files

Merge "Add logging for ACTION_SWITCH_DISPLAY_FOLD" into main

parents ced5cb66 8f8a6ac1
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPOR
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_SMARTSPACE_DOORBELL;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_START_RECENTS_ANIMATION;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_SWITCH_DISPLAY_UNFOLD;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_SWITCH_DISPLAY_FOLD;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_TOGGLE_RECENTS;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_TURN_ON_SCREEN;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_UDFPS_ILLUMINATE;
@@ -311,6 +312,15 @@ public class LatencyTracker {
     */
    public static final int ACTION_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE = 33;

    /**
     * Time it takes to turn on the outer screen for a foldable device after fold.
     * <p>
     * Starts when the device is folded, signaled by device-state change event.
     * Ends when the outer screen is turned on, signaled by power interactor emitting SCREEN_ON
     * event.
     */
    public static final int ACTION_SWITCH_DISPLAY_FOLD = 34;

    private static final int[] ACTIONS_ALL = {
        ACTION_EXPAND_PANEL,
        ACTION_TOGGLE_RECENTS,
@@ -346,6 +356,7 @@ public class LatencyTracker {
        ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU,
        ACTION_DESKTOP_MODE_EXIT_MODE,
        ACTION_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE,
        ACTION_SWITCH_DISPLAY_FOLD,
    };

    /** @hide */
@@ -384,6 +395,7 @@ public class LatencyTracker {
        ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU,
        ACTION_DESKTOP_MODE_EXIT_MODE,
        ACTION_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE,
        ACTION_SWITCH_DISPLAY_FOLD,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Action {}
@@ -424,6 +436,7 @@ public class LatencyTracker {
            UIACTION_LATENCY_REPORTED__ACTION__ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU,
            UIACTION_LATENCY_REPORTED__ACTION__ACTION_DESKTOP_MODE_EXIT_MODE,
            UIACTION_LATENCY_REPORTED__ACTION__ACTION_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE,
            UIACTION_LATENCY_REPORTED__ACTION__ACTION_SWITCH_DISPLAY_FOLD,
    };

    private final Object mLock = new Object();
@@ -636,6 +649,8 @@ public class LatencyTracker {
                return "ACTION_DESKTOP_MODE_EXIT_MODE";
            case UIACTION_LATENCY_REPORTED__ACTION__ACTION_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE:
                return "ACTION_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE";
            case UIACTION_LATENCY_REPORTED__ACTION__ACTION_SWITCH_DISPLAY_FOLD:
                return "ACTION_SWITCH_DISPLAY_FOLD";
            default:
                throw new IllegalArgumentException("Invalid action");
        }
+113 −7
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.R
import com.android.internal.util.LatencyTracker
import com.android.internal.util.LatencyTracker.ACTION_SWITCH_DISPLAY_FOLD
import com.android.internal.util.LatencyTracker.ACTION_SWITCH_DISPLAY_UNFOLD
import com.android.systemui.SysuiTestCase
import com.android.systemui.deviceStateManager
@@ -228,7 +229,25 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
    }

    @Test
    fun unfoldingDevice_startsLatencyTracking() {
    fun foldToScreenOff_foldTrackingNotSent() {
        testScope.runTest {
            setDisplaySwitchState(Idle(HALF_FOLDED))
            isAodAvailable.emit(false)

            setDisplaySwitchState(Switching(HALF_FOLDED))

            powerInteractor.setAsleepForTest(sleepReason = GO_TO_SLEEP_REASON_DEVICE_FOLD)
            powerInteractor.setScreenPowerState(SCREEN_OFF)

            setDisplaySwitchState(Idle(FOLDED))

            verify(latencyTracker).onActionCancel(ACTION_SWITCH_DISPLAY_FOLD)
            verify(latencyTracker, never()).onActionEnd(ACTION_SWITCH_DISPLAY_FOLD)
        }
    }

    @Test
    fun unfoldingDevice_startsUnfoldLatencyTracking() {
        testScope.runTest {
            setDisplaySwitchState(Switching(HALF_FOLDED))

@@ -237,7 +256,18 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
    }

    @Test
    fun foldingDevice_doesntTrackLatency() {
    fun foldingDevice_startsFoldLatencyTracking() {
        testScope.runTest {
            setDisplaySwitchState(Idle(UNFOLDED))

            setDisplaySwitchState(Switching(FOLDED))

            verify(latencyTracker).onActionStart(ACTION_SWITCH_DISPLAY_FOLD)
        }
    }

    @Test
    fun foldingDevice_doesntTrackUnfoldLatency() {
        testScope.runTest {
            setDisplaySwitchState(Idle(UNFOLDED))

@@ -248,7 +278,16 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
    }

    @Test
    fun unfoldingDevice_endsLatencyWhenSwitchFinished() {
    fun unfoldingDevice_doesntTrackFoldLatency() {
        testScope.runTest {
            setDisplaySwitchState(Switching(HALF_FOLDED))

            verify(latencyTracker, never()).onActionStart(ACTION_SWITCH_DISPLAY_FOLD)
        }
    }

    @Test
    fun unfoldingDevice_endsUnfoldLatencyWhenSwitchFinished() {
        testScope.runTest {
            setDisplaySwitchState(Switching(HALF_FOLDED))

@@ -259,7 +298,20 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
    }

    @Test
    fun unfoldingDevice_doesntEndLatencyTrackingWhenSwitchNotFinished() {
    fun foldingDevice_endsFoldLatencyWhenSwitchFinished() {
        testScope.runTest {
            setDisplaySwitchState(Idle(HALF_FOLDED))

            setDisplaySwitchState(Switching(FOLDED))
            powerInteractor.setScreenPowerState(SCREEN_ON)
            setDisplaySwitchState(Idle(FOLDED))

            verify(latencyTracker).onActionEnd(ACTION_SWITCH_DISPLAY_FOLD)
        }
    }

    @Test
    fun unfoldingDevice_doesntEndUnfoldLatencyTrackingWhenSwitchNotFinished() {
        testScope.runTest {
            setDisplaySwitchState(Switching(HALF_FOLDED))

@@ -268,7 +320,18 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
    }

    @Test
    fun displaySwitchInterrupted_newDeviceState_trackingNotSent() {
    fun foldingDevice_doesntEndFoldLatencyTrackingWhenSwitchNotFinished() {
        testScope.runTest {
            setDisplaySwitchState(Idle(UNFOLDED))

            setDisplaySwitchState(Switching(FOLDED))

            verify(latencyTracker, never()).onActionEnd(ACTION_SWITCH_DISPLAY_UNFOLD)
        }
    }

    @Test
    fun displaySwitchInterrupted_newDeviceState_unfoldTrackingNotSent() {
        testScope.runTest {
            setDisplaySwitchState(Switching(HALF_FOLDED))

@@ -281,11 +344,26 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
    }

    @Test
    fun interruptedDisplaySwitchFinished_coolDownPassed_trackingWorksAsUsual() {
    fun displaySwitchInterrupted_newDeviceState_foldTrackingNotSent() {
        testScope.runTest {
            setDisplaySwitchState(Switching(HALF_FOLDED))

            setDisplaySwitchState(Corrupted(HALF_FOLDED))
            powerInteractor.setScreenPowerState(SCREEN_ON)
            setDisplaySwitchState(Idle(UNFOLDED))

            verify(latencyTracker).onActionCancel(ACTION_SWITCH_DISPLAY_FOLD)
            verify(latencyTracker, never()).onActionEnd(ACTION_SWITCH_DISPLAY_FOLD)
        }
    }

    @Test
    fun interruptedDisplaySwitchFinished_coolDownPassed_unfoldTrackingWorksAsUsual() {
        testScope.runTest {
            setDisplaySwitchState(Switching(HALF_FOLDED))
            setDisplaySwitchState(Corrupted(HALF_FOLDED))
            setDisplaySwitchState(Idle(FOLDED))
            powerInteractor.setScreenPowerState(SCREEN_ON)

            setDisplaySwitchState(Switching(HALF_FOLDED))
            setDisplaySwitchState(Idle(UNFOLDED))
@@ -295,6 +373,22 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
        }
    }

    @Test
    fun interruptedDisplaySwitchFinished_coolDownPassed_foldTrackingWorksAsUsual() {
        testScope.runTest {
            setDisplaySwitchState(Switching(FOLDED))
            setDisplaySwitchState(Corrupted(FOLDED))
            setDisplaySwitchState(Idle(UNFOLDED))

            setDisplaySwitchState(Switching(FOLDED))
            powerInteractor.setScreenPowerState(SCREEN_ON)
            setDisplaySwitchState(Idle(FOLDED))

            verify(latencyTracker, times(2)).onActionStart(ACTION_SWITCH_DISPLAY_FOLD)
            verify(latencyTracker).onActionEnd(ACTION_SWITCH_DISPLAY_FOLD)
        }
    }

    @Test
    fun interruptedDisplaySwitchFinished_coolDownPassed_eventWithCorruptedResultSent() {
        testScope.runTest {
@@ -312,7 +406,7 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
    }

    @Test
    fun displaySwitchTimedOut_trackingCancelled() {
    fun displaySwitchTimedOut_unfoldTrackingCancelled() {
        testScope.runTest {
            setDisplaySwitchState(Switching(HALF_FOLDED))

@@ -322,6 +416,18 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
        }
    }

    @Test
    fun displaySwitchTimedOut_foldTrackingCancelled() {
        testScope.runTest {
            setDisplaySwitchState(Switching(HALF_FOLDED))
            powerInteractor.setScreenPowerState(SCREEN_ON)

            setDisplaySwitchState(Idle(FOLDED, timedOut = true))

            verify(latencyTracker).onActionCancel(ACTION_SWITCH_DISPLAY_FOLD)
        }
    }

    @Test
    fun displaySwitchTimedOut_eventLoggedWithTimeOut() {
        testScope.runTest {
+16 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.hardware.devicestate.DeviceStateManager
import android.util.Log
import com.android.app.tracing.instantForTrack
import com.android.internal.util.LatencyTracker
import com.android.internal.util.LatencyTracker.ACTION_SWITCH_DISPLAY_FOLD
import com.android.internal.util.LatencyTracker.ACTION_SWITCH_DISPLAY_UNFOLD
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
@@ -79,7 +80,7 @@ constructor(
        scope.launch {
            displaySwitchInteractor.displaySwitchState
                .filter { it !is DisplaySwitchState.Unknown }
                .onEach(::startLatencyTrackingIfUnfolding)
                .onEach(::startLatencyTracking)
                .map(::toDisplaySwitchUpdate)
                // we need full chain of updates to create tracking event with possible options for
                // display switch chain:
@@ -98,20 +99,30 @@ constructor(
                    log { "new display switch states: $updatesChain " }
                    if (updatesChain.wasCorrupted || updatesChain.timedOut) {
                        latencyTracker.onActionCancel(ACTION_SWITCH_DISPLAY_UNFOLD)
                        latencyTracker.onActionCancel(ACTION_SWITCH_DISPLAY_FOLD)
                    } else {
                        latencyTracker.onActionEnd(ACTION_SWITCH_DISPLAY_UNFOLD)

                        if (getCurrentState()
                            != SysUiStatsLog.DISPLAY_SWITCH_LATENCY_TRACKED__TO_STATE__SCREEN_OFF
                        ) {
                            latencyTracker.onActionEnd(ACTION_SWITCH_DISPLAY_FOLD)
                        } else {
                            latencyTracker.onActionCancel(ACTION_SWITCH_DISPLAY_FOLD)
                        }
                    }
                    logDisplaySwitchEvent(updatesChain)
                }
        }
    }

    private fun startLatencyTrackingIfUnfolding(switchState: DisplaySwitchState) {
        val startedUnfolding =
            switchState is DisplaySwitchState.Switching &&
                switchState.newDeviceState != DeviceState.FOLDED
    private fun startLatencyTracking(switchState: DisplaySwitchState) {
        if (switchState !is DisplaySwitchState.Switching) return
        val startedUnfolding = switchState.newDeviceState != DeviceState.FOLDED
        if (startedUnfolding) {
            latencyTracker.onActionStart(ACTION_SWITCH_DISPLAY_UNFOLD)
        } else {
            latencyTracker.onActionStart(ACTION_SWITCH_DISPLAY_FOLD)
        }
    }