Add an api to get active staged session

This was requested during review of ag/6638240

Test: CtsStagedInstallHostTestCases
Bug: 127296534
Change-Id: Ifcc6270dc1655b1b07a0879c140f30967df8910d
This commit is contained in:
Nikita Ioffe
2019-03-07 20:55:08 +00:00
parent c4ef64285d
commit 00a08f12fe
3 changed files with 45 additions and 0 deletions

View File

@@ -11384,6 +11384,7 @@ package android.content.pm {
public class PackageInstaller {
method public void abandonSession(int);
method public int createSession(@NonNull android.content.pm.PackageInstaller.SessionParams) throws java.io.IOException;
method @Nullable public android.content.pm.PackageInstaller.SessionInfo getActiveStagedSession();
method @NonNull public java.util.List<android.content.pm.PackageInstaller.SessionInfo> getAllSessions();
method @NonNull public java.util.List<android.content.pm.PackageInstaller.SessionInfo> getMySessions();
method @Nullable public android.content.pm.PackageInstaller.SessionInfo getSessionInfo(int);
@@ -11468,6 +11469,7 @@ package android.content.pm {
method @NonNull public String getStagedSessionErrorMessage();
method @NonNull public android.os.UserHandle getUser();
method public boolean isActive();
method public boolean isCommitted();
method public boolean isMultiPackage();
method public boolean isSealed();
method public boolean isStaged();

View File

@@ -496,6 +496,36 @@ public class PackageInstaller {
}
}
/**
* Returns an active staged session, or {@code null} if there is none.
*
* <p>Staged session is active iff:
* <ul>
* <li>It is committed.
* <li>It is not applied.
* <li>It is not failed.
* </ul>
*
* <p>In case of a multi-apk session, parent session will be returned.
*/
public @Nullable SessionInfo getActiveStagedSession() {
final List<SessionInfo> stagedSessions = getStagedSessions();
for (SessionInfo s : stagedSessions) {
if (s.isStagedSessionApplied() || s.isStagedSessionFailed()) {
// Finalized session.
continue;
}
if (s.getParentSessionId() != SessionInfo.INVALID_ID) {
// Child session.
continue;
}
if (s.isCommitted()) {
return s;
}
}
return null;
}
/**
* Uninstall the given package, removing it completely from the device. This
* method is available to:
@@ -1769,6 +1799,9 @@ public class PackageInstaller {
private int mStagedSessionErrorCode;
private String mStagedSessionErrorMessage;
/** {@hide} */
public boolean isCommitted;
/** {@hide} */
@UnsupportedAppUsage
public SessionInfo() {
@@ -1809,6 +1842,7 @@ public class PackageInstaller {
isStagedSessionFailed = source.readBoolean();
mStagedSessionErrorCode = source.readInt();
mStagedSessionErrorMessage = source.readString();
isCommitted = source.readBoolean();
}
/**
@@ -2181,6 +2215,13 @@ public class PackageInstaller {
mStagedSessionErrorMessage = errorMessage;
}
/**
* Whenever this session was committed.
*/
public boolean isCommitted() {
return isCommitted;
}
@Override
public int describeContents() {
return 0;
@@ -2218,6 +2259,7 @@ public class PackageInstaller {
dest.writeBoolean(isStagedSessionFailed);
dest.writeInt(mStagedSessionErrorCode);
dest.writeString(mStagedSessionErrorMessage);
dest.writeBoolean(isCommitted);
}
public static final Parcelable.Creator<SessionInfo>

View File

@@ -476,6 +476,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
mResolvedBaseFile.getAbsolutePath() : null;
info.progress = mProgress;
info.sealed = mSealed;
info.isCommitted = mCommitted;
info.active = mActiveCount.get() > 0;
info.mode = params.mode;