Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c053b82 authored by JW Wang's avatar JW Wang
Browse files

Protect accesses to members of childSession (5/n)

Add a method to ensure access to mCommitted and mDestroyed are
properly protected.

Bug: 159663586
Test: atest StagedInstallTest AtomicInstallTest
Change-Id: I704d972f7ec68eaa310da0a80f6f8acd4e1cc928
parent 39fae7be
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -2951,13 +2951,17 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        return EMPTY_CHILD_SESSION_ARRAY;
    }

    private boolean canBeAddedAsChild(int parentCandidate) {
        synchronized (mLock) {
            return (!hasParentSessionId() || mParentSessionId == parentCandidate)
                    && !mCommitted && !mDestroyed;
        }
    }

    @Override
    public void addChildSessionId(int childSessionId) {
        final PackageInstallerSession childSession = mSessionProvider.getSession(childSessionId);
        if (childSession == null
                || (childSession.hasParentSessionId() && childSession.mParentSessionId != sessionId)
                || childSession.mCommitted
                || childSession.mDestroyed) {
        if (childSession == null || !childSession.canBeAddedAsChild(sessionId)) {
            throw new IllegalStateException("Unable to add child session " + childSessionId
                            + " as it does not exist or is in an invalid state.");
        }