From a1c5f63126a670c42cc998a382dc5b174673c720 Mon Sep 17 00:00:00 2001 From: Dario Freni Date: Thu, 14 Feb 2019 15:37:54 +0000 Subject: [PATCH] IllegalStateException if apex is unavailable. apexservice is expected to be active before zygote is run. In the exceptional case it isn't we should fail fast and throw a clear error message. The current version of the code would just assign "null" to the mApexService variable, thus causing a null pointer exception later in the code. Bug: 124363450 Test: device boots. Change-Id: I07361163c6e9efd392a633b30e85ca6be9f58ab3 --- .../core/java/com/android/server/pm/ApexManager.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/pm/ApexManager.java b/services/core/java/com/android/server/pm/ApexManager.java index e12d1dc927144..f35921caf8d37 100644 --- a/services/core/java/com/android/server/pm/ApexManager.java +++ b/services/core/java/com/android/server/pm/ApexManager.java @@ -27,6 +27,7 @@ import android.content.pm.PackageParser; import android.content.pm.PackageParser.PackageParserException; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.ServiceManager.ServiceNotFoundException; import android.util.Slog; import com.android.internal.util.IndentingPrintWriter; @@ -50,8 +51,12 @@ class ApexManager { private final Map mActivePackagesCache; ApexManager() { - mApexService = IApexService.Stub.asInterface( - ServiceManager.getService("apexservice")); + try { + mApexService = IApexService.Stub.asInterface( + ServiceManager.getServiceOrThrow("apexservice")); + } catch (ServiceNotFoundException e) { + throw new IllegalStateException("Required service apexservice not available"); + } mActivePackagesCache = populateActivePackagesCache(); }