Prevent ANR while receiving volume broadcasts to update slices
Use ConcurrentHashMap for registering Uri to the audio stream, and remove synchronized blocks from the receiver. Fix: 302234235 Fix: 301777614 Test: manual, robotest Change-Id: I5cca209baf9756aebb8ff44b7e8e9671d2c7aaad
This commit is contained in:
@@ -24,7 +24,6 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.ArrayMap;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
@@ -32,6 +31,7 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
import com.android.settingslib.SliceBroadcastRelay;
|
import com.android.settingslib.SliceBroadcastRelay;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This helper is to handle the broadcasts of volume slices
|
* This helper is to handle the broadcasts of volume slices
|
||||||
@@ -41,7 +41,7 @@ public class VolumeSliceHelper {
|
|||||||
private static final String TAG = "VolumeSliceHelper";
|
private static final String TAG = "VolumeSliceHelper";
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static Map<Uri, Integer> sRegisteredUri = new ArrayMap<>();
|
static Map<Uri, Integer> sRegisteredUri = new ConcurrentHashMap<>();
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static IntentFilter sIntentFilter;
|
static IntentFilter sIntentFilter;
|
||||||
|
|
||||||
@@ -133,23 +133,19 @@ public class VolumeSliceHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void handleStreamChanged(Context context, int inputType) {
|
private static void handleStreamChanged(Context context, int inputType) {
|
||||||
synchronized (sRegisteredUri) {
|
for (Map.Entry<Uri, Integer> entry : sRegisteredUri.entrySet()) {
|
||||||
for (Map.Entry<Uri, Integer> entry : sRegisteredUri.entrySet()) {
|
if (entry.getValue() == inputType) {
|
||||||
if (entry.getValue() == inputType) {
|
context.getContentResolver().notifyChange(entry.getKey(), null /* observer */);
|
||||||
context.getContentResolver().notifyChange(entry.getKey(), null /* observer */);
|
if (inputType != AudioManager.STREAM_RING) { // Two URIs are mapped to ring
|
||||||
if (inputType != AudioManager.STREAM_RING) { // Two URIs are mapped to ring
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void notifyAllStreamsChanged(Context context) {
|
private static void notifyAllStreamsChanged(Context context) {
|
||||||
synchronized (sRegisteredUri) {
|
sRegisteredUri.keySet().forEach(uri -> {
|
||||||
sRegisteredUri.forEach((uri, audioStream) -> {
|
context.getContentResolver().notifyChange(uri, null /* observer */);
|
||||||
context.getContentResolver().notifyChange(uri, null /* observer */);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user