From 87c5855e17c51c4dafafb020f3d310c19dd54481 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Wed, 14 Aug 2019 18:14:55 -0700 Subject: [PATCH] Fixed SystemServiceRegistry to return a null AppPredictionManager when the service is not defined. Test: manual verification Test: atest CtsAssistTestCases Fixes: 139416391 Change-Id: Ieb2ae3f39bd42dc077ed3db1c6acdf429a39d519 --- core/java/android/app/SystemServiceRegistry.java | 3 ++- core/java/android/content/Context.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index d32b6b516a7d8..fe4b0d52b1337 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -1162,7 +1162,8 @@ final class SystemServiceRegistry { @Override public AppPredictionManager createService(ContextImpl ctx) throws ServiceNotFoundException { - return new AppPredictionManager(ctx); + IBinder b = ServiceManager.getService(Context.APP_PREDICTION_SERVICE); + return b == null ? null : new AppPredictionManager(ctx); } }); diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index c3dd82729d6d3..41c3da394de3e 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -4106,6 +4106,9 @@ public abstract class Context { /** * Official published name of the app prediction service. * + *

NOTE: this service is optional; callers of + * {@code Context.getSystemServiceName(APP_PREDICTION_SERVICE)} should check for {@code null}. + * * @hide * @see #getSystemService(String) */