AudioService: fix removeDeviceAsNonDefaultForStrategy regression

Calling AudioManager.removeDeviceAsNonDefaultForStrategy with
an invalid strategy is expected to fail (as documented).
Fix by returning a failure when the useCase (aka strategy) and
role is not found in the map of roles for the audio devices.

Bug: 280554476
Test: atest android.media.audio.cts.NonDefaultDeviceForStrategyTest#testInvalidStrategy
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:8777944d3010a3be3d69405300b4a4e0b9f961a5)
Merged-In: I29f9d9a5d9e7fb2c0865dfa0c86e7531bb148b41
Change-Id: I29f9d9a5d9e7fb2c0865dfa0c86e7531bb148b41
This commit is contained in:
Jean-Michel Trivi
2023-05-04 15:48:07 -07:00
committed by Cherrypicker Worker
parent aa93568740
commit 183c8a3a27

View File

@@ -1031,7 +1031,8 @@ public class AudioDeviceInventory {
synchronized (rolesMap) {
Pair<Integer, Integer> key = new Pair<>(useCase, role);
if (!rolesMap.containsKey(key)) {
return AudioSystem.SUCCESS;
// trying to remove a role for a device that wasn't set
return AudioSystem.BAD_VALUE;
}
List<AudioDeviceAttributes> roleDevices = rolesMap.get(key);
List<AudioDeviceAttributes> appliedDevices = new ArrayList<>();