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

Commit 381acff5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I8f73b215,Ifd0ca9e3,Id218fccf into main

* changes:
  Hap: various cleanup in avatar
  Hap: prevent setactive on unknow preset
  Hap: set available on unknow preset no crash
parents bafbd718 4aab5e40
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -156,8 +156,7 @@ class Hap(val context: Context) : HAPImplBase(), Closeable {
    ) {
        grpcUnary<GetPresetRecordResponse>(scope, responseObserver) {
            val device = request.connection.toBluetoothDevice(bluetoothAdapter)

            Log.i(TAG, "getPresetRecord device=${device.address} index=${request.index}")
            Log.i(TAG, "getPresetRecord($device, ${request.index})")

            val presetInfo: BluetoothHapPresetInfo? =
                bluetoothHapClient.getPresetInfo(device, request.index)
@@ -211,8 +210,7 @@ class Hap(val context: Context) : HAPImplBase(), Closeable {
    ) {
        grpcUnary<Empty>(scope, responseObserver) {
            val device = request.connection.toBluetoothDevice(bluetoothAdapter)

            Log.i(TAG, "writePresetName index=${request.index} name=${request.name}")
            Log.i(TAG, "writePresetName($device, ${request.index}, ${request.name})")

            bluetoothHapClient.setPresetName(device, request.index, request.name)

@@ -226,8 +224,7 @@ class Hap(val context: Context) : HAPImplBase(), Closeable {
    ) {
        grpcUnary<Empty>(scope, responseObserver) {
            val device = request.connection.toBluetoothDevice(bluetoothAdapter)

            Log.i(TAG, "SetActivePreset")
            Log.i(TAG, "SetActivePreset($device, ${request.index})")

            bluetoothHapClient.selectPreset(device, request.index)

@@ -241,8 +238,7 @@ class Hap(val context: Context) : HAPImplBase(), Closeable {
    ) {
        grpcUnary<Empty>(scope, responseObserver) {
            val device = request.connection.toBluetoothDevice(bluetoothAdapter)

            Log.i(TAG, "setNextPreset")
            Log.i(TAG, "setNextPreset($device)")

            bluetoothHapClient.switchToNextPreset(device)

@@ -256,8 +252,7 @@ class Hap(val context: Context) : HAPImplBase(), Closeable {
    ) {
        grpcUnary<Empty>(scope, responseObserver) {
            val device = request.connection.toBluetoothDevice(bluetoothAdapter)

            Log.i(TAG, "setPreviousPreset")
            Log.i(TAG, "setPreviousPreset($device)")

            bluetoothHapClient.switchToPreviousPreset(device)

+5 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ from bumble.gatt import GATT_HEARING_ACCESS_SERVICE, GATT_AUDIO_STREAM_CONTROL_S
from bumble.profiles import hap
from bumble.profiles.hap import DynamicPresets, HearingAccessService, HearingAidFeatures, HearingAidType, IndependentPresets, PresetRecord, PresetSynchronizationSupport, WritablePresetsSupport

from pandora_experimental.os_grpc_aio import Os as OsAio
from pandora_experimental.gatt_grpc_aio import GATT
from pandora_experimental.hap_grpc_aio import HAP
from pandora_experimental.hap_pb2 import PresetRecord as grpcPresetRecord  # type: ignore
@@ -84,6 +85,8 @@ class HapTest(base_test.BaseTestClass):
    @asynchronous
    async def setup_test(self) -> None:
        await asyncio.gather(self.dut.reset(), self.ref_left.reset())
        self.logcat = OsAio(channel=self.dut.aio.channel)
        await self.logcat.Log("setup test")
        self.hap_grpc = HAP(channel=self.dut.aio.channel)
        device_features = HearingAidFeatures(HearingAidType.MONAURAL_HEARING_AID,
                                             PresetSynchronizationSupport.PRESET_SYNCHRONIZATION_IS_NOT_SUPPORTED,
@@ -162,6 +165,7 @@ class HapTest(base_test.BaseTestClass):

    @asynchronous
    async def test_get_features(self) -> None:
        await self.logcat.Log("test_get_features")
        dut_connection_to_ref = await self.setupHapConnection()

        features = hap.HearingAidFeatures_from_bytes(
@@ -170,6 +174,7 @@ class HapTest(base_test.BaseTestClass):

    @asynchronous
    async def test_get_preset(self) -> None:
        await self.logcat.Log("test_get_preset")
        dut_connection_to_ref = await self.setupHapConnection()

        await self.assertIdentiqPresetInDutAndRef(dut_connection_to_ref)
+18 −5
Original line number Diff line number Diff line
@@ -1394,6 +1394,12 @@ private:
        break;
      }

      if (!device.has_presets.contains(nt.index)) {
        log::error("Unknown preset. Notification is discarded: {}", nt);
        device.has_journal_.Append(HasJournalRecord(nt));
        device.ctp_notifications_.pop_front();
        continue;
      }
      auto preset = device.has_presets.extract(nt.index).value();
      auto new_props = preset.GetProperties();

@@ -1560,7 +1566,15 @@ private:

    /* Get the active preset value */
    auto* pp = value;
    STREAM_TO_UINT8(device->currently_active_preset, pp);
    uint8_t active_preset_index;
    STREAM_TO_UINT8(active_preset_index, pp);
    if (active_preset_index != 0 && device->isGattServiceValid() &&
        !device->has_presets.contains(active_preset_index)) {
      log::error("Unknown preset {}. Active preset change is discarded", active_preset_index);
      device->has_journal_.Append(HasJournalRecord(active_preset_index, false));
      return;
    }
    device->currently_active_preset = active_preset_index;

    if (device->isGattServiceValid()) {
      btif_storage_set_leaudio_has_active_preset(device->addr, device->currently_active_preset);
@@ -1573,7 +1587,9 @@ private:
    MarkDeviceValidIfInInitialDiscovery(*device);

    if (device->isGattServiceValid()) {
      if (!pending_group_operation_timeouts_.empty()) {
      if (pending_group_operation_timeouts_.empty()) {
        callbacks_->OnActivePresetSelected(device->addr, device->currently_active_preset);
      } else {
        for (auto it = pending_group_operation_timeouts_.rbegin();
             it != pending_group_operation_timeouts_.rend(); ++it) {
          auto& group_op_coordinator = it->second;
@@ -1609,9 +1625,6 @@ private:
            break;
          }
        }

      } else {
        callbacks_->OnActivePresetSelected(device->addr, device->currently_active_preset);
      }
    }
  }