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
This commit is contained in:
committed by
Iavor-Valentin Iftime
parent
0dddb2d92d
commit
69313c2145
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -147,6 +147,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
|
||||
// the background on first content update just in case it happens to be during a theme change.
|
||||
private boolean mUpdateSelfBackgroundOnUpdate = true;
|
||||
private boolean mIsSnoozed;
|
||||
private boolean mShowSnooze = false;
|
||||
private boolean mIsFaded;
|
||||
private boolean mAnimatePinnedRoundness = false;
|
||||
|
||||
@@ -3728,4 +3729,14 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
|
||||
updateBaseRoundness();
|
||||
}
|
||||
}
|
||||
|
||||
/** Set whether this notification may show a snooze action. */
|
||||
public void setShowSnooze(boolean showSnooze) {
|
||||
mShowSnooze = showSnooze;
|
||||
}
|
||||
|
||||
/** Whether this notification may show a snooze action. */
|
||||
public boolean getShowSnooze() {
|
||||
return mShowSnooze;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.AttributeSet;
|
||||
@@ -1440,11 +1439,9 @@ public class NotificationContentView extends FrameLayout implements Notification
|
||||
if (snoozeButton == null || actionContainer == null) {
|
||||
return;
|
||||
}
|
||||
final boolean showSnooze = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.SHOW_NOTIFICATION_SNOOZE, 0) == 1;
|
||||
// Notification.Builder can 'disable' the snooze button to prevent it from being shown here
|
||||
boolean snoozeDisabled = !snoozeButton.isEnabled();
|
||||
if (!showSnooze || snoozeDisabled) {
|
||||
if (!mContainingNotification.getShowSnooze() || snoozeDisabled) {
|
||||
snoozeButton.setVisibility(GONE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.systemui.statusbar.notification.row;
|
||||
|
||||
import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE;
|
||||
import static android.view.HapticFeedbackConstants.CLOCK_TICK;
|
||||
|
||||
import static com.android.systemui.SwipeHelper.SWIPED_FAR_ENOUGH_SIZE_FRACTION;
|
||||
@@ -253,9 +252,7 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
|
||||
mLeftMenuItems.clear();
|
||||
mRightMenuItems.clear();
|
||||
|
||||
boolean showSnooze = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
SHOW_NOTIFICATION_SNOOZE, 0) == 1;
|
||||
|
||||
final boolean showSnooze = mParent.getShowSnooze();
|
||||
// Construct the menu items based on the notification
|
||||
if (showSnooze) {
|
||||
// Only show snooze for non-foreground notifications, and if the setting is on
|
||||
|
||||
@@ -41,6 +41,7 @@ import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.internal.statusbar.IStatusBarService;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
|
||||
import com.android.systemui.statusbar.RankingBuilder;
|
||||
import com.android.systemui.statusbar.notification.collection.GroupEntry;
|
||||
@@ -103,6 +104,7 @@ public class PreparationCoordinatorTest extends SysuiTestCase {
|
||||
@Mock private SecureSettings mSecureSettings;
|
||||
@Spy private FakeNotifInflater mNotifInflater = new FakeNotifInflater();
|
||||
private final SectionStyleProvider mSectionStyleProvider = new SectionStyleProvider();
|
||||
@Mock private UserTracker mUserTracker;
|
||||
|
||||
private NotifUiAdjustmentProvider mAdjustmentProvider;
|
||||
|
||||
@@ -118,7 +120,8 @@ public class PreparationCoordinatorTest extends SysuiTestCase {
|
||||
mHandler,
|
||||
mSecureSettings,
|
||||
mLockscreenUserManager,
|
||||
mSectionStyleProvider);
|
||||
mSectionStyleProvider,
|
||||
mUserTracker);
|
||||
mEntry = getNotificationEntryBuilder().setParent(ROOT_ENTRY).build();
|
||||
mInflationError = new Exception(TEST_MESSAGE);
|
||||
mErrorManager = new NotifInflationErrorManager();
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.testing.AndroidTestingRunner
|
||||
import android.testing.TestableLooper.RunWithLooper
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.systemui.SysuiTestCase
|
||||
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.NotificationEntryBuilder
|
||||
@@ -53,6 +54,7 @@ class NotifUiAdjustmentProviderTest : SysuiTestCase() {
|
||||
private val secureSettings: SecureSettings = mock()
|
||||
private val uri = FakeSettings().getUriFor(SHOW_NOTIFICATION_SNOOZE)
|
||||
private val dirtyListener: Runnable = mock()
|
||||
private val userTracker: UserTracker = mock()
|
||||
|
||||
private val section = NotifSection(mock(), 0)
|
||||
private val entry = NotificationEntryBuilder()
|
||||
@@ -67,13 +69,14 @@ class NotifUiAdjustmentProviderTest : SysuiTestCase() {
|
||||
secureSettings,
|
||||
lockscreenUserManager,
|
||||
sectionStyleProvider,
|
||||
userTracker
|
||||
)
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
verifyNoMoreInteractions(secureSettings)
|
||||
adjustmentProvider.addDirtyListener(dirtyListener)
|
||||
verify(secureSettings).getInt(eq(SHOW_NOTIFICATION_SNOOZE), any())
|
||||
verify(secureSettings).getIntForUser(eq(SHOW_NOTIFICATION_SNOOZE), any(), any())
|
||||
contentObserver = withArgCaptor {
|
||||
verify(secureSettings).registerContentObserverForUser(
|
||||
eq(SHOW_NOTIFICATION_SNOOZE), capture(), any()
|
||||
@@ -105,18 +108,20 @@ class NotifUiAdjustmentProviderTest : SysuiTestCase() {
|
||||
fun onChangeWillQueryThenNotifyDirty() {
|
||||
contentObserver.onChange(false, listOf(uri), 0, 0)
|
||||
with(inOrder(secureSettings, dirtyListener)) {
|
||||
verify(secureSettings).getInt(eq(SHOW_NOTIFICATION_SNOOZE), any())
|
||||
verify(secureSettings).getIntForUser(eq(SHOW_NOTIFICATION_SNOOZE), any(), any())
|
||||
verify(dirtyListener).run()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun changingSnoozeChangesProvidedAdjustment() {
|
||||
whenever(secureSettings.getInt(eq(SHOW_NOTIFICATION_SNOOZE), any())).thenReturn(0)
|
||||
whenever(secureSettings.getIntForUser(eq(SHOW_NOTIFICATION_SNOOZE), any(), any()))
|
||||
.thenReturn(0)
|
||||
val original = adjustmentProvider.calculateAdjustment(entry)
|
||||
assertThat(original.isSnoozeEnabled).isFalse()
|
||||
|
||||
whenever(secureSettings.getInt(eq(SHOW_NOTIFICATION_SNOOZE), any())).thenReturn(1)
|
||||
whenever(secureSettings.getIntForUser(eq(SHOW_NOTIFICATION_SNOOZE), any(), any()))
|
||||
.thenReturn(1)
|
||||
contentObserver.onChange(false, listOf(uri), 0, 0)
|
||||
val withSnoozing = adjustmentProvider.calculateAdjustment(entry)
|
||||
assertThat(withSnoozing.isSnoozeEnabled).isTrue()
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.android.systemui.statusbar.notification.row;
|
||||
|
||||
import static android.provider.Settings.Global.SHOW_NEW_NOTIF_DISMISS;
|
||||
import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE;
|
||||
import static android.view.HapticFeedbackConstants.CLOCK_TICK;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
@@ -100,7 +99,7 @@ public class NotificationMenuRowTest extends LeakCheckedTest {
|
||||
|
||||
@Test
|
||||
public void testNoAppOpsInSlowSwipe() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, 0);
|
||||
when(mRow.getShowSnooze()).thenReturn(false);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), SHOW_NEW_NOTIF_DISMISS, 0);
|
||||
|
||||
NotificationMenuRow row = new NotificationMenuRow(mContext, mPeopleNotificationIdentifier);
|
||||
@@ -113,7 +112,7 @@ public class NotificationMenuRowTest extends LeakCheckedTest {
|
||||
|
||||
@Test
|
||||
public void testNoSnoozeInSlowSwipe() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, 0);
|
||||
when(mRow.getShowSnooze()).thenReturn(false);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), SHOW_NEW_NOTIF_DISMISS, 0);
|
||||
|
||||
NotificationMenuRow row = new NotificationMenuRow(mContext, mPeopleNotificationIdentifier);
|
||||
@@ -126,7 +125,7 @@ public class NotificationMenuRowTest extends LeakCheckedTest {
|
||||
|
||||
@Test
|
||||
public void testSnoozeInSlowSwipe() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, 1);
|
||||
when(mRow.getShowSnooze()).thenReturn(true);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), SHOW_NEW_NOTIF_DISMISS, 0);
|
||||
|
||||
NotificationMenuRow row = new NotificationMenuRow(mContext, mPeopleNotificationIdentifier);
|
||||
@@ -139,7 +138,7 @@ public class NotificationMenuRowTest extends LeakCheckedTest {
|
||||
|
||||
@Test
|
||||
public void testSlowSwipe_newDismiss() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, 1);
|
||||
when(mRow.getShowSnooze()).thenReturn(true);
|
||||
Settings.Global.putInt(mContext.getContentResolver(), SHOW_NEW_NOTIF_DISMISS, 1);
|
||||
|
||||
NotificationMenuRow row = new NotificationMenuRow(mContext, mPeopleNotificationIdentifier);
|
||||
|
||||
Reference in New Issue
Block a user