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

Commit 1356ec95 authored by Steven Thomas's avatar Steven Thomas
Browse files

On standalones, stay in vr mode until standby

On standalones, stay in vr mode until the Power Policy Service notifies
us it has switched to standby mode.

We still have a few issues elsewhere in the code, so the "stay in vr
mode" functionality is only enabled if the system property
"persist.vr.use_standby_to_exit_vr_mode" is set to true, which you can
do like this:

$ adb shell setprop persist.vr.use_standby_to_exit_vr_mode true

Bug: 65248224

Test: - Confirmed on a standalone that doffing leaves us in vr mode for
5 minutes, then we get a notification that we've entered standby, and we
exit vr mode. Confirmed we enter vr mode again when we don the device.

- Confirmed no behavioral change on phones, as expected.

Change-Id: I41d62761fe8c2fc7630f0615732453669cb25f06
parent 5d889722
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -198,4 +198,20 @@ public class VrManager {
            e.rethrowFromSystemServer();
        }
    }

    /**
     * Sets the current standby status of the VR device. Standby mode is only used on standalone vr
     * devices. Standby mode is a deep sleep state where it's appropriate to turn off vr mode.
     *
     * @param standby True if the device is entering standby, false if it's exiting standby.
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.ACCESS_VR_MANAGER)
    public void setStandbyEnabled(boolean standby) {
        try {
            mService.setStandbyEnabled(standby);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -101,5 +101,13 @@ interface IVrManager {
     * application's compositor process to bind to, or null to clear the current binding.
     */
    void setAndBindCompositor(in String componentName);

    /**
     * Sets the current standby status of the VR device. Standby mode is only used on standalone vr
     * devices. Standby mode is a deep sleep state where it's appropriate to turn off vr mode.
     *
     * @param standy True if the device is entering standby, false if it's exiting standby.
     */
    void setStandbyEnabled(boolean standby);
}
+25 −1
Original line number Diff line number Diff line
@@ -166,6 +166,8 @@ public class VrManagerService extends SystemService implements EnabledComponentC
    private boolean mUserUnlocked;
    private Vr2dDisplay mVr2dDisplay;
    private boolean mBootsToVr;
    private boolean mStandby;
    private boolean mUseStandbyToExitVrMode;

    // Handles events from the managed services (e.g. VrListenerService and any bound VR compositor
    // service).
@@ -203,7 +205,10 @@ public class VrManagerService extends SystemService implements EnabledComponentC
     *
     */
    private void updateVrModeAllowedLocked() {
        boolean allowed = mSystemSleepFlags == FLAG_ALL && mUserUnlocked;
        boolean ignoreSleepFlags = mBootsToVr && mUseStandbyToExitVrMode;
        boolean disallowedByStandby = mStandby && mUseStandbyToExitVrMode;
        boolean allowed = (mSystemSleepFlags == FLAG_ALL || ignoreSleepFlags) && mUserUnlocked
                && !disallowedByStandby;
        if (mVrModeAllowed != allowed) {
            mVrModeAllowed = allowed;
            if (DBG) Slog.d(TAG, "VR mode is " + ((allowed) ? "allowed" : "disallowed"));
@@ -273,6 +278,17 @@ public class VrManagerService extends SystemService implements EnabledComponentC
        }
    }

    private void setStandbyEnabled(boolean standby) {
        synchronized(mLock) {
            if (!mBootsToVr) {
                Slog.e(TAG, "Attempting to set standby mode on a non-standalone device");
                return;
            }
            mStandby = standby;
            updateVrModeAllowedLocked();
        }
    }

    private final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
@@ -586,6 +602,12 @@ public class VrManagerService extends SystemService implements EnabledComponentC
                (componentName == null) ? null : ComponentName.unflattenFromString(componentName));
        }

        @Override
        public void setStandbyEnabled(boolean standby) {
            enforceCallerPermissionAnyOf(Manifest.permission.ACCESS_VR_MANAGER);
            VrManagerService.this.setStandbyEnabled(standby);
        }

        @Override
        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
            if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
@@ -733,6 +755,8 @@ public class VrManagerService extends SystemService implements EnabledComponentC
        }

        mBootsToVr = SystemProperties.getBoolean("ro.boot.vr", false);
        mUseStandbyToExitVrMode = mBootsToVr
                && SystemProperties.getBoolean("persist.vr.use_standby_to_exit_vr_mode", false);
        publishLocalService(VrManagerInternal.class, new LocalService());
        publishBinderService(Context.VR_SERVICE, mVrManager.asBinder());
    }