am e8d9810c: Merge "Get UsageStats if no PackageUsage is available for boot dexopt filtering." into lmp-mr1-dev
* commit 'e8d9810cdef5b3e288f54f42adc3205532343406': Get UsageStats if no PackageUsage is available for boot dexopt filtering.
This commit is contained in:
@@ -84,6 +84,8 @@ import android.app.AppGlobals;
|
|||||||
import android.app.IActivityManager;
|
import android.app.IActivityManager;
|
||||||
import android.app.admin.IDevicePolicyManager;
|
import android.app.admin.IDevicePolicyManager;
|
||||||
import android.app.backup.IBackupManager;
|
import android.app.backup.IBackupManager;
|
||||||
|
import android.app.usage.UsageStats;
|
||||||
|
import android.app.usage.UsageStatsManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -329,6 +331,7 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
final boolean mFactoryTest;
|
final boolean mFactoryTest;
|
||||||
final boolean mOnlyCore;
|
final boolean mOnlyCore;
|
||||||
final boolean mLazyDexOpt;
|
final boolean mLazyDexOpt;
|
||||||
|
final long mDexOptLRUThresholdInMills;
|
||||||
final DisplayMetrics mMetrics;
|
final DisplayMetrics mMetrics;
|
||||||
final int mDefParseFlags;
|
final int mDefParseFlags;
|
||||||
final String[] mSeparateProcesses;
|
final String[] mSeparateProcesses;
|
||||||
@@ -1294,6 +1297,15 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
mSettings.addSharedUserLPw("android.uid.shell", SHELL_UID,
|
mSettings.addSharedUserLPw("android.uid.shell", SHELL_UID,
|
||||||
ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
|
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");
|
String separateProcesses = SystemProperties.get("debug.separate_processes");
|
||||||
if (separateProcesses != null && separateProcesses.length() > 0) {
|
if (separateProcesses != null && separateProcesses.length() > 0) {
|
||||||
if ("*".equals(separateProcesses)) {
|
if ("*".equals(separateProcesses)) {
|
||||||
@@ -4568,22 +4580,13 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
// The exception is first boot of a non-eng device (aka !mLazyDexOpt), which
|
// The exception is first boot of a non-eng device (aka !mLazyDexOpt), which
|
||||||
// should do a full dexopt.
|
// should do a full dexopt.
|
||||||
if (mLazyDexOpt || (!isFirstBoot() && mPackageUsage.isHistoricalPackageUsageAvailable())) {
|
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 total = pkgs.size();
|
||||||
int skipped = 0;
|
int skipped = 0;
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for (Iterator<PackageParser.Package> i = pkgs.iterator(); i.hasNext();) {
|
for (Iterator<PackageParser.Package> i = pkgs.iterator(); i.hasNext();) {
|
||||||
PackageParser.Package pkg = i.next();
|
PackageParser.Package pkg = i.next();
|
||||||
long then = pkg.mLastPackageUsageTimeInMills;
|
long then = pkg.mLastPackageUsageTimeInMills;
|
||||||
if (then + dexOptLRUThresholdInMills < now) {
|
if (then + mDexOptLRUThresholdInMills < now) {
|
||||||
if (DEBUG_DEXOPT) {
|
if (DEBUG_DEXOPT) {
|
||||||
Log.i(TAG, "Skipping dexopt of " + pkg.packageName + " last resumed: " +
|
Log.i(TAG, "Skipping dexopt of " + pkg.packageName + " last resumed: " +
|
||||||
((then == 0) ? "never" : new Date(then)));
|
((then == 0) ? "never" : new Date(then)));
|
||||||
@@ -13381,4 +13384,25 @@ public class PackageManagerService extends IPackageManager.Stub {
|
|||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -374,6 +374,8 @@ public final class SystemServer {
|
|||||||
mSystemServiceManager.startService(UsageStatsService.class);
|
mSystemServiceManager.startService(UsageStatsService.class);
|
||||||
mActivityManagerService.setUsageStatsManager(
|
mActivityManagerService.setUsageStatsManager(
|
||||||
LocalServices.getService(UsageStatsManagerInternal.class));
|
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.
|
// Tracks whether the updatable WebView is in a ready state and watches for update installs.
|
||||||
mSystemServiceManager.startService(WebViewUpdateService.class);
|
mSystemServiceManager.startService(WebViewUpdateService.class);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import android.os.Environment;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.os.Process;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@@ -349,8 +350,12 @@ public class UsageStatsService extends SystemService implements
|
|||||||
private class BinderService extends IUsageStatsManager.Stub {
|
private class BinderService extends IUsageStatsManager.Stub {
|
||||||
|
|
||||||
private boolean hasPermission(String callingPackage) {
|
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,
|
final int mode = mAppOps.checkOp(AppOpsManager.OP_GET_USAGE_STATS,
|
||||||
Binder.getCallingUid(), callingPackage);
|
callingUid, callingPackage);
|
||||||
if (mode == AppOpsManager.MODE_DEFAULT) {
|
if (mode == AppOpsManager.MODE_DEFAULT) {
|
||||||
// The default behavior here is to check if PackageManager has given the app
|
// The default behavior here is to check if PackageManager has given the app
|
||||||
// permission.
|
// permission.
|
||||||
|
|||||||
Reference in New Issue
Block a user