Loading services/core/java/com/android/server/pm/PackageManagerService.java +34 −10 Original line number Diff line number Diff line Loading @@ -84,6 +84,8 @@ import android.app.AppGlobals; import android.app.IActivityManager; import android.app.admin.IDevicePolicyManager; import android.app.backup.IBackupManager; import android.app.usage.UsageStats; import android.app.usage.UsageStatsManager; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -329,6 +331,7 @@ public class PackageManagerService extends IPackageManager.Stub { final boolean mFactoryTest; final boolean mOnlyCore; final boolean mLazyDexOpt; final long mDexOptLRUThresholdInMills; final DisplayMetrics mMetrics; final int mDefParseFlags; final String[] mSeparateProcesses; Loading Loading @@ -1294,6 +1297,15 @@ public class PackageManagerService extends IPackageManager.Stub { mSettings.addSharedUserLPw("android.uid.shell", SHELL_UID, ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED); // TODO: add a property to control this? long dexOptLRUThresholdInMinutes; if (mLazyDexOpt) { dexOptLRUThresholdInMinutes = 30; // only last 30 minutes of apps for eng builds. } else { dexOptLRUThresholdInMinutes = 7 * 24 * 60; // apps used in the 7 days for users. } mDexOptLRUThresholdInMills = dexOptLRUThresholdInMinutes * 60 * 1000; String separateProcesses = SystemProperties.get("debug.separate_processes"); if (separateProcesses != null && separateProcesses.length() > 0) { if ("*".equals(separateProcesses)) { Loading Loading @@ -4568,22 +4580,13 @@ public class PackageManagerService extends IPackageManager.Stub { // The exception is first boot of a non-eng device (aka !mLazyDexOpt), which // should do a full dexopt. if (mLazyDexOpt || (!isFirstBoot() && mPackageUsage.isHistoricalPackageUsageAvailable())) { // TODO: add a property to control this? long dexOptLRUThresholdInMinutes; if (mLazyDexOpt) { dexOptLRUThresholdInMinutes = 30; // only last 30 minutes of apps for eng builds. } else { dexOptLRUThresholdInMinutes = 7 * 24 * 60; // apps used in the 7 days for users. } long dexOptLRUThresholdInMills = dexOptLRUThresholdInMinutes * 60 * 1000; int total = pkgs.size(); int skipped = 0; long now = System.currentTimeMillis(); for (Iterator<PackageParser.Package> i = pkgs.iterator(); i.hasNext();) { PackageParser.Package pkg = i.next(); long then = pkg.mLastPackageUsageTimeInMills; if (then + dexOptLRUThresholdInMills < now) { if (then + mDexOptLRUThresholdInMills < now) { if (DEBUG_DEXOPT) { Log.i(TAG, "Skipping dexopt of " + pkg.packageName + " last resumed: " + ((then == 0) ? "never" : new Date(then))); Loading Loading @@ -13381,4 +13384,25 @@ public class PackageManagerService extends IPackageManager.Stub { return false; } } public void getUsageStatsIfNoPackageUsageInfo() { if (!mPackageUsage.isHistoricalPackageUsageAvailable()) { UsageStatsManager usm = (UsageStatsManager) mContext.getSystemService(Context.USAGE_STATS_SERVICE); if (usm == null) { throw new IllegalStateException("UsageStatsManager must be initialized"); } long now = System.currentTimeMillis(); Map<String, UsageStats> stats = usm.queryAndAggregateUsageStats(now - mDexOptLRUThresholdInMills, now); for (Map.Entry<String, UsageStats> entry : stats.entrySet()) { String packageName = entry.getKey(); PackageParser.Package pkg = mPackages.get(packageName); if (pkg == null) { continue; } UsageStats usage = entry.getValue(); pkg.mLastPackageUsageTimeInMills = usage.getLastTimeUsed(); mPackageUsage.mIsHistoricalPackageUsageAvailable = true; } } } } services/java/com/android/server/SystemServer.java +2 −0 Original line number Diff line number Diff line Loading @@ -374,6 +374,8 @@ public final class SystemServer { mSystemServiceManager.startService(UsageStatsService.class); mActivityManagerService.setUsageStatsManager( LocalServices.getService(UsageStatsManagerInternal.class)); // Update after UsageStatsService is available, needed before performBootDexOpt. mPackageManagerService.getUsageStatsIfNoPackageUsageInfo(); // Tracks whether the updatable WebView is in a ready state and watches for update installs. mSystemServiceManager.startService(WebViewUpdateService.class); Loading services/usage/java/com/android/server/usage/UsageStatsService.java +6 −1 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import android.os.Environment; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; Loading Loading @@ -349,8 +350,12 @@ public class UsageStatsService extends SystemService implements private class BinderService extends IUsageStatsManager.Stub { private boolean hasPermission(String callingPackage) { final int callingUid = Binder.getCallingUid(); if (callingUid == Process.SYSTEM_UID) { return true; } final int mode = mAppOps.checkOp(AppOpsManager.OP_GET_USAGE_STATS, Binder.getCallingUid(), callingPackage); callingUid, callingPackage); if (mode == AppOpsManager.MODE_DEFAULT) { // The default behavior here is to check if PackageManager has given the app // permission. Loading Loading
services/core/java/com/android/server/pm/PackageManagerService.java +34 −10 Original line number Diff line number Diff line Loading @@ -84,6 +84,8 @@ import android.app.AppGlobals; import android.app.IActivityManager; import android.app.admin.IDevicePolicyManager; import android.app.backup.IBackupManager; import android.app.usage.UsageStats; import android.app.usage.UsageStatsManager; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; Loading Loading @@ -329,6 +331,7 @@ public class PackageManagerService extends IPackageManager.Stub { final boolean mFactoryTest; final boolean mOnlyCore; final boolean mLazyDexOpt; final long mDexOptLRUThresholdInMills; final DisplayMetrics mMetrics; final int mDefParseFlags; final String[] mSeparateProcesses; Loading Loading @@ -1294,6 +1297,15 @@ public class PackageManagerService extends IPackageManager.Stub { mSettings.addSharedUserLPw("android.uid.shell", SHELL_UID, ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED); // TODO: add a property to control this? long dexOptLRUThresholdInMinutes; if (mLazyDexOpt) { dexOptLRUThresholdInMinutes = 30; // only last 30 minutes of apps for eng builds. } else { dexOptLRUThresholdInMinutes = 7 * 24 * 60; // apps used in the 7 days for users. } mDexOptLRUThresholdInMills = dexOptLRUThresholdInMinutes * 60 * 1000; String separateProcesses = SystemProperties.get("debug.separate_processes"); if (separateProcesses != null && separateProcesses.length() > 0) { if ("*".equals(separateProcesses)) { Loading Loading @@ -4568,22 +4580,13 @@ public class PackageManagerService extends IPackageManager.Stub { // The exception is first boot of a non-eng device (aka !mLazyDexOpt), which // should do a full dexopt. if (mLazyDexOpt || (!isFirstBoot() && mPackageUsage.isHistoricalPackageUsageAvailable())) { // TODO: add a property to control this? long dexOptLRUThresholdInMinutes; if (mLazyDexOpt) { dexOptLRUThresholdInMinutes = 30; // only last 30 minutes of apps for eng builds. } else { dexOptLRUThresholdInMinutes = 7 * 24 * 60; // apps used in the 7 days for users. } long dexOptLRUThresholdInMills = dexOptLRUThresholdInMinutes * 60 * 1000; int total = pkgs.size(); int skipped = 0; long now = System.currentTimeMillis(); for (Iterator<PackageParser.Package> i = pkgs.iterator(); i.hasNext();) { PackageParser.Package pkg = i.next(); long then = pkg.mLastPackageUsageTimeInMills; if (then + dexOptLRUThresholdInMills < now) { if (then + mDexOptLRUThresholdInMills < now) { if (DEBUG_DEXOPT) { Log.i(TAG, "Skipping dexopt of " + pkg.packageName + " last resumed: " + ((then == 0) ? "never" : new Date(then))); Loading Loading @@ -13381,4 +13384,25 @@ public class PackageManagerService extends IPackageManager.Stub { return false; } } public void getUsageStatsIfNoPackageUsageInfo() { if (!mPackageUsage.isHistoricalPackageUsageAvailable()) { UsageStatsManager usm = (UsageStatsManager) mContext.getSystemService(Context.USAGE_STATS_SERVICE); if (usm == null) { throw new IllegalStateException("UsageStatsManager must be initialized"); } long now = System.currentTimeMillis(); Map<String, UsageStats> stats = usm.queryAndAggregateUsageStats(now - mDexOptLRUThresholdInMills, now); for (Map.Entry<String, UsageStats> entry : stats.entrySet()) { String packageName = entry.getKey(); PackageParser.Package pkg = mPackages.get(packageName); if (pkg == null) { continue; } UsageStats usage = entry.getValue(); pkg.mLastPackageUsageTimeInMills = usage.getLastTimeUsed(); mPackageUsage.mIsHistoricalPackageUsageAvailable = true; } } } }
services/java/com/android/server/SystemServer.java +2 −0 Original line number Diff line number Diff line Loading @@ -374,6 +374,8 @@ public final class SystemServer { mSystemServiceManager.startService(UsageStatsService.class); mActivityManagerService.setUsageStatsManager( LocalServices.getService(UsageStatsManagerInternal.class)); // Update after UsageStatsService is available, needed before performBootDexOpt. mPackageManagerService.getUsageStatsIfNoPackageUsageInfo(); // Tracks whether the updatable WebView is in a ready state and watches for update installs. mSystemServiceManager.startService(WebViewUpdateService.class); Loading
services/usage/java/com/android/server/usage/UsageStatsService.java +6 −1 Original line number Diff line number Diff line Loading @@ -38,6 +38,7 @@ import android.os.Environment; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; Loading Loading @@ -349,8 +350,12 @@ public class UsageStatsService extends SystemService implements private class BinderService extends IUsageStatsManager.Stub { private boolean hasPermission(String callingPackage) { final int callingUid = Binder.getCallingUid(); if (callingUid == Process.SYSTEM_UID) { return true; } final int mode = mAppOps.checkOp(AppOpsManager.OP_GET_USAGE_STATS, Binder.getCallingUid(), callingPackage); callingUid, callingPackage); if (mode == AppOpsManager.MODE_DEFAULT) { // The default behavior here is to check if PackageManager has given the app // permission. Loading