From 3b7e6eda939b2c06238609726d53a3885495623e Mon Sep 17 00:00:00 2001 From: Alex Johnston Date: Wed, 17 Feb 2021 14:05:37 +0000 Subject: [PATCH] Update network logging metrics SET_NETWORK_LOGGING_ENABLED_VALUE Log whether the network logging is enabled on the work profile or the device. If network logging is enabled by a profile owner, then network logging will only be enabled on the work profile. RETRIEVE_NETWORK_LOGS_VALUE Log when network logs are retrieved. If network logging was enabled by a profile owner, then network logs will only include network activity on the work profile. Bug: 170460270 Test: atest com.android.cts.devicepolicy.MixedDeviceOwnerTest#testDelegation atest com.android.cts.devicepolicy.OrgOwnedProfileOwnerTest#testNetworkLogging Change-Id: If03a048e852ea13a664e4a2d0e492f1b1f4c75fb --- .../DevicePolicyManagerService.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 604d1d6c010b0..a42618f926c70 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -533,8 +533,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { /** * Strings logged with {@link - * com.android.internal.logging.nano.MetricsProto.MetricsEvent#PROVISIONING_ENTRY_POINT_ADB} - * and {@link DevicePolicyEnums#PROVISIONING_ENTRY_POINT_ADB}. + * com.android.internal.logging.nano.MetricsProto.MetricsEvent#PROVISIONING_ENTRY_POINT_ADB}, + * {@link DevicePolicyEnums#PROVISIONING_ENTRY_POINT_ADB}, + * {@link DevicePolicyEnums#SET_NETWORK_LOGGING_ENABLED} and + * {@link DevicePolicyEnums#RETRIEVE_NETWORK_LOGS}. */ private static final String LOG_TAG_PROFILE_OWNER = "profile-owner"; private static final String LOG_TAG_DEVICE_OWNER = "device-owner"; @@ -14153,9 +14155,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return; } final CallerIdentity caller = getCallerIdentity(admin, packageName); + final boolean isManagedProfileOwner = isProfileOwner(caller) + && isManagedProfile(caller.getUserId()); Preconditions.checkCallAuthorization((caller.hasAdminComponent() - && (isDeviceOwner(caller) - || (isProfileOwner(caller) && isManagedProfile(caller.getUserId())))) + && (isDeviceOwner(caller) || isManagedProfileOwner)) || (caller.hasPackage() && isCallerDelegate(caller, DELEGATION_NETWORK_LOGGING))); synchronized (getLockObject()) { @@ -14177,6 +14180,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { .setAdmin(caller.getPackageName()) .setBoolean(/* isDelegate */ admin == null) .setInt(enabled ? 1 : 0) + .setStrings(isManagedProfileOwner + ? LOG_TAG_PROFILE_OWNER : LOG_TAG_DEVICE_OWNER) .write(); } } @@ -14333,9 +14338,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { return null; } final CallerIdentity caller = getCallerIdentity(admin, packageName); + final boolean isManagedProfileOwner = isProfileOwner(caller) + && isManagedProfile(caller.getUserId()); Preconditions.checkCallAuthorization((caller.hasAdminComponent() - && (isDeviceOwner(caller) - || (isProfileOwner(caller) && isManagedProfile(caller.getUserId())))) + && (isDeviceOwner(caller) || isManagedProfileOwner)) || (caller.hasPackage() && isCallerDelegate(caller, DELEGATION_NETWORK_LOGGING))); if (mOwners.hasDeviceOwner()) { checkAllUsersAreAffiliatedWithDevice(); @@ -14349,6 +14355,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { .createEvent(DevicePolicyEnums.RETRIEVE_NETWORK_LOGS) .setAdmin(caller.getPackageName()) .setBoolean(/* isDelegate */ admin == null) + .setStrings(isManagedProfileOwner + ? LOG_TAG_PROFILE_OWNER : LOG_TAG_DEVICE_OWNER) .write(); final long currentTime = System.currentTimeMillis();