bluetooth: Prevent null pointer crashes in A2DP initNative
Change-Id: I91f555ae8f2311d80145fe6b33a6c93b1997ca66
diff --git a/jni/com_android_bluetooth_a2dp.cpp b/jni/com_android_bluetooth_a2dp.cpp
index 7c15c37..fd286ff 100644
--- a/jni/com_android_bluetooth_a2dp.cpp
+++ b/jni/com_android_bluetooth_a2dp.cpp
@@ -221,7 +221,13 @@
const char *offload_capabilities;
bt_status_t status;
- offload_capabilities = env->GetStringUTFChars(offload_cap, NULL);
+ // Calling GetStringUTFChars with a null jstring can cause ART to crash
+ if (offload_cap != NULL) {
+ offload_capabilities = env->GetStringUTFChars(offload_cap, NULL);
+ } else {
+ offload_capabilities = NULL;
+ }
+
if ( (btInf = getBluetoothInterface()) == NULL) {
ALOGE("Bluetooth module is not loaded");