Android12 隐藏状态栏导航栏

客户需要开机就隐藏导航栏和状态栏,平台是RK3568,代码整理如下:

Index: device/rockchip/rk356x/device.mk
===================================================================
--- device/rockchip/rk356x/device.mk	(revision 2442)
+++ device/rockchip/rk356x/device.mk	(revision 2443)
@@ -97,4 +97,6 @@
                 ro.kernel.android.checkjni=0 \
                 ro.build.shutdown_timeout=6 \
                 persist.enable_task_snapshots=false \
-                ro.vendor.frameratelock=true
+                ro.vendor.frameratelock=true \
+                persist.sys.statusbar.enable=false \
+                persist.sys.navigationbar.enable=false
\ No newline at end of file
Index: frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
===================================================================
--- frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java	(revision 2442)
+++ frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java	(revision 2443)
@@ -313,6 +313,9 @@
     public static final int[] CAMERA_LAUNCH_GESTURE_VIBRATION_AMPLITUDES =
             new int[]{39, 82, 139, 213, 0, 127};
 
+    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.
@@ -966,6 +969,9 @@
         }
 
         createAndAddWindows(result);
+        if (!SystemProperties.getBoolean(SYS_PROPERTY_STATUS_BAR, false)) {
+            mStatusBarWindowController.setBarVisibility(View.GONE);
+        }
 
         if (mWallpaperSupported) {
             // Make sure we always have the most current wallpaper info.
@@ -1178,7 +1184,9 @@
         mHeadsUpManager.addListener(mVisualStabilityManager);
         mNotificationPanelViewController.setHeadsUpManager(mHeadsUpManager);
 
-        createNavigationBar(result);
+        if (SystemProperties.getBoolean(SYS_PROPERTY_NAVIGATION_BAR, false)) {
+            createNavigationBar(result);
+        }
 
         if (ENABLE_LOCKSCREEN_WALLPAPER && mWallpaperSupported) {
             mLockscreenWallpaper = mLockscreenWallpaperLazy.get();
Index: frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java
===================================================================
--- frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java	(revision 2442)
+++ frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java	(revision 2443)
@@ -315,4 +315,8 @@
             mLpChanged.privateFlags &= ~PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR;
         }
     }
+
+    public void setBarVisibility(int visibility) {
+        mStatusBarWindowView.setVisibility(visibility);
+    }
 }

通过属性 persist.sys.statusbar.enable,persist.sys.navigationbar.enable来控制状态栏和导航栏,false隐藏,true是显示。

在设置里面添加状态栏和导航栏的开关。代码如下:

Index: frameworks/base/packages/SystemUI/AndroidManifest.xml
===================================================================
--- frameworks/base/packages/SystemUI/AndroidManifest.xml    (revision 2443)
+++ frameworks/base/packages/SystemUI/AndroidManifest.xml    (revision 2444)
@@ -295,6 +295,14 @@
     <protected-broadcast android:name="com.android.settingslib.action.UNREGISTER_SLICE_RECEIVER" />
     <protected-broadcast android:name="com.android.settings.flashlight.action.FLASHLIGHT_CHANGED" />
 
+    <!-- For statusbar show or not -->
+    <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" />
+
     <application
         android:name=".SystemUIApplication"
         android:persistent="true"
Index: frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
===================================================================
--- frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java    (revision 2443)
+++ frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java    (revision 2444)
@@ -431,4 +431,11 @@
             mNavigationBars.valueAt(i).dump(pw);
         }
     }
+    
+    public void removeNavigationBars() {
+        Display[] displays = mDisplayManager.getDisplays();
+        for (Display display : displays) {
+            removeNavigationBar(display.getDisplayId());
+        }
+    }
 }
Index: frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
===================================================================
--- frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java    (revision 2443)
+++ frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java    (revision 2444)
@@ -313,6 +313,10 @@
     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";
 
@@ -1414,6 +1418,10 @@
         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);
     }
 
@@ -2674,7 +2682,19 @@
             }
             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();
         }
     };
Index: packages/apps/Settings/res/values/strings.xml
===================================================================
--- packages/apps/Settings/res/values/strings.xml    (revision 2443)
+++ packages/apps/Settings/res/values/strings.xml    (revision 2444)
@@ -13714,6 +13714,8 @@
     <string name="dialog_getting_screen_info">getting screen info...</string>
     <string name="dialog_update_resolution">Updating resolution...</string>
     <string name="dialog_wait_screen_connect">please wait while updating info to the device...</string>
