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

Commit 9789a45e authored by Martin Stjernholm's avatar Martin Stjernholm
Browse files

Remove the internal DexLoadReporter for system server's own dex loads.

System server can only be compiled and signed by odrefresh in early
boot, so it is no use capturing dex load events for it.

Test: Build & boot
Bug: 254043366
Change-Id: If27569b784aeb882d3a20bd21a30137e6530e663
parent 48de4049
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -83,7 +83,6 @@ import android.content.pm.IOnChecksumsReadyListener;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageDeleteObserver2;
import android.content.pm.IPackageLoadingProgressCallback;
import android.content.pm.IPackageManager;
import android.content.pm.IPackageMoveObserver;
import android.content.pm.IncrementalStatesInfo;
import android.content.pm.InstallSourceInfo;
@@ -1459,7 +1458,8 @@ public class PackageManagerService implements PackageSender, TestUtilityService
        }
    };

    public static Pair<PackageManagerService, IPackageManager> main(Context context,
    /** Starts PackageManagerService. */
    public static PackageManagerService main(Context context,
            Installer installer, @NonNull DomainVerificationService domainVerificationService,
            boolean factoryTest) {
        // Self-check for initial settings.
@@ -1589,7 +1589,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
        ServiceManager.addService("package_native", pmn);
        LocalManagerRegistry.addManager(PackageManagerLocal.class,
                new PackageManagerLocalImpl(m));
        return Pair.create(m, iPackageManager);
        return m;
    }

    /** Install/uninstall system packages for all users based on their user-type, as applicable. */
@@ -5286,10 +5286,6 @@ public class PackageManagerService implements PackageSender, TestUtilityService
                Map<String, String> classLoaderContextMap,
                String loaderIsa) {
            int callingUid = Binder.getCallingUid();

            // TODO(b/254043366): System server should not report its own dex load because there's
            // nothing ART can do with it.

            Computer snapshot = snapshot();

            // System server should be able to report dex load on behalf of other apps. E.g., it
+0 −83
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.pm.dex;

import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME;

import android.content.pm.IPackageManager;
import android.os.RemoteException;
import android.util.Log;
import android.util.Slog;

import dalvik.system.BaseDexClassLoader;
import dalvik.system.VMRuntime;

import java.util.Map;

/**
 * Reports dex file use to the package manager on behalf of system server.
 */
public class SystemServerDexLoadReporter implements BaseDexClassLoader.Reporter {
    private static final String TAG = "SystemServerDexLoadReporter";

    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);

    private final IPackageManager mPackageManager;

    private SystemServerDexLoadReporter(IPackageManager pm) {
        mPackageManager = pm;
    }

    @Override
    public void report(Map<String, String> classLoaderContextMap) {
        if (DEBUG) {
            Slog.i(TAG, "Reporting "  + classLoaderContextMap);
        }
        if (classLoaderContextMap.isEmpty()) {
            Slog.wtf(TAG, "Bad call to DexLoadReporter: empty classLoaderContextMap");
            return;
        }

        try {
            mPackageManager.notifyDexLoad(
                    PLATFORM_PACKAGE_NAME,
                    classLoaderContextMap,
                    VMRuntime.getRuntime().vmInstructionSet());
        } catch (RemoteException ignored) {
            // We're in system server, it can't happen.
        }
    }

    /**
     * Configures system server dex file reporting.
     * <p>The method will install a reporter in the BaseDexClassLoader and also
     * force the reporting of any dex files already loaded by the system server.
     */
    public static void configureSystemServerDexReporter(IPackageManager pm) {
        Slog.i(TAG, "Configuring system server dex reporter");

        SystemServerDexLoadReporter reporter = new SystemServerDexLoadReporter(pm);
        BaseDexClassLoader.setReporter(reporter);
        ClassLoader currrentClassLoader = reporter.getClass().getClassLoader();
        if (currrentClassLoader instanceof BaseDexClassLoader) {
            ((BaseDexClassLoader) currrentClassLoader).reportClassLoaderChain();
        } else {
            Slog.wtf(TAG, "System server class loader is not a BaseDexClassLoader. type="
                    + currrentClassLoader.getClass().getName());
        }
    }
}
+1 −11
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import android.app.usage.UsageStatsManagerInternal;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.IPackageManager;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
@@ -168,7 +167,6 @@ import com.android.server.pm.PackageManagerService;
import com.android.server.pm.ShortcutService;
import com.android.server.pm.UserManagerService;
import com.android.server.pm.dex.OdsignStatsLogger;
import com.android.server.pm.dex.SystemServerDexLoadReporter;
import com.android.server.pm.verify.domain.DomainVerificationService;
import com.android.server.policy.AppOpsPolicy;
import com.android.server.policy.PermissionPolicyService;
@@ -1210,24 +1208,16 @@ public final class SystemServer implements Dumpable {
        mSystemServiceManager.startService(domainVerificationService);
        t.traceEnd();

        IPackageManager iPackageManager;
        t.traceBegin("StartPackageManagerService");
        try {
            Watchdog.getInstance().pauseWatchingCurrentThread("packagemanagermain");
            Pair<PackageManagerService, IPackageManager> pmsPair = PackageManagerService.main(
            mPackageManagerService = PackageManagerService.main(
                    mSystemContext, installer, domainVerificationService,
                    mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF);
            mPackageManagerService = pmsPair.first;
            iPackageManager = pmsPair.second;
        } finally {
            Watchdog.getInstance().resumeWatchingCurrentThread("packagemanagermain");
        }

        // Now that the package manager has started, register the dex load reporter to capture any
        // dex files loaded by system server.
        // These dex files will be optimized by the BackgroundDexOptService.
        SystemServerDexLoadReporter.configureSystemServerDexReporter(iPackageManager);

        mFirstBoot = mPackageManagerService.isFirstBoot();
        mPackageManager = mSystemContext.getPackageManager();
        t.traceEnd();