public static class PackageInstaller.Session extends Object implements Closeable
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.
Constructor and Description |
---|
Session(IPackageInstallerSession session) |
Modifier and Type | Method and Description |
---|---|
void |
abandon()
Completely abandon this session, destroying all staged data and
rendering it invalid.
|
void |
addProgress(float progress) |
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 |
setProgress(float progress)
Deprecated.
|
void |
setStagingProgress(float progress)
Set current progress of staging this session.
|
@Deprecated public void setProgress(float progress)
public void setStagingProgress(float progress)
Note that this progress may not directly correspond to the value
reported by PackageInstaller.SessionCallback.onProgressChanged(int, float)
, as
the system may carve out a portion of the overall progress to
represent its own internal installation work.
public void addProgress(float progress)
public OutputStream openWrite(String name, long offsetBytes, long lengthBytes) throws IOException
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.public void fsync(OutputStream out) throws IOException
openWrite(String, long, long)
.IOException
public String[] getNames() throws IOException
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
public InputStream openRead(String name) throws IOException
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
public void removeSplit(String splitName) throws IOException
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.
IOException
public void commit(IntentSender statusReceiver)
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.public void close()
close
in interface Closeable
close
in interface AutoCloseable
public void abandon()
PackageInstaller.SessionCallback
listeners as failures. This is equivalent to
opening the session and calling abandon()
.