Android修改横屏的默认角度

默认的横屏角度是顺时针90度,修改为顺时针270度,即是逆时针90度。


1.查看相关逻辑,可以看到有个布尔值com.android.internal.R.bool.config_reverseDefaultRotation控制翻转:

frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

  @Override
    public void setInitialDisplaySize(Display display, int width, int height, int density) {
        // This method might be called before the policy has been fully initialized
        // or for other displays we don't care about.
        if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
            return;
        }
        mDisplay = display;

        final Resources res = mContext.getResources();
        int shortSize, longSize;
        if (width > height) {
            shortSize = height;
            longSize = width;
            mLandscapeRotation = Surface.ROTATION_0;
            mSeascapeRotation = Surface.ROTATION_180;
            if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
                mPortraitRotation = Surface.ROTATION_90;
                mUpsideDownRotation = Surface.ROTATION_270;
            } else {
                mPortraitRotation = Surface.ROTATION_270;
                mUpsideDownRotation = Surface.ROTATION_90;
            }
        } else {
            shortSize = width;
            longSize = height;
            mPortraitRotation = Surface.ROTATION_0;
            mUpsideDownRotation = Surface.ROTATION_180;
            if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
                mLandscapeRotation = Surface.ROTATION_270;
                mSeascapeRotation = Surface.ROTATION_90;
            } else {
                mLandscapeRotation = Surface.ROTATION_90;
                mSeascapeRotation = Surface.ROTATION_270;
            }
        }

        mStatusBarHeight =
                res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);

        // Height of the navigation bar when presented horizontally at bottom
        mNavigationBarHeightForRotation[mPortraitRotation] =
        mNavigationBarHeightForRotation[mUpsideDownRotation] =
                res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
        mNavigationBarHeightForRotation[mLandscapeRotation] =
        mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
                com.android.internal.R.dimen.navigation_bar_height_landscape);

        // Width of the navigation bar when presented vertically along one side
        mNavigationBarWidthForRotation[mPortraitRotation] =
        mNavigationBarWidthForRotation[mUpsideDownRotation] =
        mNavigationBarWidthForRotation[mLandscapeRotation] =
        mNavigationBarWidthForRotation[mSeascapeRotation] =
                res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);

        // SystemUI (status bar) layout policy
        int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
        int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;

        // Allow the navigation bar to move on small devices (phones).
        
        /// M: read the critical dp from mtk resource @{
        //mNavigationBarCanMove = shortSizeDp < 600;
        mNavigationBarCanMove = shortSizeDp < mContext.getResources().getInteger(
            com.mediatek.internal.R.integer.config_dp_for_rotation);
        /// @}
        mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);

        /// M:[SmartBook]Don't show navigation bar if SmartBook plugged in @{
        if (FeatureOption.MTK_SMARTBOOK_SUPPORT) {
            mNavigationBarCanMove = false;
            mHasNavigationBar = mSmartBookPlugIn ? false : mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_showNavigationBar);
            Slog.d(TAG, "mSmartBookPlugIn:" + mSmartBookPlugIn + ", mHasNavigationBar:" + mHasNavigationBar);
        }
        /// @}

        // Allow a system property to override this. Used by the emulator.
        // See also hasNavigationBar().
        String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
        if ("1".equals(navBarOverride)) {
            mHasNavigationBar = false;
        } else if ("0".equals(navBarOverride)) {
            mHasNavigationBar = true;
        }

        // For demo purposes, allow the rotation of the HDMI display to be controlled.
        // By default, HDMI locks rotation to landscape.
        if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
            mDemoHdmiRotation = mPortraitRotation;
        } else {
            mDemoHdmiRotation = mLandscapeRotation;
        }
        mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);

        // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
        // http://developer.android.com/guide/practices/screens_support.html#range
        mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
                res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
                // 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"));
    }


修改:frameworks/base/core/res/res/values/config.xml

