OSDN Git Service

Remove IBluetooth.dump(), dumpsys arguments
authorMarie Janssen <jamuraa@google.com>
Tue, 12 Jan 2016 19:03:00 +0000 (11:03 -0800)
committerMarie Janssen <jamuraa@google.com>
Tue, 26 Jan 2016 20:13:55 +0000 (20:13 +0000)
Move the majority of dumpsys into the AdapterService so we don't need
IBluetooth.dump(), and update the JNI interface for dumpsys arguments.

Change-Id: I481f147d913e0f4e1b85b8e4b027dbc349372ce5
(cherry picked from commit 48131cd77d2a1fd7d6112eee388a90a1fdbe0c6c)

jni/com_android_bluetooth_btservice_AdapterService.cpp
src/com/android/bluetooth/btservice/AdapterService.java

index ee6e566..b4e717e 100755 (executable)
@@ -1197,7 +1197,8 @@ static int readEnergyInfo()
     return result;
 }
 
-static void dumpNative(JNIEnv *env, jobject obj, jobject fdObj)
+static void dumpNative(JNIEnv *env, jobject obj, jobject fdObj,
+                       jobjectArray argArray)
 {
     ALOGV("%s()", __FUNCTION__);
     if (!sBluetoothInterface) return;
@@ -1205,7 +1206,24 @@ static void dumpNative(JNIEnv *env, jobject obj, jobject fdObj)
     int fd = jniGetFDFromFileDescriptor(env, fdObj);
     if (fd < 0) return;
 
-    sBluetoothInterface->dump(fd);
+    int numArgs = env->GetArrayLength(argArray);
+
+    jstring *argObjs = new jstring[numArgs];
+    const char **args = new const char*[numArgs];
+
+    for (int i = 0; i < numArgs; i++) {
+      argObjs[i] = (jstring) env->GetObjectArrayElement(argArray, i);
+      args[i] = env->GetStringUTFChars(argObjs[i], NULL);
+    }
+
+    sBluetoothInterface->dump(fd, args);
+
+    for (int i = 0; i < numArgs; i++) {
+      env->ReleaseStringUTFChars(argObjs[i], args[i]);
+    }
+
+    delete[] args;
+    delete[] argObjs;
 }
 
 static jboolean factoryResetNative(JNIEnv *env, jobject obj) {
@@ -1243,7 +1261,7 @@ static JNINativeMethod sMethods[] = {
     {"configHciSnoopLogNative", "(Z)Z", (void*) configHciSnoopLogNative},
     {"alarmFiredNative", "()V", (void *) alarmFiredNative},
     {"readEnergyInfo", "()I", (void*) readEnergyInfo},
-    {"dumpNative", "(Ljava/io/FileDescriptor;)V", (void*) dumpNative},
+    {"dumpNative", "(Ljava/io/FileDescriptor;[Ljava/lang/String;)V", (void*) dumpNative},
     {"factoryResetNative", "()Z", (void*)factoryResetNative}
 };
 
index fe97f0d..9f8c86e 100644 (file)
@@ -71,8 +71,10 @@ import com.android.bluetooth.Utils;
 import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties;
 
 import java.io.FileDescriptor;
+import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -131,6 +133,13 @@ public class AdapterService extends Service {
 
     private static final int ADAPTER_SERVICE_TYPE=Service.START_STICKY;
 
+    private static final String[] DEVICE_TYPE_NAMES = new String[] {
+      "???",
+      "BR/EDR",
+      "LE",
+      "DUAL"
+    };
+
     static {
         classInitNative();
     }
@@ -1321,12 +1330,6 @@ public class AdapterService extends Service {
              return service.reportActivityInfo();
          }
 
-         public void dump(ParcelFileDescriptor fd) {
-            AdapterService service = getService();
-            if (service == null) return;
-            service.dump(fd.getFileDescriptor());
-         }
-
          public void onLeServiceUp(){
              AdapterService service = getService();
              if (service == null) return;
@@ -1338,6 +1341,12 @@ public class AdapterService extends Service {
              if (service == null) return;
              service.onBrEdrDown();
          }
+
+         public void dump(FileDescriptor fd, String[] args) {
+            PrintWriter writer = new PrintWriter(new FileOutputStream(fd));
+            AdapterService service = getService();
+            service.dump(fd, writer, args);
+         }
     };
 
     // ----API Methods--------
@@ -2139,8 +2148,24 @@ public class AdapterService extends Service {
         return getResources().getInteger(R.integer.config_bluetooth_operating_voltage_mv) / 1000.0;
     }
 
-    private void dump(FileDescriptor fd) {
-        // Collect profile information
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
+        enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
+
+        writer.println("Bluetooth Status");
+        writer.println("  enabled: " + isEnabled());
+        writer.println("  state: " + getState());
+        writer.println("  address: " + getAddress());
+        writer.println("  name: " + getName() + "\n");
+
+        writer.println("Bonded devices:");
+        for (BluetoothDevice device : getBondedDevices()) {
+          writer.println("  " + device.getAddress() +
+              " [" + DEVICE_TYPE_NAMES[device.getType()] + "] " +
+              device.getName());
+        }
+
+        // Dump profile information
         StringBuilder sb = new StringBuilder();
         synchronized (mProfiles) {
             for (ProfileService profile : mProfiles) {
@@ -2148,25 +2173,11 @@ public class AdapterService extends Service {
             }
         }
 
-        // Dump Java based profiles first
-        FileWriter fw = null;
-        try {
-            fw = new FileWriter(fd);
-            fw.write(sb.toString());
-        } catch (IOException ex) {
-            errorLog("IOException writing profile status!");
-        } finally {
-            if (fw != null) {
-                try {
-                    fw.close();
-                } catch (IOException ex) {
-                    debugLog("IOException closing a file after writing the profile status");
-                }
-            }
-        }
+        writer.write(sb.toString());
+        writer.flush();
 
         // Add native logs
-        dumpNative(fd);
+        dumpNative(fd, args);
     }
 
     private void debugLog(String msg) {
@@ -2229,7 +2240,7 @@ public class AdapterService extends Service {
     /*package*/ native boolean factoryResetNative();
 
     private native void alarmFiredNative();
-    private native void dumpNative(FileDescriptor fd);
+    private native void dumpNative(FileDescriptor fd, String[] arguments);
 
     protected void finalize() {
         cleanup();