Android 11 系统默认横屏显示

1,添加宏控制
  • device/mediatek/system/common/system.prop
//add start
persist.panel.orientation=270
//add end
2.开机动画横屏显示
  • frameworks/base/cmds/bootanimation/BootAnimation.cpp
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;

	// add start
	int defaultOrientation = 0;
	char property[PROPERTY_VALUE_MAX];
	property_get("persist.panel.orientation", property, "0");
	defaultOrientation = atoi(property)/90;
	
	// create the native surface
    sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
            (defaultOrientation==1 || defaultOrientation==3) ?resolution.getHeight():resolution.getWidth(), 
            (defaultOrientation==1 || defaultOrientation==3) ?resolution.getWidth():resolution.getHeight(), PIXEL_FORMAT_RGB_565);
	
	if (defaultOrientation==1){
        Rect destRect(resolution.getHeight(), resolution.getWidth());
        t.setDisplayProjection(mDisplayToken, ui::ROTATION_90, destRect, destRect);
    }

    if (defaultOrientation==3){
        Rect destRect(resolution.getHeight(), resolution.getWidth());
        t.setDisplayProjection(mDisplayToken, ui::ROTATION_270, destRect, destRect);
    }
    // add end
3.初始化方向
  • frameworks/native/services/surfaceflinger/DisplayDevice.cpp
	// add start
	#include <cutils/properties.h>
	// add end
	
	// add start
	int orientation = 0;
    ui::Rotation defaultOrientation = ui::ROTATION_0;
    char property[PROPERTY_VALUE_MAX];

    property_get("persist.panel.orientation", property, "0");
    ALOGD("readyToRun 1: %d", orientation);
    orientation = atoi(property);
    ALOGD("readyToRun 1: %d", orientation);
    switch(orientation) {
        case 0:
            defaultOrientation = ui::ROTATION_0;
            break;
        case 90:
            defaultOrientation = ui::ROTATION_90;
            break;
        case 180:
            defaultOrientation = ui::ROTATION_180;
            break;
        case 270:
            defaultOrientation = ui::ROTATION_270;
            break;
        default:
            defaultOrientation = ui::ROTATION_0;
            break;
    }
    // initialize the display orientation transform.
    //setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT);
    setProjection(defaultOrientation, Rect::INVALID_RECT, Rect::INVALID_RECT);
    // add end

android11 屏幕方向旋转相关代码DisplayRotation.java

4.上层方向修改
  • frameworks/base/services/core/java/com/android/server/wm/DisplayRotation.java
	//add start
    private int mDefaultOrientation = Surface.ROTATION_0;
    // end
    
    void configure(int width, int height, int shortSizeDp, int longSizeDp) {
        final Resources res = mContext.getResources();
        ....
        mDefaultFixedToUserRotation =
                (isCar || isTv || mService.mIsPc || forceDesktopMode)
                // For debug purposes the next line turns this feature off with:
                // $ adb shell setprop config.override_forced_orient true
                // $ adb shell wm size reset
                && !"true".equals(SystemProperties.get("config.override_forced_orient"));
                
        // add start
        String defaultOrientation = SystemProperties.get("persist.panel.orientation", "0");
        if("0".equals(defaultOrientation)) {
            mDefaultOrientation = Surface.ROTATION_0;
        } else if("90".equals(defaultOrientation)) {
            mDefaultOrientation = Surface.ROTATION_90;
        } else if("180".equals(defaultOrientation)) {
            mDefaultOrientation = Surface.ROTATION_180;
        } else if("270".equals(defaultOrientation)) {
            mDefaultOrientation = Surface.ROTATION_270;
        } else {
            mDefaultOrientation = Surface.ROTATION_0;
        }
        mRotation = mDefaultOrientation;
        //add end        
    }
    
    int rotationForOrientation(@ScreenOrientation int orientation,
            @Surface.Rotation int lastRotation) {
            ....
            default:
                // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
                // just return the preferred orientation we already calculated.
                if (preferredRotation >= 0) {
                    return preferredRotation;
                }
                // add start
                //return Surface.ROTATION_0;
                return mDefaultOrientation;
                // end
        }
    }
                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值