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

Commit 46e333d1 authored by Eugene Susla's avatar Eugene Susla
Browse files

Don't use stale LiveData values for auto-revoke

This may have an impact in case PermissionController
is running for a long time

Test: presubmit
Bug: 153607914
Change-Id: Ifa457791e6361ee1350a968bee75d06ad1f30c8f
parent 1767eadc
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -177,7 +177,7 @@ suspend fun dumpAutoRevokePermissions(context: Context): AutoRevokePermissionsDu
    }

    val dumpData = GlobalScope.async(IPC) {
        AutoRevokeDumpLiveData(context).getInitializedValue(staleOk = true)
        AutoRevokeDumpLiveData(context).getInitializedValue()
    }

    return AutoRevokePermissionsDumpProto.newBuilder()
@@ -245,7 +245,7 @@ private suspend fun revokePermissionsOnUnusedApps(
    // TODO ntmyren: remove once b/154796729 is fixed
    Log.i(LOG_TAG, "getting UserPackageInfoLiveData for all users " +
        "in AutoRevokePermissions")
    val unusedApps = AllPackageInfosLiveData.getInitializedValue(staleOk = true).toMutableMap()
    val unusedApps = AllPackageInfosLiveData.getInitializedValue().toMutableMap()

    val userStats = UsageStatsLiveData[getUnusedThresholdMs(context),
        if (DEBUG_OVERRIDE_THRESHOLDS) INTERVAL_DAILY else INTERVAL_MONTHLY].getInitializedValue()
@@ -306,12 +306,12 @@ private suspend fun revokePermissionsOnUnusedApps(

    // TODO: Support more than the current user
    val manifestExemptPackages = AutoRevokeManifestExemptPackagesLiveData[myUserHandle()]
            .getInitializedValue(staleOk = true)
            .getInitializedValue()

    // Exempt important system-bound services
    // TODO: Support more than the current user
    val exemptServicePackages = ExemptServicesLiveData[myUserHandle()]
            .getInitializedValue(staleOk = true).keys
            .getInitializedValue().keys

    val revokedApps = mutableListOf<Pair<String, UserHandle>>()
    val userManager = context.getSystemService(UserManager::class.java)
@@ -337,7 +337,7 @@ private suspend fun revokePermissionsOnUnusedApps(
            val anyPermsRevoked = AtomicBoolean(false)
            val pkgPermGroups: Map<String, List<String>>? =
                PackagePermissionsLiveData[packageName, user]
                    .getInitializedValue(staleOk = true)
                    .getInitializedValue()

            pkgPermGroups?.entries?.forEachInParallel(Main) { (groupName, _) ->
                if (groupName == PackagePermissionsLiveData.NON_RUNTIME_NORMAL_PERMS) {
@@ -346,7 +346,7 @@ private suspend fun revokePermissionsOnUnusedApps(

                val group: LightAppPermGroup =
                    LightAppPermGroupLiveData[packageName, groupName, user]
                        .getInitializedValue(staleOk = true)
                        .getInitializedValue()
                        ?: return@forEachInParallel

                val fixed = group.isBackgroundFixed || group.isForegroundFixed