android10 dynamically displays and hides the navigation bar and status bar

Implementation method: Add a custom service in the frameworks, receive the upper-layer application broadcast, and then send the function of controlling display and hiding through this service, or the upper-layer application can send a broadcast to directly control the display and hiding, because there are other functions, so add it separately Made a service
modification:frameworks/base/core/res/AndroidManifest.xml

@@ -634,6 +634,12 @@
     <!-- For tether entitlement recheck-->
     <protected-broadcast
         android:name="com.android.server.connectivity.tethering.PROVISIONING_RECHECK_ALARM" />
+
+	<!--add by hclydao for broadcast -->
+	<protected-broadcast android:name="com.gzease.action.hide_nav_bar" />
+	<protected-broadcast android:name="com.gzease.action.show_nav_bar" />
+	<protected-broadcast android:name="com.gzease.action.hide_status_bar" />
+	<protected-broadcast android:name="com.gzease.action.show_status_bar" />
     <!-- ====================================================================== -->
     <!--                          RUNTIME PERMISSIONS                           -->
     <!-- ====================================================================== -->

Revise:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -316,7 +316,14 @@ public class StatusBar extends SystemUI implements DemoMode,
 
     /** If true, the lockscreen will show a distinct wallpaper */
     public static final boolean ENABLE_LOCKSCREEN_WALLPAPER = true;
-
+	//add by hclydao
+	private final String ACTION_HIDE_NAV_BAR = "com.gzease.action.hide_nav_bar";
+	private final String ACTION_SHOW_NAV_BAR = "com.gzease.action.show_nav_bar";
+	private final String ACTION_HIDE_STATUS_BAR = "com.gzease.action.hide_status_bar";
+	private final String ACTION_SHOW_STATUS_BAR = "com.gzease.action.show_status_bar";
+
+	private boolean isHideNavBar = false;
+	private boolean isHideStatusBar = false;
     static {
         boolean onlyCoreApps;
         try {
@@ -1011,6 +1018,11 @@ public class StatusBar extends SystemUI implements DemoMode,
         IntentFilter filter = new IntentFilter();
         filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
         filter.addAction(Intent.ACTION_SCREEN_OFF);
+		//add by hclydao
+		filter.addAction(ACTION_HIDE_NAV_BAR);
+		filter.addAction(ACTION_SHOW_NAV_BAR);
+		filter.addAction(ACTION_HIDE_STATUS_BAR);
+		filter.addAction(ACTION_SHOW_STATUS_BAR);
         filter.addAction(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG);
         context.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
 
@@ -2535,7 +2547,7 @@ public class StatusBar extends SystemUI implements DemoMode,
             return deferred;
         }, cancelAction, afterKeyguardGone);
     }
-
+	
     private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
@@ -2570,7 +2582,34 @@ public class StatusBar extends SystemUI implements DemoMode,
             }
             else if (DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG.equals(action)) {
                 mQSPanel.showDeviceMonitoringDialog();
-            }
+            } else if(action.equals(ACTION_HIDE_NAV_BAR)) { //add by hclydao
+				Log.d(TAG, "ACTION_HIDE_NAV_BAR isHideNavBar: " + isHideNavBar);
+				if(!isHideNavBar) {
+					isHideNavBar = true;
+					mNavigationBarController.onDisplayRemoved(mDisplayId);
+				}
+			} else if(action.equals(ACTION_SHOW_NAV_BAR)) {
+				Log.d(TAG, "ACTION_SHOW_NAV_BAR isHideNavBar: " + isHideNavBar);
+				if(isHideNavBar) {
+					isHideNavBar = false;
+					mNavigationBarController.onDisplayReady(mDisplayId);
+				}
+			} else if(action.equals(ACTION_HIDE_STATUS_BAR)) {
+				Log.d(TAG, "ACTION_HIDE_STATUS_BAR isHideStatusBar: " + isHideStatusBar);
+				if(!isHideStatusBar) {
+					isHideStatusBar = true;
+					//mStatusBarView.setVisibility(View.GONE);//如果同时要隐藏导航栏和状态栏可以只使用这一个,不会出现bug
+					mStatusBarWindowController.setBarHeight(0);//一定要加这个,不然removeViewImmediate后更新mStatusBarWindowController会出现bug
+					mWindowManager.removeViewImmediate(mStatusBarWindow);
+				}
+			} else if(action.equals(ACTION_SHOW_STATUS_BAR)) {
+				Log.d(TAG, "ACTION_SHOW_STATUS_BAR isHideStatusBar: " + isHideStatusBar);
+				if(isHideStatusBar) {
+					isHideStatusBar = false;
+					mStatusBarWindowController.add(mStatusBarWindow, getStatusBarHeight());
+					//mStatusBarView.setVisibility(View.VISIBLE);//如果同时要隐藏导航栏和状态栏可以只使用这一个,不会出现bug
+				}
+			} //add end
         }
     };
 
