From 80f1f86f7a6b44e0abd927ba980289e599c9976f Mon Sep 17 00:00:00 2001 From: Rubin Xu Date: Tue, 13 Jul 2021 13:53:19 +0100 Subject: [PATCH] Clear binder identity during network logging notification processing A regression was introduced by Iab009978c472f843000c1b193de571863fc185bb which moved some external calls outside a binderClearCallingIdentity block. Fix it by moving them back. Bug: 193206826 Test: atest DeviceOwnerTest#testAdminActionBookkeeping Test: atest DeviceOwnerTest#testNetworkLoggingWithSingleUser Test: atest DeviceOwnerTest#testNetworkLogging_multipleBatches Test: atest DeviceOwnerTest#testNetworkLoggingWithTwoUsers Test: atest DeviceOwnerTest#testNetworkLogging_rebootResetsId Test: atest OrgOwnedProfileOwnerTest#testNetworkLoggingLogged Test: atest OrgOwnedProfileOwnerTest#testNetworkLoggingDelegate Test: atest OrgOwnedProfileOwnerTest#testNetworkLogging Test: atest DeviceOwnerPlusProfileOwnerTest#testNetworkAndSecurityLoggingAvailableIfAffiliated Test: atest MixedDeviceOwnerTest#testDelegation Test: CTSVerifier: Device Owner Tests -> Network Logging U Change-Id: I6c6420f39f671082137adcf498914dd5ee1374fa --- .../DevicePolicyManagerService.java | 24 +++++++++---------- 1 file changed, 12 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 fd71d1bc1c382..e9babceb87c6d 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -14991,9 +14991,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } private void setNetworkLoggingActiveInternal(boolean active) { - final boolean[] shouldSendNotification = new boolean[] {false}; - synchronized (getLockObject()) { - mInjector.binderWithCleanCallingIdentity(() -> { + mInjector.binderWithCleanCallingIdentity(() -> { + boolean shouldSendNotification = false; + synchronized (getLockObject()) { if (active) { if (mNetworkLogger == null) { final int affectedUserId = getNetworkLoggingAffectedUser(); @@ -15008,7 +15008,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { + " service not being available yet."); } maybePauseDeviceWideLoggingLocked(); - shouldSendNotification[0] = shouldSendNetworkLoggingNotificationLocked(); + shouldSendNotification = shouldSendNetworkLoggingNotificationLocked(); } else { if (mNetworkLogger != null && !mNetworkLogger.stopNetworkLogging()) { Slogf.wtf(LOG_TAG, "Network logging could not be stopped due to the logging" @@ -15016,15 +15016,15 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } mNetworkLogger = null; } - }); - } - if (active) { - if (shouldSendNotification[0]) { - sendNetworkLoggingNotification(); } - } else { - mInjector.getNotificationManager().cancel(SystemMessage.NOTE_NETWORK_LOGGING); - } + if (active) { + if (shouldSendNotification) { + sendNetworkLoggingNotification(); + } + } else { + mInjector.getNotificationManager().cancel(SystemMessage.NOTE_NETWORK_LOGGING); + } + }); } private @UserIdInt int getNetworkLoggingAffectedUser() {