Skip to content

Commit 4dfce20

Browse files
author
Jeff Brown
committed
Make SENSOR orientation modes trump rotation lock.
Bug: 5371750 Change-Id: I4d18b6c8ba1de0afd5929ddb8d7123272e35fbe2
1 parent 66fb1f3 commit 4dfce20

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

core/java/android/view/IWindowManager.aidl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,12 @@ interface IWindowManager
192192
int getPreferredOptionsPanelGravity();
193193

194194
/**
195-
* Lock the device orientation to the current rotation. Sensor input will
196-
* be ignored until thawRotation() is called.
195+
* Lock the device orientation to the specified rotation, or to the
196+
* current rotation if -1. Sensor input will be ignored until
197+
* thawRotation() is called.
197198
* @hide
198199
*/
199-
void freezeRotation();
200+
void freezeRotation(int rotation);
200201

201202
/**
202203
* Release the orientation lock imposed by freezeRotation().

packages/SystemUI/src/com/android/systemui/statusbar/policy/AutoRotateController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.os.RemoteException;
2323
import android.os.ServiceManager;
2424
import android.provider.Settings;
25+
import android.util.Log;
2526
import android.util.Slog;
2627
import android.view.IWindowManager;
2728
import android.widget.CompoundButton;
@@ -63,13 +64,13 @@ public void run() {
6364
try {
6465
IWindowManager wm = IWindowManager.Stub.asInterface(
6566
ServiceManager.getService(Context.WINDOW_SERVICE));
66-
ContentResolver cr = mContext.getContentResolver();
6767
if (autorotate) {
6868
wm.thawRotation();
6969
} else {
70-
wm.freezeRotation();
70+
wm.freezeRotation(-1);
7171
}
7272
} catch (RemoteException exc) {
73+
Log.w(TAG, "Unable to save auto-rotate setting");
7374
}
7475
}
7576
});

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,10 +2947,7 @@ public int rotationForOrientationLw(int orientation, int lastRotation) {
29472947
// enable 180 degree rotation while docked.
29482948
preferredRotation = mDeskDockEnablesAccelerometer
29492949
? sensorRotation : mDeskDockRotation;
2950-
} else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
2951-
// Ignore sensor when user locked rotation.
2952-
preferredRotation = mUserRotation;
2953-
} else if ((mAccelerometerDefault != 0
2950+
} else if ((mAccelerometerDefault != 0 /* implies not rotation locked */
29542951
&& (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
29552952
|| orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED))
29562953
|| orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
@@ -2973,6 +2970,9 @@ public int rotationForOrientationLw(int orientation, int lastRotation) {
29732970
} else {
29742971
preferredRotation = lastRotation;
29752972
}
2973+
} else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
2974+
// Apply rotation lock.
2975+
preferredRotation = mUserRotation;
29762976
}
29772977

29782978
// TODO: Sometimes, we might want to override the application-requested
@@ -3018,8 +3018,8 @@ public int rotationForOrientationLw(int orientation, int lastRotation) {
30183018
return mPortraitRotation;
30193019

30203020
default:
3021-
// For USER, UNSPECIFIED and NOSENSOR, just return the preferred
3022-
// orientation we already calculated.
3021+
// For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
3022+
// just return the preferred orientation we already calculated.
30233023
if (preferredRotation >= 0) {
30243024
return preferredRotation;
30253025
}

services/java/com/android/server/wm/WindowManagerService.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5050,16 +5050,23 @@ public Bitmap screenshotApplications(IBinder appToken, int width, int height) {
50505050
/**
50515051
* Freeze rotation changes. (Enable "rotation lock".)
50525052
* Persists across reboots.
5053+
* @param rotation The desired rotation to freeze to, or -1 to use the
5054+
* current rotation.
50535055
*/
5054-
public void freezeRotation() {
5056+
public void freezeRotation(int rotation) {
50555057
if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
50565058
"freezeRotation()")) {
50575059
throw new SecurityException("Requires SET_ORIENTATION permission");
50585060
}
5061+
if (rotation < -1 || rotation > Surface.ROTATION_270) {
5062+
throw new IllegalArgumentException("Rotation argument must be -1 or a valid "
5063+
+ "rotation constant.");
5064+
}
50595065

50605066
if (DEBUG_ORIENTATION) Slog.v(TAG, "freezeRotation: mRotation=" + mRotation);
50615067

5062-
mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED, mRotation);
5068+
mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED,
5069+
rotation == -1 ? mRotation : rotation);
50635070
updateRotationUnchecked(false);
50645071
}
50655072

0 commit comments

Comments
 (0)