From a380749398c02c5b7fd48c9e39160236aac4cfd7 Mon Sep 17 00:00:00 2001 From: Pavel Grafov Date: Wed, 18 Jan 2023 17:51:32 +0000 Subject: [PATCH] Fix NPE in streamin policy getters. If there is a DO but it is not on userId, admin was null. With this change DO policies set on other users aren't taken into account, NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY is returned. Fixes: 264761323 Test: atest NearbyNotificationStreamingPolicyTest Test: atest NearbyAppStreamingPolicyTest Change-Id: I4562fb44d663a2d590ab92dd66b881b636838910 --- .../DevicePolicyManagerService.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index fa6fa530296cc..45a1696828c84 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -7957,13 +7957,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { Preconditions.checkCallAuthorization(hasCrossUsersPermission(caller, userId)); synchronized (getLockObject()) { - if (mOwners.hasProfileOwner(userId) || mOwners.hasDeviceOwner()) { - final ActiveAdmin admin = getDeviceOrProfileOwnerAdminLocked(userId); - return admin.mNearbyNotificationStreamingPolicy; - } + final ActiveAdmin admin = getDeviceOrProfileOwnerAdminLocked(userId); + return admin != null + ? admin.mNearbyNotificationStreamingPolicy + : NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY; } - - return NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY; } @Override @@ -7998,13 +7996,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { Preconditions.checkCallAuthorization(hasCrossUsersPermission(caller, userId)); synchronized (getLockObject()) { - if (mOwners.hasProfileOwner(userId) || mOwners.hasDeviceOwner()) { - final ActiveAdmin admin = getDeviceOrProfileOwnerAdminLocked(userId); - return admin.mNearbyAppStreamingPolicy; - } + final ActiveAdmin admin = getDeviceOrProfileOwnerAdminLocked(userId); + return admin != null + ? admin.mNearbyAppStreamingPolicy + : NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY; } - - return NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY; } /**