Loading packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogBuilder.kt +3 −1 Original line number Diff line number Diff line Loading @@ -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 Loading packages/SystemUI/src/com/android/systemui/privacy/PrivacyItem.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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) Loading packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogBuilderTest.kt +15 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/privacy/PrivacyDialogBuilder.kt +3 −1 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/privacy/PrivacyItem.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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) Loading
packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogBuilderTest.kt +15 −0 Original line number Diff line number Diff line Loading @@ -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