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

Commit 815a4338 authored by Martin Brabham's avatar Martin Brabham
Browse files

Topshim API: Add SecurityTest framework.

Add RemoveBond API to Topshim proto, AdapterClient and Facade Service.

Bug: 234756905
Test: system/gd/cert/run --clean --topshim SecurityTest
Tag: #stability
Change-Id: Ibfbb4f4da1e3dd5374f87f2c1cc1ba46b6e604c0
parent 50bea9a1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ service AdapterService {
  rpc LeRand(google.protobuf.Empty) returns (google.protobuf.Empty) {}
  rpc SetEventFilterConnectionSetupAllDevices(google.protobuf.Empty) returns (google.protobuf.Empty) {}
  rpc AllowWakeByHid(google.protobuf.Empty) returns (google.protobuf.Empty) {}
  rpc RemoveBond(RemoveBondRequest) returns (google.protobuf.Empty) {}
  rpc RestoreFilterAcceptList(google.protobuf.Empty) returns (google.protobuf.Empty) {}
  rpc SetDefaultEventMask(google.protobuf.Empty) returns (google.protobuf.Empty) {}
  rpc SetEventFilterInquiryResultAllDevices(google.protobuf.Empty) returns (google.protobuf.Empty) {}
@@ -144,3 +145,7 @@ message A2dpSourceSetActiveDeviceRequest {
}

message A2dpSourceSetActiveDevicetResponse {}

message RemoveBondRequest {
  string address = 1;
}
+3 −0
Original line number Diff line number Diff line
@@ -111,6 +111,9 @@ class AdapterClient():
    async def allow_wake_by_hid(self):
        await self.__adapter_stub.AllowWakeByHid(empty_proto.Empty())

    async def remove_bond(self, address):
        await self.__adapter_stub.RemoveBond(facade_pb2.RemoveBondRequest(address=address))


class A2dpAutomationHelper():
    """Invoke gRPC on topshim for A2DP testing"""
+39 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
#
#   Copyright 2022 - 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.

import asyncio

from blueberry.tests.gd.cert.truth import assertThat
from blueberry.tests.topshim.lib.topshim_base_test import TopshimBaseTest
from blueberry.tests.topshim.lib.adapter_client import AdapterClient

from mobly import test_runner


class SecurityTest(TopshimBaseTest):

    DEFAULT_ADDRESS = "01:02:03:04:05:06"

    async def __test_remove_bond(self, address):
        await self.dut_adapter.remove_bond(address)
        return await self.dut_adapter.le_rand()

    def test_remove_bond_with_no_bonded_devices(self):
        asyncio.get_event_loop().run_until_complete(self.__test_remove_bond(self.DEFAULT_ADDRESS))


if __name__ == "__main__":
    test_runner.main()
+2 −1
Original line number Diff line number Diff line
@@ -16,11 +16,12 @@

from blueberry.tests.topshim.adapter.adapter_test import AdapterTest
from blueberry.tests.topshim.power.suspend_test import SuspendTest
from blueberry.tests.topshim.security.security_test import SecurityTest

from mobly import suite_runner
import argparse

ALL_TESTS = [AdapterTest, SuspendTest]
ALL_TESTS = [AdapterTest, SecurityTest, SuspendTest]


def main():
+10 −2
Original line number Diff line number Diff line
//! Adapter service facade

use bt_topshim::btif;
use bt_topshim::btif::{BaseCallbacks, BaseCallbacksDispatcher, BluetoothInterface};
use bt_topshim::btif::{BaseCallbacks, BaseCallbacksDispatcher, BluetoothInterface, RawAddress};

use bt_topshim_facade_protobuf::empty::Empty;
use bt_topshim_facade_protobuf::facade::{
    EventType, FetchEventsRequest, FetchEventsResponse, SetDiscoveryModeRequest,
    EventType, FetchEventsRequest, FetchEventsResponse, RemoveBondRequest, SetDiscoveryModeRequest,
    SetDiscoveryModeResponse, ToggleStackRequest, ToggleStackResponse,
};
use bt_topshim_facade_protobuf::facade_grpc::{create_adapter_service, AdapterService};
@@ -173,6 +173,14 @@ impl AdapterService for AdapterServiceImpl {
        })
    }

    fn remove_bond(&mut self, ctx: RpcContext<'_>, req: RemoveBondRequest, sink: UnarySink<Empty>) {
        let raw_address = RawAddress::from_string(req.address).unwrap();
        self.btif_intf.lock().unwrap().remove_bond(&raw_address);
        ctx.spawn(async move {
            sink.success(Empty::default()).await.unwrap();
        })
    }

    fn restore_filter_accept_list(
        &mut self,
        ctx: RpcContext<'_>,