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

Commit ec0aaa06 authored by Steven Thomas's avatar Steven Thomas Committed by Android (Google) Code Review
Browse files

Merge "On standalones, stay in vr mode until standby"

parents 46fabf34 1356ec95
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());
    }