diff options
| author | Dianne Hackborn <hackbod@google.com> | 2009-12-08 19:45:14 -0800 |
|---|---|---|
| committer | Dianne Hackborn <hackbod@google.com> | 2009-12-14 15:03:35 -0800 |
| commit | 1c633fc89bae9bf0af6fe643ac7ad2e744f27bed (patch) | |
| tree | ba72742fc17755ec69996ad3dd6a6f82f445a2ab /services/java/com/android/server/ConnectivityService.java | |
| parent | 19553241513bd2ee2610026ebbce8c45c7ae0dbc (diff) | |
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.
Diffstat (limited to 'services/java/com/android/server/ConnectivityService.java')
| -rw-r--r-- | services/java/com/android/server/ConnectivityService.java | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 27b631e4929b..77884a4444c0 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -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; } } } |
