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

Commit f2ffa3dd authored by Yuri Lin's avatar Yuri Lin Committed by Android (Google) Code Review
Browse files

Merge "Update app lists for adjustment exclusion screens" into main

parents cdb95814 598e5987
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -94,6 +94,10 @@ class AppNotificationRepository(
        }
    }

    fun hasSentMessageNotification(app: ApplicationInfo): Boolean =
        notificationManager.hasSentValidMsg(app.packageName, app.uid)
                || notificationManager.isInInvalidMsgState(app.packageName, app.uid)

    fun isEnabled(app: ApplicationInfo): Boolean =
        notificationManager.areNotificationsEnabledForPackage(app.packageName, app.uid)

+16 −6
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import kotlinx.coroutines.withContext
data class AppNotificationsRecord(
    override val app: ApplicationInfo,
    val sentState: NotificationSentState?,
    val hasSentMsgNotification: Boolean,
    val controller: AppNotificationController,
) : AppRecord

@@ -66,6 +67,7 @@ class AppNotificationsListModel(
                AppNotificationsRecord(
                    app = app,
                    sentState = usageEvents[app.packageName],
                    hasSentMsgNotification = repository.hasSentMessageNotification(app),
                    controller = AppNotificationController(repository, app, listType),
                )
            }
@@ -75,6 +77,9 @@ class AppNotificationsListModel(
        userIdFlow: Flow<Int>, option: Int, recordListFlow: Flow<List<AppNotificationsRecord>>,
    ) = recordListFlow.map { recordList ->
        recordList.asyncFilter { record ->
            if (listType == ListType.ExcludeSummarization && !record.hasSentMsgNotification) {
                false
            } else {
                when (option.toSpinnerItem()) {
                    SpinnerItem.MostRecent -> record.sentState != null
                    SpinnerItem.MostFrequent -> record.sentState != null
@@ -83,6 +88,7 @@ class AppNotificationsListModel(
                }
            }
        }
    }

    override suspend fun onFirstLoaded(recordList: List<AppNotificationsRecord>): Boolean {
        recordList.asyncForEach { it.controller.getEnabled() }
@@ -106,11 +112,15 @@ class AppNotificationsListModel(
        }

    override fun getSpinnerOptions(recordList: List<AppNotificationsRecord>): List<SpinnerOption> {
        val options = mutableListOf(SpinnerItem.AllApps, SpinnerItem.TurnedOff)
        val options = mutableListOf(SpinnerItem.AllApps)
        if (recordList.isNotEmpty() && repository.isUserUnlocked(recordList[0].app.userId)) {
            options.add(0, SpinnerItem.MostRecent)
            options.add(1, SpinnerItem.MostFrequent)
        }
        if (!listType.equals(ListType.ExcludeSummarization)
            && !listType.equals(ListType.ExcludeClassification)) {
            options.add(SpinnerItem.TurnedOff)
        }

        return options.map {
            SpinnerOption(
+19 −0
Original line number Diff line number Diff line
@@ -312,6 +312,25 @@ class AppNotificationRepositoryTest {
        assertThat(summary).isEqualTo("About 3 notifications per week")
    }

    @Test
    fun hasSentMessageNotification_yesValid() {
        whenever(notificationManager.hasSentValidMsg(APP.packageName, APP.uid)).thenReturn(true)

        assertThat(repository.hasSentMessageNotification(APP)).isTrue()
    }

    @Test
    fun hasSentMessageNotification_yesInvalid() {
        whenever(notificationManager.isInInvalidMsgState(APP.packageName, APP.uid)).thenReturn(true)

        assertThat(repository.hasSentMessageNotification(APP)).isTrue()
    }

    @Test
    fun hasSentMessageNotification_no() {
        assertThat(repository.hasSentMessageNotification(APP)).isFalse()
    }

    private companion object {
        const val USER_ID = 0
        const val PACKAGE_NAME = "package.name"