Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27834cef authored by Charlie Boutier's avatar Charlie Boutier Committed by Automerger Merge Worker
Browse files

BumbleBluetoothTest: Add Dck Gatt Discover tests am: f84c1c74 am: 0c3d1551...

BumbleBluetoothTest: Add Dck Gatt Discover tests am: f84c1c74 am: 0c3d1551 am: 00283c47 am: 3231cdb9

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2769128



Change-Id: I074d0c2f5d2db2a65004b628048ab44bb4575840
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents e8a60817 3231cdb9
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -31,10 +31,11 @@ android_test_helper_app {
        "pandora_experimental-proto-java",
    ],

    // Include all test java files.
    srcs: ["src/**/*.java"],

    platform_apis: true,
    // Include all test java and kotlin files.
    srcs: [
        "src/**/*.java",
        "src/**/*.kt",
    ],
}

// This empty test host is needed for building required host binary
@@ -60,3 +61,17 @@ java_test_host {
        "general-tests",
    ],
}

python_binary_host {
    name: "bumble_pandora_server",
    main: "src/bumble_server.py",
    srcs: [
        "src/bumble_server.py",
    ],
    libs: [
        "bumble-pandora",
        "bumble_services_experimental-python",
        "pandora-python",
        "pandora_experimental-python",
    ],
}
+99 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 android.bluetooth

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.compatibility.common.util.AdoptShellPermissionsRule
import com.google.common.truth.Truth.assertThat
import com.google.protobuf.Empty
import io.grpc.Deadline
import java.util.UUID
import java.util.concurrent.TimeUnit
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.any
import org.mockito.Mockito.eq
import org.mockito.Mockito.mock
import org.mockito.Mockito.timeout
import org.mockito.Mockito.verify
import pandora.HostProto.AdvertiseRequest
import pandora.HostProto.OwnAddressType

@RunWith(AndroidJUnit4::class)
public class DckTest {
    private val TAG = "DckTest"
    private val TIMEOUT: Long = 2000

    private val context: Context = ApplicationProvider.getApplicationContext()
    private val bluetoothManager = context.getSystemService(BluetoothManager::class.java)!!
    private val bluetoothAdapter = bluetoothManager.adapter

    // CCC DK Specification R3 1.2.0 r14 section 19.2.1.2 Bluetooth Le Pairing
    private val CCC_DK_UUID = UUID.fromString("0000FFF5-0000-1000-8000-00805f9b34fb")

    @Rule @JvmField val mPermissionRule = AdoptShellPermissionsRule()

    @Rule @JvmField val mBumble = PandoraDevice()

    @Test
    fun testDiscoverDkGattService() {
        mBumble
            .dckBlocking()
            .withDeadline(Deadline.after(TIMEOUT, TimeUnit.MILLISECONDS))
            .register(Empty.getDefaultInstance())

        mBumble
            .hostBlocking()
            .advertise(
                AdvertiseRequest.newBuilder()
                    .setLegacy(true)
                    .setConnectable(true)
                    .setOwnAddressType(OwnAddressType.RANDOM)
                    .build()
            )

        val bumbleDevice =
            bluetoothAdapter.getRemoteLeDevice(
                Utils.BUMBLE_RANDOM_ADDRESS,
                BluetoothDevice.ADDRESS_TYPE_RANDOM
            )
        val gattCallback = mock(BluetoothGattCallback::class.java)
        var bumbleGatt = bumbleDevice.connectGatt(context, false, gattCallback)
        verify(gattCallback, timeout(TIMEOUT))
            .onConnectionStateChange(
                any(),
                eq(BluetoothGatt.GATT_SUCCESS),
                eq(BluetoothProfile.STATE_CONNECTED)
            )

        bumbleGatt.discoverServices()
        verify(gattCallback, timeout(TIMEOUT))
            .onServicesDiscovered(any(), eq(BluetoothGatt.GATT_SUCCESS))
        assertThat(bumbleGatt.getService(CCC_DK_UUID)).isNotNull()

        bumbleGatt.disconnect()
        verify(gattCallback, timeout(TIMEOUT))
            .onConnectionStateChange(
                any(),
                eq(BluetoothGatt.GATT_SUCCESS),
                eq(BluetoothProfile.STATE_DISCONNECTED)
            )
    }
}
+7 −7
Original line number Diff line number Diff line
@@ -32,11 +32,10 @@ import android.bluetooth.le.BluetoothLeScanner;
import android.content.Context;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.android.compatibility.common.util.AdoptShellPermissionsRule;


import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -54,8 +53,6 @@ import pandora.HostProto.OwnAddressType;
public class GattClientTest {
    private static final String TAG = "GattClientTest";

    private static final String BUMBLE_RPA = "51:F7:A8:75:AC:5E";

    @ClassRule public static final AdoptShellPermissionsRule PERM = new AdoptShellPermissionsRule();

    @Rule public final PandoraDevice mBumble = new PandoraDevice();
@@ -70,7 +67,8 @@ public class GattClientTest {
        advertiseWithBumble();

        BluetoothDevice device =
            mAdapter.getRemoteLeDevice(BUMBLE_RPA, BluetoothDevice.ADDRESS_TYPE_RANDOM);
                mAdapter.getRemoteLeDevice(
                        Utils.BUMBLE_RANDOM_ADDRESS, BluetoothDevice.ADDRESS_TYPE_RANDOM);

        for (int i = 0; i < 10; i++) {
            BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class);
@@ -101,7 +99,8 @@ public class GattClientTest {
        advertiseWithBumble();

        BluetoothDevice device =
            mAdapter.getRemoteLeDevice(BUMBLE_RPA, BluetoothDevice.ADDRESS_TYPE_RANDOM);
                mAdapter.getRemoteLeDevice(
                        Utils.BUMBLE_RANDOM_ADDRESS, BluetoothDevice.ADDRESS_TYPE_RANDOM);

        for (int i = 0; i < 10; i++) {
            BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class);
@@ -123,7 +122,8 @@ public class GattClientTest {
        advertiseWithBumble();

        BluetoothDevice device =
                mAdapter.getRemoteLeDevice(BUMBLE_RPA, BluetoothDevice.ADDRESS_TYPE_RANDOM);
                mAdapter.getRemoteLeDevice(
                        Utils.BUMBLE_RANDOM_ADDRESS, BluetoothDevice.ADDRESS_TYPE_RANDOM);
        BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class);
        InOrder inOrder = inOrder(gattCallback);

+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import android.util.Log;

import androidx.core.util.Pair;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.android.compatibility.common.util.AdoptShellPermissionsRule;

+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import android.os.ParcelUuid;
import android.util.Log;

import androidx.test.core.app.ApplicationProvider;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.android.compatibility.common.util.AdoptShellPermissionsRule;

Loading