From ae6119ffce7f2be8846d1d2fd1497965946b66b8 Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Tue, 11 Nov 2014 18:54:39 -0800 Subject: [PATCH] implement HDMI-like demo mode for remote display adding the following two system properties to control remote display rotation and device orientation lock: "persist.demo.rotationlock"=true|false "persist.demo.remoterotation"=landscape|portrait Bug: 18317603 Change-Id: Id5fe115f895c6a0e72563036b9a98ff3b5037763 --- .../internal/policy/impl/PhoneWindowManager.java | 16 ++++++++++++++++ .../server/display/VirtualDisplayAdapter.java | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 3c44e87178d91..90f4312e12843 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -342,6 +342,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { int mUndockedHdmiRotation; int mDemoHdmiRotation; boolean mDemoHdmiRotationLock; + int mDemoRotation; + boolean mDemoRotationLock; boolean mWakeGestureEnabledSetting; MyWakeGestureListener mWakeGestureListener; @@ -1444,6 +1446,16 @@ public class PhoneWindowManager implements WindowManagerPolicy { } mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); + // For demo purposes, allow the rotation of the remote display to be controlled. + // By default, remote display locks rotation to landscape. + if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) { + mDemoRotation = mPortraitRotation; + } else { + mDemoRotation = mLandscapeRotation; + } + mDemoRotationLock = SystemProperties.getBoolean( + "persist.demo.rotationlock", false); + // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per // http://developer.android.com/guide/practices/screens_support.html#range mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && @@ -5294,6 +5306,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { // full multi-display support). // Note that the dock orientation overrides the HDMI orientation. preferredRotation = mUndockedHdmiRotation; + } else if (mDemoRotationLock) { + // Ignore sensor when demo rotation lock is enabled. + // Note that the dock orientation and HDMI rotation lock override this. + preferredRotation = mDemoRotation; } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { // Application just wants to remain locked in the last rotation. preferredRotation = lastRotation; diff --git a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java index 0232bad0605cc..28d5fc03af0e6 100644 --- a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java +++ b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java @@ -23,6 +23,7 @@ import android.media.projection.IMediaProjection; import android.media.projection.IMediaProjectionCallback; import android.os.Handler; import android.os.IBinder; +import android.os.SystemProperties; import android.os.IBinder.DeathRecipient; import android.os.Message; import android.os.RemoteException; @@ -278,6 +279,15 @@ final class VirtualDisplayAdapter extends DisplayAdapter { } if ((mFlags & DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION) != 0) { mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION; + + if ((mFlags & DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) { + // For demonstration purposes, allow rotation of the external display. + // In the future we might allow the user to configure this directly. + if ("portrait".equals(SystemProperties.get( + "persist.demo.remoterotation"))) { + mInfo.rotation = Surface.ROTATION_270; + } + } } mInfo.type = Display.TYPE_VIRTUAL; mInfo.touch = DisplayDeviceInfo.TOUCH_NONE;