summaryrefslogtreecommitdiff
path: root/apex/blobstore
diff options
context:
space:
mode:
author Sudheer Shanka <sudheersai@google.com> 2022-04-20 06:55:02 +0000
committer Sudheer Shanka <sudheersai@google.com> 2022-04-20 18:27:20 +0000
commit878e618b167b2fa66bc25d3ca4d6ce4f9659811b (patch)
tree0d026c439988060e172b490166ce613c42b3c18a /apex/blobstore
parent525fad6cb2e0946132ae4ab352284f85f3bf08bd (diff)
Add BlobStoreManager.releaseAllLeases().
Also, rename isAllowedBlobAccess() to isAllowedBlobStoreAccess(). Bug: 227589710 Test: atest ./apct-tests/perftests/blobstore/src/com/android/perftests/blob/BlobStorePerfTests.java Change-Id: I190c6c1789e16942e116c8602173040a05c14990
Diffstat (limited to 'apex/blobstore')
-rw-r--r--apex/blobstore/framework/java/android/app/blob/BlobStoreManager.java16
-rw-r--r--apex/blobstore/framework/java/android/app/blob/IBlobStoreManager.aidl1
-rw-r--r--apex/blobstore/service/java/com/android/server/blob/BlobStoreManagerService.java42
3 files changed, 53 insertions, 6 deletions
diff --git a/apex/blobstore/framework/java/android/app/blob/BlobStoreManager.java b/apex/blobstore/framework/java/android/app/blob/BlobStoreManager.java
index 38500aff34ea..f6ae56f01758 100644
--- a/apex/blobstore/framework/java/android/app/blob/BlobStoreManager.java
+++ b/apex/blobstore/framework/java/android/app/blob/BlobStoreManager.java
@@ -507,6 +507,22 @@ public class BlobStoreManager {
}
/**
+ * Release all the leases which are currently held by the caller.
+ *
+ * @hide
+ */
+ public void releaseAllLeases() throws Exception {
+ try {
+ mService.releaseAllLeases(mContext.getOpPackageName());
+ } catch (ParcelableException e) {
+ e.maybeRethrow(IOException.class);
+ throw new RuntimeException(e);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Return the remaining quota size for acquiring a lease (in bytes) which indicates the
* remaining amount of data that an app can acquire a lease on before the System starts
* rejecting lease requests.
diff --git a/apex/blobstore/framework/java/android/app/blob/IBlobStoreManager.aidl b/apex/blobstore/framework/java/android/app/blob/IBlobStoreManager.aidl
index 39a9fb4bb1f4..1566fa8b00d0 100644
--- a/apex/blobstore/framework/java/android/app/blob/IBlobStoreManager.aidl
+++ b/apex/blobstore/framework/java/android/app/blob/IBlobStoreManager.aidl
@@ -31,6 +31,7 @@ interface IBlobStoreManager {
void acquireLease(in BlobHandle handle, int descriptionResId, in CharSequence description,
long leaseTimeoutMillis, in String packageName);
void releaseLease(in BlobHandle handle, in String packageName);
+ void releaseAllLeases(in String packageName);
long getRemainingLeaseQuotaBytes(String packageName);
void waitForIdle(in RemoteCallback callback);
diff --git a/apex/blobstore/service/java/com/android/server/blob/BlobStoreManagerService.java b/apex/blobstore/service/java/com/android/server/blob/BlobStoreManagerService.java
index c83ca8c2e31d..9ac3e412b1e4 100644
--- a/apex/blobstore/service/java/com/android/server/blob/BlobStoreManagerService.java
+++ b/apex/blobstore/service/java/com/android/server/blob/BlobStoreManagerService.java
@@ -554,6 +554,21 @@ public class BlobStoreManagerService extends SystemService {
}
}
+ private void releaseAllLeasesInternal(int callingUid, String callingPackage) {
+ synchronized (mBlobsLock) {
+ // Remove the package from the leasee list
+ mBlobsMap.forEach((blobHandle, blobMetadata) -> {
+ blobMetadata.removeLeasee(callingPackage, callingUid);
+ });
+ writeBlobsInfoAsync();
+
+ if (LOGV) {
+ Slog.v(TAG, "Release all leases associated with pkg="
+ + callingPackage + ", uid=" + callingUid);
+ }
+ }
+ }
+
private long getRemainingLeaseQuotaBytesInternal(int callingUid, String callingPackage) {
synchronized (mBlobsLock) {
final long remainingQuota = BlobStoreConfig.getAppDataBytesLimit()
@@ -1376,7 +1391,7 @@ public class BlobStoreManagerService extends SystemService {
}
}
- private boolean isAllowedBlobAccess(int uid, String packageName) {
+ private boolean isAllowedBlobStoreAccess(int uid, String packageName) {
return (!Process.isSdkSandboxUid(uid) && !Process.isIsolated(uid)
&& !mPackageManagerInternal.isInstantApp(packageName, UserHandle.getUserId(uid)));
}
@@ -1442,7 +1457,7 @@ public class BlobStoreManagerService extends SystemService {
final int callingUid = Binder.getCallingUid();
verifyCallingPackage(callingUid, packageName);
- if (!isAllowedBlobAccess(callingUid, packageName)) {
+ if (!isAllowedBlobStoreAccess(callingUid, packageName)) {
throw new SecurityException("Caller not allowed to create session; "
+ "callingUid=" + callingUid + ", callingPackage=" + packageName);
}
@@ -1491,7 +1506,7 @@ public class BlobStoreManagerService extends SystemService {
final int callingUid = Binder.getCallingUid();
verifyCallingPackage(callingUid, packageName);
- if (!isAllowedBlobAccess(callingUid, packageName)) {
+ if (!isAllowedBlobStoreAccess(callingUid, packageName)) {
throw new SecurityException("Caller not allowed to open blob; "
+ "callingUid=" + callingUid + ", callingPackage=" + packageName);
}
@@ -1522,7 +1537,7 @@ public class BlobStoreManagerService extends SystemService {
final int callingUid = Binder.getCallingUid();
verifyCallingPackage(callingUid, packageName);
- if (!isAllowedBlobAccess(callingUid, packageName)) {
+ if (!isAllowedBlobStoreAccess(callingUid, packageName)) {
throw new SecurityException("Caller not allowed to open blob; "
+ "callingUid=" + callingUid + ", callingPackage=" + packageName);
}
@@ -1546,7 +1561,7 @@ public class BlobStoreManagerService extends SystemService {
final int callingUid = Binder.getCallingUid();
verifyCallingPackage(callingUid, packageName);
- if (!isAllowedBlobAccess(callingUid, packageName)) {
+ if (!isAllowedBlobStoreAccess(callingUid, packageName)) {
throw new SecurityException("Caller not allowed to open blob; "
+ "callingUid=" + callingUid + ", callingPackage=" + packageName);
}
@@ -1555,6 +1570,21 @@ public class BlobStoreManagerService extends SystemService {
}
@Override
+ public void releaseAllLeases(@NonNull String packageName) {
+ Objects.requireNonNull(packageName, "packageName must not be null");
+
+ final int callingUid = Binder.getCallingUid();
+ verifyCallingPackage(callingUid, packageName);
+
+ if (!isAllowedBlobStoreAccess(callingUid, packageName)) {
+ throw new SecurityException("Caller not allowed to open blob; "
+ + "callingUid=" + callingUid + ", callingPackage=" + packageName);
+ }
+
+ releaseAllLeasesInternal(callingUid, packageName);
+ }
+
+ @Override
public long getRemainingLeaseQuotaBytes(@NonNull String packageName) {
final int callingUid = Binder.getCallingUid();
verifyCallingPackage(callingUid, packageName);
@@ -1629,7 +1659,7 @@ public class BlobStoreManagerService extends SystemService {
final int callingUid = Binder.getCallingUid();
verifyCallingPackage(callingUid, packageName);
- if (!isAllowedBlobAccess(callingUid, packageName)) {
+ if (!isAllowedBlobStoreAccess(callingUid, packageName)) {
throw new SecurityException("Caller not allowed to open blob; "
+ "callingUid=" + callingUid + ", callingPackage=" + packageName);
}