Setting default screen-orientation

1,881 views
Skip to first unread message

Dudero

unread,
Jan 13, 2011, 10:37:27 AM1/13/11
to android-porting
Hello,

I have nowhere found how to set the inital screen-orientation of an
android-build.
I know that this is possible in an Android-Activtiy or directly by
manipulating the Android-source...

But I think it should exists a "clean-solution" like a property which
can be set in "init.rc"-file?

In addition it would be a nice feature if it is possible to swich the
orientation by using a adb-shell-command?

Greetz dudero

Colin

unread,
Jan 17, 2011, 1:29:37 AM1/17/11
to android-porting
I have a question similar to this.
For an Android TV solution, it's better to fix the orientation to be
landscape.
How can I do this? Set some property?

Thanks and regards,
Colin

Dianne Hackborn

unread,
Jan 17, 2011, 5:51:43 PM1/17/11
to sinfa...@googlemail.com, android-porting
It is assumed that the screen's native orientation is the default orientation.  That is, the default orientation is whatever get when the software rotation of the screen is 0.

If you need to make your default orientation a rotation of the screen's natural frame buffer, you will need to modify PhoneWindowManager to do this.  And be very careful, it is easy to screw up the behavior of the overall platform there.

I would be happy to review a change that adds a configuration parameter for this.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Bram

unread,
Jan 24, 2011, 1:56:38 PM1/24/11
to android-porting
How is this native orientation defined? Is it based on the dimensions
that the screen reports? E.g. If it reports itself to be 1024x600, it
is assumed that it is natively landscape?

I have a chinese android tablet where I am trying to port froyo to. In
this case, the screen reports itself as 1024x600. The launcher starts
in landscape mode just fine. However, it seems they have messed up the
g-sensor, as rotation is off by 90 degrees. In their own official
firmware, it seems they fixed this somehow for at least the launcher,
but some applications still get it wrong.

What would the best way to fix this, when the drivers themselves
cannot be modified (no source) ?

Bram
On Jan 17, 11:51 pm, Dianne Hackborn <hack...@android.com> wrote:
> It is assumed that the screen's native orientation is the default
> orientation.  That is, the default orientation is whatever get when the
> software rotation of the screen is 0.
>
> If you need to make your default orientation a rotation of the screen's
> natural frame buffer, you will need to modify PhoneWindowManager to do this.
>  And be very careful, it is easy to screw up the behavior of the overall
> platform there.
>
> I would be happy to review a change that adds a configuration parameter for
> this.
>
>
>
> On Thu, Jan 13, 2011 at 7:37 AM, Dudero <sinfanh...@googlemail.com> wrote:
> > Hello,
>
> > I have nowhere found how to set the inital screen-orientation of an
> > android-build.
> > I know that this is possible in an Android-Activtiy or directly by
> > manipulating the Android-source...
>
> > But I think it should exists a "clean-solution" like a property which
> > can be set in "init.rc"-file?
>
> > In addition it would be a nice feature if it is possible to swich the
> > orientation by using a adb-shell-command?
>
> > Greetz dudero
>
> > --
> > unsubscribe: android-porti...@googlegroups.com<android-porting%2Bunsu...@googlegroups.com>
> > website:http://groups.google.com/group/android-porting
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com

Dianne Hackborn

unread,
Jan 24, 2011, 2:10:41 PM1/24/11
to avon...@gmail.com, android-porting
Yes it is just based on the screen size.

You'll need to modify something above the driver if you can't modify the driver itself.  I don't know what amount of sensor HAL was in Froyo, but maybe that.  Or if not you'd have to hack the framework.




--
Dianne Hackborn
Android framework engineer

Chinmay S

unread,
Jan 24, 2011, 2:20:08 PM1/24/11
to hac...@android.com, avon...@gmail.com, android-porting
Hi,

The sensors HAL is definitely where you should look to make these changes.

It should be a simple matter of swapping the values reported for x and y by the driver.
(and/or reversing the signs) to get the 90degree offset in orientation right.

The sensor-HAL for froyo being a single-file (Sensors.c) in either:
- hardware\sensors\ or
- device\<vendor>\<product>\sensors\

Just swap the vars accordingly for ACCEL_X & ACCEL_Y events in the
data_poll function implemented in Sensors.c

A little experimentation will give you the complete idea
of how acceleration values determine the orientation.

regards
CVS

Bram

unread,
Jan 26, 2011, 4:03:38 PM1/26/11
to android-porting
Thanks Dianne, Chinmay.

I investigated the proper HAL way, but it turns out that the device
(bma150) is implemented by the linux driver without support for the
input subsystem. E.g. there's no /dev/input/* device for it, just a
raw data device /dev/bma150. This differs from all the implementations
I've seen of the sensors.

I have no clue how the manufacturers implemented this, then. I suppose
they either faked a dummy input device, or just returned a bogus
filedescriptor for the input device requested by the hal interface.

I, instead, decided to adjust the base framework and swap the axes of
the accelerometer there. It seemed that, on the original firmware that
came shipped with the device, the orientation of the accelerometer was
also interpreted differently by multiple applications. E.g. the
launcher and browser behaved differently than some games. Might have
to do with the way they hacked it into android. So, I made it user-
configurable using a system property, and also added a system property
that will make the SensorManager optionally monitor for changes to the
axis swapping vector.

E.g., one can specify this as vector: "-y,x,z" which will swap x and
y, and invert y. And with the monitor property, one could write a
simple app that will allow the user to toggle between multiple setups.
So, in the end, I'm happy with doing this directly in the framework.

Patch that implements this in 2.2 can be found here:
https://github.com/stragulus/Flytouch-2-Frameworks-Base/commit/2d9355dd2de93f25db3977dd2367ab1558a5a765

I was dubbing whether I should spawn a separate thread to monitor the
changes to the swap settings, but chose to add it to the same thread
that broadcasts the sensor events to limit the extra bookkeeping
required for the thread. A drawback to this solution is that it will
call System.nanoTime() quite frequently. Is that bad? At least, this
way, when the sensor thread is cleaned up, this too will go away, not
hogging the system accidentally when the device goes in idle mode.

Andrew Prunicki

unread,
Jan 27, 2011, 9:50:14 AM1/27/11
to android...@googlegroups.com
I have made changes to support modifying the default screen orientation.  The work is part of a closed-source project, but it may be able to be released to AOSP.  I'll post back if it can be released.
Reply all
Reply to author
Forward
0 new messages