summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorBiswarup Pal <biswarupp@google.com>2020-12-16 15:53:15 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-12-16 15:53:15 +0000
commit685eca7077dd6299196c36b415889e142d30e55b (patch)
tree8db0aa6f30ece3c8df52450ccc4d12750d7fc2ca /core/java/android
parent2a9790b42e054c11c5a73a012cf31f836219f4a9 (diff)
parentb23206602ade13e06a2dc68b257dbb426f3b8f85 (diff)
Merge "Add freeCache API to ExternalStorageService"
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/os/storage/StorageManagerInternal.java11
-rw-r--r--core/java/android/service/storage/ExternalStorageService.java28
-rw-r--r--core/java/android/service/storage/IExternalStorageService.aidl2
3 files changed, 41 insertions, 0 deletions
diff --git a/core/java/android/os/storage/StorageManagerInternal.java b/core/java/android/os/storage/StorageManagerInternal.java
index 55ba15a5e57b..b12bb2ece4c2 100644
--- a/core/java/android/os/storage/StorageManagerInternal.java
+++ b/core/java/android/os/storage/StorageManagerInternal.java
@@ -101,4 +101,15 @@ public abstract class StorageManagerInternal {
* Return true if uid is external storage service.
*/
public abstract boolean isExternalStorageService(int uid);
+
+ /**
+ * Frees cache held by ExternalStorageService.
+ *
+ * <p> Blocks until the service frees the cache or fails in doing so.
+ *
+ * @param volumeUuid uuid of the {@link StorageVolume} from which cache needs to be freed,
+ * null value indicates private internal volume.
+ * @param bytes number of bytes which need to be freed
+ */
+ public abstract void freeCache(@Nullable String volumeUuid, long bytes);
}
diff --git a/core/java/android/service/storage/ExternalStorageService.java b/core/java/android/service/storage/ExternalStorageService.java
index 3b4d84a1c668..0123c368583c 100644
--- a/core/java/android/service/storage/ExternalStorageService.java
+++ b/core/java/android/service/storage/ExternalStorageService.java
@@ -16,6 +16,7 @@
package android.service.storage;
+import android.annotation.BytesLong;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SdkConstant;
@@ -29,6 +30,7 @@ import android.os.ParcelFileDescriptor;
import android.os.ParcelableException;
import android.os.RemoteCallback;
import android.os.RemoteException;
+import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import com.android.internal.os.BackgroundThread;
@@ -37,6 +39,7 @@ import java.io.File;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.UUID;
/**
* A service to handle filesystem I/O from other apps.
@@ -147,6 +150,18 @@ public abstract class ExternalStorageService extends Service {
*/
public abstract void onVolumeStateChanged(@NonNull StorageVolume vol) throws IOException;
+ /**
+ * Called when any cache held by the ExternalStorageService needs to be freed.
+ *
+ * <p> Blocks until the service frees the cache or fails in doing so.
+ *
+ * @param volumeUuid uuid of the {@link StorageVolume} from which cache needs to be freed
+ * @param bytes number of bytes which need to be freed
+ */
+ public void onFreeCacheRequested(@NonNull UUID volumeUuid, @BytesLong long bytes) {
+ throw new UnsupportedOperationException("onFreeCacheRequested not implemented");
+ }
+
@Override
@NonNull
public final IBinder onBind(@NonNull Intent intent) {
@@ -183,6 +198,19 @@ public abstract class ExternalStorageService extends Service {
}
@Override
+ public void freeCache(String sessionId, String volumeUuid, long bytes,
+ RemoteCallback callback) {
+ mHandler.post(() -> {
+ try {
+ onFreeCacheRequested(StorageManager.convert(volumeUuid), bytes);
+ sendResult(sessionId, null /* throwable */, callback);
+ } catch (Throwable t) {
+ sendResult(sessionId, t, callback);
+ }
+ });
+ }
+
+ @Override
public void endSession(String sessionId, RemoteCallback callback) throws RemoteException {
mHandler.post(() -> {
try {
diff --git a/core/java/android/service/storage/IExternalStorageService.aidl b/core/java/android/service/storage/IExternalStorageService.aidl
index 30fefd33016d..d06671b3fb9f 100644
--- a/core/java/android/service/storage/IExternalStorageService.aidl
+++ b/core/java/android/service/storage/IExternalStorageService.aidl
@@ -30,4 +30,6 @@ oneway interface IExternalStorageService
void endSession(@utf8InCpp String sessionId, in RemoteCallback callback);
void notifyVolumeStateChanged(@utf8InCpp String sessionId, in StorageVolume vol,
in RemoteCallback callback);
+ void freeCache(@utf8InCpp String sessionId, in String volumeUuid, long bytes,
+ in RemoteCallback callback);
} \ No newline at end of file