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

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

Merge "Cleanup NOTIF_LS_BACKGROUND_THREAD" into main

parents 351cdcd1 10f479b0
Loading
Loading
Loading
Loading
+0 −614

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −2
Original line number Diff line number Diff line
@@ -172,8 +172,6 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
    public void setUp() {
        MockitoAnnotations.initMocks(this);

        mFakeFeatureFlags.set(Flags.NOTIF_LS_BACKGROUND_THREAD, true);

        int currentUserId = ActivityManager.getCurrentUser();
        when(mUserTracker.getUserId()).thenReturn(currentUserId);
        mSettings = new FakeSettings();
+0 −5
Original line number Diff line number Diff line
@@ -102,11 +102,6 @@ object Flags {
            default = true
        )

    // TODO(b/301955929)
    @JvmField
    val NOTIF_LS_BACKGROUND_THREAD =
            releasedFlag("notification_lockscreen_mgr_bg_thread")

    // 200 - keyguard/lockscreen
    // ** Flag retired **
    // public static final BooleanFlag KEYGUARD_LAYOUT =
+102 −193
Original line number Diff line number Diff line
@@ -156,7 +156,6 @@ public class NotificationLockscreenUserManagerImpl implements
            final String action = intent.getAction();

            if (ACTION_KEYGUARD_PRIVATE_NOTIFICATIONS_CHANGED.equals(action)) {
                if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
                mKeyguardAllowingNotifications =
                        intent.getBooleanExtra(EXTRA_KM_PRIVATE_NOTIFS_ALLOWED, false);
                if (mCurrentUserId == getSendingUserId()) {
@@ -167,7 +166,6 @@ public class NotificationLockscreenUserManagerImpl implements
                }
            }
        }
        }
    };

    protected final BroadcastReceiver mAllUsersReceiver = new BroadcastReceiver() {
@@ -176,7 +174,6 @@ public class NotificationLockscreenUserManagerImpl implements
            final String action = intent.getAction();

            if (ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action)) {
                if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
                boolean changed = false;
                int sendingUserId = getSendingUserId();
                if (sendingUserId == USER_ALL) {
@@ -198,15 +195,6 @@ public class NotificationLockscreenUserManagerImpl implements
                if (changed) {
                    notifyNotificationStateChanged();
                }
                } else {
                    if (isCurrentProfile(getSendingUserId())) {
                        mUsersAllowingPrivateNotifications.clear();
                        updateLockscreenNotificationSetting();
                        // TODO(b/231976036): Consolidate pipeline invalidations related to this
                        //  event
                        // notifyNotificationStateChanged();
                    }
                }
            }
        }
    };
