Android 9.0 USER_ROTATION restart recovery problem analysis

Android 9.0 USER_ROTATION restart recovery problem analysis

Summary:

Recently, in the MTK platform 9.0 system, I encountered the problem that the system signature APK uses the method " System.putInt(contentResolver, "user_rotation", rotation); " to adjust the screen orientation, and the orientation always returns to the default orientation after restarting.

problem causes:

When a NavigationBarFragment of MtkSystemUI is initialized, user_rotation is reset

Adjust direction:

    protected void setScreenRotation(int rotation) {
        ContentResolver contentResolver = this.mActivity.getContentResolver();
        try {
            if (System.getInt(contentResolver, "accelerometer_rotation", 0) != 0) {
                System.putInt(contentResolver, "accelerometer_rotation", 0);
            }
        } catch (Exception e) {
        }
        try {
            if (rotation != System.getInt(contentResolver, "user_rotation", 0)) {
                System.putInt(contentResolver, "user_rotation", rotation);
            }
        } catch (Exception e2) {
        }
    }


simple mind map

Take the time to find a modified solution:
The following is a 9.0 system that I recently made using Xmind. The value of user_rotation will be reset every time the system is restarted. The problem analysis should start from bottom to top and gradually find the starting point of the problem.
flow chart:

insert image description here

Mind Map Description

The following content is to use xmind to export the md file of the mind map, and then import it into CSDN to generate it automatically

SystemUI

Location: frameworks/base/packages/SystemUI/

NavigationBarFragment.java

onCreate() initialization

By calling the function of RotationLockController in NavigationBarFragment

setRotationLockedAtAngle incoming parameters

  • onCreate


**Interface class: RotationLockController.java**

  • setRotationLockedAtAngle


RotationLockControllerImpl.java

Implement the RotationLockController interface

Implement setRotationLockedAtAngle

  • setRotationLockedAtAngle


RotationPolicy

位置:frameworks/base/core/java/com/android/internal/view/RotationPolicy.java

  • setRotationLockAtAngle

  • setRotationLock
    This function calls the WMS function freezeRotation through AsyncTask to fix the screen orientation


windowManagerService

位置:
frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java

  • freezeRotation
    fixed screen rotation


PhoneWindowManager

  • The main function of the setUserRotationMode
    function is to re-put the rotation to the SettingsProvider. At this time, all ContentObserver

Guess you like

Origin blog.csdn.net/xiaowang_lj/article/details/131312867