前言
在Android系統(tǒng)中,狀態(tài)欄(StatusBar)贝咙、導(dǎo)航欄(NavigationBar)以及下拉菜單(通常稱為Notification Shade或Quick Settings Panel)構(gòu)成了用戶界面不可或缺的三個(gè)元素亚斋,它們共同為用戶提供了豐富的信息顯示與便捷的交互體驗(yàn)作媚。具體而言,狀態(tài)欄實(shí)時(shí)展示著時(shí)間帅刊、電池電量纸泡、信號(hào)強(qiáng)度等關(guān)鍵信息;導(dǎo)航欄則集成了如返回赖瞒、主頁及多任務(wù)管理等基礎(chǔ)操作按鈕女揭;而下拉菜單則讓用戶能夠迅速訪問快速設(shè)置項(xiàng)及通知詳情蚤假。
值得注意的是,盡管這些元素在多數(shù)Android設(shè)備上普遍存在且至關(guān)重要吧兔,但并非所有用戶或應(yīng)用場景都需要它們持續(xù)顯示磷仰。因此,Android系統(tǒng)提供了靈活的配置選項(xiàng)境蔼,允許用戶或開發(fā)者根據(jù)實(shí)際需求控制這些元素的顯示與隱藏狀態(tài)灶平。
在Android 13中,對(duì)于導(dǎo)航欄的動(dòng)態(tài)顯示與隱藏控制相較于之前版本有了更為簡化的處理方式箍土。通過利用廣播機(jī)制或其他系統(tǒng)接口逢享,開發(fā)者可以更加便捷地實(shí)現(xiàn)這些高級(jí)定制功能,為用戶帶來更加個(gè)性化和流暢的使用體驗(yàn)吴藻。同時(shí)瞒爬,這也意味著Android平臺(tái)在持續(xù)優(yōu)化其靈活性和可定制性,以更好地滿足不同用戶群體的多樣化需求了调缨。
修改示例
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
old mode 100644
new mode 100755
index 5c8d2212cef..ffd22dc73b1
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
@@ -496,4 +496,15 @@ public class NavigationBarController implements
mNavigationBars.valueAt(i).dump(pw);
}
}
+
+ /**
+ * Create by yeruilai 2024-8-22 10:23:59
+ */
+ public void removeNavigationBars() {
+ Display[] displays = mDisplayManager.getDisplays();
+ for (Display display : displays) {
+ removeNavigationBar(display.getDisplayId());
+ }
+ }
+
}
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
index f76470badf1..94cca11834b 100755
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
@@ -286,6 +286,15 @@ import dagger.Lazy;
public class CentralSurfacesImpl extends CoreStartable implements
CentralSurfaces {
+ // Create by yeruilai 2024-8-22 10:19:38 Dynamically display hidden navigation bar and status bar
+ 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 SYS_PROPERTY_STATUS_BAR = "persist.sys.statusbar.enable";
+ 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_NAVIGATION_BAR = "persist.sys.navigationbar.enable";
+
private static final String BANNER_ACTION_CANCEL =
"com.android.systemui.statusbar.banner_action_cancel";
private static final String BANNER_ACTION_SETUP =
@@ -1522,6 +1531,12 @@ public class CentralSurfacesImpl extends CoreStartable implements
filter.addAction(UnisocPowerManagerUtil.ACTION_POWEREX_SAVE_MODE_CHANGED);
}
/* @} */
+ // Create by yeruilai 2024-8-22 10:19:38 Dynamically display hidden navigation bar and status bar
+ filter.addAction(ACTION_HIDE_STATUS_BAR);
+ filter.addAction(ACTION_SHOW_STATUS_BAR);
+ filter.addAction(ACTION_HIDE_NAVIGATION_BAR);
+ filter.addAction(ACTION_SHOW_NAVIGATION_BAR);
+
mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, null, UserHandle.ALL);
}
@@ -2543,8 +2558,8 @@ public class CentralSurfacesImpl extends CoreStartable implements
@Override
public void createAndAddWindows(@Nullable RegisterStatusBarResult result) {
makeStatusBarView(result);
- mNotificationShadeWindowController.attach();
mStatusBarWindowController.attach();
+ mNotificationShadeWindowController.attach();
}
// called by makeStatusbar and also by PhoneStatusBarView
@@ -2870,6 +2885,29 @@ public class CentralSurfacesImpl extends CoreStartable implements
&& mDataSaverController.isDataSaverEnabled()) {
mDataSaverController.setDataSaverEnabled(false);
}
+ // Create by yeruilai 2024-8-22 10:19:38 Dynamically display hidden navigation bar and status bar
+ else if(ACTION_HIDE_STATUS_BAR.equals(action)){
+ android.util.Log.d("yeruilai","yeruilai:action=" + ACTION_HIDE_STATUS_BAR);
+
+ mStatusBarWindowController.hideStatusBar();
+ SystemProperties.set(SYS_PROPERTY_STATUS_BAR, "false");
+ } else if(ACTION_SHOW_STATUS_BAR.equals(action)){
+ android.util.Log.d("yeruilai","yeruilai:action=" + ACTION_SHOW_STATUS_BAR);
+
+ mStatusBarWindowController.showStatusBar();
+ SystemProperties.set(SYS_PROPERTY_STATUS_BAR, "true");
+ } else if(ACTION_HIDE_NAVIGATION_BAR.equals(action)){
+ android.util.Log.d("yeruilai","yeruilai:action=" + ACTION_HIDE_NAVIGATION_BAR);
+
+ mNavigationBarController.removeNavigationBars();
+ SystemProperties.set(SYS_PROPERTY_NAVIGATION_BAR, "false");
+ } else if(ACTION_SHOW_NAVIGATION_BAR.equals(action)){
+ android.util.Log.d("yeruilai","yeruilai:action=" + ACTION_SHOW_NAVIGATION_BAR);
+
+ createNavigationBar(null);
+ SystemProperties.set(SYS_PROPERTY_NAVIGATION_BAR, "true");
+ }
+
/* @} */
Trace.endSection();
}
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java
old mode 100644
new mode 100755
index e0d780a5fcd..08b4628f4c5
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/window/StatusBarWindowController.java
@@ -316,4 +316,42 @@ public class StatusBarWindowController {
mLpChanged.privateFlags &= ~PRIVATE_FLAG_FORCE_SHOW_STATUS_BAR;
}
}
+
+ /**
+ * Create by yeruilai 2024-8-22 10:23:59
+ */
+ private void apply(State state,boolean isHideStatus) {
+ if (!mIsAttached) {
+ return;
+ }
+ applyForceStatusBarVisibleFlag(state);
+ if (!isHideStatus){
+ applyHeight(state);
+ }
+ if (mLp != null && mLp.copyFrom(mLpChanged) != 0) {
+ mWindowManager.updateViewLayout(mStatusBarWindowView, mLp);
+ }
+ }
+
+ /**
+ * Create by yeruilai 2024-8-22 10:23:59
+ */
+ public void showStatusBar(){
+ apply(mCurrentState);
+ mStatusBarWindowView.setVisibility(View.VISIBLE);
+ }
+
+ /**
+ * Create by yeruilai 2024-8-22 10:23:59
+ */
+ public void hideStatusBar(){
+ mStatusBarWindowView.setVisibility(View.GONE);
+ mLpChanged.height = 0;
+ for (int rot = Surface.ROTATION_0; rot <= Surface.ROTATION_270; rot++) {
+ mLpChanged.paramsForRotation[rot].height = 0;
+ }
+ apply(mCurrentState,true);
+ }
+
}
添加相應(yīng)的SELinux權(quán)限疮鲫,代碼示例如下:
diff --git a/system/sepolicy/public/platform_app.te b/system/sepolicy/public/platform_app.te
index 3f689d82481..21a1f30d29f 100755
--- a/system/sepolicy/public/platform_app.te
+++ b/system/sepolicy/public/platform_app.te
@@ -7,3 +7,5 @@ allow platform_app system_app_data_file:dir r_dir_perms;
allow platform_app system_app_data_file:file r_file_perms;
#redstone
type platform_app, domain;
+
+allow platform_app system_prop:property_service set;
+
diff --git a/system/sepolicy/prebuilts/api/33.0/public/platform_app.te b/system/sepolicy/prebuilts/api/33.0/public/platform_app.te
index 3f689d82481..21a1f30d29f 100755
--- a/system/sepolicy/prebuilts/api/33.0/public/platform_app.te
+++ b/system/sepolicy/prebuilts/api/33.0/public/platform_app.te
@@ -7,3 +7,5 @@ allow platform_app system_app_data_file:dir r_dir_perms;
allow platform_app system_app_data_file:file r_file_perms;
#redstone
type platform_app, domain;
+
+allow platform_app system_prop:property_service set;
+