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

Commit df157f99 authored by /e/ robot's avatar /e/ robot
Browse files

Merge remote-tracking branch 'origin/lineage-17.1' into v1-q

parents e44db0e1 14e1bbe0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto;
import com.android.server.pm.PackageManagerService;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -330,6 +331,7 @@ public class SnoozeHelper {
        return PendingIntent.getBroadcast(mContext,
                REQUEST_CODE_REPOST,
                new Intent(REPOST_ACTION)
                        .setPackage(PackageManagerService.PLATFORM_PACKAGE_NAME)
                        .setData(new Uri.Builder().scheme(REPOST_SCHEME).appendPath(key).build())
                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
                        .putExtra(EXTRA_KEY, key)
+2 −0
Original line number Diff line number Diff line
@@ -12466,6 +12466,8 @@ public class PackageManagerService extends IPackageManager.Stub
                    if (hasOldPkg) {
                        mPermissionManager.revokeRuntimePermissionsIfGroupChanged(pkg, oldPkg,
                                allPackageNames, mPermissionCallback);
                        mPermissionManager.revokeStoragePermissionsIfScopeExpanded(pkg, oldPkg,
                                mPermissionCallback);
                    }
                    if (hasPermissionDefinitionChanges) {
                        mPermissionManager.revokeRuntimePermissionsIfPermissionDefinitionChanged(
+65 −0
Original line number Diff line number Diff line
@@ -150,6 +150,9 @@ public class PermissionManagerService {
    private static final int USER_PERMISSION_FLAGS = FLAG_PERMISSION_USER_SET
            | FLAG_PERMISSION_USER_FIXED;

    /** All storage permissions */
    private static final List<String> STORAGE_PERMISSIONS = new ArrayList<>();

    /** If the permission of the value is granted, so is the key */
    private static final Map<String, String> FULLER_PERMISSION_MAP = new HashMap<>();

@@ -158,6 +161,9 @@ public class PermissionManagerService {
                Manifest.permission.ACCESS_FINE_LOCATION);
        FULLER_PERMISSION_MAP.put(Manifest.permission.INTERACT_ACROSS_USERS,
                Manifest.permission.INTERACT_ACROSS_USERS_FULL);
        STORAGE_PERMISSIONS.add(Manifest.permission.READ_EXTERNAL_STORAGE);
        STORAGE_PERMISSIONS.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        STORAGE_PERMISSIONS.add(Manifest.permission.ACCESS_MEDIA_LOCATION);
    }

    /** Lock to protect internal data access */
@@ -589,6 +595,50 @@ public class PermissionManagerService {
        return protectionLevel;
    }

    /**
     * If the app is updated, and has scoped storage permissions, then it is possible that the
     * app updated in an attempt to get unscoped storage. If so, revoke all storage permissions.
     * @param newPackage The new package that was installed
     * @param oldPackage The old package that was updated
     */
    private void revokeStoragePermissionsIfScopeExpanded(
            @NonNull PackageParser.Package newPackage,
            @NonNull PackageParser.Package oldPackage,
            @NonNull PermissionCallback permissionCallback) {
        boolean downgradedSdk = oldPackage.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.Q
                && newPackage.applicationInfo.targetSdkVersion < Build.VERSION_CODES.Q;
        boolean upgradedSdk = oldPackage.applicationInfo.targetSdkVersion < Build.VERSION_CODES.Q
                && newPackage.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.Q;
        boolean newlyRequestsLegacy = !upgradedSdk
                && !oldPackage.applicationInfo.hasRequestedLegacyExternalStorage()
                && newPackage.applicationInfo.hasRequestedLegacyExternalStorage();

        if (!newlyRequestsLegacy && !downgradedSdk) {
            return;
        }

        final int callingUid = Binder.getCallingUid();
        final int userId = UserHandle.getUserId(newPackage.applicationInfo.uid);
        int numRequestedPermissions = newPackage.requestedPermissions.size();
        for (int i = 0; i < numRequestedPermissions; i++) {
            PermissionInfo permInfo = getPermissionInfo(newPackage.requestedPermissions.get(i),
                    newPackage.packageName, 0, callingUid);
            if (permInfo == null || !STORAGE_PERMISSIONS.contains(permInfo.name)) {
                continue;
            }

            EventLog.writeEvent(0x534e4554, "171430330", newPackage.applicationInfo.uid,
                    "Revoking permission " + permInfo.name + " from package "
                            + newPackage.packageName + " as either the sdk downgraded "
                            + downgradedSdk + " or newly requested legacy full storage "
                            + newlyRequestsLegacy);

            revokeRuntimePermission(permInfo.name, newPackage.packageName,
                    false, userId, permissionCallback);
        }

    }

    /**
     * We might auto-grant permissions if any permission of the group is already granted. Hence if
     * the group of a granted permission changes we need to revoke it to avoid having permissions of
@@ -3119,6 +3169,21 @@ public class PermissionManagerService {
        public boolean isPermissionsReviewRequired(@NonNull Package pkg, @UserIdInt int userId) {
            return PermissionManagerService.this.isPermissionsReviewRequired(pkg, userId);
        }

        /**
         * If the app is updated, and has scoped storage permissions, then it is possible that the
         * app updated in an attempt to get unscoped storage. If so, revoke all storage permissions.
         * @param newPackage The new package that was installed
         * @param oldPackage The old package that was updated
         */
        public void revokeStoragePermissionsIfScopeExpanded(
                @NonNull PackageParser.Package newPackage,
                @NonNull PackageParser.Package oldPackage,
                @NonNull PermissionCallback permissionCallback) {
            PermissionManagerService.this.revokeStoragePermissionsIfScopeExpanded(newPackage,
                    oldPackage, permissionCallback);
        }

        @Override
        public void revokeRuntimePermissionsIfGroupChanged(
                @NonNull PackageParser.Package newPackage,
+11 −0
Original line number Diff line number Diff line
@@ -126,6 +126,17 @@ public abstract class PermissionManagerServiceInternal extends PermissionManager
            @NonNull ArrayList<String> allPackageNames,
            @NonNull PermissionCallback permissionCallback);

    /**
     * If the app is updated, and has scoped storage permissions, then it is possible that the
     * app updated in an attempt to get unscoped storage. If so, revoke all storage permissions.
     * @param newPackage The new package that was installed
     * @param oldPackage The old package that was updated
     */
    public abstract void revokeStoragePermissionsIfScopeExpanded(
            @NonNull PackageParser.Package newPackage,
            @NonNull PackageParser.Package oldPackage,
            @NonNull PermissionCallback permissionCallback);

    /**
     * Add all permissions in the given package.
     * <p>
+5 −5
Original line number Diff line number Diff line
@@ -485,7 +485,7 @@ public class LockTaskController {
            setStatusBarState(LOCK_TASK_MODE_NONE, userId);
            setKeyguardState(LOCK_TASK_MODE_NONE, userId);
            if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) {
                lockKeyguardIfNeeded();
                lockKeyguardIfNeeded(userId);
            }
            if (getDevicePolicyManager() != null) {
                getDevicePolicyManager().notifyLockTaskModeChanged(false, null, userId);
@@ -801,15 +801,15 @@ public class LockTaskController {
     * Helper method for locking the device immediately. This may be necessary when the device
     * leaves the pinned mode.
     */
    private void lockKeyguardIfNeeded() {
        if (shouldLockKeyguard()) {
    private void lockKeyguardIfNeeded(int userId) {
        if (shouldLockKeyguard(userId)) {
            mWindowManager.lockNow(null);
            mWindowManager.dismissKeyguard(null /* callback */, null /* message */);
            getLockPatternUtils().requireCredentialEntry(USER_ALL);
        }
    }

    private boolean shouldLockKeyguard() {
    private boolean shouldLockKeyguard(int userId) {
        // This functionality should be kept consistent with
        // com.android.settings.security.ScreenPinningSettings (see b/127605586)
        try {
@@ -819,7 +819,7 @@ public class LockTaskController {
        } catch (Settings.SettingNotFoundException e) {
            // Log to SafetyNet for b/127605586
            android.util.EventLog.writeEvent(0x534e4554, "127605586", -1, "");
            return getLockPatternUtils().isSecure(USER_CURRENT);
            return getLockPatternUtils().isSecure(userId);
        }
    }

Loading