diff options
2 files changed, 49 insertions, 10 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java index e486457b89bf..05c383910542 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java @@ -18,6 +18,7 @@ package com.android.systemui.statusbar; import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED; import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS; import static android.app.admin.DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS; +import static android.os.UserHandle.USER_ALL; import static android.os.UserHandle.USER_NULL; import static android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS; import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS; @@ -46,6 +47,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; import android.util.Log; +import android.util.Slog; import android.util.SparseArray; import android.util.SparseBooleanArray; @@ -155,8 +157,22 @@ public class NotificationLockscreenUserManagerImpl implements if (ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action)) { if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) { - boolean changed = updateDpcSettings(getSendingUserId()); - if (mCurrentUserId == getSendingUserId()) { + boolean changed = false; + int sendingUserId = getSendingUserId(); + if (sendingUserId == USER_ALL) { + // When a Device Owner triggers changes it's sent as USER_ALL. Normalize + // the user before calling into DPM + sendingUserId = mCurrentUserId; + @SuppressLint("MissingPermission") + List<UserInfo> users = mUserManager.getUsers(); + for (int i = users.size() - 1; i >= 0; i--) { + changed |= updateDpcSettings(users.get(i).id); + } + } else { + changed |= updateDpcSettings(sendingUserId); + } + + if (mCurrentUserId == sendingUserId) { changed |= updateLockscreenNotificationSetting(); } if (changed) { @@ -374,13 +390,13 @@ public class NotificationLockscreenUserManagerImpl implements mContext.getContentResolver().registerContentObserver( SHOW_LOCKSCREEN, false, mLockscreenSettingsObserver, - UserHandle.USER_ALL); + USER_ALL); mContext.getContentResolver().registerContentObserver( SHOW_PRIVATE_LOCKSCREEN, true, mLockscreenSettingsObserver, - UserHandle.USER_ALL); + USER_ALL); if (!mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) { mContext.getContentResolver().registerContentObserver( @@ -441,7 +457,7 @@ public class NotificationLockscreenUserManagerImpl implements public boolean isCurrentProfile(int userId) { synchronized (mLock) { - return userId == UserHandle.USER_ALL || mCurrentProfiles.get(userId) != null; + return userId == USER_ALL || mCurrentProfiles.get(userId) != null; } } @@ -526,7 +542,7 @@ public class NotificationLockscreenUserManagerImpl implements */ public boolean userAllowsPrivateNotificationsInPublic(int userHandle) { if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) { - if (userHandle == UserHandle.USER_ALL) { + if (userHandle == USER_ALL) { userHandle = mCurrentUserId; } if (mUsersUsersAllowingPrivateNotifications.indexOfKey(userHandle) < 0) { @@ -540,7 +556,7 @@ public class NotificationLockscreenUserManagerImpl implements return mUsersUsersAllowingPrivateNotifications.get(userHandle) && mUsersDpcAllowingPrivateNotifications.get(userHandle); } else { - if (userHandle == UserHandle.USER_ALL) { + if (userHandle == USER_ALL) { return true; } @@ -574,7 +590,7 @@ public class NotificationLockscreenUserManagerImpl implements } private boolean adminAllowsKeyguardFeature(int userHandle, int feature) { - if (userHandle == UserHandle.USER_ALL) { + if (userHandle == USER_ALL) { return true; } final int dpmFlags = @@ -591,7 +607,7 @@ public class NotificationLockscreenUserManagerImpl implements } public boolean isLockscreenPublicMode(int userId) { - if (userId == UserHandle.USER_ALL) { + if (userId == USER_ALL) { return mLockscreenPublicMode.get(mCurrentUserId, false); } return mLockscreenPublicMode.get(userId, false); @@ -610,7 +626,7 @@ public class NotificationLockscreenUserManagerImpl implements if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) { // Unlike 'show private', settings does not show a copy of this setting for each // profile, so it inherits from the parent user. - if (userHandle == UserHandle.USER_ALL || mCurrentManagedProfiles.contains(userHandle)) { + if (userHandle == USER_ALL || mCurrentManagedProfiles.contains(userHandle)) { userHandle = mCurrentUserId; } if (mUsersUsersAllowingNotifications.indexOfKey(userHandle) < 0) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java index 34c7b09ba86a..42c7375bfb2e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java @@ -515,6 +515,29 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { } @Test + public void testDevicePolicyDoesNotAllowNotifications_deviceOwnerSetsForUserAll() { + // User allows them + mSettings.putIntForUser(LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, mCurrentUser.id); + mSettings.putIntForUser(LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, mSecondaryUser.id); + changeSetting(LOCK_SCREEN_SHOW_NOTIFICATIONS); + + // DevicePolicy hides notifs on lockscreen + when(mDevicePolicyManager.getKeyguardDisabledFeatures(null, mCurrentUser.id)) + .thenReturn(KEYGUARD_DISABLE_SECURE_NOTIFICATIONS); + when(mDevicePolicyManager.getKeyguardDisabledFeatures(null, mSecondaryUser.id)) + .thenReturn(KEYGUARD_DISABLE_SECURE_NOTIFICATIONS); + + BroadcastReceiver.PendingResult pr = new BroadcastReceiver.PendingResult( + 0, null, null, 0, true, false, null, USER_ALL, 0); + mLockscreenUserManager.mAllUsersReceiver.setPendingResult(pr); + mLockscreenUserManager.mAllUsersReceiver.onReceive(mContext, + new Intent(ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED)); + + assertFalse(mLockscreenUserManager.userAllowsNotificationsInPublic(mCurrentUser.id)); + assertFalse(mLockscreenUserManager.userAllowsNotificationsInPublic(mSecondaryUser.id)); + } + + @Test public void testDevicePolicyDoesNotAllowNotifications_userAll() { // User allows them mSettings.putIntForUser(LOCK_SCREEN_SHOW_NOTIFICATIONS, 1, mCurrentUser.id); |