Only deliver latest WIFI_DISPLAY_STATUS_CHANGED.

We've heard reports of apps getting confused about hearing thrashing
WIFI_DISPLAY_STATUS_CHANGED broadcasts when they're thawed.  To
mitigate this, only deliver the latest instance of the broadcast,
replacing any stale broadcasts.

Bug: 273923757
Test: manual
Change-Id: Ie8e4a7213f7b4838b33fdc6cf4ccca9520ad49f9
This commit is contained in:
Jeff Sharkey
2023-03-29 13:56:09 -06:00
parent 3f88c15585
commit d0c73d6373

View File

@@ -16,6 +16,7 @@
package com.android.server.display;
import android.app.BroadcastOptions;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -421,6 +422,7 @@ final class WifiDisplayAdapter extends DisplayAdapter {
// Runs on the handler.
private void handleSendStatusChangeBroadcast() {
final Intent intent;
final BroadcastOptions options;
synchronized (getSyncRoot()) {
if (!mPendingStatusChangeBroadcast) {
return;
@@ -431,10 +433,13 @@ final class WifiDisplayAdapter extends DisplayAdapter {
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
intent.putExtra(DisplayManager.EXTRA_WIFI_DISPLAY_STATUS,
getWifiDisplayStatusLocked());
options = BroadcastOptions.makeBasic();
options.setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT);
}
// Send protected broadcast about wifi display status to registered receivers.
getContext().sendBroadcastAsUser(intent, UserHandle.ALL);
getContext().sendBroadcastAsUser(intent, UserHandle.ALL, null, options.toBundle());
}
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {