Android Q(10) 默认横屏

直接上代码

开机动画(android那个动画) 横屏就改这些cpp h,但是在动画界面一段时间后,还是会竖屏,必须加下面的java代码。

frameworks/base/cmds/bootanimation/BootAnimation.h

添加枚举

private:
    virtual bool        threadLoop();
    virtual status_t    readyToRun();
    virtual void        onFirstRef();
    virtual void        binderDied(const wp<IBinder>& who);

    //aaron add
    enum {
        eOrientationDefault     = 0,
        eOrientation90          = 1,
        eOrientation180         = 2,
        eOrientation270         = 3,
    };
    //end

    bool                updateIsTimeAccurate();

frameworks/base/cmds/bootanimation/BootAnimation.cpp

status_t BootAnimation::readyToRun() {
    mAssets.addDefaultAssets();

    mDisplayToken = SurfaceComposerClient::getInternalDisplayToken();
    if (mDisplayToken == nullptr)
        return -1;

    DisplayInfo dinfo;
    status_t status = SurfaceComposerClient::getDisplayInfo(mDisplayToken, &dinfo);
    if (status)
        return -1;

    //aaron add
    if (eOrientation90) {
        int temp = dinfo.h;
        dinfo.h = dinfo.w;
        dinfo.w = temp;
    }
    Rect destRect(dinfo.w, dinfo.h);

    SurfaceComposerClient::Transaction t;
    t.setDisplayProjection(mDisplayToken, eOrientation90, destRect, destRect);
    t.apply();
    //end

    // create the native surface
    sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
            dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);

    //aaron delete
    //SurfaceComposerClient::Transaction t;


    t.setLayer(control, 0x40000000)
        .apply();

 

frameworks/base/core/java/com/android/internal/view/RotationPolicy.java

把NATURAL_ROTATION改成Surface.ROTATION_90,原来是Surface.ROTATION_0


/**
 * Provides helper functions for configuring the display rotation policy.
 */
public final class RotationPolicy {


    public static final int NATURAL_ROTATION = Surface.ROTATION_90;


}

 

frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java

省略了代码,只把修改到的代码贴出来了。

    /**
     * Current rotation of the display.
     * Constants as per {@link android.view.Surface.Rotation}.
     *
     * @see #updateRotationUnchecked()
     */

    private int mRotation = 1;
    

    boolean updateRotationUnchecked(boolean forceUpdate) {

        final int oldRotation = mWmService.mBootAnimationStopped ? mRotation:ROTATION_90;


    }


    private DisplayInfo updateDisplayAndOrientation(int uiMode, Configuration outConfig) {

        final int appWidth = mDisplayPolicy.getNonDecorDisplayWidth(dw, dh, mWmService.mBootAnimationStopped ?mRotation:ROTATION_90, uiMode,
                displayCutout);
        final int appHeight = mDisplayPolicy.getNonDecorDisplayHeight(dw, dh, mWmService.mBootAnimationStopped ?mRotation:ROTATION_90, uiMode,
                displayCutout);

    }

@CallSuper
    @Override
    public void writeToProto(ProtoOutputStream proto, long fieldId,
            @WindowTraceLogLevel int logLevel) {

    proto.write(ROTATION, mWmService.mBootAnimationStopped ? mRotation:ROTATION_90);

    }

 

这边不改的话,launcher就不会横屏,其他app都会横屏了。

frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java

最后返回ROTATION_90

int rotationForOrientation(int orientation, int lastRotation) {

    return Surface.ROTATION_90;
}

 


版权声明:本文为Aaron121314原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。