在设置里面增加关闭和打开GPS ,数据流量的接口

 

 

commit 9fc9ca69fb16aa9da42435010974a8d176c0def8
Date:   Fri Aug 14 15:04:10 2020 +0800

     增加打开关闭GPS/数据流量的广播

diff --git a/frameworks/base/services/core/java/com/android/server/am/BroadcastQueue.java b/frameworks/base/services/core/java/com/android/server/am/BroadcastQueue.java
old mode 100644
new mode 100755
index c9a26cb..0c1ff4a
--- a/frameworks/base/services/core/java/com/android/server/am/BroadcastQueue.java
+++ b/frameworks/base/services/core/java/com/android/server/am/BroadcastQueue.java
@@ -1285,7 +1285,7 @@ public final class BroadcastQueue {
                     Slog.w(TAG, "Background execution not allowed: receiving "
                             + r.intent + " to "
                             + component.flattenToShortString());
-                    skip = true;
+                  //  skip = true; // remove for not sendbroadcast issue
                 }
             }
         }
diff --git a/packages/apps/Settings/AndroidManifest.xml b/packages/apps/Settings/AndroidManifest.xml
index b4ec440..87e4eff 100755
--- a/packages/apps/Settings/AndroidManifest.xml
+++ b/packages/apps/Settings/AndroidManifest.xml
@@ -2235,6 +2235,23 @@
                  
             
        
+	   
+	    
+		
+            
+                 
+            
+            
+                 
+            
+			
+                 
+            
+			
+                 
+            
+       
+	   
 		
             
                  
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 0000000..58581ff
--- /dev/null
+++ b/packages/apps/Settings/src/com/android/settings/ShellSettingsBroadcastReceiver.java
@@ -0,0 +1,84 @@
+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;
+
+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" ;
+    public ShellSettingsBroadcastReceiver() {
+    }
+    
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        Log.e("ShellSettingsBroadcastReceiver","action: "+intent.getAction());
+        if (intent.getAction().equals(DATA_ENABLE)) {
+			execByRuntime("svc data enable");
+        }else if(intent.getAction().equals(DATA_DISABLE)){
+			execByRuntime("svc data disable");
+		}else if(intent.getAction().equals(GPS_ENABLE)){
+			execByRuntime("settings put secure location_providers_allowed +gps");
+		}else if(intent.getAction().equals(GPS_DISABLE)){
+			execByRuntime("settings put secure location_providers_allowed -gps");
+		}
+    }
+	
+	
+	/**
+ * 执行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) {
+                    
+                }
+            }
+        }
+    }
+}

 

你可能感兴趣的:(Android,Phone,android)