Screen rotation principle and process analysis in Android 6.0 development
This paper describes the principle and process of screen rotation in the development of Android 6.0. Share with you for your reference, as follows:
Starting from the development of Android system, here is the analysis of Android 6.0 screen rotation system.
Part I
Kenel
The screen rotation of Android system is realized by obtaining data from the underlying driver gsensor to judge the screen direction. The driver of the kernel sensor will not be described here. For a brief introduction, the gsensor driver registers input events. Under / dev / input /, you can view all input events of the system through ADB getevent - P. Gsensor provides acceleration data in X / Y / z directions. Once registered in the system and the hardware layer opens the device, the sensor starts reporting data. Note that this is very important. After the sensor driver is loaded, it will not be activated immediately. You need to open the device in the hardware layer to activate the device before the device starts to work.
Part II
Hardware
In the hardware layer, after registering Android standard modules, the device will be activated and registered in the Android system
Part III
framework
In updatesettings() in phonewindownmanager.java, read the setting mode of the screen in the system. Once automatic rotation is enabled, call updateorientationlistener lp() to start reading sensor data;
MOrientationListener.enable () is called in updateOrientationListenerLp. Call enable in windoworientationlistener.java to register the listening of gsensor
The type of M orientationjudge is orientationjudge, where the onsensorchanged method provides a method to calculate the direction from the acceleration data of gsensor in each direction. Once the screen direction change is calculated, the onproposedrotationchanged interface is called to notify the previous listener. Onproposedrotationchanged is an abstract method, which is implemented by subclasses and is also the myoorientationlistener class in phonewindowmanger
Call the updaterotation method in windowsmanagerservice
Attachment: how to dynamically disable or turn on screen rotation for Android
More readers interested in Android related content can view the special topics of this site: introduction and advanced tutorial of Android development, summary of Android view skills, summary of activity operation skills of Android programming, summary of Android file operation skills, summary of Android resource operation skills and summary of Android control usage
I hope this article will help you in Android programming.