Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/app/blob/BlobStoreManager#nestedclasses) \| [Methods](https://developer.android.com/reference/android/app/blob/BlobStoreManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/app/blob/BlobStoreManager#inhmethods)

# BlobStoreManager

*** ** * ** ***


`
public


class
BlobStoreManager
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.blob.BlobStoreManager |

<br />

*** ** * ** ***

This class provides access to the blob store managed by the system.

Apps can publish and access a data blob using a `https://developer.android.com/reference/android/app/blob/BlobHandle` object which can
be created with `https://developer.android.com/reference/android/app/blob/BlobHandle#createWithSha256(byte[],%20java.lang.CharSequence,%20long,%20java.lang.String)`.
This `https://developer.android.com/reference/android/app/blob/BlobHandle` object encapsulates the following pieces of information used for
identifying the blobs:

- `https://developer.android.com/reference/android/app/blob/BlobHandle#getSha256Digest()`
- `https://developer.android.com/reference/android/app/blob/BlobHandle#getLabel()`
- `https://developer.android.com/reference/android/app/blob/BlobHandle#getExpiryTimeMillis()`
- `https://developer.android.com/reference/android/app/blob/BlobHandle#getTag()`

For two `https://developer.android.com/reference/android/app/blob/BlobHandle` objects to be considered identical, all these pieces of information must be equal.

For contributing a new data blob, an app needs to create a session using
`https://developer.android.com/reference/android/app/blob/BlobStoreManager#createSession(android.app.blob.BlobHandle)` and then open this session for writing using
`https://developer.android.com/reference/android/app/blob/BlobStoreManager#openSession(long)`.

The following code snippet shows how to create and open a session for writing:

```
    final long sessionId = blobStoreManager.createSession(blobHandle);
    try (BlobStoreManager.Session session = blobStoreManager.openSession(sessionId)) {
        try (OutputStream out = new ParcelFileDescriptor.AutoCloseOutputStream(
                session.openWrite(offsetBytes, lengthBytes))) {
            writeData(out);
        }
    }
```

If all the data could not be written in a single attempt, apps can close this session
and re-open it again using the session id obtained via
`https://developer.android.com/reference/android/app/blob/BlobStoreManager#createSession(android.app.blob.BlobHandle)`. Note that the session data is persisted
and can be re-opened for completing the data contribution, even across device reboots.

After the data is written to the session, it can be committed using
`https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#commit(java.util.concurrent.Executor,%20java.util.function.Consumer<java.lang.Integer>)`. Until the session is committed, data written
to the session will not be shared with any app.

Once a session is committed using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#commit(java.util.concurrent.Executor,%20java.util.function.Consumer<java.lang.Integer>)`,
any data written as part of this session is sealed and cannot be modified anymore.

Before committing the session, apps can indicate which apps are allowed to access the
contributed data using one or more of the following access modes:

- `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPackageAccess(java.lang.String,%20byte[])` which will allow specific packages to access the blobs.
- `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowSameSignatureAccess()` which will allow only apps which are signed with the same certificate as the app which contributed the blob to access it.
- `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPublicAccess()` which will allow any app on the device to access the blob.

The following code snippet shows how to specify the access mode and commit the session:

```
    try (BlobStoreManager.Session session = blobStoreManager.openSession(sessionId)) {
        try (OutputStream out = new ParcelFileDescriptor.AutoCloseOutputStream(
                session.openWrite(offsetBytes, lengthBytes))) {
            writeData(out);
        }
        session.allowSameSignatureAccess();
        session.allowPackageAccess(packageName, certificate);
        session.commit(executor, callback);
    }
```

Apps that satisfy at least one of the access mode constraints specified by the publisher
of the data blob will be able to access it.

A data blob published without specifying any of
these access modes will be considered private and only the app that contributed the data
blob will be allowed to access it. This is still useful for overall device system health as
the System can try to keep one copy of data blob on disk when multiple apps contribute the
same data.

It is strongly recommended that apps use one of
`https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPackageAccess(java.lang.String,%20byte[])` or `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowSameSignatureAccess()`
when they know, ahead of time, the set of apps they would like to share the blobs with.
`https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPublicAccess()` is meant for publicly available data committed from
libraries and SDKs.

