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

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

Invalidate all livedatas for package on uninstall

Invalidate every livedata that depends on a package when that package is
uninstalled

Test: atest PermissionTest23#testDenialWithPrejudice,testGrantPreviouslyRevokedWithPrejudiceShowsPrompt,testDefault,testNoResidualPermissionsOnUninstall --rerun-until-failure 4
Fixes: 150902744
Fixes: 150801305
Bug: 151696874

Change-Id: I72775412c5cb58aca09b4498af900f8716964131
parent 1ff65274
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -272,7 +272,7 @@ class AppPermGroupUiInfoLiveData private constructor(
     * <p> Key value is a triple of string package name, string permission group name, and UserHandle,
     * value is its corresponding LiveData.
     */
    companion object : DataRepository<Triple<String, String, UserHandle>,
    companion object : DataRepositoryForPackage<Triple<String, String, UserHandle>,
            AppPermGroupUiInfoLiveData>() {
        override fun newValue(key: Triple<String, String, UserHandle>):
                AppPermGroupUiInfoLiveData {
+2 −1
Original line number Diff line number Diff line
@@ -151,7 +151,8 @@ class AutoRevokeStateLiveData private constructor(
     * <p> Key value is a pair of string package name and UserHandle, value is its corresponding
     * LiveData.
     */
    companion object : DataRepository<Pair<String, UserHandle>, AutoRevokeStateLiveData>() {
    companion object : DataRepositoryForPackage<Pair<String, UserHandle>,
        AutoRevokeStateLiveData>() {
        override fun newValue(key: Pair<String, UserHandle>): AutoRevokeStateLiveData {
            return AutoRevokeStateLiveData(PermissionControllerApplication.get(),
                key.first, key.second)
+23 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ abstract class DataRepository<K, V : DataRepository.InactiveTimekeeper> : Compon
    private val TIME_THRESHOLD_TIGHT_NANOS: Long = TimeUnit.NANOSECONDS.convert(1, TimeUnit.MINUTES)
    private val TIME_THRESHOLD_ALL_NANOS: Long = 0

    private val data = mutableMapOf<K, V>()
    protected val data = mutableMapOf<K, V>()

    /**
     * Whether or not this data repository has been registered as a component callback yet
@@ -142,6 +142,28 @@ abstract class DataRepository<K, V : DataRepository.InactiveTimekeeper> : Compon
    }
}

/**
 * A DataRepository where all values are contingent on the existence of a package. Supports
 * invalidating all values tied to a package. Expects key to be a pair or triple, with the package
 * name as the first value of the key.
 */
abstract class DataRepositoryForPackage<K, V : DataRepository.InactiveTimekeeper>
    : DataRepository<K, V>() {

    /**
     * Invalidates every value with the packageName in the key.
     *
     * @param packageName The package to be invalidated
     */
    fun invalidateAllForPackage(packageName: String) {
        for (key in data.keys) {
            if (key is Pair<*, *> || key is Triple<*, *, *> && key.first == packageName) {
                data.remove(key)
            }
        }
    }
}

/**
 * A convenience to retrieve data from a repository with a composite key
 */
+1 −1
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ class LightAppPermGroupLiveData private constructor(
     * <p> Key value is a triple of string package name, string permission group name, and
     * UserHandle, value is its corresponding LiveData.
     */
    companion object : DataRepository<Triple<String, String, UserHandle>,
    companion object : DataRepositoryForPackage<Triple<String, String, UserHandle>,
        LightAppPermGroupLiveData>() {
        override fun newValue(key: Triple<String, String, UserHandle>):
            LightAppPermGroupLiveData {
+1 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ class LightPackageInfoLiveData private constructor(
     * <p> Key value is a string package name and UserHandle pair, value is its corresponding
     * LiveData.
     */
    companion object : DataRepository<Pair<String, UserHandle>,
    companion object : DataRepositoryForPackage<Pair<String, UserHandle>,
        LightPackageInfoLiveData>() {
        override fun newValue(key: Pair<String, UserHandle>): LightPackageInfoLiveData {
            return LightPackageInfoLiveData(PermissionControllerApplication.get(),
Loading