android 11.0 增加控制状态栏和导航栏的接口

这篇博客介绍了在Android系统中增加和控制状态栏及导航栏的接口实现,包括`NavigationBarController`、`NavigationBarFragment`、`PhoneStatusBarView`和`StatusBar`等类的修改,涉及隐藏和显示导航栏的功能,并添加了广播接收器以响应设置导航栏显示状态的意图。
摘要由CSDN通过智能技术生成

 

增加控制状态栏和导航栏的接口,代码如下

 

 

 

 

 .../statusbar/NavigationBarController.java    |   6 +-
 .../phone/NavigationBarFragment.java          |   9 +-
 .../statusbar/phone/PhoneStatusBarView.java   |   7 +-
 .../systemui/statusbar/phone/StatusBar.java   |  31 +++-
 packages/apps/Settings/AndroidManifest.xml    |  61 ++++++-
 .../ShellSettingsBroadcastReceiver.java       | 163 ++++++++++++++++++
 6 files changed, 262 insertions(+), 15 deletions(-)
 mode change 100644 => 100755 frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/NavigationBarController.java
 mode change 100644 => 100755 frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
 mode change 100644 => 100755 frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
 mode change 100644 => 100755 frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
 create mode 100755 packages/apps/Settings/src/com/android/settings/ShellSettingsBroadcastReceiver.java

diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/NavigationBarController.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/NavigationBarController.java
old mode 100644
new mode 100755
index 8c24c540e7..17339243da
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/NavigationBarController.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/NavigationBarController.java
@@ -155,7 +155,7 @@ public class NavigationBarController implements Callbacks {
             navBar.setAutoHideController(autoHideController);
             navBar.restoreAppearanceAndTransientState();
             mNavigationBars.append(displayId, navBar);
-
+			mDisplayId = displayId;
             if (result != null) {
                 navBar.setImeWindowStatus(display.getDisplayId(), result.mImeToken,
                         result.mImeWindowVis, result.mImeBackDisposition,
@@ -163,6 +163,10 @@ public class NavigationBarController implements Callbacks {
             }
         });
     }
+    private int mDisplayId;
+    public void removeNavigationBarView(){
+        removeNavigationBar(mDisplayId);
+    }
 
     private void removeNavigationBar(int displayId) {
         NavigationBarFragment navBar = mNavigationBars.get(displayId);
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
old mode 100644
new mode 100755
index 27daf8615a..ec10f7e438
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
@@ -320,9 +320,10 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
                 buttonDispatcher = mNavigationBarView.getHomeHandle();
             }
             if (buttonDispatcher != null) {
-                buttonDispatcher.setVisibility(
-                        (forceVisible || alpha > 0) ? View.VISIBLE : View.INVISIBLE);
-                buttonDispatcher.setAlpha(forceVisible ? 1f : alpha, animate);
+           //     buttonDispatcher.setVisibility(
+            //            (forceVisible || alpha > 0) ? View.VISIBLE : View.INVISIBLE);
+               // buttonDispatcher.setAlpha(forceVisible ? 1f : alpha, animate);
+				 buttonDispatcher.setAlpha(alpha, animate);
             }
         }
 
@@ -971,7 +972,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
         }
     }
 
-    private void notifyNavigationBarScreenOn() {
+    public void notifyNavigationBarScreenOn() {
         mNavigationBarView.updateNavButtonIcons();
     }
 
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
old mode 100644
new mode 100755
index 7c41bcd09b..97dcb8925b
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
@@ -45,6 +45,7 @@ import com.android.systemui.statusbar.CommandQueue;
 import com.android.systemui.util.leak.RotationUtils;
 
 import java.util.Objects;
+import android.provider.Settings;
 
 public class PhoneStatusBarView extends PanelBar {
     private static final String TAG = "PhoneStatusBarView";
@@ -221,7 +222,11 @@ public class PhoneStatusBarView extends PanelBar {
             }
         }
 
-        return barConsumedEvent || super.onTouchEvent(event);
+		int status = Settings.System.getInt(mContext.getContentResolver(), "PANEL_BAR_STATUS", 1);
+		boolean isEnable = (status ==1);//wed112 add
+        return isEnable ? barConsumedEvent || super.onTouchEvent(event) : isEnable;
+
+//        return barConsumedEvent || super.onTouchEvent(event);
     }
 
     @Override
diff --git 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
old mode 100644
new mode 100755
index 0c88d06cc9..8b08cb732e
--- 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
@@ -265,6 +265,9 @@ public class StatusBar extends SystemUI implements DemoMode,
 
     public static final boolean DEBUG_WINDOW_STATE = false;
 
