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

Commit 943d1e76 authored by Calin Juravle's avatar Calin Juravle Committed by Andreas Gampe
Browse files

Record usage information per split

Increase the granularity of usage information to store data on each split
separately.

Now, splits get their own useByOtherApps flag and can be compiled
speed-profile when only the primary apk is loaded by other apps.

(cherry picked from commit 52a452cf)

Bug: 64124380
Test: runtest -x
services/tests/servicestests/src/com/android/server/pm/dex/*

Merged-In: Ibf9e7b9e67db9c6f0f45dc695bce8fbeb7be20ae
Change-Id: Ibf9e7b9e67db9c6f0f45dc695bce8fbeb7be20ae
parent fad6dc10
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -177,7 +177,7 @@ public class PackageDexOptimizer {
            }

            final boolean isUsedByOtherApps = options.isDexoptAsSharedLibrary()
                    || packageUseInfo.isUsedByOtherApps();
                    || packageUseInfo.isUsedByOtherApps(path);
            final String compilerFilter = getRealCompilerFilter(pkg.applicationInfo,
                options.getCompilerFilter(), isUsedByOtherApps);
            final boolean profileUpdated = options.isCheckForProfileUpdates() &&
+1 −1
Original line number Diff line number Diff line
@@ -9758,7 +9758,7 @@ public class PackageManagerService extends IPackageManager.Stub
    public void shutdown() {
        mPackageUsage.writeNow(mPackages);
        mCompilerStats.writeNow();
        mDexManager.savePackageDexUsageNow();
        mDexManager.writePackageDexUsageNow();
    }
    @Override
+4 −3
Original line number Diff line number Diff line
@@ -145,8 +145,9 @@ public class PackageManagerServiceUtils {
        // Give priority to apps used by other apps.
        DexManager dexManager = packageManagerService.getDexManager();
        applyPackageFilter((pkg) ->
                dexManager.getPackageUseInfoOrDefault(pkg.packageName).isUsedByOtherApps(), result,
                remainingPkgs, sortTemp, packageManagerService);
                dexManager.getPackageUseInfoOrDefault(pkg.packageName)
                        .isAnyCodePathUsedByOtherApps(),
                result, remainingPkgs, sortTemp, packageManagerService);

        // Filter out packages that aren't recently used, add all remaining apps.
        // TODO: add a property to control this?
@@ -219,7 +220,7 @@ public class PackageManagerServiceUtils {
        boolean isActiveInBackgroundAndUsedByOtherPackages = ((currentTimeInMillis
                - latestPackageUseTimeInMillis)
                < thresholdTimeinMillis)
                && packageUseInfo.isUsedByOtherApps();
                && packageUseInfo.isAnyCodePathUsedByOtherApps();

        return !isActiveInBackgroundAndUsedByOtherPackages;
    }
+17 −4
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ import com.android.server.pm.PackageManagerServiceCompilerMapping;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.HashMap;
import java.util.HashSet;
@@ -310,6 +312,8 @@ public class DexManager {

    private void loadInternal(Map<Integer, List<PackageInfo>> existingPackages) {
        Map<String, Set<Integer>> packageToUsersMap = new HashMap<>();
        Map<String, Set<String>> packageToCodePaths = new HashMap<>();

        // Cache the code locations for the installed packages. This allows for
        // faster lookups (no locks) when finding what package owns the dex file.
        for (Map.Entry<Integer, List<PackageInfo>> entry : existingPackages.entrySet()) {
@@ -319,17 +323,26 @@ public class DexManager {
                // Cache the code locations.
                cachePackageInfo(pi, userId);

                // Cache a map from package name to the set of user ids who installed the package.
                // Cache two maps:
                //   - from package name to the set of user ids who installed the package.
                //   - from package name to the set of code paths.
                // We will use it to sync the data and remove obsolete entries from
                // mPackageDexUsage.
                Set<Integer> users = putIfAbsent(
                        packageToUsersMap, pi.packageName, new HashSet<>());
                users.add(userId);

                Set<String> codePaths = putIfAbsent(
                    packageToCodePaths, pi.packageName, new HashSet<>());
                codePaths.add(pi.applicationInfo.sourceDir);
                if (pi.applicationInfo.splitSourceDirs != null) {
                    Collections.addAll(codePaths, pi.applicationInfo.splitSourceDirs);
                }
            }
        }

        mPackageDexUsage.read();
        mPackageDexUsage.syncData(packageToUsersMap);
        mPackageDexUsage.syncData(packageToUsersMap, packageToCodePaths);
    }

    /**
@@ -608,9 +621,9 @@ public class DexManager {
    }

    /**
     * Saves the in-memory package dex usage to disk right away.
     * Writes the in-memory package dex usage to disk right away.
     */
    public void savePackageDexUsageNow() {
    public void writePackageDexUsageNow() {
        mPackageDexUsage.writeNow();
    }

+179 −100

File changed.

Preview size limit exceeded, changes collapsed.

Loading