java.lang.Object | |
↳ | android.content.pm.PackageInstaller.Session |
An installation that is being actively staged. For an install to succeed, all existing and new packages must have identical package names, version codes, and signing certificates.
A session may contain any number of split packages. If the application does not yet exist, this session must include a base package.
If an APK included in this session is already defined by the existing installation (for example, the same split name), the APK in this session will replace the existing APK.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Completely abandon this session, destroying all staged data and
rendering it invalid.
| |||||||||||
Release this session object.
| |||||||||||
Attempt to commit everything staged in this session.
| |||||||||||
Ensure that any outstanding data for given stream has been committed
to disk.
| |||||||||||
Return all APK names contained in this session.
| |||||||||||
Open a stream to read an APK file from the session.
| |||||||||||
Open a stream to write an APK file into the session.
| |||||||||||
Set current progress of staging this session.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.io.Closeable
| |||||||||||
From interface
java.lang.AutoCloseable
|
Completely abandon this session, destroying all staged data and
rendering it invalid. Abandoned sessions will be reported to
PackageInstaller.SessionCallback
listeners as failures. This is equivalent to
opening the session and calling abandon()
.
Release this session object. You can open the session again if it hasn't been finalized.
Attempt to commit everything staged in this session. This may require user intervention, and so it may not happen immediately. The final result of the commit will be reported through the given callback.
Once this method is called, no additional mutations may be performed on the session. If the device reboots before the session has been finalized, you may commit the session again.
SecurityException | if streams opened through
openWrite(String, long, long) are still open.
|
---|
Ensure that any outstanding data for given stream has been committed
to disk. This is only valid for streams returned from
openWrite(String, long, long)
.
IOException |
---|
Return all APK names contained in this session.
This returns all names which have been previously written through
openWrite(String, long, long)
as part of this session.
SecurityException | if called after the session has been committed or abandoned. |
---|---|
IOException |
Open a stream to read an APK file from the session.
This is only valid for names which have been previously written
through openWrite(String, long, long)
as part of this
session. For example, this stream may be used to calculate a
MessageDigest
of a written APK before committing.
SecurityException | if called after the session has been committed or abandoned. |
---|---|
IOException |
Open a stream to write an APK file into the session.
The returned stream 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's strongly recommended to provide a valid file length when known.
You can write data into the returned stream, optionally call
fsync(OutputStream)
as needed to ensure bytes have been
persisted to disk, and then close when finished. All streams must be
closed before calling commit(IntentSender)
.
name | arbitrary, unique name of your choosing to identify the APK being written. You can open a file again for additional writes (such as after a reboot) by using the same name. This name is only meaningful within the context of a single install session. |
---|---|
offsetBytes | offset into the file to begin writing at, or 0 to start at the beginning of the file. |
lengthBytes | 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. |
IOException | if trouble opening the file for writing, such as lack of disk space or unavailable media. |
---|---|
SecurityException | if called after the session has been committed or abandoned. |
Set current progress of staging this session. Valid values are anywhere between 0 and 1.
Note that this progress may not directly correspond to the value
reported by onProgressChanged(int, float)
, as
the system may carve out a portion of the overall progress to
represent its own internal installation work.