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

Commit d8099f60 authored by Bryce Lee's avatar Bryce Lee
Browse files

Trigger PowerManager setting update from DreamManager.

Currently, PowerManager relies on a broadcast receiver to be
notified when settings change. In a testing environment, this
can lead to inconsistent behavior as there is no guarantees
around the timing for receiving the broadcast.

This changelist informs PowerManager of a settings change when
screensaver enabled settings are changed from DreamManager.

Test: atest DreamServiceTest
Bug: 393270901
Flag: EXEMPT bugfix
Change-Id: I83cf24dc8fc70aab3e183ba9821b1c8162b6db8b
parent 91dbfc66
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -71,8 +71,11 @@ public class DreamManager {
    @TestApi
    @RequiresPermission(WRITE_SECURE_SETTINGS)
    public void setScreensaverEnabled(boolean enabled) {
        Settings.Secure.putIntForUser(mContext.getContentResolver(),
                Settings.Secure.SCREENSAVER_ENABLED, enabled ? 1 : 0, UserHandle.USER_CURRENT);
        try {
            mService.setScreensaverEnabled(enabled);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    /**
+5 −0
Original line number Diff line number Diff line
@@ -357,4 +357,9 @@ public abstract class PowerManagerInternal {
     * This may affect dream eligibility.
     */
    public abstract void setDevicePostured(boolean isPostured);

    /**
     * Notifies PowerManager that settings have changed and that it should refresh its state.
     */
    public abstract void updateSettings();
}
+2 −0
Original line number Diff line number Diff line
@@ -59,4 +59,6 @@ interface IDreamManager {
            float screenBrightnessFloat, int screenBrightnessInt,
            boolean useNormalBrightnessForDoze);
    oneway void finishSelfOneway(in IBinder token, boolean immediate);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)")
    void setScreensaverEnabled(boolean enabled);
}
+15 −0
Original line number Diff line number Diff line
@@ -1365,6 +1365,21 @@ public final class DreamManagerService extends SystemService {
            }
        }

        @Override
        public void setScreensaverEnabled(boolean enabled) {
            checkPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS);
            final UserHandle userHandle = getCallingUserHandle();
            final long ident = Binder.clearCallingIdentity();
            try {
                Settings.Secure.putIntForUser(mContext.getContentResolver(),
                        Settings.Secure.SCREENSAVER_ENABLED, enabled ? 1 : 0,
                        userHandle.getIdentifier());
                mPowerManagerInternal.updateSettings();
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }

        boolean canLaunchDreamActivity(String dreamPackageName, String packageName,
                int callingUid) {
            if (dreamPackageName == null || packageName == null) {
+7 −0
Original line number Diff line number Diff line
@@ -7441,6 +7441,13 @@ public final class PowerManagerService extends SystemService
        public void setDevicePostured(boolean isPostured) {
            setDevicePosturedInternal(isPostured);
        }

        @Override
        public void updateSettings() {
            synchronized (mLock) {
                updateSettingsLocked();
            }
        }
    }

    /**