Default display orientation in Android 8

cancel
Showing results for 
Search instead for 
Did you mean: 

Default display orientation in Android 8

3,200 Views
Contributor II

Hi,

on an i.MX6 SabreSD based board using the Android O8.0.0 release I'm trying to change the default display orientation to portrait mode.

Up until Android 7.1.2 this could be done setting ro.sf.hwrotation to 270 in the init.rc. Though an additional patch was needed, to rotate the touch input, too. But this doesn't work any more.

Is there another way to set the default display orientation?

Thank you and best regards

Thomas

Labels (3)
0 Kudos
8 Replies

262 Views
Contributor I

Hi,

I have been struggling with this issue off/on over the last couple weeks.

Seems like Android has an ever increasing truth table of how/and what you can do in the way of rotation.

I have an hdmi connected variscite dev board. Could not get it into reverse_landscape,..

Have tried the patches here: Gave me BSP,boot up control over orientation, but not application level Reverse_landscape.

For application level control (Oreo 8, hdmi display) the following worked for me.

Added to the onCreate in my app.

Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);// turn off rotation according to accelerometer
//Settings.System.putInt(getContentResolver(), Settings.System.USER_ROTATION, Surface.ROTATION_0);//landscape
//Settings.System.putInt(getContentResolver(), Settings.System.USER_ROTATION, Surface.ROTATION_90);//portrait
Settings.System.putInt(getContentResolver(), Settings.System.USER_ROTATION, Surface.ROTATION_180);//reverse landscape
//Settings.System.putInt(getContentResolver(), Settings.System.USER_ROTATION, Surface.ROTATION_270);//portrait

Add to manifest: (you may have to navigate SElinux permissions for this)

<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>

I believe I no longer "need" the above patches unless you want to control the orientation right from boot up.

Hope someone else finds this useful.

/***

Update: Still needs at least one of the patches described above. Default build doesn't work, but with patches it did 

***/

0 Kudos

262 Views
NXP Employee
NXP Employee

Hello,

Do you know what modifies the patch that you are mentioning?

Best Regards,

Diego.

0 Kudos

262 Views
Contributor II

Hi,

the patches are for frameworks/native and add the evaluation of the ro.sf.hwrotation property to SurfaceFlinger and InputReader. This seems deprecated as it was removed from ASOP a long while ago (but always added back by NXP). That's why I asked if there is another way to do the screen rotation. But in the meantime I was able to apply the patches to the O8 tag (see attached files).

Best regards

Thomas

0 Kudos

262 Views
NXP Employee
NXP Employee

Apparently, this is a feature that was removed by Google a long time ago. The last patch that we have in our possession is the one that you posted. You can apply it at your own risk, or you may go with professional services support and they can create a patch for you. I apologize for the inconveniences.

Best Regards,

Diego.

0 Kudos

262 Views
Contributor III

Hi Diego,

Are the following commands still exist in android 8.0 oreo? 

settings put system accelerometer_rotation 0
settings put system user_rotation 3

I can use them on android 7.1, but can't work on android 8.0.

Thx

Yen

0 Kudos

262 Views
Contributor I

I'm facing the same problem on Oreo for iMX6 board that only runs on landscape mode and the commands related to user_rotation has no effect. Has anyone tried to rotate the hdmi system orientation yet?

0 Kudos

262 Views
Contributor III

Hi Nilson,

Please try this patch 

diff --git a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 7407fd4..951e9fb 100644
--- a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -7110,11 +7110,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// been specified in the configuration (only for legacy devices without
// full multi-display support).
// Note that the dock orientation overrides the HDMI orientation.
- preferredRotation = mUndockedHdmiRotation;
+// modifided by Yen for screen rotation
+// preferredRotation = mUndockedHdmiRotation;
+ preferredRotation = mUserRotation;
+////
} else if (mDemoRotationLock) {
// Ignore sensor when demo rotation lock is enabled.
// Note that the dock orientation and HDMI rotation lock override this.
- preferredRotation = mDemoRotation;
+// modifided by Yen for screen rotation
+// preferredRotation = mDemoRotation;
+ preferredRotation = mUndockedHdmiRotation;
+////
} else if (mPersistentVrModeEnabled) {
// While in VR, apps always prefer a portrait rotation. This does not change
// any apps that explicitly set landscape, but does cause sensors be ignored,

Thx

Yen

0 Kudos

262 Views
Contributor III

Hello,

Any update?

Thx

Yen

0 Kudos