Loading android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ #include <sys/prctl.h> #include <sys/stat.h> #include <hardware/bluetooth.h> #include <mutex> using base::StringPrintf; Loading Loading @@ -1172,6 +1173,19 @@ static void dumpNative(JNIEnv* env, jobject obj, jobject fdObj, delete[] argObjs; } static jbyteArray dumpMetricsNative(JNIEnv* env, jobject obj) { ALOGI("%s", __func__); if (!sBluetoothInterface) return env->NewByteArray(0); std::string output; sBluetoothInterface->dumpMetrics(&output); jsize output_size = output.size() * sizeof(char); jbyteArray output_bytes = env->NewByteArray(output_size); env->SetByteArrayRegion(output_bytes, 0, output_size, (const jbyte*)output.data()); return output_bytes; } static jboolean factoryResetNative(JNIEnv* env, jobject obj) { ALOGV("%s", __func__); if (!sBluetoothInterface) return JNI_FALSE; Loading Loading @@ -1231,6 +1245,7 @@ static JNINativeMethod sMethods[] = { {"readEnergyInfo", "()I", (void*)readEnergyInfo}, {"dumpNative", "(Ljava/io/FileDescriptor;[Ljava/lang/String;)V", (void*)dumpNative}, {"dumpMetricsNative", "()[B", (void*)dumpMetricsNative}, {"factoryResetNative", "()Z", (void*)factoryResetNative}, {"interopDatabaseClearNative", "()V", (void*)interopDatabaseClearNative}, {"interopDatabaseAddNative", "(I[BI)V", (void*)interopDatabaseAddNative}}; Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +36 −17 Original line number Diff line number Diff line Loading @@ -69,11 +69,12 @@ import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.IBatteryStats; import com.google.protobuf.micro.InvalidProtocolBufferMicroException; import java.io.FileDescriptor; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; Loading Loading @@ -1639,6 +1640,7 @@ public class AdapterService extends Service { return; } service.dump(fd, writer, args); writer.close(); } } Loading Loading @@ -2491,10 +2493,18 @@ public class AdapterService extends Service { verboseLog("dumpsys arguments, check for protobuf output: " + TextUtils.join(" ", args)); if (args[0].startsWith("--proto")) { if (args[0].equals("--proto-java-bin")) { dumpJava(fd); } else { dumpNative(fd, args); if (args[0].equals("--proto-bin")) { dumpMetrics(fd); } else if (args[0].equals("--proto-java-bin")) { // TODO: Remove once --proto-java-bin is no longer used BluetoothProto.BluetoothLog metrics = new BluetoothProto.BluetoothLog(); byte[] metricsBytes = Base64.encode(metrics.toByteArray(), Base64.DEFAULT); Log.w(TAG, "proto-java-bin dump, empty metrics size is " + metricsBytes.length); try (FileOutputStream protoOut = new FileOutputStream(fd)) { protoOut.write(metricsBytes); } catch (IOException e) { errorLog("Unable to write Java protobuf to file descriptor."); } } return; } Loading @@ -2520,21 +2530,28 @@ public class AdapterService extends Service { dumpNative(fd, args); } private void dumpJava(FileDescriptor fd) { BluetoothProto.BluetoothLog log = new BluetoothProto.BluetoothLog(); log.setNumBondedDevices(getBondedDevices().length); private void dumpMetrics(FileDescriptor fd) { BluetoothProto.BluetoothLog metrics = new BluetoothProto.BluetoothLog(); metrics.setNumBondedDevices(getBondedDevices().length); for (ProfileService profile : mProfiles) { profile.dumpProto(log); profile.dumpProto(metrics); } byte[] nativeMetricsBytes = dumpMetricsNative(); debugLog("dumpMetrics: native metrics size is " + nativeMetricsBytes.length); if (nativeMetricsBytes.length > 0) { try { FileOutputStream protoOut = new FileOutputStream(fd); String protoOutString = Base64.encodeToString(log.toByteArray(), Base64.DEFAULT); protoOut.write(protoOutString.getBytes(StandardCharsets.UTF_8)); protoOut.close(); metrics.mergeFrom(nativeMetricsBytes); } catch (InvalidProtocolBufferMicroException ex) { Log.w(TAG, "dumpMetrics: problem parsing metrics protobuf, " + ex.getMessage()); return; } } byte[] metricsBytes = Base64.encode(metrics.toByteArray(), Base64.DEFAULT); debugLog("dumpMetrics: combined metrics size is " + metricsBytes.length); try (FileOutputStream protoOut = new FileOutputStream(fd)) { protoOut.write(metricsBytes); } catch (IOException e) { errorLog("Unable to write Java protobuf to file descriptor."); errorLog("dumpMetrics: error writing combined protobuf to fd, " + e.getMessage()); } } Loading Loading @@ -2641,6 +2658,8 @@ public class AdapterService extends Service { private native void dumpNative(FileDescriptor fd, String[] arguments); private native byte[] dumpMetricsNative(); private native void interopDatabaseClearNative(); private native void interopDatabaseAddNative(int feature, byte[] address, int length); Loading Loading
android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ #include <sys/prctl.h> #include <sys/stat.h> #include <hardware/bluetooth.h> #include <mutex> using base::StringPrintf; Loading Loading @@ -1172,6 +1173,19 @@ static void dumpNative(JNIEnv* env, jobject obj, jobject fdObj, delete[] argObjs; } static jbyteArray dumpMetricsNative(JNIEnv* env, jobject obj) { ALOGI("%s", __func__); if (!sBluetoothInterface) return env->NewByteArray(0); std::string output; sBluetoothInterface->dumpMetrics(&output); jsize output_size = output.size() * sizeof(char); jbyteArray output_bytes = env->NewByteArray(output_size); env->SetByteArrayRegion(output_bytes, 0, output_size, (const jbyte*)output.data()); return output_bytes; } static jboolean factoryResetNative(JNIEnv* env, jobject obj) { ALOGV("%s", __func__); if (!sBluetoothInterface) return JNI_FALSE; Loading Loading @@ -1231,6 +1245,7 @@ static JNINativeMethod sMethods[] = { {"readEnergyInfo", "()I", (void*)readEnergyInfo}, {"dumpNative", "(Ljava/io/FileDescriptor;[Ljava/lang/String;)V", (void*)dumpNative}, {"dumpMetricsNative", "()[B", (void*)dumpMetricsNative}, {"factoryResetNative", "()Z", (void*)factoryResetNative}, {"interopDatabaseClearNative", "()V", (void*)interopDatabaseClearNative}, {"interopDatabaseAddNative", "(I[BI)V", (void*)interopDatabaseAddNative}}; Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +36 −17 Original line number Diff line number Diff line Loading @@ -69,11 +69,12 @@ import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.IBatteryStats; import com.google.protobuf.micro.InvalidProtocolBufferMicroException; import java.io.FileDescriptor; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; Loading Loading @@ -1639,6 +1640,7 @@ public class AdapterService extends Service { return; } service.dump(fd, writer, args); writer.close(); } } Loading Loading @@ -2491,10 +2493,18 @@ public class AdapterService extends Service { verboseLog("dumpsys arguments, check for protobuf output: " + TextUtils.join(" ", args)); if (args[0].startsWith("--proto")) { if (args[0].equals("--proto-java-bin")) { dumpJava(fd); } else { dumpNative(fd, args); if (args[0].equals("--proto-bin")) { dumpMetrics(fd); } else if (args[0].equals("--proto-java-bin")) { // TODO: Remove once --proto-java-bin is no longer used BluetoothProto.BluetoothLog metrics = new BluetoothProto.BluetoothLog(); byte[] metricsBytes = Base64.encode(metrics.toByteArray(), Base64.DEFAULT); Log.w(TAG, "proto-java-bin dump, empty metrics size is " + metricsBytes.length); try (FileOutputStream protoOut = new FileOutputStream(fd)) { protoOut.write(metricsBytes); } catch (IOException e) { errorLog("Unable to write Java protobuf to file descriptor."); } } return; } Loading @@ -2520,21 +2530,28 @@ public class AdapterService extends Service { dumpNative(fd, args); } private void dumpJava(FileDescriptor fd) { BluetoothProto.BluetoothLog log = new BluetoothProto.BluetoothLog(); log.setNumBondedDevices(getBondedDevices().length); private void dumpMetrics(FileDescriptor fd) { BluetoothProto.BluetoothLog metrics = new BluetoothProto.BluetoothLog(); metrics.setNumBondedDevices(getBondedDevices().length); for (ProfileService profile : mProfiles) { profile.dumpProto(log); profile.dumpProto(metrics); } byte[] nativeMetricsBytes = dumpMetricsNative(); debugLog("dumpMetrics: native metrics size is " + nativeMetricsBytes.length); if (nativeMetricsBytes.length > 0) { try { FileOutputStream protoOut = new FileOutputStream(fd); String protoOutString = Base64.encodeToString(log.toByteArray(), Base64.DEFAULT); protoOut.write(protoOutString.getBytes(StandardCharsets.UTF_8)); protoOut.close(); metrics.mergeFrom(nativeMetricsBytes); } catch (InvalidProtocolBufferMicroException ex) { Log.w(TAG, "dumpMetrics: problem parsing metrics protobuf, " + ex.getMessage()); return; } } byte[] metricsBytes = Base64.encode(metrics.toByteArray(), Base64.DEFAULT); debugLog("dumpMetrics: combined metrics size is " + metricsBytes.length); try (FileOutputStream protoOut = new FileOutputStream(fd)) { protoOut.write(metricsBytes); } catch (IOException e) { errorLog("Unable to write Java protobuf to file descriptor."); errorLog("dumpMetrics: error writing combined protobuf to fd, " + e.getMessage()); } } Loading Loading @@ -2641,6 +2658,8 @@ public class AdapterService extends Service { private native void dumpNative(FileDescriptor fd, String[] arguments); private native byte[] dumpMetricsNative(); private native void interopDatabaseClearNative(); private native void interopDatabaseAddNative(int feature, byte[] address, int length); Loading