Bootstrap

Android 13 大屏显示时关于SystemUI和Launcher3问题

当系统运行在大屏上时,原来显示SystemUI导航栏的位置会变成Launcher3的任务栏,然后导航栏的3个按键显示靠右下角显示
我的博客
1.先看SystemUI的导航栏为什么会消失,移动


/SystemUI/src/com/android/systemui/statusbar/NavigationBarController.java
    public void createNavigationBars(final boolean includeDefaultDisplay,
            RegisterStatusBarResult result) {
        //更新辅助功能按钮模式
        updateAccessibilityButtonModeIfNeeded();

        // 判断是否初始化TaskBar,不需要TaskBar就默认显示上创建导航栏
        final boolean shouldCreateDefaultNavbar = includeDefaultDisplay
                && !initializeTaskbarIfNecessary();
        Display[] displays = mDisplayManager.getDisplays();
        for (Display display : displays) {
            if (shouldCreateDefaultNavbar || display.getDisplayId() != DEFAULT_DISPLAY) {
                createNavigationBar(display, null /* savedState */, result);
            }
        }
    }
    
    /** @return {@code true} if taskbar is enabled, false otherwise */
    private boolean initializeTaskbarIfNecessary() {
        //判断是否是平板
        if (mIsTablet) {
            // Remove navigation bar when taskbar is showing
            //移除导航栏的时候任务栏显示
            Trace.beginSection("NavigationBarController#initializeTaskbarIfNecessary");
            removeNavigationBar(mContext.getDisplayId());
            mTaskbarDelegate.init(mContext.getDisplayId());
            Trace.endSection();
        } else {
            mTaskbarDelegate.destroy();
        }
        return mIsTablet;
    }
    ...
    {
        mIsTablet = isTablet(mContext);//如果判断它是平板
    }
    
/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java

    /** @return whether or not {@param context} represents that of a large screen device or not */
    @TargetApi(Build.VERSION_CODES.R)
    //如果屏幕的(最小边长度*160/dpi值)< 600,就会判断为设备是平板设备
    public static boolean isTablet(Context context) {
        final WindowManager windowManager = context.getSystemService(WindowManager.class);
        final Rect bounds = windowManager.getCurrentWindowMetrics().getBounds();
        
        float smallestWidth = dpiFromPx(Math.min(bounds.width(), bounds.height()),
                context.getResources().getConfiguration().densityDpi);
        //add text
        return false;//smallestWidth >= TABLET_MIN_DPS; 如果想要显示导航栏,直接返回false
        //add text
    }
    
    //判断屏幕dpi
    public static float dpiFromPx(float size, int densityDpi) {
        float densityRatio = (float) densityDpi / DisplayMetrics.DENSITY_DEFAULT;
        return (size / densityRatio);
    }
    

2.找到Launcher3显示任务栏的部分,也做类似的修改不让任务栏显示

/packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java

private void recreateTaskbar() {
    destroyExistingTaskbar();
    
    DeviceProfile dp = 
        mUserUnlocked ? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) : null;
    //add text    
    boolean isTaskBarEnabled = false;//dp != null && dp.isTaskbarPresent;
    //add text  
    if (!isTaskBarEnabled) {
            SystemUiProxy.INSTANCE.get(mContext)
                      .notifyTaskbarStatus(/* visible */ false, /* stashed */ false);
            return;
        }
    ...    
}

/Launcher3/src/com/android/launcher3/states/RotationHelper.java
    public static boolean getAllowRotationDefaultValue(DeviceProfile deviceProfile) {
        // If the device's pixel density was scaled (usually via settings for A11y), use the
        // original dimensions to determine if rotation is allowed of not.
        float originalSmallestWidth = dpiFromPx(
                Math.min(deviceProfile.widthPx, deviceProfile.heightPx), DENSITY_DEVICE_STABLE);
        //add text        
        return  false;//originalSmallestWidth >= MIN_TABLET_WIDTH;
        //add text 
    }
     
/Launcher3/src/com/android/launcher3/util/DisplayController.java

    /**
    * Returns {@code true} if the bounds represent a tablet.
    */
    public boolean isTablet(WindowBounds bounds) {
        //add text
        return false;//smallestSizeDp(bounds) >= MIN_TABLET_WIDTH;
        //add text
    }

/Launcher3/src/com/android/launcher3/util/window/WindowManagerProxy.java

public class WindowManagerProxy implements ResourceBasedOverride {
         Resources systemRes = context.getResources();
         Configuration config = systemRes.getConfiguration();
 
-        boolean isTablet = config.smallestScreenWidthDp > MIN_TABLET_WIDTH;
+        boolean isTablet = false;//config.smallestScreenWidthDp > MIN_TABLET_WIDTH;
         boolean isGesture = isGestureNav(context);
         boolean isPortrait = config.screenHeightDp > config.screenWidthDp;

 
-        boolean isTablet = swDp >= MIN_TABLET_WIDTH;
+        boolean isTablet = false;//swDp >= MIN_TABLET_WIDTH;
         boolean isTabletOrGesture = isTablet
                 || (Utilities.ATLEAST_R && isGestureNav(context));


Android 13 平板Taskbar加载流程

;