public
static
class
PackageInstaller.Session
extends Object
implements
Closeable
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 | |
---|---|
void
|
abandon()
Completely abandon this session, destroying all staged data and rendering it invalid. |
void
|
close()
Release this session object. |
void
|
commit(IntentSender statusReceiver)
Attempt to commit everything staged in this session. |
void
|
fsync(OutputStream out)
Ensure that any outstanding data for given stream has been committed to disk. |
String[]
|
getNames()
Return all APK names contained in this session. |
InputStream
|
openRead(String name)
Open a stream to read an APK file from the session. |
OutputStream
|
openWrite(String name, long offsetBytes, long lengthBytes)
Open a stream to write an APK file into the session. |
void
|
removeSplit(String splitName)
Removes a split. |
void
|
setStagingProgress(float progress)
Set current progress of staging this session. |
Inherited methods | |
---|---|
From
class
java.lang.Object
| |
From
interface
java.io.Closeable
| |
From
interface
java.lang.AutoCloseable
|
void abandon ()
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()
.
void close ()
Release this session object. You can open the session again if it hasn't been finalized.
void commit (IntentSender statusReceiver)
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.
Parameters | |
---|---|
statusReceiver |
IntentSender
|
Throws | |
---|---|
SecurityException |
if streams opened through
openWrite(String, long, long) are still open.
|
void fsync (OutputStream out)
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)
.
Parameters | |
---|---|
out |
OutputStream
|
Throws | |
---|---|
IOException |
String[] getNames ()
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.
Returns | |
---|---|
String[] |
Throws | |
---|---|
SecurityException |
if called after the session has been committed or abandoned. |
IOException |
InputStream openRead (String name)
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.
Parameters | |
---|---|
name |
String
|
Returns | |
---|---|
InputStream |
Throws | |
---|---|
SecurityException |
if called after the session has been committed or abandoned. |
IOException |
OutputStream openWrite (String name, long offsetBytes, long lengthBytes)
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)
.
Parameters | |
---|---|
name |
String :
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 |
long :
offset into the file to begin writing at, or 0 to
start at the beginning of the file. |
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. |
Returns | |
---|---|
OutputStream |
Throws | |
---|---|
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. |
void removeSplit (String splitName)
Removes a split.
Split removals occur prior to adding new APKs. If upgrading a feature split, it is not expected nor desirable to remove the split prior to upgrading.
When split removal is bundled with new APKs, the packageName must be identical.
Parameters | |
---|---|
splitName |
String
|
Throws | |
---|---|
IOException |
void setStagingProgress (float progress)
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.
Parameters | |
---|---|
progress |
float
|