Bring the specific transport for get_remote_service from framework
Add support to bring the specific transport for get_remote_service from the framework
Ignore-AOSP-First: avoid merge conflict
Bug: 194447999
Tag: #feature
Test: atest BluetoothInstrumentationTests
Test: Take two headphone to test the dual mode behavior
Change-Id: I4497350a41d607705de28032f757ff6195932326
Merged-In: I4497350a41d607705de28032f757ff6195932326
diff --git a/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp b/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp
index 84ccbbd..8a8c467 100644
--- a/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp
+++ b/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp
@@ -1469,7 +1469,7 @@
}
static jboolean getRemoteServicesNative(JNIEnv* env, jobject obj,
- jbyteArray address) {
+ jbyteArray address, jint transport) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1480,7 +1480,8 @@
return JNI_FALSE;
}
- int ret = sBluetoothInterface->get_remote_services((RawAddress*)addr);
+ int ret =
+ sBluetoothInterface->get_remote_services((RawAddress*)addr, transport);
env->ReleaseByteArrayElements(address, addr, 0);
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
@@ -1713,7 +1714,7 @@
{"getConnectionStateNative", "([B)I", (void*)getConnectionStateNative},
{"pinReplyNative", "([BZI[B)Z", (void*)pinReplyNative},
{"sspReplyNative", "([BIZI)Z", (void*)sspReplyNative},
- {"getRemoteServicesNative", "([B)Z", (void*)getRemoteServicesNative},
+ {"getRemoteServicesNative", "([BI)Z", (void*)getRemoteServicesNative},
{"alarmFiredNative", "()V", (void*)alarmFiredNative},
{"readEnergyInfo", "()I", (void*)readEnergyInfo},
{"dumpNative", "(Ljava/io/FileDescriptor;[Ljava/lang/String;)V",
diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterService.java b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
index 00d66bb..98a3810 100644
--- a/android/app/src/com/android/bluetooth/btservice/AdapterService.java
+++ b/android/app/src/com/android/bluetooth/btservice/AdapterService.java
@@ -16,6 +16,7 @@
package com.android.bluetooth.btservice;
+import static android.bluetooth.BluetoothDevice.TRANSPORT_AUTO;
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
import static android.text.format.DateUtils.SECOND_IN_MILLIS;
@@ -1905,12 +1906,13 @@
@Override
public boolean fetchRemoteUuids(BluetoothDevice device) {
- return fetchRemoteUuidsWithAttribution(device, Utils.getCallingAttributionSource());
+ return fetchRemoteUuidsWithAttribution(device, TRANSPORT_AUTO,
+ Utils.getCallingAttributionSource());
}
@Override
public boolean fetchRemoteUuidsWithAttribution(
- BluetoothDevice device, AttributionSource attributionSource) {
+ BluetoothDevice device, int transport, AttributionSource attributionSource) {
Attributable.setAttributionSource(device, attributionSource);
AdapterService service = getService();
if (service == null
@@ -1919,8 +1921,11 @@
service, attributionSource, "AdapterService fetchRemoteUuids")) {
return false;
}
+ if (transport != TRANSPORT_AUTO) {
+ enforceBluetoothPrivilegedPermission(service);
+ }
- service.mRemoteDevices.fetchUuids(device);
+ service.mRemoteDevices.fetchUuids(device, transport);
return true;
}
@@ -3927,7 +3932,7 @@
private native boolean sspReplyNative(byte[] address, int type, boolean accept, int passkey);
/*package*/
- native boolean getRemoteServicesNative(byte[] address);
+ native boolean getRemoteServicesNative(byte[] address, int transport);
/*package*/
native boolean getRemoteMasInstancesNative(byte[] address);
diff --git a/android/app/src/com/android/bluetooth/btservice/RemoteDevices.java b/android/app/src/com/android/bluetooth/btservice/RemoteDevices.java
index 34cbba7..16866bf 100644
--- a/android/app/src/com/android/bluetooth/btservice/RemoteDevices.java
+++ b/android/app/src/com/android/bluetooth/btservice/RemoteDevices.java
@@ -739,7 +739,7 @@
}
- void fetchUuids(BluetoothDevice device) {
+ void fetchUuids(BluetoothDevice device, int transport) {
if (sSdpTracker.contains(device)) {
return;
}
@@ -759,7 +759,8 @@
// Uses cached UUIDs if we are bonding. If not, we fetch the UUIDs with SDP.
if (deviceProperties == null || !deviceProperties.isBonding()) {
- sAdapterService.getRemoteServicesNative(Utils.getBytesFromAddress(device.getAddress()));
+ sAdapterService.getRemoteServicesNative(Utils.getBytesFromAddress(device.getAddress()),
+ transport);
}
}