Implement API to have new broadcasts replace existing broadcasts.
Use this in various places where it should serve no purpose to deliver both broadcasts. This is intended to reduce somewhat the flurry of broadcasts that we churn through during boot.
This commit is contained in:
parent
f59a2ae61e
commit
a417ff8201
1 changed files with 11 additions and 14 deletions
|
|
@ -98,7 +98,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||
private List mFeatureUsers;
|
||||
|
||||
private boolean mSystemReady;
|
||||
private ArrayList<Intent> mDeferredBroadcasts;
|
||||
private Intent mInitialBroadcast;
|
||||
|
||||
private static class NetworkAttributes {
|
||||
/**
|
||||
|
|
@ -786,6 +786,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||
}
|
||||
|
||||
Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
|
||||
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
|
||||
if (info.isFailover()) {
|
||||
intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
|
||||
|
|
@ -885,6 +886,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||
|
||||
private void sendConnectedBroadcast(NetworkInfo info) {
|
||||
Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
|
||||
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
|
||||
if (info.isFailover()) {
|
||||
intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
|
||||
|
|
@ -922,6 +924,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||
}
|
||||
|
||||
Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
|
||||
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
|
||||
if (getActiveNetworkInfo() == null) {
|
||||
intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
|
||||
|
|
@ -941,26 +944,20 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
|||
|
||||
private void sendStickyBroadcast(Intent intent) {
|
||||
synchronized(this) {
|
||||
if (mSystemReady) {
|
||||
mContext.sendStickyBroadcast(intent);
|
||||
} else {
|
||||
if (mDeferredBroadcasts == null) {
|
||||
mDeferredBroadcasts = new ArrayList<Intent>();
|
||||
}
|
||||
mDeferredBroadcasts.add(intent);
|
||||
if (!mSystemReady) {
|
||||
mInitialBroadcast = new Intent(intent);
|
||||
}
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
||||
mContext.sendStickyBroadcast(intent);
|
||||
}
|
||||
}
|
||||
|
||||
void systemReady() {
|
||||
synchronized(this) {
|
||||
mSystemReady = true;
|
||||
if (mDeferredBroadcasts != null) {
|
||||
int count = mDeferredBroadcasts.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
mContext.sendStickyBroadcast(mDeferredBroadcasts.get(i));
|
||||
}
|
||||
mDeferredBroadcasts = null;
|
||||
if (mInitialBroadcast != null) {
|
||||
mContext.sendStickyBroadcast(mInitialBroadcast);
|
||||
mInitialBroadcast = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue