RK3128 Android 7.1 默认竖屏

该文详细介绍了如何在Android系统中通过修改`ro.sf.hwrotation`属性来设置屏幕旋转,包括在`WindowManagerService`和`BootAnimation`中的调整,以实现强制竖屏和解决开机动画旋转问题的方法。
摘要由CSDN通过智能技术生成

配置ro.sf.hwrotation为竖屏

ro.sf.hwrotation=270

ro.sf.hwrotation=0表示不旋转 ro.sf.hwrotation=90表示旋转90°
ro.sf.hwrotation=180表示旋转180° ro.sf.hwrotation=270表示旋转270°

首先强制进入桌面后竖屏

frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java里面修改WindowManagerService

boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
         long ident = Binder.clearCallingIdentity();
         try {
             // int req = getOrientationLocked();
             /*SCREEN_ORIENTATION_LANDSCAPE :横屏显示,SCREEN_ORIENTATION_PORTRAIT : 竖屏显示*/
           	 int req = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; 
             if (req != mLastOrientation) {
                 mLastOrientation = req;

但是这样会有个问题,就是如果机器默认是横屏,你强制进入桌面是竖屏的话,会在进入桌面前,自动旋转,而这个旋转会导致开机动画旋转错乱

解决开机动画旋转:

frameworks/base/cmds/bootanimation/BootAnimation.cpp

BootAnimation::BootAnimation(bool shutdown) : Thread(false), mClockEnabled(true), mTimeIsAccurate(false),
        mTimeFormat12Hour(false), mTimeCheckThread(NULL) {
    mSession = new SurfaceComposerClient();

    // If the system has already booted, the animation is not being used for a boot.
    mSystemBoot = !property_get_bool(BOOT_COMPLETED_PROP_NAME, 0);
    mShutdown = shutdown;
    mReverseAxis = false;
    mVideoFile = NULL;
    mVideoAnimation = false;
//注释mShotdown判断, 启动时, 方向有可能设置为0以外的数值
    //if(mShutdown){
        sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
                                        ISurfaceComposer::eDisplayIdMain)); // primary_display_token
        DisplayInfo dinfo;
        status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
        if (status == OK) {
            ALOGD("DISPLAY,W-H: %d-%d, ori: %d", dinfo.w, dinfo.h, dinfo.orientation);

//解决启动时方向错误, 其中, 变量 rot根据需要的方向设置[0, 3];			
			int rot = 1;//90度
			if (rot >= 0) {
				int w = dinfo.w;
				int h = dinfo.h;
				if(rot == 1 || rot == 3){//竖屏时, xy轴需要对调
					mReverseAxis=true;
					h = dinfo.w;
					w = dinfo.h;
				}else{
					mReverseAxis=false;
				}

				Rect layerStackRect(w, h);
				Rect displayRect(0, 0, w, h);
				SurfaceComposerClient::setDisplayProjection(dtoken, rot, layerStackRect, displayRect);
			}

        }
    //}
}

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

    sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
            ISurfaceComposer::eDisplayIdMain));
    DisplayInfo dinfo;
    status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
    if (status)
        return -1;

    // create the native surface
    int curWidth = dinfo.w;
    int curHeight = dinfo.h;
//注释 mShutdown, 屏幕旋转不只发生在关机动画时.
    if(/*mShutdown && */mReverseAxis){
        curWidth = dinfo.h;
        curHeight = dinfo.w;
    }
//...省略代码
}

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

    private WindowManagerService(Context context, InputManagerService inputManager,
            boolean haveInputMethods, boolean showBootMsgs, boolean onlyCore) {
		//... 省略代码
        // Add ourself to the Watchdog monitors.
        Watchdog.getInstance().addMonitor(this);

//设置默认旋转方向, 与动画的默认方向保持一致
		mRotation = Surface.ROTATION_90;

        SurfaceControl.openTransaction();
        try {
            createWatermarkInTransaction();
        } finally {
            SurfaceControl.closeTransaction();
        }

        showEmulatorDisplayOverlayIfNeeded();
    }

    /**
     * Updates the current rotation.
     *
     * Returns true if the rotation has been changed.  In this case YOU
     * MUST CALL sendNewConfiguration() TO UNFREEZE THE SCREEN.
     */
    public boolean updateRotationUncheckedLocked(boolean inTransaction) {
//省略大量代码
        if (DEBUG_ORIENTATION) {
            Slog.v(TAG_WM, "Selected orientation "
                    + mLastOrientation + ", got rotation " + rotation
                    + " which has " + (altOrientation ? "incompatible" : "compatible")
                    + " metrics");
        }
//保持默认方向
        /*if (mRotateOnBoot) {
             mRotation = Surface.ROTATION_0;
             rotation = Surface.ROTATION_90;
        }*/

        if (mRotation == rotation && mAltOrientation == altOrientation) {
            // No change.
             return false;
        }
//省略大量代码
	}

最终更新屏幕显示:
frameworks/base/services/core/java/com/android/server/display/DisplayDevice.java

    /**
     * Sets the display projection while in a transaction.
     *
     * @param orientation defines the display's orientation
     * @param layerStackRect defines which area of the window manager coordinate
     *            space will be used
     * @param displayRect defines where on the display will layerStackRect be
     *            mapped to. displayRect is specified post-orientation, that is
     *            it uses the orientation seen by the end-user
     */
    public final void setProjectionInTransactionLocked(int orientation,
            Rect layerStackRect, Rect displayRect) {
        if (mCurrentOrientation != orientation
                || mCurrentLayerStackRect == null
                || !mCurrentLayerStackRect.equals(layerStackRect)
                || mCurrentDisplayRect == null
                || !mCurrentDisplayRect.equals(displayRect)) {
            mCurrentOrientation = orientation;

            if (mCurrentLayerStackRect == null) {
                mCurrentLayerStackRect = new Rect();
            }
            mCurrentLayerStackRect.set(layerStackRect);

            if (mCurrentDisplayRect == null) {
                mCurrentDisplayRect = new Rect();
            }
            mCurrentDisplayRect.set(displayRect);
//与Bootanimation中的函数类似
            SurfaceControl.setDisplayProjection(mDisplayToken,
                    orientation, layerStackRect, displayRect);
        }
    }

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值