+	private static final String OP_BUTTON = "cc.intent.systemui.SHOW_NAVIGATION_BUTTON";//wed112 add status bar
+    private static final String SHOW_NAVIGATION = "com.chengwei.NavBar_ENABLE";
+    private static final String HIDE_NAVIGATION = "com.chengwei.NavBar_DISABLED";
     // additional instrumentation for testing purposes; intended to be left on during development
     public static final boolean CHATTY = DEBUG;
 
@@ -394,6 +397,7 @@ public class StatusBar extends SystemUI implements DemoMode,
 
     // settings
     private QSPanel mQSPanel;
+	RegisterStatusBarResult result = null;
 
     KeyguardIndicationController mKeyguardIndicationController;
 
@@ -853,7 +857,7 @@ public class StatusBar extends SystemUI implements DemoMode,
         // Connect in to the status bar manager service
         mCommandQueue.addCallback(this);
 
-        RegisterStatusBarResult result = null;
+    //    RegisterStatusBarResult result = null;
         try {
             result = mBarService.registerStatusBar(mCommandQueue);
         } catch (RemoteException ex) {
@@ -1086,8 +1090,16 @@ public class StatusBar extends SystemUI implements DemoMode,
         mHeadsUpManager.addListener(mVisualStabilityManager);
         mNotificationPanelViewController.setHeadsUpManager(mHeadsUpManager);
         mNotificationLogger.setHeadsUpManager(mHeadsUpManager);
-
-        createNavigationBar(result);
+      //  createNavigationBar(result);	
+        try {
+			   boolean cwnvb ="0".equals(SystemProperties.get("persist.sys.nvbshow")) ;
+			   if (DEBUG) Log.v(TAG, "cwnvb=" + cwnvb);
+			   if (cwnvb) {
+					createNavigationBar(result);
+			   }
+			} catch (Exception ex) {
+           // no window manager? good luck with that
+			}
 
         if (ENABLE_LOCKSCREEN_WALLPAPER && mWallpaperSupported) {
             mLockscreenWallpaper = mLockscreenWallpaperLazy.get();
@@ -1273,6 +1285,8 @@ public class StatusBar extends SystemUI implements DemoMode,
         filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
         filter.addAction(Intent.ACTION_SCREEN_OFF);
         filter.addAction(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG);
+		filter.addAction(SHOW_NAVIGATION);//wed112 add status bar
+		filter.addAction(HIDE_NAVIGATION);//wed112 add status bar
         mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, null, UserHandle.ALL);
     }
 
@@ -2771,6 +2785,17 @@ public class StatusBar extends SystemUI implements DemoMode,
             else if (DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG.equals(action)) {
                 mQSPanel.showDeviceMonitoringDialog();
             }
+			else  if (HIDE_NAVIGATION.equals(action)) {
+				NavigationBarView mNavigationBarView = mNavigationBarController.getDefaultNavigationBarView();	
+				if (mNavigationBarView == null) return;
+                    mNavigationBarController.removeNavigationBarView();
+			}
+			else if (SHOW_NAVIGATION.equals(action)) {
+                Log.e("StatusBar", "SHOW_NAVIGATION : " + action);
+				NavigationBarView mNavigationBarView = mNavigationBarController.getDefaultNavigationBarView();	
+                    if (mNavigationBarView != null) return;
+                        createNavigationBar(result);
+			}
         }
     };
 
diff --git a/packages/apps/Settings/AndroidManifest.xml b/packages/apps/Settings/AndroidManifest.xml
index 0bae141537..17fddeb137 100755
--- a/packages/apps/Settings/AndroidManifest.xml
+++ b/packages/apps/Settings/AndroidManifest.xml
@@ -1918,7 +1918,61 @@
                 android:theme="@style/GlifV3Theme.Light"
                 android:exported="true"
                 android:permission="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
+				
+        <receiver android:name=".TestingSettingsBroadcastReceiver">
+            <intent-filter>
+                 <action android:name="android.telephony.action.SECRET_CODE" />
+                 <data android:scheme="android_secret_code" android:host="4636" />
+            </intent-filter>
+            <intent-filter>
+                <action android:name="android.telephony.action.SECRET_CODE" />
+                 <data android:scheme="android_secret_code" android:host="1258" />
+            </intent-filter>
+            <intent-filter>
+                 <action android:name="android.telephony.action.SECRET_CODE" />
+                 <data android:scheme="android_secret_code" android:host="00" />
+            </intent-filter>	
+			<intent-filter>
+                <action android:name="android.telephony.action.SECRET_CODE" />
+                 <data android:scheme="android_secret_code" android:host="8989" />
+            </intent-filter>
+            <intent-filter>
+                 <action android:name="android.intent.action.DEFAULT_LAUNCHER" />
+            </intent-filter>
 
