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

Commit 31653b08 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Fixes to Privacy Dialog" into sc-dev

parents 14edd622 8cff8629
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -31,6 +31,6 @@
          android:gravity="center"
          android:width="@dimen/ongoing_appops_dialog_icon_size"
          android:height="@dimen/ongoing_appops_dialog_icon_size"
          android:drawable="@*android:drawable/perm_group_microphone"
          android:drawable="@*android:drawable/perm_group_location"
    />
</layer-list>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ class PrivacyDialog(
        val finalText = element.attribution?.let {
            TextUtils.concat(
                    firstLine,
                    "\n",
                    " ",
                    context.getString(R.string.ongoing_privacy_dialog_attribution_text, it)
            )
        } ?: firstLine
+9 −10
Original line number Diff line number Diff line
@@ -227,21 +227,20 @@ class PrivacyDialogController(
    /**
     * Filters the list of elements to show.
     *
     * * Return at most one element per [PrivacyType], sorted by the natural order of the
     * [PrivacyType].
     * * If there are no active usages for a type, return the most recent
     * * If there are multiple active usages for a type, return the most active recent.
     * For each privacy type, it'll return all active elements. If there are no active elements,
     * it'll return the most recent access
     */
    private fun filterAndSelect(
        list: List<PrivacyDialog.PrivacyElement>
    ): List<PrivacyDialog.PrivacyElement> {
        return list.groupBy { it.type }.toSortedMap().mapNotNull { entry ->
            if (entry.value.isEmpty()) {
                null
        return list.groupBy { it.type }.toSortedMap().flatMap { (_, elements) ->
            val actives = elements.filter { it.active }
            if (actives.isNotEmpty()) {
                actives.sortedByDescending { it.lastActiveTimestamp }
            } else {
                val actives = entry.value.filter { it.active }
                val out = if (actives.isNotEmpty()) actives else entry.value
                out.maxByOrNull { it.lastActiveTimestamp }
                elements.maxByOrNull { it.lastActiveTimestamp }?.let {
                    listOf(it)
                } ?: emptyList()
            }
        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -295,8 +295,9 @@ class PrivacyDialogControllerTest : SysuiTestCase() {
        )
        controller.showDialog(context)
        exhaustExecutors()
        assertThat(dialogProvider.list).hasSize(1)
        assertThat(dialogProvider.list).hasSize(2)
        assertThat(dialogProvider.list?.get(0)?.lastActiveTimestamp).isEqualTo(1L)
        assertThat(dialogProvider.list?.get(1)?.lastActiveTimestamp).isEqualTo(0L)
    }

    @Test