Android12 动态控制SystemUI状态栏和导航栏的显示和隐藏

1.首先屏蔽底部任务栏显示:

packages/apps/Launcher3/src/com/android/launcher3/config/FeatureFlags.java

diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
old mode 100644
new mode 100755
index 2d31aa4..15eadff
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -191,7 +191,7 @@ public final class FeatureFlags {
             + "predictions to be updated while they are visible to the user.");
 
     public static final BooleanFlag ENABLE_TASKBAR = getDebugFlag(
-            "ENABLE_TASKBAR", true, "Allows a system Taskbar to be shown on larger devices.");
+            "ENABLE_TASKBAR", false, "Allows a system Taskbar to be shown on larger devices.");
 
     public static final BooleanFlag ENABLE_TASKBAR_EDU = getDebugFlag("ENABLE_TASKBAR_EDU", true,
             "Enables showing taskbar education the first time an app is opened.");

frameworks/base/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java

diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java
index 8d98a75..6650989 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java
@@ -127,7 +127,7 @@ public class Utilities {
 
         float smallestWidth = dpiFromPx(Math.min(bounds.width(), bounds.height()),
                 context.getResources().getConfiguration().densityDpi);
-        return smallestWidth >= TABLET_MIN_DPS;
+        return false;
     }   
 
     public static float dpiFromPx(float size, int densityDpi) {

2.frameworks/base下面打上下面补丁:

diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index 27ece4b8e..b4d7e56 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -295,6 +295,16 @@
     <protected-broadcast android:name="com.android.settingslib.action.UNREGISTER_SLICE_RECEIVER" />
     <protected-broadcast android:name="com.android.settings.flashlight.action.FLASHLIGHT_CHANGED" />
 
+    <protected-broadcast android:name="com.systemui.statusbar.show" />
+    <protected-broadcast android:name="com.systemui.statusbar.hide" />
+
+    <!-- For NavigationBar show or not -->
+    <protected-broadcast android:name="com.systemui.navigationbar.show" />
+    <protected-broadcast android:name="com.systemui.navigationbar.hide" />
+
+    <protected-broadcast android:name="android.intent.action_disable_statusbar" />
+    <protected-broadcast android:name="android.intent.action_enable_statusbar" />
+
     <application
         android:name=".SystemUIApplication"
         android:persistent="true"
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
index a984974..f1748c0 100644
--- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
+++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
@@ -241,6 +241,13 @@ public class NavigationBarController implements
         }
     }
 
+	public void removeNavigationBars() {
+		Display[] displays = mDisplayManager.getDisplays();
+		for (Display display : displays) {
+			removeNavigationBar(display.getDisplayId());
+		}
+	}
+
     /**
      * Recreates the navigation bar for the given display.
      */
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index a6fb317..a5c0b47 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -313,6 +313,13 @@ public class StatusBar extends SystemUI implements
     public static final int[] CAMERA_LAUNCH_GESTURE_VIBRATION_AMPLITUDES =
             new int[]{39, 82, 139, 213, 0, 127};
 
+    private static final String ACTION_HIDE_STATUS_BAR = "com.systemui.statusbar.hide";
+    private static final String ACTION_SHOW_STATUS_BAR = "com.systemui.statusbar.show";
+    private static final String ACTION_HIDE_NAVIGATION_BAR = "com.systemui.navigationbar.hide";
+    private static final String ACTION_SHOW_NAVIGATION_BAR = "com.systemui.navigationbar.show";
+    private static final String SYS_PROPERTY_STATUS_BAR = "persist.sys.statusbar.enable";
+    private static final String SYS_PROPERTY_NAVIGATION_BAR = "persist.sys.navigationbar.enable";
+
     /**
      * If true, the system is in the half-boot-to-decryption-screen state.
      * Prudently disable QS and notifications.
@@ -967,6 +974,10 @@ public class StatusBar extends SystemUI implements
 
         createAndAddWindows(result);
 
+        if (!SystemProperties.getBoolean(SYS_PROPERTY_STATUS_BAR, true)) {
+            mStatusBarWindowController.setBarVisibility(View.GONE);
+        }
+
         if (mWallpaperSupported) {
             // Make sure we always have the most current wallpaper info.
             IntentFilter wallpaperChangedFilter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
@@ -1178,7 +1189,9 @@ public class StatusBar extends SystemUI implements
         mHeadsUpManager.addListener(mVisualStabilityManager);
         mNotificationPanelViewController.setHeadsUpManager(mHeadsUpManager);
 
-        createNavigationBar(result);
+        if (SystemProperties.getBoolean(SYS_PROPERTY_NAVIGATION_BAR, true)) {
+            createNavigationBar(result);
+        }
 
         if (ENABLE_LOCKSCREEN_WALLPAPER && mWallpaperSupported) {
             mLockscreenWallpaper = mLockscreenWallpaperLazy.get();
@@ -1406,6 +1419,10 @@ public class StatusBar extends SystemUI implements
         filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
         filter.addAction(Intent.ACTION_SCREEN_OFF);
         filter.addAction(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG);
+        filter.addAction(ACTION_HIDE_NAVIGATION_BAR);
+        filter.addAction(ACTION_SHOW_NAVIGATION_BAR);
+        filter.addAction(ACTION_HIDE_STATUS_BAR);
+        filter.addAction(ACTION_SHOW_STATUS_BAR);
         mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, null, UserHandle.ALL);
     }
 
@@ -2666,6 +2683,18 @@ public class StatusBar extends SystemUI implements
             }
             else if (DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG.equals(action)) {
                 mQSPanelController.showDeviceMonitoringDialog();
+            } else if (ACTION_HIDE_NAVIGATION_BAR.equals(action)) {
+                mNavigationBarController.removeNavigationBars();
+                SystemProperties.set(SYS_PROPERTY_NAVIGATION_BAR, "false");
+            } else if (ACTION_SHOW_NAVIGATION_BAR.equals(action)) {
+                createNavigationBar(null);
+                SystemProperties.set(SYS_PROPERTY_NAVIGATION_BAR, "true");
+            } else if (ACTION_HIDE_STATUS_BAR.equals(action)) {
+                mStatusBarWindowController.setBarVisibility(View.GONE);
+                SystemProperties.set(SYS_PROPERTY_STATUS_BAR, "false");
+            } else if (ACTION_SHOW_STATUS_BAR.equals(action)) {
+                mStatusBarWindowController.setBarVisibility(View.VISIBLE);
+                SystemProperties.set(SYS_PROPERTY_STATUS_BAR, "true");
             }
             Trace.endSection();
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java b/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java
index 85a6cd2..8405964 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java
@@ -315,4 +315,8 @@ public class StatusBarWindowController {
             mLpChanged.privateFlags &= ~PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR;
         }
     }
+
+	public void setBarVisibility(int visibility) {
+		mStatusBarWindowView.setVisibility(visibility);
+	}
 }

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值