@@ -3666,17 +3705,23 @@ public class StatusBar extends SystemUI implements DemoMode,
     final ScreenLifecycle.Observer mScreenObserver = new ScreenLifecycle.Observer() {
         @Override
         public void onScreenTurningOn() {
+			if(isHideStatusBar) //add by hclydao 使用setVisibility隐藏时不用加
+				return;
             mFalsingManager.onScreenTurningOn();
             mNotificationPanel.onScreenTurningOn();
         }
 
         @Override
         public void onScreenTurnedOn() {
+			if(isHideStatusBar) //add by hclydao 使用setVisibility隐藏时不用加
+				return;
             mScrimController.onScreenTurnedOn();
         }
 
         @Override
         public void onScreenTurnedOff() {
+			if(isHideStatusBar) //add by hclydao 使用setVisibility隐藏时不用加
+				return;
             mFalsingManager.onScreenOff();
             mScrimController.onScreenTurnedOff();
             updateIsKeyguard();

Instructions for displaying and hiding the status bar
If you only use mStatusBarView.setVisibility(View.GONE);to hide and use mStatusBarView.setVisibility(View.VISIBLE);to display, all the content in the status bar is hidden when hiding, but the height of the status bar is still there, and it still takes up space. The upper application needs to be set to full screen display In order to completely hide the position of the status bar, that is to add in the upper application

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);

This modification does not have the risk of systemui exceptions.
However, some customers request to display the navigation bar but hide the status bar. This method cannot be used at this time. When hiding, the status bar needs to be completely removed. When using this method, several places need to be modified, otherwise systemui will be abnormal.
When using the completely hidden method, you need to modify
it. Modify:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java

@@ -328,6 +328,12 @@ public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable,
     }
 
     private void updateRegionForNotch(Region region) {
+		//add by hclydao
+		if(mStatusBarWindowView == null)
+			return;
+		if(mStatusBarWindowView.getRootWindowInsets() == null)
+			return;
+		//add end
         DisplayCutout cutout = mStatusBarWindowView.getRootWindowInsets().getDisplayCutout();
         if (cutout == null) {
             return;

Reviseframeworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowController.java

@@ -322,7 +322,8 @@ public class StatusBarWindowController implements Callback, Dumpable, Configurat
         applyNotTouchable(state);
         applyStatusBarColorSpaceAgnosticFlag(state);
         if (mLp != null && mLp.copyFrom(mLpChanged) != 0) {
-            mWindowManager.updateViewLayout(mStatusBarView, mLp);
+			if(mBarHeight != 0) //add by hclydao
+	            mWindowManager.updateViewLayout(mStatusBarView, mLp);
         }
         if (mHasTopUi != mHasTopUiChanged) {
             try {

Prompt when closing app full screen

Reviseframeworks/base/services/core/java/com/android/server/wm/ImmersiveModeConfirmation.java

@@ -54,7 +54,7 @@ import android.widget.Button;
 import android.widget.FrameLayout;
 
 import com.android.internal.R;
-
+import android.os.SystemProperties; //add by hclydao
 /**
  *  Helper to manage showing/hiding a confirmation prompt when the navigation bar is hidden
  *  entering immersive mode.
@@ -326,6 +326,9 @@ public class ImmersiveModeConfirmation {
 
             mContext.registerReceiver(mReceiver,
                     new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
+			if(!SystemProperties.getBoolean("gzease.fullnotify",false)) { //add by hclydao
+				mConfirm.run();//add by hclydao no fullscreen notify
+			}
         }
 
         @Override

Guess you like

Origin blog.csdn.net/xiaowang_lj/article/details/131282219