From b488ef885e5690c3f6085ccf35e213e0f7eb7597 Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Thu, 3 Dec 2015 16:17:17 -0800 Subject: [PATCH] Add traffic accounting to Bluetooth App. Update the Bluetooth app to build against the new Bluetooth HAL, which expects to be given a calling UID when opening sockets and expects a callback for energy info that accepts uid_traffic_t data. Bug:26039657 Change-Id: I23ffbe39041f11706376acfc6aba33ba661a6ef1 --- jni/com_android_bluetooth_btservice_AdapterService.cpp | 17 ++++++++++------- src/com/android/bluetooth/btservice/AdapterService.java | 8 ++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/jni/com_android_bluetooth_btservice_AdapterService.cpp b/jni/com_android_bluetooth_btservice_AdapterService.cpp index 9223157d..47a62642 100755 --- a/jni/com_android_bluetooth_btservice_AdapterService.cpp +++ b/jni/com_android_bluetooth_btservice_AdapterService.cpp @@ -447,7 +447,8 @@ static void le_test_mode_recv_callback (bt_status_t status, uint16_t packet_coun ALOGV("%s: status:%d packet_count:%d ", __FUNCTION__, status, packet_count); } -static void energy_info_recv_callback(bt_activity_energy_info *p_energy_info) +static void energy_info_recv_callback(bt_activity_energy_info *p_energy_info, + bt_uid_traffic_t* /* uid_data */) { if (!checkCallbackThread()) { ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); @@ -1002,7 +1003,7 @@ static jboolean getRemoteServicesNative(JNIEnv *env, jobject obj, jbyteArray add } static int connectSocketNative(JNIEnv *env, jobject object, jbyteArray address, jint type, - jbyteArray uuidObj, jint channel, jint flag) { + jbyteArray uuidObj, jint channel, jint flag, jint callingUid) { jbyte *addr = NULL, *uuid = NULL; int socket_fd; bt_status_t status; @@ -1024,7 +1025,8 @@ static int connectSocketNative(JNIEnv *env, jobject object, jbyteArray address, } if ( (status = sBluetoothSocketInterface->connect((bt_bdaddr_t *) addr, (btsock_type_t) type, - (const uint8_t*) uuid, channel, &socket_fd, flag)) != BT_STATUS_SUCCESS) { + (const uint8_t*) uuid, channel, &socket_fd, flag, callingUid)) + != BT_STATUS_SUCCESS) { ALOGE("Socket connection failed: %d", status); goto Fail; } @@ -1047,7 +1049,7 @@ Fail: static int createSocketChannelNative(JNIEnv *env, jobject object, jint type, jstring name_str, jbyteArray uuidObj, - jint channel, jint flag) { + jint channel, jint flag, jint callingUid) { const char *service_name = NULL; jbyte *uuid = NULL; int socket_fd; @@ -1069,7 +1071,8 @@ static int createSocketChannelNative(JNIEnv *env, jobject object, jint type, } } if ( (status = sBluetoothSocketInterface->listen((btsock_type_t) type, service_name, - (const uint8_t*) uuid, channel, &socket_fd, flag)) != BT_STATUS_SUCCESS) { + (const uint8_t*) uuid, channel, &socket_fd, flag, callingUid)) + != BT_STATUS_SUCCESS) { ALOGE("Socket listen failed: %d", status); goto Fail; } @@ -1151,8 +1154,8 @@ static JNINativeMethod sMethods[] = { {"pinReplyNative", "([BZI[B)Z", (void*) pinReplyNative}, {"sspReplyNative", "([BIZI)Z", (void*) sspReplyNative}, {"getRemoteServicesNative", "([B)Z", (void*) getRemoteServicesNative}, - {"connectSocketNative", "([BI[BII)I", (void*) connectSocketNative}, - {"createSocketChannelNative", "(ILjava/lang/String;[BII)I", + {"connectSocketNative", "([BI[BIII)I", (void*) connectSocketNative}, + {"createSocketChannelNative", "(ILjava/lang/String;[BIII)I", (void*) createSocketChannelNative}, {"configHciSnoopLogNative", "(Z)Z", (void*) configHciSnoopLogNative}, {"alarmFiredNative", "()V", (void *) alarmFiredNative}, diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java index ea06baa6..fab654a3 100644 --- a/src/com/android/bluetooth/btservice/AdapterService.java +++ b/src/com/android/bluetooth/btservice/AdapterService.java @@ -1819,7 +1819,7 @@ public class AdapterService extends Service { ParcelUuid uuid, int port, int flag) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); int fd = connectSocketNative(Utils.getBytesFromAddress(device.getAddress()), - type, Utils.uuidToByteArray(uuid), port, flag); + type, Utils.uuidToByteArray(uuid), port, flag, Binder.getCallingUid()); if (fd < 0) { errorLog("Failed to connect socket"); return null; @@ -1831,7 +1831,7 @@ public class AdapterService extends Service { ParcelUuid uuid, int port, int flag) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); int fd = createSocketChannelNative(type, serviceName, - Utils.uuidToByteArray(uuid), port, flag); + Utils.uuidToByteArray(uuid), port, flag, Binder.getCallingUid()); if (fd < 0) { errorLog("Failed to create socket channel"); return null; @@ -2144,9 +2144,9 @@ public class AdapterService extends Service { private native int readEnergyInfo(); // TODO(BT) move this to ../btsock dir private native int connectSocketNative(byte[] address, int type, - byte[] uuid, int port, int flag); + byte[] uuid, int port, int flag, int callingUid); private native int createSocketChannelNative(int type, String serviceName, - byte[] uuid, int port, int flag); + byte[] uuid, int port, int flag, int callingUid); /*package*/ native boolean configHciSnoopLogNative(boolean enable); /*package*/ native boolean factoryResetNative(); -- 2.11.0