From 1292d5808efd94c8ce0d3862bdbbb327011cdc1a Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Fri, 5 Mar 2021 13:34:31 -0800 Subject: [PATCH] Restricts PersonalAppsSuspensionHelper.dump() to system user. It calls a pm method that fails if called for a different user. As this dump is mostly useful for system user anyways, we can just ignore the other users (rather than changing the permission check in the PM method). Also fixed the userId passed to that method. Test: adb shell dumpsys device_policy |grep -A 20 PersonalAppsSuspensionHelper # on automotive Bug: 181238156 Change-Id: Ib416fe9be81a12f40b0b95bfe864d0b2c45efe0b --- .../DevicePolicyManagerService.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 04af5c93160d6..ea233c5ce271e 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -1598,10 +1598,6 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { void setDevicePolicySafetyChecker(DevicePolicySafetyChecker safetyChecker) { mSafetyChecker = safetyChecker; } - - void dumpPerUserData(IndentingPrintWriter pw, @UserIdInt int userId) { - PersonalAppsSuspensionHelper.forUser(mContext, userId).dump(pw); - } } /** @@ -9166,15 +9162,23 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { private void dumpPerUserData(IndentingPrintWriter pw) { int userCount = mUserData.size(); - for (int userId = 0; userId < userCount; userId++) { - DevicePolicyData policy = getUserData(mUserData.keyAt(userId)); + for (int i = 0; i < userCount; i++) { + int userId = mUserData.keyAt(i); + DevicePolicyData policy = getUserData(userId); policy.dump(pw); pw.println(); - pw.increaseIndent(); - mInjector.dumpPerUserData(pw, userId); - pw.decreaseIndent(); - pw.println(); + if (userId == UserHandle.USER_SYSTEM) { + pw.increaseIndent(); + PersonalAppsSuspensionHelper.forUser(mContext, userId).dump(pw); + pw.decreaseIndent(); + pw.println(); + } else { + // pm.getUnsuspendablePackages() will fail if it's called for a different user; + // as this dump is mostly useful for system user anyways, we can just ignore the + // others (rather than changing the permission check in the PM method) + Slog.d(LOG_TAG, "skipping PersonalAppsSuspensionHelper.dump() for user " + userId); + } } }