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

Commit c0d63088 authored by Nate Myren's avatar Nate Myren
Browse files

Disable toggle for work profile and services

Do not show the auto revoke toggle for work profile apps, and exempt
services.

Fixes: 157724010
Test: Navigate to a work profile app, and the Device Policy app. Verify
neither show the auto revoke toggle.

Change-Id: I280d3856cfbfd4b104d84c3568fe98692aef28a6
parent ec0c4eac
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.UserHandle
import com.android.permissioncontroller.PermissionControllerApplication
import com.android.permissioncontroller.permission.data.PackagePermissionsLiveData.Companion.NON_RUNTIME_NORMAL_PERMS
import com.android.permissioncontroller.permission.model.livedatatypes.AutoRevokeState
import com.android.permissioncontroller.permission.service.ExemptServicesLiveData
import com.android.permissioncontroller.permission.service.isAutoRevokeEnabled
import com.android.permissioncontroller.permission.service.isPackageAutoRevokeExempt
import com.android.permissioncontroller.permission.service.isPackageAutoRevokePermanentlyExempt
@@ -47,6 +48,7 @@ class AutoRevokeStateLiveData private constructor(
        PackagePermissionsLiveData[packageName, user]
    private val packageLiveData = LightPackageInfoLiveData[packageName, user]
    private val permStateLiveDatas = mutableMapOf<String, PermStateLiveData>()
    private val exemptServicesLiveData = ExemptServicesLiveData[user]
    private val appOpsManager = app.getSystemService(AppOpsManager::class.java)!!

    init {
@@ -56,29 +58,22 @@ class AutoRevokeStateLiveData private constructor(
        addSource(packageLiveData) {
            updateIfActive()
        }
        addSource(exemptServicesLiveData) {
            updateIfActive()
        }

    override suspend fun loadDataAndPostValue(job: Job) {
        if (!packageLiveData.isInitialized) {
            return
        }
        if (packageLiveData.value == null) {
            postValue(null)
            return
    }

        val uid = packageLiveData.value?.uid
        if (uid == null) {
            postValue(null)
    override suspend fun loadDataAndPostValue(job: Job) {
        if (!packageLiveData.isInitialized || !packagePermsLiveData.isInitialized ||
            !exemptServicesLiveData.isInitialized) {
            return
        }

        val groups = packagePermsLiveData.value?.keys?.filter { it != NON_RUNTIME_NORMAL_PERMS }
        if (groups == null && packagePermsLiveData.isInitialized) {

        if (packageLiveData.value?.uid == null || groups == null) {
            postValue(null)
            return
        } else if (groups == null) {
            return
        }

        val getLiveData = { groupName: String -> PermStateLiveData[packageName, groupName, user] }
+1 −6
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ import android.app.usage.UsageStats
import android.app.usage.UsageStatsManager
import android.app.usage.UsageStatsManager.INTERVAL_MONTHLY
import android.os.UserHandle
import android.os.UserManager
import com.android.permissioncontroller.DeviceUtils
import com.android.permissioncontroller.PermissionControllerApplication
import com.android.permissioncontroller.permission.utils.Utils
import kotlinx.coroutines.Job
@@ -54,13 +52,10 @@ class UsageStatsLiveData private constructor(

        val now = System.currentTimeMillis()
        val userMap = mutableMapOf<UserHandle, List<UsageStats>>()
        val userManager = app.getSystemService(UserManager::class.java)!!
        val enabledUsers = userManager.enabledProfiles
        for (user in UsersLiveData.value!!) {
            // If the user is not enabled, or if the user is a managed profile, and this is not an
            // android TV (where parental control accounts are managed profiles), do not get stats.
            if (user !in enabledUsers || (userManager.isManagedProfile(user.identifier) &&
                    !DeviceUtils.isTelevision(app))) {
            if (Utils.isUserDisabledOrWorkProfile(user)) {
                continue
            }
            val statsManager = Utils.getUserContext(app, user).getSystemService(
+1 −1
Original line number Diff line number Diff line
@@ -670,7 +670,7 @@ class AutoRevokeService : JobService() {
 * Packages using exempt services for the current user (package-name -> list<service-interfaces>
 * implemented by the package)
 */
private class ExemptServicesLiveData(val user: UserHandle)
class ExemptServicesLiveData(val user: UserHandle)
    : SmartUpdateMediatorLiveData<Map<String, List<String>>>() {
    private val serviceLiveDatas: List<SmartUpdateMediatorLiveData<Set<String>>> = listOf(
            ServiceLiveData[InputMethod.SERVICE_INTERFACE,
+7 −3
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@ class AppPermissionGroupsViewModel(
            this(groupName, isSystem, PermSubtitle.NONE)
    }

    val autoRevokeLiveData = AutoRevokeStateLiveData[packageName, user]

    /**
     * LiveData whose data is a map of grant category (either allowed or denied) to a list
     * of permission group names that match the key, and two booleans representing if this is a
@@ -103,6 +105,10 @@ class AppPermissionGroupsViewModel(
            addSource(fullStoragePermsLiveData) {
                updateIfActive()
            }
            addSource(autoRevokeLiveData) {
                removeSource(autoRevokeLiveData)
                updateIfActive()
            }
            updateIfActive()
        }

@@ -112,7 +118,7 @@ class AppPermissionGroupsViewModel(
                value = null
                return
            } else if (groups == null || (Manifest.permission_group.STORAGE in groups &&
                    !fullStoragePermsLiveData.isInitialized)) {
                    !fullStoragePermsLiveData.isInitialized) || !autoRevokeLiveData.isInitialized) {
                return
            }

@@ -168,8 +174,6 @@ class AppPermissionGroupsViewModel(
        }
    }

    val autoRevokeLiveData = AutoRevokeStateLiveData[packageName, user]

    fun setAutoRevoke(enabled: Boolean) {
        GlobalScope.launch(IPC) {
            val aom = PermissionControllerApplication.get()