From ce8499e167c9ad4896125c17f2015ac1d9528267 Mon Sep 17 00:00:00 2001 From: Anthony Stange Date: Thu, 17 Feb 2022 19:49:48 +0000 Subject: [PATCH] Use enforceCallingOrSelfPermission for ContextHub APIs Previously, checkCallingPermission was used which fails when an IPC isn't used (e.g. something in the system server calls our APIs). Additionally, enforceCallingOrSelfPermission helps throw an exception with better logging than the check and throw does today. Fixes: 220167285 Test: Call from system server code Change-Id: I152ff750fa1505628bfe7f9cd78f21a222eefa87 --- .../location/contexthub/ContextHubServiceUtil.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java b/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java index 8fdde2486401f..e9bf90f1a82ed 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java @@ -16,8 +16,6 @@ package com.android.server.location.contexthub; -import static android.content.pm.PackageManager.PERMISSION_GRANTED; - import android.Manifest; import android.content.Context; import android.hardware.contexthub.V1_0.AsyncEventType; @@ -297,19 +295,14 @@ import java.util.List; } /** - * Checks for location hardware permissions. + * Checks for ACCESS_CONTEXT_HUB permissions. * * @param context the context of the service */ /* package */ static void checkPermissions(Context context) { - boolean hasAccessContextHubPermission = (context.checkCallingPermission( - CONTEXT_HUB_PERMISSION) == PERMISSION_GRANTED); - - if (!hasAccessContextHubPermission) { - throw new SecurityException( - "ACCESS_CONTEXT_HUB permission required to use Context Hub"); - } + context.enforceCallingOrSelfPermission(CONTEXT_HUB_PERMISSION, + "ACCESS_CONTEXT_HUB permission required to use Context Hub"); } /**