Add API to get compatibility display id

Add an API to get the compatibility display ID from CompatibilityDisplay
in the framework.

Testing Done: Compiled, built and used this API from ActivityManager and
it works.

Bug: 36071574
Change-Id: Ie4d1eb6a6befa7dbc3413519de20e2762529079d
Signed-off-by: Karthik Ravi Shankar <karthikrs@google.com>
This commit is contained in:
Karthik Ravi Shankar
2017-03-08 18:09:35 -08:00
parent 61f31c7b3a
commit 3a47ec2edd
4 changed files with 54 additions and 4 deletions

View File

@@ -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();
}

View File

@@ -1,6 +1,8 @@
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,10 +88,8 @@ class CompatibilityDisplay {
startVirtualDisplay();
}
} else {
// TODO: Remove conditional when launching apps 2D doesn't force VrMode to stop.
if (!DEBUG) {
stopVirtualDisplay();
}
// Stop virtual display to test exit condition
stopVirtualDisplay();
}
}
@@ -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);

View File

@@ -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.
*/

View File

@@ -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;