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

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

Check if already watching UserPackageInfosLiveData before observing

Fixes: 155991162
Test: Manual
Change-Id: I6b50dbe186ee19478f8a235b22656edfe823ab05
parent 22b7dc7b
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -87,9 +87,6 @@ class LightPackageInfoLiveData private constructor(
        } catch (e: PackageManager.NameNotFoundException) {
            Log.w(LOG_TAG, "Package \"$packageName\" not found")
            invalidateSingle(packageName to user)
            if (watchingUserPackagesLiveData) {
                removeSource(userPackagesLiveData)
            }
            null
        })
    }
@@ -109,7 +106,7 @@ class LightPackageInfoLiveData private constructor(
            registeredUid = uid
            PermissionListenerMultiplexer.addCallback(it, this)
        }
        if (userPackagesLiveData.hasActiveObservers()) {
        if (userPackagesLiveData.hasActiveObservers() && !watchingUserPackagesLiveData) {
            watchingUserPackagesLiveData = true
            addSource(userPackagesLiveData) {
                updateFromUserPackageInfosLiveData()
@@ -128,8 +125,13 @@ class LightPackageInfoLiveData private constructor(
        if (packageInfo != null) {
            postValue(packageInfo)
        } else {
            // If the UserPackageInfosLiveData does not contain this package, check for removal
            // If the UserPackageInfosLiveData does not contain this package, check for removal, and
            // stop watching.
            updateAsync()
            if (watchingUserPackagesLiveData) {
                removeSource(UserPackageInfosLiveData[user])
                watchingUserPackagesLiveData = false
            }
        }
    }

@@ -143,6 +145,7 @@ class LightPackageInfoLiveData private constructor(
        }
        if (watchingUserPackagesLiveData) {
            removeSource(UserPackageInfosLiveData[user])
            watchingUserPackagesLiveData = false
        }
    }