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

Commit 76561c0e authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6477313 from ff044db3 to rvc-release

Change-Id: I9a1b49e988775f6ee148b1977dd1545aee1978df
parents 37490ca4 ff044db3
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
        }
    }

+13 −8
Original line number Diff line number Diff line
@@ -137,12 +137,12 @@ abstract class SmartUpdateMediatorLiveData<T> : MediatorLiveData<T>(),
    fun observeStale(owner: LifecycleOwner, observer: Observer<in T>) {
        val oldStaleObserver = hasStaleObserver()
        staleObservers.add(owner to observer)
        notifySourcesOnStaleUpdates(oldStaleObserver, true)
        if (owner == ForeverActiveLifecycle) {
            observeForever(observer)
        } else {
            observe(owner, observer)
        }
        updateSourceStaleObservers(oldStaleObserver, true)
    }

    override fun <S : Any?> addSource(source: LiveData<S>, onChanged: Observer<in S>) {
@@ -181,7 +181,7 @@ abstract class SmartUpdateMediatorLiveData<T> : MediatorLiveData<T>(),
    }

    @MainThread
    private fun <S : Any?> updateStaleChildNotify(
    private fun <S : Any?> updateShouldSendStaleUpdates(
        liveData: SmartUpdateMediatorLiveData<S>,
        sendStaleUpdates: Boolean
    ) {
@@ -196,30 +196,35 @@ abstract class SmartUpdateMediatorLiveData<T> : MediatorLiveData<T>(),
    override fun removeObserver(observer: Observer<in T>) {
        val oldStaleObserver = hasStaleObserver()
        staleObservers.removeIf { it.second == observer }
        notifySourcesOnStaleUpdates(oldStaleObserver, hasStaleObserver())
        super.removeObserver(observer)
        updateSourceStaleObservers(oldStaleObserver, hasStaleObserver())
    }

    @MainThread
    override fun removeObservers(owner: LifecycleOwner) {
        val oldStaleObserver = hasStaleObserver()
        staleObservers.removeIf { it.first == owner }
        notifySourcesOnStaleUpdates(oldStaleObserver, hasStaleObserver())
        super.removeObservers(owner)
        updateSourceStaleObservers(oldStaleObserver, hasStaleObserver())
    }

    @MainThread
    private fun notifySourcesOnStaleUpdates(oldHasStale: Boolean, newHasStale: Boolean) {
        if (oldHasStale == newHasStale) {
    override fun observeForever(observer: Observer<in T>) {
        super.observeForever(observer)
    }

    @MainThread
    private fun updateSourceStaleObservers(hadStaleObserver: Boolean, hasStaleObserver: Boolean) {
        if (hadStaleObserver == hasStaleObserver) {
            return
        }
        for (liveData in sources) {
            liveData.updateStaleChildNotify(this, hasStaleObserver())
            liveData.updateShouldSendStaleUpdates(this, hasStaleObserver)
        }

        // if all sources are not stale, and we just requested stale updates, and we are stale,
        // update our value
        if (sources.all { !it.isStale } && newHasStale && isStale) {
        if (sources.all { !it.isStale } && hasStaleObserver && isStale) {
            updateIfActive()
        }
    }
+4 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.app.usage.UsageStatsManager.INTERVAL_MONTHLY
import android.os.UserHandle
import android.os.UserManager
import com.android.permissioncontroller.PermissionControllerApplication
import com.android.permissioncontroller.permission.utils.Utils
import kotlinx.coroutines.Job

/**
@@ -57,8 +58,9 @@ class UsageStatsLiveData private constructor(
            if (user !in enabledUsers) {
                continue
            }
            userMap[user] = app.getSystemService(UsageStatsManager::class.java)!!.queryUsageStats(
            interval, now - searchTimeMs, now)
            val statsManager = Utils.getUserContext(app, user).getSystemService(
                UsageStatsManager::class.java)!!
            userMap[user] = statsManager.queryUsageStats(interval, now - searchTimeMs, now)
        }

        postValue(userMap)
+17 −6
Original line number Diff line number Diff line
@@ -743,8 +743,8 @@ public final class AppPermissionGroup implements Comparable<AppPermissionGroup>
        return false;
    }

    public boolean grantRuntimePermissions(boolean fixedByTheUser) {
        return grantRuntimePermissions(fixedByTheUser, null);
    public boolean grantRuntimePermissions(boolean setByTheUser, boolean fixedByTheUser) {
        return grantRuntimePermissions(setByTheUser, fixedByTheUser, null);
    }

    /**
@@ -843,6 +843,7 @@ public final class AppPermissionGroup implements Comparable<AppPermissionGroup>
     * <p>This does <u>only</u> grant permissions in {@link #mPermissions}, i.e. usually not
     * the background permissions.
     *
     * @param setByTheUser If the user has made the decision. This does not unset the flag
     * @param fixedByTheUser If the user requested that she/he does not want to be asked again
     * @param filterPermissions If {@code null} all permissions of the group will be granted.
     *                          Otherwise only permissions in {@code filterPermissions} will be
@@ -850,7 +851,8 @@ public final class AppPermissionGroup implements Comparable<AppPermissionGroup>
     *
     * @return {@code true} iff all permissions of this group could be granted.
     */
    public boolean grantRuntimePermissions(boolean fixedByTheUser, String[] filterPermissions) {
    public boolean grantRuntimePermissions(boolean setByTheUser, boolean fixedByTheUser,
            String[] filterPermissions) {
        boolean killApp = false;
        boolean wasAllGranted = true;

@@ -889,10 +891,19 @@ public final class AppPermissionGroup implements Comparable<AppPermissionGroup>

                // Update the permission flags.
                if (!fixedByTheUser) {
                    // Now the apps can ask for the permission as the user
                    // no longer has it fixed in a denied state.
                    if (permission.isUserFixed() || permission.isUserSet()) {
                    if (permission.isUserFixed()) {
                        permission.setUserFixed(false);
                    }
                    if (setByTheUser) {
                        if (!permission.isUserSet()) {
                            permission.setUserSet(true);
                        }
                    }
                } else {
                    if (!permission.isUserFixed()) {
                        permission.setUserFixed(true);
                    }
                    if (permission.isUserSet()) {
                        permission.setUserSet(false);
                    }
                }
+1 −1
Original line number Diff line number Diff line
@@ -390,7 +390,7 @@ public class PermissionApps {
        }

        public void grantRuntimePermissions() {
            mAppPermissionGroup.grantRuntimePermissions(false);
            mAppPermissionGroup.grantRuntimePermissions(true, false);
        }

        public void revokeRuntimePermissions() {
Loading