Fix crash in PendingIntentRecord debug output.

Add null checks to a few places to avoid crashes when dumping
debug data.

Also add some sanity checks for accessing content providers in
the activity manager.
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 4169cc5..7b64704 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -7615,6 +7615,15 @@
                                     ? cpi.readPermission : cpi.writePermission);
                 }
 
+                if (!mSystemReady && !mDidUpdate && !mWaitingUpdate
+                        && !cpi.processName.equals("system")) {
+                    // If this content provider does not run in the system
+                    // process, and the system is not yet ready to run other
+                    // processes, then fail fast instead of hanging.
+                    throw new IllegalArgumentException(
+                            "Attempt to launch content provider before system ready");
+                }
+                
                 cpr = (ContentProviderRecord)mProvidersByClass.get(cpi.name);
                 final boolean firstClass = cpr == null;
                 if (firstClass) {
@@ -7862,6 +7871,16 @@
     public static final void installSystemProviders() {
         ProcessRecord app = mSelf.mProcessNames.get("system", Process.SYSTEM_UID);
         List providers = mSelf.generateApplicationProvidersLocked(app);
+        if (providers != null) {
+            for (int i=providers.size()-1; i>=0; i--) {
+                ProviderInfo pi = (ProviderInfo)providers.get(i);
+                if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
+                    Log.w(TAG, "Not installing system proc provider " + pi.name
+                            + ": not system .apk");
+                    providers.remove(i);
+                }
+            }
+        }
         mSystemThread.installSystemProviders(providers);
     }
 
diff --git a/services/java/com/android/server/am/PendingIntentRecord.java b/services/java/com/android/server/am/PendingIntentRecord.java
index 94b5f56..fac47d7 100644
--- a/services/java/com/android/server/am/PendingIntentRecord.java
+++ b/services/java/com/android/server/am/PendingIntentRecord.java
@@ -145,8 +145,9 @@
         
         public String toString() {
             return "Key{" + typeName() + " pkg=" + packageName
-                + " intent=" + requestIntent.toShortString(true, false) + " flags=0x"
-                + Integer.toHexString(flags) + "}";
+                + " intent="
+                + (requestIntent != null ? requestIntent.toShortString(true, false) : "<null>")
+                + " flags=0x" + Integer.toHexString(flags) + "}";
         }
         
         String typeName() {
@@ -295,8 +296,10 @@
             pw.print(prefix); pw.print("requestCode="); pw.print(key.requestCode);
                     pw.print(" requestResolvedType="); pw.println(key.requestResolvedType);
         }
-        pw.print(prefix); pw.print("requestIntent=");
-                pw.println(key.requestIntent.toShortString(true, true));
+        if (key.requestIntent != null) {
+            pw.print(prefix); pw.print("requestIntent=");
+                    pw.println(key.requestIntent.toShortString(true, true));
+        }
         if (sent || canceled) {
             pw.print(prefix); pw.print("sent="); pw.print(sent);
                     pw.print(" canceled="); pw.println(canceled);