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;
}

 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值