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

Commit 68d75b28 authored by JW Wang's avatar JW Wang Committed by Android (Google) Code Review
Browse files

Merge changes Ibbf7f77c,I7e80c13f,I4eeeea28

* changes:
  Some cleanup (3/n)
  Move some fields/methods into StagedSession (2/n)
  Extract staged session code to a separate class (1/n)
parents bc33c8db 16c3ec77
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -291,23 +291,23 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
    }

    void restoreAndApplyStagedSessionIfNeeded() {
        List<PackageInstallerSession> stagedSessionsToRestore = new ArrayList<>();
        List<StagingManager.StagedSession> stagedSessionsToRestore = new ArrayList<>();
        synchronized (mSessions) {
            for (int i = 0; i < mSessions.size(); i++) {
                final PackageInstallerSession session = mSessions.valueAt(i);
                if (session.isStaged()) {
                    stagedSessionsToRestore.add(session);
                    stagedSessionsToRestore.add(session.mStagedSession);
                }
            }
        }
        // Don't hold mSessions lock when calling restoreSession, since it might trigger an APK
        // atomic install which needs to query sessions, which requires lock on mSessions.
        boolean isDeviceUpgrading = mPm.isDeviceUpgrading();
        for (PackageInstallerSession session : stagedSessionsToRestore) {
            if (!session.isStagedAndInTerminalState() && session.hasParentSessionId()
        for (StagingManager.StagedSession session : stagedSessionsToRestore) {
            if (!session.isInTerminalState() && session.hasParentSessionId()
                    && getSession(session.getParentSessionId()) == null) {
                session.setStagedSessionFailed(SessionInfo.STAGED_SESSION_ACTIVATION_FAILED,
                        "An orphan staged session " + session.sessionId + " is found, "
                session.setSessionFailed(SessionInfo.STAGED_SESSION_ACTIVATION_FAILED,
                        "An orphan staged session " + session.sessionId() + " is found, "
                                + "parent " + session.getParentSessionId() + " is missing");
            }
            mStagingManager.restoreSession(session, isDeviceUpgrading);
@@ -1399,7 +1399,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
                @Override
                public void run() {
                    if (session.isStaged() && !success) {
                        mStagingManager.abortSession(session);
                        mStagingManager.abortSession(session.mStagedSession);
                    }
                    synchronized (mSessions) {
                        if (!session.isStaged() || !success) {
+369 −245

File changed.

Preview size limit exceeded, changes collapsed.

+166 −131

File changed.

Preview size limit exceeded, changes collapsed.

+13 −6
Original line number Diff line number Diff line
@@ -33,8 +33,11 @@ import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import java.io.File;
import java.util.function.Predicate;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -70,8 +73,8 @@ public class StagingManagerTest {
    public void checkNonOverlappingWithStagedSessions_laterSessionShouldNotFailEarlierOnes()
            throws Exception {
        // Create 2 sessions with overlapping packages
        PackageInstallerSession session1 = createSession(111, "com.foo", 1);
        PackageInstallerSession session2 = createSession(222, "com.foo", 2);
        StagingManager.StagedSession session1 = createSession(111, "com.foo", 1);
        StagingManager.StagedSession session2 = createSession(222, "com.foo", 2);

        mStagingManager.createSession(session1);
        mStagingManager.createSession(session2);
@@ -82,7 +85,7 @@ public class StagingManagerTest {
                () -> mStagingManager.checkNonOverlappingWithStagedSessions(session2));
    }

    private PackageInstallerSession createSession(int sessionId, String packageName,
    private StagingManager.StagedSession createSession(int sessionId, String packageName,
            long committedMillis) {
        PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(
                PackageInstaller.SessionParams.MODE_FULL_INSTALL);
@@ -121,8 +124,12 @@ public class StagingManagerTest {
                /* stagedSessionErrorCode */ PackageInstaller.SessionInfo.STAGED_SESSION_NO_ERROR,
                /* stagedSessionErrorMessage */ "no error");

        session = spy(session);
        doReturn(packageName).when(session).getPackageName();
        return session;
        StagingManager.StagedSession stagedSession = spy(session.mStagedSession);
        doReturn(packageName).when(stagedSession).getPackageName();
        doAnswer(invocation -> {
            Predicate<StagingManager.StagedSession> filter = invocation.getArgument(0);
            return filter.test(stagedSession);
        }).when(stagedSession).sessionContains(any());
        return stagedSession;
    }
}