diff options
author | Jessica Wagantall <jwagantall@cyngn.com> | 2016-04-19 14:51:15 -0700 |
---|---|---|
committer | Jessica Wagantall <jwagantall@cyngn.com> | 2016-04-19 14:51:15 -0700 |
commit | 87c2095d35174747e6e76f65d665209cdbfd2e07 (patch) | |
tree | a94e5a2ac8b50e4133cc47f37c3dea38e6bfa6c1 | |
parent | 1e3c1227d587c2f637c8ecaf7bfadd980f816f52 (diff) | |
parent | a71eb120c7390a82474bf8bdb94d08e723582f9f (diff) | |
download | android_packages_apps_Bluetooth-87c2095d35174747e6e76f65d665209cdbfd2e07.tar.gz android_packages_apps_Bluetooth-87c2095d35174747e6e76f65d665209cdbfd2e07.tar.bz2 android_packages_apps_Bluetooth-87c2095d35174747e6e76f65d665209cdbfd2e07.zip |
Merge commit 'a71eb120c7390a82474bf8bdb94d08e723582f9f' into HEAD
RM-234
Change-Id: I00b6d4819298fe53dcda3de0f41ed40ca1a86d0b
-rw-r--r-- | jni/com_android_bluetooth_btservice_AdapterService.cpp | 26 | ||||
-rw-r--r-- | src/com/android/bluetooth/btservice/AdapterService.java | 58 | ||||
-rw-r--r-- | src/com/android/bluetooth/map/BluetoothMapUtils.java | 7 |
3 files changed, 86 insertions, 5 deletions
diff --git a/jni/com_android_bluetooth_btservice_AdapterService.cpp b/jni/com_android_bluetooth_btservice_AdapterService.cpp index 2544eb8d4..f18856c1a 100644 --- a/jni/com_android_bluetooth_btservice_AdapterService.cpp +++ b/jni/com_android_bluetooth_btservice_AdapterService.cpp @@ -1256,6 +1256,27 @@ static jboolean factoryResetNative(JNIEnv *env, jobject obj) { 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[] = { /* name, signature, funcPtr */ {"classInitNative", "()V", (void *) classInitNative}, @@ -1287,8 +1308,9 @@ static JNINativeMethod sMethods[] = { {"dumpNative", "(Ljava/io/FileDescriptor;)V", (void*) dumpNative}, {"factoryResetNative", "()Z", (void*)factoryResetNative}, {"getSocketOptNative", "(III[B)I", (void*) getSocketOptNative}, - {"setSocketOptNative", "(III[BI)I", (void*) setSocketOptNative} - + {"setSocketOptNative", "(III[BI)I", (void*) setSocketOptNative}, + {"interopDatabaseClearNative", "()V", (void*) interopDatabaseClearNative}, + {"interopDatabaseAddNative", "(I[BI)V", (void*) interopDatabaseAddNative} }; int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java index fba0c8933..ba597c3e4 100644 --- a/src/com/android/bluetooth/btservice/AdapterService.java +++ b/src/com/android/bluetooth/btservice/AdapterService.java @@ -395,6 +395,8 @@ public class AdapterService extends Service { mAdapterStateMachine.sendMessage(mAdapterStateMachine.obtainMessage(AdapterState.BREDR_STOPPED)); } else if (isTurningOn) { + updateInteropDatabase(); + //Process start pending //Check if all services are started if so, update state synchronized (mProfileServicesState) { @@ -421,6 +423,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 public void onCreate() { super.onCreate(); @@ -2528,6 +2583,9 @@ public class AdapterService extends Service { private native void alarmFiredNative(); private native void dumpNative(FileDescriptor fd); + private native void interopDatabaseClearNative(); + private native void interopDatabaseAddNative(int feature, byte[] address, int length); + protected void finalize() { cleanup(); if (TRACE_REF) { diff --git a/src/com/android/bluetooth/map/BluetoothMapUtils.java b/src/com/android/bluetooth/map/BluetoothMapUtils.java index 1537807a0..7ca55301a 100644 --- a/src/com/android/bluetooth/map/BluetoothMapUtils.java +++ b/src/com/android/bluetooth/map/BluetoothMapUtils.java @@ -394,15 +394,16 @@ public class BluetoothMapUtils { static public byte[] truncateUtf8StringToBytearray(String utf8String, int maxLength) throws UnsupportedEncodingException { - byte[] utf8Bytes = null; + byte[] utf8Bytes = new byte[utf8String.length() + 1]; try { - utf8Bytes = utf8String.getBytes("UTF-8"); + System.arraycopy(utf8String.getBytes("UTF-8"), 0, + utf8Bytes, 0, utf8String.length()); } catch (UnsupportedEncodingException e) { Log.e(TAG,"truncateUtf8StringToBytearray: getBytes exception ", e); throw e; } - if (utf8Bytes.length > (maxLength - 1)) { + if (utf8Bytes.length > maxLength) { /* if 'continuation' byte is in place 200, * then strip previous bytes until utf-8 start byte is found */ if ( (utf8Bytes[maxLength - 1] & 0xC0) == 0x80 ) { |