[高通SDM450][Android9.0]动态控制虚拟导航栏显示与隐藏

文章目录

    • 开发平台基本信息
    • 问题描述
    • 解决方法

开发平台基本信息

芯片: SDM450
版本: Android 9.0
kernel: msm-4.9

问题描述

虚拟导航栏原生默认是显示的,但是,作为智能硬件大部门客户都要求能够动态控制虚拟导航栏的显示与隐藏。动态设置可通过广播,在SystemUI接收到广播,去移除或者创建虚拟导航栏,并且将状态存到数据,在开机的时候读取数据库,去判断是否显示虚拟导航栏。

解决方法

--- 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
@@ -333,6 +333,12 @@ public class StatusBar extends SystemUI implements DemoMode,
      * libhwui.
      */
     private static final float SRC_MIN_ALPHA = 0.002f;
+       
+       private static final String ACTION_SYSTEMUI = "android.intent.action.systemui";
+       private static final String ACTION_NAVIGATION_BAR = "navigation_bar";
+       private static final String KEY_NAVIGATOR_BAR = "navigatorbar_isneed";
+       private static final String SHOW = "show";
+       private static final String DISMISS = "dismiss";
+       
+
 
     static {
         boolean onlyCoreApps;
@@ -749,6 +755,13 @@ public class StatusBar extends SystemUI implements DemoMode,
         internalFilter.addAction(BANNER_ACTION_SETUP);
         mContext.registerReceiver(mBannerActionBroadcastReceiver, internalFilter, PERMISSION_SELF,
                 null);
+                               
+               IntentFilter intentFilter1 = new IntentFilter();
+               intentFilter1.addAction(ACTION_SYSTEMUI);
+               mContext.registerReceiver(mStatusBarReceiver, intentFilter1);
+
 
         IVrManager vrManager = IVrManager.Stub.asInterface(ServiceManager.getService(
                 Context.VR_SERVICE));
@@ -877,9 +890,15 @@ public class StatusBar extends SystemUI implements DemoMode,
         try {
             boolean showNav = mWindowManagerService.hasNavigationBar();
             if (DEBUG) Log.v(TAG, "hasNavigationBar=" + showNav);
-            if (showNav) {
+            //判断NAVIGATOR_BAR值,显示、隐藏虚拟导航栏    
+            if(Settings.System.getString(context.getContentResolver(),KEY_NAVIGATOR_BAR,DISMISS).equals(SHOW)){
                 createNavigationBar();
             }
+
         } catch (RemoteException ex) {
             // no window manager? good luck with that
         }
@@ -2596,6 +2615,17 @@ public class StatusBar extends SystemUI implements DemoMode,
         if (mNavigationBar != null) mNavigationBar.checkNavBarModes();
         mNoAnimationOnNextBarModeChange = false;
     }
 
     // Called by NavigationBarFragment
     void setQsScrimEnabled(boolean scrimEnabled) {
@@ -3387,6 +3417,7 @@ public class StatusBar extends SystemUI implements DemoMode,
         }
         mContext.unregisterReceiver(mBroadcastReceiver);
         mContext.unregisterReceiver(mDemoReceiver);
+        mContext.unregisterReceiver(mDemoReceiver);
         mAssistManager.destroy();
 
         if (mQSPanel != null && mQSPanel.getHost() != null) {
@@ -5602,6 +5633,100 @@ public class StatusBar extends SystemUI implements DemoMode,
     public Handler getHandler() {
         return mHandler;
     }
+       
+       //控制虚拟导航栏开关
+       BroadcastReceiver mStatusBarReceiver = new BroadcastReceiver() {
+               @Override
+               public void onReceive(Context context, Intent intent) {
+                       if (intent != null && !TextUtils.isEmpty(intent.getAction())) {
+                               String action = intent.getAction();
+                               if(ACTION_SYSTEMUI.equals(action)) {
+                                   String navigationBarValue = intent.getStringExtra(ACTION_NAVIGATION_BAR);
+                                   if(navigationBarValue != null && SHOW.equals(navigationBarValue)){
+                                       if (null == mNavigationBarView) {
+											createNavigationBar();
+											Settings.System.putString(context.getContentResolver(), KEY_NAVIGATOR_BAR,SHOW);
+										}
+									}
+                                   if(navigationBarValue != null && DISMISS.equals(navigationBarValue)){
+                                       if (mNavigationBarView != null) {
+                                           synchronized (mNavigationBarView){
+                                       		mWindowManager.removeViewImmediate(mNavigationBarView);
+                                       		mNavigationBarView = null;
+                                       		Settings.System.putString(context.getContentResolver(), KEY_NAVIGATOR_BAR,DISMISS);
+                                       	}
+                                       }
+									}
+                                   Slog.e(TAG, "ACTION_SYSTEMUI。navigationBarValue : " + navigationBarValue);
+                               }
+                       }
+               }
+       };
+
 
     private final NotificationInfo.CheckSaveListener mCheckSaveListener =
             (Runnable saveImportance, StatusBarNotification sbn) -> {



你可能感兴趣的:(Android9.0,framework,虚拟导航栏,Android9.0,SystemUI)