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

Commit 94c93ab7 authored by Narayan Kamath's avatar Narayan Kamath
Browse files

StagingManager: Make commitSession async.

Post to the system servers shared B/G handler.

Test: m, atest apex_e2e_tests
Change-Id: I9e087f57a0f194951b6993403ad81c5b60018d8e
parent 2b9930d0
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -19,9 +19,11 @@ package com.android.server.pm;
import android.annotation.NonNull;
import android.content.pm.PackageInstaller;
import android.content.pm.ParceledListSlice;
import android.os.Handler;
import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.BackgroundThread;

import java.util.ArrayList;
import java.util.List;
@@ -35,6 +37,7 @@ public class StagingManager {
    private static final String TAG = "StagingManager";

    private final PackageManagerService mPm;
    private final Handler mBgHandler;

    // STOPSHIP: This is a temporary mock implementation of staged sessions. This variable
    //           shouldn't be needed at all.
@@ -44,18 +47,19 @@ public class StagingManager {

    StagingManager(PackageManagerService pm) {
        mPm = pm;
        mBgHandler = BackgroundThread.getHandler();
    }

    private void updateStoredSession(@NonNull PackageInstallerSession sessionInfo) {
        synchronized (mStagedSessions) {
            PackageInstallerSession storedSession = mStagedSessions.get(sessionInfo.sessionId);
            if (storedSession == null) {
                throw new IllegalStateException("Attempting to change state of a session not "
                        + "known to StagingManager");
            }
            // storedSession might be null if a call to abortSession was made before the session
            // is updated.
            if (storedSession != null) {
                mStagedSessions.put(sessionInfo.sessionId, sessionInfo);
            }
        }
    }

    ParceledListSlice<PackageInstaller.SessionInfo> getSessions() {
        final List<PackageInstaller.SessionInfo> result = new ArrayList<>();
@@ -69,10 +73,13 @@ public class StagingManager {

    void commitSession(@NonNull PackageInstallerSession sessionInfo) {
        updateStoredSession(sessionInfo);

        mBgHandler.post(() -> {
            // TODO(b/118865310): Dispatch the session to apexd/PackageManager for verification. For
            //                    now we directly mark it as ready.
            sessionInfo.setStagedSessionReady();
            mPm.sendSessionUpdatedBroadcast(sessionInfo.generateInfo(), sessionInfo.userId);
        });
    }

    void createSession(@NonNull PackageInstallerSession sessionInfo) {