Loading android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -780,6 +780,22 @@ static jboolean cancelBondNative(JNIEnv* env, jobject obj, jbyteArray address) { return result; } static jboolean isConnectedNative(JNIEnv* env, jobject obj, jbyteArray address) { ALOGV("%s:",__FUNCTION__); if (!sBluetoothInterface) return JNI_FALSE; jbyte *addr = env->GetByteArrayElements(address, NULL); if (addr == NULL) { jniThrowIOException(env, EINVAL); return JNI_FALSE; } int ret = sBluetoothInterface->get_connection_state((bt_bdaddr_t *)addr); env->ReleaseByteArrayElements(address, addr, 0); return (ret != 0 ? JNI_TRUE : JNI_FALSE); } static jboolean pinReplyNative(JNIEnv *env, jobject obj, jbyteArray address, jboolean accept, jint len, jbyteArray pinArray) { ALOGV("%s:",__FUNCTION__); Loading Loading @@ -1065,6 +1081,7 @@ static JNINativeMethod sMethods[] = { {"createBondNative", "([B)Z", (void*) createBondNative}, {"removeBondNative", "([B)Z", (void*) removeBondNative}, {"cancelBondNative", "([B)Z", (void*) cancelBondNative}, {"isConnectedNative", "([B)Z", (void*) isConnectedNative}, {"pinReplyNative", "([BZI[B)Z", (void*) pinReplyNative}, {"sspReplyNative", "([BIZI)Z", (void*) sspReplyNative}, {"getRemoteServicesNative", "([B)Z", (void*) getRemoteServicesNative}, Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +4 −4 Original line number Diff line number Diff line Loading @@ -1314,10 +1314,8 @@ public class AdapterService extends Service { boolean isConnected(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device); if (deviceProp == null) return false; return deviceProp.getOpenAclConnectionCount() > 0; byte[] addr = Utils.getBytesFromAddress(device.getAddress()); return isConnectedNative(addr); } String getRemoteName(BluetoothDevice device) { Loading Loading @@ -1600,6 +1598,8 @@ public class AdapterService extends Service { /*package*/ native boolean removeBondNative(byte[] address); /*package*/ native boolean cancelBondNative(byte[] address); /*package*/ native boolean isConnectedNative(byte[] address); private native boolean startDiscoveryNative(); private native boolean cancelDiscoveryNative(); Loading android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +0 −13 Original line number Diff line number Diff line Loading @@ -107,11 +107,9 @@ final class RemoteDevices { private int mDeviceType; private String mAlias; private int mBondState; private AtomicInteger mOpenAclConnectionCount; DeviceProperties() { mBondState = BluetoothDevice.BOND_NONE; mOpenAclConnectionCount = new AtomicInteger(0); } /** Loading Loading @@ -212,10 +210,6 @@ final class RemoteDevices { return mBondState; } } int getOpenAclConnectionCount() { return mOpenAclConnectionCount.get(); } } private void sendUuidIntent(BluetoothDevice device) { Loading Loading @@ -415,7 +409,6 @@ final class RemoteDevices { return; } int openAclConnectionCount; DeviceProperties prop = getDeviceProperties(device); if (prop == null) { errorLog("aclStateChangeCallback reported unknown device " + Arrays.toString(address)); Loading @@ -424,15 +417,9 @@ final class RemoteDevices { if (newState == AbstractionLayer.BT_ACL_STATE_CONNECTED) { intent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED); debugLog("aclStateChangeCallback: State:Connected to Device:" + device); if (prop != null) { prop.mOpenAclConnectionCount.incrementAndGet(); } } else { intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED); debugLog("aclStateChangeCallback: State:DisConnected to Device:" + device); if (prop != null) { prop.mOpenAclConnectionCount.decrementAndGet(); } } intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); Loading Loading
android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -780,6 +780,22 @@ static jboolean cancelBondNative(JNIEnv* env, jobject obj, jbyteArray address) { return result; } static jboolean isConnectedNative(JNIEnv* env, jobject obj, jbyteArray address) { ALOGV("%s:",__FUNCTION__); if (!sBluetoothInterface) return JNI_FALSE; jbyte *addr = env->GetByteArrayElements(address, NULL); if (addr == NULL) { jniThrowIOException(env, EINVAL); return JNI_FALSE; } int ret = sBluetoothInterface->get_connection_state((bt_bdaddr_t *)addr); env->ReleaseByteArrayElements(address, addr, 0); return (ret != 0 ? JNI_TRUE : JNI_FALSE); } static jboolean pinReplyNative(JNIEnv *env, jobject obj, jbyteArray address, jboolean accept, jint len, jbyteArray pinArray) { ALOGV("%s:",__FUNCTION__); Loading Loading @@ -1065,6 +1081,7 @@ static JNINativeMethod sMethods[] = { {"createBondNative", "([B)Z", (void*) createBondNative}, {"removeBondNative", "([B)Z", (void*) removeBondNative}, {"cancelBondNative", "([B)Z", (void*) cancelBondNative}, {"isConnectedNative", "([B)Z", (void*) isConnectedNative}, {"pinReplyNative", "([BZI[B)Z", (void*) pinReplyNative}, {"sspReplyNative", "([BIZI)Z", (void*) sspReplyNative}, {"getRemoteServicesNative", "([B)Z", (void*) getRemoteServicesNative}, Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +4 −4 Original line number Diff line number Diff line Loading @@ -1314,10 +1314,8 @@ public class AdapterService extends Service { boolean isConnected(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device); if (deviceProp == null) return false; return deviceProp.getOpenAclConnectionCount() > 0; byte[] addr = Utils.getBytesFromAddress(device.getAddress()); return isConnectedNative(addr); } String getRemoteName(BluetoothDevice device) { Loading Loading @@ -1600,6 +1598,8 @@ public class AdapterService extends Service { /*package*/ native boolean removeBondNative(byte[] address); /*package*/ native boolean cancelBondNative(byte[] address); /*package*/ native boolean isConnectedNative(byte[] address); private native boolean startDiscoveryNative(); private native boolean cancelDiscoveryNative(); Loading
android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +0 −13 Original line number Diff line number Diff line Loading @@ -107,11 +107,9 @@ final class RemoteDevices { private int mDeviceType; private String mAlias; private int mBondState; private AtomicInteger mOpenAclConnectionCount; DeviceProperties() { mBondState = BluetoothDevice.BOND_NONE; mOpenAclConnectionCount = new AtomicInteger(0); } /** Loading Loading @@ -212,10 +210,6 @@ final class RemoteDevices { return mBondState; } } int getOpenAclConnectionCount() { return mOpenAclConnectionCount.get(); } } private void sendUuidIntent(BluetoothDevice device) { Loading Loading @@ -415,7 +409,6 @@ final class RemoteDevices { return; } int openAclConnectionCount; DeviceProperties prop = getDeviceProperties(device); if (prop == null) { errorLog("aclStateChangeCallback reported unknown device " + Arrays.toString(address)); Loading @@ -424,15 +417,9 @@ final class RemoteDevices { if (newState == AbstractionLayer.BT_ACL_STATE_CONNECTED) { intent = new Intent(BluetoothDevice.ACTION_ACL_CONNECTED); debugLog("aclStateChangeCallback: State:Connected to Device:" + device); if (prop != null) { prop.mOpenAclConnectionCount.incrementAndGet(); } } else { intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED); debugLog("aclStateChangeCallback: State:DisConnected to Device:" + device); if (prop != null) { prop.mOpenAclConnectionCount.decrementAndGet(); } } intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); Loading