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

Commit 2a92e01a authored by Lucas Silva's avatar Lucas Silva Committed by Automerger Merge Worker
Browse files

Merge "Add internal API to PowerManager which allows napping when device is...

Merge "Add internal API to PowerManager which allows napping when device is asleep." into tm-qpr-dev am: a13bb162 am: 0ddce51c

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



Change-Id: Id7223aa20f51f153e5950060dd7f52a6d771dc2c
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 2929ce45 0ddce51c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -335,4 +335,10 @@ public abstract class PowerManagerInternal {

    /** Allows power button to intercept a power key button press. */
    public abstract boolean interceptPowerKeyDown(KeyEvent event);

    /**
     * Internal version of {@link android.os.PowerManager#nap} which allows for napping while the
     * device is not awake.
     */
    public abstract void nap(long eventTime, boolean allowWake);
}
+3 −3
Original line number Diff line number Diff line
@@ -246,8 +246,8 @@ public final class DreamManagerService extends SystemService {
        // Because napping could cause the screen to turn off immediately if the dream
        // cannot be started, we keep one eye open and gently poke user activity.
        long time = SystemClock.uptimeMillis();
        mPowerManager.userActivity(time, true /*noChangeLights*/);
        mPowerManager.nap(time);
        mPowerManager.userActivity(time, /* noChangeLights= */ true);
        mPowerManagerInternal.nap(time, /* allowWake= */ true);
    }

    private void requestAwakenInternal(String reason) {
@@ -637,7 +637,7 @@ public final class DreamManagerService extends SystemService {
                @Nullable FileDescriptor err,
                @NonNull String[] args, @Nullable ShellCallback callback,
                @NonNull ResultReceiver resultReceiver) throws RemoteException {
            new DreamShellCommand(DreamManagerService.this, mPowerManager)
            new DreamShellCommand(DreamManagerService.this)
                    .exec(this, in, out, err, args, callback, resultReceiver);
        }

+1 −7
Original line number Diff line number Diff line
@@ -18,10 +18,8 @@ package com.android.server.dreams;

import android.annotation.NonNull;
import android.os.Binder;
import android.os.PowerManager;
import android.os.Process;
import android.os.ShellCommand;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Slog;

@@ -34,11 +32,9 @@ public class DreamShellCommand extends ShellCommand {
    private static final boolean DEBUG = true;
    private static final String TAG = "DreamShellCommand";
    private final @NonNull DreamManagerService mService;
    private final @NonNull PowerManager mPowerManager;

    DreamShellCommand(@NonNull DreamManagerService service, @NonNull PowerManager powerManager) {
    DreamShellCommand(@NonNull DreamManagerService service) {
        mService = service;
        mPowerManager = powerManager;
    }

    @Override
@@ -67,8 +63,6 @@ public class DreamShellCommand extends ShellCommand {
    }

    private int startDreaming() {
        mPowerManager.wakeUp(SystemClock.uptimeMillis(),
                PowerManager.WAKE_REASON_PLUGGED_IN, "shell:cmd:android.service.dreams:DREAM");
        mService.requestStartDreamFromShell();
        return 0;
    }
+2 −2
Original line number Diff line number Diff line
@@ -229,8 +229,8 @@ public class PowerGroup {
        }
    }

    boolean dreamLocked(long eventTime, int uid) {
        if (eventTime < mLastWakeTime || mWakefulness != WAKEFULNESS_AWAKE) {
    boolean dreamLocked(long eventTime, int uid, boolean allowWake) {
        if (eventTime < mLastWakeTime || (!allowWake && mWakefulness != WAKEFULNESS_AWAKE)) {
            return false;
        }

+18 −7
Original line number Diff line number Diff line
@@ -1973,6 +1973,13 @@ public final class PowerManagerService extends SystemService
        }
    }

    private void napInternal(long eventTime, int uid, boolean allowWake) {
        synchronized (mLock) {
            dreamPowerGroupLocked(mPowerGroups.get(Display.DEFAULT_DISPLAY_GROUP),
                    eventTime, uid, allowWake);
        }
    }

    private void onUserAttention() {
        synchronized (mLock) {
            if (userActivityNoUpdateLocked(mPowerGroups.get(Display.DEFAULT_DISPLAY_GROUP),
@@ -2088,7 +2095,8 @@ public final class PowerManagerService extends SystemService
    }

    @GuardedBy("mLock")
    private boolean dreamPowerGroupLocked(PowerGroup powerGroup, long eventTime, int uid) {
    private boolean dreamPowerGroupLocked(PowerGroup powerGroup, long eventTime, int uid,
            boolean allowWake) {
        if (DEBUG_SPEW) {
            Slog.d(TAG, "dreamPowerGroup: groupId=" + powerGroup.getGroupId() + ", eventTime="
                    + eventTime + ", uid=" + uid);
@@ -2096,7 +2104,7 @@ public final class PowerManagerService extends SystemService
        if (!mBootCompleted || !mSystemReady) {
            return false;
        }
        return powerGroup.dreamLocked(eventTime, uid);
        return powerGroup.dreamLocked(eventTime, uid, allowWake);
    }

    @GuardedBy("mLock")
@@ -3151,7 +3159,8 @@ public final class PowerManagerService extends SystemService
                changed = sleepPowerGroupLocked(powerGroup, time,
                        PowerManager.GO_TO_SLEEP_REASON_INATTENTIVE, Process.SYSTEM_UID);
            } else if (shouldNapAtBedTimeLocked()) {
                changed = dreamPowerGroupLocked(powerGroup, time, Process.SYSTEM_UID);
                changed = dreamPowerGroupLocked(powerGroup, time,
                        Process.SYSTEM_UID, /* allowWake= */ false);
            } else {
                changed = dozePowerGroupLocked(powerGroup, time,
                        PowerManager.GO_TO_SLEEP_REASON_TIMEOUT, Process.SYSTEM_UID);
@@ -5778,10 +5787,7 @@ public final class PowerManagerService extends SystemService
            final int uid = Binder.getCallingUid();
            final long ident = Binder.clearCallingIdentity();
            try {
                synchronized (mLock) {
                    dreamPowerGroupLocked(mPowerGroups.get(Display.DEFAULT_DISPLAY_GROUP),
                            eventTime, uid);
                }
                napInternal(eventTime, uid, /* allowWake= */ false);
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
@@ -6720,6 +6726,11 @@ public final class PowerManagerService extends SystemService
        public boolean interceptPowerKeyDown(KeyEvent event) {
            return interceptPowerKeyDownInternal(event);
        }

        @Override
        public void nap(long eventTime, boolean allowWake) {
            napInternal(eventTime, Process.SYSTEM_UID, allowWake);
        }
    }

    /**
Loading