The fix got merged into AOSP master. There's no need to patch sources anymore, just sync your repository. Then, set def_user_rotation
at frameworks/base/packages/SettingsProvider/res/values/defaults.xml
as mentioned below and it should work.
Previous answer
There is a pair of config settings for default orientation in frameworks/base/packages/SettingsProvider/res/values/defaults.xml
:
def_accelerometer_rotation
- determines default value of accelerometer_rotation
from the other thread (it's set to false by default, so you should be fine)
def_user_rotation
- should determine default value of user_rotation
(so you can set it to value 1-4)
The problem is... the latter doesn't seem to be supported! The good part is AOSP is open source and you can fix it (precisely, fix DatabaseHelper.java
). Here is a patch I prepared for you (to apply against frameworks/base):
--- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -846,8 +846,8 @@ class DatabaseHelper extends SQLiteOpenHelper {
try {
stmt = db.compileStatement("INSERT INTO system(name,value)"
+ " VALUES(?,?);");
- loadBooleanSetting(stmt, Settings.System.USER_ROTATION,
- R.integer.def_user_rotation); // should be zero degrees
+ loadIntegerSetting(stmt, Settings.System.USER_ROTATION,
+ R.integer.def_user_rotation);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
@@ -2265,6 +2265,8 @@ class DatabaseHelper extends SQLiteOpenHelper {
loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,
R.bool.def_accelerometer_rotation);
+ loadIntegerSetting(stmt, Settings.System.USER_ROTATION, R.integer.def_user_rotation);
+
loadDefaultHapticSettings(stmt);
loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
After building and flashing patched system image (with the patch above and defaults.xml
changes), you can verify if the settings got correctly initialized:
adb shell settings get system user_rotation
(should not be null
)
adb shell settings get system accelerometer_rotation
(should be 0
)
Please let me know if it helped with your device - it did with mine. You may also need to set config.override_forced_orient
to true
, but it wasn't necessary with my Pixel 3a.