Android fw modify the system so that app follow the direction direction

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. Be sure to add reprint reprint https://blog.csdn.net/qq_23327993 https://blog.csdn.net/qq_23327993/article/details/88566902

Platform: qcom msm8953 android7.1

Phenomenon: customer app store to download the application or app in Android run our own board, the situation will be displayed in the opposite direction, such as the direction of the system is 90 °, running some app, open the app will be the direction of 270 °.

 

Solution:

1 idea: to sort out AndroidGUI system displays the frame, beginning from the bottom to go to sort out AndroidGUI display frame system, the results see of knowledge involved more and more, and finally look at the mind that is not sober, more confused, more Not to mention a solution to this bug. Began turning ideas 2;

Thinking 2: Before Android system has to find out about the rotary screen WMS and PMS is based, in addition, we have done some time Android application development, know Android application direction is set to be displayed by the application xml, thus binding the two point, begin by this talent.

 

First, find an article https://blog.csdn.net/jinzhuojun/article/details/50085491 , we can combine the reading at the source, I added a point were printed in PMS, and WMS, and then crawl will open app problem, found some of the information found in the produce screen rotation when I opened the app phenomenon in WMS will enter

updateRotationUncheckedLocked this method followed in this method, the operation shown in FIG. I found that in the process when the screen orientation has been modified to

