From 6515263fd9edb248c9b11285832147204ecbd53f Mon Sep 17 00:00:00 2001 From: Pavel Grafov Date: Mon, 26 Mar 2018 15:14:45 +0100 Subject: [PATCH] Show work notifications in the shade unless on keyguard. 1. Make work profile notifications redacted but visible if only work profile is locked (i.e. not on the keyguard). Previously if the user disables notifications on the lockscreen, work notifications will disappear from notification shade when the profile is locked even if the device itself is not locked. To achieve this NotificationLockscreenUserManager now checks notification status for a given user rather than system-wide. When the keyguard is locked, system-wide setting will still prevent work notification from being visible. 2. Fix bug introduced by previous CL, since isCurrentProfile is alwoays true for mCurrentUser, it caused notifications to be visible on keyguard when they shouldn't. Test: manual, tried combinations of device and profile settings Test: runtest systemui Bug: 64829587 Change-Id: I104e938b15897a909c086c62e273f922b96ba7db --- .../NotificationLockscreenUserManager.java | 20 ++++++++++--------- .../NotificationViewHierarchyManager.java | 3 +-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java index ccabb79e229b9..e24bf6762b4c2 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java @@ -47,7 +47,6 @@ import com.android.systemui.statusbar.policy.DeviceProvisionedController; import java.io.FileDescriptor; import java.io.PrintWriter; -import java.util.List; /** * Handles keeping track of the current user, profiles, and various things related to hiding @@ -352,7 +351,8 @@ public class NotificationLockscreenUserManager implements Dumpable { final boolean allowedByUser = 0 != Settings.Secure.getIntForUser( mContext.getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, userHandle); - final boolean allowedByDpm = adminAllowsUnredactedNotifications(userHandle); + final boolean allowedByDpm = adminAllowsKeyguardFeature(userHandle, + DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS); final boolean allowed = allowedByUser && allowedByDpm; mUsersAllowingPrivateNotifications.append(userHandle, allowed); return allowed; @@ -361,13 +361,13 @@ public class NotificationLockscreenUserManager implements Dumpable { return mUsersAllowingPrivateNotifications.get(userHandle); } - private boolean adminAllowsUnredactedNotifications(int userHandle) { + private boolean adminAllowsKeyguardFeature(int userHandle, int feature) { if (userHandle == UserHandle.USER_ALL) { return true; } - final int dpmFlags = mDevicePolicyManager.getKeyguardDisabledFeatures(null /* admin */, - userHandle); - return (dpmFlags & DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS) == 0; + final int dpmFlags = + mDevicePolicyManager.getKeyguardDisabledFeatures(null /* admin */, userHandle); + return (dpmFlags & feature) == 0; } /** @@ -389,14 +389,17 @@ public class NotificationLockscreenUserManager implements Dumpable { * "public" (secure & locked) mode? */ private boolean userAllowsNotificationsInPublic(int userHandle) { - if (isCurrentProfile(userHandle)) { + if (isCurrentProfile(userHandle) && userHandle != mCurrentUserId) { return true; } if (mUsersAllowingNotifications.indexOfKey(userHandle) < 0) { - final boolean allowed = 0 != Settings.Secure.getIntForUser( + final boolean allowedByUser = 0 != Settings.Secure.getIntForUser( mContext.getContentResolver(), Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, userHandle); + final boolean allowedByDpm = adminAllowsKeyguardFeature(userHandle, + DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS); + final boolean allowed = allowedByUser && allowedByDpm; mUsersAllowingNotifications.append(userHandle, allowed); return allowed; } @@ -428,7 +431,6 @@ public class NotificationLockscreenUserManager implements Dumpable { Notification.VISIBILITY_PRIVATE; } - private void updateCurrentProfilesCache() { synchronized (mCurrentProfiles) { mCurrentProfiles.clear(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java index 75b8b371119e5..fb8d5faff6283 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java @@ -313,8 +313,7 @@ public class NotificationViewHierarchyManager { boolean showOnKeyguard = mLockscreenUserManager.shouldShowOnKeyguard(entry .notification); if (suppressedSummary - || (mLockscreenUserManager.isLockscreenPublicMode(userId) - && !mLockscreenUserManager.shouldShowLockscreenNotifications()) + || mLockscreenUserManager.shouldHideNotifications(userId) || (isLocked && !showOnKeyguard)) { entry.row.setVisibility(View.GONE); } else {