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

Commit 9202dd9f authored by Jeremy Wu's avatar Jeremy Wu
Browse files

ADI: remove opposite role

In `EngineBase.cpp`, when a role is set for a device, its counterpart
is removed.

However, this is not reflected in the `AudioDeviceInventory` cache.

In this CL, we anticipate that to occur and do the symmetric operation.

Bug: 432772716
Test: m # and verify the roles are updated from the logs
Flag: EXEMPT bug fix
Change-Id: Iad90a1bfe6e4c6214b6e07a896b32ab0edfe3e8d
parent cd2120c3
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -93,6 +93,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
@@ -1859,6 +1860,21 @@ public class AudioDeviceInventory {
                status = addOp.deviceRoleAction(useCase, role, devices);
                if (status == AudioSystem.SUCCESS) {
                    rolesMap.put(key, new ArrayList(devices));
                    // Mirrors the behavior in EngineBase::setDevicesRoleForT() to ensure a
                    // preferred device is not also disabled, and vice-versa.
                    if (role != AudioSystem.DEVICE_ROLE_NONE) {
                        int roleToRemove = role == AudioSystem.DEVICE_ROLE_PREFERRED
                                ? AudioSystem.DEVICE_ROLE_DISABLED
                                : AudioSystem.DEVICE_ROLE_PREFERRED;
                        Pair<Integer, Integer> oppositeKey = new Pair<>(useCase, roleToRemove);
                        List<AudioDeviceAttributes> oppositeDevs = rolesMap.get(oppositeKey);
                        if (oppositeDevs != null) {
                            List<AudioDeviceAttributes> filteredDevs = oppositeDevs.stream()
                                    .filter(e -> !devices.contains(e))
                                    .collect(Collectors.toList());
                            rolesMap.put(oppositeKey, filteredDevs);
                        }
                    }
                }
            }
            return status;