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

Commit b1a79007 authored by Martin Stjernholm's avatar Martin Stjernholm
Browse files

Use ART Service to clear app profiles when it is enabled.

Changed system server initialization order: ArtManagerLocal needs to be
initialized before mPackageManagerService.systemReady() is called,
because that calls CarrierAppUtils.disableCarrierAppsUntilPrivileged,
which may call ApplicationPackageManager.setSystemAppState to set
SYSTEM_APP_STATE_UNINSTALLED, which ends up calling ArtManagerLocal to
clean up any app profiles.

Test: Boot with dalvik.vm.useartservice=true and verify that calls to
      clearAppProfilesLIF and destroyAppProfilesLeafLIF during boot
      are handled by ART Service.
Bug: 251903639
Change-Id: I8a3a16ce85f315a28fa8459325470cfe5f32ca8c
parent 08d74434
Loading
Loading
Loading
Loading
+31 −12
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;


import static com.android.server.pm.DexOptHelper.useArtService;
import static com.android.server.pm.DexOptHelper.useArtService;
import static com.android.server.pm.PackageManagerService.TAG;
import static com.android.server.pm.PackageManagerService.TAG;
import static com.android.server.pm.PackageManagerServiceUtils.getPackageManagerLocal;
import static com.android.server.pm.PackageManagerServiceUtils.logCriticalInfo;
import static com.android.server.pm.PackageManagerServiceUtils.logCriticalInfo;


import android.annotation.NonNull;
import android.annotation.NonNull;
@@ -586,13 +587,16 @@ public class AppDataHelper {
            Slog.wtf(TAG, "Package was null!", new Throwable());
            Slog.wtf(TAG, "Package was null!", new Throwable());
            return;
            return;
        }
        }
        // TODO(b/251903639): Call into ART Service.
        if (useArtService()) {
            destroyAppProfilesWithArtService(pkg);
        } else {
            try {
            try {
                mArtManagerService.clearAppProfiles(pkg);
                mArtManagerService.clearAppProfiles(pkg);
            } catch (LegacyDexoptDisabledException e) {
            } catch (LegacyDexoptDisabledException e) {
                throw new RuntimeException(e);
                throw new RuntimeException(e);
            }
            }
        }
        }
    }


    public void destroyAppDataLIF(AndroidPackage pkg, int userId, int flags) {
    public void destroyAppDataLIF(AndroidPackage pkg, int userId, int flags) {
        if (pkg == null) {
        if (pkg == null) {
@@ -629,7 +633,9 @@ public class AppDataHelper {
    }
    }


    private void destroyAppProfilesLeafLIF(AndroidPackage pkg) {
    private void destroyAppProfilesLeafLIF(AndroidPackage pkg) {
        // TODO(b/251903639): Call into ART Service.
        if (useArtService()) {
            destroyAppProfilesWithArtService(pkg);
        } else {
            try {
            try {
                mInstaller.destroyAppProfiles(pkg.getPackageName());
                mInstaller.destroyAppProfiles(pkg.getPackageName());
            } catch (LegacyDexoptDisabledException e) {
            } catch (LegacyDexoptDisabledException e) {
@@ -638,6 +644,19 @@ public class AppDataHelper {
                Slog.w(TAG, String.valueOf(e));
                Slog.w(TAG, String.valueOf(e));
            }
            }
        }
        }
    }

    private void destroyAppProfilesWithArtService(AndroidPackage pkg) {
        try (PackageManagerLocal.FilteredSnapshot snapshot =
                        getPackageManagerLocal().withFilteredSnapshot()) {
            try {
                DexOptHelper.getArtManagerLocal().clearAppProfiles(snapshot, pkg.getPackageName());
            } catch (IllegalArgumentException e) {
                // Package isn't found, but that should only happen due to race.
                Slog.w(TAG, e);
            }
        }
    }


    /**
    /**
     * Returns {@code true} if app's internal storage should be created for this {@code pkg}.
     * Returns {@code true} if app's internal storage should be created for this {@code pkg}.
+4 −4
Original line number Original line Diff line number Diff line
@@ -2736,6 +2736,10 @@ public final class SystemServer implements Dumpable {
        mSystemServiceManager.startService(PermissionPolicyService.class);
        mSystemServiceManager.startService(PermissionPolicyService.class);
        t.traceEnd();
        t.traceEnd();


        t.traceBegin("ArtManagerLocal");
        DexOptHelper.initializeArtManagerLocal(context, mPackageManagerService);
        t.traceEnd();

        t.traceBegin("MakePackageManagerServiceReady");
        t.traceBegin("MakePackageManagerServiceReady");
        mPackageManagerService.systemReady();
        mPackageManagerService.systemReady();
        t.traceEnd();
        t.traceEnd();
@@ -2770,10 +2774,6 @@ public final class SystemServer implements Dumpable {
        mSystemServiceManager.startService(GAME_MANAGER_SERVICE_CLASS);
        mSystemServiceManager.startService(GAME_MANAGER_SERVICE_CLASS);
        t.traceEnd();
        t.traceEnd();


        t.traceBegin("ArtManagerLocal");
        DexOptHelper.initializeArtManagerLocal(context, mPackageManagerService);
        t.traceEnd();

        if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_UWB)) {
        if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_UWB)) {
            t.traceBegin("UwbService");
            t.traceBegin("UwbService");
            mSystemServiceManager.startServiceFromJar(UWB_SERVICE_CLASS, UWB_APEX_SERVICE_JAR_PATH);
            mSystemServiceManager.startServiceFromJar(UWB_SERVICE_CLASS, UWB_APEX_SERVICE_JAR_PATH);