+            <!--<intent-filter>
+                 <action android:name="android.intent.action.BOOT_COMPLETED"/>
+            </intent-filter>-->
+
+       </receiver>
+	   
+		<receiver android:name=".ShellSettingsBroadcastReceiver">
+            <intent-filter>
+                 <action android:name="com.chengwei.DATA_ENABLE" />
+            </intent-filter>
+            <intent-filter>
+                 <action android:name="com.chengwei.DATA_DISABLE" />
+            </intent-filter>
+			<intent-filter>
+                 <action android:name="com.chengwei.GPS_ENABLE" />
+            </intent-filter>
+			<intent-filter>
+                 <action android:name="com.chengwei.GPS_DISABLE" />
+            </intent-filter>
+			<intent-filter>
+                 <action android:name="com.chengwei.BT_ENABLE" />
+            </intent-filter>
+			<intent-filter>
+                 <action android:name="com.chengwei.BT_DISABLE" />
+            </intent-filter>
+			<intent-filter>
+                 <action android:name="com.chengwei.NavBar_ENABLE" />
+            </intent-filter>
+			<intent-filter>
+                 <action android:name="com.chengwei.NavBar_DISABLED" />
+            </intent-filter>
+       </receiver>
+	   
         <!-- Exported for SystemUI to trigger -->
         <receiver android:name=".deviceinfo.StorageUnmountReceiver"
                 android:exported="true"
@@ -2169,12 +2223,7 @@
                 android:value="com.android.settings.TestingSettings" />
         </activity>
 
-        <receiver android:name=".TestingSettingsBroadcastReceiver">
-            <intent-filter>
-                 <action android:name="android.telephony.action.SECRET_CODE" />
-                 <data android:scheme="android_secret_code" android:host="4636" />
-            </intent-filter>
-       </receiver>
+
         <receiver android:name=".BootSettingsBroadcastReceiver">
             <intent-filter>
                 <action android:name="android.intent.action.BOOT_COMPLETED"/>
