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

Commit bac99b5f authored by Song Chun Fan's avatar Song Chun Fan
Browse files

[pm] move PackageInstallerSession.extractNativeLibraries to IO thread

PackageInstallerSession.write() holds mLock and is on the IO thread.
Prior to this CL, PackageInstallerSession.extractNativeLibraries() also
holds mLock but was on the mInstallThread. This causes a lock contention
where the write() can ANR waiting for mLock held by
extractNativeLibraries(). Move the latter to the IO thread to avoid such
lock contentions.

FLAG: EXEMPT refactor
BUG: 393698598
Test: manual

Change-Id: I99418b8983a63751e6d485efae947a49a6a88db5
parent 562c3a18
Loading
Loading
Loading
Loading
+33 −8
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;
import com.android.server.IoThread;
import com.android.server.LocalServices;
import com.android.server.art.ArtManagedInstallFileHelper;
import com.android.server.pm.Installer.InstallerException;
@@ -236,6 +237,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    private static final int MSG_SESSION_VALIDATION_FAILURE = 5;
    private static final int MSG_PRE_APPROVAL_REQUEST = 6;

    private static final int MSG_ON_NATIVE_LIBS_EXTRACTED = 7;

    /** XML constants used for persisting a session */
    static final String TAG_SESSION = "session";
    static final String TAG_CHILD_SESSION = "childSession";
@@ -943,6 +946,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                case MSG_PRE_APPROVAL_REQUEST:
                    handlePreapprovalRequest();
                    break;
                case MSG_ON_NATIVE_LIBS_EXTRACTED:
                    handleOnNativeLibsExtracted();
            }

            return true;
@@ -2908,6 +2913,24 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    }

    private void verify() {
        // Extract native libraries on the IO thread before proceeding to the verification
        runExtractNativeLibraries();
    }

    @WorkerThread
    private void handleOnNativeLibsExtracted() {
        try {
            verifyNonStaged();
        } catch (PackageManagerException e) {
            final String completeMsg = ExceptionUtils.getCompleteMessage(e);
            final String errorMsg = PackageManager.installStatusToString(e.error, completeMsg);
            setSessionFailed(e.error, errorMsg);
            onSessionVerificationFailure(e.error, errorMsg);
        }
    }

    private void runExtractNativeLibraries() {
        IoThread.getHandler().post(() -> {
            try {
                List<PackageInstallerSession> children = getChildSessions();
                if (isMultiPackage()) {
@@ -2917,13 +2940,14 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                } else {
                    extractNativeLibraries();
                }
            verifyNonStaged();
                mHandler.obtainMessage(MSG_ON_NATIVE_LIBS_EXTRACTED).sendToTarget();
            } catch (PackageManagerException e) {
                final String completeMsg = ExceptionUtils.getCompleteMessage(e);
                final String errorMsg = PackageManager.installStatusToString(e.error, completeMsg);
                setSessionFailed(e.error, errorMsg);
                onSessionVerificationFailure(e.error, errorMsg);
            }
        });
    }

    private IntentSender getRemoteStatusReceiver() {
@@ -3072,6 +3096,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        }
    }

    @WorkerThread
    private void extractNativeLibraries() throws PackageManagerException {
        synchronized (mLock) {
            if (mPackageLite != null) {