+    <string name="ctrl_statusbar">StatusBar</string>
+    <string name="ctrl_navigationbar">NavigationBar</string>
         
     <string name="how_to_shutdown">Shutdown Immediately</string>
     <string name="how_to_shutdown_summary">Shutdown Immediately with no confirm</string>
Index: packages/apps/Settings/res/values-zh-rCN/strings.xml
===================================================================
--- packages/apps/Settings/res/values-zh-rCN/strings.xml    (revision 2443)
+++ packages/apps/Settings/res/values-zh-rCN/strings.xml    (revision 2444)
@@ -5608,4 +5608,7 @@
     <string name="screenshot_delay_title">延时截屏设置 </string>
     <string name="screenshot_show_title">在状态栏上显示截屏按钮</string>
     <string name="later">秒以后截屏</string>
+    
+    <string name="ctrl_statusbar">状态栏</string>
+     <string name="ctrl_navigationbar">导航栏</string>
 </resources>
Index: packages/apps/Settings/res/xml/display_settings.xml
===================================================================
--- packages/apps/Settings/res/xml/display_settings.xml    (revision 2443)
+++ packages/apps/Settings/res/xml/display_settings.xml    (revision 2444)
@@ -104,6 +104,14 @@
         android:title="@string/category_name_display_controls">
 
         <SwitchPreference
+            android:key="ctrl_statusbar"
+            android:title="@string/ctrl_statusbar"/>
+
+        <SwitchPreference
+            android:key="ctrl_navigationbar"
+            android:title="@string/ctrl_navigationbar"/>
+
+        <SwitchPreference
             android:key="auto_rotate"
             android:title="@string/accelerometer_title"
             settings:keywords="@string/keywords_auto_rotate"
Index: packages/apps/Settings/src/com/android/settings/DisplaySettings.java
===================================================================
--- packages/apps/Settings/src/com/android/settings/DisplaySettings.java    (revision 2443)
+++ packages/apps/Settings/src/com/android/settings/DisplaySettings.java    (revision 2444)
@@ -30,6 +30,8 @@
 import com.android.settings.display.TapToWakePreferenceController;
 import com.android.settings.display.ThemePreferenceController;
 import com.android.settings.display.VrDisplayPreferenceController;
+import com.android.settings.display.StatusBarPreferenceController;
+import com.android.settings.display.NavigationBarPreferenceController;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settingslib.core.AbstractPreferenceController;
 import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -85,6 +87,8 @@
         controllers.add(new ThemePreferenceController(context));
         controllers.add(new BrightnessLevelPreferenceController(context, lifecycle));
         controllers.add(new HdmiSettingsPreferenceController(context, KET_HDMI_SETTINGS));
+        controllers.add(new StatusBarPreferenceController(context));
+        controllers.add(new NavigationBarPreferenceController(context));
         return controllers;
     }
 
