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

Commit e2b2d5aa authored by Eric Jeong's avatar Eric Jeong Committed by Android (Google) Code Review
Browse files

Merge "Make auto-suspend configurable" into main

parents 73ce8b4c b0a52632
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -7038,4 +7038,7 @@
         If the gesture is completed faster than this, we assume it's not performed by human and the
         event gets ignored. -->
    <integer name="config_defaultMinEmergencyGestureTapDurationMillis">200</integer>

    <!-- Whether the system uses auto-suspend mode. -->
    <bool name="config_useAutoSuspend">true</bool>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -5424,4 +5424,7 @@
  <!-- Back swipe thresholds -->
  <java-symbol type="dimen" name="navigation_edge_action_progress_threshold" />
  <java-symbol type="dimen" name="back_progress_non_linear_factor" />

  <!-- For PowerManagerService to determine whether to use auto-suspend mode -->
  <java-symbol type="bool" name="config_useAutoSuspend" />
</resources>
+10 −0
Original line number Diff line number Diff line
@@ -444,6 +444,9 @@ public final class PowerManagerService extends SystemService
    // Refer to autosuspend.h.
    private boolean mHalAutoSuspendModeEnabled;

    // True if the device uses auto-suspend mode.
    private final boolean mUseAutoSuspend;

    // True if interactive mode is enabled.
    // Refer to power.h.
    private boolean mHalInteractiveModeEnabled;
@@ -1203,6 +1206,9 @@ public final class PowerManagerService extends SystemService

        mPowerGroupWakefulnessChangeListener = new PowerGroupWakefulnessChangeListener();

        mUseAutoSuspend = mContext.getResources().getBoolean(com.android.internal.R.bool
                .config_useAutoSuspend);

        // Save brightness values:
        // Get float values from config.
        // Store float if valid
@@ -3918,6 +3924,9 @@ public final class PowerManagerService extends SystemService

    @GuardedBy("mLock")
    private void setHalAutoSuspendModeLocked(boolean enable) {
        if (!mUseAutoSuspend) {
            return;
        }
        if (enable != mHalAutoSuspendModeEnabled) {
            if (DEBUG) {
                Slog.d(TAG, "Setting HAL auto-suspend mode to " + enable);
@@ -4661,6 +4670,7 @@ public final class PowerManagerService extends SystemService
                pw.println("  mEnhancedDischargePredictionIsPersonalized="
                        + mEnhancedDischargePredictionIsPersonalized);
            }
            pw.println("  mUseAutoSuspend=" + mUseAutoSuspend);
            pw.println("  mHalAutoSuspendModeEnabled=" + mHalAutoSuspendModeEnabled);
            pw.println("  mHalInteractiveModeEnabled=" + mHalInteractiveModeEnabled);
            pw.println("  mWakeLockSummary=0x" + Integer.toHexString(mWakeLockSummary));
+42 −0
Original line number Diff line number Diff line
@@ -3241,6 +3241,48 @@ public class PowerManagerServiceTest {
        }
    }

    @Test
    public void testHalAutoSuspendMode_enabledByConfiguration() {
        AtomicReference<DisplayManagerInternal.DisplayPowerCallbacks> callback =
                new AtomicReference<>();
        doAnswer((Answer<Void>) invocation -> {
            callback.set(invocation.getArgument(0));
            return null;
        }).when(mDisplayManagerInternalMock).initPowerManagement(any(), any(), any());
        when(mResourcesSpy.getBoolean(
                com.android.internal.R.bool.config_powerDecoupleAutoSuspendModeFromDisplay))
                .thenReturn(false);
        when(mResourcesSpy.getBoolean(com.android.internal.R.bool.config_useAutoSuspend))
                .thenReturn(true);

        createService();
        startSystem();
        callback.get().onDisplayStateChange(/* allInactive= */ true, /* allOff= */ true);

        verify(mNativeWrapperMock).nativeSetAutoSuspend(true);
    }

    @Test
    public void testHalAutoSuspendMode_disabledByConfiguration() {
        AtomicReference<DisplayManagerInternal.DisplayPowerCallbacks> callback =
                new AtomicReference<>();
        doAnswer((Answer<Void>) invocation -> {
            callback.set(invocation.getArgument(0));
            return null;
        }).when(mDisplayManagerInternalMock).initPowerManagement(any(), any(), any());
        when(mResourcesSpy.getBoolean(
                com.android.internal.R.bool.config_powerDecoupleAutoSuspendModeFromDisplay))
                .thenReturn(false);
        when(mResourcesSpy.getBoolean(com.android.internal.R.bool.config_useAutoSuspend))
                .thenReturn(false);

        createService();
        startSystem();
        callback.get().onDisplayStateChange(/* allInactive= */ true, /* allOff= */ true);

        verify(mNativeWrapperMock, never()).nativeSetAutoSuspend(true);
    }

    private void setCachedUidProcState(int uid) {
        mService.updateUidProcStateInternal(uid, PROCESS_STATE_TOP_SLEEPING);
    }