Once a data blob is committed with `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#commit(java.util.concurrent.Executor,%20java.util.function.Consumer<java.lang.Integer>)`, it
can be accessed using `https://developer.android.com/reference/android/app/blob/BlobStoreManager#openBlob(android.app.blob.BlobHandle)`, assuming the caller
satisfies constraints of any of the access modes associated with that data blob. An app may
acquire a lease on a blob with `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int)` and
release the lease with `https://developer.android.com/reference/android/app/blob/BlobStoreManager#releaseLease(android.app.blob.BlobHandle)`. A blob will not be
deleted from the system while there is at least one app leasing it.

The following code snippet shows how to access the data blob:

```
    try (InputStream in = new ParcelFileDescriptor.AutoCloseInputStream(
            blobStoreManager.openBlob(blobHandle)) {
        useData(in);
    }
```
.   
Restricted for SDK Runtime environment in API level 34.

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session` Represents an ongoing session of a blob's contribution to the blob store managed by the system. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager#abandonSession(long)(long sessionId) ` Abandons an existing session and deletes any data that was written to that session so far. |
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int,%20long)(https://developer.android.com/reference/android/app/blob/BlobHandle blobHandle, int descriptionResId, long leaseExpiryTimeMillis) ` Acquire a lease to the blob represented by `blobHandle`. |
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20java.lang.CharSequence,%20long)(https://developer.android.com/reference/android/app/blob/BlobHandle blobHandle, https://developer.android.com/reference/java/lang/CharSequence description, long leaseExpiryTimeMillis) ` Acquire a lease to the blob represented by `blobHandle`. |
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20java.lang.CharSequence)(https://developer.android.com/reference/android/app/blob/BlobHandle blobHandle, https://developer.android.com/reference/java/lang/CharSequence description) ` Acquire a lease to the blob represented by `blobHandle`. |
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int)(https://developer.android.com/reference/android/app/blob/BlobHandle blobHandle, int descriptionResId) ` Acquire a lease to the blob represented by `blobHandle`. |
| ` long` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager#createSession(android.app.blob.BlobHandle)(https://developer.android.com/reference/android/app/blob/BlobHandle blobHandle) ` Create a new session using the given `https://developer.android.com/reference/android/app/blob/BlobHandle`, returning a unique id that represents the session. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/blob/BlobHandle>` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager#getLeasedBlobs()() ` Return the `https://developer.android.com/reference/android/app/blob/BlobHandle` corresponding to the data blobs that the calling app currently has a lease on. |
| ` long` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager#getRemainingLeaseQuotaBytes()() ` 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. |
| ` https://developer.android.com/reference/android/os/ParcelFileDescriptor` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager#openBlob(android.app.blob.BlobHandle)(https://developer.android.com/reference/android/app/blob/BlobHandle blobHandle) ` Opens an existing blob for reading from the blob store managed by the system. |
| ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager#openSession(long)(long sessionId) ` Open an existing session to actively perform work. |
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager#releaseLease(android.app.blob.BlobHandle)(https://developer.android.com/reference/android/app/blob/BlobHandle blobHandle) ` Release any active lease to the blob represented by `blobHandle` which is currently held by the caller. |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


## Public methods

### abandonSession

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void abandonSession (long sessionId)
```

Abandons an existing session and deletes any data that was written to that session so far.

<br />

| Parameters ||
|---|---|
| `sessionId` | `long`: a unique id obtained via `https://developer.android.com/reference/android/app/blob/BlobStoreManager#createSession(android.app.blob.BlobHandle)` that represents a particular session. Value is 1 or greater <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while deleting the session. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller does not own the session, or the session does not exist or is invalid. |

### acquireLease

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void acquireLease (BlobHandle blobHandle, 
                int descriptionResId, 
                long leaseExpiryTimeMillis)
```

Acquire a lease to the blob represented by `blobHandle`. This lease indicates to the
system that the caller wants the blob to be kept around.

Any active leases will be automatically released when the blob's expiry time
(`https://developer.android.com/reference/android/app/blob/BlobHandle#getExpiryTimeMillis()`) is elapsed.

This lease information is persisted and calling this more than once will result in
latest lease overriding any previous lease.

When an app acquires a lease on a blob, the System will try to keep this
blob around but note that it can still be deleted if it was requested by the user.

In case the resource name for the `descriptionResId` is modified as part of
an app update, apps should re-acquire the lease with the new resource id.

<br />

| Parameters ||
|---|---|
| `blobHandle` | `BlobHandle`: the `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob that the caller wants to acquire a lease for. This value cannot be `null`. <br /> |
| `descriptionResId` | `int`: the resource id for a short description string that can be surfaced to the user explaining what the blob is used for. <br /> |
| `leaseExpiryTimeMillis` | `long`: the time in milliseconds after which the lease can be automatically released, in `https://developer.android.com/reference/java/lang/System#currentTimeMillis()` timebase. If its value is `0`, then the behavior of this API is identical to `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int)` where clients have to explicitly call `https://developer.android.com/reference/android/app/blob/BlobStoreManager#releaseLease(android.app.blob.BlobHandle)` when they don't need the blob anymore. Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/LimitExceededException` | when a lease could not be acquired, such as when the caller is trying to acquire too many leases or acquire leases on too much data. Apps can avoid this by checking the remaining quota using `https://developer.android.com/reference/android/app/blob/BlobStoreManager#getRemainingLeaseQuotaBytes()` before trying to acquire a lease. |
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while acquiring a lease to the blob. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | when `blobHandle` is invalid or if the `leaseExpiryTimeMillis` is greater than the `https://developer.android.com/reference/android/app/blob/BlobHandle#getExpiryTimeMillis()`. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the blob represented by the `blobHandle` does not exist or the caller does not have access to it. |

**See also:**

- `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int)`
- `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20java.lang.CharSequence)`

### acquireLease

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void acquireLease (BlobHandle blobHandle, 
                CharSequence description, 
                long leaseExpiryTimeMillis)
```

Acquire a lease to the blob represented by `blobHandle`. This lease indicates to the
system that the caller wants the blob to be kept around.

This is a variant of `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int,%20long)` taking a
`https://developer.android.com/reference/java/lang/CharSequence` for `description`. It is highly recommended that callers only
use this when a valid resource ID for `description` could not be provided. Otherwise,
apps should prefer using `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int)` which will allow
`description` to be localized.