@@ -225,12 +213,10 @@ public class NotificationLockscreenUserManagerImpl implements
                updateCurrentProfilesCache();
            } else if (Objects.equals(action, Intent.ACTION_USER_ADDED)){
                updateCurrentProfilesCache();
                if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
                final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, USER_NULL);
                mBackgroundExecutor.execute(() -> {
                    initValuesForUser(userId);
                });
                }
            } else if (profileAvailabilityActions(action)) {
                updateCurrentProfilesCache();
            } else if (Objects.equals(action, Intent.ACTION_USER_UNLOCKED)) {
@@ -360,28 +346,16 @@ public class NotificationLockscreenUserManagerImpl implements
    }

    private void init() {
        mLockscreenSettingsObserver = new ExecutorContentObserver(
                mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)
                        ? mBackgroundExecutor
                        : mMainExecutor) {
        mLockscreenSettingsObserver = new ExecutorContentObserver(mBackgroundExecutor) {

            @Override
            public void onChange(boolean selfChange, Collection<Uri> uris, int flags) {
                if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
                @SuppressLint("MissingPermission")
                List<UserInfo> users = mUserManager.getUsers();
                for (int i = users.size() - 1; i >= 0; i--) {
                    onChange(selfChange, uris, flags,users.get(i).getUserHandle());
                }
                } else {
                    // We don't know which user changed LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS or
                    // LOCK_SCREEN_SHOW_NOTIFICATIONS, so we just dump our cache ...
                    mUsersAllowingPrivateNotifications.clear();
                    mUsersAllowingNotifications.clear();
                    // ... and refresh all the notifications
                    updateLockscreenNotificationSetting();
                    notifyNotificationStateChanged();
                }

            }

            // Note: even though this is an override, this method is not called by the OS
@@ -390,7 +364,6 @@ public class NotificationLockscreenUserManagerImpl implements
            @Override
            public void onChange(boolean selfChange, Collection<Uri> uris,
                    int flags, UserHandle user) {
                if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
                boolean changed = false;
                for (Uri uri: uris) {
                    if (SHOW_LOCKSCREEN.equals(uri)) {
@@ -407,7 +380,6 @@ public class NotificationLockscreenUserManagerImpl implements
                    notifyNotificationStateChanged();
                }
            }
            }
        };

        mSettingsObserver = new ExecutorContentObserver(mMainExecutor) {
@@ -432,16 +404,10 @@ public class NotificationLockscreenUserManagerImpl implements
                mLockscreenSettingsObserver,
                USER_ALL);

        if (!mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
            mContext.getContentResolver().registerContentObserver(
                    Settings.Global.getUriFor(Settings.Global.ZEN_MODE), false,
                    mSettingsObserver);
        }

        mBroadcastDispatcher.registerReceiver(mAllUsersReceiver,
                new IntentFilter(ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED),
                mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)
                        ? mBackgroundExecutor : null, UserHandle.ALL);
                mBackgroundExecutor, UserHandle.ALL);
        if (keyguardPrivateNotifications()) {
            mBroadcastDispatcher.registerReceiver(mKeyguardReceiver,
                    new IntentFilter(ACTION_KEYGUARD_PRIVATE_NOTIFICATIONS_CHANGED),
@@ -471,7 +437,6 @@ public class NotificationLockscreenUserManagerImpl implements
        mCurrentUserId = mUserTracker.getUserId(); // in case we reg'd receiver too late
        updateCurrentProfilesCache();

        if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
        // Set  up
        mBackgroundExecutor.execute(() -> {
            @SuppressLint("MissingPermission") List<UserInfo> users = mUserManager.getUsers();
@@ -479,9 +444,6 @@ public class NotificationLockscreenUserManagerImpl implements
                initValuesForUser(users.get(i).id);
            }
        });
        } else {
            mSettingsObserver.onChange(false);  // set up
        }
    }

    private void initValuesForUser(@UserIdInt int userId) {
@@ -519,7 +481,6 @@ public class NotificationLockscreenUserManagerImpl implements
        boolean show;
        boolean allowedByDpm;

        if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
        if (keyguardPrivateNotifications()) {
            show = mUsersUsersAllowingNotifications.get(mCurrentUserId);
        } else {
@@ -529,16 +490,6 @@ public class NotificationLockscreenUserManagerImpl implements
        // If DPC never notified us about a user, that means they have no policy for the user,
        // and they allow the behavior
        allowedByDpm = mUsersDpcAllowingNotifications.get(mCurrentUserId, true);
        } else {
            show = mSecureSettings.getIntForUser(
                    LOCK_SCREEN_SHOW_NOTIFICATIONS,
                    1,
                    mCurrentUserId) != 0;
            final int dpmFlags = mDevicePolicyManager.getKeyguardDisabledFeatures(
                    null /* admin */, mCurrentUserId);
            allowedByDpm = (dpmFlags
                    & KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) == 0;
        }

        final boolean oldValue = mShowLockscreenNotifications;
        setShowLockscreenNotifications(show && allowedByDpm);
@@ -600,7 +551,6 @@ public class NotificationLockscreenUserManagerImpl implements
     * when the lockscreen is in "public" (secure & locked) mode?
     */
    public boolean userAllowsPrivateNotificationsInPublic(int userHandle) {
        if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
        if (userHandle == USER_ALL) {
            userHandle = mCurrentUserId;
        }
@@ -620,23 +570,6 @@ public class NotificationLockscreenUserManagerImpl implements
            return mUsersUsersAllowingPrivateNotifications.get(userHandle)
                    && mUsersDpcAllowingPrivateNotifications.get(userHandle);
        }
        } else {
            if (userHandle == USER_ALL) {
                return true;
            }

            if (mUsersAllowingPrivateNotifications.indexOfKey(userHandle) < 0) {
                final boolean allowedByUser = 0 != mSecureSettings.getIntForUser(
                        LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, userHandle);
                final boolean allowedByDpm = adminAllowsKeyguardFeature(userHandle,
                        KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
                final boolean allowed = allowedByUser && allowedByDpm;
                mUsersAllowingPrivateNotifications.append(userHandle, allowed);
                return allowed;
            }

            return mUsersAllowingPrivateNotifications.get(userHandle);
        }
    }

    /**
@@ -688,7 +621,6 @@ public class NotificationLockscreenUserManagerImpl implements
     * "public" (secure & locked) mode?
     */
    public boolean userAllowsNotificationsInPublic(int userHandle) {
        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 == USER_ALL || mCurrentManagedProfiles.contains(userHandle)) {
@@ -714,23 +646,6 @@ public class NotificationLockscreenUserManagerImpl implements
                    && mUsersDpcAllowingNotifications.get(userHandle)
                    && mKeyguardAllowingNotifications;
        }
        } else {
            if (isCurrentProfile(userHandle) && userHandle != mCurrentUserId) {
                return true;
            }

            if (mUsersAllowingNotifications.indexOfKey(userHandle) < 0) {
                final boolean allowedByUser = 0 != mSecureSettings.getIntForUser(
                        LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, userHandle);
                final boolean allowedByDpm = adminAllowsKeyguardFeature(userHandle,
                        KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
                final boolean allowedBySystem = mKeyguardManager.getPrivateNotificationsAllowed();
                final boolean allowed = allowedByUser && allowedByDpm && allowedBySystem;
                mUsersAllowingNotifications.append(userHandle, allowed);
                return allowed;
            }
            return mUsersAllowingNotifications.get(userHandle);
        }
    }

    /** @return true if the entry needs redaction when on the lockscreen. */
