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

Commit 85a17af9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove a binder call from updateExternalStorageFileQuotaType" into main

parents 08d80a72 6b447a04
Loading
Loading
Loading
Loading
+30 −16
Original line number Diff line number Diff line
@@ -120,6 +120,8 @@ import java.util.concurrent.Executor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * StorageManager is the interface to the systems storage service. The storage
@@ -2512,6 +2514,9 @@ public class StorageManager {
        return userId * PER_USER_RANGE + projectId;
    }

    private static final Pattern PATTERN_USER_ID = Pattern.compile(
            "(?i)^/storage/emulated/([0-9]+)");

    /**
     * Let StorageManager know that the quota type for a file on external storage should
     * be updated. Android tracks quotas for various media types. Consequently, this should be
@@ -2541,11 +2546,19 @@ public class StorageManager {
    @SystemApi
    public void updateExternalStorageFileQuotaType(@NonNull File path,
            @QuotaType int quotaType) throws IOException {
        if (!path.exists()) return;

        long projectId;
        final String filePath = path.getCanonicalPath();

        final int userId;
        final Matcher matcher = PATTERN_USER_ID.matcher(filePath);
        if (matcher.find()) {
            userId = Integer.parseInt(matcher.group(1));
        } else {  // fallback
            int volFlags = FLAG_REAL_STATE | FLAG_INCLUDE_INVISIBLE;
        // If caller has MANAGE_EXTERNAL_STORAGE permission, results from User Profile(s) are also
        // returned by enabling FLAG_INCLUDE_SHARED_PROFILE.
            // If caller has MANAGE_EXTERNAL_STORAGE permission, results from User Profile(s) are
            // also returned by enabling FLAG_INCLUDE_SHARED_PROFILE.
            if (mContext.checkSelfPermission(MANAGE_EXTERNAL_STORAGE) == PERMISSION_GRANTED) {
                volFlags |= FLAG_INCLUDE_SHARED_PROFILE;
            }
@@ -2559,8 +2572,9 @@ public class StorageManager {
                // We only support quota tracking on emulated filesystems
                return;
            }
            userId = volume.getOwner().getIdentifier();
        }

        final int userId = volume.getOwner().getIdentifier();
        if (userId < 0) {
            throw new IllegalStateException("Failed to update quota type for " + filePath);
        }