Any active leases will be automatically released when the blob's expiry time
(`https://developer.android.com/reference/android/app/blob/BlobHandle#getExpiryTimeMillis()`) is elapsed.

This lease information is persisted and calling this more than once will result in
latest lease overriding any previous lease.

When an app acquires a lease on a blob, the System will try to keep this
blob around but note that it can still be deleted if it was requested by the user.

<br />

| Parameters ||
|---|---|
| `blobHandle` | `BlobHandle`: the `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob that the caller wants to acquire a lease for. This value cannot be `null`. <br /> |
| `description` | `CharSequence`: a short description string that can be surfaced to the user explaining what the blob is used for. It is recommended to keep this description brief. This may be truncated and ellipsized if it is too long to be displayed to the user. This value cannot be `null`. <br /> |
| `leaseExpiryTimeMillis` | `long`: the time in milliseconds after which the lease can be automatically released, in `https://developer.android.com/reference/java/lang/System#currentTimeMillis()` timebase. If its value is `0`, then the behavior of this API is identical to `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int)` where clients have to explicitly call `https://developer.android.com/reference/android/app/blob/BlobStoreManager#releaseLease(android.app.blob.BlobHandle)` when they don't need the blob anymore. Value is a non-negative timestamp measured as the number of milliseconds since 1970-01-01T00:00:00Z. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/LimitExceededException` | when a lease could not be acquired, such as when the caller is trying to acquire too many leases or acquire leases on too much data. Apps can avoid this by checking the remaining quota using `https://developer.android.com/reference/android/app/blob/BlobStoreManager#getRemainingLeaseQuotaBytes()` before trying to acquire a lease. |
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while acquiring a lease to the blob. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | when `blobHandle` is invalid or if the `leaseExpiryTimeMillis` is greater than the `https://developer.android.com/reference/android/app/blob/BlobHandle#getExpiryTimeMillis()`. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the blob represented by the `blobHandle` does not exist or the caller does not have access to it. |

