Ensure recipient can be launched before attempting broadcast delivery

User removal or eviction inherently races with broadcast delivery.  This
patch introduces a latest-possible recheck of the availbility of the
target application before attempting to send it a broadcast.

Once the process has actually been spun up the system is essentially
committed to presenting it as a running application, and there is no
later check of the availability of the app: the failure mode for
continuing to attempt delivery is a crash *in the app process*,
and is user-visible.

We now check the app+userid existence of the intended recipient
just prior to committing to launch its process for receipt, and
if it is no longer available we simply skip that receiver and
continue normally.

Bug 11652784
Bug 11272019
Bug 8263020

Change-Id: Ib19ba2af493250890db7371c1a9f853772db1af0
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 17d13e5..e6da288 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -282,6 +282,10 @@
                 || (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
     }
 
+    public static boolean isAvailable(PackageUserState state) {
+        return checkUseInstalledOrBlocked(0, state);
+    }
+
     public static PackageInfo generatePackageInfo(PackageParser.Package p,
             int gids[], int flags, long firstInstallTime, long lastUpdateTime,
             HashSet<String> grantedPermissions, PackageUserState state, int userId) {