Fix crash: check for install failure cleanly

Don't go looking at attributes of a package struct without first verifying
that the struct pointer is non-null:  in the failed-install case, of course
there will be no package info.

Change-Id: I3b2cafca2f1e3891a6592825ce5bcc977e7f3483
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 90a606d..38d8615 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -4344,7 +4344,9 @@
                 // succeeded, (b) the operation is not an update, and (c) the new
                 // package has a backupAgent defined.
                 final boolean update = res.removedInfo.removedPackage != null;
-                boolean doRestore = (!update && res.pkg.applicationInfo.backupAgentName != null);
+                boolean doRestore = (!update
+                        && res.pkg != null
+                        && res.pkg.applicationInfo.backupAgentName != null);
 
                 // Set up the post-install work request bookkeeping.  This will be used
                 // and cleaned up by the post-install event handling regardless of whether