@@ -766,13 +681,7 @@ public class NotificationLockscreenUserManagerImpl implements
            return true;
        }
        NotificationEntry entry = mCommonNotifCollectionLazy.get().getEntry(key);
        if (mFeatureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
        return entry != null && entry.isChannelVisibilityPrivate();
        } else {
            return entry != null
                    && entry.getRanking().getLockscreenVisibilityOverride()
                    == Notification.VISIBILITY_PRIVATE;
        }
    }

    @SuppressLint("MissingPermission")
+4 −8
Original line number Diff line number Diff line
@@ -219,15 +219,11 @@ class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
    }

    private fun isRankingVisibilitySecret(entry: NotificationEntry): Boolean {
        return if (featureFlags.isEnabled(Flags.NOTIF_LS_BACKGROUND_THREAD)) {
        // ranking.lockscreenVisibilityOverride contains possibly out of date DPC and Setting
        // info, and NotificationLockscreenUserManagerImpl is already listening for updates
        // to those
            entry.ranking.channel != null && entry.ranking.channel.lockscreenVisibility ==
        return entry.ranking.channel != null && entry.ranking.channel.lockscreenVisibility ==
                    VISIBILITY_SECRET
        } else {
            entry.ranking.lockscreenVisibilityOverride == VISIBILITY_SECRET
        }
    }

    override fun dump(pw: PrintWriter, args: Array<out String>) = pw.asIndenting().run {
Loading