summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-03-16 11:33:41 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-16 11:33:41 -0700
commit084f6ced41f860f06e50e316f9e8d2bce1df5388 (patch)
tree6c5de28fbe26fe3e931f778aaa6e124f87c51457
parent4268f76938fb080026c2a4c24ed353b49487084b (diff)
parentb556e6ad18d6ead459e78e97fd3b815cca589bbe (diff)
Merge changes I07a13ed0,I2e5e6a40,I826189c8 into main
* changes: Convert DistanceMeasurementBinderTest to Kotlin Convert AdvertiseBinderTest to Kotlin Convert ScanBinderTest to Kotlin
-rw-r--r--android/app/tests/unit/Android.bp9
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseBinderTest.java202
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseBinderTest.kt201
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementBinderTest.java119
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementBinderTest.kt112
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanBinderTest.java194
-rw-r--r--android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanBinderTest.kt187
7 files changed, 507 insertions, 517 deletions
diff --git a/android/app/tests/unit/Android.bp b/android/app/tests/unit/Android.bp
index 01d195cc43..a5b7dc36c8 100644
--- a/android/app/tests/unit/Android.bp
+++ b/android/app/tests/unit/Android.bp
@@ -35,6 +35,7 @@ android_test {
"androidx.room_room-runtime",
"androidx.room_room-testing",
"androidx.test.espresso.intents",
+ "androidx.test.ext.junit",
"androidx.test.ext.truth",
"androidx.test.rules",
"androidx.test.uiautomator_uiautomator",
@@ -45,6 +46,7 @@ android_test {
"gson",
"guava-android-testlib",
"mmslib",
+ "mockito-kotlin2",
"mockito-target-extended",
"modules-utils-handlerexecutor",
"platform-parametric-runner-lib",
@@ -61,8 +63,11 @@ android_test {
jarjar_rules: ":bluetooth-jarjar-rules",
asset_dirs: ["src/com/android/bluetooth/btservice/storage/schemas"],
- // Include all test java files.
- srcs: ["src/**/*.java"],
+ // Include all test java and kotlin files.
+ srcs: [
+ "src/**/*.java",
+ "src/**/*.kt",
+ ],
jacoco: {
include_filter: ["android.bluetooth.*"],
exclude_filter: [],
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseBinderTest.java
deleted file mode 100644
index c78c9ec6db..0000000000
--- a/android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseBinderTest.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Copyright (C) 2025 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.bluetooth.gatt;
-
-import static com.android.bluetooth.TestUtils.MockitoRule;
-
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import android.bluetooth.BluetoothManager;
-import android.bluetooth.le.AdvertiseData;
-import android.bluetooth.le.AdvertisingSetParameters;
-import android.bluetooth.le.IAdvertisingSetCallback;
-import android.bluetooth.le.PeriodicAdvertisingParameters;
-import android.content.AttributionSource;
-
-import androidx.test.filters.SmallTest;
-import androidx.test.platform.app.InstrumentationRegistry;
-import androidx.test.runner.AndroidJUnit4;
-
-import com.android.bluetooth.btservice.AdapterService;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-
-/** Test cases for {@link AdvertiseBinder}. */
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class AdvertiseBinderTest {
- @Rule public final MockitoRule mMockitoRule = new MockitoRule();
-
- @Mock private AdapterService mAdapterService;
- @Mock private AdvertiseManager mAdvertiseManager;
-
- private final AttributionSource mAttributionSource =
- InstrumentationRegistry.getInstrumentation()
- .getTargetContext()
- .getSystemService(BluetoothManager.class)
- .getAdapter()
- .getAttributionSource();
- private AdvertiseBinder mBinder;
-
- @Before
- public void setUp() {
- doAnswer(
- invocation -> {
- ((Runnable) invocation.getArgument(0)).run();
- return null;
- })
- .when(mAdvertiseManager)
- .doOnAdvertiseThread(any());
- mBinder = new AdvertiseBinder(mAdapterService, mAdvertiseManager);
- }
-
- @Test
- public void startAdvertisingSet() {
- AdvertisingSetParameters parameters = new AdvertisingSetParameters.Builder().build();
- AdvertiseData advertiseData = new AdvertiseData.Builder().build();
- AdvertiseData scanResponse = new AdvertiseData.Builder().build();
- PeriodicAdvertisingParameters periodicParameters =
- new PeriodicAdvertisingParameters.Builder().build();
- AdvertiseData periodicData = new AdvertiseData.Builder().build();
- int duration = 1;
- int maxExtAdvEvents = 2;
- int serverIf = 3;
- IAdvertisingSetCallback callback = mock(IAdvertisingSetCallback.class);
-
- mBinder.startAdvertisingSet(
- parameters,
- advertiseData,
- scanResponse,
- periodicParameters,
- periodicData,
- duration,
- maxExtAdvEvents,
- serverIf,
- callback,
- mAttributionSource);
-
- verify(mAdvertiseManager)
- .startAdvertisingSet(
- parameters,
- advertiseData,
- scanResponse,
- periodicParameters,
- periodicData,
- duration,
- maxExtAdvEvents,
- serverIf,
- callback,
- mAttributionSource);
- }
-
- @Test
- public void stopAdvertisingSet() {
- IAdvertisingSetCallback callback = mock(IAdvertisingSetCallback.class);
-
- mBinder.stopAdvertisingSet(callback, mAttributionSource);
-
- verify(mAdvertiseManager).stopAdvertisingSet(callback);
- }
-
- @Test
- public void setAdvertisingData() {
- int advertiserId = 1;
- AdvertiseData data = new AdvertiseData.Builder().build();
-
- mBinder.setAdvertisingData(advertiserId, data, mAttributionSource);
- verify(mAdvertiseManager).setAdvertisingData(advertiserId, data);
- }
-
- @Test
- public void setAdvertisingParameters() {
- int advertiserId = 1;
- AdvertisingSetParameters parameters = new AdvertisingSetParameters.Builder().build();
-
- mBinder.setAdvertisingParameters(advertiserId, parameters, mAttributionSource);
- verify(mAdvertiseManager).setAdvertisingParameters(advertiserId, parameters);
- }
-
- @Test
- public void setPeriodicAdvertisingData() {
- int advertiserId = 1;
- AdvertiseData data = new AdvertiseData.Builder().build();
-
- mBinder.setPeriodicAdvertisingData(advertiserId, data, mAttributionSource);
- verify(mAdvertiseManager).setPeriodicAdvertisingData(advertiserId, data);
- }
-
- @Test
- public void setPeriodicAdvertisingEnable() {
- int advertiserId = 1;
- boolean enable = true;
-
- mBinder.setPeriodicAdvertisingEnable(advertiserId, enable, mAttributionSource);
- verify(mAdvertiseManager).setPeriodicAdvertisingEnable(advertiserId, enable);
- }
-
- @Test
- public void setPeriodicAdvertisingParameters() {
- int advertiserId = 1;
- PeriodicAdvertisingParameters parameters =
- new PeriodicAdvertisingParameters.Builder().build();
-
- mBinder.setPeriodicAdvertisingParameters(advertiserId, parameters, mAttributionSource);
- verify(mAdvertiseManager).setPeriodicAdvertisingParameters(advertiserId, parameters);
- }
-
- @Test
- public void setScanResponseData() {
- int advertiserId = 1;
- AdvertiseData data = new AdvertiseData.Builder().build();
-
- mBinder.setScanResponseData(advertiserId, data, mAttributionSource);
- verify(mAdvertiseManager).setScanResponseData(advertiserId, data);
- }
-
- @Test
- public void getOwnAddress() {
- int advertiserId = 1;
-
- mBinder.getOwnAddress(advertiserId, mAttributionSource);
- verify(mAdvertiseManager).getOwnAddress(advertiserId);
- }
-
- @Test
- public void enableAdvertisingSet() {
- int advertiserId = 1;
- boolean enable = true;
- int duration = 3;
- int maxExtAdvEvents = 4;
-
- mBinder.enableAdvertisingSet(
- advertiserId, enable, duration, maxExtAdvEvents, mAttributionSource);
- verify(mAdvertiseManager)
- .enableAdvertisingSet(advertiserId, enable, duration, maxExtAdvEvents);
- }
-
- @Test
- public void cleanUp_doesNotCrash() {
- mBinder.cleanup();
- }
-}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseBinderTest.kt b/android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseBinderTest.kt
new file mode 100644
index 0000000000..6b038678f0
--- /dev/null
+++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/AdvertiseBinderTest.kt
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bluetooth.gatt
+
+import android.bluetooth.BluetoothManager
+import android.bluetooth.le.AdvertiseData
+import android.bluetooth.le.AdvertisingSetParameters
+import android.bluetooth.le.IAdvertisingSetCallback
+import android.bluetooth.le.PeriodicAdvertisingParameters
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import androidx.test.platform.app.InstrumentationRegistry
+import com.android.bluetooth.TestUtils.MockitoRule
+import com.android.bluetooth.btservice.AdapterService
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mock
+import org.mockito.Mockito.any
+import org.mockito.Mockito.doAnswer
+import org.mockito.Mockito.mock
+import org.mockito.Mockito.verify
+import org.mockito.kotlin.whenever
+
+/** Test cases for [AdvertiseBinder] */
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class AdvertiseBinderTest {
+
+ @get:Rule val mockitoRule = MockitoRule()
+
+ @Mock private lateinit var adapterService: AdapterService
+ @Mock private lateinit var advertiseManager: AdvertiseManager
+
+ private val attributionSource =
+ InstrumentationRegistry.getInstrumentation()
+ .targetContext
+ .getSystemService(BluetoothManager::class.java)
+ .adapter
+ .attributionSource
+
+ private lateinit var binder: AdvertiseBinder
+
+ @Before
+ fun setUp() {
+ doAnswer { invocation ->
+ (invocation.getArgument(0) as Runnable).run()
+ null
+ }
+ .whenever(advertiseManager)
+ .doOnAdvertiseThread(any())
+ binder = AdvertiseBinder(adapterService, advertiseManager)
+ }
+
+ @Test
+ fun startAdvertisingSet() {
+ val parameters = AdvertisingSetParameters.Builder().build()
+ val advertiseData = AdvertiseData.Builder().build()
+ val scanResponse = AdvertiseData.Builder().build()
+ val periodicParameters = PeriodicAdvertisingParameters.Builder().build()
+ val periodicData = AdvertiseData.Builder().build()
+ val duration = 1
+ val maxExtAdvEvents = 2
+ val serverIf = 3
+ val callback = mock(IAdvertisingSetCallback::class.java)
+
+ binder.startAdvertisingSet(
+ parameters,
+ advertiseData,
+ scanResponse,
+ periodicParameters,
+ periodicData,
+ duration,
+ maxExtAdvEvents,
+ serverIf,
+ callback,
+ attributionSource,
+ )
+ verify(advertiseManager)
+ .startAdvertisingSet(
+ parameters,
+ advertiseData,
+ scanResponse,
+ periodicParameters,
+ periodicData,
+ duration,
+ maxExtAdvEvents,
+ serverIf,
+ callback,
+ attributionSource,
+ )
+ }
+
+ @Test
+ fun stopAdvertisingSet() {
+ val callback = mock(IAdvertisingSetCallback::class.java)
+
+ binder.stopAdvertisingSet(callback, attributionSource)
+ verify(advertiseManager).stopAdvertisingSet(callback)
+ }
+
+ @Test
+ fun setAdvertisingData() {
+ val advertiserId = 1
+ val data = AdvertiseData.Builder().build()
+
+ binder.setAdvertisingData(advertiserId, data, attributionSource)
+ verify(advertiseManager).setAdvertisingData(advertiserId, data)
+ }
+
+ @Test
+ fun setAdvertisingParameters() {
+ val advertiserId = 1
+ val parameters = AdvertisingSetParameters.Builder().build()
+
+ binder.setAdvertisingParameters(advertiserId, parameters, attributionSource)
+ verify(advertiseManager).setAdvertisingParameters(advertiserId, parameters)
+ }
+
+ @Test
+ fun setPeriodicAdvertisingData() {
+ val advertiserId = 1
+ val data = AdvertiseData.Builder().build()
+
+ binder.setPeriodicAdvertisingData(advertiserId, data, attributionSource)
+ verify(advertiseManager).setPeriodicAdvertisingData(advertiserId, data)
+ }
+
+ @Test
+ fun setPeriodicAdvertisingEnable() {
+ val advertiserId = 1
+ val enable = true
+
+ binder.setPeriodicAdvertisingEnable(advertiserId, enable, attributionSource)
+ verify(advertiseManager).setPeriodicAdvertisingEnable(advertiserId, enable)
+ }
+
+ @Test
+ fun setPeriodicAdvertisingParameters() {
+ val advertiserId = 1
+ val parameters = PeriodicAdvertisingParameters.Builder().build()
+
+ binder.setPeriodicAdvertisingParameters(advertiserId, parameters, attributionSource)
+ verify(advertiseManager).setPeriodicAdvertisingParameters(advertiserId, parameters)
+ }
+
+ @Test
+ fun setScanResponseData() {
+ val advertiserId = 1
+ val data = AdvertiseData.Builder().build()
+
+ binder.setScanResponseData(advertiserId, data, attributionSource)
+ verify(advertiseManager).setScanResponseData(advertiserId, data)
+ }
+
+ @Test
+ fun getOwnAddress() {
+ val advertiserId = 1
+
+ binder.getOwnAddress(advertiserId, attributionSource)
+ verify(advertiseManager).getOwnAddress(advertiserId)
+ }
+
+ @Test
+ fun enableAdvertisingSet() {
+ val advertiserId = 1
+ val enable = true
+ val duration = 3
+ val maxExtAdvEvents = 4
+
+ binder.enableAdvertisingSet(
+ advertiserId,
+ enable,
+ duration,
+ maxExtAdvEvents,
+ attributionSource,
+ )
+ verify(advertiseManager)
+ .enableAdvertisingSet(advertiserId, enable, duration, maxExtAdvEvents)
+ }
+
+ @Test
+ fun cleanup_doesNotCrash() {
+ binder.cleanup()
+ }
+}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementBinderTest.java
deleted file mode 100644
index a65c805a47..0000000000
--- a/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementBinderTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (C) 2025 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.bluetooth.gatt;
-
-import static com.android.bluetooth.TestUtils.MockitoRule;
-import static com.android.bluetooth.TestUtils.getTestDevice;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothManager;
-import android.bluetooth.le.DistanceMeasurementMethod;
-import android.bluetooth.le.DistanceMeasurementParams;
-import android.bluetooth.le.IDistanceMeasurementCallback;
-import android.content.AttributionSource;
-import android.os.ParcelUuid;
-
-import androidx.test.filters.SmallTest;
-import androidx.test.platform.app.InstrumentationRegistry;
-import androidx.test.runner.AndroidJUnit4;
-
-import com.android.bluetooth.btservice.AdapterService;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-
-import java.util.Collections;
-import java.util.UUID;
-
-/** Test cases for {@link DistanceMeasurementBinder}. */
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class DistanceMeasurementBinderTest {
- @Rule public final MockitoRule mMockitoRule = new MockitoRule();
-
- @Mock private DistanceMeasurementManager mDistanceMeasurementManager;
- @Mock private AdapterService mAdapterService;
-
- private final AttributionSource mAttributionSource =
- InstrumentationRegistry.getInstrumentation()
- .getTargetContext()
- .getSystemService(BluetoothManager.class)
- .getAdapter()
- .getAttributionSource();
-
- private DistanceMeasurementBinder mBinder;
-
- @Before
- public void setUp() throws Throwable {
- mBinder = new DistanceMeasurementBinder(mAdapterService, mDistanceMeasurementManager);
- when(mDistanceMeasurementManager.getSupportedDistanceMeasurementMethods())
- .thenReturn(Collections.emptyList());
- when(mDistanceMeasurementManager.runOnDistanceMeasurementThreadAndWaitForResult(any()))
- .thenAnswer(
- invocationOnMock -> {
- DistanceMeasurementManager.GetResultTask task =
- invocationOnMock.getArgument(0);
- return task.getResult();
- });
- doAnswer(
- invocation -> {
- ((Runnable) (invocation.getArgument(0))).run();
- return null;
- })
- .when(mDistanceMeasurementManager)
- .postOnDistanceMeasurementThread(any());
- }
-
- @Test
- public void getSupportedDistanceMeasurementMethods() {
- mBinder.getSupportedDistanceMeasurementMethods(mAttributionSource);
- verify(mDistanceMeasurementManager).getSupportedDistanceMeasurementMethods();
- }
-
- @Test
- public void startDistanceMeasurement() {
- UUID uuid = UUID.randomUUID();
- BluetoothDevice device = getTestDevice(3);
- DistanceMeasurementParams params =
- new DistanceMeasurementParams.Builder(device)
- .setDurationSeconds(123)
- .setFrequency(DistanceMeasurementParams.REPORT_FREQUENCY_LOW)
- .build();
- IDistanceMeasurementCallback callback = mock(IDistanceMeasurementCallback.class);
- mBinder.startDistanceMeasurement(
- new ParcelUuid(uuid), params, callback, mAttributionSource);
- verify(mDistanceMeasurementManager).startDistanceMeasurement(uuid, params, callback);
- }
-
- @Test
- public void stopDistanceMeasurement() {
- UUID uuid = UUID.randomUUID();
- BluetoothDevice device = getTestDevice(3);
- int method = DistanceMeasurementMethod.DISTANCE_MEASUREMENT_METHOD_RSSI;
- mBinder.stopDistanceMeasurement(new ParcelUuid(uuid), device, method, mAttributionSource);
- verify(mDistanceMeasurementManager).stopDistanceMeasurement(uuid, device, method, false);
- }
-}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementBinderTest.kt b/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementBinderTest.kt
new file mode 100644
index 0000000000..b20eda9a17
--- /dev/null
+++ b/android/app/tests/unit/src/com/android/bluetooth/gatt/DistanceMeasurementBinderTest.kt
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bluetooth.gatt
+
+import android.bluetooth.BluetoothDevice
+import android.bluetooth.BluetoothManager
+import android.bluetooth.le.DistanceMeasurementMethod
+import android.bluetooth.le.DistanceMeasurementParams
+import android.bluetooth.le.IDistanceMeasurementCallback
+import android.os.ParcelUuid
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import androidx.test.platform.app.InstrumentationRegistry
+import com.android.bluetooth.TestUtils.MockitoRule
+import com.android.bluetooth.TestUtils.getTestDevice
+import com.android.bluetooth.btservice.AdapterService
+import com.android.bluetooth.gatt.DistanceMeasurementManager.GetResultTask
+import java.util.UUID
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mock
+import org.mockito.Mockito.any
+import org.mockito.Mockito.doAnswer
+import org.mockito.Mockito.doReturn
+import org.mockito.Mockito.mock
+import org.mockito.Mockito.verify
+import org.mockito.kotlin.whenever
+
+/** Test cases for [DistanceMeasurementBinder] */
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class DistanceMeasurementBinderTest {
+
+ @get:Rule val mockitoRule = MockitoRule()
+
+ @Mock private lateinit var distanceMeasurementManager: DistanceMeasurementManager
+ @Mock private lateinit var adapterService: AdapterService
+
+ private val attributionSource =
+ InstrumentationRegistry.getInstrumentation()
+ .targetContext
+ .getSystemService(BluetoothManager::class.java)
+ .adapter
+ .attributionSource
+
+ private lateinit var binder: DistanceMeasurementBinder
+
+ @Before
+ fun setUp() {
+ binder = DistanceMeasurementBinder(adapterService, distanceMeasurementManager)
+ doReturn(emptyList<DistanceMeasurementMethod>())
+ .whenever(distanceMeasurementManager)
+ .getSupportedDistanceMeasurementMethods()
+ doAnswer { invocationOnMock ->
+ val task = invocationOnMock.getArgument<GetResultTask<*>>(0)
+ task.result
+ }
+ .whenever(distanceMeasurementManager)
+ .runOnDistanceMeasurementThreadAndWaitForResult(any<GetResultTask<*>>())
+ doAnswer { invocation ->
+ (invocation.getArgument(0) as Runnable).run()
+ null
+ }
+ .whenever(distanceMeasurementManager)
+ .postOnDistanceMeasurementThread(any())
+ }
+
+ @Test
+ fun getSupportedDistanceMeasurementMethods() {
+ binder.getSupportedDistanceMeasurementMethods(attributionSource)
+ verify(distanceMeasurementManager).supportedDistanceMeasurementMethods
+ }
+
+ @Test
+ fun startDistanceMeasurement() {
+ val uuid = UUID.randomUUID()
+ val device: BluetoothDevice = getTestDevice(3)
+ val params =
+ DistanceMeasurementParams.Builder(device)
+ .setDurationSeconds(123)
+ .setFrequency(DistanceMeasurementParams.REPORT_FREQUENCY_LOW)
+ .build()
+ val callback = mock(IDistanceMeasurementCallback::class.java)
+ binder.startDistanceMeasurement(ParcelUuid(uuid), params, callback, attributionSource)
+ verify(distanceMeasurementManager).startDistanceMeasurement(uuid, params, callback)
+ }
+
+ @Test
+ fun stopDistanceMeasurement() {
+ val uuid = UUID.randomUUID()
+ val device: BluetoothDevice = getTestDevice(3)
+ val method = DistanceMeasurementMethod.DISTANCE_MEASUREMENT_METHOD_RSSI
+ binder.stopDistanceMeasurement(ParcelUuid(uuid), device, method, attributionSource)
+ verify(distanceMeasurementManager).stopDistanceMeasurement(uuid, device, method, false)
+ }
+}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanBinderTest.java
deleted file mode 100644
index 61c7df48b8..0000000000
--- a/android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanBinderTest.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright (C) 2025 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.bluetooth.le_scan;
-
-import static com.android.bluetooth.TestUtils.MockitoRule;
-import static com.android.bluetooth.TestUtils.getTestDevice;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import android.app.PendingIntent;
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothManager;
-import android.bluetooth.le.IPeriodicAdvertisingCallback;
-import android.bluetooth.le.IScannerCallback;
-import android.bluetooth.le.ScanFilter;
-import android.bluetooth.le.ScanResult;
-import android.bluetooth.le.ScanSettings;
-import android.content.AttributionSource;
-import android.content.Intent;
-import android.os.WorkSource;
-
-import androidx.test.filters.SmallTest;
-import androidx.test.platform.app.InstrumentationRegistry;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/** Test cases for {@link ScanBinder}. */
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class ScanBinderTest {
- @Rule public final MockitoRule mMockitoRule = new MockitoRule();
-
- @Mock private ScanController mScanController;
-
- private final AttributionSource mAttributionSource =
- InstrumentationRegistry.getInstrumentation()
- .getTargetContext()
- .getSystemService(BluetoothManager.class)
- .getAdapter()
- .getAttributionSource();
- private final BluetoothDevice mDevice = getTestDevice(89);
- private ScanBinder mBinder;
-
- @Before
- public void setUp() {
- mBinder = new ScanBinder(mScanController);
- }
-
- @Test
- public void registerScanner() {
- IScannerCallback callback = mock(IScannerCallback.class);
- WorkSource workSource = mock(WorkSource.class);
-
- mBinder.registerScanner(callback, workSource, mAttributionSource);
- verify(mScanController).registerScanner(callback, workSource, mAttributionSource);
- }
-
- @Test
- public void unregisterScanner() {
- int scannerId = 1;
-
- mBinder.unregisterScanner(scannerId, mAttributionSource);
- verify(mScanController).unregisterScanner(scannerId, mAttributionSource);
- }
-
- @Test
- public void startScan() {
- int scannerId = 1;
- ScanSettings settings = new ScanSettings.Builder().build();
- List<ScanFilter> filters = new ArrayList<>();
-
- mBinder.startScan(scannerId, settings, filters, mAttributionSource);
- verify(mScanController).startScan(scannerId, settings, filters, mAttributionSource);
- }
-
- @Test
- public void startScanForIntent() {
- PendingIntent intent =
- PendingIntent.getBroadcast(
- InstrumentationRegistry.getInstrumentation().getTargetContext(),
- 0,
- new Intent(),
- PendingIntent.FLAG_IMMUTABLE);
- ScanSettings settings = new ScanSettings.Builder().build();
- List<ScanFilter> filters = new ArrayList<>();
-
- mBinder.startScanForIntent(intent, settings, filters, mAttributionSource);
- verify(mScanController)
- .registerPiAndStartScan(intent, settings, filters, mAttributionSource);
- }
-
- @Test
- public void stopScan_withScannerId() {
- int scannerId = 1;
-
- mBinder.stopScan(scannerId, mAttributionSource);
- verify(mScanController).stopScan(scannerId, mAttributionSource);
- }
-
- @Test
- public void stopScan_withIntent() {
- PendingIntent intent =
- PendingIntent.getBroadcast(
- InstrumentationRegistry.getInstrumentation().getTargetContext(),
- 0,
- new Intent(),
- PendingIntent.FLAG_IMMUTABLE);
-
- mBinder.stopScanForIntent(intent, mAttributionSource);
- verify(mScanController).stopScan(intent, mAttributionSource);
- }
-
- @Test
- public void flushPendingBatchResults() {
- int scannerId = 1;
-
- mBinder.flushPendingBatchResults(scannerId, mAttributionSource);
- verify(mScanController).flushPendingBatchResults(scannerId, mAttributionSource);
- }
-
- @Test
- public void registerSync() {
- ScanResult scanResult = new ScanResult(mDevice, null, 0, 0);
- int skip = 1;
- int timeout = 2;
- IPeriodicAdvertisingCallback callback = mock(IPeriodicAdvertisingCallback.class);
-
- mBinder.registerSync(scanResult, skip, timeout, callback, mAttributionSource);
- verify(mScanController)
- .registerSync(scanResult, skip, timeout, callback, mAttributionSource);
- }
-
- @Test
- public void unregisterSync() {
- IPeriodicAdvertisingCallback callback = mock(IPeriodicAdvertisingCallback.class);
-
- mBinder.unregisterSync(callback, mAttributionSource);
- verify(mScanController).unregisterSync(callback, mAttributionSource);
- }
-
- @Test
- public void transferSync() {
- int serviceData = 1;
- int syncHandle = 2;
-
- mBinder.transferSync(mDevice, serviceData, syncHandle, mAttributionSource);
- verify(mScanController).transferSync(mDevice, serviceData, syncHandle, mAttributionSource);
- }
-
- @Test
- public void transferSetInfo() {
- int serviceData = 1;
- int advHandle = 2;
- IPeriodicAdvertisingCallback callback = mock(IPeriodicAdvertisingCallback.class);
-
- mBinder.transferSetInfo(mDevice, serviceData, advHandle, callback, mAttributionSource);
- verify(mScanController)
- .transferSetInfo(mDevice, serviceData, advHandle, callback, mAttributionSource);
- }
-
- @Test
- public void numHwTrackFiltersAvailable() {
- mBinder.numHwTrackFiltersAvailable(mAttributionSource);
- verify(mScanController).numHwTrackFiltersAvailable(mAttributionSource);
- }
-
- @Test
- public void cleanup_doesNotCrash() {
- mBinder.cleanup();
- }
-}
diff --git a/android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanBinderTest.kt b/android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanBinderTest.kt
new file mode 100644
index 0000000000..3424c48a54
--- /dev/null
+++ b/android/app/tests/unit/src/com/android/bluetooth/le_scan/ScanBinderTest.kt
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.bluetooth.le_scan
+
+import android.app.PendingIntent
+import android.bluetooth.BluetoothDevice
+import android.bluetooth.BluetoothManager
+import android.bluetooth.le.IPeriodicAdvertisingCallback
+import android.bluetooth.le.IScannerCallback
+import android.bluetooth.le.ScanFilter
+import android.bluetooth.le.ScanResult
+import android.bluetooth.le.ScanSettings
+import android.content.Intent
+import android.os.WorkSource
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import androidx.test.platform.app.InstrumentationRegistry
+import com.android.bluetooth.TestUtils.MockitoRule
+import com.android.bluetooth.TestUtils.getTestDevice
+import org.junit.Before
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.Mock
+import org.mockito.Mockito.mock
+import org.mockito.Mockito.verify
+
+/** Test cases for [ScanBinder] */
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+class ScanBinderTest {
+
+ @get:Rule val mockitoRule = MockitoRule()
+
+ @Mock private lateinit var scanController: ScanController
+
+ private val attributionSource =
+ InstrumentationRegistry.getInstrumentation()
+ .targetContext
+ .getSystemService(BluetoothManager::class.java)
+ .adapter
+ .attributionSource
+ private val device: BluetoothDevice = getTestDevice(89)
+ private lateinit var binder: ScanBinder
+
+ @Before
+ fun setUp() {
+ binder = ScanBinder(scanController)
+ }
+
+ @Test
+ fun registerScanner() {
+ val callback = mock(IScannerCallback::class.java)
+ val workSource = mock(WorkSource::class.java)
+
+ binder.registerScanner(callback, workSource, attributionSource)
+ verify(scanController).registerScanner(callback, workSource, attributionSource)
+ }
+
+ @Test
+ fun unregisterScanner() {
+ val scannerId = 1
+
+ binder.unregisterScanner(scannerId, attributionSource)
+ verify(scanController).unregisterScanner(scannerId, attributionSource)
+ }
+
+ @Test
+ fun startScan() {
+ val scannerId = 1
+ val settings = ScanSettings.Builder().build()
+ val filters = listOf<ScanFilter>()
+
+ binder.startScan(scannerId, settings, filters, attributionSource)
+ verify(scanController).startScan(scannerId, settings, filters, attributionSource)
+ }
+
+ @Test
+ fun startScanForIntent() {
+ val intent =
+ PendingIntent.getBroadcast(
+ InstrumentationRegistry.getInstrumentation().targetContext,
+ 0,
+ Intent(),
+ PendingIntent.FLAG_IMMUTABLE,
+ )
+ val settings = ScanSettings.Builder().build()
+ val filters = listOf<ScanFilter>()
+
+ binder.startScanForIntent(intent, settings, filters, attributionSource)
+ verify(scanController).registerPiAndStartScan(intent, settings, filters, attributionSource)
+ }
+
+ @Test
+ fun stopScan_withScannerId() {
+ val scannerId = 1
+
+ binder.stopScan(scannerId, attributionSource)
+ verify(scanController).stopScan(scannerId, attributionSource)
+ }
+
+ @Test
+ fun stopScan_withIntent() {
+ val intent =
+ PendingIntent.getBroadcast(
+ InstrumentationRegistry.getInstrumentation().targetContext,
+ 0,
+ Intent(),
+ PendingIntent.FLAG_IMMUTABLE,
+ )
+
+ binder.stopScanForIntent(intent, attributionSource)
+ verify(scanController).stopScan(intent, attributionSource)
+ }
+
+ @Test
+ fun flushPendingBatchResults() {
+ val scannerId = 1
+
+ binder.flushPendingBatchResults(scannerId, attributionSource)
+ verify(scanController).flushPendingBatchResults(scannerId, attributionSource)
+ }
+
+ @Test
+ fun registerSync() {
+ val scanResult = mock(ScanResult::class.java)
+ val skip = 1
+ val timeout = 2
+ val callback = mock(IPeriodicAdvertisingCallback::class.java)
+
+ binder.registerSync(scanResult, skip, timeout, callback, attributionSource)
+ verify(scanController).registerSync(scanResult, skip, timeout, callback, attributionSource)
+ }
+
+ @Test
+ fun unregisterSync() {
+ val callback = mock(IPeriodicAdvertisingCallback::class.java)
+
+ binder.unregisterSync(callback, attributionSource)
+ verify(scanController).unregisterSync(callback, attributionSource)
+ }
+
+ @Test
+ fun transferSync() {
+ val serviceData = 1
+ val syncHandle = 2
+
+ binder.transferSync(device, serviceData, syncHandle, attributionSource)
+ verify(scanController).transferSync(device, serviceData, syncHandle, attributionSource)
+ }
+
+ @Test
+ fun transferSetInfo() {
+ val serviceData = 1
+ val advHandle = 2
+ val callback = mock(IPeriodicAdvertisingCallback::class.java)
+
+ binder.transferSetInfo(device, serviceData, advHandle, callback, attributionSource)
+ verify(scanController)
+ .transferSetInfo(device, serviceData, advHandle, callback, attributionSource)
+ }
+
+ @Test
+ fun numHwTrackFiltersAvailable() {
+ binder.numHwTrackFiltersAvailable(attributionSource)
+ verify(scanController).numHwTrackFiltersAvailable(attributionSource)
+ }
+
+ @Test
+ fun cleanup_doesNotCrash() {
+ binder.cleanup()
+ }
+}