动态关闭状态栏和导航栏

2024-05-15  本文已影响0人  gale_小米

需求部分应用情况下不允许弹出状态栏和导航栏

 frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java
===================================================================
@@ -1268,7 +1268,7 @@
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     }
 
-    private int getNavBarHeight() {
+    public int getNavBarHeight() {
         return mIsVertical
                 ? getResources().getDimensionPixelSize(
                 com.android.internal.R.dimen.navigation_bar_height_landscape)
frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
===================================================================
@@ -159,6 +159,12 @@
 import java.util.function.Consumer;
 
 import dagger.Lazy;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.SystemProperties;
+import android.view.ViewGroup;



+    private NavigationBarFrame mFrame;
+    private WindowManager.LayoutParams mLp;
+    private int mNavigationBarHeight;
+
     public View createView(Bundle savedState) {
         WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                 WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
@@ -550,16 +560,17 @@
         lp.setTitle("NavigationBar" + mContext.getDisplayId());
         lp.setFitInsetsTypes(0 /* types */);
         lp.setTrustedOverlay();
-
-        NavigationBarFrame frame = (NavigationBarFrame) LayoutInflater.from(mContext).inflate(
+        mFrame = (NavigationBarFrame) LayoutInflater.from(mContext).inflate(
                 R.layout.navigation_bar_window, null);
-        View barView = LayoutInflater.from(frame.getContext()).inflate(
-                R.layout.navigation_bar, frame);
+        View barView = LayoutInflater.from(mFrame.getContext()).inflate(
+                R.layout.navigation_bar, mFrame);
         barView.addOnAttachStateChangeListener(this);
         mNavigationBarView = barView.findViewById(R.id.navigation_bar_view);
 
         if (DEBUG) Log.v(TAG, "addNavigationBar: about to add " + barView);
-        mContext.getSystemService(WindowManager.class).addView(frame, lp);
+        mNavigationBarHeight = mNavigationBarView.getNavBarHeight();
+        mLp=lp;
+        mContext.getSystemService(WindowManager.class).addView(mFrame, lp);
         mDisplayId = mContext.getDisplayId();
         mIsOnDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
 
@@ -609,9 +620,39 @@
 
         setAccessibilityFloatingMenuModeIfNeeded();
 
+        Log.e(TAG, "registerReceiver mNavigationBarReceiver");
+        
+        IntentFilter localeChangedFilter = new IntentFilter(HIDE_NAV_BAR_ACTION);
+        localeChangedFilter.addAction(SHOW_NAV_BAR_ACTION);
+        mContext.registerReceiver(mNavigationBarReceiver, localeChangedFilter);
         return barView;
     }
 
+    private boolean mHasNavigationBar=true;
+    private static String HIDE_NAV_BAR_ACTION = "com.dj.hideNavigationBar";
+    private static String SHOW_NAV_BAR_ACTION = "com.dj.showNavigationBar";
+
+    BroadcastReceiver mNavigationBarReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (HIDE_NAV_BAR_ACTION.equals(intent.getAction())) {
+                mHasNavigationBar = false;
+            }else if (SHOW_NAV_BAR_ACTION.equals(intent.getAction())) {
+                mHasNavigationBar = true;
+            }
+            //Log.e(TAG, "mNavigationBarReceiver mHasNavigationBar="+mHasNavigationBar+","+intent.getAction());
+            if (mFrame !=null) {
+                mHandler.post(() -> {
+                    ViewGroup.LayoutParams layoutParams =(ViewGroup.LayoutParams) mNavigationBarView.getLayoutParams();
+                    layoutParams.height = mHasNavigationBar?mNavigationBarHeight:0;
+                    Log.e(TAG, "layoutParams.height="+layoutParams.height);
+                    mNavigationBarView.setLayoutParams(layoutParams);
+                    mNavigationBarView.invalidate();
+                });
+            }
+        }
+    };
+
     public void destroyView() {
         setAutoHideController(/* autoHideController */ null);
         mCommandQueue.removeCallback(this);
@@ -1580,6 +1621,9 @@
     }
 
     public boolean isNavBarWindowVisible() {
+        if (!mHasNavigationBar) {
+            return false;
+        }
         return mNavigationBarWindowState == WINDOW_STATE_SHOWING;
     }
 
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
===================================================================
@@ -47,6 +47,12 @@
 
 import java.util.List;
 import java.util.Objects;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.util.Log;
+import android.os.SystemProperties;
 
 public class PhoneStatusBarView extends PanelBar {
     private static final String TAG = "PhoneStatusBarView";
@@ -87,12 +93,34 @@
     private int mCutoutSideNudge = 0;
     private boolean mHeadsUpVisible;
 
+    private boolean mHasStatusBar=true;
+    private static final String PROPERTY_NAME = "persist.sys.hideNavigationBar";
     public PhoneStatusBarView(Context context, AttributeSet attrs) {
         super(context, attrs);
         mCommandQueue = Dependency.get(CommandQueue.class);
         mContentInsetsProvider = Dependency.get(StatusBarContentInsetsProvider.class);
+
+        IntentFilter localeChangedFilter = new IntentFilter(HIDE_NAV_BAR_ACTION);
+        localeChangedFilter.addAction(SHOW_NAV_BAR_ACTION);
+        context.registerReceiver(mNavigationBarReceiver, localeChangedFilter);
     }
 
+
+    private static String HIDE_NAV_BAR_ACTION = "com.dj.hideNavigationBar";
+    private static String SHOW_NAV_BAR_ACTION = "com.dj.showNavigationBar";
+
+    BroadcastReceiver mNavigationBarReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            //Log.e(TAG, "mNavigationBarReceiver action=" + intent.getAction());
+            if (HIDE_NAV_BAR_ACTION.equals(intent.getAction())) {
+                mHasStatusBar = false;
+            }else if (SHOW_NAV_BAR_ACTION.equals(intent.getAction())) {
+                mHasStatusBar = true;
+            }
+            updateResources();
+        }
+    };
     public void setBar(StatusBar bar) {
         mBar = bar;
     }
