Loading core/java/android/content/pm/PackageParser.java +13 −0 Original line number Diff line number Diff line Loading @@ -5096,6 +5096,19 @@ public class PackageParser { return latestUse; } public long getLatestForegroundPackageUseTimeInMills() { int[] foregroundReasons = { PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY, PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE }; long latestUse = 0L; for (int reason : foregroundReasons) { latestUse = Math.max(latestUse, mLastPackageUsageTimeInMills[reason]); } return latestUse; } public String toString() { return "Package{" + Integer.toHexString(System.identityHashCode(this)) Loading services/core/java/com/android/server/pm/PackageDexOptimizer.java +33 −26 Original line number Diff line number Diff line Loading @@ -137,10 +137,7 @@ class PackageDexOptimizer { boolean isProfileGuidedFilter = DexFile.isProfileGuidedCompilerFilter(targetCompilerFilter); // If any part of the app is used by other apps, we cannot use profile-guided // compilation. // Skip the check for forward locked packages since they don't share their code. if (isProfileGuidedFilter && !pkg.isForwardLocked()) { for (String path : paths) { if (isUsedByOtherApps(path)) { if (isProfileGuidedFilter && isUsedByOtherApps(pkg)) { checkProfiles = false; targetCompilerFilter = getNonProfileGuidedCompilerFilter(targetCompilerFilter); Loading @@ -148,10 +145,6 @@ class PackageDexOptimizer { throw new IllegalStateException(targetCompilerFilter); } isProfileGuidedFilter = false; break; } } } // If we're asked to take profile updates into account, check now. Loading Loading @@ -281,7 +274,19 @@ class PackageDexOptimizer { mSystemReady = true; } private boolean isUsedByOtherApps(String apkPath) { /** * Returns true if the profiling data collected for the given app indicate * that the apps's APK has been loaded by another app. * Note that this returns false for all forward-locked apps and apps without * any collected profiling data. */ public static boolean isUsedByOtherApps(PackageParser.Package pkg) { if (pkg.isForwardLocked()) { // Skip the check for forward locked packages since they don't share their code. return false; } for (String apkPath : pkg.getAllCodePathsExcludingResourceOnly()) { try { apkPath = new File(apkPath).getCanonicalPath(); } catch (IOException e) { Loading @@ -291,12 +296,14 @@ class PackageDexOptimizer { String useMarker = apkPath.replace('/', '@'); final int[] currentUserIds = UserManagerService.getInstance().getUserIds(); for (int i = 0; i < currentUserIds.length; i++) { File profileDir = Environment.getDataProfilesDeForeignDexDirectory(currentUserIds[i]); File profileDir = Environment.getDataProfilesDeForeignDexDirectory(currentUserIds[i]); File foreignUseMark = new File(profileDir, useMarker); if (foreignUseMark.exists()) { return true; } } } return false; } Loading services/core/java/com/android/server/pm/PackageManagerServiceUtils.java +16 −3 Original line number Diff line number Diff line Loading @@ -69,10 +69,11 @@ public class PackageManagerServiceUtils { long now = System.currentTimeMillis(); for (Iterator<PackageParser.Package> i = pkgs.iterator(); i.hasNext();) { PackageParser.Package pkg = i.next(); long then = pkg.getLatestPackageUseTimeInMills(); long then = pkg.getLatestForegroundPackageUseTimeInMills(); if (then + dexOptLRUThresholdInMills < now) { if (DEBUG_DEXOPT) { Log.i(TAG, "Skipping dexopt of " + pkg.packageName + " last resumed: " + Log.i(TAG, "Skipping dexopt of " + pkg.packageName + " last used in foreground: " + ((then == 0) ? "never" : new Date(then))); } i.remove(); Loading Loading @@ -117,6 +118,18 @@ public class PackageManagerServiceUtils { } remainingPkgs.removeAll(result); // Give priority to apps used by other apps. for (PackageParser.Package pkg : remainingPkgs) { if (PackageDexOptimizer.isUsedByOtherApps(pkg)) { if (DEBUG_DEXOPT) { Log.i(TAG, "Adding app used by other apps " + result.size() + ": " + pkg.packageName); } result.add(pkg); } } remainingPkgs.removeAll(result); // Filter out packages that aren't recently used, add all remaining apps. // TODO: add a property to control this? if (packageManagerService.isHistoricalPackageUsageAvailable()) { Loading Loading
core/java/android/content/pm/PackageParser.java +13 −0 Original line number Diff line number Diff line Loading @@ -5096,6 +5096,19 @@ public class PackageParser { return latestUse; } public long getLatestForegroundPackageUseTimeInMills() { int[] foregroundReasons = { PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY, PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE }; long latestUse = 0L; for (int reason : foregroundReasons) { latestUse = Math.max(latestUse, mLastPackageUsageTimeInMills[reason]); } return latestUse; } public String toString() { return "Package{" + Integer.toHexString(System.identityHashCode(this)) Loading
services/core/java/com/android/server/pm/PackageDexOptimizer.java +33 −26 Original line number Diff line number Diff line Loading @@ -137,10 +137,7 @@ class PackageDexOptimizer { boolean isProfileGuidedFilter = DexFile.isProfileGuidedCompilerFilter(targetCompilerFilter); // If any part of the app is used by other apps, we cannot use profile-guided // compilation. // Skip the check for forward locked packages since they don't share their code. if (isProfileGuidedFilter && !pkg.isForwardLocked()) { for (String path : paths) { if (isUsedByOtherApps(path)) { if (isProfileGuidedFilter && isUsedByOtherApps(pkg)) { checkProfiles = false; targetCompilerFilter = getNonProfileGuidedCompilerFilter(targetCompilerFilter); Loading @@ -148,10 +145,6 @@ class PackageDexOptimizer { throw new IllegalStateException(targetCompilerFilter); } isProfileGuidedFilter = false; break; } } } // If we're asked to take profile updates into account, check now. Loading Loading @@ -281,7 +274,19 @@ class PackageDexOptimizer { mSystemReady = true; } private boolean isUsedByOtherApps(String apkPath) { /** * Returns true if the profiling data collected for the given app indicate * that the apps's APK has been loaded by another app. * Note that this returns false for all forward-locked apps and apps without * any collected profiling data. */ public static boolean isUsedByOtherApps(PackageParser.Package pkg) { if (pkg.isForwardLocked()) { // Skip the check for forward locked packages since they don't share their code. return false; } for (String apkPath : pkg.getAllCodePathsExcludingResourceOnly()) { try { apkPath = new File(apkPath).getCanonicalPath(); } catch (IOException e) { Loading @@ -291,12 +296,14 @@ class PackageDexOptimizer { String useMarker = apkPath.replace('/', '@'); final int[] currentUserIds = UserManagerService.getInstance().getUserIds(); for (int i = 0; i < currentUserIds.length; i++) { File profileDir = Environment.getDataProfilesDeForeignDexDirectory(currentUserIds[i]); File profileDir = Environment.getDataProfilesDeForeignDexDirectory(currentUserIds[i]); File foreignUseMark = new File(profileDir, useMarker); if (foreignUseMark.exists()) { return true; } } } return false; } Loading
services/core/java/com/android/server/pm/PackageManagerServiceUtils.java +16 −3 Original line number Diff line number Diff line Loading @@ -69,10 +69,11 @@ public class PackageManagerServiceUtils { long now = System.currentTimeMillis(); for (Iterator<PackageParser.Package> i = pkgs.iterator(); i.hasNext();) { PackageParser.Package pkg = i.next(); long then = pkg.getLatestPackageUseTimeInMills(); long then = pkg.getLatestForegroundPackageUseTimeInMills(); if (then + dexOptLRUThresholdInMills < now) { if (DEBUG_DEXOPT) { Log.i(TAG, "Skipping dexopt of " + pkg.packageName + " last resumed: " + Log.i(TAG, "Skipping dexopt of " + pkg.packageName + " last used in foreground: " + ((then == 0) ? "never" : new Date(then))); } i.remove(); Loading Loading @@ -117,6 +118,18 @@ public class PackageManagerServiceUtils { } remainingPkgs.removeAll(result); // Give priority to apps used by other apps. for (PackageParser.Package pkg : remainingPkgs) { if (PackageDexOptimizer.isUsedByOtherApps(pkg)) { if (DEBUG_DEXOPT) { Log.i(TAG, "Adding app used by other apps " + result.size() + ": " + pkg.packageName); } result.add(pkg); } } remainingPkgs.removeAll(result); // Filter out packages that aren't recently used, add all remaining apps. // TODO: add a property to control this? if (packageManagerService.isHistoricalPackageUsageAvailable()) { Loading