am 3a3fd2ba: Merge change Iaf1f0918 into eclair-mr2

Merge commit '3a3fd2ba1ffc6171725375396cc59711a34bb39e' into eclair-mr2-plus-aosp

* commit '3a3fd2ba1ffc6171725375396cc59711a34bb39e':
  Implement API to have new broadcasts replace existing broadcasts.
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index 27b631e..77884a4 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -98,7 +98,7 @@
     private List mFeatureUsers;
 
     private boolean mSystemReady;
-    private ArrayList<Intent> mDeferredBroadcasts;
+    private Intent mInitialBroadcast;
 
     private static class NetworkAttributes {
         /**
@@ -786,6 +786,7 @@
         }
 
         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 @@
 
     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 @@
         }
 
         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 @@
 
     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;
             }
         }
     }