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

Commit 69313c21 authored by Valentin Iftime's avatar Valentin Iftime Committed by Iavor-Valentin Iftime
Browse files

Get notification snoozing setting for current user

 Sync the snooze setting from a SettingsObserver and propagate to ExpandableNotificationRow.

Test: atest NotifUiAdjustmentProviderTest
atest NotificationMenuRowTest
atest NotificationSnoozeTest

Bug: 236819881
Change-Id: Ifae99461288e53dc4cc766a64797b2c0e187bc66
parent 0dddb2d9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -5754,8 +5754,8 @@ public class Notification implements Parcelable
        private boolean isSnoozeSettingEnabled() {
            try {
                return Settings.Secure.getInt(mContext.getContentResolver(),
                    Settings.Secure.SHOW_NOTIFICATION_SNOOZE, 0) == 1;
                return Settings.Secure.getIntForUser(mContext.getContentResolver(),
                    Settings.Secure.SHOW_NOTIFICATION_SNOOZE, 0, UserHandle.USER_CURRENT) == 1;
            } catch (SecurityException ex) {
                // Most 3p apps can't access this snooze setting, so their NotificationListeners
                // would be unable to create notification views if we propagated this exception.
+2 −1
Original line number Diff line number Diff line
@@ -359,7 +359,8 @@ public class PreparationCoordinator implements Coordinator {
    }

    NotifInflater.Params getInflaterParams(NotifUiAdjustment adjustment, String reason) {
        return new NotifInflater.Params(adjustment.isMinimized(), reason);
        return new NotifInflater.Params(adjustment.isMinimized(), reason,
                adjustment.isSnoozeEnabled());
    }

    private void abortInflation(NotificationEntry entry, String reason) {
+1 −1
Original line number Diff line number Diff line
@@ -61,5 +61,5 @@ interface NotifInflater {
    /**
     * A class holding parameters used when inflating the notification row
     */
    class Params(val isLowPriority: Boolean, val reason: String)
    class Params(val isLowPriority: Boolean, val reason: String, val showSnooze: Boolean)
}
+20 −2
Original line number Diff line number Diff line
@@ -16,12 +16,15 @@

package com.android.systemui.statusbar.notification.collection.inflation

import android.content.Context
import android.database.ContentObserver
import android.os.Handler
import android.os.HandlerExecutor
import android.os.UserHandle
import android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.settings.UserTracker
import com.android.systemui.statusbar.NotificationLockscreenUserManager
import com.android.systemui.statusbar.notification.collection.GroupEntry
import com.android.systemui.statusbar.notification.collection.NotificationEntry
@@ -39,11 +42,25 @@ class NotifUiAdjustmentProvider @Inject constructor(
    @Main private val handler: Handler,
    private val secureSettings: SecureSettings,
    private val lockscreenUserManager: NotificationLockscreenUserManager,
    private val sectionStyleProvider: SectionStyleProvider
    private val sectionStyleProvider: SectionStyleProvider,
    private val userTracker: UserTracker
) {
    private val dirtyListeners = ListenerSet<Runnable>()
    private var isSnoozeEnabled = false

    /**
     *  Update the snooze enabled value on user switch
     */
    private val userTrackerCallback = object : UserTracker.Callback {
        override fun onUserChanged(newUser: Int, userContext: Context) {
            updateSnoozeEnabled()
        }
    }

    init {
        userTracker.addCallback(userTrackerCallback, HandlerExecutor(handler))
    }

    fun addDirtyListener(listener: Runnable) {
        if (dirtyListeners.isEmpty()) {
            lockscreenUserManager.addNotificationStateChangedListener(notifStateChangedListener)
@@ -78,7 +95,8 @@ class NotifUiAdjustmentProvider @Inject constructor(
    }

    private fun updateSnoozeEnabled() {
        isSnoozeEnabled = secureSettings.getInt(SHOW_NOTIFICATION_SNOOZE, 0) == 1
        isSnoozeEnabled =
            secureSettings.getIntForUser(SHOW_NOTIFICATION_SNOOZE, 0, UserHandle.USER_CURRENT) == 1
    }

    private fun isEntryMinimized(entry: NotificationEntry): Boolean {
+3 −0
Original line number Diff line number Diff line
@@ -212,6 +212,9 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
                mMessagingUtil.isImportantMessaging(entry.getSbn(), entry.getImportance());
        final boolean isLowPriority = inflaterParams.isLowPriority();

        // Set show snooze action
        row.setShowSnooze(inflaterParams.getShowSnooze());

        RowContentBindParams params = mRowContentBindStage.getStageParams(entry);
        params.requireContentViews(FLAG_CONTENT_VIEW_CONTRACTED);
        params.requireContentViews(FLAG_CONTENT_VIEW_EXPANDED);
Loading