diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/content/pm/PackageInstaller.java | 78 | ||||
| -rw-r--r-- | core/java/android/content/pm/PackageManager.java | 2 |
2 files changed, 53 insertions, 27 deletions
diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java index 2217807254e9..2914e4c2c2ff 100644 --- a/core/java/android/content/pm/PackageInstaller.java +++ b/core/java/android/content/pm/PackageInstaller.java @@ -68,6 +68,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.Executor; +import java.util.stream.Collectors; /** * Offers the ability to install, upgrade, and remove applications on the @@ -486,35 +487,30 @@ public class PackageInstaller { } /** - * Returns an active staged session, or {@code null} if there is none. + * Returns first active staged session, or {@code null} if there is none. * - * <p>Staged session is active iff: - * <ul> - * <li>It is committed, i.e. {@link SessionInfo#isCommitted()} is {@code true}, and - * <li>it is not applied, i.e. {@link SessionInfo#isStagedSessionApplied()} is {@code - * false}, and - * <li>it is not failed, i.e. {@link SessionInfo#isStagedSessionFailed()} is {@code false}. - * </ul> + * <p>For more information on what sessions are considered active see + * {@link SessionInfo#isStagedSessionActive()}. * - * <p>In case of a multi-apk session, reasoning above is applied to the parent session, since - * that is the one that should been {@link Session#commit committed}. + * @deprecated Use {@link #getActiveStagedSessions} as there can be more than one active staged + * session */ + @Deprecated 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; + List<SessionInfo> activeSessions = getActiveStagedSessions(); + return activeSessions.isEmpty() ? null : activeSessions.get(0); + } + + /** + * Returns list of active staged sessions. Returns empty list if there is none. + * + * <p>For more information on what sessions are considered active see + * * {@link SessionInfo#isStagedSessionActive()}. + */ + public @NonNull List<SessionInfo> getActiveStagedSessions() { + return getStagedSessions().stream() + .filter(s -> s.isStagedSessionActive()) + .collect(Collectors.toList()); } /** @@ -2234,13 +2230,36 @@ public class PackageInstaller { } /** - * Returns true if this session is a staged session which will be applied at next reboot. + * Returns true if this session is a staged session. */ public boolean isStaged() { return isStaged; } /** + * Returns {@code true} if this session is an active staged session. + * + * We consider a session active if it has been committed and it is either pending + * verification, or will be applied at next reboot. + * + * <p>Staged session is active iff: + * <ul> + * <li>It is committed, i.e. {@link SessionInfo#isCommitted()} is {@code true}, and + * <li>it is not applied, i.e. {@link SessionInfo#isStagedSessionApplied()} is {@code + * false}, and + * <li>it is not failed, i.e. {@link SessionInfo#isStagedSessionFailed()} is + * {@code false}. + * </ul> + * + * <p>In case of a multi-package session, reasoning above is applied to the parent session, + * since that is the one that should have been {@link Session#commit committed}. + */ + public boolean isStagedSessionActive() { + return isStaged && isCommitted && !isStagedSessionApplied && !isStagedSessionFailed + && !hasParentSessionId(); + } + + /** * Returns the parent multi-package session ID if this session belongs to one, * {@link #INVALID_ID} otherwise. */ @@ -2249,6 +2268,13 @@ public class PackageInstaller { } /** + * Returns true if session has a valid parent session, otherwise false. + */ + public boolean hasParentSessionId() { + return parentSessionId != INVALID_ID; + } + + /** * Returns the set of session IDs that will be committed when this session is commited if * this session is a multi-package session. */ diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index 2db661dc2c96..66f9ac0fb53f 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -1424,7 +1424,7 @@ public abstract class PackageManager { /** * Installation failed return code: a new staged session was attempted to be committed while - * there is already one in-progress. + * there is already one in-progress or new session has package that is already staged. * * @hide */ |
