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

Commit bf16066b authored by Jing Ji's avatar Jing Ji
Browse files

Only evaluate the appops when the preflight check says soft denied

.. in the permission check of the foreground service type policy.

Bug: 254662522
Bug: 246792057
Test: atest CtsAppFgsTestCases
Change-Id: I83c6bd370481b1404ba12fa1c7b6d99d3daabca8
parent 8af9e2cd
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import android.hardware.usb.UsbManager;
import android.healthconnect.HealthConnectManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.permission.PermissionCheckerManager;
import android.util.ArraySet;
import android.util.SparseArray;

@@ -880,11 +881,12 @@ public abstract class ForegroundServiceTypePolicy {
        int checkPermission(@NonNull Context context, @NonNull String name, int callerUid,
                int callerPid, String packageName, boolean allowWhileInUse) {
            // Simple case, check if it's already granted.
            if (PermissionChecker.checkPermissionForPreflight(context, name,
                    callerPid, callerUid, packageName) == PERMISSION_GRANTED) {
            @PackageManager.PermissionResult int result;
            if ((result = PermissionChecker.checkPermissionForPreflight(context, name,
                    callerPid, callerUid, packageName)) == PERMISSION_GRANTED) {
                return PERMISSION_GRANTED;
            }
            if (allowWhileInUse) {
            if (allowWhileInUse && result == PermissionCheckerManager.PERMISSION_SOFT_DENIED) {
                // Check its appops
                final int opCode = AppOpsManager.permissionToOpCode(name);
                final AppOpsManager appOpsManager = context.getSystemService(AppOpsManager.class);