Fix issue #593153: Broadcast time out when sending...

...ordered broadcast for ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE

Turns out this was because the broadcast receiver for ContextImpl was
not correctly being created, so when it received an ordered broadcast
it would not tell the activity manager when it was done.

This is now fixed, along with a ton of superficial changes to debug
output to help track this down and a little cleanup of dealing with
error cases in dispatching broadcasts.  Also a fix for a NPE when
dumping the broadcast state.

Finally, a little fiddling with package manager to get rid of a lot
of the noise when removing and re-adding packages on the SD card.

Change-Id: I961c14836dc613d3ea8122b6e910ef866e7fcb25
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 78f7b33..7babb34 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -179,6 +179,8 @@
     static final int SCAN_NEW_INSTALL = 1<<4;
     static final int SCAN_NO_PATHS = 1<<5;
 
+    static final int REMOVE_CHATTY = 1<<16;
+    
     static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName(
             "com.android.defcontainer",
             "com.android.defcontainer.DefaultContainerService");
@@ -6068,7 +6070,8 @@
         }
         
         synchronized (mInstallLock) {
-            res = deletePackageLI(packageName, deleteCodeAndResources, flags, info);
+            res = deletePackageLI(packageName, deleteCodeAndResources,
+                    flags | REMOVE_CHATTY, info);
         }
 
         if(res && sendBroadCast) {
@@ -6134,7 +6137,7 @@
         if (outInfo != null) {
             outInfo.removedPackage = packageName;
         }
-        removePackageLI(p, true);
+        removePackageLI(p, (flags&REMOVE_CHATTY) != 0);
         // Retrieve object to delete permissions for shared user later on
         PackageSetting deletedPs;
         synchronized (mPackages) {
@@ -9589,8 +9592,7 @@
                    continue;
                }
                // Parse package
-               int parseFlags = PackageParser.PARSE_CHATTY |
-                       PackageParser.PARSE_ON_SDCARD | mDefParseFlags;
+               int parseFlags = PackageParser.PARSE_ON_SDCARD | mDefParseFlags;
                doGc = true;
                synchronized (mInstallLock) {
                    final PackageParser.Package pkg =  scanPackageLI(new File(codePath),