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

Commit 39d1d7fd authored by Charlie Boutier's avatar Charlie Boutier Committed by Automerger Merge Worker
Browse files

Merge changes I6aab6a4d,I7c0e928c,I3ac8a0e2,I62b56ec2,If0643b68, ... am:...

Merge changes I6aab6a4d,I7c0e928c,I3ac8a0e2,I62b56ec2,If0643b68, ... am: e54bf6cb am: 88182e8d am: 8d7765e6 am: a47a2fbc am: 8f6f59f9

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



Change-Id: I59b841b9cea877409e0a57f920bf7197a70aa269
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 6d7da602 8f6f59f9
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
import time
import sys

from mmi2grpc._helpers import assert_description
from mmi2grpc._helpers import match_description
from mmi2grpc._proxy import ProfileProxy

from pandora_experimental.host_grpc import Host
from pandora_experimental.host_pb2 import Connection
from pandora_experimental.host_pb2 import Connection, ConnectabilityMode, AddressType
from pandora_experimental.l2cap_grpc import L2CAP

from typing import Optional
import sys


class L2CAPProxy(ProfileProxy):
@@ -88,7 +90,10 @@ class L2CAPProxy(ProfileProxy):
        """
        Place the IUT into LE connectable mode.
        """
        self.host.SetLEConnectable()
        self.host.StartAdvertising(
            connectability_mode=ConnectabilityMode.CONECTABILITY_CONNECTABLE,
            own_address_type=AddressType.PUBLIC,
        )
        # not strictly necessary, but can save time on waiting connection
        tests_to_open_bluetooth_server_socket = [
            "L2CAP/LE/CFC/BV-03-C",
+5 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ from mmi2grpc._streaming import StreamWrapper

from pandora_experimental.security_grpc import Security
from pandora_experimental.host_grpc import Host
from pandora_experimental.host_pb2 import ConnectabilityMode, AddressType


def debug(*args, **kwargs):
@@ -89,7 +90,10 @@ class SMProxy(ProfileProxy):
        """
        Action: Place the IUT in connectable mode
        """
        self.host.SetLEConnectable()
        self.host.StartAdvertising(
            connectability_mode=ConnectabilityMode.CONECTABILITY_CONNECTABLE,
            own_address_type=AddressType.PUBLIC,
        )
        return "OK"

    @assert_description
+136 −4
Original line number Diff line number Diff line
@@ -41,12 +41,23 @@ service Host {
  rpc GetLEConnection(GetLEConnectionRequest) returns (GetLEConnectionResponse);
  // Disconnect ongoing LE connection.
  rpc DisconnectLE(DisconnectLERequest) returns (google.protobuf.Empty);
  // Start LE advertisement
  rpc SetLEConnectable(google.protobuf.Empty) returns (google.protobuf.Empty);
  // Create and enable an advertising set using legacy or extended advertising,
  // except periodic advertising.
  rpc StartAdvertising(StartAdvertisingRequest) returns (StartAdvertisingResponse);
  // Create and enable a periodic advertising set.
  rpc StartPeriodicAdvertising(StartPeriodicAdvertisingRequest) returns (StartPeriodicAdvertisingResponse);
  // Remove an advertising set.
  rpc StopAdvertising(StopAdvertisingRequest) returns (StopAdvertisingResponse);
  // Run BR/EDR inquiry and returns each device found
  rpc RunInquiry(RunInquiryRequest) returns (stream RunInquiryResponse);
  // Run LE discovery (scanning) and return each device found
  rpc RunDiscovery(RunDiscoveryRequest) returns (stream RunDiscoveryResponse);
  // Set BREDR connectability mode
  rpc SetConnectabilityMode(SetConnectabilityModeRequest) returns (SetConnectabilityModeResponse);
  // Set BREDR discoverable mode
  rpc SetDiscoverabilityMode(SetDiscoverabilityModeRequest) returns (SetDiscoverabilityModeResponse);
  // Get device name from connection
  rpc GetDeviceName(GetDeviceNameRequest) returns (GetDeviceNameResponse);
}

// Response of the `ReadLocalAddress` method.
@@ -58,15 +69,33 @@ message ReadLocalAddressResponse {
// A Token representing an ACL connection.
// It's acquired via a Connect on the Host service.
message Connection {
  // Opaque value filled by the gRPC server, must not
  // be modified nor crafted.
  // Opaque value filled by the gRPC server, must not be modified nor crafted
  // Android specific: it's secretly an encoded InternelConnectionRef created using newConnection
  bytes cookie = 1;
}

// Internal representation of a Connection - not exposed to clients, included here
// just for code-generation convenience
message InternalConnectionRef {
  bytes address = 1;
  Transport transport = 2;
}

// WARNING: Leaving this enum empty will default to BREDR, so make sure that this is a
// valid default whenever used, and that we always populate this value.
enum Transport {
  TRANSPORT_BREDR = 0;
  TRANSPORT_LE = 1;
}

// Request of the `Connect` method.
message ConnectRequest {
  // Peer Bluetooth Device Address as array of 6 bytes.
  bytes address = 1;
  // Whether we want to initiate pairing as part of the connection
  bool skip_pairing = 2;
  // Whether confirmation prompts should be auto-accepted or handled manually
  bool manually_confirm = 3;
}

// Response of the `Connect` method.
@@ -146,6 +175,74 @@ message DisconnectLERequest {
  Connection connection = 1;
}

message AdvertisingHandle {
  bytes cookie = 1;
}

enum AddressType {
  PUBLIC = 0x00;
  RANDOM = 0x01;
}

// Advertising Data including one or multiple AD types.
// Since the Flags AD type is mandatory, it must be automatically set by the
// IUT.
// include_<AD type> fields are used for AD type which are generally not
// exposed and that must be set by the IUT when specified.
// See Core Supplement, Part A, Data Types for details
message AdvertisingData {
  repeated string service_uuids = 1;
  bool include_local_name = 2;
  bytes manufacturer_specific_data = 3;
  bool include_tx_power_level = 4;
  bool include_peripheral_connection_interval_range = 5;
  repeated string service_solicitation = 6;
  map<string, bytes> service_data = 7;
  // Must be on 16 bits.
  uint32 appearance = 8;
  repeated bytes public_target_addresses = 9;
  repeated bytes random_target_addresses = 10;
  bool include_advertising_interval = 11;
  bool include_le_address = 12;
  bool include_le_role = 13;
  string uri = 14;
}

message StartAdvertisingRequest {
  bool legacy = 1;
  DiscoverabilityMode discovery_mode = 2;
  ConnectabilityMode connectability_mode = 3;
  AddressType own_address_type = 4;
  // If none, undirected.
  bytes peer_address = 5;
  AdvertisingData advertising_data = 6;
  // If none, not scannable.
  AdvertisingData scan_response_data = 7;
}

message StartAdvertisingResponse {
  AdvertisingHandle handle = 1;
}

message StartPeriodicAdvertisingRequest {
  AddressType own_address_type = 1;
  // If none, undirected.
  bytes peer_address = 2;
  uint32 interval_min = 3;
  uint32 interval_max = 4;
  AdvertisingData advertising_data = 5;
}

message StartPeriodicAdvertisingResponse {
  AdvertisingHandle handle = 1;
}

message StopAdvertisingRequest {
  AdvertisingHandle handle = 1;
}

message StopAdvertisingResponse {}

message RunInquiryRequest {
}

@@ -165,3 +262,38 @@ message Device {
  string name = 1;
  bytes address = 2;
}

// 5.3 Vol 3C 4.1 Discoverability Modes
enum DiscoverabilityMode {
  DISCOVERABILITY_UNSPECIFIED = 0;
  DISCOVERABILITY_NONE = 1;
  DISCOVERABILITY_LIMITED = 2;
  DISCOVERABILITY_GENERAL = 3;
}

// 5.3 Vol 3C 4.2 Connectability Modes
enum ConnectabilityMode {
  CONNECTABILITY_UNSPECIFIED = 0;
  CONNECTABILITY_NOT_CONNECTABLE = 1;
  CONECTABILITY_CONNECTABLE = 2;
}

message SetConnectabilityModeRequest {
  ConnectabilityMode connectability = 1;
}

message SetConnectabilityModeResponse {}

message SetDiscoverabilityModeRequest {
  DiscoverabilityMode discoverability = 1;
}

message SetDiscoverabilityModeResponse {}

message GetDeviceNameRequest {
  Connection connection = 1;
}

message GetDeviceNameResponse {
  string name = 1;
}
+8 −8
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ class Gatt(private val context: Context) : GATTImplBase() {
    grpcUnary<ExchangeMTUResponse>(mScope, responseObserver) {
      val mtu = request.mtu
      Log.i(TAG, "exchangeMTU MTU=$mtu")
      if (!GattInstance.get(request.connection.cookie).mGatt.requestMtu(mtu)) {
      if (!GattInstance.get(request.connection.address).mGatt.requestMtu(mtu)) {
        Log.e(TAG, "Error on requesting MTU $mtu")
        throw Status.UNKNOWN.asException()
      }
@@ -88,7 +88,7 @@ class Gatt(private val context: Context) : GATTImplBase() {
  ) {
    grpcUnary<WriteResponse>(mScope, responseObserver) {
      Log.i(TAG, "writeAttFromHandle handle=${request.handle}")
      val gattInstance = GattInstance.get(request.connection.cookie)
      val gattInstance = GattInstance.get(request.connection.address)
      var characteristic: BluetoothGattCharacteristic? =
          getCharacteristicWithHandle(request.handle, gattInstance)
      if (characteristic == null) {
@@ -113,7 +113,7 @@ class Gatt(private val context: Context) : GATTImplBase() {
      responseObserver: StreamObserver<DiscoverServicesResponse>
  ) {
    grpcUnary<DiscoverServicesResponse>(mScope, responseObserver) {
      val gattInstance = GattInstance.get(request.connection.cookie)
      val gattInstance = GattInstance.get(request.connection.address)
      Log.i(TAG, "discoverServiceByUuid uuid=${request.uuid}")
      // In some cases, GATT starts a discovery immediately after being connected, so
      // we need to wait until the service discovery is finished to be able to discover again.
@@ -133,7 +133,7 @@ class Gatt(private val context: Context) : GATTImplBase() {
  ) {
    grpcUnary<DiscoverServicesResponse>(mScope, responseObserver) {
      Log.i(TAG, "discoverServices")
      val gattInstance = GattInstance.get(request.connection.cookie)
      val gattInstance = GattInstance.get(request.connection.address)
      check(gattInstance.mGatt.discoverServices())
      gattInstance.waitForDiscoveryEnd()
      DiscoverServicesResponse.newBuilder()
@@ -168,7 +168,7 @@ class Gatt(private val context: Context) : GATTImplBase() {
  ) {
    grpcUnary<ClearCacheResponse>(mScope, responseObserver) {
      Log.i(TAG, "clearCache")
      val gattInstance = GattInstance.get(request.connection.cookie)
      val gattInstance = GattInstance.get(request.connection.address)
      check(gattInstance.mGatt.refresh())
      ClearCacheResponse.newBuilder().build()
    }
@@ -180,7 +180,7 @@ class Gatt(private val context: Context) : GATTImplBase() {
  ) {
    grpcUnary<ReadCharacteristicResponse>(mScope, responseObserver) {
      Log.i(TAG, "readCharacteristicFromHandle handle=${request.handle}")
      val gattInstance = GattInstance.get(request.connection.cookie)
      val gattInstance = GattInstance.get(request.connection.address)
      val characteristic: BluetoothGattCharacteristic? =
          getCharacteristicWithHandle(request.handle, gattInstance)
      checkNotNull(characteristic) { "Characteristic handle ${request.handle} not found." }
@@ -198,7 +198,7 @@ class Gatt(private val context: Context) : GATTImplBase() {
  ) {
    grpcUnary<ReadCharacteristicsFromUuidResponse>(mScope, responseObserver) {
      Log.i(TAG, "readCharacteristicsFromUuid uuid=${request.uuid}")
      val gattInstance = GattInstance.get(request.connection.cookie)
      val gattInstance = GattInstance.get(request.connection.address)
      tryDiscoverServices(gattInstance)
      val readValues =
          gattInstance.readCharacteristicUuidBlocking(
@@ -215,7 +215,7 @@ class Gatt(private val context: Context) : GATTImplBase() {
  ) {
    grpcUnary<ReadCharacteristicDescriptorResponse>(mScope, responseObserver) {
      Log.i(TAG, "readCharacteristicDescriptorFromHandle handle=${request.handle}")
      val gattInstance = GattInstance.get(request.connection.cookie)
      val gattInstance = GattInstance.get(request.connection.address)
      val descriptor: BluetoothGattDescriptor? =
          getDescriptorWithHandle(request.handle, gattInstance)
      checkNotNull(descriptor) { "Descriptor handle ${request.handle} not found." }
+216 −79

File changed.

Preview size limit exceeded, changes collapsed.

Loading