Udostępnij za pośrednictwem


BlobStoreManager Class

Definition

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

[Android.Runtime.Register("android/app/blob/BlobStoreManager", ApiSince=30, DoNotGenerateAcw=true)]
public class BlobStoreManager : Java.Lang.Object
[<Android.Runtime.Register("android/app/blob/BlobStoreManager", ApiSince=30, DoNotGenerateAcw=true)>]
type BlobStoreManager = class
    inherit Object
Inheritance
BlobStoreManager
Attributes

Remarks

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

Apps can publish and access a data blob using a BlobHandle object which can be created with BlobHandle#createWithSha256(byte[], CharSequence, long, String). This BlobHandle object encapsulates the following pieces of information used for identifying the blobs: <ul> <li> BlobHandle#getSha256Digest()<li> BlobHandle#getLabel()<li> BlobHandle#getExpiryTimeMillis()<li> BlobHandle#getTag()</ul> For two 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 BlobStoreManager#createSession(BlobHandle) and then open this session for writing using 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 BlobStoreManager#createSession(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 Session#commit(Executor, Consumer). Until the session is committed, data written to the session will not be shared with any app.

<p class="note"> Once a session is committed using Session#commit(Executor, Consumer), 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: <ul> <li> Session#allowPackageAccess(String, byte[]) which will allow specific packages to access the blobs. <li> Session#allowSameSignatureAccess() which will allow only apps which are signed with the same certificate as the app which contributed the blob to access it. <li> Session#allowPublicAccess() which will allow any app on the device to access the blob. </ul>

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.

<p class="note"> It is strongly recommended that apps use one of Session#allowPackageAccess(String, byte[]) or Session#allowSameSignatureAccess() when they know, ahead of time, the set of apps they would like to share the blobs with. Session#allowPublicAccess() is meant for publicly available data committed from libraries and SDKs.

Once a data blob is committed with Session#commit(Executor, Consumer), it can be accessed using BlobStoreManager#openBlob(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 BlobStoreManager#acquireLease(BlobHandle, int) and release the lease with BlobStoreManager#releaseLease(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);
                }

Java documentation for android.app.blob.BlobStoreManager.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

BlobStoreManager(IntPtr, JniHandleOwnership)

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
LeasedBlobs

Return the BlobHandle BlobHandles corresponding to the data blobs that the calling app currently has a lease on.

PeerReference (Inherited from Object)
RemainingLeaseQuotaBytes

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.

ThresholdClass
ThresholdType

Methods

AbandonSession(Int64)

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

AcquireLease(BlobHandle, ICharSequence, Int64)

Acquire a lease to the blob represented by blobHandle.

AcquireLease(BlobHandle, ICharSequence)

Acquire a lease to the blob represented by blobHandle.

AcquireLease(BlobHandle, Int32, Int64)

Acquire a lease to the blob represented by blobHandle.

AcquireLease(BlobHandle, Int32)

Acquire a lease to the blob represented by blobHandle.

AcquireLease(BlobHandle, String, Int64)

Acquire a lease to the blob represented by blobHandle.

AcquireLease(BlobHandle, String)

Acquire a lease to the blob represented by blobHandle.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CreateSession(BlobHandle)

Create a new session using the given BlobHandle, returning a unique id that represents the session.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

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

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

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

(Inherited from Object)
Notify()

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

(Inherited from Object)
NotifyAll()

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

(Inherited from Object)
OpenBlob(BlobHandle)

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

OpenSession(Int64)

Open an existing session to actively perform work.

ReleaseLease(BlobHandle)

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

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

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

(Inherited from Object)
Wait(Int64)

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

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to