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

Commit a13bb162 authored by Lucas Silva's avatar Lucas Silva Committed by Android (Google) Code Review
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
parents aeb8c264 16d6ddde
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
@@ -1924,6 +1924,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),
@@ -2039,7 +2046,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);
@@ -2047,7 +2055,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")
@@ -3099,7 +3107,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);
@@ -5716,10 +5725,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);
            }
@@ -6647,6 +6653,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