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

Commit d82bdafc authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Do not inherit grant of background location

This is a special behavior, different from regular split-permissions.

Test: atest CtsPermissionTestCases:SplitPermissionTest
Change-Id: I305a9765e31a317409e3df5e6cf41cd48a6862c8
Fixes: 117171661
parent 17f65afe
Loading
Loading
Loading
Loading
+30 −11
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.pm.permission;

import static android.Manifest.permission.ACCESS_BACKGROUND_LOCATION;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.app.AppOpsManager.MODE_ALLOWED;
@@ -1128,8 +1129,8 @@ public class PermissionManagerService {
                                        }
                                    }
                                } else {
                                    int revokeOpSuccess = ps.revokeRuntimePermission(bp, userId);
                                    if (revokeOpSuccess
                                    int revokeResult = ps.revokeRuntimePermission(bp, userId);
                                    if (revokeResult
                                            != PermissionsState.PERMISSION_OPERATION_FAILURE) {

                                        if (DEBUG_PERMISSIONS) {
@@ -1269,6 +1270,8 @@ public class PermissionManagerService {
            @NonNull PermissionsState origPs,
            @NonNull PermissionsState ps, @NonNull PackageParser.Package pkg,
            @NonNull int[] updatedUserIds) {
        AppOpsManager appOpsManager = mContext.getSystemService(AppOpsManager.class);

        String pkgName = pkg.packageName;
        ArraySet<String> newImplicitPermissions = new ArraySet<>();

@@ -1331,11 +1334,26 @@ public class PermissionManagerService {
                                FLAG_PERMISSION_REVOKE_WHEN_REQUESTED);
                        updatedUserIds = ArrayUtils.appendInt(updatedUserIds, userId);

                        // SPECIAL BEHAVIOR for background location. Foreground only by default.
                        if (newPerm.equals(ACCESS_BACKGROUND_LOCATION)) {
                            int numSourcePerms = sourcePerms.size();
                            for (int sourcePermNum = 0; sourcePermNum < numSourcePerms;
                                    sourcePermNum++) {
                                String sourcePerm = sourcePerms.valueAt(sourcePermNum);

                                if (appOpsManager.unsafeCheckOpNoThrow(permissionToOp(sourcePerm),
                                        getUid(userId, getAppId(pkg.applicationInfo.uid)), pkgName)
                                        == MODE_ALLOWED) {
                                    setAppOpMode(sourcePerm, pkg, userId, MODE_FOREGROUND);
                                }
                            }
                        } else {
                            if (!origPs.hasRequestedPermission(sourcePerms)) {
                                // Both permissions are new, do nothing
                                if (DEBUG_PERMISSIONS) {
                                    Slog.i(TAG, newPerm + " does not inherit from " + sourcePerms
                                        + " for " + pkgName + " as split permission is also new");
                                            + " for " + pkgName
                                            + " as split permission is also new");
                                }

                                break;
@@ -1347,6 +1365,7 @@ public class PermissionManagerService {
                    }
                }
            }
        }

        return updatedUserIds;
    }