From bed14ecfc5c15c8c1229a3823e74b42308d2c226 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Tue, 10 May 2016 12:54:45 -0600 Subject: [PATCH] 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 --- core/java/android/app/usage/NetworkStatsManager.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/java/android/app/usage/NetworkStatsManager.java b/core/java/android/app/usage/NetworkStatsManager.java index 7961a72a12..e805fabc79 100644 --- a/core/java/android/app/usage/NetworkStatsManager.java +++ b/core/java/android/app/usage/NetworkStatsManager.java @@ -34,6 +34,7 @@ import android.os.Handler; import android.os.Looper; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.ServiceManager.ServiceNotFoundException; import android.util.Log; /** @@ -95,10 +96,10 @@ public class NetworkStatsManager { /** * {@hide} */ - public NetworkStatsManager(Context context) { + public NetworkStatsManager(Context context) throws ServiceNotFoundException { mContext = context; mService = INetworkStatsService.Stub.asInterface( - ServiceManager.getService(Context.NETWORK_STATS_SERVICE)); + ServiceManager.getServiceOrThrow(Context.NETWORK_STATS_SERVICE)); } /**