Android 13上是可以根据dpi来判断机器是平板模式还是手机模式,我的设备分辨率是2000x1200,当我们利用 adb shell -> wm density 获取当前dpi然后执行 wm density 320会发现Launcher发生了变化,此时会有布局改变以及锁屏改变,还有hotseat显示不全,导航栏变小靠右等问题,所以我们的思路是在变为平板模式后不要让Launcher和SystemUI改变即可。
改完后我们还需验证下QQ和微信是否为平板模式
ProjectConfig.mk
#density
FREEME_DEVICE_LCD_DENSITY = 320
路径:vendor/mediatek/proprietary/packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
private void recreateTaskbar() {
destroyExistingTaskbar();
DeviceProfile dp =
mUserUnlocked ? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) : null;
//*/soda water.20230906 Tablet mode
boolean isTaskBarEnabled = false;
/*/
boolean isTaskBarEnabled = dp != null && dp.isTaskbarPresent;
//*/
if (!isTaskBarEnabled) {
SystemUiProxy.INSTANCE.get(mContext)
.notifyTaskbarStatus(/* visible */ false, /* stashed */ false);
return;
}
路径:vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/util/DisplayController.java
public boolean isTablet(WindowBounds bounds) {
//*/soda water.20230906 Tablet mode
return false;
/*/
return smallestSizeDp(bounds) >= MIN_TABLET_WIDTH;
//*/
}
路径:vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/util/window/WindowManagerProxy.java
public WindowInsets normalizeWindowInsets(Context context, WindowInsets oldInsets,
Rect outInsets) {
if (!Utilities.ATLEAST_R || !mTaskbarDrawnInProcess) {
outInsets.set(oldInsets.getSystemWindowInsetLeft(), oldInsets.getSystemWindowInsetTop(),
oldInsets.getSystemWindowInsetRight(), oldInsets.getSystemWindowInsetBottom());
return oldInsets;
}
WindowInsets.Builder insetsBuilder = new WindowInsets.Builder(oldInsets);
Insets navInsets = oldInsets.getInsets(WindowInsets.Type.navigationBars());
Resources systemRes = context.getResources();
Configuration config = systemRes.getConfiguration();
//*/soda water.20230906 Tablet mode
boolean isTablet = false;
/*/
boolean isTablet = config.smallestScreenWidthDp > MIN_TABLET_WIDTH;
//*/
boolean isGesture = isGestureNav(context);
boolean isPortrait = config.screenHeightDp > config.screenWidthDp;
//第二处修改
Resources systemRes;
{
Configuration conf = new Configuration();
conf.smallestScreenWidthDp = swDp;
systemRes = context.createConfigurationContext(conf).getResources();
}
//*/soda water.20230906 Tablet mode
boolean isTablet = false;
/*/
boolean isTablet = swDp >= MIN_TABLET_WIDTH;
/*/
boolean isTabletOrGesture = isTablet
|| (Utilities.ATLEAST_R && isGestureNav(context));
int statusBarHeightPortrait = getDimenByName(systemRes,
STATUS_BAR_HEIGHT_PORTRAIT, STATUS_BAR_HEIGHT);
int statusBarHeightLandscape = getDimenByName(systemRes,
STATUS_BAR_HEIGHT_LANDSCAPE, STATUS_BAR_HEIGHT);
以上 Launcher3修改是防止 launcher变为平板模式的样式导致显示不全
路径: overlay/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw600dp-port/dimens.xml
修改:下拉栏左右边距问题
0dp
路径:vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
mStatusBarKeyguardViewManager = statusBarKeyguardViewManager;
mTaskbarDelegate.setDependencies(commandQueue, overviewProxyService,
navBarHelper, navigationModeController, sysUiFlagsContainer,
dumpManager, autoHideController, lightBarController, pipOptional,
backAnimation.orElse(null));
//*/soda water.20230906 Tablet mode
mIsTablet = false;
/*/
mIsTablet = isTablet(mContext);
//*/
dumpManager.registerDumpable(this);
}
@Override
public void onConfigChanged(Configuration newConfig) {
boolean isOldConfigTablet = mIsTablet;
//*/soda water.20230906 Tablet mode
mIsTablet = false;
/*/
mIsTablet = isTablet(mContext);
//*/
boolean largeScreenChanged = mIsTablet != isOldConfigTablet;
// If we folded/unfolded while in 3 button, show navbar in folded state, hide in unfolded
if (largeScreenChanged && updateNavbarForTaskbar()) {
return;
}
public void onDisplayReady(int displayId) {
Display display = mDisplayManager.getDisplay(displayId);
//*/soda water.20230906 Tablet mode
mIsTablet = false;
/*/
mIsTablet = isTablet(mContext);
//*/
createNavigationBar(display, null /* savedState */, null /* result */);
}
路径:vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
private void setNavigationIconHints(int hints) {
if (hints == mNavigationIconHints) return;
//*/soda water.20230906 Tablet mode
if (true) {
/*/
if (!isTablet(mContext)) {
//*/
// All IME functions handled by launcher via Sysui flags for large screen
final boolean newBackAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0;
路径:vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/recents/ScreenPinningRequest.java
if (!QuickStepContract.isGesturalMode(mNavBarMode)
&& wm.hasSoftNavigationBar(mContext.getDisplayId()) /*&& !isTablet(mContext)) soda water.20230906 Tablet mode*/) {
buttons.setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE);
swapChildrenIfRtlAndVertical(buttons);
}
以上修改防止UI界面变得现实不全 导航栏显示问题
完成后微信会识别成平板模式但QQ不会
路径:build/core/product_config.mk
ifndef PRODUCT_CHARACTERISTICS
TARGET_AAPT_CHARACTERISTICS := tablet
else
TARGET_AAPT_CHARACTERISTICS := $(PRODUCT_CHARACTERISTICS)
endif
改完后QQ就会变为平板模式