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

Commit 648ec93f authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6216739 from 627d3db0 to rvc-release

Change-Id: I183d13728a8683f0e55e896735c1f70159b3b01a
parents b9250326 627d3db0
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -51,10 +51,12 @@ class PermStateLiveData private constructor(

    private var uid: Int? = null
    private var registeredUid: Int? = null
    private var currentPackageInfo: LightPackageInfo? = null

    init {
        addSource(packageInfoLiveData) {
            checkForUidUpdate(it)
            currentPackageInfo = it
            updateAsync()
        }

@@ -71,7 +73,8 @@ class PermStateLiveData private constructor(
        if (!packageInfoLiveData.isInitialized || !groupLiveData.isInitialized) {
            return
        }
        val packageInfo = packageInfoLiveData.value

        val packageInfo = currentPackageInfo
        val permissionGroup = groupLiveData.value
        if (packageInfo == null || permissionGroup == null) {
            postValue(null)
@@ -84,7 +87,7 @@ class PermStateLiveData private constructor(
                val packageFlags = packageInfo.requestedPermissionsFlags[index]
                val permFlags = context.packageManager.getPermissionFlags(permInfo.name,
                    packageName, user)
                var granted = packageFlags and PackageInfo.REQUESTED_PERMISSION_GRANTED != 0 &&
                val granted = packageFlags and PackageInfo.REQUESTED_PERMISSION_GRANTED != 0 &&
                    permFlags and PackageManager.FLAG_PERMISSION_REVOKED_COMPAT == 0

                if (job.isCancelled) {
+16 −7
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.permissioncontroller.permission.data

import android.os.Handler
import android.os.Looper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
@@ -28,7 +30,11 @@ import kotlinx.coroutines.launch
abstract class SmartAsyncMediatorLiveData<T> : SmartUpdateMediatorLiveData<T>() {

    private var currentJob: Job? = null
    @Volatile
    private var jobQueued = false
    @Volatile
    private var jobRunning = false
    private val mainHandler = Handler(Looper.getMainLooper())

    /**
     * The main function which will load data. It should periodically check isCancelled to see if
@@ -41,22 +47,25 @@ abstract class SmartAsyncMediatorLiveData<T> : SmartUpdateMediatorLiveData<T>()
    }

    open fun updateAsync() {
        if (currentJob?.isActive == true) {
        if (jobRunning) {
            jobQueued = true
            return
        } else {
            jobRunning = true
        }

        GlobalScope.launch(Dispatchers.IO) {
            currentJob = coroutineContext[Job]
            loadDataAndPostValue(currentJob!!)
        }

            jobRunning = false
            if (jobQueued) {
                jobQueued = false
            currentJob?.cancel()
                mainHandler.post {
                    updateAsync()
                }
            }
        }
    }

    override fun onInactive() {
        cancelJobIfRunning()
+14 −1
Original line number Diff line number Diff line
@@ -16,10 +16,23 @@

package com.android.permissioncontroller.permission.model.livedatatypes

import android.content.pm.PackageManager

/**
 * A class representing the state of one permission for one package.
 *
 * @param permFlags The system flags of the permission
 * @param granted whether or not the permission is granted
 */
data class PermState(val permFlags: Int, val granted: Boolean)
data class PermState(val permFlags: Int, val granted: Boolean) {

    override fun toString(): String {
        return "granted: $granted, " +
            "user fixed: ${permFlags and PackageManager.FLAG_PERMISSION_USER_FIXED != 0} " +
            "user set: ${permFlags and PackageManager.FLAG_PERMISSION_USER_SET != 0} " +
            "one time: ${permFlags and PackageManager.FLAG_PERMISSION_ONE_TIME != 0} " +
            "review required: " +
            "${permFlags and PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED != 0} " +
            "revoked compat: ${permFlags and PackageManager.FLAG_PERMISSION_REVOKED_COMPAT != 0}"
    }
}
+14 −1
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.text.BidiFormatter;
import android.view.LayoutInflater;
@@ -77,6 +79,7 @@ import kotlin.Pair;
 */
public class AppPermissionFragment extends SettingsWithLargeHeader {
    private static final String LOG_TAG = "AppPermissionFragment";
    private static final long POST_DELAY_MS = 20;

    static final String GRANT_CATEGORY = "grant_category";

@@ -173,7 +176,17 @@ public class AppPermissionFragment extends SettingsWithLargeHeader {
                getActivity().getApplication(), mPackageName, mPermGroupName, mUser, sessionId);
        mViewModel = new ViewModelProvider(this, factory).get(AppPermissionViewModel.class);

        mViewModel.getButtonStateLiveData().observe(this, this::setRadioButtonsState);
        boolean[] firstRun = new boolean[] { true };
        Handler delayHandler = new Handler(Looper.getMainLooper());
        mViewModel.getButtonStateLiveData().observe(this, buttonState -> {
            if (firstRun[0]) {
                firstRun[0] = false;
                setRadioButtonsState(buttonState);
            } else {
                delayHandler.removeCallbacksAndMessages(null);
                delayHandler.postDelayed(() -> setRadioButtonsState(buttonState), POST_DELAY_MS);
            }
        });
        mViewModel.getDetailResIdLiveData().observe(this, this::setDetail);
        mViewModel.getShowAdminSupportLiveData().observe(this, this::setAdminSupportDetail);
    }
+40 −37
Original line number Diff line number Diff line
@@ -404,18 +404,14 @@ class AppPermissionViewModel(
        var newGroup = group
        val oldGroup = group

        if (shouldGrantForeground) {
            newGroup = KotlinUtils.grantForegroundRuntimePermissions(app, newGroup)

            if (!wasForegroundGranted) {
                SafetyNetLogger.logPermissionToggled(newGroup)
            }
        }

        if (shouldGrantBackground && group.hasBackgroundGroup) {
            newGroup = KotlinUtils.grantBackgroundRuntimePermissions(app, newGroup)
        if (shouldRevokeBackground && group.hasBackgroundGroup &&
            (wasBackgroundGranted || userFixed != group.background.isUserFixed)) {
            newGroup = KotlinUtils.revokeBackgroundRuntimePermissions(app,
                newGroup, userFixed)

            if (!wasBackgroundGranted) {
            // only log if we have actually denied permissions, not if we switch from
            // "ask every time" to denied
            if (wasBackgroundGranted) {
                SafetyNetLogger.logPermissionToggled(newGroup, true)
            }
        }
@@ -432,17 +428,22 @@ class AppPermissionViewModel(
            }
        }

        if (shouldRevokeBackground && group.hasBackgroundGroup &&
            (wasBackgroundGranted || userFixed != group.background.isUserFixed)) {
            newGroup = KotlinUtils.revokeBackgroundRuntimePermissions(app,
                newGroup, userFixed)
        if (shouldGrantForeground) {
            newGroup = KotlinUtils.grantForegroundRuntimePermissions(app, newGroup)

            // only log if we have actually denied permissions, not if we switch from
            // "ask every time" to denied
            if (wasBackgroundGranted) {
            if (!wasForegroundGranted) {
                SafetyNetLogger.logPermissionToggled(newGroup)
            }
        }

        if (shouldGrantBackground && group.hasBackgroundGroup) {
            newGroup = KotlinUtils.grantBackgroundRuntimePermissions(app, newGroup)

            if (!wasBackgroundGranted) {
                SafetyNetLogger.logPermissionToggled(newGroup, true)
            }
        }

        logPermissionChanges(oldGroup, newGroup, buttonClicked)
    }

@@ -465,13 +466,7 @@ class AppPermissionViewModel(

        var newGroup = group
        val oldGroup = group
        if (changeRequest andValue ChangeRequest.REVOKE_FOREGROUND != 0) {
            newGroup = KotlinUtils.revokeForegroundRuntimePermissions(app, newGroup, userFixed)
            if (wasForegroundGranted) {
                SafetyNetLogger.logPermissionToggled(newGroup)
            }
            hasDefaultPermissions = group.foreground.isGrantedByDefault
        }

        if (changeRequest andValue ChangeRequest.REVOKE_BACKGROUND != 0 &&
            group.hasBackgroundGroup) {
            newGroup = KotlinUtils.revokeBackgroundRuntimePermissions(app, newGroup, userFixed)
@@ -482,6 +477,14 @@ class AppPermissionViewModel(
            hasDefaultPermissions = hasDefaultPermissions ||
                group.background.isGrantedByDefault
        }

        if (changeRequest andValue ChangeRequest.REVOKE_FOREGROUND != 0) {
            newGroup = KotlinUtils.revokeForegroundRuntimePermissions(app, newGroup, userFixed)
            if (wasForegroundGranted) {
                SafetyNetLogger.logPermissionToggled(newGroup)
            }
            hasDefaultPermissions = group.foreground.isGrantedByDefault
        }
        logPermissionChanges(oldGroup, newGroup, buttonPressed)

        if (hasDefaultPermissions || !group.supportsRuntimePerms) {
Loading