diff options
18 files changed, 1350 insertions, 710 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index d7b9a2c46c9b..18f16ba31c0c 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -3910,6 +3910,13 @@ public class Notification implements Parcelable /** * @hide */ + public boolean hasAppProvidedWhen() { + return when != 0 && when != creationTime; + } + + /** + * @hide + */ @UnsupportedAppUsage public boolean isGroupSummary() { return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; diff --git a/core/java/android/app/notification.aconfig b/core/java/android/app/notification.aconfig index 29ffdc5f4a55..a2cf672c1f30 100644 --- a/core/java/android/app/notification.aconfig +++ b/core/java/android/app/notification.aconfig @@ -81,4 +81,11 @@ flag { metadata { purpose: PURPOSE_BUGFIX } +} + +flag { + name: "sort_section_by_time" + namespace: "systemui" + description: "Changes notification sort order to be by time within a section" + bug: "330193582" }
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/SortBySectionTimeFlag.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/SortBySectionTimeFlag.kt new file mode 100644 index 000000000000..09cb31043606 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/SortBySectionTimeFlag.kt @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.systemui.statusbar.notification.collection + +import android.app.Flags; +import com.android.systemui.flags.FlagToken +import com.android.systemui.flags.RefactorFlagUtils + +/** + * Helper for android.app.Flags.FLAG_SORT_BY_SECTION_TIME + */ +@Suppress("NOTHING_TO_INLINE") +object SortBySectionTimeFlag { + const val FLAG_NAME = Flags.FLAG_SORT_SECTION_BY_TIME + + /** A token used for dependency declaration */ + val token: FlagToken + get() = FlagToken(FLAG_NAME, isEnabled) + + /** Are sections sorted by time? */ + @JvmStatic + inline val isEnabled + get() = Flags.sortSectionByTime() + + /** + * Called to ensure code is only run when the flag is enabled. This protects users from the + * unintended behaviors caused by accidentally running new logic, while also crashing on an eng + * build to ensure that the refactor author catches issues in testing. + */ + @JvmStatic + inline fun isUnexpectedlyInLegacyMode() = + RefactorFlagUtils.isUnexpectedlyInLegacyMode(isEnabled, FLAG_NAME) + + /** + * Called to ensure code is only run when the flag is disabled. This will throw an exception if + * the flag is enabled to ensure that the refactor author catches issues in testing. + */ + @JvmStatic + inline fun assertInLegacyMode() = RefactorFlagUtils.assertInLegacyMode(isEnabled, FLAG_NAME) +}
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ConversationCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ConversationCoordinator.kt index 1631ae28bf5e..3d0fd89dce88 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ConversationCoordinator.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ConversationCoordinator.kt @@ -19,6 +19,7 @@ package com.android.systemui.statusbar.notification.collection.coordinator import com.android.systemui.statusbar.notification.collection.ListEntry import com.android.systemui.statusbar.notification.collection.NotifPipeline import com.android.systemui.statusbar.notification.collection.NotificationEntry +import com.android.systemui.statusbar.notification.collection.SortBySectionTimeFlag import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeRenderListListener import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifComparator @@ -80,11 +81,20 @@ class ConversationCoordinator @Inject constructor( } } + // TODO(b/330193582): Rename to just "People" val peopleAlertingSectioner = object : NotifSectioner("People(alerting)", BUCKET_PEOPLE) { - override fun isInSection(entry: ListEntry): Boolean = - highPriorityProvider.isHighPriorityConversation(entry) + override fun isInSection(entry: ListEntry): Boolean { + if (SortBySectionTimeFlag.isEnabled) { + return highPriorityProvider.isHighPriorityConversation(entry) + || isConversation(entry) + } else { + return highPriorityProvider.isHighPriorityConversation(entry) + } + } - override fun getComparator(): NotifComparator = notifComparator + override fun getComparator(): NotifComparator? { + return if (SortBySectionTimeFlag.isEnabled) null else notifComparator + } override fun getHeaderNodeController(): NodeController? = conversationHeaderNodeController } @@ -92,11 +102,20 @@ class ConversationCoordinator @Inject constructor( val peopleSilentSectioner = object : NotifSectioner("People(silent)", BUCKET_PEOPLE) { // Because the peopleAlertingSectioner is above this one, it will claim all conversations that are alerting. // All remaining conversations must be silent. - override fun isInSection(entry: ListEntry): Boolean = isConversation(entry) + override fun isInSection(entry: ListEntry): Boolean { + SortBySectionTimeFlag.assertInLegacyMode() + return isConversation(entry) + } - override fun getComparator(): NotifComparator = notifComparator + override fun getComparator(): NotifComparator { + SortBySectionTimeFlag.assertInLegacyMode() + return notifComparator + } - override fun getHeaderNodeController(): NodeController? = conversationHeaderNodeController + override fun getHeaderNodeController(): NodeController? { + SortBySectionTimeFlag.assertInLegacyMode() + return conversationHeaderNodeController + } } override fun attach(pipeline: NotifPipeline) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt index b9d1dde82eeb..36c12a719570 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/NotifCoordinators.kt @@ -20,6 +20,7 @@ import com.android.systemui.flags.Flags.LOCKSCREEN_WALLPAPER_DREAM_ENABLED import com.android.systemui.statusbar.notification.collection.NotifPipeline import com.android.systemui.statusbar.notification.collection.PipelineDumpable import com.android.systemui.statusbar.notification.collection.PipelineDumper +import com.android.systemui.statusbar.notification.collection.SortBySectionTimeFlag import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner import com.android.systemui.statusbar.notification.collection.provider.SectionStyleProvider @@ -114,17 +115,26 @@ class NotifCoordinatorsImpl @Inject constructor( mOrderedSections.add(headsUpCoordinator.sectioner) // HeadsUp mOrderedSections.add(colorizedFgsCoordinator.sectioner) // ForegroundService mOrderedSections.add(conversationCoordinator.peopleAlertingSectioner) // People Alerting - mOrderedSections.add(conversationCoordinator.peopleSilentSectioner) // People Silent + if (!SortBySectionTimeFlag.isEnabled) { + mOrderedSections.add(conversationCoordinator.peopleSilentSectioner) // People Silent + } mOrderedSections.add(rankingCoordinator.alertingSectioner) // Alerting mOrderedSections.add(rankingCoordinator.silentSectioner) // Silent mOrderedSections.add(rankingCoordinator.minimizedSectioner) // Minimized sectionStyleProvider.setMinimizedSections(setOf(rankingCoordinator.minimizedSectioner)) - sectionStyleProvider.setSilentSections(listOf( - conversationCoordinator.peopleSilentSectioner, - rankingCoordinator.silentSectioner, - rankingCoordinator.minimizedSectioner, - )) + if (SortBySectionTimeFlag.isEnabled) { + sectionStyleProvider.setSilentSections(listOf( + rankingCoordinator.silentSectioner, + rankingCoordinator.minimizedSectioner, + )) + } else { + sectionStyleProvider.setSilentSections(listOf( + conversationCoordinator.peopleSilentSectioner, + rankingCoordinator.silentSectioner, + rankingCoordinator.minimizedSectioner, + )) + } } /** diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/SectionStyleProvider.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/SectionStyleProvider.kt index 5a3edf4ac8fd..ea9f29521459 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/SectionStyleProvider.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/SectionStyleProvider.kt @@ -18,8 +18,10 @@ package com.android.systemui.statusbar.notification.collection.provider import com.android.systemui.dagger.SysUISingleton import com.android.systemui.statusbar.notification.collection.ListEntry +import com.android.systemui.statusbar.notification.collection.SortBySectionTimeFlag import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner +import com.android.systemui.statusbar.notification.stack.BUCKET_PEOPLE import javax.inject.Inject /** @@ -27,7 +29,8 @@ import javax.inject.Inject * NOTE: This class exists to avoid putting metadata like "isMinimized" on the NotifSection */ @SysUISingleton -class SectionStyleProvider @Inject constructor() { +class SectionStyleProvider @Inject constructor( + private val highPriorityProvider: HighPriorityProvider) { private lateinit var silentSections: Set<NotifSectioner> private lateinit var lowPrioritySections: Set<NotifSectioner> @@ -76,6 +79,13 @@ class SectionStyleProvider @Inject constructor() { @JvmOverloads fun isSilent(entry: ListEntry, ifNotInSection: Boolean = true): Boolean { val section = entry.section ?: return ifNotInSection - return isSilentSection(section) + if (SortBySectionTimeFlag.isEnabled) { + if (entry.section?.bucket == BUCKET_PEOPLE) { + return !highPriorityProvider.isHighPriorityConversation(entry) + } + return isSilentSection(section) + } else { + return isSilentSection(section) + } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/SectionStyleProviderTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/SectionStyleProviderTest.kt new file mode 100644 index 000000000000..ab55a7d650c6 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/SectionStyleProviderTest.kt @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.systemui.statusbar.notification.collection + +import android.app.Flags +import android.os.UserHandle +import android.platform.test.annotations.EnableFlags +import android.platform.test.flag.junit.SetFlagsRule +import android.service.notification.StatusBarNotification +import android.testing.AndroidTestingRunner +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection +import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner +import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider +import com.android.systemui.statusbar.notification.collection.provider.SectionStyleProvider +import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow +import com.android.systemui.statusbar.notification.stack.BUCKET_ALERTING +import com.android.systemui.statusbar.notification.stack.BUCKET_FOREGROUND_SERVICE +import com.android.systemui.statusbar.notification.stack.BUCKET_PEOPLE +import com.android.systemui.statusbar.notification.stack.BUCKET_SILENT +import com.android.systemui.statusbar.notification.stack.BUCKET_UNKNOWN +import com.android.systemui.util.mockito.any +import com.android.systemui.util.mockito.mock +import com.google.common.collect.ImmutableList +import com.google.common.truth.Truth.assertThat +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito.verify +import org.mockito.MockitoAnnotations +import org.mockito.Mockito.`when` as whenever + +@SmallTest +@RunWith(AndroidTestingRunner::class) +class SectionStyleProviderTest : SysuiTestCase() { + + @Rule @JvmField public val setFlagsRule = SetFlagsRule() + + @Mock private lateinit var highPriorityProvider: HighPriorityProvider + + @Mock private lateinit var peopleMixedSectioner : NotifSectioner + @Mock private lateinit var allSilentSectioner : NotifSectioner + @Mock private lateinit var allAlertingSectioner : NotifSectioner + + private lateinit var sectionStyleProvider: SectionStyleProvider + + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + sectionStyleProvider = SectionStyleProvider(highPriorityProvider) + + whenever(peopleMixedSectioner.bucket).thenReturn(BUCKET_PEOPLE); + whenever(allSilentSectioner.bucket).thenReturn(BUCKET_SILENT); + whenever(allAlertingSectioner.bucket).thenReturn(BUCKET_ALERTING); + + sectionStyleProvider.setSilentSections(ImmutableList.of(allSilentSectioner)) + } + + @Test + fun testIsSilent_silentSection() { + assertThat(sectionStyleProvider.isSilent(fakeNotification(allSilentSectioner))).isTrue() + } + + @Test + fun testIsSilent_alertingSection() { + val listEntry = fakeNotification(allAlertingSectioner) + // this line should not matter for any non-people sections + whenever(highPriorityProvider.isHighPriorityConversation(listEntry)).thenReturn(true) + + assertThat(sectionStyleProvider.isSilent(fakeNotification(allAlertingSectioner))).isFalse() + } + + @Test + @EnableFlags(Flags.FLAG_SORT_SECTION_BY_TIME) + fun testIsSilent_silentPeople() { + val listEntry = fakeNotification(peopleMixedSectioner) + whenever(highPriorityProvider.isHighPriorityConversation(listEntry)).thenReturn(false) + assertThat(sectionStyleProvider.isSilent(listEntry)).isTrue() + } + + @Test + fun testIsSilent_alertingPeople() { + val listEntry = fakeNotification(peopleMixedSectioner) + whenever(highPriorityProvider.isHighPriorityConversation(listEntry)).thenReturn(true) + + assertThat(sectionStyleProvider.isSilent(listEntry)).isFalse() + } + + private fun fakeNotification(inputSectioner: NotifSectioner): ListEntry { + val mockUserHandle = + mock<UserHandle>().apply { whenever(identifier).thenReturn(0) } + val mockSbn: StatusBarNotification = + mock<StatusBarNotification>().apply { whenever(user).thenReturn(mockUserHandle) } + val mockRow: ExpandableNotificationRow = mock<ExpandableNotificationRow>() + val mockEntry = mock<NotificationEntry>().apply { + whenever(sbn).thenReturn(mockSbn) + whenever(row).thenReturn(mockRow) + } + whenever(mockEntry.rowExists()).thenReturn(true) + return object : ListEntry("key", 0) { + override fun getRepresentativeEntry(): NotificationEntry = mockEntry + override fun getSection(): NotifSection? = NotifSection(inputSectioner, 1) + } + } +}
\ No newline at end of file diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/ConversationCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/ConversationCoordinatorTest.kt index 36f643ab9cca..c5d7e1f490ee 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/ConversationCoordinatorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/ConversationCoordinatorTest.kt @@ -16,10 +16,14 @@ package com.android.systemui.statusbar.notification.collection.coordinator +import android.app.Flags import android.app.NotificationChannel import android.app.NotificationManager.IMPORTANCE_DEFAULT import android.app.NotificationManager.IMPORTANCE_HIGH import android.app.NotificationManager.IMPORTANCE_LOW +import android.platform.test.annotations.DisableFlags +import android.platform.test.annotations.EnableFlags +import android.platform.test.flag.junit.SetFlagsRule import android.testing.AndroidTestingRunner import android.testing.TestableLooper import androidx.test.filters.SmallTest @@ -29,6 +33,7 @@ import com.android.systemui.statusbar.notification.collection.GroupEntryBuilder import com.android.systemui.statusbar.notification.collection.NotifPipeline import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder +import com.android.systemui.statusbar.notification.collection.SortBySectionTimeFlag import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeRenderListListener import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifComparator @@ -48,12 +53,13 @@ import com.google.common.truth.Truth.assertThat import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Before +import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.verify -import org.mockito.Mockito.`when` as whenever import org.mockito.MockitoAnnotations +import org.mockito.Mockito.`when` as whenever @SmallTest @RunWith(AndroidTestingRunner::class) @@ -77,6 +83,8 @@ class ConversationCoordinatorTest : SysuiTestCase() { private lateinit var coordinator: ConversationCoordinator + @Rule @JvmField public val setFlagsRule = SetFlagsRule() + @Before fun setUp() { MockitoAnnotations.initMocks(this) @@ -99,7 +107,8 @@ class ConversationCoordinatorTest : SysuiTestCase() { peopleAlertingSectioner = coordinator.peopleAlertingSectioner peopleSilentSectioner = coordinator.peopleSilentSectioner - peopleComparator = peopleAlertingSectioner.comparator!! + if (!SortBySectionTimeFlag.isEnabled) + peopleComparator = peopleAlertingSectioner.comparator!! entry = NotificationEntryBuilder().setChannel(channel).build() @@ -150,6 +159,20 @@ class ConversationCoordinatorTest : SysuiTestCase() { } @Test + @EnableFlags(Flags.FLAG_SORT_SECTION_BY_TIME) + fun testInAlertingPeopleSectionWhenTheImportanceIsLowerThanDefault() { + // GIVEN + val silentEntry = + NotificationEntryBuilder().setChannel(channel).setImportance(IMPORTANCE_LOW).build() + whenever(peopleNotificationIdentifier.getPeopleNotificationType(silentEntry)) + .thenReturn(TYPE_PERSON) + + // THEN put silent people notifications in alerting section + assertThat(peopleAlertingSectioner.isInSection(silentEntry)).isTrue() + } + + @Test + @DisableFlags(Flags.FLAG_SORT_SECTION_BY_TIME) fun testInSilentPeopleSectionWhenTheImportanceIsLowerThanDefault() { // GIVEN val silentEntry = @@ -178,7 +201,8 @@ class ConversationCoordinatorTest : SysuiTestCase() { .thenReturn(TYPE_NON_PERSON) // THEN - only put people notification either silent or alerting - assertThat(peopleSilentSectioner.isInSection(entry)).isFalse() + if (!SortBySectionTimeFlag.isEnabled) + assertThat(peopleSilentSectioner.isInSection(entry)).isFalse() assertThat(peopleAlertingSectioner.isInSection(importantEntry)).isFalse() } @@ -207,6 +231,7 @@ class ConversationCoordinatorTest : SysuiTestCase() { } @Test + @DisableFlags(Flags.FLAG_SORT_SECTION_BY_TIME) fun testComparatorPutsImportantPeopleFirst() { whenever(peopleNotificationIdentifier.getPeopleNotificationType(entryA)) .thenReturn(TYPE_IMPORTANT_PERSON) @@ -218,6 +243,7 @@ class ConversationCoordinatorTest : SysuiTestCase() { } @Test + @DisableFlags(Flags.FLAG_SORT_SECTION_BY_TIME) fun testComparatorEquatesPeopleWithSameType() { whenever(peopleNotificationIdentifier.getPeopleNotificationType(entryA)) .thenReturn(TYPE_PERSON) @@ -227,4 +253,10 @@ class ConversationCoordinatorTest : SysuiTestCase() { // only put people notifications in this section assertThat(peopleComparator.compare(entryA, entryB)).isEqualTo(0) } + + @Test + @EnableFlags(Flags.FLAG_SORT_SECTION_BY_TIME) + fun testNoSecondarySortForConversations() { + assertThat(peopleAlertingSectioner.comparator).isNull() + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/PreparationCoordinatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/PreparationCoordinatorTest.java index 118d27a68c8c..cceaaea672c4 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/PreparationCoordinatorTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/PreparationCoordinatorTest.java @@ -64,6 +64,7 @@ import com.android.systemui.statusbar.notification.collection.listbuilder.OnBefo import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifFilter; import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner; import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener; +import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider; import com.android.systemui.statusbar.notification.collection.provider.SectionStyleProvider; import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager; import com.android.systemui.statusbar.notification.collection.render.NotifViewBarn; @@ -112,7 +113,9 @@ public class PreparationCoordinatorTest extends SysuiTestCase { @Mock private Handler mHandler; @Mock private SecureSettings mSecureSettings; @Spy private FakeNotifInflater mNotifInflater = new FakeNotifInflater(); - private final SectionStyleProvider mSectionStyleProvider = new SectionStyleProvider(); + @Mock + HighPriorityProvider mHighPriorityProvider; + private SectionStyleProvider mSectionStyleProvider; @Mock private UserTracker mUserTracker; @Mock private GroupMembershipManager mGroupMembershipManager; @@ -126,6 +129,7 @@ public class PreparationCoordinatorTest extends SysuiTestCase { @Before public void setUp() { MockitoAnnotations.initMocks(this); + mSectionStyleProvider = new SectionStyleProvider(mHighPriorityProvider); mAdjustmentProvider = new NotifUiAdjustmentProvider( mHandler, mSecureSettings, diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 493c4a0e749b..a30424ef9271 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -142,7 +142,6 @@ import static android.service.notification.NotificationListenerService.TRIM_LIGH import static android.view.contentprotection.flags.Flags.rapidClearNotificationsByListenerAppOpEnabled; import static android.view.WindowManager.LayoutParams.TYPE_TOAST; -import static android.app.Flags.updateRankingTime; import static com.android.internal.util.FrameworkStatsLog.DND_MODE_RULE; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_GROUP_PREFERENCES; import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_CHANNEL_PREFERENCES; @@ -8499,7 +8498,7 @@ public class NotificationManagerService extends SystemService { r.isUpdate = true; final boolean isInterruptive = isVisuallyInterruptive(old, r); r.setTextChanged(isInterruptive); - if (updateRankingTime()) { + if (android.app.Flags.updateRankingTime()) { if (isInterruptive) { r.resetRankingTime(); } @@ -8644,14 +8643,26 @@ public class NotificationManagerService extends SystemService { return false; } - // Ignore visual interruptions from foreground services because users - // consider them one 'session'. Count them for everything else. - if ((r.getSbn().getNotification().flags & FLAG_FOREGROUND_SERVICE) != 0) { - if (DEBUG_INTERRUPTIVENESS) { - Slog.v(TAG, "INTERRUPTIVENESS: " - + r.getKey() + " is not interruptive: foreground service"); + if (android.app.Flags.updateRankingTime()) { + // Ignore visual interruptions from FGS/UIJs because users + // consider them one 'session'. Count them for everything else. + if (r.getSbn().getNotification().isFgsOrUij()) { + if (DEBUG_INTERRUPTIVENESS) { + Slog.v(TAG, "INTERRUPTIVENESS: " + + r.getKey() + " is not interruptive: FGS/UIJ"); + } + return false; + } + } else { + // Ignore visual interruptions from foreground services because users + // consider them one 'session'. Count them for everything else. + if ((r.getSbn().getNotification().flags & FLAG_FOREGROUND_SERVICE) != 0) { + if (DEBUG_INTERRUPTIVENESS) { + Slog.v(TAG, "INTERRUPTIVENESS: " + + r.getKey() + " is not interruptive: foreground service"); + } + return false; } - return false; } final String oldTitle = String.valueOf(oldN.extras.get(Notification.EXTRA_TITLE)); diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java index 7e58d0af6195..a4464a1cbb14 100644 --- a/services/core/java/com/android/server/notification/NotificationRecord.java +++ b/services/core/java/com/android/server/notification/NotificationRecord.java @@ -1090,7 +1090,7 @@ public final class NotificationRecord { Notification n = getNotification(); // Take developer provided 'when', unless it's in the future. if (updateRankingTime()) { - if (n.when != n.creationTime && n.when <= getSbn().getPostTime()){ + if (n.hasAppProvidedWhen() && n.when <= getSbn().getPostTime()){ return n.when; } } else { diff --git a/services/core/java/com/android/server/notification/NotificationTimeComparator.java b/services/core/java/com/android/server/notification/NotificationTimeComparator.java new file mode 100644 index 000000000000..550c428a6e7c --- /dev/null +++ b/services/core/java/com/android/server/notification/NotificationTimeComparator.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.server.notification; + +import java.util.Comparator; + +/** + * Sorts notifications by stabilised recency. + */ +public class NotificationTimeComparator implements Comparator<NotificationRecord> { + /** + * Sorts by time, with some stability being applied to updates + * + * Time stability logic lives in NotificationRecord. + */ + @Override + public int compare(NotificationRecord left, NotificationRecord right) { + // earliest first + return -1 * Long.compare(left.getRankingTimeMs(), right.getRankingTimeMs()); + } +} diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 773d10b1f076..7b12d8686f0e 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -15,6 +15,8 @@ */ package com.android.server.notification; +import static android.app.Flags.sortSectionByTime; +import static android.app.NotificationManager.IMPORTANCE_MIN; import static android.text.TextUtils.formatSimple; import android.annotation.NonNull; @@ -28,12 +30,13 @@ import android.util.proto.ProtoOutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; public class RankingHelper { private static final String TAG = "RankingHelper"; private final NotificationSignalExtractor[] mSignalExtractors; - private final NotificationComparator mPreliminaryComparator; + private final Comparator mPreliminaryComparator; private final GlobalSortKeyComparator mFinalComparator = new GlobalSortKeyComparator(); private final ArrayMap<String, NotificationRecord> mProxyByGroupTmp = new ArrayMap<>(); @@ -46,7 +49,11 @@ public class RankingHelper { ZenModeHelper zenHelper, NotificationUsageStats usageStats, String[] extractorNames) { mContext = context; mRankingHandler = rankingHandler; - mPreliminaryComparator = new NotificationComparator(mContext); + if (sortSectionByTime()) { + mPreliminaryComparator = new NotificationTimeComparator(); + } else { + mPreliminaryComparator = new NotificationComparator(mContext); + } final int N = extractorNames.length; mSignalExtractors = new NotificationSignalExtractor[N]; @@ -104,9 +111,13 @@ public class RankingHelper { } // Rank each record individually. - // Lock comparator state for consistent compare() results. - synchronized (mPreliminaryComparator.mStateLock) { + if (sortSectionByTime()) { notificationList.sort(mPreliminaryComparator); + } else { + // Lock comparator state for consistent compare() results. + synchronized (((NotificationComparator) mPreliminaryComparator).mStateLock) { + notificationList.sort(mPreliminaryComparator); + } } synchronized (mProxyByGroupTmp) { @@ -114,10 +125,22 @@ public class RankingHelper { for (int i = 0; i < N; i++) { final NotificationRecord record = notificationList.get(i); record.setAuthoritativeRank(i); - final String groupKey = record.getGroupKey(); - NotificationRecord existingProxy = mProxyByGroupTmp.get(groupKey); - if (existingProxy == null) { - mProxyByGroupTmp.put(groupKey, record); + if (sortSectionByTime()) { + final String groupKey = record.getGroupKey(); + NotificationRecord existingProxy = mProxyByGroupTmp.get(groupKey); + // summaries are mostly hidden in systemui - if there is a child notification + // with better information, use its rank + if (existingProxy == null + || (existingProxy.getNotification().isGroupSummary() + && !existingProxy.getNotification().hasAppProvidedWhen())) { + mProxyByGroupTmp.put(groupKey, record); + } + } else { + final String groupKey = record.getGroupKey(); + NotificationRecord existingProxy = mProxyByGroupTmp.get(groupKey); + if (existingProxy == null) { + mProxyByGroupTmp.put(groupKey, record); + } } } // assign global sort key: @@ -142,12 +165,14 @@ public class RankingHelper { } boolean isGroupSummary = record.getNotification().isGroupSummary(); + char intrusiveRank = sortSectionByTime() + ? '2' + : record.isRecentlyIntrusive() && record.getImportance() > IMPORTANCE_MIN + ? '0' : '1'; record.setGlobalSortKey( formatSimple("crtcl=0x%04x:intrsv=%c:grnk=0x%04x:gsmry=%c:%s:rnk=0x%04x", record.getCriticality(), - record.isRecentlyIntrusive() - && record.getImportance() > NotificationManager.IMPORTANCE_MIN - ? '0' : '1', + intrusiveRank, groupProxy.getAuthoritativeRank(), isGroupSummary ? '0' : '1', groupSortKeyPortion, diff --git a/services/tests/uiservicestests/src/com/android/server/UiServiceTestCase.java b/services/tests/uiservicestests/src/com/android/server/UiServiceTestCase.java index 06fc01738967..b3ec2153542a 100644 --- a/services/tests/uiservicestests/src/com/android/server/UiServiceTestCase.java +++ b/services/tests/uiservicestests/src/com/android/server/UiServiceTestCase.java @@ -19,10 +19,13 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; +import android.annotation.UserIdInt; import android.content.Intent; import android.content.pm.PackageManagerInternal; import android.net.Uri; +import android.os.Binder; import android.os.Build; +import android.os.UserHandle; import android.testing.TestableContext; import androidx.test.InstrumentationRegistry; @@ -45,10 +48,20 @@ public class UiServiceTestCase { protected static final String PKG_P = "com.example.p"; protected static final String PKG_R = "com.example.r"; + protected static final int UID_N_MR1 = 10001; + protected static final int UID_O = 10002; + protected static final int UID_P = 10003; + protected static final int UID_R = 10004; + @Rule public TestableContext mContext = spy(new TestableContext(InstrumentationRegistry.getContext(), null)); + protected final int mUid = Binder.getCallingUid(); + protected final @UserIdInt int mUserId = UserHandle.getUserId(mUid); + protected final UserHandle mUser = UserHandle.of(mUserId); + protected final String mPkg = mContext.getPackageName(); + protected TestableContext getContext() { return mContext; } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 39a962d1bba0..87f0773a146b 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -331,9 +331,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setOwner(new ComponentName("pkg", "cls")) .build(); - private final int mUid = Binder.getCallingUid(); - private final @UserIdInt int mUserId = UserHandle.getUserId(mUid); - @ClassRule public static final LimitDevicesRule sLimitDevicesRule = new LimitDevicesRule(); @@ -357,7 +354,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Mock private PermissionHelper mPermissionHelper; private NotificationChannelLoggerFake mLogger = new NotificationChannelLoggerFake(); - private final String PKG = mContext.getPackageName(); private TestableLooper mTestableLooper; @Mock private RankingHelper mRankingHelper; @@ -566,8 +562,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); when(mPackageManagerClient.hasSystemFeature(FEATURE_WATCH)).thenReturn(false); when(mUgmInternal.newUriPermissionOwner(anyString())).thenReturn(mPermOwner); - when(mPackageManager.getPackagesForUid(mUid)).thenReturn(new String[]{PKG}); - when(mPackageManagerClient.getPackagesForUid(anyInt())).thenReturn(new String[]{PKG}); + when(mPackageManager.getPackagesForUid(mUid)).thenReturn(new String[]{mPkg}); + when(mPackageManagerClient.getPackagesForUid(anyInt())).thenReturn(new String[]{mPkg}); when(mAtm.getTaskToShowPermissionDialogOn(anyString(), anyInt())) .thenReturn(INVALID_TASK_ID); mContext.addMockSystemService(AppOpsManager.class, mock(AppOpsManager.class)); @@ -599,7 +595,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mNlf.isPackageAllowed(null)).thenReturn(true); when(mListeners.getNotificationListenerFilter(any())).thenReturn(mNlf); mListener = mListeners.new ManagedServiceInfo( - null, new ComponentName(PKG, "test_class"), + null, new ComponentName(mPkg, "test_class"), mUserId, true, null, 0, 123); ComponentName defaultComponent = ComponentName.unflattenFromString("config/device"); ArraySet<ComponentName> components = new ArraySet<>(); @@ -743,7 +739,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Pretend the shortcut exists List<ShortcutInfo> shortcutInfos = new ArrayList<>(); ShortcutInfo info = mock(ShortcutInfo.class); - when(info.getPackage()).thenReturn(PKG); + when(info.getPackage()).thenReturn(mPkg); when(info.getId()).thenReturn(VALID_CONVO_SHORTCUT_ID); when(info.getUserId()).thenReturn(USER_SYSTEM); when(info.isLongLived()).thenReturn(true); @@ -765,16 +761,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mBinderService = mService.getBinderService(); mInternalService = mService.getInternalService(); - mBinderService.createNotificationChannels(PKG, new ParceledListSlice( + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice( Arrays.asList(mTestNotificationChannel, mSilentChannel))); mBinderService.createNotificationChannels(PKG_P, new ParceledListSlice( Arrays.asList(mTestNotificationChannel, mSilentChannel))); mBinderService.createNotificationChannels(PKG_O, new ParceledListSlice( Arrays.asList(mTestNotificationChannel, mSilentChannel))); assertNotNull(mBinderService.getNotificationChannel( - PKG, mContext.getUserId(), PKG, TEST_CHANNEL_ID)); + mPkg, mContext.getUserId(), mPkg, TEST_CHANNEL_ID)); assertNotNull(mBinderService.getNotificationChannel( - PKG, mContext.getUserId(), PKG, mSilentChannel.getId())); + mPkg, mContext.getUserId(), mPkg, mSilentChannel.getId())); clearInvocations(mRankingHandler); when(mPermissionHelper.hasPermission(mUid)).thenReturn(true); @@ -976,7 +972,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setSmallIcon(android.R.drawable.sym_def_app_icon) .setGroup(groupKey) .setGroupSummary(isSummary); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, id, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, id, tag, mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); return new NotificationRecord(mContext, sbn, channel); @@ -998,14 +994,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { if (extender != null) { nb.extend(extender); } - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); return new NotificationRecord(mContext, sbn, channel); } private NotificationRecord generateNotificationRecord(NotificationChannel channel, long postTime) { - final StatusBarNotification sbn = generateSbn(PKG, mUid, postTime, mUserId); + final StatusBarNotification sbn = generateSbn(mPkg, mUid, postTime, mUserId); return new NotificationRecord(mContext, sbn, channel); } @@ -1026,7 +1022,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification.Builder nb = new Notification.Builder(mContext, channel.getId()) .setContentTitle(title) .setSmallIcon(android.R.drawable.sym_def_app_icon); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, id, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, id, "tag", mUid, 0, nb.build(), new UserHandle(userId), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, channel); return r; @@ -1046,7 +1042,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { tag = "tag"; } Notification.Builder nb = getMessageStyleNotifBuilder(addMetadata, groupKey, isSummary); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, id, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, id, tag, mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); return new NotificationRecord(mContext, sbn, channel); @@ -1058,7 +1054,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setContentText(REDACTED_TEXT); - return new StatusBarNotification(PKG, PKG, id, "tag", mUid, 0, + return new StatusBarNotification(mPkg, mPkg, id, "tag", mUid, 0, nb.build(), new UserHandle(userId), null, 0); } @@ -1180,13 +1176,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord nrBubble = generateMessageBubbleNotifRecord(true /* addMetadata */, mTestNotificationChannel, 1 /* id */, "tag", groupKey, false /* isSummary */); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nrBubble.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nrBubble.getSbn().getTag(), nrBubble.getSbn().getId(), nrBubble.getSbn().getNotification(), nrBubble.getSbn().getUserId()); waitForIdle(); // Make sure we are a bubble - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsAfter.length); assertTrue((notifsAfter[0].getNotification().flags & FLAG_BUBBLE) != 0); @@ -1194,12 +1190,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord nrPlain = generateMessageBubbleNotifRecord(false /* addMetadata */, mTestNotificationChannel, 2 /* id */, "tag", groupKey, false /* isSummary */); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nrPlain.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nrPlain.getSbn().getTag(), nrPlain.getSbn().getId(), nrPlain.getSbn().getNotification(), nrPlain.getSbn().getUserId()); waitForIdle(); - notifsAfter = mBinderService.getActiveNotifications(PKG); + notifsAfter = mBinderService.getActiveNotifications(mPkg); assertEquals(2, notifsAfter.length); // Summary notification for both of those @@ -1209,12 +1205,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { if (summaryAutoCancel) { nrSummary.getNotification().flags |= FLAG_AUTO_CANCEL; } - mBinderService.enqueueNotificationWithTag(PKG, PKG, nrSummary.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nrSummary.getSbn().getTag(), nrSummary.getSbn().getId(), nrSummary.getSbn().getNotification(), nrSummary.getSbn().getUserId()); waitForIdle(); - notifsAfter = mBinderService.getActiveNotifications(PKG); + notifsAfter = mBinderService.getActiveNotifications(mPkg); assertEquals(3, notifsAfter.length); return nrSummary; @@ -1229,7 +1225,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setSmallIcon(android.R.drawable.sym_def_app_icon) .setTimeoutAfter(1); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, channel); @@ -1269,17 +1265,17 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testCreateNotificationChannels_SingleChannel() throws Exception { final NotificationChannel channel = new NotificationChannel("id", "name", IMPORTANCE_DEFAULT); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(channel))); final NotificationChannel createdChannel = - mBinderService.getNotificationChannel(PKG, mContext.getUserId(), PKG, "id"); + mBinderService.getNotificationChannel(mPkg, mContext.getUserId(), mPkg, "id"); assertTrue(createdChannel != null); } @Test public void testCreateNotificationChannels_NullChannelThrowsException() throws Exception { try { - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList((Object[])null))); fail("Exception should be thrown immediately."); } catch (NullPointerException e) { @@ -1304,11 +1300,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testCreateNotificationChannels_SecondChannelWithFgndTaskDoesntStartPermDialog() throws Exception { when(mAtm.getTaskToShowPermissionDialogOn(anyString(), anyInt())).thenReturn(TEST_TASK_ID); - assertTrue(mBinderService.getNumNotificationChannelsForPackage(PKG, mUid, true) > 0); + assertTrue(mBinderService.getNumNotificationChannelsForPackage(mPkg, mUid, true) > 0); final NotificationChannel channel = new NotificationChannel("id", "name", IMPORTANCE_DEFAULT); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(channel))); verify(mWorkerHandler, never()).post(any( NotificationManagerService.ShowNotificationPermissionPromptRunnable.class)); @@ -1322,7 +1318,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final NotificationChannel channel = new NotificationChannel("id", "name", IMPORTANCE_DEFAULT); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(channel))); verify(mWorkerHandler, never()).post(any( @@ -1335,12 +1331,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { new NotificationChannel("id1", "name", IMPORTANCE_DEFAULT); final NotificationChannel channel2 = new NotificationChannel("id2", "name", IMPORTANCE_DEFAULT); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(channel1, channel2))); assertTrue(mBinderService.getNotificationChannel( - PKG, mContext.getUserId(), PKG, "id1") != null); + mPkg, mContext.getUserId(), mPkg, "id1") != null); assertTrue(mBinderService.getNotificationChannel( - PKG, mContext.getUserId(), PKG, "id2") != null); + mPkg, mContext.getUserId(), mPkg, "id2") != null); } @Test @@ -1348,16 +1344,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { throws Exception { final NotificationChannel channel = new NotificationChannel("id", "name", IMPORTANCE_DEFAULT); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(channel))); // Recreating the channel doesn't throw, but ignores importance. final NotificationChannel dupeChannel = new NotificationChannel("id", "name", IMPORTANCE_HIGH); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(dupeChannel))); final NotificationChannel createdChannel = - mBinderService.getNotificationChannel(PKG, mContext.getUserId(), PKG, "id"); + mBinderService.getNotificationChannel(mPkg, mContext.getUserId(), mPkg, "id"); assertEquals(IMPORTANCE_DEFAULT, createdChannel.getImportance()); } @@ -1366,16 +1362,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { throws Exception { final NotificationChannel channel = new NotificationChannel("id", "name", IMPORTANCE_DEFAULT); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(channel))); // Recreating with a lower importance is allowed to modify the channel. final NotificationChannel dupeChannel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_LOW); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(dupeChannel))); final NotificationChannel createdChannel = - mBinderService.getNotificationChannel(PKG, mContext.getUserId(), PKG, "id"); + mBinderService.getNotificationChannel(mPkg, mContext.getUserId(), mPkg, "id"); assertEquals(NotificationManager.IMPORTANCE_LOW, createdChannel.getImportance()); } @@ -1384,21 +1380,21 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { throws Exception { final NotificationChannel channel = new NotificationChannel("id", "name", IMPORTANCE_DEFAULT); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(channel))); // The user modifies importance directly, can no longer be changed by the app. final NotificationChannel updatedChannel = new NotificationChannel("id", "name", IMPORTANCE_HIGH); - mBinderService.updateNotificationChannelForPackage(PKG, mUid, updatedChannel); + mBinderService.updateNotificationChannelForPackage(mPkg, mUid, updatedChannel); // Recreating with a lower importance leaves channel unchanged. final NotificationChannel dupeChannel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_LOW); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(dupeChannel))); final NotificationChannel createdChannel = - mBinderService.getNotificationChannel(PKG, mContext.getUserId(), PKG, "id"); + mBinderService.getNotificationChannel(mPkg, mContext.getUserId(), mPkg, "id"); assertEquals(IMPORTANCE_HIGH, createdChannel.getImportance()); } @@ -1409,10 +1405,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { new NotificationChannel("id", "name", IMPORTANCE_DEFAULT); final NotificationChannel channel2 = new NotificationChannel("id", "name", IMPORTANCE_HIGH); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(channel1, channel2))); final NotificationChannel createdChannel = - mBinderService.getNotificationChannel(PKG, mContext.getUserId(), PKG, "id"); + mBinderService.getNotificationChannel(mPkg, mContext.getUserId(), mPkg, "id"); assertEquals(IMPORTANCE_DEFAULT, createdChannel.getImportance()); } @@ -1438,9 +1434,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertTrue(mService.isRecordBlockedLocked(r)); mBinderService.createNotificationChannels( - PKG, new ParceledListSlice(Arrays.asList(channel))); + mPkg, new ParceledListSlice(Arrays.asList(channel))); final StatusBarNotification sbn = generateNotificationRecord(channel).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testBlockedNotifications_blockedChannel", sbn.getId(), sbn.getNotification(), sbn.getUserId()); waitForIdle(); @@ -1457,18 +1453,18 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannel channel = new NotificationChannel("blocked", "name", NotificationManager.IMPORTANCE_NONE); mBinderService.createNotificationChannels( - PKG, new ParceledListSlice(Arrays.asList(channel))); + mPkg, new ParceledListSlice(Arrays.asList(channel))); final StatusBarNotification sbn = generateNotificationRecord(channel).getSbn(); sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, sbn.getTag(), sbn.getId(), sbn.getNotification(), sbn.getUserId()); waitForIdle(); assertEquals(1, mBinderService.getActiveNotifications(sbn.getPackageName()).length); assertEquals(IMPORTANCE_LOW, mService.getNotificationRecord(sbn.getKey()).getImportance()); assertEquals(IMPORTANCE_LOW, mBinderService.getNotificationChannel( - PKG, mContext.getUserId(), PKG, channel.getId()).getImportance()); + mPkg, mContext.getUserId(), mPkg, channel.getId()).getImportance()); } @Test @@ -1481,18 +1477,18 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannel channel = new NotificationChannel("blockedbyuser", "name", IMPORTANCE_HIGH); mBinderService.createNotificationChannels( - PKG, new ParceledListSlice(Arrays.asList(channel))); + mPkg, new ParceledListSlice(Arrays.asList(channel))); NotificationChannel update = new NotificationChannel("blockedbyuser", "name", IMPORTANCE_NONE); - mBinderService.updateNotificationChannelForPackage(PKG, mUid, update); + mBinderService.updateNotificationChannelForPackage(mPkg, mUid, update); waitForIdle(); assertEquals(IMPORTANCE_NONE, mBinderService.getNotificationChannel( - PKG, mContext.getUserId(), PKG, channel.getId()).getImportance()); + mPkg, mContext.getUserId(), mPkg, channel.getId()).getImportance()); StatusBarNotification sbn = generateNotificationRecord(channel).getSbn(); sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, sbn.getTag(), sbn.getId(), sbn.getNotification(), sbn.getUserId()); waitForIdle(); // The first time a foreground service notification is shown, we allow the channel @@ -1501,20 +1497,20 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(IMPORTANCE_LOW, mService.getNotificationRecord(sbn.getKey()).getImportance()); assertEquals(IMPORTANCE_LOW, mBinderService.getNotificationChannel( - PKG, mContext.getUserId(), PKG, channel.getId()).getImportance()); - mBinderService.cancelNotificationWithTag(PKG, PKG, "tag", sbn.getId(), sbn.getUserId()); + mPkg, mContext.getUserId(), mPkg, channel.getId()).getImportance()); + mBinderService.cancelNotificationWithTag(mPkg, mPkg, "tag", sbn.getId(), sbn.getUserId()); waitForIdle(); update = new NotificationChannel("blockedbyuser", "name", IMPORTANCE_NONE); update.setUserVisibleTaskShown(true); - mBinderService.updateNotificationChannelForPackage(PKG, mUid, update); + mBinderService.updateNotificationChannelForPackage(mPkg, mUid, update); waitForIdle(); assertEquals(IMPORTANCE_NONE, mBinderService.getNotificationChannel( - PKG, mContext.getUserId(), PKG, channel.getId()).getImportance()); + mPkg, mContext.getUserId(), mPkg, channel.getId()).getImportance()); sbn = generateNotificationRecord(channel).getSbn(); sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueuedBlockedNotifications_userBlockedChannelForegroundService", sbn.getId(), sbn.getNotification(), sbn.getUserId()); waitForIdle(); @@ -1522,7 +1518,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(0, mBinderService.getActiveNotifications(sbn.getPackageName()).length); assertNull(mService.getNotificationRecord(sbn.getKey())); assertEquals(IMPORTANCE_NONE, mBinderService.getNotificationChannel( - PKG, mContext.getUserId(), PKG, channel.getId()).getImportance()); + mPkg, mContext.getUserId(), mPkg, channel.getId()).getImportance()); } @Test @@ -1545,7 +1541,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mPermissionHelper.hasPermission(mUid)).thenReturn(false); final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueuedBlockedNotifications_blockedApp", sbn.getId(), sbn.getNotification(), sbn.getUserId()); waitForIdle(); @@ -1561,7 +1557,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueuedBlockedNotifications_blockedAppForegroundService", sbn.getId(), sbn.getNotification(), sbn.getUserId()); waitForIdle(); @@ -1590,12 +1586,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel, ++id, "", false).getSbn(); sbn.getNotification().category = category; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueuedRestrictedNotifications_asSystem", sbn.getId(), sbn.getNotification(), sbn.getUserId()); } waitForIdle(); - assertEquals(categories.size(), mBinderService.getActiveNotifications(PKG).length); + assertEquals(categories.size(), mBinderService.getActiveNotifications(mPkg).length); } @@ -1614,12 +1610,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel, ++id, "", false).getSbn(); sbn.getNotification().category = category; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueuedRestrictedNotifications_notAutomotive", sbn.getId(), sbn.getNotification(), sbn.getUserId()); } waitForIdle(); - assertEquals(categories.size(), mBinderService.getActiveNotifications(PKG).length); + assertEquals(categories.size(), mBinderService.getActiveNotifications(mPkg).length); } /** @@ -1637,7 +1633,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().category = category; try { - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueuedRestrictedNotifications_badUser", sbn.getId(), sbn.getNotification(), sbn.getUserId()); fail("Calls from non system apps should not allow use of restricted categories"); @@ -1646,7 +1642,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } } waitForIdle(); - assertEquals(0, mBinderService.getActiveNotifications(PKG).length); + assertEquals(0, mBinderService.getActiveNotifications(mPkg).length); } @Test @@ -1726,7 +1722,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord nr = generateNotificationRecord( new NotificationChannel("did not create", "", IMPORTANCE_DEFAULT)); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -1736,7 +1732,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { reset(mPermissionHelper); when(mPermissionHelper.hasPermission(mUid)).thenReturn(true); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -1748,7 +1744,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testEnqueueNotification_appBlocked() throws Exception { when(mPermissionHelper.hasPermission(mUid)).thenReturn(false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueueNotification_appBlocked", 0, generateNotificationRecord(null).getNotification(), mUserId); waitForIdle(); @@ -1758,11 +1754,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testEnqueueNotificationWithTag_PopulatesGetActiveNotifications() throws Exception { - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueueNotificationWithTag_PopulatesGetActiveNotifications", 0, generateNotificationRecord(null).getNotification(), mUserId); waitForIdle(); - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifs.length); assertEquals(1, mService.getNotificationRecordCount()); } @@ -1770,7 +1766,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testEnqueueNotificationWithTag_WritesExpectedLogs() throws Exception { final String tag = "testEnqueueNotificationWithTag_WritesExpectedLog"; - mBinderService.enqueueNotificationWithTag(PKG, PKG, tag, 0, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, generateNotificationRecord(null).getNotification(), mUserId); waitForIdle(); assertEquals(1, mNotificationRecordLogger.numCalls()); @@ -1782,7 +1778,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertNull(call.old); assertEquals(0, call.position); assertEquals(0, call.buzzBeepBlink); - assertEquals(PKG, call.r.getSbn().getPackageName()); + assertEquals(mPkg, call.r.getSbn().getPackageName()); assertEquals(0, call.r.getSbn().getId()); assertEquals(tag, call.r.getSbn().getTag()); assertEquals(1, call.getInstanceId()); // Fake instance IDs are assigned in order @@ -1795,12 +1791,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification original = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setSmallIcon(android.R.drawable.sym_def_app_icon).build(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, tag, 0, original, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, original, mUserId); Notification update = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setSmallIcon(android.R.drawable.sym_def_app_icon) .setCategory(Notification.CATEGORY_ALARM).build(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, tag, 0, update, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, update, mUserId); waitForIdle(); assertEquals(2, mNotificationRecordLogger.numCalls()); @@ -1819,9 +1815,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testEnqueueNotificationWithTag_DoesNotLogOnMinorUpdate() throws Exception { final String tag = "testEnqueueNotificationWithTag_DoesNotLogOnMinorUpdate"; - mBinderService.enqueueNotificationWithTag(PKG, PKG, tag, 0, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, generateNotificationRecord(null).getNotification(), mUserId); - mBinderService.enqueueNotificationWithTag(PKG, PKG, tag, 0, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, generateNotificationRecord(null).getNotification(), mUserId); waitForIdle(); assertEquals(2, mNotificationRecordLogger.numCalls()); @@ -1834,12 +1830,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testEnqueueNotificationWithTag_DoesNotLogOnTitleUpdate() throws Exception { final String tag = "testEnqueueNotificationWithTag_DoesNotLogOnTitleUpdate"; - mBinderService.enqueueNotificationWithTag(PKG, PKG, tag, 0, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, generateNotificationRecord(null).getNotification(), mUserId); final Notification notif = generateNotificationRecord(null).getNotification(); notif.extras.putString(Notification.EXTRA_TITLE, "Changed title"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, tag, 0, notif, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, notif, mUserId); waitForIdle(); assertEquals(2, mNotificationRecordLogger.numCalls()); assertEquals(NOTIFICATION_POSTED, mNotificationRecordLogger.event(0)); @@ -1852,11 +1848,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification notification = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setSmallIcon(android.R.drawable.sym_def_app_icon).build(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, tag, 0, notification, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, notification, mUserId); waitForIdle(); - mBinderService.cancelNotificationWithTag(PKG, PKG, tag, 0, mUserId); + mBinderService.cancelNotificationWithTag(mPkg, mPkg, tag, 0, mUserId); waitForIdle(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, tag, 0, notification, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, 0, notification, mUserId); waitForIdle(); assertEquals(3, mNotificationRecordLogger.numCalls()); @@ -1893,14 +1889,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setSmallIcon(android.R.drawable.sym_def_app_icon) .setFlag(FLAG_FOREGROUND_SERVICE, true) .build(); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, tag, mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, tag, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); - mBinderService.enqueueNotificationWithTag(PKG, PKG, tag, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, tag, sbn.getId(), sbn.getNotification(), sbn.getUserId()); waitForIdle(); StatusBarNotification[] notifs = - mBinderService.getActiveNotifications(PKG); + mBinderService.getActiveNotifications(mPkg); assertThat(notifs[0].getNotification().flags).isEqualTo( FLAG_FOREGROUND_SERVICE | FLAG_CAN_COLORIZE | FLAG_NO_CLEAR); } @@ -1916,10 +1912,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); n.actions[1] = null; - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 0, n, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", 0, n, mUserId); waitForIdle(); - StatusBarNotification[] posted = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] posted = mBinderService.getActiveNotifications(mPkg); assertThat(posted).hasLength(1); assertThat(posted[0].getNotification().actions).hasLength(2); assertThat(posted[0].getNotification().actions[0].title.toString()).isEqualTo("one"); @@ -1937,17 +1933,17 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { n.actions[0] = null; n.actions[1] = null; - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 0, n, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", 0, n, mUserId); waitForIdle(); - StatusBarNotification[] posted = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] posted = mBinderService.getActiveNotifications(mPkg); assertThat(posted).hasLength(1); assertThat(posted[0].getNotification().actions).isNull(); } @Test public void enqueueNotificationWithTag_usesAndFinishesTracker() throws Exception { - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueueNotificationWithTag_PopulatesGetActiveNotifications", 0, generateNotificationRecord(null).getNotification(), mUserId); @@ -1956,7 +1952,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); - assertThat(mBinderService.getActiveNotifications(PKG)).hasLength(1); + assertThat(mBinderService.getActiveNotifications(mPkg)).hasLength(1); assertThat(mPostNotificationTrackerFactory.mCreatedTrackers).hasSize(1); assertThat(mPostNotificationTrackerFactory.mCreatedTrackers.get(0).isOngoing()).isFalse(); } @@ -1965,13 +1961,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void enqueueNotificationWithTag_throws_usesAndCancelsTracker() throws Exception { // Simulate not enqueued due to rejected inputs. assertThrows(Exception.class, - () -> mBinderService.enqueueNotificationWithTag(PKG, PKG, + () -> mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueueNotificationWithTag_PopulatesGetActiveNotifications", 0, /* notification= */ null, mUserId)); waitForIdle(); - assertThat(mBinderService.getActiveNotifications(PKG)).hasLength(0); + assertThat(mBinderService.getActiveNotifications(mPkg)).hasLength(0); assertThat(mPostNotificationTrackerFactory.mCreatedTrackers).hasSize(1); assertThat(mPostNotificationTrackerFactory.mCreatedTrackers.get(0).isOngoing()).isFalse(); } @@ -1982,12 +1978,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mSnoozeHelper.getSnoozeContextForUnpostedNotification(anyInt(), any(), any())) .thenReturn("zzzzzzz"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueueNotificationWithTag_PopulatesGetActiveNotifications", 0, generateNotificationRecord(null).getNotification(), mUserId); waitForIdle(); - assertThat(mBinderService.getActiveNotifications(PKG)).hasLength(0); + assertThat(mBinderService.getActiveNotifications(mPkg)).hasLength(0); assertThat(mPostNotificationTrackerFactory.mCreatedTrackers).hasSize(1); assertThat(mPostNotificationTrackerFactory.mCreatedTrackers.get(0).isOngoing()).isFalse(); } @@ -1997,19 +1993,19 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Simulate not posted due to blocked app. when(mPermissionHelper.hasPermission(anyInt())).thenReturn(false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testEnqueueNotificationWithTag_PopulatesGetActiveNotifications", 0, generateNotificationRecord(null).getNotification(), mUserId); waitForIdle(); - assertThat(mBinderService.getActiveNotifications(PKG)).hasLength(0); + assertThat(mBinderService.getActiveNotifications(mPkg)).hasLength(0); assertThat(mPostNotificationTrackerFactory.mCreatedTrackers).hasSize(1); assertThat(mPostNotificationTrackerFactory.mCreatedTrackers.get(0).isOngoing()).isFalse(); } @Test public void enqueueNotification_acquiresAndReleasesWakeLock() throws Exception { - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "enqueueNotification_acquiresAndReleasesWakeLock", 0, generateNotificationRecord(null).getNotification(), mUserId); @@ -2027,7 +2023,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void enqueueNotification_throws_acquiresAndReleasesWakeLock() throws Exception { // Simulate not enqueued due to rejected inputs. assertThrows(Exception.class, - () -> mBinderService.enqueueNotificationWithTag(PKG, PKG, + () -> mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "enqueueNotification_throws_acquiresAndReleasesWakeLock", 0, /* notification= */ null, mUserId)); @@ -2042,7 +2038,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mSnoozeHelper.getSnoozeContextForUnpostedNotification(anyInt(), any(), any())) .thenReturn("zzzzzzz"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "enqueueNotification_notEnqueued_acquiresAndReleasesWakeLock", 0, generateNotificationRecord(null).getNotification(), mUserId); @@ -2063,7 +2059,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setContentTitle("foo") .build(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "enqueueNotification_notPosted_acquiresAndReleasesWakeLock", 0, notif, mUserId); @@ -2088,14 +2084,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { WakeLock wakeLock = mock(WakeLock.class); when(mPowerManager.newWakeLock(anyInt(), anyString())).thenReturn(wakeLock); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "enqueueNotification_setsWakeLockWorkSource", 0, generateNotificationRecord(null).getNotification(), mUserId); waitForIdle(); InOrder inOrder = inOrder(mPowerManager, wakeLock); inOrder.verify(mPowerManager).newWakeLock(eq(PARTIAL_WAKE_LOCK), anyString()); - inOrder.verify(wakeLock).setWorkSource(eq(new WorkSource(mUid, PKG))); + inOrder.verify(wakeLock).setWorkSource(eq(new WorkSource(mUid, mPkg))); inOrder.verify(wakeLock).acquire(anyLong()); inOrder.verify(wakeLock).release(); inOrder.verifyNoMoreInteractions(); @@ -2103,7 +2099,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testCancelNonexistentNotification() throws Exception { - mBinderService.cancelNotificationWithTag(PKG, PKG, + mBinderService.cancelNotificationWithTag(mPkg, mPkg, "testCancelNonexistentNotification", 0, mUserId); waitForIdle(); // The notification record logger doesn't even get called when a nonexistent notification @@ -2113,14 +2109,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testCancelNotificationImmediatelyAfterEnqueue() throws Exception { - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelNotificationImmediatelyAfterEnqueue", 0, generateNotificationRecord(null).getNotification(), mUserId); - mBinderService.cancelNotificationWithTag(PKG, PKG, + mBinderService.cancelNotificationWithTag(mPkg, mPkg, "testCancelNotificationImmediatelyAfterEnqueue", 0, mUserId); waitForIdle(); StatusBarNotification[] notifs = - mBinderService.getActiveNotifications(PKG); + mBinderService.getActiveNotifications(mPkg); assertEquals(0, notifs.length); assertEquals(0, mService.getNotificationRecordCount()); } @@ -2129,39 +2125,39 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testPostCancelPostNotifiesListeners() throws Exception { // WHEN a notification is posted final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", sbn.getId(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", sbn.getId(), sbn.getNotification(), sbn.getUserId()); mTestableLooper.moveTimeForward(1); // THEN it is canceled - mBinderService.cancelNotificationWithTag(PKG, PKG, "tag", sbn.getId(), sbn.getUserId()); + mBinderService.cancelNotificationWithTag(mPkg, mPkg, "tag", sbn.getId(), sbn.getUserId()); mTestableLooper.moveTimeForward(1); // THEN it is posted again (before the cancel has a chance to finish) - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", sbn.getId(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", sbn.getId(), sbn.getNotification(), sbn.getUserId()); // THEN the later enqueue isn't swallowed by the cancel. I.e., ordering is respected waitForIdle(); // The final enqueue made it to the listener instead of being canceled StatusBarNotification[] notifs = - mBinderService.getActiveNotifications(PKG); + mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifs.length); assertEquals(1, mService.getNotificationRecordCount()); } @Test public void testCancelNotificationWhilePostedAndEnqueued() throws Exception { - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelNotificationWhilePostedAndEnqueued", 0, generateNotificationRecord(null).getNotification(), mUserId); waitForIdle(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelNotificationWhilePostedAndEnqueued", 0, generateNotificationRecord(null).getNotification(), mUserId); - mBinderService.cancelNotificationWithTag(PKG, PKG, + mBinderService.cancelNotificationWithTag(mPkg, mPkg, "testCancelNotificationWhilePostedAndEnqueued", 0, mUserId); waitForIdle(); StatusBarNotification[] notifs = - mBinderService.getActiveNotifications(PKG); + mBinderService.getActiveNotifications(mPkg); assertEquals(0, notifs.length); assertEquals(0, mService.getNotificationRecordCount()); ArgumentCaptor<NotificationStats> captor = ArgumentCaptor.forClass(NotificationStats.class); @@ -2173,7 +2169,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testCancelNotificationsFromListenerImmediatelyAfterEnqueue() throws Exception { NotificationRecord r = generateNotificationRecord(null); final StatusBarNotification sbn = r.getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelNotificationsFromListenerImmediatelyAfterEnqueue", sbn.getId(), sbn.getNotification(), sbn.getUserId()); mBinderService.cancelNotificationsFromListener(null, null); @@ -2187,10 +2183,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testCancelAllNotificationsImmediatelyAfterEnqueue() throws Exception { final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotificationsImmediatelyAfterEnqueue", sbn.getId(), sbn.getNotification(), sbn.getUserId()); - mBinderService.cancelAllNotifications(PKG, sbn.getUserId()); + mBinderService.cancelAllNotifications(mPkg, sbn.getUserId()); waitForIdle(); StatusBarNotification[] notifs = mBinderService.getActiveNotifications(sbn.getPackageName()); @@ -2203,7 +2199,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final NotificationRecord n = generateNotificationRecord( mTestNotificationChannel, 1, "group", true); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testUserInitiatedClearAll_noLeak", n.getSbn().getId(), n.getSbn().getNotification(), n.getSbn().getUserId()); waitForIdle(); @@ -2227,17 +2223,17 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final NotificationRecord child = generateNotificationRecord( mTestNotificationChannel, 2, "group1", false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotificationsCancelsChildren", parent.getSbn().getId(), parent.getSbn().getNotification(), parent.getSbn().getUserId()); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotificationsCancelsChildren", child.getSbn().getId(), child.getSbn().getNotification(), child.getSbn().getUserId()); waitForIdle(); - mBinderService.cancelAllNotifications(PKG, parent.getSbn().getUserId()); + mBinderService.cancelAllNotifications(mPkg, parent.getSbn().getUserId()); waitForIdle(); assertEquals(0, mService.getNotificationRecordCount()); } @@ -2246,11 +2242,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testCancelAllNotificationsMultipleEnqueuedDoesNotCrash() throws Exception { final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); for (int i = 0; i < 10; i++) { - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotificationsMultipleEnqueuedDoesNotCrash", sbn.getId(), sbn.getNotification(), sbn.getUserId()); } - mBinderService.cancelAllNotifications(PKG, sbn.getUserId()); + mBinderService.cancelAllNotifications(mPkg, sbn.getUserId()); waitForIdle(); assertEquals(0, mService.getNotificationRecordCount()); @@ -2266,7 +2262,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mTestNotificationChannel, 2, "group1", false); // fully post parent notification - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelGroupSummaryMultipleEnqueuedChildrenDoesNotCrash", parent.getSbn().getId(), parent.getSbn().getNotification(), parent.getSbn().getUserId()); @@ -2274,13 +2270,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // enqueue the child several times for (int i = 0; i < 10; i++) { - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelGroupSummaryMultipleEnqueuedChildrenDoesNotCrash", child.getSbn().getId(), child.getSbn().getNotification(), child.getSbn().getUserId()); } // make the parent a child, which will cancel the child notification - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelGroupSummaryMultipleEnqueuedChildrenDoesNotCrash", parentAsChild.getSbn().getId(), parentAsChild.getSbn().getNotification(), parentAsChild.getSbn().getUserId()); @@ -2332,10 +2328,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { any(), anyString(), anyInt(), anyString(), anyInt())).thenReturn(SHOW_IMMEDIATELY); final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotifications_IgnoreForegroundService", sbn.getId(), sbn.getNotification(), sbn.getUserId()); - mBinderService.cancelAllNotifications(PKG, sbn.getUserId()); + mBinderService.cancelAllNotifications(mPkg, sbn.getUserId()); waitForIdle(); StatusBarNotification[] notifs = mBinderService.getActiveNotifications(sbn.getPackageName()); @@ -2350,10 +2346,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(NOT_FOREGROUND_SERVICE); final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotifications_IgnoreForegroundService", sbn.getId(), sbn.getNotification(), sbn.getUserId()); - mBinderService.cancelAllNotifications(PKG, sbn.getUserId()); + mBinderService.cancelAllNotifications(mPkg, sbn.getUserId()); waitForIdle(); StatusBarNotification[] notifs = mBinderService.getActiveNotifications(sbn.getPackageName()); @@ -2367,7 +2363,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(SHOW_IMMEDIATELY); final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotifications_IgnoreOtherPackages", sbn.getId(), sbn.getNotification(), sbn.getUserId()); mBinderService.cancelAllNotifications("other_pkg_name", sbn.getUserId()); @@ -2381,7 +2377,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testCancelAllNotifications_NullPkgRemovesAll() throws Exception { final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotifications_NullPkgRemovesAll", sbn.getId(), sbn.getNotification(), sbn.getUserId()); mBinderService.cancelAllNotifications(null, sbn.getUserId()); @@ -2395,7 +2391,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testCancelAllNotifications_NullPkgIgnoresUserAllNotifications() throws Exception { final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotifications_NullPkgIgnoresUserAllNotifications", sbn.getId(), sbn.getNotification(), UserHandle.USER_ALL); // Null pkg is how we signal a user switch. @@ -2411,10 +2407,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testAppInitiatedCancelAllNotifications_CancelsNoClearFlag() throws Exception { final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags |= Notification.FLAG_NO_CLEAR; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testAppInitiatedCancelAllNotifications_CancelsNoClearFlag", sbn.getId(), sbn.getNotification(), sbn.getUserId()); - mBinderService.cancelAllNotifications(PKG, sbn.getUserId()); + mBinderService.cancelAllNotifications(mPkg, sbn.getUserId()); waitForIdle(); StatusBarNotification[] notifs = mBinderService.getActiveNotifications(sbn.getPackageName()); @@ -2427,7 +2423,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mTestNotificationChannel, 1, "group", true); notif.getNotification().flags |= Notification.FLAG_NO_CLEAR; mService.addNotification(notif); - mService.cancelAllNotificationsInt(mUid, 0, PKG, null, 0, 0, + mService.cancelAllNotificationsInt(mUid, 0, mPkg, null, 0, 0, notif.getUserId(), REASON_CANCEL); waitForIdle(); StatusBarNotification[] notifs = @@ -2462,9 +2458,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, null, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, null, sbn.getId(), sbn.getNotification(), sbn.getUserId()); - mInternalService.removeForegroundServiceFlagFromNotification(PKG, sbn.getId(), + mInternalService.removeForegroundServiceFlagFromNotification(mPkg, sbn.getId(), sbn.getUserId()); waitForIdle(); StatusBarNotification[] notifs = @@ -2477,12 +2473,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags = Notification.FLAG_ONGOING_EVENT | FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, sbn.getTag(), sbn.getId(), sbn.getNotification(), sbn.getUserId()); sbn.getNotification().flags = Notification.FLAG_ONGOING_EVENT; - mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, sbn.getTag(), sbn.getId(), sbn.getNotification(), sbn.getUserId()); - mBinderService.cancelNotificationWithTag(PKG, PKG, sbn.getTag(), sbn.getId(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, sbn.getTag(), sbn.getId(), sbn.getUserId()); waitForIdle(); assertEquals(0, mBinderService.getActiveNotifications(sbn.getPackageName()).length); @@ -2501,7 +2497,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertThat(mBinderService.getActiveNotifications(sbn.getPackageName()).length).isEqualTo(1); assertThat(mService.getNotificationRecordCount()).isEqualTo(1); - mBinderService.cancelNotificationWithTag(PKG, PKG, sbn.getTag(), sbn.getId(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, sbn.getTag(), sbn.getId(), sbn.getUserId()); waitForIdle(); @@ -2520,7 +2516,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY); mSetFlagsRule.disableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR); - mBinderService.cancelNotificationWithTag(PKG, PKG, sbn.getTag(), sbn.getId(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, sbn.getTag(), sbn.getId(), sbn.getUserId()); waitForIdle(); @@ -2542,13 +2538,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mTestNotificationChannel, 2, null, false); mService.addNotification(notifCancelable); // Verify that both notifications have been posted and are active. - assertThat(mBinderService.getActiveNotifications(PKG).length).isEqualTo(2); + assertThat(mBinderService.getActiveNotifications(mPkg).length).isEqualTo(2); - mBinderService.cancelAllNotifications(PKG, notif.getSbn().getUserId()); + mBinderService.cancelAllNotifications(mPkg, notif.getSbn().getUserId()); waitForIdle(); // The non-lifetime extended notification, with id = 2, has been cancelled. - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertThat(notifs.length).isEqualTo(1); assertThat(notifs[0].getId()).isEqualTo(1); @@ -3230,7 +3226,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testGroupInstanceIds() throws Exception { final NotificationRecord group1 = generateNotificationRecord( mTestNotificationChannel, 1, "group1", true); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testGroupInstanceIds", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testGroupInstanceIds", group1.getSbn().getId(), group1.getSbn().getNotification(), group1.getSbn().getUserId()); waitForIdle(); @@ -3238,7 +3234,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // same group, child, should be returned final NotificationRecord group1Child = generateNotificationRecord( mTestNotificationChannel, 2, "group1", false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testGroupInstanceIds", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testGroupInstanceIds", group1Child.getSbn().getId(), group1Child.getSbn().getNotification(), group1Child.getSbn().getUserId()); waitForIdle(); @@ -3259,7 +3255,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // should not be returned final NotificationRecord group2 = generateNotificationRecord( mTestNotificationChannel, 2, "group2", true); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testFindGroupNotificationsLocked", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testFindGroupNotificationsLocked", group2.getSbn().getId(), group2.getSbn().getNotification(), group2.getSbn().getUserId()); waitForIdle(); @@ -3267,7 +3263,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // should not be returned final NotificationRecord nonGroup = generateNotificationRecord( mTestNotificationChannel, 3, null, false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testFindGroupNotificationsLocked", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testFindGroupNotificationsLocked", nonGroup.getSbn().getId(), nonGroup.getSbn().getNotification(), nonGroup.getSbn().getUserId()); waitForIdle(); @@ -3275,13 +3271,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // same group, child, should be returned final NotificationRecord group1Child = generateNotificationRecord( mTestNotificationChannel, 4, "group1", false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testFindGroupNotificationsLocked", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testFindGroupNotificationsLocked", group1Child.getSbn().getId(), group1Child.getSbn().getNotification(), group1Child.getSbn().getUserId()); waitForIdle(); List<NotificationRecord> inGroup1 = - mService.findGroupNotificationsLocked(PKG, group1.getGroupKey(), + mService.findGroupNotificationsLocked(mPkg, group1.getGroupKey(), group1.getSbn().getUserId()); assertEquals(3, inGroup1.size()); for (NotificationRecord record : inGroup1) { @@ -3296,7 +3292,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mTestNotificationChannel, 1, "group", true); notif.getNotification().flags |= Notification.FLAG_NO_CLEAR; mService.addNotification(notif); - mService.cancelAllNotificationsInt(mUid, 0, PKG, null, 0, + mService.cancelAllNotificationsInt(mUid, 0, mPkg, null, 0, Notification.FLAG_ONGOING_EVENT, notif.getUserId(), REASON_CANCEL); waitForIdle(); StatusBarNotification[] notifs = @@ -3308,10 +3304,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testAppInitiatedCancelAllNotifications_CancelsOngoingFlag() throws Exception { final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags |= Notification.FLAG_ONGOING_EVENT; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testAppInitiatedCancelAllNotifications_CancelsOnGoingFlag", sbn.getId(), sbn.getNotification(), sbn.getUserId()); - mBinderService.cancelAllNotifications(PKG, sbn.getUserId()); + mBinderService.cancelAllNotifications(mPkg, sbn.getUserId()); waitForIdle(); StatusBarNotification[] notifs = mBinderService.getActiveNotifications(sbn.getPackageName()); @@ -3324,7 +3320,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mTestNotificationChannel, 1, "group", true); notif.getNotification().flags |= Notification.FLAG_ONGOING_EVENT; mService.addNotification(notif); - mService.cancelAllNotificationsInt(mUid, 0, PKG, null, 0, 0, + mService.cancelAllNotificationsInt(mUid, 0, mPkg, null, 0, 0, notif.getUserId(), REASON_CANCEL); waitForIdle(); StatusBarNotification[] notifs = @@ -3420,16 +3416,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testPostNotification_appPermissionFixed() throws Exception { when(mPermissionHelper.hasPermission(mUid)).thenReturn(true); - when(mPermissionHelper.isPermissionFixed(PKG, mUserId)).thenReturn(true); + when(mPermissionHelper.isPermissionFixed(mPkg, mUserId)).thenReturn(true); NotificationRecord temp = generateNotificationRecord(mTestNotificationChannel); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testPostNotification_appPermissionFixed", 0, temp.getNotification(), mUserId); waitForIdle(); assertThat(mService.getNotificationRecordCount()).isEqualTo(1); StatusBarNotification[] notifs = - mBinderService.getActiveNotifications(PKG); + mBinderService.getActiveNotifications(mPkg); assertThat(mService.getNotificationRecord(notifs[0].getKey()).isImportanceFixed()).isTrue(); } @@ -3439,7 +3435,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(temp); when(mPermissionHelper.hasPermission(mUid)).thenReturn(true); - when(mPermissionHelper.isPermissionFixed(PKG, temp.getUserId())).thenReturn(true); + when(mPermissionHelper.isPermissionFixed(mPkg, temp.getUserId())).thenReturn(true); NotificationRecord r = mService.createAutoGroupSummary(temp.getUserId(), temp.getSbn().getPackageName(), temp.getKey(), 0, mock(Icon.class), 0, @@ -3457,7 +3453,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { new NotificationChannel("foo", "foo", IMPORTANCE_HIGH)); Notification.TvExtender tv = new Notification.TvExtender().setChannelId("foo"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testTvExtenderChannelOverride_onTv", 0, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testTvExtenderChannelOverride_onTv", 0, generateNotificationRecord(null, tv).getNotification(), mUserId); verify(mPreferencesHelper, times(1)).getConversationNotificationChannel( anyString(), anyInt(), eq("foo"), eq(null), anyBoolean(), anyBoolean()); @@ -3472,7 +3468,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mTestNotificationChannel); Notification.TvExtender tv = new Notification.TvExtender().setChannelId("foo"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testTvExtenderChannelOverride_notOnTv", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testTvExtenderChannelOverride_notOnTv", 0, generateNotificationRecord(null, tv).getNotification(), mUserId); verify(mPreferencesHelper, times(1)).getConversationNotificationChannel( anyString(), anyInt(), eq(mTestNotificationChannel.getId()), eq(null), @@ -3585,7 +3581,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testUpdateAppNotifyCreatorBlock() throws Exception { when(mPermissionHelper.hasPermission(mUid)).thenReturn(true); - mBinderService.setNotificationsEnabledForPackage(PKG, mUid, false); + mBinderService.setNotificationsEnabledForPackage(mPkg, mUid, false); Thread.sleep(500); waitForIdle(); @@ -3594,7 +3590,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED, captor.getValue().getAction()); - assertEquals(PKG, captor.getValue().getPackage()); + assertEquals(mPkg, captor.getValue().getPackage()); assertTrue(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true)); } @@ -3602,7 +3598,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testUpdateAppNotifyCreatorBlock_notIfMatchesExistingSetting() throws Exception { when(mPermissionHelper.hasPermission(mUid)).thenReturn(false); - mBinderService.setNotificationsEnabledForPackage(PKG, 0, false); + mBinderService.setNotificationsEnabledForPackage(mPkg, 0, false); verify(mContext, never()).sendBroadcastAsUser(any(), any(), eq(null)); } @@ -3610,7 +3606,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testUpdateAppNotifyCreatorUnblock() throws Exception { when(mPermissionHelper.hasPermission(mUid)).thenReturn(false); - mBinderService.setNotificationsEnabledForPackage(PKG, mUid, true); + mBinderService.setNotificationsEnabledForPackage(mPkg, mUid, true); Thread.sleep(500); waitForIdle(); @@ -3619,14 +3615,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED, captor.getValue().getAction()); - assertEquals(PKG, captor.getValue().getPackage()); + assertEquals(mPkg, captor.getValue().getPackage()); assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true)); } @Test public void testUpdateChannelNotifyCreatorBlock() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(mTestNotificationChannel); @@ -3634,13 +3630,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { new NotificationChannel(mTestNotificationChannel.getId(), mTestNotificationChannel.getName(), IMPORTANCE_NONE); - mBinderService.updateNotificationChannelForPackage(PKG, 0, updatedChannel); + mBinderService.updateNotificationChannelForPackage(mPkg, 0, updatedChannel); ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(1)).sendBroadcastAsUser(captor.capture(), any(), eq(null)); assertEquals(NotificationManager.ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED, captor.getValue().getAction()); - assertEquals(PKG, captor.getValue().getPackage()); + assertEquals(mPkg, captor.getValue().getPackage()); assertEquals(mTestNotificationChannel.getId(), captor.getValue().getStringExtra( NotificationManager.EXTRA_NOTIFICATION_CHANNEL_ID)); assertTrue(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, false)); @@ -3652,17 +3648,17 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { new NotificationChannel(mTestNotificationChannel.getId(), mTestNotificationChannel.getName(), IMPORTANCE_NONE); mService.setPreferencesHelper(mPreferencesHelper); - when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(existingChannel); - mBinderService.updateNotificationChannelForPackage(PKG, 0, mTestNotificationChannel); + mBinderService.updateNotificationChannelForPackage(mPkg, 0, mTestNotificationChannel); ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(1)).sendBroadcastAsUser(captor.capture(), any(), eq(null)); assertEquals(NotificationManager.ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED, captor.getValue().getAction()); - assertEquals(PKG, captor.getValue().getPackage()); + assertEquals(mPkg, captor.getValue().getPackage()); assertEquals(mTestNotificationChannel.getId(), captor.getValue().getStringExtra( NotificationManager.EXTRA_NOTIFICATION_CHANNEL_ID)); assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, false)); @@ -3674,11 +3670,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { new NotificationChannel(mTestNotificationChannel.getId(), mTestNotificationChannel.getName(), IMPORTANCE_MAX); mService.setPreferencesHelper(mPreferencesHelper); - when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(existingChannel); - mBinderService.updateNotificationChannelForPackage(PKG, 0, mTestNotificationChannel); + mBinderService.updateNotificationChannelForPackage(mPkg, 0, mTestNotificationChannel); verify(mContext, never()).sendBroadcastAsUser(any(), any(), eq(null)); } @@ -3687,19 +3683,19 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannelGroup existing = new NotificationChannelGroup("id", "name"); mService.setPreferencesHelper(mPreferencesHelper); when(mPreferencesHelper.getNotificationChannelGroup(eq(existing.getId()), - eq(PKG), anyInt())) + eq(mPkg), anyInt())) .thenReturn(existing); NotificationChannelGroup updated = new NotificationChannelGroup("id", "name"); updated.setBlocked(true); - mBinderService.updateNotificationChannelGroupForPackage(PKG, 0, updated); + mBinderService.updateNotificationChannelGroupForPackage(mPkg, 0, updated); ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(1)).sendBroadcastAsUser(captor.capture(), any(), eq(null)); assertEquals(NotificationManager.ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED, captor.getValue().getAction()); - assertEquals(PKG, captor.getValue().getPackage()); + assertEquals(mPkg, captor.getValue().getPackage()); assertEquals(existing.getId(), captor.getValue().getStringExtra( NotificationManager.EXTRA_NOTIFICATION_CHANNEL_GROUP_ID)); assertTrue(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, false)); @@ -3711,17 +3707,17 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { existing.setBlocked(true); mService.setPreferencesHelper(mPreferencesHelper); when(mPreferencesHelper.getNotificationChannelGroup(eq(existing.getId()), - eq(PKG), anyInt())) + eq(mPkg), anyInt())) .thenReturn(existing); mBinderService.updateNotificationChannelGroupForPackage( - PKG, 0, new NotificationChannelGroup("id", "name")); + mPkg, 0, new NotificationChannelGroup("id", "name")); ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); verify(mContext, times(1)).sendBroadcastAsUser(captor.capture(), any(), eq(null)); assertEquals(NotificationManager.ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED, captor.getValue().getAction()); - assertEquals(PKG, captor.getValue().getPackage()); + assertEquals(mPkg, captor.getValue().getPackage()); assertEquals(existing.getId(), captor.getValue().getStringExtra( NotificationManager.EXTRA_NOTIFICATION_CHANNEL_GROUP_ID)); assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, false)); @@ -3732,131 +3728,131 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannelGroup existing = new NotificationChannelGroup("id", "name"); mService.setPreferencesHelper(mPreferencesHelper); when(mPreferencesHelper.getNotificationChannelGroup( - eq(existing.getId()), eq(PKG), anyInt())) + eq(existing.getId()), eq(mPkg), anyInt())) .thenReturn(existing); mBinderService.updateNotificationChannelGroupForPackage( - PKG, 0, new NotificationChannelGroup("id", "new name")); + mPkg, 0, new NotificationChannelGroup("id", "new name")); verify(mContext, never()).sendBroadcastAsUser(any(), any(), eq(null)); } @Test public void testCreateChannelNotifyListener() throws Exception { - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mService.setPreferencesHelper(mPreferencesHelper); - when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(mTestNotificationChannel); NotificationChannel channel2 = new NotificationChannel("a", "b", IMPORTANCE_LOW); - when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(), eq(channel2.getId()), anyBoolean())) .thenReturn(channel2); - when(mPreferencesHelper.createNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.createNotificationChannel(eq(mPkg), anyInt(), eq(channel2), anyBoolean(), anyBoolean(), anyInt(), anyBoolean())) .thenReturn(true); reset(mListeners); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(mTestNotificationChannel, channel2))); - verify(mListeners, never()).notifyNotificationChannelChanged(eq(PKG), + verify(mListeners, never()).notifyNotificationChannelChanged(eq(mPkg), eq(Process.myUserHandle()), eq(mTestNotificationChannel), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_ADDED)); - verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(PKG), + verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(mPkg), eq(Process.myUserHandle()), eq(channel2), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_ADDED)); } @Test public void testCreateChannelGroupNotifyListener() throws Exception { - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mService.setPreferencesHelper(mPreferencesHelper); NotificationChannelGroup group1 = new NotificationChannelGroup("a", "b"); NotificationChannelGroup group2 = new NotificationChannelGroup("n", "m"); reset(mListeners); - mBinderService.createNotificationChannelGroups(PKG, + mBinderService.createNotificationChannelGroups(mPkg, new ParceledListSlice(Arrays.asList(group1, group2))); - verify(mListeners, times(1)).notifyNotificationChannelGroupChanged(eq(PKG), + verify(mListeners, times(1)).notifyNotificationChannelGroupChanged(eq(mPkg), eq(Process.myUserHandle()), eq(group1), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_ADDED)); - verify(mListeners, times(1)).notifyNotificationChannelGroupChanged(eq(PKG), + verify(mListeners, times(1)).notifyNotificationChannelGroupChanged(eq(mPkg), eq(Process.myUserHandle()), eq(group2), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_ADDED)); } @Test public void testUpdateChannelNotifyListener() throws Exception { - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mService.setPreferencesHelper(mPreferencesHelper); mTestNotificationChannel.setLightColor(Color.CYAN); - when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(mTestNotificationChannel); reset(mListeners); - mBinderService.updateNotificationChannelForPackage(PKG, mUid, mTestNotificationChannel); - verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(PKG), + mBinderService.updateNotificationChannelForPackage(mPkg, mUid, mTestNotificationChannel); + verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(mPkg), eq(Process.myUserHandle()), eq(mTestNotificationChannel), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED)); } @Test public void testDeleteChannelNotifyListener() throws Exception { - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mService.setPreferencesHelper(mPreferencesHelper); - when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(mTestNotificationChannel); - when(mPreferencesHelper.deleteNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.deleteNotificationChannel(eq(mPkg), anyInt(), eq(mTestNotificationChannel.getId()), anyInt(), anyBoolean())).thenReturn(true); reset(mListeners); - mBinderService.deleteNotificationChannel(PKG, mTestNotificationChannel.getId()); - verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(PKG), + mBinderService.deleteNotificationChannel(mPkg, mTestNotificationChannel.getId()); + verify(mListeners, times(1)).notifyNotificationChannelChanged(eq(mPkg), eq(Process.myUserHandle()), eq(mTestNotificationChannel), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED)); } @Test public void testDeleteChannelOnlyDoExtraWorkIfExisted() throws Exception { - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mService.setPreferencesHelper(mPreferencesHelper); - when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(null); reset(mListeners); - mBinderService.deleteNotificationChannel(PKG, mTestNotificationChannel.getId()); + mBinderService.deleteNotificationChannel(mPkg, mTestNotificationChannel.getId()); verifyNoMoreInteractions(mListeners); verifyNoMoreInteractions(mHistoryManager); } @Test public void testDeleteChannelGroupNotifyListener() throws Exception { - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); NotificationChannelGroup ncg = new NotificationChannelGroup("a", "b/c"); mService.setPreferencesHelper(mPreferencesHelper); when(mPreferencesHelper.getNotificationChannelGroupWithChannels( - eq(PKG), anyInt(), eq(ncg.getId()), anyBoolean())) + eq(mPkg), anyInt(), eq(ncg.getId()), anyBoolean())) .thenReturn(ncg); reset(mListeners); - mBinderService.deleteNotificationChannelGroup(PKG, ncg.getId()); - verify(mListeners, times(1)).notifyNotificationChannelGroupChanged(eq(PKG), + mBinderService.deleteNotificationChannelGroup(mPkg, ncg.getId()); + verify(mListeners, times(1)).notifyNotificationChannelGroupChanged(eq(mPkg), eq(Process.myUserHandle()), eq(ncg), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED)); } @Test public void testDeleteChannelGroupChecksForFgses() throws Exception { - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); CountDownLatch latch = new CountDownLatch(2); mService.createNotificationChannelGroup( - PKG, mUid, new NotificationChannelGroup("group", "group"), true, false); + mPkg, mUid, new NotificationChannelGroup("group", "group"), true, false); new Thread(() -> { NotificationChannel notificationChannel = new NotificationChannel("id", "id", NotificationManager.IMPORTANCE_HIGH); @@ -3864,7 +3860,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { ParceledListSlice<NotificationChannel> pls = new ParceledListSlice(ImmutableList.of(notificationChannel)); try { - mBinderService.createNotificationChannelsForPackage(PKG, mUid, pls); + mBinderService.createNotificationChannelsForPackage(mPkg, mUid, pls); } catch (RemoteException e) { throw new RuntimeException(e); } @@ -3875,7 +3871,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { synchronized (this) { wait(5000); } - mService.createNotificationChannelGroup(PKG, mUid, + mService.createNotificationChannelGroup(mPkg, mUid, new NotificationChannelGroup("new", "new group"), true, false); NotificationChannel notificationChannel = new NotificationChannel("id", "id", NotificationManager.IMPORTANCE_HIGH); @@ -3883,8 +3879,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { ParceledListSlice<NotificationChannel> pls = new ParceledListSlice(ImmutableList.of(notificationChannel)); try { - mBinderService.createNotificationChannelsForPackage(PKG, mUid, pls); - mBinderService.deleteNotificationChannelGroup(PKG, "group"); + mBinderService.createNotificationChannelsForPackage(mPkg, mUid, pls); + mBinderService.deleteNotificationChannelGroup(mPkg, "group"); } catch (RemoteException e) { throw new RuntimeException(e); } @@ -3901,19 +3897,19 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testUpdateNotificationChannelFromPrivilegedListener_success() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); - when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(mTestNotificationChannel); mBinderService.updateNotificationChannelFromPrivilegedListener( - null, PKG, Process.myUserHandle(), mTestNotificationChannel); + null, mPkg, Process.myUserHandle(), mTestNotificationChannel); verify(mPreferencesHelper, times(1)).updateNotificationChannel( anyString(), anyInt(), any(), anyBoolean(), anyInt(), anyBoolean()); - verify(mListeners, never()).notifyNotificationChannelChanged(eq(PKG), + verify(mListeners, never()).notifyNotificationChannelChanged(eq(mPkg), eq(Process.myUserHandle()), eq(mTestNotificationChannel), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED)); } @@ -3921,12 +3917,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testUpdateNotificationChannelFromPrivilegedListener_noAccess() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(emptyList()); try { mBinderService.updateNotificationChannelFromPrivilegedListener( - null, PKG, Process.myUserHandle(), mTestNotificationChannel); + null, mPkg, Process.myUserHandle(), mTestNotificationChannel); fail("listeners that don't have a companion device shouldn't be able to call this"); } catch (SecurityException e) { // pass @@ -3935,7 +3931,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mPreferencesHelper, never()).updateNotificationChannel( anyString(), anyInt(), any(), anyBoolean(), anyInt(), anyBoolean()); - verify(mListeners, never()).notifyNotificationChannelChanged(eq(PKG), + verify(mListeners, never()).notifyNotificationChannelChanged(eq(mPkg), eq(Process.myUserHandle()), eq(mTestNotificationChannel), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED)); } @@ -3943,16 +3939,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testUpdateNotificationChannelFromPrivilegedListener_badUser() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mListener = mock(ManagedServices.ManagedServiceInfo.class); - mListener.component = new ComponentName(PKG, PKG); + mListener.component = new ComponentName(mPkg, mPkg); when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); try { mBinderService.updateNotificationChannelFromPrivilegedListener( - null, PKG, UserHandle.ALL, mTestNotificationChannel); + null, mPkg, UserHandle.ALL, mTestNotificationChannel); fail("incorrectly allowed a change to a user listener cannot see"); } catch (SecurityException e) { // pass @@ -3961,7 +3957,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mPreferencesHelper, never()).updateNotificationChannel( anyString(), anyInt(), any(), anyBoolean(), anyInt(), anyBoolean()); - verify(mListeners, never()).notifyNotificationChannelChanged(eq(PKG), + verify(mListeners, never()).notifyNotificationChannelChanged(eq(mPkg), eq(Process.myUserHandle()), eq(mTestNotificationChannel), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED)); } @@ -3970,9 +3966,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testUpdateNotificationChannelFromPrivilegedListener_noSoundUriPermission() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); - when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(mTestNotificationChannel); @@ -3987,13 +3983,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { anyInt(), eq(Process.myUserHandle().getIdentifier())); assertThrows(SecurityException.class, - () -> mBinderService.updateNotificationChannelFromPrivilegedListener(null, PKG, + () -> mBinderService.updateNotificationChannelFromPrivilegedListener(null, mPkg, Process.myUserHandle(), updatedNotificationChannel)); verify(mPreferencesHelper, never()).updateNotificationChannel( anyString(), anyInt(), any(), anyBoolean(), anyInt(), anyBoolean()); - verify(mListeners, never()).notifyNotificationChannelChanged(eq(PKG), + verify(mListeners, never()).notifyNotificationChannelChanged(eq(mPkg), eq(Process.myUserHandle()), eq(mTestNotificationChannel), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED)); } @@ -4002,9 +3998,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testUpdateNotificationChannelFromPrivilegedListener_noSoundUriPermission_sameSound() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); - when(mPreferencesHelper.getNotificationChannel(eq(PKG), anyInt(), + when(mPreferencesHelper.getNotificationChannel(eq(mPkg), anyInt(), eq(mTestNotificationChannel.getId()), anyBoolean())) .thenReturn(mTestNotificationChannel); @@ -4019,12 +4015,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { anyInt(), eq(Process.myUserHandle().getIdentifier())); mBinderService.updateNotificationChannelFromPrivilegedListener( - null, PKG, Process.myUserHandle(), updatedNotificationChannel); + null, mPkg, Process.myUserHandle(), updatedNotificationChannel); verify(mPreferencesHelper, times(1)).updateNotificationChannel( anyString(), anyInt(), any(), anyBoolean(), anyInt(), anyBoolean()); - verify(mListeners, never()).notifyNotificationChannelChanged(eq(PKG), + verify(mListeners, never()).notifyNotificationChannelChanged(eq(mPkg), eq(Process.myUserHandle()), eq(mTestNotificationChannel), eq(NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED)); } @@ -4032,11 +4028,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testGetNotificationChannelFromPrivilegedListener_cdm_success() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mBinderService.getNotificationChannelsFromPrivilegedListener( - null, PKG, Process.myUserHandle()); + null, mPkg, Process.myUserHandle()); verify(mPreferencesHelper, times(1)).getNotificationChannels( anyString(), anyInt(), anyBoolean()); @@ -4045,12 +4041,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testGetNotificationChannelFromPrivilegedListener_cdm_noAccess() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(emptyList()); try { mBinderService.getNotificationChannelsFromPrivilegedListener( - null, PKG, Process.myUserHandle()); + null, mPkg, Process.myUserHandle()); fail("listeners that don't have a companion device shouldn't be able to call this"); } catch (SecurityException e) { // pass @@ -4064,12 +4060,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testGetNotificationChannelFromPrivilegedListener_assistant_success() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(emptyList()); when(mAssistants.isServiceTokenValidLocked(any())).thenReturn(true); mBinderService.getNotificationChannelsFromPrivilegedListener( - null, PKG, Process.myUserHandle()); + null, mPkg, Process.myUserHandle()); verify(mPreferencesHelper, times(1)).getNotificationChannels( anyString(), anyInt(), anyBoolean()); @@ -4079,13 +4075,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testGetNotificationChannelFromPrivilegedListener_assistant_noAccess() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(emptyList()); when(mAssistants.isServiceTokenValidLocked(any())).thenReturn(false); try { mBinderService.getNotificationChannelsFromPrivilegedListener( - null, PKG, Process.myUserHandle()); + null, mPkg, Process.myUserHandle()); fail("listeners that don't have a companion device shouldn't be able to call this"); } catch (SecurityException e) { // pass @@ -4098,16 +4094,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testGetNotificationChannelFromPrivilegedListener_badUser() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mListener = mock(ManagedServices.ManagedServiceInfo.class); - mListener.component = new ComponentName(PKG, PKG); + mListener.component = new ComponentName(mPkg, mPkg); when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); try { mBinderService.getNotificationChannelsFromPrivilegedListener( - null, PKG, Process.myUserHandle()); + null, mPkg, Process.myUserHandle()); fail("listener getting channels from a user they cannot see"); } catch (SecurityException e) { // pass @@ -4120,11 +4116,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testGetNotificationChannelGroupsFromPrivilegedListener_success() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mBinderService.getNotificationChannelGroupsFromPrivilegedListener( - null, PKG, Process.myUserHandle()); + null, mPkg, Process.myUserHandle()); verify(mPreferencesHelper, times(1)).getNotificationChannelGroups(anyString(), anyInt()); } @@ -4132,12 +4128,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testGetNotificationChannelGroupsFromPrivilegedListener_noAccess() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(emptyList()); try { mBinderService.getNotificationChannelGroupsFromPrivilegedListener( - null, PKG, Process.myUserHandle()); + null, mPkg, Process.myUserHandle()); fail("listeners that don't have a companion device shouldn't be able to call this"); } catch (SecurityException e) { // pass @@ -4149,15 +4145,15 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testGetNotificationChannelGroupsFromPrivilegedListener_badUser() throws Exception { mService.setPreferencesHelper(mPreferencesHelper); - when(mCompanionMgr.getAssociations(PKG, mUserId)) + when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(emptyList()); mListener = mock(ManagedServices.ManagedServiceInfo.class); - mListener.component = new ComponentName(PKG, PKG); + mListener.component = new ComponentName(mPkg, mPkg); when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); try { mBinderService.getNotificationChannelGroupsFromPrivilegedListener( - null, PKG, Process.myUserHandle()); + null, mPkg, Process.myUserHandle()); fail("listeners that don't have a companion device shouldn't be able to call this"); } catch (SecurityException e) { // pass @@ -4190,7 +4186,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r2); mListener = mock(ManagedServices.ManagedServiceInfo.class); - mListener.component = new ComponentName(PKG, PKG); + mListener.component = new ComponentName(mPkg, mPkg); when(mListener.enabledAndUserMatches(anyInt())).thenReturn(false); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); @@ -4209,7 +4205,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r2); mListener = mock(ManagedServices.ManagedServiceInfo.class); - mListener.component = new ComponentName(PKG, PKG); + mListener.component = new ComponentName(mPkg, mPkg); when(mListener.enabledAndUserMatches(anyInt())).thenReturn(true); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); @@ -4231,7 +4227,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(nr1); mListener = mock(ManagedServices.ManagedServiceInfo.class); - mListener.component = new ComponentName(PKG, PKG); + mListener.component = new ComponentName(mPkg, mPkg); when(mListener.enabledAndUserMatches(anyInt())).thenReturn(true); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); @@ -4242,7 +4238,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { any(NotificationManagerService.SnoozeNotificationRunnable.class)); // Ensure cancel event is logged. verify(mAppOpsManager).noteOpNoThrow( - AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER, mUid, PKG, null, + AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER, mUid, mPkg, null, null); } @@ -4257,7 +4253,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(nr1); mListener = mock(ManagedServices.ManagedServiceInfo.class); - mListener.component = new ComponentName(PKG, PKG); + mListener.component = new ComponentName(mPkg, mPkg); when(mListener.enabledAndUserMatches(anyInt())).thenReturn(true); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); @@ -4283,7 +4279,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(nr1); mListener = mock(ManagedServices.ManagedServiceInfo.class); - mListener.component = new ComponentName(PKG, PKG); + mListener.component = new ComponentName(mPkg, mPkg); when(mListener.enabledAndUserMatches(anyInt())).thenReturn(true); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); @@ -4309,7 +4305,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(nr1); mListener = mock(ManagedServices.ManagedServiceInfo.class); - mListener.component = new ComponentName(PKG, PKG); + mListener.component = new ComponentName(mPkg, mPkg); when(mListener.enabledAndUserMatches(anyInt())).thenReturn(true); when(mListeners.checkServiceTokenLocked(any())).thenReturn(mListener); @@ -4619,7 +4615,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final NotificationRecord child = generateNotificationRecord( mTestNotificationChannel, 2, "group", false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testPostNonGroup_noUnsnoozing", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testPostNonGroup_noUnsnoozing", child.getSbn().getId(), child.getSbn().getNotification(), child.getSbn().getUserId()); waitForIdle(); @@ -4633,7 +4629,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final NotificationRecord record = generateNotificationRecord( mTestNotificationChannel, 2, null, false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testPostNonGroup_noUnsnoozing", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testPostNonGroup_noUnsnoozing", record.getSbn().getId(), record.getSbn().getNotification(), record.getSbn().getUserId()); waitForIdle(); @@ -4646,7 +4642,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final NotificationRecord parent = generateNotificationRecord( mTestNotificationChannel, 2, "group", true); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testPostGroupSummary_noUnsnoozing", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testPostGroupSummary_noUnsnoozing", parent.getSbn().getId(), parent.getSbn().getNotification(), parent.getSbn().getUserId()); waitForIdle(); @@ -4659,7 +4655,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final NotificationRecord nr = generateNotificationRecord( mTestNotificationChannel, 2, "group", false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testSystemNotificationListenerCanUnsnooze", nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); @@ -4670,13 +4666,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { snoozeNotificationRunnable.run(); ManagedServices.ManagedServiceInfo listener = mListeners.new ManagedServiceInfo( - null, new ComponentName(PKG, "test_class"), mUid, true, null, 0, 234); + null, new ComponentName(mPkg, "test_class"), mUid, true, null, 0, 234); listener.isSystem = true; when(mListeners.checkServiceTokenLocked(any())).thenReturn(listener); mBinderService.unsnoozeNotificationFromSystemListener(null, nr.getKey()); waitForIdle(); - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifs.length); assertNotNull(notifs[0].getKey());//mService.getNotificationRecord(nr.getSbn().getKey())); } @@ -5197,17 +5193,17 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setContentTitle("foo") .addExtras(extras) .setSmallIcon(android.R.drawable.sym_def_app_icon); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "testNoNotificationDuringSetupPermission", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel); - mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, sbn.getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); NotificationRecord posted = mService.findNotificationLocked( - PKG, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getUserId()); + mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getUserId()); assertTrue(posted.getNotification().extras.containsKey(EXTRA_ALLOW_DURING_SETUP)); } @@ -5222,17 +5218,17 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setColorized(true).setColor(Color.WHITE) .setFlag(FLAG_CAN_COLORIZE, true) .setSmallIcon(android.R.drawable.sym_def_app_icon); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "testNoFakeColorizedPermission", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel); - mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, sbn.getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); NotificationRecord posted = mService.findNotificationLocked( - PKG, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getUserId()); + mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getUserId()); assertFalse(posted.getNotification().isColorized()); } @@ -5430,9 +5426,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // anything that's currently enqueued or posted int userId = mUserId; assertEquals(40, - mService.getNotificationCount(PKG, userId, 0, null)); + mService.getNotificationCount(mPkg, userId, 0, null)); assertEquals(40, - mService.getNotificationCount(PKG, userId, 0, "tag2")); + mService.getNotificationCount(mPkg, userId, 0, "tag2")); // return all for package "a" - "banana" tag isn't used assertEquals(2, @@ -5440,7 +5436,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // exclude a known notification - it's excluded from only the posted list, not enqueued assertEquals(39, mService.getNotificationCount( - PKG, userId, sampleIdToExclude, sampleTagToExclude)); + mPkg, userId, sampleIdToExclude, sampleTagToExclude)); } @Test @@ -5702,7 +5698,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Check that the notification was cancelled. - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertThat(notifsAfter.length).isEqualTo(0); assertThat(mService.getNotificationRecord(notif.getKey())).isNull(); } @@ -5718,7 +5714,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Check that the notification was not cancelled. - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertThat(notifsAfter.length).isEqualTo(1); assertThat(mService.getNotificationRecord(notif.getKey())).isEqualTo(notif); } @@ -5734,7 +5730,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Check that the notification was not cancelled. - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertThat(notifsAfter.length).isEqualTo(1); assertThat(mService.getNotificationRecord(notif.getKey())).isEqualTo(notif); } @@ -5752,7 +5748,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Check that the notification was not cancelled. - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertThat(notifsAfter.length).isEqualTo(1); assertThat(mService.getNotificationRecord(notif.getKey())).isEqualTo(notif); @@ -5926,7 +5922,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); final NotificationVisibility nv = NotificationVisibility.obtain(r.getKey(), 0, 1, true); - mService.mNotificationDelegate.onNotificationClear(mUid, 0, PKG, r.getUserId(), + mService.mNotificationDelegate.onNotificationClear(mUid, 0, mPkg, r.getUserId(), r.getKey(), NotificationStats.DISMISSAL_AOD, NotificationStats.DISMISS_SENTIMENT_POSITIVE, nv); waitForIdle(); @@ -5949,7 +5945,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); final NotificationVisibility nv = NotificationVisibility.obtain(r.getKey(), 0, 1, true); - mService.mNotificationDelegate.onNotificationClear(mUid, 0, PKG, r.getUserId(), + mService.mNotificationDelegate.onNotificationClear(mUid, 0, mPkg, r.getUserId(), r.getKey(), NotificationStats.DISMISSAL_AOD, NotificationStats.DISMISS_SENTIMENT_NEGATIVE, nv); waitForIdle(); @@ -5979,7 +5975,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord original = generateNotificationRecord(mTestNotificationChannel); mService.addNotification(original); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, original.getSbn().getId(), + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, original.getSbn().getId(), original.getSbn().getTag(), mUid, 0, new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setContentTitle("new title").build(), @@ -6411,7 +6407,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .addMessage(message1) .addMessage(message2)); NotificationRecord recordA = new NotificationRecord(mContext, new StatusBarNotification( - PKG, PKG, 0, "tag", mUid, 0, nbA.build(), UserHandle.getUserHandleForUid(mUid), + mPkg, mPkg, 0, "tag", mUid, 0, nbA.build(), UserHandle.getUserHandleForUid(mUid), null, 0), c); // First post means we grant access to both @@ -6429,8 +6425,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setStyle(new Notification.MessagingStyle("").addMessage(message2)); - NotificationRecord recordB = new NotificationRecord(mContext, new StatusBarNotification(PKG, - PKG, 0, "tag", mUid, 0, nbB.build(), UserHandle.getUserHandleForUid(mUid), null, 0), + NotificationRecord recordB = new NotificationRecord(mContext, new StatusBarNotification(mPkg, + mPkg, 0, "tag", mUid, 0, nbB.build(), UserHandle.getUserHandleForUid(mUid), null, 0), c); // Update means we drop access to first @@ -6470,7 +6466,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setStyle(new Notification.MessagingStyle("") .addMessage(message1)); NotificationRecord recordA = new NotificationRecord(mContext, new StatusBarNotification( - PKG, PKG, 0, "tag", mUid, 0, nbA.build(), UserHandle.getUserHandleForUid(mUid), + mPkg, mPkg, 0, "tag", mUid, 0, nbA.build(), UserHandle.getUserHandleForUid(mUid), null, 0), c); doThrow(new SecurityException("no access")).when(mUgm) @@ -6929,7 +6925,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testVisualDifference_foreground() { Notification.Builder nb1 = new Notification.Builder(mContext, "") .setContentTitle("foo"); - StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r1 = new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); @@ -6937,7 +6933,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification.Builder nb2 = new Notification.Builder(mContext, "") .setFlag(FLAG_FOREGROUND_SERVICE, true) .setContentTitle("bar"); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -6949,14 +6945,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testVisualDifference_diffTitle() { Notification.Builder nb1 = new Notification.Builder(mContext, "") .setContentTitle("foo"); - StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r1 = new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); Notification.Builder nb2 = new Notification.Builder(mContext, "") .setContentTitle("bar"); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -6969,7 +6965,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification.Builder nb1 = new Notification.Builder(mContext, "") .setStyle(new Notification.InboxStyle() .addLine("line1").addLine("line2")); - StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r1 = new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); @@ -6977,7 +6973,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification.Builder nb2 = new Notification.Builder(mContext, "") .setStyle(new Notification.InboxStyle() .addLine("line1").addLine("line2_changed")); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -6987,7 +6983,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification.Builder nb3 = new Notification.Builder(mContext, "") .setStyle(new Notification.InboxStyle() .addLine("line1")); - StatusBarNotification sbn3 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn3 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb3.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r3 = new NotificationRecord(mContext, sbn3, mock(NotificationChannel.class)); @@ -6997,7 +6993,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification.Builder nb4 = new Notification.Builder(mContext, "") .setStyle(new Notification.InboxStyle() .addLine("line1").addLine("line2").addLine("line3")); - StatusBarNotification sbn4 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn4 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb4.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r4 = new NotificationRecord(mContext, sbn4, mock(NotificationChannel.class)); @@ -7006,7 +7002,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification.Builder nb5 = new Notification.Builder(mContext, "") .setContentText("not an inbox"); - StatusBarNotification sbn5 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn5 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb5.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r5 = new NotificationRecord(mContext, sbn5, mock(NotificationChannel.class)); @@ -7018,14 +7014,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testVisualDifference_diffText() { Notification.Builder nb1 = new Notification.Builder(mContext, "") .setContentText("foo"); - StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r1 = new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); Notification.Builder nb2 = new Notification.Builder(mContext, "") .setContentText("bar"); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -7037,14 +7033,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testVisualDifference_sameText() { Notification.Builder nb1 = new Notification.Builder(mContext, "") .setContentText("foo"); - StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r1 = new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); Notification.Builder nb2 = new Notification.Builder(mContext, "") .setContentText("foo"); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -7056,14 +7052,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testVisualDifference_sameTextButStyled() { Notification.Builder nb1 = new Notification.Builder(mContext, "") .setContentText(Html.fromHtml("<b>foo</b>")); - StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r1 = new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); Notification.Builder nb2 = new Notification.Builder(mContext, "") .setContentText(Html.fromHtml("<b>foo</b>")); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -7075,14 +7071,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testVisualDifference_diffTextButStyled() { Notification.Builder nb1 = new Notification.Builder(mContext, "") .setContentText(Html.fromHtml("<b>foo</b>")); - StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r1 = new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); Notification.Builder nb2 = new Notification.Builder(mContext, "") .setContentText(Html.fromHtml("<b>bar</b>")); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -7094,14 +7090,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testVisualDifference_diffProgress() { Notification.Builder nb1 = new Notification.Builder(mContext, "") .setProgress(100, 90, false); - StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r1 = new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); Notification.Builder nb2 = new Notification.Builder(mContext, "") .setProgress(100, 100, false); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -7113,14 +7109,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testVisualDifference_diffProgressNotDone() { Notification.Builder nb1 = new Notification.Builder(mContext, "") .setProgress(100, 90, false); - StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r1 = new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); Notification.Builder nb2 = new Notification.Builder(mContext, "") .setProgress(100, 91, false); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -7132,14 +7128,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testVisualDifference_sameProgressStillDone() { Notification.Builder nb1 = new Notification.Builder(mContext, "") .setProgress(100, 100, false); - StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r1 = new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); Notification.Builder nb2 = new Notification.Builder(mContext, "") .setProgress(100, 100, false); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -7153,7 +7149,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setGroup("bananas") .setFlag(Notification.FLAG_GROUP_SUMMARY, true) .setContentText("foo"); - StatusBarNotification sbn1 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r1 = new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); @@ -7162,7 +7158,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setGroup("bananas") .setFlag(Notification.FLAG_GROUP_SUMMARY, true) .setContentText("bar"); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -7176,7 +7172,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setGroup("bananas") .setFlag(Notification.FLAG_GROUP_SUMMARY, true) .setContentText("bar"); - StatusBarNotification sbn2 = new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r2 = new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); @@ -7227,10 +7223,31 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertThat(mService.isVisuallyInterruptive(r1, r2)).isTrue(); } + @Test + @EnableFlags({android.app.Flags.FLAG_UPDATE_RANKING_TIME}) + public void testVisualDifference_userInitiatedJob() { + Notification.Builder nb1 = new Notification.Builder(mContext, "") + .setContentTitle("foo"); + StatusBarNotification sbn1 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, + nb1.build(), UserHandle.getUserHandleForUid(mUid), null, 0); + NotificationRecord r1 = + new NotificationRecord(mContext, sbn1, mock(NotificationChannel.class)); + + Notification.Builder nb2 = new Notification.Builder(mContext, "") + .setFlag(FLAG_USER_INITIATED_JOB, true) + .setContentTitle("bar"); + StatusBarNotification sbn2 = new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, + nb2.build(), UserHandle.getUserHandleForUid(mUid), null, 0); + NotificationRecord r2 = + new NotificationRecord(mContext, sbn2, mock(NotificationChannel.class)); + + assertFalse(mService.isVisuallyInterruptive(r1, r2)); + } + private NotificationRecord notificationToRecord(Notification n) { return new NotificationRecord( mContext, - new StatusBarNotification(PKG, PKG, 0, "tag", mUid, 0, n, + new StatusBarNotification(mPkg, mPkg, 0, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0), mock(NotificationChannel.class)); } @@ -7246,13 +7263,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(notif2); // on broadcast, hide the 2 notifications - simulatePackageSuspendBroadcast(true, PKG, notif1.getUid()); + simulatePackageSuspendBroadcast(true, mPkg, notif1.getUid()); ArgumentCaptor<List> captorHide = ArgumentCaptor.forClass(List.class); verify(mListeners, times(1)).notifyHiddenLocked(captorHide.capture()); assertEquals(2, captorHide.getValue().size()); // on broadcast, unhide the 2 notifications - simulatePackageSuspendBroadcast(false, PKG, notif1.getUid()); + simulatePackageSuspendBroadcast(false, mPkg, notif1.getUid()); ArgumentCaptor<List> captorUnhide = ArgumentCaptor.forClass(List.class); verify(mListeners, times(1)).notifyUnhiddenLocked(captorUnhide.capture()); assertEquals(2, captorUnhide.getValue().size()); @@ -7286,7 +7303,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(notif2); // on broadcast, nothing is hidden since no notifications are of user 10 with package PKG - simulatePackageSuspendBroadcast(true, PKG, 10); + simulatePackageSuspendBroadcast(true, mPkg, 10); ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(mListeners, times(1)).notifyHiddenLocked(captor.capture()); assertEquals(0, captor.getValue().size()); @@ -7467,7 +7484,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mContext, mTestNotificationChannel.getId()) .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "tag" + System.currentTimeMillis(), UserHandle.PER_USER_RANGE, 0, nb.build(), UserHandle.getUserHandleForUid(mUid + UserHandle.PER_USER_RANGE), null, 0); @@ -7490,7 +7507,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mContext, mTestNotificationChannel.getId()) .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "tag" + System.currentTimeMillis(), UserHandle.PER_USER_RANGE, 0, nb.build(), UserHandle.getUserHandleForUid(mUid + UserHandle.PER_USER_RANGE), null, 0); @@ -7540,31 +7557,31 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testBubble() throws Exception { - mBinderService.setBubblesAllowed(PKG, mUid, BUBBLE_PREFERENCE_NONE); - assertFalse(mBinderService.areBubblesAllowed(PKG)); - assertEquals(mBinderService.getBubblePreferenceForPackage(PKG, mUid), + mBinderService.setBubblesAllowed(mPkg, mUid, BUBBLE_PREFERENCE_NONE); + assertFalse(mBinderService.areBubblesAllowed(mPkg)); + assertEquals(mBinderService.getBubblePreferenceForPackage(mPkg, mUid), BUBBLE_PREFERENCE_NONE); } @Test public void testUserApprovedBubblesForPackageSelected() throws Exception { - mBinderService.setBubblesAllowed(PKG, mUid, BUBBLE_PREFERENCE_SELECTED); - assertEquals(mBinderService.getBubblePreferenceForPackage(PKG, mUid), + mBinderService.setBubblesAllowed(mPkg, mUid, BUBBLE_PREFERENCE_SELECTED); + assertEquals(mBinderService.getBubblePreferenceForPackage(mPkg, mUid), BUBBLE_PREFERENCE_SELECTED); } @Test public void testUserApprovedBubblesForPackageAll() throws Exception { - mBinderService.setBubblesAllowed(PKG, mUid, BUBBLE_PREFERENCE_ALL); - assertTrue(mBinderService.areBubblesAllowed(PKG)); - assertEquals(mBinderService.getBubblePreferenceForPackage(PKG, mUid), + mBinderService.setBubblesAllowed(mPkg, mUid, BUBBLE_PREFERENCE_ALL); + assertTrue(mBinderService.areBubblesAllowed(mPkg)); + assertEquals(mBinderService.getBubblePreferenceForPackage(mPkg, mUid), BUBBLE_PREFERENCE_ALL); } @Test public void testUserRejectsBubblesForPackage() throws Exception { - mBinderService.setBubblesAllowed(PKG, mUid, BUBBLE_PREFERENCE_NONE); - assertFalse(mBinderService.areBubblesAllowed(PKG)); + mBinderService.setBubblesAllowed(mPkg, mUid, BUBBLE_PREFERENCE_NONE); + assertFalse(mBinderService.areBubblesAllowed(mPkg)); } @Test @@ -7763,14 +7780,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification n = new Notification.Builder(mContext, "").build(); n.flags |= FLAG_FOREGROUND_SERVICE; - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 9, null, mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 9, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addEnqueuedNotification(r); mInternalService.removeForegroundServiceFlagFromNotification( - PKG, r.getSbn().getId(), r.getSbn().getUserId()); + mPkg, r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); @@ -7785,14 +7802,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification n = new Notification.Builder(mContext, "").build(); n.flags |= FLAG_FOREGROUND_SERVICE; - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 9, null, mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 9, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addNotification(r); mInternalService.removeForegroundServiceFlagFromNotification( - PKG, r.getSbn().getId(), r.getSbn().getUserId()); + mPkg, r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); @@ -7810,7 +7827,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(SHOW_IMMEDIATELY); for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) { Notification n = new Notification.Builder(mContext, "").build(); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, i, null, mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, i, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addEnqueuedNotification(r); @@ -7818,7 +7835,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification n = new Notification.Builder(mContext, "").build(); n.flags |= FLAG_FOREGROUND_SERVICE; - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -7826,7 +7843,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addEnqueuedNotification(r); mInternalService.removeForegroundServiceFlagFromNotification( - PKG, r.getSbn().getId(), r.getSbn().getUserId()); + mPkg, r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); @@ -7841,7 +7858,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(SHOW_IMMEDIATELY); for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) { Notification n = new Notification.Builder(mContext, "").build(); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, i, null, mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, i, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addNotification(r); @@ -7849,7 +7866,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification n = new Notification.Builder(mContext, "").build(); n.flags |= FLAG_FOREGROUND_SERVICE; - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -7857,7 +7874,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); mInternalService.removeForegroundServiceFlagFromNotification( - PKG, r.getSbn().getId(), r.getSbn().getUserId()); + mPkg, r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); @@ -8723,7 +8740,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon); - StatusBarNotification sbn = new StatusBarNotification(PKG, "opPkg", 0, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, "opPkg", 0, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -8745,7 +8762,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord r = generateNotificationRecord(mTestNotificationChannel); mService.addNotification(r); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, r.getSbn().getId(), + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, r.getSbn().getId(), r.getSbn().getTag(), mUid, 0, new Notification.Builder(mContext, mTestNotificationChannel.getId()).build(), UserHandle.getUserHandleForUid(mUid), null, 0); @@ -9073,7 +9090,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testFlagBubble() throws RemoteException { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -9081,11 +9098,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "testFlagBubble"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifs.length); assertTrue((notifs[0].getNotification().flags & FLAG_BUBBLE) != 0); assertTrue(mService.getNotificationRecord( @@ -9094,7 +9111,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testFlagBubble_noFlag_appNotAllowed() throws RemoteException { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_NONE /* app */, true /* channel */); @@ -9102,11 +9119,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "testFlagBubble_noFlag_appNotAllowed"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifs.length); assertEquals((notifs[0].getNotification().flags & FLAG_BUBBLE), 0); assertFalse(mService.getNotificationRecord( @@ -9115,7 +9132,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testFlagBubbleNotifs_noFlag_whenAppForeground() throws RemoteException { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -9126,14 +9143,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon) .setBubbleMetadata(getBubbleMetadata()); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel); // Say we're foreground when(mActivityManager.getPackageImportance(nr.getSbn().getPackageName())).thenReturn( IMPORTANCE_FOREGROUND); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -9145,7 +9162,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testFlagBubbleNotifs_flag_messaging() throws RemoteException { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -9153,7 +9170,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "testFlagBubbleNotifs_flag_messaging"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -9164,18 +9181,18 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testFlagBubbleNotifs_noFlag_noShortcut() throws RemoteException { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); Notification.Builder nb = getMessageStyleNotifBuilder(true, null, false); nb.setShortcutId(null); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, null, mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); - mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, sbn.getTag(), sbn.getId(), sbn.getNotification(), sbn.getUserId()); waitForIdle(); @@ -9186,7 +9203,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testFlagBubbleNotifs_noFlag_messaging_appNotAllowed() throws RemoteException { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_NONE /* app */, true /* channel */); @@ -9195,7 +9212,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { "testFlagBubbleNotifs_noFlag_messaging_appNotAllowed"); // Post the notification - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -9206,7 +9223,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testFlagBubbleNotifs_noFlag_notBubble() throws RemoteException { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -9215,13 +9232,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification.Builder nb = getMessageStyleNotifBuilder(false /* addBubbleMetadata */, null /* groupKey */, false /* isSummary */); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "testFlagBubbleNotifs_noFlag_notBubble", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel); // Post the notification - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -9232,7 +9249,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testFlagBubbleNotifs_noFlag_messaging_channelNotAllowed() throws RemoteException { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, false /* channel */); @@ -9242,7 +9259,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { nr.getChannel().lockFields(USER_LOCKED_ALLOW_BUBBLE); // Post the notification - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -9257,22 +9274,22 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { nrBubble.getSbn().getNotification().flags |= FLAG_BUBBLE; // Post the notification - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testAppCancelNotifications_cancelsBubbles", nrBubble.getSbn().getId(), nrBubble.getSbn().getNotification(), nrBubble.getSbn().getUserId()); waitForIdle(); - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifs.length); assertEquals(1, mService.getNotificationRecordCount()); - mBinderService.cancelNotificationWithTag(PKG, PKG, + mBinderService.cancelNotificationWithTag(mPkg, mPkg, "testAppCancelNotifications_cancelsBubbles", nrBubble.getSbn().getId(), nrBubble.getSbn().getUserId()); waitForIdle(); - StatusBarNotification[] notifs2 = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs2 = mBinderService.getActiveNotifications(mPkg); assertEquals(0, notifs2.length); assertEquals(0, mService.getNotificationRecordCount()); } @@ -9283,10 +9300,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { nr.getSbn().getNotification().flags |= FLAG_BUBBLE; mService.addNotification(nr); - mBinderService.cancelAllNotifications(PKG, nr.getSbn().getUserId()); + mBinderService.cancelAllNotifications(mPkg, nr.getSbn().getUserId()); waitForIdle(); - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertEquals(0, notifs.length); assertEquals(0, mService.getNotificationRecordCount()); } @@ -9303,7 +9320,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.getBinderService().cancelNotificationsFromListener(null, null); waitForIdle(); - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifs.length); assertEquals(1, mService.getNotificationRecordCount()); } @@ -9320,7 +9337,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Notif not active anymore - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertEquals(0, notifs.length); assertEquals(0, mService.getNotificationRecordCount()); // Cancel event is logged @@ -9332,13 +9349,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testCancelNotificationsFromListener_suppressesBubble() throws Exception { // Add bubble notif - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "tag"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -9348,7 +9365,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Bubble notif active and suppressed - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifs.length); assertEquals(1, mService.getNotificationRecordCount()); assertTrue(notifs[0].getNotification().getBubbleMetadata().isNotificationSuppressed()); @@ -9367,7 +9384,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // THEN the bubble notification does not get removed - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifs.length); assertEquals(1, mService.getNotificationRecordCount()); } @@ -9498,13 +9515,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { AutomaticZenRule rule = new AutomaticZenRule.Builder("rule", Uri.parse("uri")) .setType(AutomaticZenRule.TYPE_MANAGED) - .setOwner(new ComponentName(PKG, "cls")) + .setOwner(new ComponentName(mPkg, "cls")) .build(); when(mDevicePolicyManager.isActiveDeviceOwner(anyInt())).thenReturn(true); - mBinderService.addAutomaticZenRule(rule, PKG, /* fromUser= */ false); + mBinderService.addAutomaticZenRule(rule, mPkg, /* fromUser= */ false); - verify(zenModeHelper).addAutomaticZenRule(eq(PKG), eq(rule), anyInt(), any(), anyInt()); + verify(zenModeHelper).addAutomaticZenRule(eq(mPkg), eq(rule), anyInt(), any(), anyInt()); } @Test @@ -9526,27 +9543,27 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { ZenModeHelper zenModeHelper = setUpMockZenTest(); mService.setCallerIsNormalPackage(); reset(mPackageManagerInternal); - when(mPackageManagerInternal.isSameApp(eq(PKG), eq(mUid), anyInt())).thenReturn(true); + when(mPackageManagerInternal.isSameApp(eq(mPkg), eq(mUid), anyInt())).thenReturn(true); when(mResources .getString(com.android.internal.R.string.config_systemWellbeing)) - .thenReturn(PKG); + .thenReturn(mPkg); when(mContext.getResources()).thenReturn(mResources); AutomaticZenRule rule = new AutomaticZenRule.Builder("rule", Uri.parse("uri")) .setType(AutomaticZenRule.TYPE_BEDTIME) - .setOwner(new ComponentName(PKG, "cls")) + .setOwner(new ComponentName(mPkg, "cls")) .build(); - mBinderService.addAutomaticZenRule(rule, PKG, /* fromUser= */ false); + mBinderService.addAutomaticZenRule(rule, mPkg, /* fromUser= */ false); - verify(zenModeHelper).addAutomaticZenRule(eq(PKG), eq(rule), anyInt(), any(), anyInt()); + verify(zenModeHelper).addAutomaticZenRule(eq(mPkg), eq(rule), anyInt(), any(), anyInt()); } @Test @EnableFlags(android.app.Flags.FLAG_MODES_API) public void testAddAutomaticZenRule_typeBedtimeCanBeUsedBySystem() throws Exception { reset(mPackageManagerInternal); - when(mPackageManagerInternal.isSameApp(eq(PKG), eq(mUid), anyInt())).thenReturn(true); + when(mPackageManagerInternal.isSameApp(eq(mPkg), eq(mUid), anyInt())).thenReturn(true); addAutomaticZenRule_restrictedRuleTypeCanBeUsedBySystem(AutomaticZenRule.TYPE_BEDTIME); } @@ -9554,7 +9571,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @EnableFlags(android.app.Flags.FLAG_MODES_API) public void testAddAutomaticZenRule_typeBedtimeCannotBeUsedByRegularApps() throws Exception { reset(mPackageManagerInternal); - when(mPackageManagerInternal.isSameApp(eq(PKG), eq(mUid), anyInt())).thenReturn(true); + when(mPackageManagerInternal.isSameApp(eq(mPkg), eq(mUid), anyInt())).thenReturn(true); addAutomaticZenRule_restrictedRuleTypeCannotBeUsedByRegularApps( AutomaticZenRule.TYPE_BEDTIME); } @@ -9566,13 +9583,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { AutomaticZenRule rule = new AutomaticZenRule.Builder("rule", Uri.parse("uri")) .setType(ruleType) - .setOwner(new ComponentName(PKG, "cls")) + .setOwner(new ComponentName(mPkg, "cls")) .build(); when(mDevicePolicyManager.isActiveDeviceOwner(anyInt())).thenReturn(true); - mBinderService.addAutomaticZenRule(rule, PKG, /* fromUser= */ false); + mBinderService.addAutomaticZenRule(rule, mPkg, /* fromUser= */ false); - verify(zenModeHelper).addAutomaticZenRule(eq(PKG), eq(rule), anyInt(), any(), anyInt()); + verify(zenModeHelper).addAutomaticZenRule(eq(mPkg), eq(rule), anyInt(), any(), anyInt()); } private void addAutomaticZenRule_restrictedRuleTypeCannotBeUsedByRegularApps( @@ -9584,12 +9601,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { AutomaticZenRule rule = new AutomaticZenRule.Builder("rule", Uri.parse("uri")) .setType(ruleType) - .setOwner(new ComponentName(PKG, "cls")) + .setOwner(new ComponentName(mPkg, "cls")) .build(); when(mDevicePolicyManager.isActiveDeviceOwner(anyInt())).thenReturn(false); assertThrows(IllegalArgumentException.class, - () -> mBinderService.addAutomaticZenRule(rule, PKG, /* fromUser= */ false)); + () -> mBinderService.addAutomaticZenRule(rule, mPkg, /* fromUser= */ false)); } @Test @@ -9871,7 +9888,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testNotificationBubbleChanged_false() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -9880,7 +9897,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "testNotificationBubbleChanged_false"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -9888,7 +9905,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { reset(mListeners); // First we were a bubble - StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsBefore.length); assertTrue((notifsBefore[0].getNotification().flags & FLAG_BUBBLE) != 0); @@ -9897,14 +9914,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Make sure we are not a bubble - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsAfter.length); assertEquals((notifsAfter[0].getNotification().flags & FLAG_BUBBLE), 0); } @Test public void testNotificationBubbleChanged_true() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -9912,19 +9929,19 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Notif that is not a bubble NotificationRecord nr = generateNotificationRecord(mTestNotificationChannel, 1, null, false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); // Would be a normal notification because wouldn't have met requirements to bubble - StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsBefore.length); assertEquals((notifsBefore[0].getNotification().flags & FLAG_BUBBLE), 0); // Update the notification to be message style / meet bubble requirements NotificationRecord nr2 = generateMessageBubbleNotifRecord(mTestNotificationChannel, nr.getSbn().getTag()); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr2.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr2.getSbn().getTag(), nr2.getSbn().getId(), nr2.getSbn().getNotification(), nr2.getSbn().getUserId()); waitForIdle(); @@ -9936,21 +9953,21 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Make sure we are a bubble - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsAfter.length); assertTrue((notifsAfter[0].getNotification().flags & FLAG_BUBBLE) != 0); } @Test public void testNotificationBubbleChanged_true_notAllowed() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); // Notif that is not a bubble NotificationRecord nr = generateNotificationRecord(mTestNotificationChannel); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -9958,7 +9975,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { reset(mListeners); // Would be a normal notification because wouldn't have met requirements to bubble - StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsBefore.length); assertEquals((notifsBefore[0].getNotification().flags & FLAG_BUBBLE), 0); @@ -9967,14 +9984,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // We still wouldn't be a bubble because the notification didn't meet requirements - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsAfter.length); assertEquals((notifsAfter[0].getNotification().flags & FLAG_BUBBLE), 0); } @Test public void testNotificationBubbleIsFlagRemoved_resetOnUpdate() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -9983,7 +10000,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "testNotificationBubbleIsFlagRemoved_resetOnUpdate"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); // Flag shouldn't be modified @@ -9999,7 +10016,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Update the notif - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); // And the flag is reset @@ -10009,7 +10026,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testNotificationBubbleIsFlagRemoved_resetOnBubbleChangedTrue() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -10018,7 +10035,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "testNotificationBubbleIsFlagRemoved_trueOnBubbleChangedTrue"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); // Flag shouldn't be modified @@ -10041,7 +10058,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testOnBubbleMetadataFlagChanged() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -10051,12 +10068,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Set this so that the bubble can be suppressed nr.getNotification().getBubbleMetadata().setFlags( Notification.BubbleMetadata.FLAG_SUPPRESSABLE_BUBBLE); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); // Check the flags - Notification n = mBinderService.getActiveNotifications(PKG)[0].getNotification(); + Notification n = mBinderService.getActiveNotifications(mPkg)[0].getNotification(); assertFalse(n.getBubbleMetadata().isNotificationSuppressed()); assertFalse(n.getBubbleMetadata().getAutoExpandBubble()); assertFalse(n.getBubbleMetadata().isBubbleSuppressed()); @@ -10074,7 +10091,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Check - n = mBinderService.getActiveNotifications(PKG)[0].getNotification(); + n = mBinderService.getActiveNotifications(mPkg)[0].getNotification(); assertEquals(flags, n.getBubbleMetadata().getFlags()); // Reset to check again @@ -10085,7 +10102,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Check - n = mBinderService.getActiveNotifications(PKG)[0].getNotification(); + n = mBinderService.getActiveNotifications(mPkg)[0].getNotification(); assertEquals(0, n.getBubbleMetadata().getFlags()); } @@ -10093,14 +10110,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testOnBubbleMetadataChangedToSuppressNotification_soundStopped() throws RemoteException { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); // Post a bubble notification NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "tag"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -10120,12 +10137,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { : USER_SYSTEM; NotificationRecord nr = generateNotificationRecord(mTestNotificationChannel, userId); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); // A notification exists for the given record - StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsBefore.length); reset(mPackageManager); @@ -10152,7 +10169,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // No notifications exist for the given record - StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(mPkg); assertEquals(0, notifsBefore.length); Uri uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 1); @@ -10172,12 +10189,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // generate a NotificationRecord for USER_ALL to make sure it's converted into USER_SYSTEM NotificationRecord nr = generateNotificationRecord(mTestNotificationChannel, UserHandle.USER_ALL); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); // A notification exists for the given record - StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsBefore = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsBefore.length); reset(mPackageManager); @@ -10202,13 +10219,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { int otherUserId = 11; NotificationRecord nr = generateNotificationRecord(mTestNotificationChannel, otherUserId); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); // A notification exists for the given record List<StatusBarNotification> notifsBefore = - mBinderService.getAppActiveNotifications(PKG, nr.getSbn().getUserId()).getList(); + mBinderService.getAppActiveNotifications(mPkg, nr.getSbn().getUserId()).getList(); assertEquals(1, notifsBefore.size()); reset(mPackageManager); @@ -10310,7 +10327,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testNotificationBubbles_disabled_lowRamDevice() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -10321,12 +10338,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Notification that would typically bubble NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "testNotificationBubbles_disabled_lowRamDevice"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); // But we wouldn't be a bubble because the device is low ram & all bubbles are disabled. - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsAfter.length); assertEquals((notifsAfter[0].getNotification().flags & FLAG_BUBBLE), 0); } @@ -10381,7 +10398,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertNotNull(n.publicVersion.bigContentView); assertNotNull(n.publicVersion.headsUpContentView); - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); assertNull(n.contentView); assertNull(n.bigContentView); @@ -10390,13 +10407,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertNull(n.publicVersion.bigContentView); assertNull(n.publicVersion.headsUpContentView); - verify(mUsageStats, times(5)).registerImageRemoved(PKG); + verify(mUsageStats, times(5)).registerImageRemoved(mPkg); } @Test public void testNotificationBubbles_flagAutoExpandForeground_fails_notForeground() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -10412,7 +10429,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mActivityManager.getPackageImportance(nr.getSbn().getPackageName())).thenReturn( IMPORTANCE_VISIBLE); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -10427,7 +10444,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testNotificationBubbles_flagAutoExpandForeground_succeeds_foreground() throws RemoteException { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -10443,7 +10460,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mActivityManager.getPackageImportance(nr.getSbn().getPackageName())).thenReturn( IMPORTANCE_FOREGROUND); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -10459,7 +10476,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testNotificationBubbles_flagRemoved_whenShortcutRemoved() throws RemoteException { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -10474,12 +10491,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { null /* groupKey */, false /* isSummary */); nb.setShortcutId(VALID_CONVO_SHORTCUT_ID); nb.setBubbleMetadata(metadata); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel); // Test: Send the bubble notification - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -10494,12 +10511,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Make sure the shortcut is cached. verify(mShortcutServiceInternal).cacheShortcuts( - anyInt(), any(), eq(PKG), eq(singletonList(VALID_CONVO_SHORTCUT_ID)), + anyInt(), any(), eq(mPkg), eq(singletonList(VALID_CONVO_SHORTCUT_ID)), eq(USER_SYSTEM), eq(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS)); // Test: Remove the shortcut when(mLauncherApps.getShortcuts(any(), any())).thenReturn(null); - launcherAppsCallback.getValue().onShortcutsChanged(PKG, emptyList(), + launcherAppsCallback.getValue().onShortcutsChanged(mPkg, emptyList(), UserHandle.getUserHandleForUid(mUid)); waitForIdle(); @@ -10519,7 +10536,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testNotificationBubbles_shortcut_stopListeningWhenNotifRemoved() throws RemoteException { final String shortcutId = "someshortcutId"; - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -10534,14 +10551,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { null /* groupKey */, false /* isSummary */); nb.setShortcutId(shortcutId); nb.setBubbleMetadata(metadata); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel); // Pretend the shortcut exists List<ShortcutInfo> shortcutInfos = new ArrayList<>(); ShortcutInfo info = mock(ShortcutInfo.class); - when(info.getPackage()).thenReturn(PKG); + when(info.getPackage()).thenReturn(mPkg); when(info.getId()).thenReturn(shortcutId); when(info.getUserId()).thenReturn(USER_SYSTEM); when(info.isLongLived()).thenReturn(true); @@ -10552,7 +10569,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { anyString(), anyInt(), any())).thenReturn(true); // Test: Send the bubble notification - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -10567,11 +10584,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Make sure the shortcut is cached. verify(mShortcutServiceInternal).cacheShortcuts( - anyInt(), any(), eq(PKG), eq(singletonList(shortcutId)), + anyInt(), any(), eq(mPkg), eq(singletonList(shortcutId)), eq(USER_SYSTEM), eq(ShortcutInfo.FLAG_CACHED_NOTIFICATIONS)); // Test: Remove the notification - mBinderService.cancelNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getUserId()); waitForIdle(); @@ -10584,7 +10601,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testNotificationBubbles_bubbleChildrenStay_whenGroupSummaryDismissed() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -10595,21 +10612,21 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Dismiss summary final NotificationVisibility nv = NotificationVisibility.obtain(nrSummary.getKey(), 1, 2, true); - mService.mNotificationDelegate.onNotificationClear(mUid, 0, PKG, + mService.mNotificationDelegate.onNotificationClear(mUid, 0, mPkg, nrSummary.getUserId(), nrSummary.getKey(), NotificationStats.DISMISSAL_SHADE, NotificationStats.DISMISS_SENTIMENT_NEUTRAL, nv); waitForIdle(); // The bubble should still exist - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsAfter.length); } @Test public void testNotificationBubbles_bubbleChildrenStay_whenGroupSummaryClicked() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -10625,7 +10642,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // The bubble should still exist - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsAfter.length); // Check we got the click log and associated dismissal logs @@ -10643,7 +10660,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testNotificationBubbles_bubbleStays_whenClicked() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -10660,7 +10677,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // THEN the bubble should still exist - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsAfter.length); // Check we got the click log @@ -10677,7 +10694,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testNotificationBubbles_bubbleStays_whenClicked_afterBubbleDismissed() throws Exception { - setUpPrefsForBubbles(PKG, mUid, + setUpPrefsForBubbles(mPkg, mUid, true /* global */, BUBBLE_PREFERENCE_ALL /* app */, true /* channel */); @@ -10701,7 +10718,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // THEN the bubble should still exist - StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifsAfter = mBinderService.getActiveNotifications(mPkg); assertEquals(1, notifsAfter.length); // Check we got the click log @@ -10761,7 +10778,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testHandleOnPackageChanged() { - String[] pkgs = new String[] {PKG, PKG_N_MR1}; + String[] pkgs = new String[] {mPkg, PKG_N_MR1}; int[] uids = new int[] {mUid, UserHandle.PER_USER_RANGE + 1}; mService.handleOnPackageChanged(false, USER_SYSTEM, pkgs, uids); @@ -10788,25 +10805,25 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(1, notifs.length); // Cancels all notifications. - mService.cancelAllNotificationsInt(mUid, 0, PKG, null, 0, 0, + mService.cancelAllNotificationsInt(mUid, 0, mPkg, null, 0, 0, notif.getUserId(), REASON_CANCEL); waitForIdle(); notifs = mBinderService.getActiveNotifications(notif.getSbn().getPackageName()); assertEquals(0, notifs.length); // Checks that notification history's recently canceled archive contains the notification. - notifs = mBinderService.getHistoricalNotificationsWithAttribution(PKG, + notifs = mBinderService.getHistoricalNotificationsWithAttribution(mPkg, mContext.getAttributionTag(), 5 /* count */, false /* includeSnoozed */); waitForIdle(); assertEquals(1, notifs.length); // Remove sthe package that contained the channel - simulatePackageRemovedBroadcast(PKG, mUid); + simulatePackageRemovedBroadcast(mPkg, mUid); waitForIdle(); // Checks that notification history no longer contains the notification. notifs = mBinderService.getHistoricalNotificationsWithAttribution( - PKG, mContext.getAttributionTag(), 5 /* count */, false /* includeSnoozed */); + mPkg, mContext.getAttributionTag(), 5 /* count */, false /* includeSnoozed */); waitForIdle(); assertEquals(0, notifs.length); } @@ -10815,7 +10832,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testNotificationHistory_addNoisyNotification() throws Exception { NotificationRecord nr = generateNotificationRecord(mTestNotificationChannel, null /* tvExtender */); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -10839,14 +10856,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertEquals(original, orig); assertFalse(TextUtils.isEmpty(orig.getName())); - mBinderService.createNotificationChannels(PKG, new ParceledListSlice(Arrays.asList( + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList( orig))); mBinderService.createConversationNotificationChannelForPackage( - PKG, mUid, orig, "friend"); + mPkg, mUid, orig, "friend"); NotificationChannel friendChannel = mBinderService.getConversationNotificationChannel( - PKG, userId, PKG, original.getId(), false, "friend"); + mPkg, userId, mPkg, original.getId(), false, "friend"); assertEquals(original.getName(), friendChannel.getName()); assertEquals(original.getId(), friendChannel.getParentChannelId()); @@ -10911,15 +10928,15 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannel parentChannel = parcelAndUnparcel(originalChannel, NotificationChannel.CREATOR); assertEquals(originalChannel, parentChannel); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(parentChannel))); //Create deleted conversation channel mBinderService.createConversationNotificationChannelForPackage( - PKG, mUid, parentChannel, VALID_CONVO_SHORTCUT_ID); + mPkg, mUid, parentChannel, VALID_CONVO_SHORTCUT_ID); final NotificationChannel conversationChannel = mBinderService.getConversationNotificationChannel( - PKG, mUserId, PKG, originalChannel.getId(), false, VALID_CONVO_SHORTCUT_ID); + mPkg, mUserId, mPkg, originalChannel.getId(), false, VALID_CONVO_SHORTCUT_ID); conversationChannel.setDeleted(true); //Create notification record @@ -10927,12 +10944,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { null /* groupKey */, false /* isSummary */); nb.setShortcutId(VALID_CONVO_SHORTCUT_ID); nb.setChannelId(originalChannel.getId()); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, originalChannel); assertThat(nr.getChannel()).isEqualTo(originalChannel); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -10954,7 +10971,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannel parentChannel = parcelAndUnparcel(originalChannel, NotificationChannel.CREATOR); assertEquals(originalChannel, parentChannel); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(parentChannel))); parentChannel.setDeleted(true); @@ -10963,14 +10980,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { null /* groupKey */, false /* isSummary */); nb.setShortcutId(VALID_CONVO_SHORTCUT_ID); nb.setChannelId(originalChannel.getId()); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, originalChannel); assertThat(nr.getChannel()).isEqualTo(originalChannel); when(mPermissionHelper.hasPermission(mUid)).thenReturn(true); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -10992,27 +11009,27 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannel parentChannel = parcelAndUnparcel(originalChannel, NotificationChannel.CREATOR); assertEquals(originalChannel, parentChannel); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(parentChannel))); //Create conversation channel mBinderService.createConversationNotificationChannelForPackage( - PKG, mUid, parentChannel, VALID_CONVO_SHORTCUT_ID); + mPkg, mUid, parentChannel, VALID_CONVO_SHORTCUT_ID); final NotificationChannel conversationChannel = mBinderService.getConversationNotificationChannel( - PKG, mUserId, PKG, originalChannel.getId(), false, VALID_CONVO_SHORTCUT_ID); + mPkg, mUserId, mPkg, originalChannel.getId(), false, VALID_CONVO_SHORTCUT_ID); //Create notification record Notification.Builder nb = getMessageStyleNotifBuilder(false /* addDefaultMetadata */, null /* groupKey */, false /* isSummary */); nb.setShortcutId(VALID_CONVO_SHORTCUT_ID); nb.setChannelId(originalChannel.getId()); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, originalChannel); assertThat(nr.getChannel()).isEqualTo(originalChannel); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -11037,27 +11054,27 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannel parentChannel = parcelAndUnparcel(originalChannel, NotificationChannel.CREATOR); assertEquals(originalChannel, parentChannel); - mBinderService.createNotificationChannels(PKG, + mBinderService.createNotificationChannels(mPkg, new ParceledListSlice(Arrays.asList(parentChannel))); //Create deleted conversation channel mBinderService.createConversationNotificationChannelForPackage( - PKG, mUid, parentChannel, VALID_CONVO_SHORTCUT_ID); + mPkg, mUid, parentChannel, VALID_CONVO_SHORTCUT_ID); final NotificationChannel conversationChannel = mBinderService.getConversationNotificationChannel( - PKG, mUserId, PKG, originalChannel.getId(), false, VALID_CONVO_SHORTCUT_ID); + mPkg, mUserId, mPkg, originalChannel.getId(), false, VALID_CONVO_SHORTCUT_ID); //Create notification record without a shortcutId Notification.Builder nb = getMessageStyleNotifBuilder(false /* addDefaultMetadata */, null /* groupKey */, false /* isSummary */); nb.setShortcutId(null); nb.setChannelId(originalChannel.getId()); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, originalChannel); assertThat(nr.getChannel()).isEqualTo(originalChannel); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -11173,7 +11190,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { generateMessageBubbleNotifRecord(mTestNotificationChannel, "testShortcutHelperNull_doesntCrashEnqueue"); try { - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); } catch (Exception e) { @@ -11252,23 +11269,23 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testRecordMessages_invalidMsg_afterValidMsg() throws RemoteException { NotificationRecord nr = generateMessageBubbleNotifRecord(mTestNotificationChannel, "testRecordMessages_invalidMsg_afterValidMsg_1"); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); assertTrue(mService.getNotificationRecord(nr.getKey()).isConversation()); - mBinderService.cancelAllNotifications(PKG, mUid); + mBinderService.cancelAllNotifications(mPkg, mUid); waitForIdle(); Notification.Builder nb = getMessageStyleNotifBuilder(false /* addDefaultMetadata */, null /* groupKey */, false /* isSummary */); nb.setShortcutId(null); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, "testRecordMessages_invalidMsg_afterValidMsg_2", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel); - mBinderService.enqueueNotificationWithTag(PKG, PKG, nr.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -11283,14 +11300,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) { StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel, i, null, false).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCanPostFgsWhenOverLimit", sbn.getId(), sbn.getNotification(), sbn.getUserId()); } final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCanPostFgsWhenOverLimit - fgs over limit!", sbn.getId(), sbn.getNotification(), sbn.getUserId()); @@ -11311,7 +11328,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) { StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel, i, null, false).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCanPostFgsWhenOverLimit", sbn.getId(), sbn.getNotification(), sbn.getUserId()); waitForIdle(); @@ -11320,13 +11337,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel, 100, null, false).getSbn(); sbn.getNotification().flags |= FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCanPostFgsWhenOverLimit - fgs over limit!", sbn.getId(), sbn.getNotification(), sbn.getUserId()); final StatusBarNotification sbn2 = generateNotificationRecord(mTestNotificationChannel, 101, null, false).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCanPostFgsWhenOverLimit - non fgs over limit!", sbn2.getId(), sbn2.getNotification(), sbn2.getUserId()); @@ -11337,7 +11354,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final StatusBarNotification sbn3 = generateNotificationRecord(mTestNotificationChannel, 101, null, false).getSbn(); sbn3.getNotification().flags |= FLAG_FOREGROUND_SERVICE; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCanPostFgsWhenOverLimit - fake fgs over limit!", sbn3.getId(), sbn3.getNotification(), sbn3.getUserId()); @@ -11486,7 +11503,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord r = generateMessageBubbleNotifRecord(true, mTestNotificationChannel, 7, "testImmutableBubbleIntent", null, false); try { - mBinderService.enqueueNotificationWithTag(PKG, PKG, r.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, r.getSbn().getTag(), r.getSbn().getId(), r.getNotification(), r.getSbn().getUserId()); waitForIdle(); @@ -11503,7 +11520,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord r = generateMessageBubbleNotifRecord(true, mTestNotificationChannel, 7, "testMutableBubbleIntent", null, false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, r.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, r.getSbn().getTag(), r.getSbn().getId(), r.getNotification(), r.getSbn().getUserId()); waitForIdle(); @@ -11519,7 +11536,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord r = generateMessageBubbleNotifRecord(false, mTestNotificationChannel, 7, "testImmutableDirectReplyActionIntent", null, false); try { - mBinderService.enqueueNotificationWithTag(PKG, PKG, r.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, r.getSbn().getTag(), r.getSbn().getId(), r.getNotification(), r.getSbn().getUserId()); waitForIdle(); @@ -11535,7 +11552,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(FLAG_MUTABLE | FLAG_ONE_SHOT); NotificationRecord r = generateMessageBubbleNotifRecord(false, mTestNotificationChannel, 7, "testMutableDirectReplyActionIntent", null, false); - mBinderService.enqueueNotificationWithTag(PKG, PKG, r.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, r.getSbn().getTag(), r.getSbn().getId(), r.getNotification(), r.getSbn().getUserId()); waitForIdle(); @@ -11609,7 +11626,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(FLAG_IMMUTABLE | FLAG_ONE_SHOT); NotificationRecord r = generateNotificationRecord(mTestNotificationChannel); - mBinderService.enqueueNotificationWithTag(PKG, PKG, r.getSbn().getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, r.getSbn().getTag(), r.getSbn().getId(), r.getNotification(), r.getSbn().getUserId()); waitForIdle(); @@ -11779,9 +11796,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { when(mPermissionHelper.hasPermission(mUid)).thenReturn(false); - assertThat(mBinderService.getNotificationChannelsBypassingDnd(PKG, mUid).getList()) + assertThat(mBinderService.getNotificationChannelsBypassingDnd(mPkg, mUid).getList()) .isEmpty(); - verify(mPreferencesHelper, never()).getNotificationChannelsBypassingDnd(PKG, mUid); + verify(mPreferencesHelper, never()).getNotificationChannelsBypassingDnd(mPkg, mUid); } @Test @@ -11873,7 +11890,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon) .addAction(new Notification.Action.Builder(null, "test", null).build()); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -11885,7 +11902,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // just using the style - blocked nb.setStyle(new Notification.MediaStyle()); - sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -11897,7 +11914,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Bundle extras = new Bundle(); extras.putParcelable(Notification.EXTRA_MEDIA_SESSION, new Intent()); nb.addExtras(extras); - sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -11906,7 +11923,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // style + media session - bypasses block nb.setStyle(new Notification.MediaStyle().setMediaSession(mock(MediaSession.Token.class))); - sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -11924,7 +11941,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon) .addAction(new Notification.Action.Builder(null, "test", null).build()); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -11944,7 +11961,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.clearNotifications(); reset(mUsageStats); nb.setStyle(new Notification.MediaStyle()); - sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -11961,7 +11978,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.clearNotifications(); reset(mUsageStats); nb.setStyle(new Notification.MediaStyle().setMediaSession(mock(MediaSession.Token.class))); - sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -11986,7 +12003,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon) .addAction(new Notification.Action.Builder(null, "test", null).build()); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -12003,7 +12020,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { nb.setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))); nb.setFullScreenIntent(mock(PendingIntent.class), true); - sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -12051,7 +12068,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon) .addAction(new Notification.Action.Builder(null, "test", null).build()); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -12072,7 +12089,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Person person = new Person.Builder().setName("caller").build(); nb.setStyle(Notification.CallStyle.forOngoingCall(person, mock(PendingIntent.class))); nb.setFullScreenIntent(mock(PendingIntent.class), true); - sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, nb.build(), + sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -12194,21 +12211,21 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord nr0 = generateNotificationRecord(mTestNotificationChannel, mUserId); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag0", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag0", nr0.getSbn().getId(), nr0.getSbn().getNotification(), nr0.getSbn().getUserId()); NotificationRecord nr10 = generateNotificationRecord(mTestNotificationChannel, 10); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag10", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag10", nr10.getSbn().getId(), nr10.getSbn().getNotification(), nr10.getSbn().getUserId()); NotificationRecord nr11 = generateNotificationRecord(mTestNotificationChannel, 11); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag11", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag11", nr11.getSbn().getId(), nr11.getSbn().getNotification(), nr11.getSbn().getUserId()); waitForIdle(); - StatusBarNotification[] notifs = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifs = mBinderService.getActiveNotifications(mPkg); assertEquals(2, notifs.length); for (StatusBarNotification sbn : notifs) { if (sbn.getUserId() == 11) { @@ -12297,9 +12314,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { VISIBILITY_PRIVATE)); // cancel both children - mBinderService.cancelNotificationWithTag(PKG, PKG, nr0.getSbn().getTag(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, nr0.getSbn().getTag(), nr0.getSbn().getId(), nr0.getSbn().getUserId()); - mBinderService.cancelNotificationWithTag(PKG, PKG, nr1.getSbn().getTag(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, nr1.getSbn().getTag(), nr1.getSbn().getId(), nr1.getSbn().getUserId()); waitForIdle(); @@ -12339,9 +12356,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { nr0_all.getKey(), GroupHelper.BASE_FLAGS, mock(Icon.class), 0, VISIBILITY_PRIVATE)); // cancel both children for USER_ALL - mBinderService.cancelNotificationWithTag(PKG, PKG, nr0_all.getSbn().getTag(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, nr0_all.getSbn().getTag(), nr0_all.getSbn().getId(), UserHandle.USER_ALL); - mBinderService.cancelNotificationWithTag(PKG, PKG, nr1_all.getSbn().getTag(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, nr1_all.getSbn().getTag(), nr1_all.getSbn().getId(), UserHandle.USER_ALL); waitForIdle(); @@ -12641,7 +12658,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { boolean isSticky) throws Exception { when(mPermissionHelper.hasRequestedPermission(Manifest.permission.USE_FULL_SCREEN_INTENT, - PKG, mUserId)).thenReturn(appRequested); + mPkg, mUserId)).thenReturn(appRequested); when(mPermissionManager.checkPermissionForDataDelivery( eq(Manifest.permission.USE_FULL_SCREEN_INTENT), any(), any())) @@ -12651,7 +12668,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setFullScreenIntent(mock(PendingIntent.class), true) .build(); - mService.fixNotification(n, PKG, "tag", 9, mUserId, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, mUserId, mUid, NOT_FOREGROUND_SERVICE, true); final int stickyFlag = n.flags & Notification.FLAG_FSI_REQUESTED_BUT_DENIED; @@ -12705,7 +12722,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setFlag(FLAG_CAN_COLORIZE, true) .build(); - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); assertFalse(n.isForegroundService()); assertFalse(n.hasColorizedPermission()); @@ -12718,7 +12735,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -12739,7 +12756,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -12769,7 +12786,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { if (isExpired) { timePostedMs -= BITMAP_DURATION.toMillis(); } - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, notification, UserHandle.getUserHandleForUid(mUid), null, timePostedMs); return new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -12899,7 +12916,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -12916,7 +12933,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -12932,7 +12949,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -12948,7 +12965,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setStyle(Notification.CallStyle.forOngoingCall( person, mock(PendingIntent.class))) .build(); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 8, "tag", mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -12976,7 +12993,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertSame(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -12993,7 +13010,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -13019,7 +13036,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -13039,7 +13056,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -13054,7 +13071,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -13070,7 +13087,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { n.flags |= Notification.FLAG_NO_DISMISS; // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should be cleared assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -13086,7 +13103,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -13105,7 +13122,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { n.flags |= Notification.FLAG_NO_DISMISS; // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should be cleared assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -13120,7 +13137,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -13137,7 +13154,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -13147,7 +13164,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void fixExemptAppOpNotification_withFlag_shouldBeNonDismissible() throws Exception { final ApplicationInfo ai = new ApplicationInfo(); - ai.packageName = PKG; + ai.packageName = mPkg; ai.uid = mUid; ai.flags |= ApplicationInfo.FLAG_SYSTEM; @@ -13155,7 +13172,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(ai); when(mAppOpsManager.checkOpNoThrow( AppOpsManager.OP_SYSTEM_EXEMPT_FROM_DISMISSIBLE_NOTIFICATIONS, mUid, - PKG)).thenReturn(AppOpsManager.MODE_ALLOWED); + mPkg)).thenReturn(AppOpsManager.MODE_ALLOWED); // Given: a notification has the flag FLAG_ONGOING_EVENT set setDpmAppOppsExemptFromDismissal(true); Notification n = new Notification.Builder(mContext, "test") @@ -13163,7 +13180,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should be cleared assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -13174,7 +13191,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { throws Exception { when(mAppOpsManager.checkOpNoThrow( AppOpsManager.OP_SYSTEM_EXEMPT_FROM_DISMISSIBLE_NOTIFICATIONS, mUid, - PKG)).thenReturn(AppOpsManager.MODE_ALLOWED); + mPkg)).thenReturn(AppOpsManager.MODE_ALLOWED); // Given: a notification has the flag FLAG_ONGOING_EVENT set setDpmAppOppsExemptFromDismissal(false); Notification n = new Notification.Builder(mContext, "test") @@ -13182,7 +13199,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertSame(0, n.flags & Notification.FLAG_NO_DISMISS); @@ -13194,10 +13211,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(true); final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags |= FLAG_USER_INITIATED_JOB; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotifications_IgnoreUserInitiatedJob", sbn.getId(), sbn.getNotification(), sbn.getUserId()); - mBinderService.cancelAllNotifications(PKG, sbn.getUserId()); + mBinderService.cancelAllNotifications(mPkg, sbn.getUserId()); waitForIdle(); StatusBarNotification[] notifs = mBinderService.getActiveNotifications(sbn.getPackageName()); @@ -13211,10 +13228,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(false); final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags |= FLAG_USER_INITIATED_JOB; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotifications_UijFlag_NoUij_Allowed", sbn.getId(), sbn.getNotification(), sbn.getUserId()); - mBinderService.cancelAllNotifications(PKG, sbn.getUserId()); + mBinderService.cancelAllNotifications(mPkg, sbn.getUserId()); waitForIdle(); StatusBarNotification[] notifs = mBinderService.getActiveNotifications(sbn.getPackageName()); @@ -13227,7 +13244,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(true); final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags |= FLAG_USER_INITIATED_JOB; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCancelAllNotifications_IgnoreOtherPackages", sbn.getId(), sbn.getNotification(), sbn.getUserId()); mBinderService.cancelAllNotifications("other_pkg_name", sbn.getUserId()); @@ -13248,9 +13265,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); sbn.getNotification().flags |= FLAG_USER_INITIATED_JOB; - mBinderService.enqueueNotificationWithTag(PKG, PKG, null, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, null, sbn.getId(), sbn.getNotification(), sbn.getUserId()); - mInternalService.removeUserInitiatedJobFlagFromNotification(PKG, sbn.getId(), + mInternalService.removeUserInitiatedJobFlagFromNotification(mPkg, sbn.getId(), sbn.getUserId()); waitForIdle(); StatusBarNotification[] notifs = @@ -13262,12 +13279,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testCancelAfterSecondEnqueueDoesNotSpecifyUserInitiatedJobFlag() throws Exception { final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags = Notification.FLAG_ONGOING_EVENT | FLAG_USER_INITIATED_JOB; - mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, sbn.getTag(), sbn.getId(), sbn.getNotification(), sbn.getUserId()); sbn.getNotification().flags = Notification.FLAG_ONGOING_EVENT; - mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, sbn.getTag(), sbn.getId(), sbn.getNotification(), sbn.getUserId()); - mBinderService.cancelNotificationWithTag(PKG, PKG, sbn.getTag(), sbn.getId(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, sbn.getTag(), sbn.getId(), sbn.getUserId()); waitForIdle(); assertEquals(0, mBinderService.getActiveNotifications(sbn.getPackageName()).length); @@ -13535,10 +13552,10 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testDeleteChannelGroupChecksForUijs() throws Exception { - when(mCompanionMgr.getAssociations(PKG, UserHandle.getUserId(mUid))) + when(mCompanionMgr.getAssociations(mPkg, UserHandle.getUserId(mUid))) .thenReturn(singletonList(mock(AssociationInfo.class))); CountDownLatch latch = new CountDownLatch(2); - mService.createNotificationChannelGroup(PKG, mUid, + mService.createNotificationChannelGroup(mPkg, mUid, new NotificationChannelGroup("group", "group"), true, false); new Thread(() -> { NotificationChannel notificationChannel = new NotificationChannel("id", "id", @@ -13547,7 +13564,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { ParceledListSlice<NotificationChannel> pls = new ParceledListSlice(ImmutableList.of(notificationChannel)); try { - mBinderService.createNotificationChannelsForPackage(PKG, mUid, pls); + mBinderService.createNotificationChannelsForPackage(mPkg, mUid, pls); } catch (RemoteException e) { throw new RuntimeException(e); } @@ -13558,7 +13575,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { synchronized (this) { wait(5000); } - mService.createNotificationChannelGroup(PKG, mUid, + mService.createNotificationChannelGroup(mPkg, mUid, new NotificationChannelGroup("new", "new group"), true, false); NotificationChannel notificationChannel = new NotificationChannel("id", "id", NotificationManager.IMPORTANCE_HIGH); @@ -13566,8 +13583,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { ParceledListSlice<NotificationChannel> pls = new ParceledListSlice(ImmutableList.of(notificationChannel)); try { - mBinderService.createNotificationChannelsForPackage(PKG, mUid, pls); - mBinderService.deleteNotificationChannelGroup(PKG, "group"); + mBinderService.createNotificationChannelsForPackage(mPkg, mUid, pls); + mBinderService.deleteNotificationChannelGroup(mPkg, "group"); } catch (RemoteException e) { throw new RuntimeException(e); } @@ -13589,14 +13606,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification n = new Notification.Builder(mContext, "").build(); n.flags |= FLAG_USER_INITIATED_JOB; - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 9, null, mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 9, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addEnqueuedNotification(r); mInternalService.removeUserInitiatedJobFlagFromNotification( - PKG, r.getSbn().getId(), r.getSbn().getUserId()); + mPkg, r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); @@ -13610,14 +13627,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification n = new Notification.Builder(mContext, "").build(); n.flags |= FLAG_USER_INITIATED_JOB; - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 9, null, mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 9, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addNotification(r); mInternalService.removeUserInitiatedJobFlagFromNotification( - PKG, r.getSbn().getId(), r.getSbn().getUserId()); + mPkg, r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); @@ -13632,7 +13649,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void testCannotRemoveUserInitiatedJobFlagWhenOverLimit_enqueued() { for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) { Notification n = new Notification.Builder(mContext, "").build(); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, i, null, mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, i, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addEnqueuedNotification(r); @@ -13640,7 +13657,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification n = new Notification.Builder(mContext, "").build(); n.flags |= FLAG_USER_INITIATED_JOB; - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -13648,7 +13665,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addEnqueuedNotification(r); mInternalService.removeUserInitiatedJobFlagFromNotification( - PKG, r.getSbn().getId(), r.getSbn().getUserId()); + mPkg, r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); @@ -13662,7 +13679,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(true); for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) { Notification n = new Notification.Builder(mContext, "").build(); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, i, null, mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, i, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mService.addNotification(r); @@ -13670,7 +13687,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { Notification n = new Notification.Builder(mContext, "").build(); n.flags |= FLAG_USER_INITIATED_JOB; - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS, null, mUid, 0, n, UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel); @@ -13678,7 +13695,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mService.addNotification(r); mInternalService.removeUserInitiatedJobFlagFromNotification( - PKG, r.getSbn().getId(), r.getSbn().getUserId()); + mPkg, r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); @@ -13693,13 +13710,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) { StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel, i, null, false).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testCanPostUijWhenOverLimit", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCanPostUijWhenOverLimit", sbn.getId(), sbn.getNotification(), sbn.getUserId()); } final StatusBarNotification sbn = generateNotificationRecord(null).getSbn(); sbn.getNotification().flags |= FLAG_USER_INITIATED_JOB; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCanPostUijWhenOverLimit - uij over limit!", sbn.getId(), sbn.getNotification(), sbn.getUserId()); @@ -13719,7 +13736,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { for (int i = 0; i < NotificationManagerService.MAX_PACKAGE_NOTIFICATIONS; i++) { StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel, i, null, false).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "testCannotPostNonUijWhenOverLimit", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCannotPostNonUijWhenOverLimit", sbn.getId(), sbn.getNotification(), sbn.getUserId()); waitForIdle(); } @@ -13727,13 +13744,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final StatusBarNotification sbn = generateNotificationRecord(mTestNotificationChannel, 100, null, false).getSbn(); sbn.getNotification().flags |= FLAG_USER_INITIATED_JOB; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCannotPostNonUijWhenOverLimit - uij over limit!", sbn.getId(), sbn.getNotification(), sbn.getUserId()); final StatusBarNotification sbn2 = generateNotificationRecord(mTestNotificationChannel, 101, null, false).getSbn(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCannotPostNonUijWhenOverLimit - non uij over limit!", sbn2.getId(), sbn2.getNotification(), sbn2.getUserId()); @@ -13742,7 +13759,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { final StatusBarNotification sbn3 = generateNotificationRecord(mTestNotificationChannel, 101, null, false).getSbn(); sbn3.getNotification().flags |= FLAG_USER_INITIATED_JOB; - mBinderService.enqueueNotificationWithTag(PKG, PKG, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "testCannotPostNonUijWhenOverLimit - fake uij over limit!", sbn3.getId(), sbn3.getNotification(), sbn3.getUserId()); @@ -13765,7 +13782,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .setFlag(FLAG_USER_INITIATED_JOB, true) .build(); - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); assertFalse(n.isUserInitiatedJob()); } @@ -13773,11 +13790,11 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void enqueue_updatesEnqueueRate() throws Exception { Notification n = generateNotificationRecord(null).getNotification(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 0, n, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", 0, n, mUserId); // Don't waitForIdle() here. We want to verify the "intermediate" state. - verify(mUsageStats).registerEnqueuedByApp(eq(PKG)); - verify(mUsageStats).registerEnqueuedByAppAndAccepted(eq(PKG)); + verify(mUsageStats).registerEnqueuedByApp(eq(mPkg)); + verify(mUsageStats).registerEnqueuedByAppAndAccepted(eq(mPkg)); verify(mUsageStats, never()).registerPostedByApp(any()); waitForIdle(); @@ -13787,26 +13804,26 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void enqueue_withPost_updatesEnqueueRateAndPost() throws Exception { Notification n = generateNotificationRecord(null).getNotification(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 0, n, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", 0, n, mUserId); waitForIdle(); - verify(mUsageStats).registerEnqueuedByApp(eq(PKG)); - verify(mUsageStats).registerEnqueuedByAppAndAccepted(eq(PKG)); + verify(mUsageStats).registerEnqueuedByApp(eq(mPkg)); + verify(mUsageStats).registerEnqueuedByAppAndAccepted(eq(mPkg)); verify(mUsageStats).registerPostedByApp(any()); } @Test public void enqueueNew_whenOverEnqueueRate_accepts() throws Exception { Notification n = generateNotificationRecord(null).getNotification(); - when(mUsageStats.getAppEnqueueRate(eq(PKG))) + when(mUsageStats.getAppEnqueueRate(eq(mPkg))) .thenReturn(DEFAULT_MAX_NOTIFICATION_ENQUEUE_RATE + 1f); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 0, n, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", 0, n, mUserId); waitForIdle(); assertThat(mService.mNotificationsByKey).hasSize(1); - verify(mUsageStats).registerEnqueuedByApp(eq(PKG)); - verify(mUsageStats).registerEnqueuedByAppAndAccepted(eq(PKG)); + verify(mUsageStats).registerEnqueuedByApp(eq(mPkg)); + verify(mUsageStats).registerEnqueuedByAppAndAccepted(eq(mPkg)); verify(mUsageStats).registerPostedByApp(any()); } @@ -13815,23 +13832,23 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Post the first version. Notification original = generateNotificationRecord(null).getNotification(); original.when = 111; - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 0, original, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", 0, original, mUserId); waitForIdle(); assertThat(mService.mNotificationList).hasSize(1); assertThat(mService.mNotificationList.get(0).getNotification().when).isEqualTo(111); reset(mUsageStats); - when(mUsageStats.getAppEnqueueRate(eq(PKG))) + when(mUsageStats.getAppEnqueueRate(eq(mPkg))) .thenReturn(DEFAULT_MAX_NOTIFICATION_ENQUEUE_RATE - 1f); // Post the update. Notification update = generateNotificationRecord(null).getNotification(); update.when = 222; - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 0, update, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", 0, update, mUserId); waitForIdle(); - verify(mUsageStats).registerEnqueuedByApp(eq(PKG)); - verify(mUsageStats).registerEnqueuedByAppAndAccepted(eq(PKG)); + verify(mUsageStats).registerEnqueuedByApp(eq(mPkg)); + verify(mUsageStats).registerEnqueuedByAppAndAccepted(eq(mPkg)); verify(mUsageStats, never()).registerPostedByApp(any()); verify(mUsageStats).registerUpdatedByApp(any(), any()); assertThat(mService.mNotificationList).hasSize(1); @@ -13843,22 +13860,22 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // Post the first version. Notification original = generateNotificationRecord(null).getNotification(); original.when = 111; - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 0, original, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", 0, original, mUserId); waitForIdle(); assertThat(mService.mNotificationList).hasSize(1); assertThat(mService.mNotificationList.get(0).getNotification().when).isEqualTo(111); reset(mUsageStats); - when(mUsageStats.getAppEnqueueRate(eq(PKG))) + when(mUsageStats.getAppEnqueueRate(eq(mPkg))) .thenReturn(DEFAULT_MAX_NOTIFICATION_ENQUEUE_RATE + 1f); // Post the update. Notification update = generateNotificationRecord(null).getNotification(); update.when = 222; - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 0, update, mUserId); + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", 0, update, mUserId); waitForIdle(); - verify(mUsageStats).registerEnqueuedByApp(eq(PKG)); + verify(mUsageStats).registerEnqueuedByApp(eq(mPkg)); verify(mUsageStats, never()).registerEnqueuedByAppAndAccepted(any()); verify(mUsageStats, never()).registerPostedByApp(any()); verify(mUsageStats, never()).registerUpdatedByApp(any(), any()); @@ -13877,7 +13894,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .addAction(new Notification.Action.Builder(null, "action2", actionIntent2).build()) .build(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 1, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", 1, parcelAndUnparcel(n, Notification.CREATOR), mUserId); verify(mAmi, times(3)).setPendingIntentAllowlistDuration( @@ -13905,7 +13922,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build()) .build(); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 1, + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag", 1, parcelAndUnparcel(source, Notification.CREATOR), mUserId); verify(mAmi, times(4)).setPendingIntentAllowlistDuration( @@ -14377,7 +14394,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertThat(mBinderService.getAutomaticZenRules()).isEmpty(); // Create an implicit zen rule by calling setNotificationPolicy from an app. - mBinderService.setNotificationPolicy(PKG, new NotificationManager.Policy(0, 0, 0), false); + mBinderService.setNotificationPolicy(mPkg, new NotificationManager.Policy(0, 0, 0), false); assertThat(mBinderService.getAutomaticZenRules()).hasSize(1); Map.Entry<String, AutomaticZenRule> rule = getOnlyElement( mBinderService.getAutomaticZenRules().entrySet()); @@ -14403,7 +14420,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertThat(mBinderService.getAutomaticZenRules()).isEmpty(); // Create an implicit zen rule by calling setNotificationPolicy from an app. - mBinderService.setNotificationPolicy(PKG, new NotificationManager.Policy(0, 0, 0), false); + mBinderService.setNotificationPolicy(mPkg, new NotificationManager.Policy(0, 0, 0), false); assertThat(mBinderService.getAutomaticZenRules()).hasSize(1); Map.Entry<String, AutomaticZenRule> rule = getOnlyElement( mBinderService.getAutomaticZenRules().entrySet()); @@ -14447,7 +14464,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertThat(n.flags & FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY).isGreaterThan(0); - mService.fixNotification(n, PKG, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); + mService.fixNotification(n, mPkg, "tag", 9, 0, mUid, NOT_FOREGROUND_SERVICE, true); assertThat(n.flags & FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY).isEqualTo(0); } @@ -14474,12 +14491,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Notifications should not be active anymore. - StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifications = mBinderService.getActiveNotifications(mPkg); assertThat(notifications).isEmpty(); assertEquals(0, mService.getNotificationRecordCount()); // Ensure cancel event is logged. verify(mAppOpsManager).noteOpNoThrow( - AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER, mUid, PKG, null, null); + AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER, mUid, mPkg, null, null); } @Test @@ -14502,7 +14519,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Notifications should not be active anymore. - StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifications = mBinderService.getActiveNotifications(mPkg); assertThat(notifications).isEmpty(); assertEquals(0, mService.getNotificationRecordCount()); // Ensure cancel event is not logged. @@ -14533,7 +14550,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Notifications should not be active anymore. - StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifications = mBinderService.getActiveNotifications(mPkg); assertThat(notifications).isEmpty(); assertEquals(0, mService.getNotificationRecordCount()); // Ensure cancel event is not logged due to flag being disabled. @@ -14563,12 +14580,12 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Notifications should not be active anymore. - StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifications = mBinderService.getActiveNotifications(mPkg); assertThat(notifications).isEmpty(); assertEquals(0, mService.getNotificationRecordCount()); // Ensure cancel event is logged. verify(mAppOpsManager).noteOpNoThrow( - AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER, mUid, PKG, null, null); + AppOpsManager.OP_RAPID_CLEAR_NOTIFICATIONS_BY_LISTENER, mUid, mPkg, null, null); } @Test @@ -14590,7 +14607,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Notifications should not be active anymore. - StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifications = mBinderService.getActiveNotifications(mPkg); assertThat(notifications).isEmpty(); assertEquals(0, mService.getNotificationRecordCount()); // Ensure cancel event is not logged. @@ -14620,7 +14637,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { waitForIdle(); // Notifications should not be active anymore. - StatusBarNotification[] notifications = mBinderService.getActiveNotifications(PKG); + StatusBarNotification[] notifications = mBinderService.getActiveNotifications(mPkg); assertThat(notifications).isEmpty(); assertEquals(0, mService.getNotificationRecordCount()); // Ensure cancel event is not logged due to flag being disabled. @@ -14651,20 +14668,20 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { ICallNotificationEventCallback listener = mock( ICallNotificationEventCallback.class); when(listener.asBinder()).thenReturn(mock(IBinder.class)); - mBinderService.registerCallNotificationEventListener(PKG, UserHandle.CURRENT, listener); + mBinderService.registerCallNotificationEventListener(mPkg, UserHandle.CURRENT, listener); waitForIdle(); final UserHandle userHandle = UserHandle.getUserHandleForUid(mUid); - final NotificationRecord r = createAndPostCallStyleNotification(PKG, userHandle, + final NotificationRecord r = createAndPostCallStyleNotification(mPkg, userHandle, "testCallNotificationListener_NotifiedOnPostCallStyle"); - verify(listener, times(1)).onCallNotificationPosted(PKG, userHandle); + verify(listener, times(1)).onCallNotificationPosted(mPkg, userHandle); - mBinderService.cancelNotificationWithTag(PKG, PKG, r.getSbn().getTag(), r.getSbn().getId(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, r.getSbn().getTag(), r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); - verify(listener, times(1)).onCallNotificationRemoved(PKG, userHandle); + verify(listener, times(1)).onCallNotificationRemoved(mPkg, userHandle); } @Test @@ -14673,7 +14690,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { ICallNotificationEventCallback listener = mock( ICallNotificationEventCallback.class); when(listener.asBinder()).thenReturn(mock(IBinder.class)); - mBinderService.registerCallNotificationEventListener(PKG, + mBinderService.registerCallNotificationEventListener(mPkg, UserHandle.getUserHandleForUid(mUid), listener); waitForIdle(); @@ -14684,7 +14701,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(listener, never()).onCallNotificationPosted(anyString(), any()); - mBinderService.cancelNotificationWithTag(PKG, PKG, r.getSbn().getTag(), r.getSbn().getId(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, r.getSbn().getTag(), r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); @@ -14698,20 +14715,20 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { ICallNotificationEventCallback listener = mock( ICallNotificationEventCallback.class); when(listener.asBinder()).thenReturn(mock(IBinder.class)); - mBinderService.registerCallNotificationEventListener(PKG, UserHandle.ALL, listener); + mBinderService.registerCallNotificationEventListener(mPkg, UserHandle.ALL, listener); waitForIdle(); final UserHandle otherUser = UserHandle.of(2); - final NotificationRecord r = createAndPostCallStyleNotification(PKG, + final NotificationRecord r = createAndPostCallStyleNotification(mPkg, otherUser, "testCallNotificationListener_registerForUserAll_notifiedOnAnyUserId"); - verify(listener, times(1)).onCallNotificationPosted(PKG, otherUser); + verify(listener, times(1)).onCallNotificationPosted(mPkg, otherUser); - mBinderService.cancelNotificationWithTag(PKG, PKG, r.getSbn().getTag(), r.getSbn().getId(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, r.getSbn().getTag(), r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); - verify(listener, times(1)).onCallNotificationRemoved(PKG, otherUser); + verify(listener, times(1)).onCallNotificationRemoved(mPkg, otherUser); } @Test @@ -14724,13 +14741,13 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { mBinderService.registerCallNotificationEventListener(packageName, UserHandle.ALL, listener); waitForIdle(); - final NotificationRecord r = createAndPostCallStyleNotification(PKG, + final NotificationRecord r = createAndPostCallStyleNotification(mPkg, UserHandle.of(mUserId), "testCallNotificationListener_differentPackage_notNotified"); verify(listener, never()).onCallNotificationPosted(anyString(), any()); - mBinderService.cancelNotificationWithTag(PKG, PKG, r.getSbn().getTag(), r.getSbn().getId(), + mBinderService.cancelNotificationWithTag(mPkg, mPkg, r.getSbn().getTag(), r.getSbn().getId(), r.getSbn().getUserId()); waitForIdle(); @@ -14742,7 +14759,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { public void rankingTime_newNotification_noisy_matchesSbn() throws Exception { NotificationRecord nr = generateNotificationRecord(mTestNotificationChannel, mUserId); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag0", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag0", nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -14757,7 +14774,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannel low = new NotificationChannel("low", "low", IMPORTANCE_LOW); NotificationRecord nr = generateNotificationRecord(low, mUserId); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag0", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag0", nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); @@ -14772,14 +14789,14 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannel low = new NotificationChannel("low", "low", IMPORTANCE_LOW); NotificationRecord nr = generateNotificationRecord(low, mUserId); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag0", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag0", nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); NotificationRecord posted = mService.mNotificationList.get(0); long originalPostTime = posted.getSbn().getPostTime(); assertThat(posted.getRankingTimeMs()).isEqualTo(originalPostTime); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag0", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag0", nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); assertThat(mService.mNotificationList.get(0).getRankingTimeMs()) @@ -14792,7 +14809,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannel low = new NotificationChannel("low", "low", IMPORTANCE_LOW); NotificationRecord nr = generateNotificationRecord(low, 0, mUserId); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag0", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag0", nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); NotificationRecord posted = mService.mNotificationList.get(0); @@ -14801,7 +14818,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationRecord nrUpdate = generateNotificationRecord(low, 0, mUserId, "bar"); // no attention helper mocked behavior needed because this does not make noise - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag0", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag0", nrUpdate.getSbn().getId(), nrUpdate.getSbn().getNotification(), nrUpdate.getSbn().getUserId()); waitForIdle(); @@ -14817,7 +14834,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { NotificationChannel low = new NotificationChannel("low", "low", IMPORTANCE_LOW); NotificationRecord nr = generateNotificationRecord(low, mUserId); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag0", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag0", nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); NotificationRecord posted = mService.mNotificationList.get(0); @@ -14832,7 +14849,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { return 2; // beep } }); - mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag0", + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, "tag0", nrUpdate.getSbn().getId(), nrUpdate.getSbn().getNotification(), nrUpdate.getSbn().getUserId()); waitForIdle(); @@ -14865,16 +14882,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { private NotificationRecord createAndPostNotification(Notification.Builder nb, String testName) throws RemoteException { - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, testName, mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, 1, testName, mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel); - mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), + mBinderService.enqueueNotificationWithTag(mPkg, mPkg, sbn.getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); return mService.findNotificationLocked( - PKG, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getUserId()); + mPkg, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getUserId()); } private static <T extends Parcelable> T parcelAndUnparcel(T source, diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationTimeComparatorTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationTimeComparatorTest.java new file mode 100644 index 000000000000..c39961e094ca --- /dev/null +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationTimeComparatorTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.server.notification; + +import static android.app.Notification.CATEGORY_MESSAGE; +import static android.app.NotificationManager.IMPORTANCE_DEFAULT; +import static android.app.NotificationManager.IMPORTANCE_HIGH; +import static android.app.NotificationManager.IMPORTANCE_LOW; +import static android.app.NotificationManager.IMPORTANCE_MIN; +import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT; +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.PendingIntent; +import android.app.Person; +import android.graphics.Color; +import android.media.session.MediaSession; +import android.platform.test.annotations.EnableFlags; +import android.platform.test.flag.junit.SetFlagsRule; +import android.service.notification.StatusBarNotification; +import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; +import com.android.server.UiServiceTestCase; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@SmallTest +@RunWith(AndroidJUnit4.class) +public class NotificationTimeComparatorTest extends UiServiceTestCase { + + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(DEVICE_DEFAULT); + + @Test + @EnableFlags({android.app.Flags.FLAG_SORT_SECTION_BY_TIME}) + public void testCompare() { + NotificationRecord one = mock(NotificationRecord.class); + when(one.getRankingTimeMs()).thenReturn(1L); + + NotificationRecord five = mock(NotificationRecord.class); + when(five.getRankingTimeMs()).thenReturn(5L); + + NotificationRecord ten = mock(NotificationRecord.class); + when(ten.getRankingTimeMs()).thenReturn(10L); + + List<NotificationRecord> expected = new ArrayList<>(); + expected.add(ten); + expected.add(five); + expected.add(one); + + List<NotificationRecord> actual = new ArrayList<>(); + actual.addAll(expected); + Collections.shuffle(actual); + + Collections.sort(actual, new NotificationTimeComparator()); + + assertThat(actual).containsExactlyElementsIn(expected).inOrder(); + } +} diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java index cee6cdb06bf5..aeeca2ae86f5 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -173,11 +173,8 @@ import java.util.concurrent.ThreadLocalRandom; @SmallTest @RunWith(AndroidJUnit4.class) public class PreferencesHelperTest extends UiServiceTestCase { - private static final int UID_N_MR1 = 0; private static final int UID_HEADLESS = 1000000; private static final UserHandle USER = UserHandle.of(0); - private static final int UID_O = 1111; - private static final int UID_P = 2222; private static final String SYSTEM_PKG = "android"; private static final int SYSTEM_UID = 1000; private static final UserHandle USER2 = UserHandle.of(10); @@ -1102,18 +1099,15 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "<package name=\"com.example.o\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" - + "=\"false\" uid=\"1111\">\n" + + "=\"false\" uid=\"10002\">\n" + "<channel id=\"id\" name=\"name\" importance=\"2\" " + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" orig_imp=\"2\" />\n" + "</package>\n" - + "<package name=\"com.example.p\" show_badge=\"true\" " - + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" - + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\" uid=\"2222\" />\n" + "<package name=\"com.example.n_mr1\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" - + "=\"false\" uid=\"0\">\n" + + "=\"false\" uid=\"10001\">\n" + "<channelGroup id=\"1\" name=\"bye\" blocked=\"false\" locked=\"0\" />\n" + "<channelGroup id=\"2\" name=\"hello\" blocked=\"false\" locked=\"0\" />\n" + "<channel id=\"id1\" name=\"name1\" importance=\"4\" show_badge=\"true\" " @@ -1129,6 +1123,9 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" />\n" + "</package>\n" + + "<package name=\"com.example.p\" show_badge=\"true\" " + + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" + + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\" uid=\"10003\" />\n" + "</ranking>"; assertThat(baos.toString()).contains(expected); } @@ -1194,10 +1191,6 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "content_type=\"4\" flags=\"0\" show_badge=\"true\" orig_imp=\"2\" />\n" + "</package>\n" // Importance default because on in permission helper - + "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " - + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" - + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\" />\n" - // Importance default because on in permission helper + "<package name=\"com.example.n_mr1\" importance=\"3\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" @@ -1217,6 +1210,10 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" />\n" + "</package>\n" + // Importance default because on in permission helper + + "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " + + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" + + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\" />\n" // Packages that exist solely in permissionhelper + "<package name=\"first\" importance=\"3\" />\n" + "<package name=\"third\" importance=\"0\" />\n" @@ -1280,12 +1277,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" orig_imp=\"2\" />\n" + "</package>\n" - // Importance default because on in permission helper - + "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " - + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" - + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\" />\n" - // Importance missing because missing from permission helper - + "<package name=\"com.example.n_mr1\" show_badge=\"true\" " + // Importance 0 because missing from permission helper + + "<package name=\"com.example.n_mr1\" importance=\"0\" show_badge=\"true\" " + "app_user_locked_fields=\"0\" sent_invalid_msg=\"false\" " + "sent_valid_msg=\"false\" user_demote_msg_app=\"false\" sent_valid_bubble" + "=\"false\">\n" @@ -1304,6 +1297,10 @@ public class PreferencesHelperTest extends UiServiceTestCase { + "sound=\"content://settings/system/notification_sound\" usage=\"5\" " + "content_type=\"4\" flags=\"0\" show_badge=\"true\" />\n" + "</package>\n" + // Importance default because on in permission helper + + "<package name=\"com.example.p\" importance=\"3\" show_badge=\"true\" " + + "app_user_locked_fields=\"0\" sent_invalid_msg=\"true\" sent_valid_msg=\"true\"" + + " user_demote_msg_app=\"true\" sent_valid_bubble=\"false\" />\n" + "</ranking>"; assertThat(baos.toString()).contains(expected); } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java index d2c6028dea45..a071f0bfed60 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java @@ -18,6 +18,8 @@ package com.android.server.notification; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_LOW; +import static android.platform.test.flag.junit.SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT; +import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.assertTrue; @@ -27,6 +29,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import android.app.Flags; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -42,6 +45,9 @@ import android.net.Uri; import android.os.Build; import android.os.UserHandle; import android.os.Vibrator; +import android.platform.test.annotations.DisableFlags; +import android.platform.test.annotations.EnableFlags; +import android.platform.test.flag.junit.SetFlagsRule; import android.service.notification.StatusBarNotification; import android.testing.TestableContentResolver; @@ -52,24 +58,23 @@ import androidx.test.runner.AndroidJUnit4; import com.android.server.UiServiceTestCase; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.ArrayList; +import java.util.Collections; +import java.util.List; @SmallTest @RunWith(AndroidJUnit4.class) public class RankingHelperTest extends UiServiceTestCase { - private static final String PKG = "com.android.server.notification"; - private static final int UID = 0; - private static final UserHandle USER = UserHandle.of(0); - private static final String UPDATED_PKG = "updatedPkg"; + private static final String UPDATED_PKG = "updatedmPkg"; private static final int UID2 = 1111; private static final String SYSTEM_PKG = "android"; private static final int SYSTEM_UID= 1000; - private static final UserHandle USER2 = UserHandle.of(10); private static final String TEST_CHANNEL_ID = "test_channel_id"; private static final String TEST_AUTHORITY = "test"; private static final Uri SOUND_URI = @@ -98,28 +103,32 @@ public class RankingHelperTest extends UiServiceTestCase { private NotificationRecord mRecordNoGroup; private NotificationRecord mRecordNoGroup2; private NotificationRecord mRecordNoGroupSortA; + private NotificationRecord mRecentlyIntrusive; + private NotificationRecord mNewest; private RankingHelper mHelper; - private AudioAttributes mAudioAttributes; + + @Rule + public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(DEVICE_DEFAULT); @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - UserHandle user = UserHandle.ALL; + UserHandle mUser = UserHandle.ALL; final ApplicationInfo legacy = new ApplicationInfo(); legacy.targetSdkVersion = Build.VERSION_CODES.N_MR1; final ApplicationInfo upgrade = new ApplicationInfo(); upgrade.targetSdkVersion = Build.VERSION_CODES.O; - when(mPm.getApplicationInfoAsUser(eq(PKG), anyInt(), anyInt())).thenReturn(legacy); + when(mPm.getApplicationInfoAsUser(eq(mPkg), anyInt(), anyInt())).thenReturn(legacy); when(mPm.getApplicationInfoAsUser(eq(UPDATED_PKG), anyInt(), anyInt())).thenReturn(upgrade); when(mPm.getApplicationInfoAsUser(eq(SYSTEM_PKG), anyInt(), anyInt())).thenReturn(upgrade); - when(mPm.getPackageUidAsUser(eq(PKG), anyInt())).thenReturn(UID); + when(mPm.getPackageUidAsUser(eq(mPkg), anyInt())).thenReturn(mUid); when(mPm.getPackageUidAsUser(eq(UPDATED_PKG), anyInt())).thenReturn(UID2); when(mPm.getPackageUidAsUser(eq(SYSTEM_PKG), anyInt())).thenReturn(SYSTEM_UID); PackageInfo info = mock(PackageInfo.class); info.signatures = new Signature[] {mock(Signature.class)}; when(mPm.getPackageInfoAsUser(eq(SYSTEM_PKG), anyInt(), anyInt())).thenReturn(info); - when(mPm.getPackageInfoAsUser(eq(PKG), anyInt(), anyInt())) + when(mPm.getPackageInfoAsUser(eq(mPkg), anyInt(), anyInt())) .thenReturn(mock(PackageInfo.class)); when(mContext.getResources()).thenReturn( InstrumentationRegistry.getContext().getResources()); @@ -155,7 +164,7 @@ public class RankingHelperTest extends UiServiceTestCase { .setWhen(1205) .build(); mRecordGroupGSortA = new NotificationRecord(mContext, new StatusBarNotification( - PKG, PKG, 1, null, 0, 0, mNotiGroupGSortA, user, + mPkg, mPkg, 1, null, 0, 0, mNotiGroupGSortA, mUser, null, System.currentTimeMillis()), getLowChannel()); mNotiGroupGSortB = new Notification.Builder(mContext, TEST_CHANNEL_ID) @@ -165,7 +174,7 @@ public class RankingHelperTest extends UiServiceTestCase { .setWhen(1200) .build(); mRecordGroupGSortB = new NotificationRecord(mContext, new StatusBarNotification( - PKG, PKG, 1, null, 0, 0, mNotiGroupGSortB, user, + mPkg, mPkg, 1, null, 0, 0, mNotiGroupGSortB, mUser, null, System.currentTimeMillis()), getLowChannel()); mNotiNoGroup = new Notification.Builder(mContext, TEST_CHANNEL_ID) @@ -173,7 +182,7 @@ public class RankingHelperTest extends UiServiceTestCase { .setWhen(1201) .build(); mRecordNoGroup = new NotificationRecord(mContext, new StatusBarNotification( - PKG, PKG, 1, null, 0, 0, mNotiNoGroup, user, + mPkg, mPkg, 1, null, 0, 0, mNotiNoGroup, mUser, null, System.currentTimeMillis()), getLowChannel()); mNotiNoGroup2 = new Notification.Builder(mContext, TEST_CHANNEL_ID) @@ -181,7 +190,7 @@ public class RankingHelperTest extends UiServiceTestCase { .setWhen(1202) .build(); mRecordNoGroup2 = new NotificationRecord(mContext, new StatusBarNotification( - PKG, PKG, 1, null, 0, 0, mNotiNoGroup2, user, + mPkg, mPkg, 1, null, 0, 0, mNotiNoGroup2, mUser, null, System.currentTimeMillis()), getLowChannel()); mNotiNoGroupSortA = new Notification.Builder(mContext, TEST_CHANNEL_ID) @@ -190,14 +199,20 @@ public class RankingHelperTest extends UiServiceTestCase { .setSortKey("A") .build(); mRecordNoGroupSortA = new NotificationRecord(mContext, new StatusBarNotification( - PKG, PKG, 1, null, 0, 0, mNotiNoGroupSortA, user, + mPkg, mPkg, 1, null, 0, 0, mNotiNoGroupSortA, mUser, null, System.currentTimeMillis()), getLowChannel()); - mAudioAttributes = new AudioAttributes.Builder() - .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) - .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) - .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED) + Notification n = new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setContentTitle("D") .build(); + mRecentlyIntrusive = new NotificationRecord(mContext, new StatusBarNotification( + mPkg, mPkg, 1, null, 0, 0, n, mUser, + null, System.currentTimeMillis()+100), getDefaultChannel()); + mRecentlyIntrusive.setRecentlyIntrusive(true); + + mNewest = new NotificationRecord(mContext, new StatusBarNotification( + mPkg, mPkg, 2, null, 0, 0, n, mUser, + null, System.currentTimeMillis()+10000), getDefaultChannel()); } private NotificationChannel getLowChannel() { @@ -303,13 +318,13 @@ public class RankingHelperTest extends UiServiceTestCase { .setGroupSummary(true) .build(); NotificationRecord lowSummary = new NotificationRecord(mContext, new StatusBarNotification( - PKG, PKG, 1, "summary", 0, 0, lowSummaryN, USER, + mPkg, mPkg, 1, "summary", 0, 0, lowSummaryN, mUser, null, System.currentTimeMillis()), getLowChannel()); notificationList.add(lowSummary); Notification lowN = new Notification.Builder(mContext, "").build(); NotificationRecord low = new NotificationRecord(mContext, new StatusBarNotification( - PKG, PKG, 1, "low", 0, 0, lowN, USER, + mPkg, mPkg, 1, "low", 0, 0, lowN, mUser, null, System.currentTimeMillis()), getLowChannel()); low.setContactAffinity(0.5f); notificationList.add(low); @@ -319,7 +334,7 @@ public class RankingHelperTest extends UiServiceTestCase { .setGroupSummary(false) .build(); NotificationRecord highChild = new NotificationRecord(mContext, new StatusBarNotification( - PKG, PKG, 1, "child", 0, 0, highChildN, USER, + mPkg, mPkg, 1, "child", 0, 0, highChildN, mUser, null, System.currentTimeMillis()), getDefaultChannel()); notificationList.add(highChild); @@ -329,4 +344,187 @@ public class RankingHelperTest extends UiServiceTestCase { assertEquals(highChild, notificationList.get(1)); assertEquals(low, notificationList.get(2)); } + + @Test + @DisableFlags({android.app.Flags.FLAG_SORT_SECTION_BY_TIME}) + public void testSortByIntrusivenessNotRecency() { + ArrayList<NotificationRecord> expected = new ArrayList<>(); + expected.add(mRecentlyIntrusive); + expected.add(mNewest); + + ArrayList<NotificationRecord> actual = new ArrayList<>(); + actual.addAll(expected); + Collections.shuffle(actual); + + mHelper.sort(actual); + assertThat(actual).containsExactlyElementsIn(expected).inOrder(); + } + + @Test + @EnableFlags({android.app.Flags.FLAG_SORT_SECTION_BY_TIME}) + public void testSortByRecencyNotIntrusiveness() { + ArrayList<NotificationRecord> expected = new ArrayList<>(); + expected.add(mNewest); + expected.add(mRecentlyIntrusive); + + ArrayList<NotificationRecord> actual = new ArrayList<>(); + actual.addAll(expected); + Collections.shuffle(actual); + + mHelper.sort(actual); + assertThat(actual).containsExactlyElementsIn(expected).inOrder(); + } + + @Test + @EnableFlags({android.app.Flags.FLAG_SORT_SECTION_BY_TIME, Flags.FLAG_UPDATE_RANKING_TIME}) + public void testSort_oldWhenChildren_unspecifiedSummary() { + NotificationRecord child1 = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 1, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setGroup("G") + .setWhen(1200) + .build(), + mUser, null, System.currentTimeMillis()), getLowChannel()); + NotificationRecord child2 = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 2, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setGroup("G") + .setWhen(1300) + .build(), + mUser, null, System.currentTimeMillis()), getLowChannel()); + NotificationRecord summary = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 3, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setGroup("G") + .setGroupSummary(true) + .build(), + mUser, null, System.currentTimeMillis()), getLowChannel()); + + // in time slightly before the children, but much earlier than the summary. + // will only be sorted first if the summary is not the group proxy for group G. + NotificationRecord unrelated = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 11, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setWhen(1500) + .build(), + mUser, null, System.currentTimeMillis()), getLowChannel()); + + ArrayList<NotificationRecord> expected = new ArrayList<>(); + expected.add(unrelated); + expected.add(summary); + expected.add(child2); + expected.add(child1); + + ArrayList<NotificationRecord> actual = new ArrayList<>(); + actual.addAll(expected); + Collections.shuffle(actual); + + mHelper.sort(actual); + assertThat(actual).containsExactlyElementsIn(expected).inOrder(); + } + + @Test + @EnableFlags({android.app.Flags.FLAG_SORT_SECTION_BY_TIME, Flags.FLAG_UPDATE_RANKING_TIME}) + public void testSort_oldChildren_unspecifiedSummary() { + NotificationRecord child1 = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 1, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setGroup("G") + .build(), + mUser, null, 1200), getLowChannel()); + NotificationRecord child2 = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 2, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setGroup("G") + .build(), + mUser, null, 1300), getLowChannel()); + NotificationRecord summary = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 3, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setGroup("G") + .setGroupSummary(true) + .build(), + mUser, null, System.currentTimeMillis()), getLowChannel()); + + // in time slightly before the children, but much earlier than the summary. + // will only be sorted first if the summary is not the group proxy for group G. + NotificationRecord unrelated = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 11, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setWhen(1500) + .build(), + mUser, null, System.currentTimeMillis()), getLowChannel()); + + ArrayList<NotificationRecord> expected = new ArrayList<>(); + expected.add(unrelated); + expected.add(summary); + expected.add(child2); + expected.add(child1); + + ArrayList<NotificationRecord> actual = new ArrayList<>(); + actual.addAll(expected); + Collections.shuffle(actual); + + mHelper.sort(actual); + assertThat(actual).containsExactlyElementsIn(expected).inOrder(); + } + + @Test + @EnableFlags({android.app.Flags.FLAG_SORT_SECTION_BY_TIME, Flags.FLAG_UPDATE_RANKING_TIME}) + public void testSort_oldChildren_oldSummary() { + NotificationRecord child1 = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 1, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setGroup("G") + .build(), + mUser, null, 1200), getLowChannel()); + NotificationRecord child2 = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 2, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setGroup("G") + .build(), + mUser, null, 1300), getLowChannel()); + NotificationRecord summary = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 3, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setGroup("G") + .setGroupSummary(true) + .setWhen(1600) + .build(), + mUser, null, System.currentTimeMillis()), getLowChannel()); + + // in time slightly before the children, but much earlier than the summary. + // will only be sorted first if the summary is not the group proxy for group G. + NotificationRecord unrelated = new NotificationRecord(mContext, + new StatusBarNotification( + mPkg, mPkg, 11, null, 0, 0, + new Notification.Builder(mContext, TEST_CHANNEL_ID) + .setWhen(1500) + .build(), + mUser, null, System.currentTimeMillis()), getLowChannel()); + + ArrayList<NotificationRecord> expected = new ArrayList<>(); + expected.add(summary); + expected.add(child2); + expected.add(child1); + expected.add(unrelated); + + ArrayList<NotificationRecord> actual = new ArrayList<>(); + actual.addAll(expected); + Collections.shuffle(actual); + + mHelper.sort(actual); + assertThat(actual).containsExactlyElementsIn(expected).inOrder(); + } } |