summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Hao <jeffhao@google.com>2014-10-22 15:57:32 -0700
committerJeff Hao <jeffhao@google.com>2014-10-23 11:27:42 -0700
commit7eb599b267d00cbde891c0a87924f2f5086f4497 (patch)
tree01978b12641d7c03ff3edecc8e2f8d672246a5a8
parentf6e297398ba23ce7d26cf2e0efaf0d8a2230fe1c (diff)
downloadframeworks_base-7eb599b267d00cbde891c0a87924f2f5086f4497.zip
frameworks_base-7eb599b267d00cbde891c0a87924f2f5086f4497.tar.gz
frameworks_base-7eb599b267d00cbde891c0a87924f2f5086f4497.tar.bz2
Get UsageStats if no PackageUsage is available for boot dexopt filtering.
Bug: 17191977 Change-Id: I33e18459e49afa42b8e8218574a2434e5205a6da
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerService.java44
-rw-r--r--services/java/com/android/server/SystemServer.java2
-rw-r--r--services/usage/java/com/android/server/usage/UsageStatsService.java7
3 files changed, 42 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index b79e157..6b046f2 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -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;
@@ -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;
@@ -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)) {
@@ -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)));
@@ -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;
+ }
+ }
+ }
}
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 6009ffd..d7f6130 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -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);
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index 2ed9745..7ff246a 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -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;
@@ -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.