From 00a08f12fe0ec452dea986da423cb35c9f593b91 Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Thu, 7 Mar 2019 20:55:08 +0000 Subject: Add an api to get active staged session This was requested during review of ag/6638240 Test: CtsStagedInstallHostTestCases Bug: 127296534 Change-Id: Ifcc6270dc1655b1b07a0879c140f30967df8910d --- api/current.txt | 2 ++ core/java/android/content/pm/PackageInstaller.java | 42 ++++++++++++++++++++++ .../android/server/pm/PackageInstallerSession.java | 1 + 3 files changed, 45 insertions(+) diff --git a/api/current.txt b/api/current.txt index 8192762c4d63..5664d4f65cc4 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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 getAllSessions(); method @NonNull public java.util.List 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(); diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java index 3edd17a4bb1f..1e6cea39b44d 100644 --- a/core/java/android/content/pm/PackageInstaller.java +++ b/core/java/android/content/pm/PackageInstaller.java @@ -496,6 +496,36 @@ public class PackageInstaller { } } + /** + * Returns an active staged session, or {@code null} if there is none. + * + *

Staged session is active iff: + *

    + *
  • It is committed. + *
  • It is not applied. + *
  • It is not failed. + *
+ * + *

In case of a multi-apk session, parent session will be returned. + */ + public @Nullable SessionInfo getActiveStagedSession() { + final List 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 diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java index 66b530f19ed8..f1d4524cccac 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerSession.java +++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java @@ -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; -- cgit v1.2.3-59-g8ed1b