Loading core/java/android/os/storage/StorageManager.java +30 −16 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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; } Loading @@ -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); } Loading Loading
core/java/android/os/storage/StorageManager.java +30 −16 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -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; } Loading @@ -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); } Loading