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

Commit c638e226 authored by Santos Cordon's avatar Santos Cordon Committed by Android (Google) Code Review
Browse files

Merge "Debugging code to CompatibilityDisplay."

parents 521d92bc 2f22da70
Loading
Loading
Loading
Loading
+77 −14
Original line number Diff line number Diff line
@@ -2,8 +2,10 @@
package com.android.server.vr;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
import android.os.Build;
@@ -14,6 +16,7 @@ import android.os.ServiceManager;
import android.service.vr.IVrStateCallbacks;
import android.service.vr.IVrManager;
import android.util.Log;
import android.view.Surface;

import com.android.server.vr.VrManagerService;

@@ -26,10 +29,19 @@ class CompatibilityDisplay {
    private final static boolean DEBUG = false;

    // TODO: Go over these values and figure out what is best
    private final static int HEIGHT = 960;
    private final static int WIDTH = 720;
    private final static int HEIGHT = 1800;
    private final static int WIDTH = 1400;
    private final static int DPI = 320;

    private final static String DEBUG_ACTION_SET_MODE =
            "com.android.server.vr.CompatibilityDisplay.SET_MODE";
    private final static String DEBUG_EXTRA_MODE_ON =
            "com.android.servier.vr.CompatibilityDisplay.EXTRA_MODE_ON";
    private final static String DEBUG_ACTION_SET_SURFACE =
            "com.android.server.vr.CompatibilityDisplay.SET_SURFACE";
    private final static String DEBUG_EXTRA_SURFACE =
            "com.android.server.vr.CompatibilityDisplay.EXTRA_SURFACE";

    private final DisplayManager mDisplayManager;
    private final IVrManager mVrManager;

@@ -42,18 +54,14 @@ class CompatibilityDisplay {
        public void onVrStateChanged(boolean enabled) {
            if (enabled != mIsVrModeEnabled) {
                mIsVrModeEnabled = enabled;
                if (enabled) {
                    // TODO: Consider not creating the display until ActivityManager needs one on
                    // which to display a 2D application.
                    startVirtualDisplay();
                } else {
                    stopVirtualDisplay();
                }
                updateVirtualDisplay();
            }
        }
    };

    private VirtualDisplay mVirtualDisplay;
    private Surface mSurface;
    private boolean mIsDebugOverrideEnabled;
    private boolean mIsVrModeEnabled;

    public CompatibilityDisplay(DisplayManager displayManager, IVrManager vrManager) {
@@ -64,8 +72,60 @@ class CompatibilityDisplay {
    /**
     * Initializes the compabilitiy display by listening to VR mode changes.
     */
    public void init() {
    public void init(Context context) {
        startVrModeListener();
        startDebugOnlyBroadcastReceiver(context);
    }

    private void updateVirtualDisplay() {
        if (mIsVrModeEnabled || (DEBUG && mIsDebugOverrideEnabled)) {
            // TODO: Consider not creating the display until ActivityManager needs one on
            // which to display a 2D application.
            // TODO: STOPSHIP Remove DEBUG conditional before launching.
            if (DEBUG) {
                startVirtualDisplay();
            }
        } else {
            // TODO: Remove conditional when launching apps 2D doesn't force VrMode to stop.
            if (!DEBUG) {
                stopVirtualDisplay();
            }
        }
    }

    private void startDebugOnlyBroadcastReceiver(Context context) {
        if (DEBUG) {
            IntentFilter intentFilter = new IntentFilter(DEBUG_ACTION_SET_MODE);
            intentFilter.addAction(DEBUG_ACTION_SET_SURFACE);

            context.registerReceiver(new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    final String action = intent.getAction();
                    if (DEBUG_ACTION_SET_MODE.equals(action)) {
                        mIsDebugOverrideEnabled =
                                intent.getBooleanExtra(DEBUG_EXTRA_MODE_ON, false);
                        updateVirtualDisplay();
                    } else if (DEBUG_ACTION_SET_SURFACE.equals(action)) {
                        if (mVirtualDisplay != null) {
                            final Surface newSurface =
                                    intent.getParcelableExtra(DEBUG_EXTRA_SURFACE);

                            Log.i(TAG, "Setting the new surface from " + mSurface + " to " + newSurface);
                            if (newSurface != mSurface) {
                                mVirtualDisplay.setSurface(newSurface);
                                if (mSurface != null) {
                                    mSurface.release();
                                }
                                mSurface = newSurface;
                            }
                        } else {
                            Log.w(TAG, "Cannot set the surface because the VD is null.");
                        }
                    }
                }
            }, intentFilter);
        }
    }

    private void startVrModeListener() {
@@ -80,7 +140,7 @@ class CompatibilityDisplay {

    private void startVirtualDisplay() {
        if (DEBUG) {
            Log.d(TAG, "Starting VD, DM:" + mDisplayManager);
            Log.d(TAG, "Request to start VD, DM:" + mDisplayManager);
        }

        if (mDisplayManager == null) {
@@ -90,13 +150,16 @@ class CompatibilityDisplay {

        synchronized (vdLock) {
            if (mVirtualDisplay != null) {
                Log.e(TAG, "Starting the virtual display when one already exists", new Exception());
                Log.i(TAG, "VD already exists, ignoring request");
                return;
            }

            mVirtualDisplay = mDisplayManager.createVirtualDisplay("VR 2D Display", WIDTH, HEIGHT,
                    DPI,
                    null /* Surface */, 0 /* flags */);
                    DPI, null /* Surface */, 0 /* flags */);
            if (mSurface != null && mSurface.isValid()) {
              // TODO: Need to protect all setSurface calls with a lock.
              mVirtualDisplay.setSurface(mSurface);
            }
        }

        if (DEBUG) {
+8 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.hardware.display.DisplayManager;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
@@ -131,6 +132,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
    private final NotificationAccessManager mNotifAccessManager = new NotificationAccessManager();
    /** Tracks the state of the screen and keyguard UI.*/
    private int mSystemSleepFlags = FLAG_AWAKE;
    private CompatibilityDisplay mCompatibilityDisplay;

    private static final int MSG_VR_STATE_CHANGE = 0;
    private static final int MSG_PENDING_VR_STATE_CHANGE = 1;
@@ -537,6 +539,11 @@ public class VrManagerService extends SystemService implements EnabledComponentC
            } else {
                Slog.i(TAG, "No default vr listener service found.");
            }

            DisplayManager dm =
                    (DisplayManager) getContext().getSystemService(Context.DISPLAY_SERVICE);
            mCompatibilityDisplay = new CompatibilityDisplay(dm, mVrManager);
            mCompatibilityDisplay.init(getContext());
        } else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
            synchronized (mLock) {
                mVrModeAllowed = true;
@@ -680,10 +687,10 @@ public class VrManagerService extends SystemService implements EnabledComponentC
                }
            }

            mCurrentVrModeComponent = calling;
            if (calling != null && !Objects.equals(calling, mCurrentVrModeComponent)) {
                sendUpdatedCaller = true;
            }
            mCurrentVrModeComponent = calling;

            if (mCurrentVrModeUser != userId) {
                mCurrentVrModeUser = userId;