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

Commit 8e2bc706 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Fixes ordering of PrivacyType. Location at bottom.

Test: atest
Change-Id: I359c91da18fc01652bfd42904ba6b5cfeca8207a
parent b34e8528
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -29,7 +29,9 @@ class PrivacyDialogBuilder(val context: Context, itemsList: List<PrivacyItem>) {
    init {
        appsAndTypes = itemsList.groupBy({ it.application }, { it.privacyType })
                .toList()
                .sortedWith(compareBy({ -it.second.size }, { it.first }))
                .sortedWith(compareBy({ -it.second.size }, // Sort by number of AppOps
                        { it.second.min() }, // Sort by "smallest" AppOpp (Location is largest)
                        { it.first })) // Sort alphabetically bt App Name
        types = itemsList.map { it.privacyType }.distinct().sorted()
        val singleApp = appsAndTypes.size == 1
        app = if (singleApp) appsAndTypes[0].first else null
+2 −2
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@ typealias Privacy = PrivacyType

enum class PrivacyType(val nameId: Int, val iconId: Int) {
    TYPE_CAMERA(R.string.privacy_type_camera, R.drawable.stat_sys_camera),
    TYPE_LOCATION(R.string.privacy_type_location, R.drawable.stat_sys_location),
    TYPE_MICROPHONE(R.string.privacy_type_microphone, R.drawable.stat_sys_mic_none);
    TYPE_MICROPHONE(R.string.privacy_type_microphone, R.drawable.stat_sys_mic_none),
    TYPE_LOCATION(R.string.privacy_type_location, R.drawable.stat_sys_location);

    fun getName(context: Context) = context.resources.getString(nameId)

+15 −0
Original line number Diff line number Diff line
@@ -51,4 +51,19 @@ class PrivacyDialogBuilderTest : SysuiTestCase() {
        assertEquals(listOf(Privacy.TYPE_CAMERA), typesList[1])
        assertEquals(listOf(Privacy.TYPE_CAMERA), typesList[2])
    }

    @Test
    fun testOrder() {
        // We want location to always go last, so it will go in the "+ other apps"
        val appCamera = PrivacyItem(PrivacyType.TYPE_CAMERA, PrivacyApplication("Camera", context))
        val appMicrophone =
                PrivacyItem(PrivacyType.TYPE_MICROPHONE, PrivacyApplication("Microphone", context))
        val appLocation =
                PrivacyItem(PrivacyType.TYPE_LOCATION, PrivacyApplication("Location", context))

        val items = listOf(appLocation, appMicrophone, appCamera)
        val textBuilder = PrivacyDialogBuilder(context, items)
        val appList = textBuilder.appsAndTypes.map { it.first }.map { it.packageName }
        assertEquals(listOf("Camera", "Microphone", "Location"), appList)
    }
}
 No newline at end of file