首页 > 其他分享 >android12 Settings 添加导航栏和状态栏开关

android12 Settings 添加导航栏和状态栏开关

时间:2024-06-05 15:45:29浏览次数:25  
标签:xml 状态栏 Settings android12 frameworks base packages revision

平台RK3568,android12 添加导航栏和状态栏的开关。

 通过设置系统属性来默认系统关闭导航栏和状态栏。

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";
+

@@ -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);
+    }
 }

 

通过广播来控制导航栏和状态栏。Settings和 frameworks的代码如下:

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

 

标签:xml,状态栏,Settings,android12,frameworks,base,packages,revision
From: https://www.cnblogs.com/dodo-asw/p/18233121

相关文章

  • .net6 类库 读取appsettings.json
    类库项目引入 Microsoft.Extensions.Configuration和 Microsoft.Extensions.Configuration.Json程序包以Sqlsugar读取配置文件为例:publicclassSqlsugarBase{publicstaticIConfigurationConfiguration{get;set;}staticSqlsugarBase()......
  • 解决MySQL安装卡在Start Service、Apply security settings问题
    一般进行1-3步骤即可。1.应用程序,卸载MySQL2.删除MySQL安装目录内容C:\ProgramFiles\MySQLC:\ProgramFiles(x86)\MySQL 3.删除MySQL数据存放目录,一般在C:\ProgramData\MySQL目录下(需要注意这个文件夹默认是隐藏的,要通过查看->隐藏的项目)4.删除注册表数据,通过regedit......
  • Settings里面切换不同Launcher的代码流程
    1.Android\packages\modules\Permission\PermissionController中的DefaultAppActivity中接收,根据packagename进行追踪路径如下:DefaultAppActivity.java--->HandheldDefaultAppFragment.java--->DefaultAppChildFragment.java:setDefaultApp()--->ManageRoleHolderState......
  • Biwen.Settings添加对IConfiguration&IOptions的集成支持
    Biwen.Settings是一个简易的配置项管理模块,主要的作用就是可以校验并持久化配置项,比如将自己的配置存储到数据库中,JSON文件中等使用上也是很简单,只需要在服务中注入配置,比如我们有一个GithubSetting的配置项,我们只需要定义好对象然后注入到Service中即可:[Descripti......
  • Zemax Optics Studio启动软件弹出Ansys Licensing Settings Utility
    博主在安装ZemaxOpticsStudio的过程中遇到了一个问题:安装完成后弹出AnsysLicensingSettingsUtility.解决方法:1.打开任务管理器,点击服务,确保“ANSYS,Inc.LicenseManagerCVD”服务和“ANSYSLicensingTomcat”服务状态是“正在运行”2.确保AnsysLicenseManagerRele......
  • C# app.config配置appSettings标签
    AppSettings标签主要用于应用程中的一些配置信息。比如上传文件的路径,需要用到的可能会根据不同环境改变的一些常量等。可以在配置文件添加可执行文件要的配置。usingSystem;usingSystem.Collections.Generic;usingSystem.Configuration;classProgram{staticvoid......
  • obsidian_plugins_settings
    settingsAdmonitionstitle:settingexample代码块类型:ad-{type}type对应表|Type|Aliases||---|---||note|note,seealso||abstract|abstract,summary,tldr||info|info,todo||tip|tip,hint,important||success|success,check,done||question|question,......
  • 中移铁通禹路由 ExportSettings 敏感信息泄露漏洞
    漏洞描述:该漏洞由于cgi-bin/ExportSettings.sh未对用户进行身份验证,导致攻击者能够未授权获取到路由器设置信息,包含了后台管理员用户的账号和密码fofa:title="互联世界物联未来-登录"鹰图:web.body="互联世界物联未来-登录"POC:GET/cgi-bin/ExportSettings.sh漏洞复现:......
  • Windows computer File share Settings
    1. Searchfor"Manageadvancedsharingsettings"intheWindowslowerleftcornerandclicktheresult.Asshownbelow①,② 2.Thenselectthetwoitemsinthepop-uppage,asshowninthefigure③ 3.Thensearchfor"TurnWindowsfeatu......
  • Windows Basics - Adjusting Your Settings
     AdjustingyoursettingsAtsomepoint,youmaywanttoadjustyourcomputer'ssettings.Forexample,youmightwanttochangeyourdesktopbackgroundormodifyyourInternetsettings.YoucanchangethesesettingsandmorefromtheControlPanel控制......