<!-- If true, the direction rotation is applied to get to an application's requested
         orientation is reversed.  Normally, the model is that landscape is
         clockwise from portrait; thus on a portrait device an app requesting
         landscape will cause a clockwise rotation, and on a landscape device an
         app requesting portrait will cause a counter-clockwise rotation.  Setting
         true here reverses that logic. -->
    <bool name="config_reverseDefaultRotation">true</bool>
<think>好的,我现在需要帮助用户解决关于全志平台下Android 10实现开机默认横屏显示的问题。首先,我需要回忆相关的系统配置方法,尤其是全志平台的特殊处理。根据用户提供的引用内容,特别是引用[1]提到全志平台Android Q横屏竖用是通过补丁实现的,而引用[2]和[3]则涉及其他平台的配置,比如高通的qcom,mdss-dsi-panel-orientation和展讯平台的修改方法。 首先,全志平台的横屏设置可能涉及到设备树的配置,比如在设备树文件(dts)中调整显示方向参数。类似引用[2]中的qcom设置,全志可能也有对应的属性需要修改,例如旋转屏幕的角度,比如180度旋转。另外,系统属性如ro.sf.hwrotation可能在Android系统中用于设置硬件旋转,需要检查这个属性是否存在并正确配置。 其次,开机动画的横屏显示可能需要修改bootanimation的分辨率和方向。引用[3]提到展讯平台修改了充电动画的横屏显示,这可能涉及到修改动画的绘制方向或调整显示的分辨率参数。对于全志平台,可能需要调整bootanimation.zip中的desc.txt文件,确保动画资源是横屏的,或者在系统属性中设置ro.sf.hwrotation来影响开机动画的方向。 还需要考虑系统服务的配置,比如SurfaceFlinger,可能需要调整其方向参数。此外,检查是否有全志特有的补丁或配置文件需要应用,如引用[1]提到的补丁,可能需要查阅全志的官方文档或社区资源。 用户可能需要分步骤操作:修改设备树、设置系统属性、调整开机动画、测试验证。同时需要注意不同平台(如全志、高通、展讯)之间的差异,确保配置适用于全志的具体硬件和驱动实现。 最后,生成相关问题需要考虑用户可能的后续疑问,比如如何验证配置是否生效、如何处理旋转后的触摸坐标问题、其他显示相关配置的影响,以及如何恢复默认设置等。</think>### 全志平台 Android 10 开机默认横屏设置方法 #### 1. **修改显示方向参数(设备树配置)** 全志平台通常通过设备树(`dts`/`dtsi`)配置显示方向。在设备树文件中添加以下属性,强制屏幕旋转: ```c &disp { screen_rotation_mode = <1>; // 0-正常,1-旋转180度(根据需求调整) }; ``` 部分平台可能使用 `lcd_direction` 或 `display_rotation` 等参数,需参考全志文档[^1]。 #### 2. **设置系统属性** 在 `system.prop` 或 `build.prop` 中添加硬件旋转属性: ```properties ro.sf.hwrotation=180 # 旋转角度(0/90/180/270) ``` 此属性直接影响 SurfaceFlinger 的渲染方向。 #### 3. **调整开机动画方向** 修改 `bootanimation.zip` 的 `desc.txt` 文件,确保动画分辨率与横屏匹配: ``` 1080 1920 30 # 横屏分辨率(宽 高 帧率) p 1 0 part0 ``` 若动画方向异常,需重新制作横屏帧图片。 #### 4. **适配 SurfaceFlinger 配置** 在 `surfaceflinger.cpp` 中检查方向补偿逻辑,确保与硬件旋转一致: ```cpp // 若 ro.sf.hwrotation=180,需补偿旋转 SurfaceFlinger::setOrientation(DisplayState::eOrientation180); ``` #### 5. **验证配置** - **重启设备**:观察开机动画、Launcher 是否横屏。 - **检查日志**:通过 `logcat` 查看 `SurfaceFlinger` 和 `Display` 相关日志。 - **测试触控**:旋转后需验证触摸坐标映射是否正确。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值