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 Original line Diff line number Diff line
@@ -50,5 +50,13 @@ interface IVrManager {
     * @param enabled true if the device should be placed in persistent VR mode.
     * @param enabled true if the device should be placed in persistent VR mode.
     */
     */
    void setPersistentVrModeEnabled(in boolean enabled);
    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 Original line Diff line number Diff line


package com.android.server.vr;
package com.android.server.vr;


import static android.view.Display.INVALID_DISPLAY;

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


    private void startDebugOnlyBroadcastReceiver(Context context) {
    private void startDebugOnlyBroadcastReceiver(Context context) {
        if (DEBUG) {
        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() {
    private void startVirtualDisplay() {
        if (DEBUG) {
        if (DEBUG) {
            Log.d(TAG, "Request to start VD, DM:" + mDisplayManager);
            Log.d(TAG, "Request to start VD, DM:" + mDisplayManager);
+9 −0
Original line number Original line Diff line number Diff line
@@ -89,6 +89,15 @@ public abstract class VrManagerInternal {
     */
     */
    public abstract void setPersistentVrModeEnabled(boolean enabled);
    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.
     * Adds listener that reports state changes to persistent VR mode.
     */
     */
+20 −0
Original line number Original line Diff line number Diff line
@@ -15,6 +15,8 @@
 */
 */
package com.android.server.vr;
package com.android.server.vr;


import static android.view.Display.INVALID_DISPLAY;

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


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

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


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

        @Override
        @Override
        public void addPersistentVrModeStateListener(PersistentVrStateListener listener) {
        public void addPersistentVrModeStateListener(PersistentVrStateListener listener) {
            VrManagerService.this.addPersistentVrModeStateListener(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) {
    private void setPersistentModeAndNotifyListenersLocked(boolean enabled) {
        if (mPersistentVrModeEnabled == enabled) {
        if (mPersistentVrModeEnabled == enabled) {
            return;
            return;