diff --git a/packages/apps/Settings/src/com/android/settings/ShellSettingsBroadcastReceiver.java b/packages/apps/Settings/src/com/android/settings/ShellSettingsBroadcastReceiver.java
new file mode 100755
index 0000000000..e5ef03efc7
--- /dev/null
+++ b/packages/apps/Settings/src/com/android/settings/ShellSettingsBroadcastReceiver.java
@@ -0,0 +1,163 @@
+package com.android.settings;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+
+import android.provider.Settings.Global;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import java.lang.reflect.Method;
+import android.provider.Settings;
+import android.provider.Settings.Secure;
+import android.os.SystemProperties;
+import android.bluetooth.BluetoothAdapter;
+
+
+public class ShellSettingsBroadcastReceiver extends BroadcastReceiver {
+
+    private static final String DATA_ENABLE = "com.chengwei.DATA_ENABLE";
+    private static final String DATA_DISABLE = "com.chengwei.DATA_DISABLE";
+	private static final String GPS_ENABLE = "com.chengwei.GPS_ENABLE";
+	private static final String GPS_DISABLE = "com.chengwei.GPS_DISABLE" ;
+	private static final String BT_ENABLE = "com.chengwei.BT_ENABLE" ;
+	private static final String BT_DISABLE = "com.chengwei.BT_DISABLE" ;
+	private static final String SHOW_NAVIGATION = "com.chengwei.NavBar_ENABLE";
+    private static final String HIDE_NAVIGATION = "com.chengwei.NavBar_DISABLED";
+	
+	private static final String TAG = "ShellSettingsBroadcastReceiver" ;
+	private Context mContext;
+	private TelephonyManager mTelephonyManager;
+	private BluetoothAdapter mBluetoothAdapter;
+	public int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+	
+    public ShellSettingsBroadcastReceiver() {
+    }
+    public ShellSettingsBroadcastReceiver(Context context) {
+			mContext =context;
+    }
+    @Override
+    public void onReceive(Context context, Intent intent) {
+		mContext =context;
+		mTelephonyManager = TelephonyManager.from(context);
+		mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+        Log.e("ShellSettingsBroadcastReceiver","232action: "+intent.getAction());
+        if (intent.getAction().equals(DATA_ENABLE)) {
+		//   String dataabel =	execByRuntime("svc data enable");
+		   SystemProperties.set("persist.sys.dataable","0");
+		   setMobileDataEnabled(true);
+
+		   
+        }else if(intent.getAction().equals(DATA_DISABLE)){
+		//	String datadisable =		execByRuntime("svc data disable");
+		//  Log.e("ShellSettingsBroadcastReceiver","datadisable: "+datadisable);
+
+		   setMobileDataEnabled(false);
+		   SystemProperties.set("persist.sys.dataable","1");
+		}else if(intent.getAction().equals(GPS_ENABLE)){
+	//	String gpsabel =		execByRuntime("settings put secure location_providers_allowed +gps");
+		// Log.e("ShellSettingsBroadcastReceiver","gpsabel: "+gpsabel);
+		 Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
+		 
+		}else if(intent.getAction().equals(GPS_DISABLE)){
+	//	String gpsdisale =		execByRuntime("settings put secure location_providers_allowed -gps");
+		 Log.e("ShellSettingsBroadcastReceiver","gpsdisale: ");
+		 
+		 
+		  Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE, android.provider.Settings.Secure.LOCATION_MODE_OFF); 
+		 
+		 
+		}else if(intent.getAction().equals(BT_ENABLE)){
+
+			mBluetoothAdapter.enable();
+		   
+		   SystemProperties.set("persist.sys.blueth","0");
+		}else if(intent.getAction().equals(BT_DISABLE)){
+
+		  mBluetoothAdapter.disable();
+		   SystemProperties.set("persist.sys.blueth","1");
+		}else if(intent.getAction().equals(HIDE_NAVIGATION)){
+		Log.e("ShellSettingsBroadcastReceiver","HIDE_NAVIGATION: ");
+
+		  SystemProperties.set("persist.sys.nvbshow","1");
+		}else if(intent.getAction().equals(SHOW_NAVIGATION)){
+		Log.e("ShellSettingsBroadcastReceiver","SHOW_NAVIGATION: ");
+
+		  SystemProperties.set("persist.sys.nvbshow","0");
+		}
+    }
+	
+	
+	
+    public void setMobileDataEnabled(boolean enabled) {
+        Log.d(TAG, "setMobileDataEnabled: enabled=" + enabled);
+		 try {
+			mTelephonyManager.setDataEnabled(enabled);
+		    }catch (Exception e){
+        e.printStackTrace();
+        Log.w("ssssett","setDataEnabled exception");
+    }
+    }
+	
+	
+	
+	
+	
+	
+	
+	/**
+ * 鎵цshell 鍛戒护锛?鍛戒护涓笉蹇呭啀甯?adb shell
+ * @param cmd
+ * @return Sting  鍛戒护鎵ц鍦ㄦ帶鍒跺彴杈撳嚭鐨勭粨鏋?+*/
+
+public static String execByRuntime(String cmd) {
+        Process process = null;
+        BufferedReader bufferedReader = null;
+        InputStreamReader inputStreamReader = null;
+        try {
+            process = Runtime.getRuntime().exec(cmd);
+            inputStreamReader = new InputStreamReader(process.getInputStream());
+            bufferedReader = new BufferedReader(inputStreamReader);
+
+            int read;
+            char[] buffer = new char[4096];
+            StringBuilder output = new StringBuilder();
+            while ((read = bufferedReader.read(buffer)) > 0) {
+                output.append(buffer, 0, read);
+            }
+            return output.toString();
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        } finally {
+            if (null != inputStreamReader) {
+                try {
+                    inputStreamReader.close();
+                } catch (Throwable t) {
+                    
+                }
+            }
+            if (null != bufferedReader) {
+                try {
+                    bufferedReader.close();
+                } catch (Throwable t) {
+                    
+                }
+            }
+            if (null != process) {
+                try {
+                    process.destroy();
+                } catch (Throwable t) {
+                    
+                }
+            }
+        }
+    }
+}
-- 
2.17.1

 

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 11 中,状态栏和通知栏的设计有所改变,可能会影响到一些应用程序的通知显示。 如果你想要屏蔽状态栏中的通知,但仍然希望能够收到通知,请尝试以下方法: 1. 检查应用程序通知设置:首先,确保你的应用程序已经开启了通知权限,并且设置了正确的通知渠道。如果应用程序的通知权限被关闭,或者通知渠道被设置为“无声”,那么即使收到了通知,也不会在状态栏中显示。 2. 检查系统设置:在 Android 11 中,系统设置中新增了一个“通知历史记录”选项,用于控制是否在状态栏中显示通知。如果你在系统设置中关闭了“通知历史记录”,那么即使收到了通知,也不会在状态栏中显示。你可以打开系统设置,找到“应用和通知” > “通知历史记录”,然后将其打开即可。 3. 检查第三方应用程序:如果你使用了一些第三方应用程序来管理通知,例如“通知助手”或“通知管理器”,那么可能会导致状态栏中的通知被屏蔽。你可以尝试卸载这些应用程序,或者在应用程序设置中将其权限关闭,然后重新启动手机。 4. 检查系统版本:最后,如果你的手机使用的是 Android 11 的早期版本,可能会存在一些系统缺陷导致通知无法在状态栏中显示。你可以尝试升级到最新的系统版本,或者联系手机制造商寻求技术支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值