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

Commit c3132f1b authored by Nate Myren's avatar Nate Myren Committed by Android (Google) Code Review
Browse files

Merge "Invalidate LiveDatas when null" into rvc-dev

parents c0878335 1f693b2b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ class AppPermGroupUiInfoLiveData private constructor(
        if (packageInfo == null || permissionGroup == null || permissionState == null) {
            if (packageInfoLiveData.isInitialized && permGroupLiveData.isInitialized &&
                permissionStateLiveData.isInitialized) {
                invalidateSingle(Triple(packageName, permGroupName, user))
                value = null
            }
            return
+8 −2
Original line number Diff line number Diff line
@@ -105,9 +105,15 @@ abstract class DataRepository<K, V : DataRepository.InactiveTimekeeper> : Compon
        // Do nothing, but required to override by interface
    }

    fun invalidateSingle(key: K) {
        data.remove(key)
    }

    private fun trimInactiveData(threshold: Long) {
        data.entries.removeAll { (_, value) ->
            value.timeInactive?.let { it >= threshold } ?: false
        data.keys.toList().forEach { key ->
            if (data[key]?.timeInactive?.let { it >= threshold } == true) {
                data.remove(key)
            }
        }
    }

+5 −0
Original line number Diff line number Diff line
@@ -59,8 +59,11 @@ class LightAppPermGroupLiveData private constructor(
            updateIfActive()
        }

        val key = Triple(packageName, permGroupName, user)

        addSource(permStateLiveData) { permStates ->
            if (permStates == null && permStateLiveData.isInitialized) {
                invalidateSingle(key)
                value = null
            } else {
                updateIfActive()
@@ -69,6 +72,7 @@ class LightAppPermGroupLiveData private constructor(

        addSource(permGroupLiveData) { permGroup ->
            if (permGroup == null && permGroupLiveData.isInitialized) {
                invalidateSingle(key)
                value = null
            } else {
                updateIfActive()
@@ -77,6 +81,7 @@ class LightAppPermGroupLiveData private constructor(

        addSource(packageInfoLiveData) { packageInfo ->
            if (packageInfo == null && packageInfoLiveData.isInitialized) {
                invalidateSingle(key)
                value = null
            } else {
                updateIfActive()
+1 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ class LightPackageInfoLiveData private constructor(
                PackageManager.GET_PERMISSIONS))
        } catch (e: PackageManager.NameNotFoundException) {
            Log.w(LOG_TAG, "Package \"$packageName\" not found")
            invalidateSingle(packageName to user)
            null
        })
    }
+5 −0
Original line number Diff line number Diff line
@@ -44,6 +44,11 @@ class PackagePermissionsLiveData private constructor(

    init {
        addSource(packageInfoLiveData) {
            if (packageInfoLiveData.isInitialized && packageInfoLiveData.value == null) {
                invalidateSingle(packageName to user)
                value = null
                return@addSource
            }
            updateIfActive()
        }
    }
Loading