AudioService: fix capture policy restoration
Fix ConcurrentModificationException thrown during capture policy
restoration. The code was retrieving the list of mappings from
uid to capture policies (ALLOW_CAPTURE_*) to send them to
AudioSystem. In case of failure, the capture policy was reset
and thus modified the mapping list.
Because the iteration happened on the same list it was trying to
modify, an exception was thrown.
The fix consists in iterating over a copy of the list of mappings
instead of the actual list, a private field in the PlaybackMonitor
class.
Bug: 192496758
Test: atest AudioPlaybackCaptureTest, AudioPlaybackConfigurationTest
Change-Id: I80afc28e5ddd8d389803306a7fa6da8f6fec3987
diff --git a/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java b/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java
index af9a14e..a13b2eb 100644
--- a/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java
+++ b/services/core/java/com/android/server/audio/PlaybackActivityMonitor.java
@@ -380,10 +380,12 @@
}
/**
- * Return all cached capture policies.
+ * Return a copy of all cached capture policies.
*/
public HashMap<Integer, Integer> getAllAllowedCapturePolicies() {
- return mAllowedCapturePolicies;
+ synchronized (mAllowedCapturePolicies) {
+ return (HashMap<Integer, Integer>) mAllowedCapturePolicies.clone();
+ }
}
private void updateAllowedCapturePolicy(AudioPlaybackConfiguration apc, int capturePolicy) {