Index: packages/apps/Settings/src/com/android/settings/display/NavigationBarPreferenceController.java
===================================================================
--- packages/apps/Settings/src/com/android/settings/display/NavigationBarPreferenceController.java    (nonexistent)
+++ packages/apps/Settings/src/com/android/settings/display/NavigationBarPreferenceController.java    (revision 2444)
@@ -0,0 +1,76 @@
+package com.android.settings.display;
+ 
+import android.content.Context;
+import android.provider.Settings;
+import androidx.preference.SwitchPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+ 
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+import android.content.Intent;
+import android.util.Log;
+import android.os.SystemProperties;
+ 
+public class NavigationBarPreferenceController extends AbstractPreferenceController
+        implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+ 
+    private static final String TAG = "NavigationBarCtrl";
+    private static final boolean DEBUG = true;
+    private static final String KEY_NAVIGATION_BAR = "ctrl_navigationbar";
+    public static final String ACTION_HIDE_NAVIGATION_BAR = "com.systemui.navigationbar.hide";
+    public static final String ACTION_SHOW_NAVIGATION_BAR = "com.systemui.navigationbar.show";
+ 
+    public NavigationBarPreferenceController(Context context) {
+        super(context);
+    }
+ 
+    @Override
+    public String getPreferenceKey() {
+        return KEY_NAVIGATION_BAR;
+    }
+ 
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+ 
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        if (!isAvailable()) {
+            setVisible(screen, KEY_NAVIGATION_BAR, false /* visible */);
+            return;
+        }
+ 
+        final SwitchPreference mNavigationBarPreference = screen.findPreference(KEY_NAVIGATION_BAR);
+        if (mNavigationBarPreference != null) {
+            String value = SystemProperties.get("persist.sys.navigationbar.enable", "false");
+            mNavigationBarPreference.setChecked(value.equals("true"));
+            mNavigationBarPreference.setOnPreferenceChangeListener(this);
+        }
+    }
+ 
+    @Override
+    public void updateState(Preference preference) {
+        String value = SystemProperties.get("persist.sys.navigationbar.enable", "false");
+        ((SwitchPreference) preference).setChecked(value.equals("true"));
+    }
+ 
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        boolean value = (Boolean) newValue;
+        if (DEBUG) {
+            Log.d(TAG, "key value " + value);
+        }
+ 
+        Intent intent = new Intent();
+        if (value) {
+            intent.setAction(ACTION_SHOW_NAVIGATION_BAR);
+        } else {
+            intent.setAction(ACTION_HIDE_NAVIGATION_BAR);
+        }
+        mContext.sendBroadcast(intent);
+        return true;
+    }
+}
+ 
\ No newline at end of file

Property changes on: packages/apps/Settings/src/com/android/settings/display/NavigationBarPreferenceController.java
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: packages/apps/Settings/src/com/android/settings/display/StatusBarPreferenceController.java
===================================================================
--- packages/apps/Settings/src/com/android/settings/display/StatusBarPreferenceController.java    (nonexistent)
+++ packages/apps/Settings/src/com/android/settings/display/StatusBarPreferenceController.java    (revision 2444)
@@ -0,0 +1,75 @@
+package com.android.settings.display;
+ 
+import android.content.Context;
+import android.provider.Settings;
+import androidx.preference.SwitchPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+ 
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+import android.content.Intent;
+import android.util.Log;
+import android.os.SystemProperties;
+ 
+public class StatusBarPreferenceController extends AbstractPreferenceController implements
+        PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+ 
+    private static final String TAG = "StatusBarCtrl";
+    private static final boolean DEBUG = true;
+    private static final String KEY_STATUS_BAR = "ctrl_statusbar";
+    public static final String ACTION_HIDE_STATUS_BAR = "com.systemui.statusbar.hide";
+    public static final String ACTION_SHOW_STATUS_BAR = "com.systemui.statusbar.show";
+ 
+    public StatusBarPreferenceController(Context context) {
+        super(context);
+    }
+ 
+    @Override
+    public String getPreferenceKey() {
+        return KEY_STATUS_BAR;
+    }
+ 
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+ 
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        if (!isAvailable()) {
+            setVisible(screen, KEY_STATUS_BAR, false /* visible */);
+            return;
+        }
+ 
+        final SwitchPreference mStatusBarPreference = screen.findPreference(KEY_STATUS_BAR);
+        if (mStatusBarPreference != null) {
+            String value = SystemProperties.get("persist.sys.statusbar.enable", "false");
+            mStatusBarPreference.setChecked(value.equals("true"));
+            mStatusBarPreference.setOnPreferenceChangeListener(this);
+        }
+    }
+ 
+    @Override
+    public void updateState(Preference preference) {
+        String value = SystemProperties.get("persist.sys.statusbar.enable", "false");
+        ((SwitchPreference) preference).setChecked(value.equals("true"));
+    }
+ 
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        boolean value = (Boolean) newValue;
+        if (DEBUG) {
+            Log.d(TAG, "key value " + value);
+        }
+ 
+        Intent intent = new Intent();
+        if (value) {
+            intent.setAction(ACTION_SHOW_STATUS_BAR);
+        } else {
+            intent.setAction(ACTION_HIDE_STATUS_BAR);
+        }
+        mContext.sendBroadcast(intent);
+        return true;
+    }
+}
\ No newline at end of file

Property changes on: packages/apps/Settings/src/com/android/settings/display/StatusBarPreferenceController.java
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

 

posted @ 2023-12-19 16:57  simple雨  阅读(985)  评论(0编辑  收藏  举报