**See also:**

- `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int,%20long)`
- `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20java.lang.CharSequence)`

### acquireLease

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void acquireLease (BlobHandle blobHandle, 
                CharSequence description)
```

Acquire a lease to the blob represented by `blobHandle`. This lease indicates to the
system that the caller wants the blob to be kept around.

This is a variant of `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int)` taking a `https://developer.android.com/reference/java/lang/CharSequence`
for `description`. It is highly recommended that callers only use this when a valid
resource ID for `description` could not be provided. Otherwise, apps should prefer
using `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int)` which will allow `description` to be
localized.

This is similar to `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20java.lang.CharSequence,%20long)` except clients
don't have to specify the lease expiry time upfront using this API and need to explicitly
release the lease using `https://developer.android.com/reference/android/app/blob/BlobStoreManager#releaseLease(android.app.blob.BlobHandle)` when they no longer like to keep
a blob around.

Any active leases will be automatically released when the blob's expiry time
(`https://developer.android.com/reference/android/app/blob/BlobHandle#getExpiryTimeMillis()`) is elapsed.

This lease information is persisted and calling this more than once will result in
latest lease overriding any previous lease.

When an app acquires a lease on a blob, the System will try to keep this
blob around but note that it can still be deleted if it was requested by the user.

<br />

| Parameters ||
|---|---|
| `blobHandle` | `BlobHandle`: the `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob that the caller wants to acquire a lease for. This value cannot be `null`. <br /> |
| `description` | `CharSequence`: a short description string that can be surfaced to the user explaining what the blob is used for. It is recommended to keep this description brief. This may be truncated and ellipsized if it is too long to be displayed to the user. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/LimitExceededException` | when a lease could not be acquired, such as when the caller is trying to acquire too many leases or acquire leases on too much data. Apps can avoid this by checking the remaining quota using `https://developer.android.com/reference/android/app/blob/BlobStoreManager#getRemainingLeaseQuotaBytes()` before trying to acquire a lease. |
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while acquiring a lease to the blob. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | when `blobHandle` is invalid. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the blob represented by the `blobHandle` does not exist or the caller does not have access to it. |

**See also:**

- `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int)`
- `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20java.lang.CharSequence,%20long)`

### acquireLease

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void acquireLease (BlobHandle blobHandle, 
                int descriptionResId)
```

Acquire a lease to the blob represented by `blobHandle`. This lease indicates to the
system that the caller wants the blob to be kept around.

This is similar to `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int,%20long)` except clients don't
have to specify the lease expiry time upfront using this API and need to explicitly
release the lease using `https://developer.android.com/reference/android/app/blob/BlobStoreManager#releaseLease(android.app.blob.BlobHandle)` when they no longer like to keep
a blob around.

Any active leases will be automatically released when the blob's expiry time
(`https://developer.android.com/reference/android/app/blob/BlobHandle#getExpiryTimeMillis()`) is elapsed.

This lease information is persisted and calling this more than once will result in
latest lease overriding any previous lease.

When an app acquires a lease on a blob, the System will try to keep this
blob around but note that it can still be deleted if it was requested by the user.

In case the resource name for the `descriptionResId` is modified as part of
an app update, apps should re-acquire the lease with the new resource id.

<br />

| Parameters ||
|---|---|
| `blobHandle` | `BlobHandle`: the `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob that the caller wants to acquire a lease for. This value cannot be `null`. <br /> |
| `descriptionResId` | `int`: the resource id for a short description string that can be surfaced to the user explaining what the blob is used for. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/LimitExceededException` | when a lease could not be acquired, such as when the caller is trying to acquire too many leases or acquire leases on too much data. Apps can avoid this by checking the remaining quota using `https://developer.android.com/reference/android/app/blob/BlobStoreManager#getRemainingLeaseQuotaBytes()` before trying to acquire a lease. |
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while acquiring a lease to the blob. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | when `blobHandle` is invalid. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the blob represented by the `blobHandle` does not exist or the caller does not have access to it. |

