Avoid caching services with missing binders.

When fetching system services early during boot, if the underlying
binder interface hasn't been published yet, we end up caching a
manager class that is broken for the remainder of the process
lifetime, and innocent downstream callers end up using the broken
cached manager.

Fix this by using an explicit exception to quickly abort manager
creation when the underlying binder is missing.  The exception is
only used to skip the remainder of the manager creation, and it
doesn't actually crash the process.

Bug: 28634953
Change-Id: I0cb62261e6d6833660704b93a11185aa11a2ac97
diff --git a/core/java/android/hardware/location/ContextHubService.java b/core/java/android/hardware/location/ContextHubService.java
index 062c958..893ed3f 100644
--- a/core/java/android/hardware/location/ContextHubService.java
+++ b/core/java/android/hardware/location/ContextHubService.java
@@ -154,6 +154,9 @@
             Log.e(TAG, "Invalid contextHubhandle " + contextHubHandle);
             return -1;
         }
+        if (app == null) {
+            return -1;
+        }
 
         int[] msgHeader = new int[MSG_LOAD_APP_HEADER_SIZE];
         msgHeader[HEADER_FIELD_HUB_HANDLE] = contextHubHandle;
@@ -240,6 +243,11 @@
                            throws RemoteException {
         checkPermissions();
 
+        if (msg == null || msg.getData() == null) {
+            Log.w(TAG, "null ptr");
+            return -1;
+        }
+
         int[] msgHeader = new int[MSG_HEADER_SIZE];
         msgHeader[HEADER_FIELD_HUB_HANDLE] = hubHandle;
         msgHeader[HEADER_FIELD_APP_INSTANCE] = nanoAppHandle;