summaryrefslogtreecommitdiff
path: root/packages/ExternalStorageProvider/src
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2017-05-09 16:55:29 -0600
committerJeff Sharkey <jsharkey@android.com>2017-05-09 16:55:31 -0600
commit06823d4c2e0fc7d64bff5d3e155d690302e0ab80 (patch)
treed36c58bd4302fbb1526c5982e0570a7b022d2034 /packages/ExternalStorageProvider/src
parent00487cf9368df10aab90c5a194667ce56acb49e4 (diff)
Use "real" free space; refresh on large changes.
For volumes where the OS manages cached data, use the "free space" as reported by StorageStatsManager, which is the same value shown in the Settings app and other UI elements. Also, when the storage space changes significantly, invalidate anyone who was holding a cached "free space" value. Test: builds, boots Bug: 38146029 Change-Id: I4b3a484a8bf32cd137a83f1ea441beca6dc6719a
Diffstat (limited to 'packages/ExternalStorageProvider/src')
-rw-r--r--packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java
index b958c2873019..f844cc163bbe 100644
--- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java
+++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java
@@ -17,6 +17,7 @@
package com.android.externalstorage;
import android.annotation.Nullable;
+import android.app.usage.StorageStatsManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.UriPermission;
@@ -49,10 +50,12 @@ import com.android.internal.util.IndentingPrintWriter;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import java.util.UUID;
public class ExternalStorageProvider extends FileSystemProvider {
private static final String TAG = "ExternalStorage";
@@ -79,6 +82,7 @@ public class ExternalStorageProvider extends FileSystemProvider {
private static class RootInfo {
public String rootId;
public String volumeId;
+ public UUID storageUuid;
public int flags;
public String title;
public String docId;
@@ -124,6 +128,7 @@ public class ExternalStorageProvider extends FileSystemProvider {
final String rootId;
final String title;
+ final UUID storageUuid;
if (volume.getType() == VolumeInfo.TYPE_EMULATED) {
// We currently only support a single emulated volume mounted at
// a time, and it's always considered the primary
@@ -142,17 +147,20 @@ public class ExternalStorageProvider extends FileSystemProvider {
title = !TextUtils.isEmpty(deviceName)
? deviceName
: getContext().getString(R.string.root_internal_storage);
+ storageUuid = StorageManager.UUID_DEFAULT;
} else {
// This should cover all other storage devices, like an SD card
// or USB OTG drive plugged in. Using getBestVolumeDescription()
// will give us a nice string like "Samsung SD card" or "SanDisk USB drive"
final VolumeInfo privateVol = mStorageManager.findPrivateForEmulated(volume);
title = mStorageManager.getBestVolumeDescription(privateVol);
+ storageUuid = StorageManager.convert(privateVol.fsUuid);
}
} else if (volume.getType() == VolumeInfo.TYPE_PUBLIC
&& volume.getMountUserId() == userId) {
rootId = volume.getFsUuid();
title = mStorageManager.getBestVolumeDescription(volume);
+ storageUuid = null;
} else {
// Unsupported volume; ignore
continue;
@@ -172,6 +180,7 @@ public class ExternalStorageProvider extends FileSystemProvider {
root.rootId = rootId;
root.volumeId = volume.id;
+ root.storageUuid = storageUuid;
root.flags = Root.FLAG_LOCAL_ONLY
| Root.FLAG_SUPPORTS_SEARCH
| Root.FLAG_SUPPORTS_IS_CHILD;
@@ -385,8 +394,22 @@ public class ExternalStorageProvider extends FileSystemProvider {
row.add(Root.COLUMN_FLAGS, root.flags);
row.add(Root.COLUMN_TITLE, root.title);
row.add(Root.COLUMN_DOCUMENT_ID, root.docId);
- row.add(Root.COLUMN_AVAILABLE_BYTES,
- root.reportAvailableBytes ? root.path.getUsableSpace() : -1);
+
+ long availableBytes = -1;
+ if (root.reportAvailableBytes) {
+ if (root.storageUuid != null) {
+ try {
+ availableBytes = getContext()
+ .getSystemService(StorageStatsManager.class)
+ .getFreeBytes(root.storageUuid);
+ } catch (IOException e) {
+ Log.w(TAG, e);
+ }
+ } else {
+ availableBytes = root.path.getUsableSpace();
+ }
+ }
+ row.add(Root.COLUMN_AVAILABLE_BYTES, availableBytes);
}
}
return result;