Skip to content

Commit a829e16

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Handle orientation changes more systematically. Bug: 4981385"
2 parents df8e00f + 01a98dd commit a829e16

12 files changed

Lines changed: 341 additions & 387 deletions

File tree

core/java/android/view/IWindowManager.aidl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,13 @@ interface IWindowManager
163163

164164
// These can only be called with the SET_ORIENTATION permission.
165165
/**
166-
* Change the current screen rotation, constants as per
167-
* {@link android.view.Surface}.
168-
* @param rotation the intended rotation.
166+
* Update the current screen rotation based on the current state of
167+
* the world.
169168
* @param alwaysSendConfiguration Flag to force a new configuration to
170169
* be evaluated. This can be used when there are other parameters in
171170
* configuration that are changing.
172-
* @param animFlags Animation flags as per {@link android.view.Surface}.
173171
*/
174-
void setRotation(int rotation, boolean alwaysSendConfiguration, int animFlags);
172+
void updateRotation(boolean alwaysSendConfiguration);
175173

176174
/**
177175
* Retrieve the current screen orientation, constants as per

core/java/android/view/Surface.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ public OutOfResourcesException(String name) {
207207

208208
/** Enable dithering when compositing this surface @hide */
209209
public static final int SURFACE_DITHER = 0x04;
210-
211-
/** Disable the orientation animation @hide */
212-
public static final int FLAGS_ORIENTATION_ANIMATION_DISABLE = 0x000000001;
213210

214211
// The mSurfaceControl will only be present for Surfaces used by the window
215212
// server or system processes. When this class is parceled we defer to the
@@ -393,7 +390,7 @@ void setCompatibilityTranslator(Translator translator) {
393390
* set the orientation of the given display.
394391
* @param display
395392
* @param orientation
396-
* @param flags
393+
* @param flags Currently unused, set to 0.
397394
* @hide
398395
*/
399396
public static native void setOrientation(int display, int orientation, int flags);

core/java/android/view/WindowManagerPolicy.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,6 @@ public void computeFrameLw(Rect parentFrame, Rect displayFrame,
375375
/** Screen turned off because of proximity sensor */
376376
public final int OFF_BECAUSE_OF_PROX_SENSOR = 4;
377377

378-
/**
379-
* Magic constant to {@link IWindowManager#setRotation} to not actually
380-
* modify the rotation.
381-
*/
382-
public final int USE_LAST_ROTATION = -1000;
383-
384378
/** When not otherwise specified by the activity's screenOrientation, rotation should be
385379
* determined by the system (that is, using sensors). */
386380
public final int USER_ROTATION_FREE = 0;
@@ -856,22 +850,30 @@ interface OnKeyguardExitResult {
856850
public boolean inKeyguardRestrictedKeyInputMode();
857851

858852
/**
859-
* Given an orientation constant
860-
* ({@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE
861-
* ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE} or
862-
* {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_PORTRAIT
863-
* ActivityInfo.SCREEN_ORIENTATION_PORTRAIT}), return a surface
864-
* rotation.
853+
* Given an orientation constant, returns the appropriate surface rotation,
854+
* taking into account sensors, docking mode, rotation lock, and other factors.
855+
*
856+
* @param orientation An orientation constant, such as
857+
* {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}.
858+
* @param lastRotation The most recently used rotation.
859+
* @return The surface rotation to use.
865860
*/
866-
public int rotationForOrientationLw(int orientation, int lastRotation,
867-
boolean displayEnabled);
868-
861+
public int rotationForOrientationLw(int orientation, int lastRotation);
862+
869863
/**
870-
* Return the currently locked screen rotation, if any. Return
871-
* Surface.ROTATION_0, Surface.ROTATION_90, Surface.ROTATION_180, or
872-
* Surface.ROTATION_270 if locked; return -1 if not locked.
864+
* Given an orientation constant and a rotation, returns true if the rotation
865+
* has compatible metrics to the requested orientation. For example, if
866+
* the application requested landscape and got seascape, then the rotation
867+
* has compatible metrics; if the application requested portrait and got landscape,
868+
* then the rotation has incompatible metrics; if the application did not specify
869+
* a preference, then anything goes.
870+
*
871+
* @param orientation An orientation constant, such as
872+
* {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_LANDSCAPE}.
873+
* @param rotation The rotation to check.
874+
* @return True if the rotation is compatible with the requested orientation.
873875
*/
874-
public int getLockedRotationLw();
876+
public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation);
875877

876878
/**
877879
* Called when the system is mostly done booting to determine whether

core/java/android/view/WindowOrientationListener.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,13 @@ public void disable() {
118118

119119
/**
120120
* Gets the current orientation.
121-
* @param lastRotation
122-
* @return
121+
* @return The current rotation, or -1 if unknown.
123122
*/
124-
public int getCurrentRotation(int lastRotation) {
123+
public int getCurrentRotation() {
125124
if (mEnabled) {
126-
return mSensorEventListener.getCurrentRotation(lastRotation);
125+
return mSensorEventListener.getCurrentRotation();
127126
}
128-
return lastRotation;
127+
return -1;
129128
}
130129

131130
/**
@@ -342,8 +341,8 @@ public SensorEventListenerImpl(WindowOrientationListener orientationListener) {
342341
mOrientationListener = orientationListener;
343342
}
344343

345-
public int getCurrentRotation(int lastRotation) {
346-
return mRotation != ROTATION_UNKNOWN ? mRotation : lastRotation;
344+
public int getCurrentRotation() {
345+
return mRotation; // may be -1, if unknown
347346
}
348347

349348
@Override

include/surfaceflinger/ISurfaceComposer.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ class ISurfaceComposer : public IInterface
8888
eElectronBeamAnimationOff = 0x10
8989
};
9090

91-
// flags for setOrientation
92-
enum {
93-
eOrientationAnimationDisable = 0x00000001
94-
};
95-
9691
/* create connection with surface flinger, requires
9792
* ACCESS_SURFACE_FLINGER permission
9893
*/
@@ -112,7 +107,8 @@ class ISurfaceComposer : public IInterface
112107
virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags) = 0;
113108
virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags) = 0;
114109

115-
/* Set display orientation. requires ACCESS_SURFACE_FLINGER permission */
110+
/* Set display orientation. requires ACCESS_SURFACE_FLINGER permission
111+
* No flags are currently defined. Set flags to 0. */
116112
virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags) = 0;
117113

118114
/* signal that we're done booting.

0 commit comments

Comments
 (0)