From c88b3ce7c4d812949ffe1289069a6437461bbe75 Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Thu, 23 Jan 2020 13:06:37 -0800 Subject: [PATCH] Guard Context Hub Service on Context Hub feature Also adds annotation to require the feature. Bug: 147677675 Test: Compile and flash, verify Context Hub Service is not found if the feature flag is not defined Change-Id: Ia718c76ec4308274dc66cfe975e762997e3539ca --- .../java/android/hardware/location/ContextHubManager.java | 3 +++ services/java/com/android/server/SystemServer.java | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java index a51d2c929a2c2..a054f45ec6f5e 100644 --- a/core/java/android/hardware/location/ContextHubManager.java +++ b/core/java/android/hardware/location/ContextHubManager.java @@ -19,6 +19,7 @@ import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.RequiresFeature; import android.annotation.RequiresPermission; import android.annotation.SuppressLint; import android.annotation.SystemApi; @@ -26,6 +27,7 @@ import android.annotation.SystemService; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.os.Handler; import android.os.HandlerExecutor; import android.os.Looper; @@ -50,6 +52,7 @@ import java.util.concurrent.Executor; */ @SystemApi @SystemService(Context.CONTEXTHUB_SERVICE) +@RequiresFeature(PackageManager.FEATURE_CONTEXTHUB) public final class ContextHubManager { private static final String TAG = "ContextHubManager"; diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 258d7628e502a..df2b9e932fbc7 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -1724,9 +1724,11 @@ public final class SystemServer { mSystemServiceManager.startService(SensorNotificationService.class); t.traceEnd(); - t.traceBegin("StartContextHubSystemService"); - mSystemServiceManager.startService(ContextHubSystemService.class); - t.traceEnd(); + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_CONTEXTHUB)) { + t.traceBegin("StartContextHubSystemService"); + mSystemServiceManager.startService(ContextHubSystemService.class); + t.traceEnd(); + } t.traceBegin("StartDiskStatsService"); try {