Changing Android Device orientation with ADB

Turn off the automatic rotation:

1
adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0

Rotate to landscape:

1
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1

Rotate portrait:

1
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0

You can also use 2 and 3 for upside-down portrait and reverse landscape respectively.