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

Commit 0f0e5512 authored by Fiona Campbell's avatar Fiona Campbell
Browse files

Ignore face down detector with shell command

- Shell command to ignore face down detector signals for testing

Bug: 329371579
Test: adb shell dumpsys power | grep mIsFaceDown -A1
Test: adb shell cmd power set-face-down-detector false
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:53ee705b9685926302dbf729f42ebbd0ad49666b)
Merged-In: I89970bda86e4624c4ef8e5c322cb03588ff719ad
Change-Id: I89970bda86e4624c4ef8e5c322cb03588ff719ad
parent 4da9a6a9
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -616,6 +616,7 @@ public final class PowerManagerService extends SystemService

    // Value we store for tracking face down behavior.
    private boolean mIsFaceDown = false;
    private boolean mUseFaceDownDetector = true;
    private long mLastFlipTime = 0L;

    // The screen brightness setting override from the window manager
@@ -3198,7 +3199,7 @@ public final class PowerManagerService extends SystemService
            long screenOffTimeout, long screenDimDuration) {
        // If face down, we decrease the timeout to equal the dim duration so that the
        // device will go into a dim state.
        if (mIsFaceDown) {
        if (mIsFaceDown && mUseFaceDownDetector) {
            return Math.min(screenDimDuration, screenOffTimeout);
        }
        return screenOffTimeout;
@@ -4643,6 +4644,7 @@ public final class PowerManagerService extends SystemService
            pw.println("  mHoldingDisplaySuspendBlocker=" + mHoldingDisplaySuspendBlocker);
            pw.println("  mLastFlipTime=" + mLastFlipTime);
            pw.println("  mIsFaceDown=" + mIsFaceDown);
            pw.println("  mUseFaceDownDetector=" + mUseFaceDownDetector);

            pw.println();
            pw.println("Settings and Configuration:");
@@ -6840,6 +6842,16 @@ public final class PowerManagerService extends SystemService
                Binder.restoreCallingIdentity(ident);
            }
        }

        public void setUseFaceDownDetector(boolean enable) {
            final long ident = Binder.clearCallingIdentity();
            try {
                mUseFaceDownDetector = enable;
            } finally {
                Binder.restoreCallingIdentity(ident);
            }
        }

    }

    @VisibleForTesting
+18 −0
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ class PowerManagerShellCommand extends ShellCommand {
                    return runListAmbientDisplaySuppressionTokens();
                case "set-prox":
                    return runSetProx();
                case "set-face-down-detector":
                    return runSetFaceDownDetector();
                default:
                    return handleDefaultCommands(cmd);
            }
@@ -178,6 +180,20 @@ class PowerManagerShellCommand extends ShellCommand {
        return 0;
    }

    /**
     * To be used for testing - allowing us to disable the usage of face down detector.
     */
    private int runSetFaceDownDetector() {
        try {
            mService.setUseFaceDownDetector(Boolean.parseBoolean(getNextArgRequired()));
        } catch (Exception e) {
            PrintWriter pw = getOutPrintWriter();
            pw.println("Error: " + e);
            return -1;
        }
        return 0;
    }

    @Override
    public void onHelp() {
        final PrintWriter pw = getOutPrintWriter();
@@ -203,6 +219,8 @@ class PowerManagerShellCommand extends ShellCommand {
        pw.println("    Acquires the proximity sensor wakelock. Wakelock is associated with");
        pw.println("    a specific display if specified. 'list' lists wakelocks previously");
        pw.println("    created by set-prox including their held status.");
        pw.println("  set-face-down-detector [true|false]");
        pw.println("    sets whether we use face down detector timeouts or not");

        pw.println();
        Intent.printIntentArgsHelp(pw , "");