Loading jni/com_android_bluetooth_btservice_AdapterService.cpp +24 −1 Original line number Original line Diff line number Diff line Loading @@ -1130,6 +1130,27 @@ static jboolean factoryResetNative(JNIEnv *env, jobject obj) { return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; } } static void interopDatabaseClearNative(JNIEnv *env, jobject obj) { ALOGV("%s()", __FUNCTION__); if (!sBluetoothInterface) return; sBluetoothInterface->interop_database_clear(); } static void interopDatabaseAddNative(JNIEnv *env, jobject obj, int feature, jbyteArray address, int length) { ALOGV("%s()", __FUNCTION__); if (!sBluetoothInterface) return; jbyte *addr = env->GetByteArrayElements(address, NULL); if (addr == NULL) { jniThrowIOException(env, EINVAL); return; } sBluetoothInterface->interop_database_add(feature, (bt_bdaddr_t *)addr, length); env->ReleaseByteArrayElements(address, addr, 0); } static JNINativeMethod sMethods[] = { static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ /* name, signature, funcPtr */ {"classInitNative", "()V", (void *) classInitNative}, {"classInitNative", "()V", (void *) classInitNative}, Loading Loading @@ -1158,7 +1179,9 @@ static JNINativeMethod sMethods[] = { {"alarmFiredNative", "()V", (void *) alarmFiredNative}, {"alarmFiredNative", "()V", (void *) alarmFiredNative}, {"readEnergyInfo", "()I", (void*) readEnergyInfo}, {"readEnergyInfo", "()I", (void*) readEnergyInfo}, {"dumpNative", "(Ljava/io/FileDescriptor;)V", (void*) dumpNative}, {"dumpNative", "(Ljava/io/FileDescriptor;)V", (void*) dumpNative}, {"factoryResetNative", "()Z", (void*)factoryResetNative} {"factoryResetNative", "()Z", (void*)factoryResetNative}, {"interopDatabaseClearNative", "()V", (void*) interopDatabaseClearNative}, {"interopDatabaseAddNative", "(I[BI)V", (void*) interopDatabaseAddNative} }; }; int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) Loading src/com/android/bluetooth/btservice/AdapterService.java +58 −0 Original line number Original line Diff line number Diff line Loading @@ -360,6 +360,8 @@ public class AdapterService extends Service { mAdapterStateMachine.sendMessage(mAdapterStateMachine.obtainMessage(AdapterState.BREDR_STOPPED)); mAdapterStateMachine.sendMessage(mAdapterStateMachine.obtainMessage(AdapterState.BREDR_STOPPED)); } else if (isTurningOn) { } else if (isTurningOn) { updateInteropDatabase(); //Process start pending //Process start pending //Check if all services are started if so, update state //Check if all services are started if so, update state synchronized (mProfileServicesState) { synchronized (mProfileServicesState) { Loading @@ -385,6 +387,59 @@ public class AdapterService extends Service { } } } } private void updateInteropDatabase() { interopDatabaseClearNative(); String interop_string = Settings.Global.getString(getContentResolver(), Settings.Global.BLUETOOTH_INTEROPERABILITY_LIST); if (interop_string == null) return; Log.d(TAG, "updateInteropDatabase: [" + interop_string + "]"); String[] entries = interop_string.split(";"); for (String entry : entries) { String[] tokens = entry.split(","); if (tokens.length != 2) continue; // Get feature int feature = 0; try { feature = Integer.parseInt(tokens[1]); } catch (NumberFormatException e) { Log.e(TAG, "updateInteropDatabase: Invalid feature '" + tokens[1] + "'"); continue; } // Get address bytes and length int length = (tokens[0].length() + 1) / 3; if (length < 1 || length > 6) { Log.e(TAG, "updateInteropDatabase: Malformed address string '" + tokens[0] + "'"); continue; } byte[] addr = new byte[6]; int offset = 0; for (int i = 0; i < tokens[0].length(); ) { if (tokens[0].charAt(i) == ':') { i += 1; } else { try { addr[offset++] = (byte) Integer.parseInt(tokens[0].substring(i, i + 2), 16); } catch (NumberFormatException e) { offset = 0; break; } i += 2; } } // Check if address was parsed ok, otherwise, move on... if (offset == 0) continue; // Add entry interopDatabaseAddNative(feature, addr, length); } } @Override @Override public void onCreate() { public void onCreate() { super.onCreate(); super.onCreate(); Loading Loading @@ -2139,6 +2194,9 @@ public class AdapterService extends Service { private native void alarmFiredNative(); private native void alarmFiredNative(); private native void dumpNative(FileDescriptor fd); private native void dumpNative(FileDescriptor fd); private native void interopDatabaseClearNative(); private native void interopDatabaseAddNative(int feature, byte[] address, int length); protected void finalize() { protected void finalize() { cleanup(); cleanup(); if (TRACE_REF) { if (TRACE_REF) { Loading Loading
jni/com_android_bluetooth_btservice_AdapterService.cpp +24 −1 Original line number Original line Diff line number Diff line Loading @@ -1130,6 +1130,27 @@ static jboolean factoryResetNative(JNIEnv *env, jobject obj) { return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; } } static void interopDatabaseClearNative(JNIEnv *env, jobject obj) { ALOGV("%s()", __FUNCTION__); if (!sBluetoothInterface) return; sBluetoothInterface->interop_database_clear(); } static void interopDatabaseAddNative(JNIEnv *env, jobject obj, int feature, jbyteArray address, int length) { ALOGV("%s()", __FUNCTION__); if (!sBluetoothInterface) return; jbyte *addr = env->GetByteArrayElements(address, NULL); if (addr == NULL) { jniThrowIOException(env, EINVAL); return; } sBluetoothInterface->interop_database_add(feature, (bt_bdaddr_t *)addr, length); env->ReleaseByteArrayElements(address, addr, 0); } static JNINativeMethod sMethods[] = { static JNINativeMethod sMethods[] = { /* name, signature, funcPtr */ /* name, signature, funcPtr */ {"classInitNative", "()V", (void *) classInitNative}, {"classInitNative", "()V", (void *) classInitNative}, Loading Loading @@ -1158,7 +1179,9 @@ static JNINativeMethod sMethods[] = { {"alarmFiredNative", "()V", (void *) alarmFiredNative}, {"alarmFiredNative", "()V", (void *) alarmFiredNative}, {"readEnergyInfo", "()I", (void*) readEnergyInfo}, {"readEnergyInfo", "()I", (void*) readEnergyInfo}, {"dumpNative", "(Ljava/io/FileDescriptor;)V", (void*) dumpNative}, {"dumpNative", "(Ljava/io/FileDescriptor;)V", (void*) dumpNative}, {"factoryResetNative", "()Z", (void*)factoryResetNative} {"factoryResetNative", "()Z", (void*)factoryResetNative}, {"interopDatabaseClearNative", "()V", (void*) interopDatabaseClearNative}, {"interopDatabaseAddNative", "(I[BI)V", (void*) interopDatabaseAddNative} }; }; int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) Loading
src/com/android/bluetooth/btservice/AdapterService.java +58 −0 Original line number Original line Diff line number Diff line Loading @@ -360,6 +360,8 @@ public class AdapterService extends Service { mAdapterStateMachine.sendMessage(mAdapterStateMachine.obtainMessage(AdapterState.BREDR_STOPPED)); mAdapterStateMachine.sendMessage(mAdapterStateMachine.obtainMessage(AdapterState.BREDR_STOPPED)); } else if (isTurningOn) { } else if (isTurningOn) { updateInteropDatabase(); //Process start pending //Process start pending //Check if all services are started if so, update state //Check if all services are started if so, update state synchronized (mProfileServicesState) { synchronized (mProfileServicesState) { Loading @@ -385,6 +387,59 @@ public class AdapterService extends Service { } } } } private void updateInteropDatabase() { interopDatabaseClearNative(); String interop_string = Settings.Global.getString(getContentResolver(), Settings.Global.BLUETOOTH_INTEROPERABILITY_LIST); if (interop_string == null) return; Log.d(TAG, "updateInteropDatabase: [" + interop_string + "]"); String[] entries = interop_string.split(";"); for (String entry : entries) { String[] tokens = entry.split(","); if (tokens.length != 2) continue; // Get feature int feature = 0; try { feature = Integer.parseInt(tokens[1]); } catch (NumberFormatException e) { Log.e(TAG, "updateInteropDatabase: Invalid feature '" + tokens[1] + "'"); continue; } // Get address bytes and length int length = (tokens[0].length() + 1) / 3; if (length < 1 || length > 6) { Log.e(TAG, "updateInteropDatabase: Malformed address string '" + tokens[0] + "'"); continue; } byte[] addr = new byte[6]; int offset = 0; for (int i = 0; i < tokens[0].length(); ) { if (tokens[0].charAt(i) == ':') { i += 1; } else { try { addr[offset++] = (byte) Integer.parseInt(tokens[0].substring(i, i + 2), 16); } catch (NumberFormatException e) { offset = 0; break; } i += 2; } } // Check if address was parsed ok, otherwise, move on... if (offset == 0) continue; // Add entry interopDatabaseAddNative(feature, addr, length); } } @Override @Override public void onCreate() { public void onCreate() { super.onCreate(); super.onCreate(); Loading Loading @@ -2139,6 +2194,9 @@ public class AdapterService extends Service { private native void alarmFiredNative(); private native void alarmFiredNative(); private native void dumpNative(FileDescriptor fd); private native void dumpNative(FileDescriptor fd); private native void interopDatabaseClearNative(); private native void interopDatabaseAddNative(int feature, byte[] address, int length); protected void finalize() { protected void finalize() { cleanup(); cleanup(); if (TRACE_REF) { if (TRACE_REF) { Loading