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

Commit 13ba34bf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'virtual-display-api' into oc-dev

* changes:
  Add command line option to set compatibility display properties
  Make VR mode virtual display properties customizable
parents 880f4f4c 33f70c16
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -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 @@ public final class Vr extends BaseCommand {
      (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 final class Vr extends BaseCommand {
    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 @@ public final class Vr extends BaseCommand {

        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 @@ public final class Vr extends BaseCommand {
        }
    }

    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);
+20 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app;

/** @hide */
parcelable CompatibilityDisplayProperties;
+123 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app;

import android.content.ComponentName;
import android.os.Parcel;
import android.os.Parcelable;

import java.io.PrintWriter;

/**
 * Display properties to be used by VR mode when creating a virtual display.
 *
 * @hide
 */
public class CompatibilityDisplayProperties implements Parcelable {

   /**
    * The actual width, height and dpi.
    */
    private final int mWidth;
    private final int mHeight;
    private final int mDpi;

    public CompatibilityDisplayProperties(int width, int height, int dpi) {
        mWidth = width;
        mHeight = height;
        mDpi = dpi;
    }

    @Override
    public int hashCode() {
        int result = getWidth();
        result = 31 * result + getHeight();
        result = 31 * result + getDpi();
        return result;
    }

    @Override
    public String toString() {
        return "CompatibilityDisplayProperties{" +
                "mWidth=" + mWidth +
                ", mHeight=" + mHeight +
                ", mDpi=" + mDpi +
                "}";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        CompatibilityDisplayProperties that = (CompatibilityDisplayProperties) o;

        if (getWidth() != that.getWidth()) return false;
        if (getHeight() != that.getHeight()) return false;
        return getDpi() == that.getDpi();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mWidth);
        dest.writeInt(mHeight);
        dest.writeInt(mDpi);
    }

    public static final Parcelable.Creator<CompatibilityDisplayProperties> CREATOR
            = new Parcelable.Creator<CompatibilityDisplayProperties>() {
        @Override
        public CompatibilityDisplayProperties createFromParcel(Parcel source) {
            return new CompatibilityDisplayProperties(source);
        }

        @Override
        public CompatibilityDisplayProperties[] newArray(int size) {
            return new CompatibilityDisplayProperties[size];
        }
    };

    private CompatibilityDisplayProperties(Parcel source) {
        mWidth = source.readInt();
        mHeight = source.readInt();
        mDpi = source.readInt();
    }

    public void dump(PrintWriter pw, String prefix) {
        pw.println(prefix + "CompatibilityDisplayProperties:");
        pw.println(prefix + "  width=" + mWidth);
        pw.println(prefix + "  height=" + mHeight);
        pw.println(prefix + "  dpi=" + mDpi);
    }

    public int getWidth() {
        return mWidth;
    }

    public int getHeight() {
        return mHeight;
    }

    public int getDpi() {
        return mDpi;
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -44,6 +44,26 @@ public class VrManager {
        }
    }

    /**
     * Sets the resolution and DPI of the compatibility virtual display used to display 2D
     * applications in VR mode.
     *
     * <p>Requires {@link android.Manifest.permission#ACCESS_VR_MANAGER} permission.</p>
     *
     * @param {@link android.app.CompatibilityDisplayProperties} properties to be set to the
     * virtual display for 2D applications in VR mode.
     *
     * {@hide}
     */
    public void setCompatibilityDisplayProperties(
            CompatibilityDisplayProperties compatDisplayProp) {
        try {
            mService.setCompatibilityDisplayProperties(compatDisplayProp);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    /**
     * Initiate connection for system controller data.
     *
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.service.vr;

import android.app.CompatibilityDisplayProperties;
import android.service.vr.IVrStateCallbacks;
import android.service.vr.IPersistentVrStateCallbacks;

@@ -66,6 +67,18 @@ interface IVrManager {
     */
    void setPersistentVrModeEnabled(in boolean enabled);

    /**
     * Sets the resolution and DPI of the compatibility virtual display used to display
     * 2D applications in VR mode.
     *
     * <p>Requires {@link android.Manifest.permission#ACCESS_VR_MANAGER} permission.</p>
     *
     * @param compatDisplayProperties Compatibitlity display properties to be set for
     * the VR virtual display
     */
    void setCompatibilityDisplayProperties(
            in CompatibilityDisplayProperties compatDisplayProperties);

    /**
     * Return current virtual display id.
     *
Loading