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

Commit 3845d2eb authored by Jiakai Zhang's avatar Jiakai Zhang
Browse files

Integrate ART Service with DynamicCodeLogger.

This change adds an additional step in the DynamicCodeLogger's periodic
job to sync data from ART Service to DynamicCodeLogger.

Bug: 263165518
Test: -
  1. Enable ART Service.
  2. Load some secondary dex file.
  3. adb shell cmd jobscheduler run android 2030028
  4. adb logcat -b events
  5. See the hash of the filename of the loaded secondary dex file in
     the event log.
Change-Id: I5a233daa3eafb4d8cfec5271d9383a6c374f6728
parent a7cb4d15
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -27,13 +27,17 @@ import android.os.Process;
import android.util.EventLog;
import android.util.Log;

import com.android.server.LocalManagerRegistry;
import com.android.server.LocalServices;
import com.android.server.art.DexUseManagerLocal;
import com.android.server.art.model.DexContainerFileUseInfo;
import com.android.server.pm.dex.DynamicCodeLogger;

import libcore.util.HexEncoding;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -137,6 +141,28 @@ public class DynamicCodeLoggingService extends JobService {
        return LocalServices.getService(PackageManagerInternal.class).getDynamicCodeLogger();
    }

    private static void syncDataFromArtService(DynamicCodeLogger dynamicCodeLogger) {
        DexUseManagerLocal dexUseManagerLocal = DexOptHelper.getDexUseManagerLocal();
        if (dexUseManagerLocal == null) {
            // ART Service is not enabled.
            return;
        }
        PackageManagerLocal packageManagerLocal =
                Objects.requireNonNull(LocalManagerRegistry.getManager(PackageManagerLocal.class));
        try (PackageManagerLocal.UnfilteredSnapshot snapshot =
                        packageManagerLocal.withUnfilteredSnapshot()) {
            for (String owningPackageName : snapshot.getPackageStates().keySet()) {
                for (DexContainerFileUseInfo info :
                        dexUseManagerLocal.getSecondaryDexContainerFileUseInfo(owningPackageName)) {
                    for (String loadingPackageName : info.getLoadingPackages()) {
                        dynamicCodeLogger.recordDex(info.getUserHandle().getIdentifier(),
                                info.getDexContainerFile(), owningPackageName, loadingPackageName);
                    }
                }
            }
        }
    }

    private class IdleLoggingThread extends Thread {
        private final JobParameters mParams;

@@ -152,6 +178,7 @@ public class DynamicCodeLoggingService extends JobService {
            }

            DynamicCodeLogger dynamicCodeLogger = getDynamicCodeLogger();
            syncDataFromArtService(dynamicCodeLogger);
            for (String packageName : dynamicCodeLogger.getAllPackagesWithDynamicCodeLoading()) {
                if (mIdleLoggingStopRequested) {
                    Log.w(TAG, "Stopping IdleLoggingJob run at scheduler request");
+8 −4
Original line number Diff line number Diff line
@@ -223,8 +223,12 @@ public class DynamicCodeLogger {
        EventLog.writeEvent(SNET_TAG, subtag, uid, message);
    }

    void recordDex(int loaderUserId, String dexPath, String owningPackageName,
            String loadingPackageName) {
    /**
     * Records that an app running in the specified uid has executed dex code from the file at
     * {@code path}.
     */
    public void recordDex(
            int loaderUserId, String dexPath, String owningPackageName, String loadingPackageName) {
        if (mPackageDynamicCodeLoading.record(owningPackageName, dexPath,
                FILE_TYPE_DEX, loaderUserId, loadingPackageName)) {
            mPackageDynamicCodeLoading.maybeWriteAsync();
@@ -232,8 +236,8 @@ public class DynamicCodeLogger {
    }

    /**
     * Record that an app running in the specified uid has executed native code from the file at
     * {@param path}.
     * Records that an app running in the specified uid has executed native code from the file at
     * {@code path}.
     */
    public void recordNative(int loadingUid, String path) {
        String[] packages;