Skip to content

Commit dec6cf4

Browse files
author
Jeff Brown
committed
Override app requested orientation when docked.
Applies to docks, lid switch, HDMI and rotation lock. We always choose a mode that is compatible with the application's request, so if in a landscape dock, we might override a request for seascape but we leave requests for portrait alone. Bug: 5620454 Change-Id: Ib0c4f60f7f9e3aeafaba9c717233a950fccb8af2
1 parent 9058435 commit dec6cf4

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,7 +3097,7 @@ public int rotationForOrientationLw(int orientation, int lastRotation) {
30973097
sensorRotation = lastRotation;
30983098
}
30993099

3100-
int preferredRotation = -1;
3100+
final int preferredRotation;
31013101
if (mHdmiPlugged) {
31023102
// Ignore sensor when plugged into HDMI.
31033103
preferredRotation = mHdmiRotation;
@@ -3146,28 +3146,39 @@ public int rotationForOrientationLw(int orientation, int lastRotation) {
31463146
} else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
31473147
// Apply rotation lock.
31483148
preferredRotation = mUserRotation;
3149+
} else {
3150+
// No overriding preference.
3151+
// We will do exactly what the application asked us to do.
3152+
preferredRotation = -1;
31493153
}
31503154

3151-
// TODO: Sometimes, we might want to override the application-requested
3152-
// orientation, such as when HDMI is plugged in or when docked.
3153-
// We can do that by modifying the appropriate cases above to return
3154-
// the preferred orientation directly instead of continuing on down here.
3155-
31563155
switch (orientation) {
31573156
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
3158-
// Always return portrait if orientation set to portrait.
3157+
// Return portrait unless overridden.
3158+
if (isAnyPortrait(preferredRotation)) {
3159+
return preferredRotation;
3160+
}
31593161
return mPortraitRotation;
31603162

31613163
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
3162-
// Always return landscape if orientation set to landscape.
3164+
// Return landscape unless overridden.
3165+
if (isLandscapeOrSeascape(preferredRotation)) {
3166+
return preferredRotation;
3167+
}
31633168
return mLandscapeRotation;
31643169

31653170
case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
3166-
// Always return portrait if orientation set to portrait.
3171+
// Return reverse portrait unless overridden.
3172+
if (isAnyPortrait(preferredRotation)) {
3173+
return preferredRotation;
3174+
}
31673175
return mUpsideDownRotation;
31683176

31693177
case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
3170-
// Always return seascape if orientation set to reverse landscape.
3178+
// Return seascape unless overridden.
3179+
if (isLandscapeOrSeascape(preferredRotation)) {
3180+
return preferredRotation;
3181+
}
31713182
return mSeascapeRotation;
31723183

31733184
case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:

0 commit comments

Comments
 (0)