Loading jni/com_android_bluetooth_btservice_AdapterService.cpp +113 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 The Linux Foundation. All rights reserved * Not a Contribution. * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); Loading @@ -17,6 +19,7 @@ #define LOG_TAG "BluetoothServiceJni" #include "com_android_bluetooth.h" #include "hardware/bt_sock.h" #include "hardware/bt_mce.h" #include "utils/Log.h" #include "utils/misc.h" #include "cutils/properties.h" Loading @@ -40,9 +43,11 @@ static jmethodID method_sspRequestCallback; static jmethodID method_bondStateChangeCallback; static jmethodID method_aclStateChangeCallback; static jmethodID method_discoveryStateChangeCallback; static jmethodID method_deviceMasInstancesFoundCallback; static const bt_interface_t *sBluetoothInterface = NULL; static const btsock_interface_t *sBluetoothSocketInterface = NULL; static const btmce_interface_t *sBluetoothMceInterface = NULL; static JNIEnv *callbackEnv = NULL; static jobject sJniCallbacksObj; Loading Loading @@ -455,6 +460,78 @@ bt_callbacks_t sBluetoothCallbacks = { le_test_mode_recv_callback }; static void remote_mas_instances_callback(bt_status_t status, bt_bdaddr_t *bd_addr, int num_instances, btmce_mas_instance_t *instances) { if (!checkCallbackThread()) { ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); return; } ALOGV("%s: Status is: %d, Instances: %d", __FUNCTION__, status, num_instances); if (status != BT_STATUS_SUCCESS) { ALOGE("%s: Status %d is incorrect", __FUNCTION__, status); return; } callbackEnv->PushLocalFrame(ADDITIONAL_NREFS); jbyteArray addr = NULL; jobjectArray a_name = NULL; jintArray a_scn = NULL; jintArray a_masid = NULL; jintArray a_msgtype = NULL; jclass mclass; mclass = callbackEnv->FindClass("java/lang/String"); addr = callbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); if (addr == NULL) goto clean; callbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte*)bd_addr); a_name = callbackEnv->NewObjectArray(num_instances, mclass, NULL); if (a_name == NULL) goto clean; a_scn = callbackEnv->NewIntArray(num_instances); if (a_scn == NULL) goto clean; a_masid = callbackEnv->NewIntArray(num_instances); if (a_masid == NULL) goto clean; a_msgtype = callbackEnv->NewIntArray(num_instances); if (a_msgtype == NULL) goto clean; for (int i = 0; i < num_instances; i++) { jstring name = callbackEnv->NewStringUTF(instances[i].p_name); callbackEnv->SetObjectArrayElement(a_name, i, name); callbackEnv->SetIntArrayRegion(a_scn, i, 1, &instances[i].scn); callbackEnv->SetIntArrayRegion(a_masid, i, 1, &instances[i].id); callbackEnv->SetIntArrayRegion(a_msgtype, i, 1, &instances[i].msg_types); callbackEnv->DeleteLocalRef(name); } callbackEnv->CallVoidMethod(sJniCallbacksObj, method_deviceMasInstancesFoundCallback, (jint) status, addr, a_name, a_scn, a_masid, a_msgtype); checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__); clean: if (addr != NULL) callbackEnv->DeleteLocalRef(addr); if (a_name != NULL) callbackEnv->DeleteLocalRef(a_name); if (a_scn != NULL) callbackEnv->DeleteLocalRef(a_scn); if (a_masid != NULL) callbackEnv->DeleteLocalRef(a_masid); if (a_msgtype != NULL) callbackEnv->DeleteLocalRef(a_msgtype); callbackEnv->PopLocalFrame(NULL); } static btmce_callbacks_t sBluetoothMceCallbacks = { sizeof(sBluetoothMceCallbacks), remote_mas_instances_callback, }; static void classInitNative(JNIEnv* env, jclass clazz) { int err; hw_module_t* module; Loading Loading @@ -486,6 +563,11 @@ static void classInitNative(JNIEnv* env, jclass clazz) { method_aclStateChangeCallback = env->GetMethodID(jniCallbackClass, "aclStateChangeCallback", "(I[BI)V"); method_deviceMasInstancesFoundCallback = env->GetMethodID(jniCallbackClass, "deviceMasInstancesFoundCallback", "(I[B[Ljava/lang/String;[I[I[I)V"); char value[PROPERTY_VALUE_MAX]; property_get("bluetooth.mock_stack", value, ""); Loading Loading @@ -523,6 +605,17 @@ static bool initNative(JNIEnv* env, jobject obj) { sBluetoothInterface->get_profile_interface(BT_PROFILE_SOCKETS_ID)) == NULL) { ALOGE("Error getting socket interface"); } if ( (sBluetoothMceInterface = (btmce_interface_t *) sBluetoothInterface->get_profile_interface(BT_PROFILE_MAP_CLIENT_ID)) == NULL) { ALOGE("Error getting mapclient interface"); } else { if ( (sBluetoothMceInterface->init(&sBluetoothMceCallbacks)) != BT_STATUS_SUCCESS) { ALOGE("Failed to initialize Bluetooth MCE"); sBluetoothMceInterface = NULL; } } return JNI_TRUE; } return JNI_FALSE; Loading Loading @@ -824,6 +917,25 @@ static jboolean getRemoteServicesNative(JNIEnv *env, jobject obj, jbyteArray add return result; } static jboolean getRemoteMasInstancesNative(JNIEnv *env, jobject obj, jbyteArray address) { ALOGV("%s:",__FUNCTION__); jbyte *addr = NULL; jboolean result = JNI_FALSE; if (!sBluetoothMceInterface) return result; addr = env->GetByteArrayElements(address, NULL); if (addr == NULL) { jniThrowIOException(env, EINVAL); return result; } int ret = sBluetoothMceInterface->get_remote_mas_instances((bt_bdaddr_t *)addr); env->ReleaseByteArrayElements(address, addr, NULL); result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; return result; } static int connectSocketNative(JNIEnv *env, jobject object, jbyteArray address, jint type, jbyteArray uuidObj, jint channel, jint flag) { jbyte *addr = NULL, *uuid = NULL; Loading Loading @@ -924,6 +1036,7 @@ static JNINativeMethod sMethods[] = { {"pinReplyNative", "([BZI[B)Z", (void*) pinReplyNative}, {"sspReplyNative", "([BIZI)Z", (void*) sspReplyNative}, {"getRemoteServicesNative", "([B)Z", (void*) getRemoteServicesNative}, {"getRemoteMasInstancesNative", "([B)Z", (void*) getRemoteMasInstancesNative}, {"connectSocketNative", "([BI[BII)I", (void*) connectSocketNative}, {"createSocketChannelNative", "(ILjava/lang/String;[BII)I", (void*) createSocketChannelNative} Loading src/com/android/bluetooth/btservice/AdapterService.java +18 −0 Original line number Diff line number Diff line Loading @@ -837,6 +837,17 @@ public class AdapterService extends Service { return service.fetchRemoteUuids(device); } public boolean fetchRemoteMasInstances(BluetoothDevice device) { if (!Utils.checkCaller()) { Log.w(TAG,"fetchMasInstances(): not allowed for non-active user"); return false; } AdapterService service = getService(); if (service == null) return false; return service.fetchRemoteMasInstances(device); } public boolean setPin(BluetoothDevice device, boolean accept, int len, byte[] pinCode) { if (!Utils.checkCaller()) { Log.w(TAG,"setPin(): not allowed for non-active user"); Loading Loading @@ -1318,6 +1329,12 @@ public class AdapterService extends Service { return true; } boolean fetchRemoteMasInstances(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); mRemoteDevices.fetchMasInstances(device); return true; } boolean setPin(BluetoothDevice device, boolean accept, int len, byte[] pinCode) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device); Loading Loading @@ -1454,6 +1471,7 @@ public class AdapterService extends Service { accept, int passkey); /*package*/ native boolean getRemoteServicesNative(byte[] address); /*package*/ native boolean getRemoteMasInstancesNative(byte[] address); // TODO(BT) move this to ../btsock dir private native int connectSocketNative(byte[] address, int type, Loading src/com/android/bluetooth/btservice/JniCallbacks.java +6 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 The Linux Foundation. All rights reserved * Not a Contribution. * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); Loading Loading @@ -81,4 +83,8 @@ final class JniCallbacks { mAdapterProperties.adapterPropertyChangedCallback(types, val); } void deviceMasInstancesFoundCallback(int status, byte[] address, String[] name, int[] scn, int[] id, int[] msgtype) { mRemoteDevices.deviceMasInstancesFoundCallback(status, address, name, scn, id, msgtype); } } src/com/android/bluetooth/btservice/RemoteDevices.java +63 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ package com.android.bluetooth.btservice; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothMasInstance; import android.content.Context; import android.content.Intent; import android.os.Handler; Loading @@ -43,6 +44,7 @@ final class RemoteDevices { private static BluetoothAdapter mAdapter; private static AdapterService mAdapterService; private static ArrayList<BluetoothDevice> mSdpTracker; private static ArrayList<BluetoothDevice> mSdpMasTracker; /* The WakeLock is used for bringing up the LCD during a pairing request * from remote device when Android is in Suspend state.*/ Loading @@ -52,12 +54,16 @@ final class RemoteDevices { private static final int UUID_INTENT_DELAY = 6000; private static final int MESSAGE_UUID_INTENT = 1; private static final int MAS_INSTANCE_INTENT_DELAY = 6000; private static final int MESSAGE_MAS_INSTANCE_INTENT = 2; private HashMap<BluetoothDevice, DeviceProperties> mDevices; RemoteDevices(PowerManager pm, AdapterService service) { mAdapter = BluetoothAdapter.getDefaultAdapter(); mAdapterService = service; mSdpTracker = new ArrayList<BluetoothDevice>(); mSdpMasTracker = new ArrayList<BluetoothDevice>(); mDevices = new HashMap<BluetoothDevice, DeviceProperties>(); //WakeLock instantiation in RemoteDevices class Loading @@ -72,6 +78,9 @@ final class RemoteDevices { if (mSdpTracker !=null) mSdpTracker.clear(); if (mSdpMasTracker != null) mSdpMasTracker.clear(); if (mDevices != null) mDevices.clear(); } Loading Loading @@ -258,6 +267,18 @@ final class RemoteDevices { mSdpTracker.remove(device); } private void sendMasInstanceIntent(BluetoothDevice device, ArrayList<BluetoothMasInstance> instances) { Intent intent = new Intent(BluetoothDevice.ACTION_MAS_INSTANCE); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); if (instances != null) intent.putExtra(BluetoothDevice.EXTRA_MAS_INSTANCE, instances); mAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_ADMIN_PERM); //Remove the outstanding UUID request mSdpMasTracker.remove(device); } private void sendDisplayPinIntent(byte[] address, int pin) { // Acquire wakelock during PIN code request to bring up LCD display mWakeLock.acquire(); Loading Loading @@ -484,6 +505,31 @@ final class RemoteDevices { mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM); } void deviceMasInstancesFoundCallback(int status, byte[] address, String[] name, int[] scn, int[] id, int[] msgtype) { BluetoothDevice device = getDevice(address); if (device == null) { errorLog("deviceMasInstancesFoundCallback: Device is NULL"); return; } debugLog("deviceMasInstancesFoundCallback: found " + name.length + " instances"); ArrayList<BluetoothMasInstance> instances = new ArrayList<BluetoothMasInstance>(); for (int i = 0; i < name.length; i++) { BluetoothMasInstance inst = new BluetoothMasInstance(id[i], name[i], scn[i], msgtype[i]); debugLog(inst.toString()); instances.add(inst); } sendMasInstanceIntent(device, instances); } void fetchUuids(BluetoothDevice device) { if (mSdpTracker.contains(device)) return; mSdpTracker.add(device); Loading @@ -496,6 +542,17 @@ final class RemoteDevices { mAdapterService.getRemoteServicesNative(Utils.getBytesFromAddress(device.getAddress())); } void fetchMasInstances(BluetoothDevice device) { if (mSdpMasTracker.contains(device)) return; mSdpMasTracker.add(device); Message message = mHandler.obtainMessage(MESSAGE_MAS_INSTANCE_INTENT); message.obj = device; mHandler.sendMessageDelayed(message, MAS_INSTANCE_INTENT_DELAY); mAdapterService.getRemoteMasInstancesNative(Utils.getBytesFromAddress(device.getAddress())); } private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { Loading @@ -506,6 +563,12 @@ final class RemoteDevices { sendUuidIntent(device); } break; case MESSAGE_MAS_INSTANCE_INTENT: BluetoothDevice dev = (BluetoothDevice)msg.obj; if (dev != null) { sendMasInstanceIntent(dev, null); } break; } } }; Loading Loading
jni/com_android_bluetooth_btservice_AdapterService.cpp +113 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 The Linux Foundation. All rights reserved * Not a Contribution. * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); Loading @@ -17,6 +19,7 @@ #define LOG_TAG "BluetoothServiceJni" #include "com_android_bluetooth.h" #include "hardware/bt_sock.h" #include "hardware/bt_mce.h" #include "utils/Log.h" #include "utils/misc.h" #include "cutils/properties.h" Loading @@ -40,9 +43,11 @@ static jmethodID method_sspRequestCallback; static jmethodID method_bondStateChangeCallback; static jmethodID method_aclStateChangeCallback; static jmethodID method_discoveryStateChangeCallback; static jmethodID method_deviceMasInstancesFoundCallback; static const bt_interface_t *sBluetoothInterface = NULL; static const btsock_interface_t *sBluetoothSocketInterface = NULL; static const btmce_interface_t *sBluetoothMceInterface = NULL; static JNIEnv *callbackEnv = NULL; static jobject sJniCallbacksObj; Loading Loading @@ -455,6 +460,78 @@ bt_callbacks_t sBluetoothCallbacks = { le_test_mode_recv_callback }; static void remote_mas_instances_callback(bt_status_t status, bt_bdaddr_t *bd_addr, int num_instances, btmce_mas_instance_t *instances) { if (!checkCallbackThread()) { ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__); return; } ALOGV("%s: Status is: %d, Instances: %d", __FUNCTION__, status, num_instances); if (status != BT_STATUS_SUCCESS) { ALOGE("%s: Status %d is incorrect", __FUNCTION__, status); return; } callbackEnv->PushLocalFrame(ADDITIONAL_NREFS); jbyteArray addr = NULL; jobjectArray a_name = NULL; jintArray a_scn = NULL; jintArray a_masid = NULL; jintArray a_msgtype = NULL; jclass mclass; mclass = callbackEnv->FindClass("java/lang/String"); addr = callbackEnv->NewByteArray(sizeof(bt_bdaddr_t)); if (addr == NULL) goto clean; callbackEnv->SetByteArrayRegion(addr, 0, sizeof(bt_bdaddr_t), (jbyte*)bd_addr); a_name = callbackEnv->NewObjectArray(num_instances, mclass, NULL); if (a_name == NULL) goto clean; a_scn = callbackEnv->NewIntArray(num_instances); if (a_scn == NULL) goto clean; a_masid = callbackEnv->NewIntArray(num_instances); if (a_masid == NULL) goto clean; a_msgtype = callbackEnv->NewIntArray(num_instances); if (a_msgtype == NULL) goto clean; for (int i = 0; i < num_instances; i++) { jstring name = callbackEnv->NewStringUTF(instances[i].p_name); callbackEnv->SetObjectArrayElement(a_name, i, name); callbackEnv->SetIntArrayRegion(a_scn, i, 1, &instances[i].scn); callbackEnv->SetIntArrayRegion(a_masid, i, 1, &instances[i].id); callbackEnv->SetIntArrayRegion(a_msgtype, i, 1, &instances[i].msg_types); callbackEnv->DeleteLocalRef(name); } callbackEnv->CallVoidMethod(sJniCallbacksObj, method_deviceMasInstancesFoundCallback, (jint) status, addr, a_name, a_scn, a_masid, a_msgtype); checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__); clean: if (addr != NULL) callbackEnv->DeleteLocalRef(addr); if (a_name != NULL) callbackEnv->DeleteLocalRef(a_name); if (a_scn != NULL) callbackEnv->DeleteLocalRef(a_scn); if (a_masid != NULL) callbackEnv->DeleteLocalRef(a_masid); if (a_msgtype != NULL) callbackEnv->DeleteLocalRef(a_msgtype); callbackEnv->PopLocalFrame(NULL); } static btmce_callbacks_t sBluetoothMceCallbacks = { sizeof(sBluetoothMceCallbacks), remote_mas_instances_callback, }; static void classInitNative(JNIEnv* env, jclass clazz) { int err; hw_module_t* module; Loading Loading @@ -486,6 +563,11 @@ static void classInitNative(JNIEnv* env, jclass clazz) { method_aclStateChangeCallback = env->GetMethodID(jniCallbackClass, "aclStateChangeCallback", "(I[BI)V"); method_deviceMasInstancesFoundCallback = env->GetMethodID(jniCallbackClass, "deviceMasInstancesFoundCallback", "(I[B[Ljava/lang/String;[I[I[I)V"); char value[PROPERTY_VALUE_MAX]; property_get("bluetooth.mock_stack", value, ""); Loading Loading @@ -523,6 +605,17 @@ static bool initNative(JNIEnv* env, jobject obj) { sBluetoothInterface->get_profile_interface(BT_PROFILE_SOCKETS_ID)) == NULL) { ALOGE("Error getting socket interface"); } if ( (sBluetoothMceInterface = (btmce_interface_t *) sBluetoothInterface->get_profile_interface(BT_PROFILE_MAP_CLIENT_ID)) == NULL) { ALOGE("Error getting mapclient interface"); } else { if ( (sBluetoothMceInterface->init(&sBluetoothMceCallbacks)) != BT_STATUS_SUCCESS) { ALOGE("Failed to initialize Bluetooth MCE"); sBluetoothMceInterface = NULL; } } return JNI_TRUE; } return JNI_FALSE; Loading Loading @@ -824,6 +917,25 @@ static jboolean getRemoteServicesNative(JNIEnv *env, jobject obj, jbyteArray add return result; } static jboolean getRemoteMasInstancesNative(JNIEnv *env, jobject obj, jbyteArray address) { ALOGV("%s:",__FUNCTION__); jbyte *addr = NULL; jboolean result = JNI_FALSE; if (!sBluetoothMceInterface) return result; addr = env->GetByteArrayElements(address, NULL); if (addr == NULL) { jniThrowIOException(env, EINVAL); return result; } int ret = sBluetoothMceInterface->get_remote_mas_instances((bt_bdaddr_t *)addr); env->ReleaseByteArrayElements(address, addr, NULL); result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE; return result; } static int connectSocketNative(JNIEnv *env, jobject object, jbyteArray address, jint type, jbyteArray uuidObj, jint channel, jint flag) { jbyte *addr = NULL, *uuid = NULL; Loading Loading @@ -924,6 +1036,7 @@ static JNINativeMethod sMethods[] = { {"pinReplyNative", "([BZI[B)Z", (void*) pinReplyNative}, {"sspReplyNative", "([BIZI)Z", (void*) sspReplyNative}, {"getRemoteServicesNative", "([B)Z", (void*) getRemoteServicesNative}, {"getRemoteMasInstancesNative", "([B)Z", (void*) getRemoteMasInstancesNative}, {"connectSocketNative", "([BI[BII)I", (void*) connectSocketNative}, {"createSocketChannelNative", "(ILjava/lang/String;[BII)I", (void*) createSocketChannelNative} Loading
src/com/android/bluetooth/btservice/AdapterService.java +18 −0 Original line number Diff line number Diff line Loading @@ -837,6 +837,17 @@ public class AdapterService extends Service { return service.fetchRemoteUuids(device); } public boolean fetchRemoteMasInstances(BluetoothDevice device) { if (!Utils.checkCaller()) { Log.w(TAG,"fetchMasInstances(): not allowed for non-active user"); return false; } AdapterService service = getService(); if (service == null) return false; return service.fetchRemoteMasInstances(device); } public boolean setPin(BluetoothDevice device, boolean accept, int len, byte[] pinCode) { if (!Utils.checkCaller()) { Log.w(TAG,"setPin(): not allowed for non-active user"); Loading Loading @@ -1318,6 +1329,12 @@ public class AdapterService extends Service { return true; } boolean fetchRemoteMasInstances(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); mRemoteDevices.fetchMasInstances(device); return true; } boolean setPin(BluetoothDevice device, boolean accept, int len, byte[] pinCode) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device); Loading Loading @@ -1454,6 +1471,7 @@ public class AdapterService extends Service { accept, int passkey); /*package*/ native boolean getRemoteServicesNative(byte[] address); /*package*/ native boolean getRemoteMasInstancesNative(byte[] address); // TODO(BT) move this to ../btsock dir private native int connectSocketNative(byte[] address, int type, Loading
src/com/android/bluetooth/btservice/JniCallbacks.java +6 −0 Original line number Diff line number Diff line /* * Copyright (C) 2013 The Linux Foundation. All rights reserved * Not a Contribution. * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); Loading Loading @@ -81,4 +83,8 @@ final class JniCallbacks { mAdapterProperties.adapterPropertyChangedCallback(types, val); } void deviceMasInstancesFoundCallback(int status, byte[] address, String[] name, int[] scn, int[] id, int[] msgtype) { mRemoteDevices.deviceMasInstancesFoundCallback(status, address, name, scn, id, msgtype); } }
src/com/android/bluetooth/btservice/RemoteDevices.java +63 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ package com.android.bluetooth.btservice; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothMasInstance; import android.content.Context; import android.content.Intent; import android.os.Handler; Loading @@ -43,6 +44,7 @@ final class RemoteDevices { private static BluetoothAdapter mAdapter; private static AdapterService mAdapterService; private static ArrayList<BluetoothDevice> mSdpTracker; private static ArrayList<BluetoothDevice> mSdpMasTracker; /* The WakeLock is used for bringing up the LCD during a pairing request * from remote device when Android is in Suspend state.*/ Loading @@ -52,12 +54,16 @@ final class RemoteDevices { private static final int UUID_INTENT_DELAY = 6000; private static final int MESSAGE_UUID_INTENT = 1; private static final int MAS_INSTANCE_INTENT_DELAY = 6000; private static final int MESSAGE_MAS_INSTANCE_INTENT = 2; private HashMap<BluetoothDevice, DeviceProperties> mDevices; RemoteDevices(PowerManager pm, AdapterService service) { mAdapter = BluetoothAdapter.getDefaultAdapter(); mAdapterService = service; mSdpTracker = new ArrayList<BluetoothDevice>(); mSdpMasTracker = new ArrayList<BluetoothDevice>(); mDevices = new HashMap<BluetoothDevice, DeviceProperties>(); //WakeLock instantiation in RemoteDevices class Loading @@ -72,6 +78,9 @@ final class RemoteDevices { if (mSdpTracker !=null) mSdpTracker.clear(); if (mSdpMasTracker != null) mSdpMasTracker.clear(); if (mDevices != null) mDevices.clear(); } Loading Loading @@ -258,6 +267,18 @@ final class RemoteDevices { mSdpTracker.remove(device); } private void sendMasInstanceIntent(BluetoothDevice device, ArrayList<BluetoothMasInstance> instances) { Intent intent = new Intent(BluetoothDevice.ACTION_MAS_INSTANCE); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); if (instances != null) intent.putExtra(BluetoothDevice.EXTRA_MAS_INSTANCE, instances); mAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_ADMIN_PERM); //Remove the outstanding UUID request mSdpMasTracker.remove(device); } private void sendDisplayPinIntent(byte[] address, int pin) { // Acquire wakelock during PIN code request to bring up LCD display mWakeLock.acquire(); Loading Loading @@ -484,6 +505,31 @@ final class RemoteDevices { mAdapterService.sendBroadcast(intent, mAdapterService.BLUETOOTH_PERM); } void deviceMasInstancesFoundCallback(int status, byte[] address, String[] name, int[] scn, int[] id, int[] msgtype) { BluetoothDevice device = getDevice(address); if (device == null) { errorLog("deviceMasInstancesFoundCallback: Device is NULL"); return; } debugLog("deviceMasInstancesFoundCallback: found " + name.length + " instances"); ArrayList<BluetoothMasInstance> instances = new ArrayList<BluetoothMasInstance>(); for (int i = 0; i < name.length; i++) { BluetoothMasInstance inst = new BluetoothMasInstance(id[i], name[i], scn[i], msgtype[i]); debugLog(inst.toString()); instances.add(inst); } sendMasInstanceIntent(device, instances); } void fetchUuids(BluetoothDevice device) { if (mSdpTracker.contains(device)) return; mSdpTracker.add(device); Loading @@ -496,6 +542,17 @@ final class RemoteDevices { mAdapterService.getRemoteServicesNative(Utils.getBytesFromAddress(device.getAddress())); } void fetchMasInstances(BluetoothDevice device) { if (mSdpMasTracker.contains(device)) return; mSdpMasTracker.add(device); Message message = mHandler.obtainMessage(MESSAGE_MAS_INSTANCE_INTENT); message.obj = device; mHandler.sendMessageDelayed(message, MAS_INSTANCE_INTENT_DELAY); mAdapterService.getRemoteMasInstancesNative(Utils.getBytesFromAddress(device.getAddress())); } private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { Loading @@ -506,6 +563,12 @@ final class RemoteDevices { sendUuidIntent(device); } break; case MESSAGE_MAS_INSTANCE_INTENT: BluetoothDevice dev = (BluetoothDevice)msg.obj; if (dev != null) { sendMasInstanceIntent(dev, null); } break; } } }; Loading