**See also:**

- `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int,%20long)`
- `https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20java.lang.CharSequence,%20long)`

### createSession

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long createSession (BlobHandle blobHandle)
```

Create a new session using the given `https://developer.android.com/reference/android/app/blob/BlobHandle`, returning a unique id
that represents the session. Once created, the session can be opened
multiple times across multiple device boots.

The system may automatically destroy sessions that have not been
finalized (either committed or abandoned) within a reasonable period of
time, typically about a week.

If an app is planning to acquire a lease on this data (using
`https://developer.android.com/reference/android/app/blob/BlobStoreManager#acquireLease(android.app.blob.BlobHandle,%20int)` or one of its other variants) after committing
this data (using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#commit(java.util.concurrent.Executor,%20java.util.function.Consumer<java.lang.Integer>)`), it is recommended that
the app checks the remaining quota for acquiring a lease first using
`https://developer.android.com/reference/android/app/blob/BlobStoreManager#getRemainingLeaseQuotaBytes()` and can skip contributing this data if needed.

<br />

| Parameters ||
|---|---|
| `blobHandle` | `BlobHandle`: the `https://developer.android.com/reference/android/app/blob/BlobHandle` identifier for which a new session needs to be created. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `long` | positive, non-zero unique id that represents the created session. This id remains consistent across device reboots until the session is finalized. IDs are not reused during a given boot. Value is 1 or greater <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/LimitExceededException` | when a new session could not be created, such as when the caller is trying to create too many sessions. |
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while creating the session. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | when `blobHandle` is invalid. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller is not allowed to create a session, such as when called from an Instant app. |

### getLeasedBlobs

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<BlobHandle> getLeasedBlobs ()
```

Return the `https://developer.android.com/reference/android/app/blob/BlobHandle` corresponding to the data blobs that
the calling app currently has a lease on.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/blob/BlobHandle>` | a list of `https://developer.android.com/reference/android/app/blob/BlobHandle` that the caller has a lease on. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### getRemainingLeaseQuotaBytes

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long getRemainingLeaseQuotaBytes ()
```

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.

If an app wants to acquire a lease on a blob but the remaining quota size is not sufficient,
then it can try releasing leases on any older blobs which are not needed anymore.

<br />

| Returns ||
|---|---|
| `long` | the remaining quota size for acquiring a lease. Value is 0 or greater <br /> |

### openBlob

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public ParcelFileDescriptor openBlob (BlobHandle blobHandle)
```

Opens an existing blob for reading from the blob store managed by the system.

<br />

| Parameters ||
|---|---|
| `blobHandle` | `BlobHandle`: the `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob that the caller wants to access. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/ParcelFileDescriptor` | a `https://developer.android.com/reference/android/os/ParcelFileDescriptor` that can be used to read the blob content. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O while opening the blob for read. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | when `blobHandle` is invalid. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the blob represented by the `blobHandle` does not exist or the caller does not have access to it. |

### openSession

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BlobStoreManager.Session openSession (long sessionId)
```

Open an existing session to actively perform work.

<br />

| Parameters ||
|---|---|
| `sessionId` | `long`: a unique id obtained via `https://developer.android.com/reference/android/app/blob/BlobStoreManager#createSession(android.app.blob.BlobHandle)` that represents a particular session. Value is 1 or greater <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session` | the `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session` object corresponding to the `sessionId`. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while opening the session. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller does not own the session, or the session does not exist or is invalid. |

### releaseLease

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void releaseLease (BlobHandle blobHandle)
```

Release any active lease to the blob represented by `blobHandle` which is
currently held by the caller.

<br />

| Parameters ||
|---|---|
| `blobHandle` | `BlobHandle`: the `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob that the caller wants to release the lease for. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while releasing the release to the blob. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | when `blobHandle` is invalid. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the blob represented by the `blobHandle` does not exist or the caller does not have access to it. |