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

Commit e6ccc3e8 authored by Karthik Ravi Shankar's avatar Karthik Ravi Shankar Committed by Android (Google) Code Review
Browse files

Merge "Add API to get compatibility display id"

parents 389d1c2b 3a47ec2e
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -50,5 +50,13 @@ interface IVrManager {
     * @param enabled true if the device should be placed in persistent VR mode.
     */
    void setPersistentVrModeEnabled(in boolean enabled);

    /**
     * Return current virtual display id.
     *
     * @return {@link android.view.Display.INVALID_DISPLAY} if there is no virtual display
     * currently, else return the display id of the virtual display
     */
    int getCompatibilityDisplayId();
}
+17 −4
Original line number Diff line number Diff line

package com.android.server.vr;

import static android.view.Display.INVALID_DISPLAY;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -86,12 +88,10 @@ class CompatibilityDisplay {
                startVirtualDisplay();
            }
        } else {
            // TODO: Remove conditional when launching apps 2D doesn't force VrMode to stop.
            if (!DEBUG) {
            // Stop virtual display to test exit condition
            stopVirtualDisplay();
        }
    }
    }

    private void startDebugOnlyBroadcastReceiver(Context context) {
        if (DEBUG) {
@@ -138,6 +138,19 @@ class CompatibilityDisplay {
        }
    }

    public int getVirtualDisplayId() {
        synchronized(vdLock) {
            if (mVirtualDisplay != null) {
                int virtualDisplayId = mVirtualDisplay.getDisplay().getDisplayId();
                if (DEBUG) {
                    Log.e(TAG, "VD id: " + virtualDisplayId);
                }
                return virtualDisplayId;
            }
        }
        return INVALID_DISPLAY;
    }

    private void startVirtualDisplay() {
        if (DEBUG) {
            Log.d(TAG, "Request to start VD, DM:" + mDisplayManager);
+9 −0
Original line number Diff line number Diff line
@@ -89,6 +89,15 @@ public abstract class VrManagerInternal {
     */
    public abstract void setPersistentVrModeEnabled(boolean enabled);

    /**
     * Return {@link android.view.Display.INVALID_DISPLAY} if there exists no virtual display
     * currently or the display id of the current virtual display.
     *
     * @return {@link android.view.Display.INVALID_DISPLAY} if there is no virtual display
     * currently, else return the display id of the virtual display
     */
    public abstract int getCompatibilityDisplayId();

    /**
     * Adds listener that reports state changes to persistent VR mode.
     */
+20 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.server.vr;

import static android.view.Display.INVALID_DISPLAY;

import android.Manifest;
import android.app.ActivityManager;
import android.app.AppOpsManager;
@@ -391,6 +393,11 @@ public class VrManagerService extends SystemService implements EnabledComponentC
            VrManagerService.this.setPersistentVrModeEnabled(enabled);
        }

        @Override
        public int getCompatibilityDisplayId() {
            return VrManagerService.this.getCompatibilityDisplayId();
        }

        @Override
        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
            if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
@@ -494,6 +501,11 @@ public class VrManagerService extends SystemService implements EnabledComponentC
            VrManagerService.this.setPersistentVrModeEnabled(enabled);
        }

        @Override
        public int getCompatibilityDisplayId() {
            return VrManagerService.this.getCompatibilityDisplayId();
        }

        @Override
        public void addPersistentVrModeStateListener(PersistentVrStateListener listener) {
            VrManagerService.this.addPersistentVrModeStateListener(listener);
@@ -1054,6 +1066,14 @@ public class VrManagerService extends SystemService implements EnabledComponentC
        }
    }

    private int getCompatibilityDisplayId() {
        if (mCompatibilityDisplay != null) {
            return mCompatibilityDisplay.getVirtualDisplayId();
        }
        Slog.w(TAG, "CompatibilityDisplay is null!");
        return INVALID_DISPLAY;
    }

    private void setPersistentModeAndNotifyListenersLocked(boolean enabled) {
        if (mPersistentVrModeEnabled == enabled) {
            return;