From cfe8c66a7a945fe813457eb7c25ceb5fc2c2a4e1 Mon Sep 17 00:00:00 2001 From: Michael Wachenschwanz Date: Mon, 11 May 2020 16:23:43 -0700 Subject: [PATCH] Fix DPM check logic for AppUsageLimitObserver (un)registering In the case that the DevicePolicyManagerInternal Local service does not exist on device, the permission check for (un)registerAppUsageLimitObserver should not be skipped. Test: atest android.app.usage.cts.UsageStatsTest (must be on a device with in it's features xml) Fixes: 155360727 Change-Id: I8a88e03a7636956d27f531cf989bda1a32799f07 --- .../java/com/android/server/usage/UsageStatsService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index 5b5d57bf2f51c..75e3df199c088 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -1847,7 +1847,7 @@ public class UsageStatsService extends SystemService implements final DevicePolicyManagerInternal dpmInternal = getDpmInternal(); if (!hasPermissions(callingPackage, Manifest.permission.SUSPEND_APPS, Manifest.permission.OBSERVE_APP_USAGE) - && (dpmInternal != null && !dpmInternal.isActiveSupervisionApp(callingUid))) { + && (dpmInternal == null || !dpmInternal.isActiveSupervisionApp(callingUid))) { throw new SecurityException("Caller must be the active supervision app or " + "it must have both SUSPEND_APPS and OBSERVE_APP_USAGE permissions"); } @@ -1874,7 +1874,7 @@ public class UsageStatsService extends SystemService implements final DevicePolicyManagerInternal dpmInternal = getDpmInternal(); if (!hasPermissions(callingPackage, Manifest.permission.SUSPEND_APPS, Manifest.permission.OBSERVE_APP_USAGE) - && (dpmInternal != null && !dpmInternal.isActiveSupervisionApp(callingUid))) { + && (dpmInternal == null || !dpmInternal.isActiveSupervisionApp(callingUid))) { throw new SecurityException("Caller must be the active supervision app or " + "it must have both SUSPEND_APPS and OBSERVE_APP_USAGE permissions"); }