Add command line option to set compatibility display properties

To be able to control the Vr compatibility virtual display's is useful.
In this case, it will be useful to control and test the
CompatibilityDisplayProperties API in VrManager.

Bug: 37260266
Test: adb shell set-compatibility-display-properties 500 500 500
      adb shell dumpsys display

      >>  mBaseDisplayInfo=DisplayInfo{"VR 2D Display", uniqueId
      "virtual:android,1000,VR 2D Display,0", app 500 x 500, real 500
      x 500, largest app 500 x 500, smallest app 500 x 500, mode 6,
      defaultMode 6, modes [{id=6, width=500, height=500, fps=60.0}],
      colorMode 0, supportedColorModes [0], hdrCapabilities null,
      rotation 0, density 500 (500.0 x 500.0) dpi...

Change-Id: Ice5bc569f380154bf2d9e9f9b9387e801d678774
Signed-off-by: Karthik Ravi Shankar <karthikrs@google.com>
diff --git a/cmds/vr/src/com/android/commands/vr/Vr.java b/cmds/vr/src/com/android/commands/vr/Vr.java
index 3fb40fb..bf97bba 100644
--- a/cmds/vr/src/com/android/commands/vr/Vr.java
+++ b/cmds/vr/src/com/android/commands/vr/Vr.java
@@ -16,6 +16,7 @@
 
 package com.android.commands.vr;
 
+import android.app.CompatibilityDisplayProperties;
 import android.content.Context;
 import android.os.RemoteException;
 import android.os.ServiceManager;
@@ -36,7 +37,10 @@
       (new Vr()).run(args);
     }
 
-    private static final String COMMAND_SET_PERSISTENT_VR_MODE_ENABLED = "set-persistent-vr-mode-enabled";
+    private static final String COMMAND_SET_PERSISTENT_VR_MODE_ENABLED =
+        "set-persistent-vr-mode-enabled";
+    private static final String COMMAND_SET_COMPATIBILITY_DISPLAY_PROPERTIES =
+        "set-display-props";
 
     private IVrManager mVrService;
 
@@ -44,7 +48,8 @@
     public void onShowUsage(PrintStream out) {
         out.println(
                 "usage: vr [subcommand]\n" +
-                "usage: vr set-persistent-vr-mode-enabled [true|false]\n"
+                "usage: vr set-persistent-vr-mode-enabled [true|false]\n" +
+                "usage: vr set-display-props [width] [height] [dpi]\n"
                 );
     }
 
@@ -58,6 +63,9 @@
 
         String command = nextArgRequired();
         switch (command) {
+            case COMMAND_SET_COMPATIBILITY_DISPLAY_PROPERTIES:
+                runSetCompatibilityDisplayProperties();
+                break;
             case COMMAND_SET_PERSISTENT_VR_MODE_ENABLED:
                 runSetPersistentVrModeEnabled();
                 break;
@@ -66,6 +74,26 @@
         }
     }
 
+    private void runSetCompatibilityDisplayProperties() throws RemoteException {
+        String widthStr = nextArgRequired();
+        int width = Integer.parseInt(widthStr);
+
+        String heightStr = nextArgRequired();
+        int height = Integer.parseInt(heightStr);
+
+        String dpiStr = nextArgRequired();
+        int dpi = Integer.parseInt(dpiStr);
+
+        CompatibilityDisplayProperties compatDisplayProperties =
+                new CompatibilityDisplayProperties(width, height, dpi);
+
+        try {
+            mVrService.setCompatibilityDisplayProperties(compatDisplayProperties);
+        } catch (RemoteException re) {
+            System.err.println("Error: Can't set persistent mode " + re);
+        }
+    }
+
     private void runSetPersistentVrModeEnabled() throws RemoteException {
         String enableStr = nextArg();
         boolean enabled = Boolean.parseBoolean(enableStr);