summaryrefslogtreecommitdiff
path: root/PermissionController/src/com/android/permissioncontroller/permission/ui/model/ManagePermissionsViewModel.kt
diff options
context:
space:
mode:
authorJordan Jozwiak <jjoz@google.com>2021-06-29 14:21:01 -0700
committerJordan Jozwiak <jjoz@google.com>2021-08-05 09:58:04 -0700
commitc00883a4e19eadc74a54171c842ff209168ca3af (patch)
treec807f2e39664ca4e05038cb723a15df3a84d74bc /PermissionController/src/com/android/permissioncontroller/permission/ui/model/ManagePermissionsViewModel.kt
parent63b05fe4369a3c40b8ae7303effe2e57b491193b (diff)
downloadPermission-c00883a4e19eadc74a54171c842ff209168ca3af.tar.gz
Permission decluttering for Auto
Only show permission groups that at least one app has access to on the main page. The page page links to "Other permissions", which includes permission groups that are only granted to system apps and "Additional permissions", which are custom/3P permissions and were previously the only content on the other permissions page. Note that permissions not used by any application are not displayed at all. For our current Seahawk build this means "Body Sensors" is not displayed at all. This change largely mirrors the TV decluttering work ag/12793223. Changes of note: - Move some TV classes to shared locations so that they can be used for both Auto and TV. Screenshots: - https://hsv.googleplex.com/6472082885967872 - https://hsv.googleplex.com/5348699729297408 - https://hsv.googleplex.com/4883953129357312 - https://screencast.googleplex.com/cast/NTY0MzU0MjcxNjIxOTM5Mnw0MTUyNGIzMi1kNA Bug: 185791856 Test: Manual testing on Seahawk and emulator for rotary Change-Id: I73af388e262762bfba741222211053d531e332a1
Diffstat (limited to 'PermissionController/src/com/android/permissioncontroller/permission/ui/model/ManagePermissionsViewModel.kt')
-rw-r--r--PermissionController/src/com/android/permissioncontroller/permission/ui/model/ManagePermissionsViewModel.kt110
1 files changed, 110 insertions, 0 deletions
diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/model/ManagePermissionsViewModel.kt b/PermissionController/src/com/android/permissioncontroller/permission/ui/model/ManagePermissionsViewModel.kt
new file mode 100644
index 000000000..970569c31
--- /dev/null
+++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/model/ManagePermissionsViewModel.kt
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2021 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.permissioncontroller.permission.ui.model
+
+import android.app.Application
+import androidx.lifecycle.AndroidViewModel
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MediatorLiveData
+import com.android.permissioncontroller.permission.data.PermGroupsPackagesUiInfoLiveData
+import com.android.permissioncontroller.permission.data.StandardPermGroupNamesLiveData
+import com.android.permissioncontroller.permission.model.livedatatypes.PermGroupPackagesUiInfo
+
+/**
+ * A [androidx.lifecycle.ViewModel] for [ManagePermissionsFragment] and
+ * [ManagePermissionsOtherFragment].
+ * However, [ManagePermissionsViewModel] is designed in a way so that its owner should be an
+ * [Activity][androidx.fragment.app.FragmentActivity] rather than individual
+ * [Fragments][androidx.fragment.app.Fragment], and the aforementioned Fragments that manage
+ * different sets of the permission groups should to share a single instance of
+ * [ManagePermissionsViewModel].
+ */
+class ManagePermissionsViewModel(app: Application) : AndroidViewModel(app) {
+
+ private val standardPermGroupsLiveData: LiveData<List<PermGroupPackagesUiInfo>> =
+ MediatorLiveData<List<PermGroupPackagesUiInfo>>().apply {
+ addSource(PermGroupsPackagesUiInfoLiveData(app, StandardPermGroupNamesLiveData)) {
+ permGroups -> value = permGroups.values.filterNotNull()
+ }
+ }
+
+ /**
+ * [LiveData] that contains a list of platform-defined permission groups, such
+ * that at least one the permissions in the group has been requested at runtime by at least one
+ * non-system application or has been pregranted to a non-system application.
+ * @see com.android.permissioncontroller.permission.ui.television.ManagePermissionsFragment
+ */
+ val usedPermissionGroups: LiveData<List<PermGroupPackagesUiInfo>> =
+ MediatorLiveData<List<PermGroupPackagesUiInfo>>().apply {
+ addSource(standardPermGroupsLiveData) {
+ permGroups -> value = permGroups.filter { it.nonSystemUserSetOrPreGranted > 0 }
+ }
+ }
+
+ /**
+ * [LiveData] that contains a list of platform-defined permission groups, such that all
+ * of the permissions in the group neither has been requested at runtime by any of the
+ * non-system applications nor has been pregranted to any such application. But at least one of
+ * the permissions in the group is requested by or pregranted to at least one system
+ * application, other than the Shell (we do not show permission groups that are granted only to
+ * the Shell, because it has all the permissions granted).
+ * @see com.android.permissioncontroller.permission.ui.television.ManagePermissionsOtherFragment
+ */
+ val unusedPermissionGroups: LiveData<List<PermGroupPackagesUiInfo>> =
+ MediatorLiveData<List<PermGroupPackagesUiInfo>>().apply {
+ addSource(standardPermGroupsLiveData) {
+ permGroups -> value = permGroups
+ .filter { it.nonSystemUserSetOrPreGranted == 0 }
+ .filter { it.systemUserSetOrPreGranted > 0 }
+ .filterNot { it.onlyShellPackageGranted }
+ }
+ }
+
+ /**
+ * [LiveData] that contains a list of the application-defined permission groups
+ * (a.k.a. "custom" permissions), such that at least one of the permissions in the group has
+ * been requested at runtime by or has been pregranted to at least one application (system or
+ * non-system).
+ * @see com.android.permissioncontroller.permission.ui.television.ManagePermissionsOtherFragment
+ */
+ val additionalPermissionGroups: LiveData<List<PermGroupPackagesUiInfo>> =
+ MediatorLiveData<List<PermGroupPackagesUiInfo>>().apply {
+ addSource(PermGroupsPackagesUiInfoLiveData(
+ app, UsedCustomPermGroupNamesLiveData())) {
+ permGroups -> value = permGroups.values
+ .filterNotNull()
+ .filter {
+ (it.nonSystemUserSetOrPreGranted > 0) or (it.systemUserSetOrPreGranted > 0)
+ }
+ }
+ }
+
+ /**
+ * [LiveData] that indicates whether there any unused or additional permission groups.
+ * @see com.android.permissioncontroller.permission.ui.television.ManagePermissionsFragment
+ */
+ @get:JvmName("hasUnusedOrAdditionalPermissionGroups")
+ val hasUnusedOrAdditionalPermissionGroups: LiveData<Boolean> =
+ MediatorLiveData<Boolean>().apply {
+ val updateValue: (Any?) -> Unit = {
+ value = !unusedPermissionGroups.value.isNullOrEmpty() ||
+ !additionalPermissionGroups.value.isNullOrEmpty()
+ }
+ addSource(unusedPermissionGroups, updateValue)
+ addSource(additionalPermissionGroups, updateValue)
+ }
+} \ No newline at end of file