@@ -312,12 +340,15 @@
     }
 
     private void updateStatusBarHeight() {
-        final int waterfallTopInset =
-                mDisplayCutout == null ? 0 : mDisplayCutout.getWaterfallInsets().top;
         ViewGroup.LayoutParams layoutParams = getLayoutParams();
-        mStatusBarHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_height);
-        layoutParams.height = mStatusBarHeight - waterfallTopInset;
-
+        if (mHasStatusBar) {
+            final int waterfallTopInset =
+                    mDisplayCutout == null ? 0 : mDisplayCutout.getWaterfallInsets().top;
+            mStatusBarHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_height);
+            layoutParams.height = mStatusBarHeight - waterfallTopInset;
+        }else{
+            layoutParams.height = 0;
+        }
         int statusBarPaddingTop = getResources().getDimensionPixelSize(
                 R.dimen.status_bar_padding_top);
         int statusBarPaddingStart = getResources().getDimensionPixelSize(
Index: frameworks/base/services/core/java/com/android/server/wm/ActivityRecord.java
===================================================================
+                //是否显示导航栏
+                String hideNavigationBar=SystemProperties.get("persist.sys.hideNavigationBar","false");
+                Log.e(TAG_WM, "hideNavigationBar: "+ hideNavigationBar);
+                if (info.name.contains("RemoteDeskActivity")) {
+                   if (hideNavigationBar.equals("false")) {
+                       mAtmService.mContext.sendBroadcast(new Intent("com.dj.hideNavigationBar"));
+                       SystemProperties.set("persist.sys.hideNavigationBar", "true");
+                   }
+                }else{
+                   if (hideNavigationBar.equals("true")) {
+                       mAtmService.mContext.sendBroadcast(new Intent("com.dj.showNavigationBar"));
+                       SystemProperties.set("persist.sys.hideNavigationBar", "false");
+                   }
+                }
Index: frameworks/base/core/res/AndroidManifest.xml
===================================================================
@@ -707,6 +707,8 @@
     <protected-broadcast android:name="android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED" />
     <protected-broadcast android:name="android.app.action.ACTION_SHOW_NEW_USER_DISCLAIMER" />
 
+    <protected-broadcast android:name="com.dj.hideNavigationBar" />
+    <protected-broadcast android:name="com.dj.showNavigationBar" />
     <!-- ====================================================================== -->
     <!--                          RUNTIME PERMISSIONS                           -->
     <!-- ====================================================================== -->


上一篇下一篇

猜你喜欢

热点阅读