Fix issue #18827122: system server crashed on broadcasting...

...an intent with invalid or null package uri

Also tweak battery stats to record in the history when we shut
down, to understand when restarts are due to clean shutdowns or
crashes.

Change-Id: I6443dafc23e356be9f569906f6081152d4f92d2b
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index be3251c..d484b8f 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -320,6 +320,9 @@
         checkManageUsersPermission("get the profile parent");
         synchronized (mPackagesLock) {
             UserInfo profile = getUserInfoLocked(userHandle);
+            if (profile == null) {
+                return null;
+            }
             int parentUserId = profile.profileGroupId;
             if (parentUserId == UserInfo.NO_PROFILE_GROUP_ID) {
                 return null;