Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1cb23eb3 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Handle USER_ALL DPM broadcast" into main

parents 330a4fc2 75e3bc83
Loading
Loading
Loading
Loading
+26 −10
Original line number Diff line number Diff line
@@ -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) {
+23 −0
Original line number Diff line number Diff line
@@ -514,6 +514,29 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
        assertFalse(mLockscreenUserManager.userAllowsNotificationsInPublic(mCurrentUser.id));
    }

    @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