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

# BlobStoreManager.Session

*** ** * ** ***

` public static class BlobStoreManager.Session `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/io/Closeable `

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

<br />

*** ** * ** ***

Represents an ongoing session of a blob's contribution to the blob store managed by the system.

Clients that want to contribute a blob need to first create a `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session` using `https://developer.android.com/reference/android/app/blob/BlobStoreManager#createSession(android.app.blob.BlobHandle)` and once the session is created, clients can open and close this session multiple times using `https://developer.android.com/reference/android/app/blob/BlobStoreManager#openSession(long)` and `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#close()` before committing it using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#commit(java.util.concurrent.Executor,%20java.util.function.Consumer<java.lang.Integer>)`, at which point system will take ownership of the blob and the client can no longer make any modifications to the blob's content.

## Summary

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#abandon()() ` Abandon this session and delete any data that was written to this session so far. |
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPackageAccess(java.lang.String,%20byte[])(https://developer.android.com/reference/java/lang/String packageName, byte[] certificate) ` Allow `packageName` with a particular signing certificate to access this blob data once it is committed using a `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob. |
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPublicAccess()() ` Allow any app on the device to access this blob data once it is committed using a `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob. |
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowSameSignatureAccess()() ` Allow packages which are signed with the same certificate as the caller to access this blob data once it is committed using a `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob. |
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#close()() ` Close this session. |
| ` void` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#commit(java.util.concurrent.Executor,%20java.util.function.Consumer<java.lang.Integer>)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/java/util/function/Consumer<https://developer.android.com/reference/java/lang/Integer> resultCallback) ` Commit the file that was written so far to this session to the blob store maintained by the system. |
| ` long` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#getSize()() ` Gets the size of the blob file that was written to the session so far. |
| ` boolean` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#isPackageAccessAllowed(java.lang.String,%20byte[])(https://developer.android.com/reference/java/lang/String packageName, byte[] certificate) ` Returns `true` if access has been allowed for a `packageName` using either `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPackageAccess(java.lang.String,%20byte[])`. |
| ` boolean` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#isPublicAccessAllowed()() ` Returns `true` if public access has been allowed by using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPublicAccess()`. |
| ` boolean` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#isSameSignatureAccessAllowed()() ` Returns `true` if access has been allowed for packages signed with the same certificate as the caller by using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowSameSignatureAccess()`. |
| ` https://developer.android.com/reference/android/os/ParcelFileDescriptor` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#openRead()() ` Opens a file descriptor to read the blob content already written into this session. |
| ` https://developer.android.com/reference/android/os/ParcelFileDescriptor` | ` https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#openWrite(long,%20long)(long offsetBytes, long lengthBytes) ` Opens a file descriptor to write a blob into the session. |

### 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*.
From interface ` https://developer.android.com/reference/java/io/Closeable ` ` abstract void` ` https://developer.android.com/reference/java/io/Closeable#close()() `

Closes this stream and releases any system resources associated with it.
From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` ` abstract void` ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() `

Closes this resource, relinquishing any underlying resources.

## Public methods

### abandon

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

```
public void abandon ()
```

Abandon this session and delete any data that was written to this session so far.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while abandoning the session. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | when the caller tries to abandon a session which was already finalized. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller is not the owner of the session. |

### allowPackageAccess

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

```
public void allowPackageAccess (String packageName, 
                byte[] certificate)
```

Allow `packageName` with a particular signing certificate to access this blob data once it is committed using a `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob.

This needs to be called before committing the blob using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#commit(java.util.concurrent.Executor,%20java.util.function.Consumer<java.lang.Integer>)`.

<br />

| Parameters ||
|---|---|
| `packageName` | `String`: the name of the package which should be allowed to access the blob. This value cannot be `null`. <br /> |
| `certificate` | `byte`: the input bytes representing a certificate of type `https://developer.android.com/reference/android/content/pm/PackageManager#CERT_INPUT_SHA256`. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/os/LimitExceededException` | when the caller tries to explicitly allow too many packages using this API. |
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while changing the access. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | when the caller tries to change access for a blob which is already committed. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller is not the owner of the session. |

### allowPublicAccess

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

```
public void allowPublicAccess ()
```

Allow any app on the device to access this blob data once it is committed using a `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob.

**Note:** This is only meant to be used from libraries and SDKs where the apps which we want to allow access is not known ahead of time. If a blob is being committed to be shared with a particular set of apps, it is highly recommended to use `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPackageAccess(java.lang.String,%20byte[])` instead.

This needs to be called before committing the blob using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#commit(java.util.concurrent.Executor,%20java.util.function.Consumer<java.lang.Integer>)`.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while changing the access. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | when the caller tries to change access for a blob which is already committed. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller is not the owner of the session. |

### allowSameSignatureAccess

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

```
public void allowSameSignatureAccess ()
```

Allow packages which are signed with the same certificate as the caller to access this blob data once it is committed using a `https://developer.android.com/reference/android/app/blob/BlobHandle` representing the blob.

This needs to be called before committing the blob using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#commit(java.util.concurrent.Executor,%20java.util.function.Consumer<java.lang.Integer>)`.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while changing the access. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | when the caller tries to change access for a blob which is already committed. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller is not the owner of the session. |

### close

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

```
public void close ()
```

Close this session. It can be re-opened for writing/reading if it has not been abandoned (using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#abandon()`) or committed (using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#commit(java.util.concurrent.Executor,%20java.util.function.Consumer<java.lang.Integer>)`).

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while closing the session. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller is not the owner of the session. |

### commit

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

```
public void commit (Executor executor, 
                Consumer<Integer> resultCallback)
```

Commit the file that was written so far to this session to the blob store maintained by the system.

Once this method is called, the session is finalized and no additional mutations can be performed on the session. If the device reboots before the session has been finalized, you may commit the session again.

Note that this commit operation will fail if the hash of the data written so far to this session does not match with the one used for `https://developer.android.com/reference/android/app/blob/BlobHandle#createWithSha256(byte[],%20java.lang.CharSequence,%20long,%20java.lang.String)` BlobHandle} associated with this session.

Committing the same data more than once will result in replacing the corresponding access mode (via calling one of `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPackageAccess(java.lang.String,%20byte[])`, `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowSameSignatureAccess()`, etc) with the latest one.

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: the executor on which result callback will be invoked. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `resultCallback` | `Consumer`: a callback to receive the commit result. when the result is `0`, it indicates success. Otherwise, failure. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while committing the session. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | when the passed parameters are not valid. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | when the caller tries to commit a session which was already finalized. |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller is not the owner of the session. |

### getSize

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

```
public long getSize ()
```

Gets the size of the blob file that was written to the session so far.   

Value is a non-negative number of bytes.

<br />

| Returns ||
|---|---|
| `long` | the size of the blob file so far. Value is a non-negative number of bytes. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while opening the file to read. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | when the caller tries to get the file size after it is abandoned (using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#abandon()`) or closed (using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#close()`). |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller is not the owner of the session. |

### isPackageAccessAllowed

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

```
public boolean isPackageAccessAllowed (String packageName, 
                byte[] certificate)
```

Returns `true` if access has been allowed for a `packageName` using either `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPackageAccess(java.lang.String,%20byte[])`. Otherwise, `false`.

<br />

| Parameters ||
|---|---|
| `packageName` | `String`: the name of the package to check the access for. This value cannot be `null`. <br /> |
| `certificate` | `byte`: the input bytes representing a certificate of type `https://developer.android.com/reference/android/content/pm/PackageManager#CERT_INPUT_SHA256`. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while getting the access type. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | when the caller tries to get access type from a session which is closed or abandoned. |

### isPublicAccessAllowed

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

```
public boolean isPublicAccessAllowed ()
```

Returns `true` if public access has been allowed by using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowPublicAccess()`. Otherwise, `false`.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while getting the access type. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | when the caller tries to get access type from a session which is closed or abandoned. |

### isSameSignatureAccessAllowed

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

```
public boolean isSameSignatureAccessAllowed ()
```

Returns `true` if access has been allowed for packages signed with the same certificate as the caller by using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#allowSameSignatureAccess()`. Otherwise, `false`.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | when there is an I/O error while getting the access type. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | when the caller tries to get access type from a session which is closed or abandoned. |

### openRead

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

```
public ParcelFileDescriptor openRead ()
```

Opens a file descriptor to read the blob content already written into this session.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/ParcelFileDescriptor` | a `https://developer.android.com/reference/android/os/ParcelFileDescriptor` for reading from the blob file. 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 file to read. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | when the caller tries to read the file after it is abandoned (using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#abandon()`) or closed (using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#close()`). |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller is not the owner of the session. |

### openWrite

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

```
public ParcelFileDescriptor openWrite (long offsetBytes, 
                long lengthBytes)
```

Opens a file descriptor to write a blob into the session.

The returned file descriptor will start writing data at the requested offset in the underlying file, which can be used to resume a partially written file. If a valid file length is specified, the system will preallocate the underlying disk space to optimize placement on disk. It is strongly recommended to provide a valid file length when known.

<br />

| Parameters ||
|---|---|
| `offsetBytes` | `long`: offset into the file to begin writing at, or 0 to start at the beginning of the file. Value is a non-negative number of bytes. <br /> |
| `lengthBytes` | `long`: total size of the file being written, used to preallocate the underlying disk space, or -1 if unknown. The system may clear various caches as needed to allocate this space. Value is a non-negative number of bytes. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/ParcelFileDescriptor` | a `https://developer.android.com/reference/android/os/ParcelFileDescriptor` for writing to the blob file. 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 file to write. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | when the caller tries to write to the file after it is abandoned (using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#abandon()`) or committed (using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#commit(java.util.concurrent.Executor,%20java.util.function.Consumer<java.lang.Integer>)`) or closed (using `https://developer.android.com/reference/android/app/blob/BlobStoreManager.Session#close()`). |
| `https://developer.android.com/reference/java/lang/SecurityException` | when the caller is not the owner of the session. |