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

Commit 8a77c25f authored by Antony Sargent's avatar Antony Sargent Committed by Automerger Merge Worker
Browse files

Merge "Fix problem with AOD when secondary power groups are awake" into...

Merge "Fix problem with AOD when secondary power groups are awake" into udc-dev am: 6fbe5c11 am: cca91b17

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22923176



Change-Id: I6ef00767f68a9dd4f90d72da65c89ed9f131417f
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents cb24b4a4 cca91b17
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -55,6 +55,7 @@ interface IPowerManager
    float getBrightnessConstraint(int constraint);
    float getBrightnessConstraint(int constraint);
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    boolean isInteractive();
    boolean isInteractive();
    boolean isDisplayInteractive(int displayId);
    boolean areAutoPowerSaveModesEnabled();
    boolean areAutoPowerSaveModesEnabled();
    boolean isPowerSaveMode();
    boolean isPowerSaveMode();
    PowerSaveState getPowerSaveState(int serviceType);
    PowerSaveState getPowerSaveState(int serviceType);
+20 −4
Original line number Original line Diff line number Diff line
@@ -1150,13 +1150,17 @@ public final class PowerManager {
                }
                }
            };
            };


    private final PropertyInvalidatedCache<Void, Boolean> mInteractiveCache =
    private final PropertyInvalidatedCache<Integer, Boolean> mInteractiveCache =
            new PropertyInvalidatedCache<Void, Boolean>(MAX_CACHE_ENTRIES,
            new PropertyInvalidatedCache<Integer, Boolean>(MAX_CACHE_ENTRIES,
                CACHE_KEY_IS_INTERACTIVE_PROPERTY) {
                CACHE_KEY_IS_INTERACTIVE_PROPERTY) {
                @Override
                @Override
                public Boolean recompute(Void query) {
                public Boolean recompute(Integer displayId) {
                    try {
                    try {
                        if (displayId == null) {
                            return mService.isInteractive();
                            return mService.isInteractive();
                        } else {
                            return mService.isDisplayInteractive(displayId);
                        }
                    } catch (RemoteException e) {
                    } catch (RemoteException e) {
                        throw e.rethrowFromSystemServer();
                        throw e.rethrowFromSystemServer();
                    }
                    }
@@ -1802,6 +1806,18 @@ public final class PowerManager {
        return mInteractiveCache.query(null);
        return mInteractiveCache.query(null);
    }
    }


    /**
     * Returns the interactive state for a specific display, which may not be the same as the
     * global wakefulness (which is true when any display is awake).
     *
     * @param displayId
     * @return whether the given display is present and interactive, or false
     *
     * @hide
     */
    public boolean isInteractive(int displayId) {
        return mInteractiveCache.query(displayId);
    }


    /**
    /**
     * Returns {@code true} if this device supports rebooting userspace.
     * Returns {@code true} if this device supports rebooting userspace.
+2 −1
Original line number Original line Diff line number Diff line
@@ -8,6 +8,7 @@ import android.database.ContentObserver
import android.os.Handler
import android.os.Handler
import android.os.PowerManager
import android.os.PowerManager
import android.provider.Settings
import android.provider.Settings
import android.view.Display
import android.view.Surface
import android.view.Surface
import android.view.View
import android.view.View
import android.view.WindowManager.fixScale
import android.view.WindowManager.fixScale
@@ -272,7 +273,7 @@ class UnlockedScreenOffAnimationController @Inject constructor(
                // dispatched, a race condition could make it possible for this callback to be run
                // dispatched, a race condition could make it possible for this callback to be run
                // as the device is waking up. That results in the AOD UI being shown while we wake
                // as the device is waking up. That results in the AOD UI being shown while we wake
                // up, with unpredictable consequences.
                // up, with unpredictable consequences.
                if (!powerManager.isInteractive) {
                if (!powerManager.isInteractive(Display.DEFAULT_DISPLAY)) {
                    aodUiAnimationPlaying = true
                    aodUiAnimationPlaying = true


                    // Show AOD. That'll cause the KeyguardVisibilityHelper to call
                    // Show AOD. That'll cause the KeyguardVisibilityHelper to call
+18 −1
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.os.Handler
import android.os.PowerManager
import android.os.PowerManager
import android.testing.AndroidTestingRunner
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper.RunWithLooper
import android.testing.TestableLooper.RunWithLooper
import android.view.Display
import androidx.test.filters.SmallTest
import androidx.test.filters.SmallTest
import com.android.internal.jank.InteractionJankMonitor
import com.android.internal.jank.InteractionJankMonitor
import com.android.systemui.SysuiTestCase
import com.android.systemui.SysuiTestCase
@@ -29,6 +30,7 @@ import com.android.systemui.shade.ShadeViewController
import com.android.systemui.statusbar.LightRevealScrim
import com.android.systemui.statusbar.LightRevealScrim
import com.android.systemui.statusbar.StatusBarStateControllerImpl
import com.android.systemui.statusbar.StatusBarStateControllerImpl
import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.settings.GlobalSettings
import com.android.systemui.util.settings.GlobalSettings
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertFalse
import org.junit.After
import org.junit.After
@@ -141,7 +143,7 @@ class UnlockedScreenOffAnimationControllerTest : SysuiTestCase() {
    @Test
    @Test
    fun testAodUiNotShownIfInteractive() {
    fun testAodUiNotShownIfInteractive() {
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
        `when`(powerManager.isInteractive).thenReturn(true)
        `when`(powerManager.isInteractive(eq(Display.DEFAULT_DISPLAY))).thenReturn(true)


        val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
        val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
        controller.startAnimation()
        controller.startAnimation()
@@ -152,6 +154,21 @@ class UnlockedScreenOffAnimationControllerTest : SysuiTestCase() {
        verify(shadeViewController, never()).showAodUi()
        verify(shadeViewController, never()).showAodUi()
    }
    }


    @Test
    fun testAodUiShownIfGloballyInteractiveButDefaultDisplayNotInteractive() {
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
        `when`(powerManager.isInteractive()).thenReturn(false)
        `when`(powerManager.isInteractive(eq(Display.DEFAULT_DISPLAY))).thenReturn(false)

        val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
        controller.startAnimation()

        verify(handler).postDelayed(callbackCaptor.capture(), anyLong())
        callbackCaptor.value.run()

        verify(shadeViewController).showAodUi()
    }

    @Test
    @Test
    fun testNoAnimationPlaying_dozeParamsCanNotControlScreenOff() {
    fun testNoAnimationPlaying_dozeParamsCanNotControlScreenOff() {
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(false)
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(false)
+34 −2
Original line number Original line Diff line number Diff line
@@ -2079,6 +2079,7 @@ public final class PowerManagerService extends SystemService
            int opUid, String opPackageName, String details) {
            int opUid, String opPackageName, String details) {
        mPowerGroups.get(groupId).setWakefulnessLocked(wakefulness, eventTime, uid, reason, opUid,
        mPowerGroups.get(groupId).setWakefulnessLocked(wakefulness, eventTime, uid, reason, opUid,
                opPackageName, details);
                opPackageName, details);
        mInjector.invalidateIsInteractiveCaches();
    }
    }


    @SuppressWarnings("deprecation")
    @SuppressWarnings("deprecation")
@@ -3743,12 +3744,32 @@ public final class PowerManagerService extends SystemService
        }
        }
    }
    }


    private boolean isInteractiveInternal() {
    private boolean isGloballyInteractiveInternal() {
        synchronized (mLock) {
        synchronized (mLock) {
            return PowerManagerInternal.isInteractive(getGlobalWakefulnessLocked());
            return PowerManagerInternal.isInteractive(getGlobalWakefulnessLocked());
        }
        }
    }
    }


    private boolean isInteractiveInternal(int displayId, int uid) {
        synchronized (mLock) {
            DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(displayId);
            if (displayInfo == null) {
                Slog.w(TAG, "Did not find DisplayInfo for displayId " + displayId);
                return false;
            }
            if (!displayInfo.hasAccess(uid)) {
                throw new SecurityException(
                        "uid " + uid + " does not have access to display " + displayId);
            }
            PowerGroup powerGroup = mPowerGroups.get(displayInfo.displayGroupId);
            if (powerGroup == null) {
                Slog.w(TAG, "Did not find PowerGroup for displayId " + displayId);
                return false;
            }
            return PowerManagerInternal.isInteractive(powerGroup.getWakefulnessLocked());
        }
    }

    private boolean setLowPowerModeInternal(boolean enabled) {
    private boolean setLowPowerModeInternal(boolean enabled) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DEBUG) {
            if (DEBUG) {
@@ -5805,7 +5826,18 @@ public final class PowerManagerService extends SystemService
        public boolean isInteractive() {
        public boolean isInteractive() {
            final long ident = Binder.clearCallingIdentity();
            final long ident = Binder.clearCallingIdentity();
            try {
            try {
                return isInteractiveInternal();
                return isGloballyInteractiveInternal();
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }

        @Override // Binder call
        public boolean isDisplayInteractive(int displayId) {
            int uid = Binder.getCallingUid();
            final long ident = Binder.clearCallingIdentity();
            try {
                return isInteractiveInternal(displayId, uid);
            } finally {
            } finally {
                Binder.restoreCallingIdentity(ident);
                Binder.restoreCallingIdentity(ident);
            }
            }
Loading