Then saw the figure of a value assigned the right values ​​statement here come from it? Up to track the source we found that this method is the result of rotationForOrientationLw come, then this method in which to define and achieve it? Continue tracking can be seen in a method mPolicy, then continue to find where inherited this proxy class, eventually traced to find a PMS implementation of the method.

 @Override
    public int rotationForOrientationLw(int orientation, int lastRotation) {
        if (true) {
            Slog.v(TAG, "rotationForOrientationLw(orient="
                    + orientation + ", last=" + lastRotation
                    + "); user=" + mUserRotation + " "
                    + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
                    ? "USER_ROTATION_LOCKED" : "")
            );
        }

        .......

            if (DEBUG_LAYOUT) Slog.i(TAG, "orientation: " + orientation);

            if (getScreenWidth(mContext) < getScreenHeight(mContext)) {  //Determine the physical screen direction
                Slog.v(TAG, "width < height");
                switch (lastRotation) //Make the app direction follow system
                {
                    case Surface.ROTATION_0:
                        mPortraitRotation = Surface.ROTATION_0;  //shu  portrait
                        mUpsideDownRotation = Surface.ROTATION_180; // fan shu
                        mLandscapeRotation = Surface.ROTATION_90; // heng  landscape
                        mSeascapeRotation = Surface.ROTATION_270; //fan heng
                        break;
                    case Surface.ROTATION_90:
                        mPortraitRotation = Surface.ROTATION_90;  //shu  portrait
                        mUpsideDownRotation = Surface.ROTATION_270; // fan shu
                        mLandscapeRotation = Surface.ROTATION_0; // heng  landscape
                        mSeascapeRotation = Surface.ROTATION_180; //fan heng
                        break;
                    case Surface.ROTATION_180:
                        mPortraitRotation = Surface.ROTATION_180;  //shu  portrait
                        mUpsideDownRotation = Surface.ROTATION_0; // fan shu
                        mLandscapeRotation = Surface.ROTATION_270; // heng  landscape
                        mSeascapeRotation = Surface.ROTATION_90; //fan heng
                        break;
                    case Surface.ROTATION_270:
                        mPortraitRotation = Surface.ROTATION_270;  //shu  portrait
                        mUpsideDownRotation = Surface.ROTATION_90; // fan shu
                        mLandscapeRotation = Surface.ROTATION_180; // heng  landscape
                        mSeascapeRotation = Surface.ROTATION_0; //fan heng
                        break;
                }
            } else {
                Slog.v(TAG, "width > height");
                switch (lastRotation)//Make the app direction follow system
                {
                    case Surface.ROTATION_0:
                        mPortraitRotation = Surface.ROTATION_0;  //shu  portrait
                        mUpsideDownRotation = Surface.ROTATION_180; // fan shu
                        mLandscapeRotation = Surface.ROTATION_90; // heng  landscape
                        mSeascapeRotation = Surface.ROTATION_270; //fan heng
                        break;
                    case Surface.ROTATION_90:
                        mPortraitRotation = Surface.ROTATION_90;  //shu  portrait
                        mUpsideDownRotation = Surface.ROTATION_270; // fan shu
                        mLandscapeRotation = Surface.ROTATION_0; // heng  landscape
                        mSeascapeRotation = Surface.ROTATION_180; //fan heng
                        break;
                    case Surface.ROTATION_180:
                        mPortraitRotation = Surface.ROTATION_180;  //shu  portrait
                        mUpsideDownRotation = Surface.ROTATION_0; // fan shu
                        mLandscapeRotation = Surface.ROTATION_270; // heng  landscape
                        mSeascapeRotation = Surface.ROTATION_90; //fan heng
                        break;
                    case Surface.ROTATION_270:
                        mPortraitRotation = Surface.ROTATION_270;
                        mUpsideDownRotation = Surface.ROTATION_90;
                        mLandscapeRotation = Surface.ROTATION_180;
                        mSeascapeRotation = Surface.ROTATION_0;
                        break;
                }
            }

            switch (orientation) {
                case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:  //portrait
                    // Return portrait unless overridden.
                    if (isAnyPortrait(preferredRotation)) {
                        Slog.v(TAG, "preferredRotation:" + preferredRotation);
                        return preferredRotation;
                    }
                    Slog.v(TAG, "mPortraitRotation:" + mPortraitRotation);
                    return mPortraitRotation;

                case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: //landscape
                    // Return landscape unless overridden.
                    if (isLandscapeOrSeascape(preferredRotation)) {
                        return preferredRotation;
                    }
                    return mLandscapeRotation;

                case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: //reversePortrait >= api 9
                    // Return reverse portrait unless overridden.
                    if (isAnyPortrait(preferredRotation)) {
                        return preferredRotation;
                    }
                    return mUpsideDownRotation;

                case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: //reverseLandscape >= api 9
                    // Return seascape unless overridden.
                    if (isLandscapeOrSeascape(preferredRotation)) {
                        return preferredRotation;
                    }
                    return mSeascapeRotation;

                case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
                case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
                    // Return either landscape rotation.
                    if (isLandscapeOrSeascape(preferredRotation)) {
                        return preferredRotation;
                    }
                    if (isLandscapeOrSeascape(lastRotation)) {
                        return lastRotation;
                    }
                    return mLandscapeRotation;

                case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
                case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
                    // Return either portrait rotation.
                    if (isAnyPortrait(preferredRotation)) {
                        return preferredRotation;
                    }
                    if (isAnyPortrait(lastRotation)) {
                        return lastRotation;
                    }
                    return mPortraitRotation;

                default:
                    // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
                    // just return the preferred orientation we already calculated.
                    if (preferredRotation >= 0) {
                        return preferredRotation;
                    }
                    //return Surface.ROTATION_0;
                    return mDefaultOrientation;
            }
        }
    }

Code is slightly longer, omitted part, focused look at adding some methods in this print found on the app here is the classification of some cases by setting the xml configuration screen orientation process, we can see the figure switch (orientation) at here respectively corresponding to a number provided to the application layer, such as: "portrait", "landscape" and the like,

So the analysis here, I think it is not possible to do this process before the classification process, let app to follow the direction of the system, carried out an add code red mark at the final test run, OK, test passed! !

 

PS: horizontal screen seems a little problem, back then scrutinized.

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

WMS:frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java

Guess you like

Origin blog.csdn.net/qq_23327993/article/details/88566902