diff options
Diffstat (limited to 'apex/jobscheduler')
3 files changed, 29 insertions, 19 deletions
diff --git a/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java b/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java index 887d82c6413f..e15f0f37fc62 100644 --- a/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java +++ b/apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java @@ -71,7 +71,7 @@ public interface AppStandbyInternal { */ void postOneTimeCheckIdleStates(); - void reportEvent(UsageEvents.Event event, long elapsedRealtime, int userId); + void reportEvent(UsageEvents.Event event, int userId); void setLastJobRunTime(String packageName, int userId, long elapsedRealtime); @@ -150,9 +150,7 @@ public interface AppStandbyInternal { void clearCarrierPrivilegedApps(); - void flushToDisk(int userId); - - void flushDurationsToDisk(); + void flushToDisk(); void initializeDefaultsForSystemApps(int userId); @@ -162,7 +160,7 @@ public interface AppStandbyInternal { void postReportExemptedSyncStart(String packageName, int userId); - void dumpUser(IndentingPrintWriter idpw, int userId, List<String> pkgs); + void dumpUsers(IndentingPrintWriter idpw, int[] userIds, List<String> pkgs); void dumpState(String[] args, PrintWriter pw); diff --git a/apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java b/apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java index 372ec981df02..70155ee84720 100644 --- a/apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java +++ b/apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java @@ -675,6 +675,14 @@ public class AppIdleHistory { return Long.parseLong(value); } + + public void writeAppIdleTimes() { + final int size = mIdleHistory.size(); + for (int i = 0; i < size; i++) { + writeAppIdleTimes(mIdleHistory.keyAt(i)); + } + } + public void writeAppIdleTimes(int userId) { FileOutputStream fos = null; AtomicFile appIdleFile = new AtomicFile(getUserFile(userId)); @@ -743,8 +751,18 @@ public class AppIdleHistory { } } - public void dump(IndentingPrintWriter idpw, int userId, List<String> pkgs) { - idpw.println("App Standby States:"); + public void dumpUsers(IndentingPrintWriter idpw, int[] userIds, List<String> pkgs) { + final int numUsers = userIds.length; + for (int i = 0; i < numUsers; i++) { + idpw.println(); + dumpUser(idpw, userIds[i], pkgs); + } + } + + private void dumpUser(IndentingPrintWriter idpw, int userId, List<String> pkgs) { + idpw.print("User "); + idpw.print(userId); + idpw.println(" App Standby States:"); idpw.increaseIndent(); ArrayMap<String, AppUsageHistory> userHistory = mIdleHistory.get(userId); final long elapsedRealtime = SystemClock.elapsedRealtime(); diff --git a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java index f27eb25fa7e2..687b1d4e0bde 100644 --- a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java +++ b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java @@ -866,7 +866,7 @@ public class AppStandbyController implements AppStandbyInternal { } @Override - public void reportEvent(UsageEvents.Event event, long elapsedRealtime, int userId) { + public void reportEvent(UsageEvents.Event event, int userId) { if (!mAppIdleEnabled) return; final int eventType = event.getEventType(); if ((eventType == UsageEvents.Event.ACTIVITY_RESUMED @@ -880,6 +880,7 @@ public class AppStandbyController implements AppStandbyInternal { final String pkg = event.getPackageName(); final List<UserHandle> linkedProfiles = getCrossProfileTargets(pkg, userId); synchronized (mAppIdleLock) { + final long elapsedRealtime = mInjector.elapsedRealtime(); reportEventLocked(pkg, eventType, elapsedRealtime, userId); final int size = linkedProfiles.size(); @@ -1630,18 +1631,11 @@ public class AppStandbyController implements AppStandbyInternal { } } - @Override - public void flushToDisk(int userId) { - synchronized (mAppIdleLock) { - mAppIdleHistory.writeAppIdleTimes(userId); - } - } @Override - public void flushDurationsToDisk() { - // Persist elapsed and screen on time. If this fails for whatever reason, the apps will be - // considered not-idle, which is the safest outcome in such an event. + public void flushToDisk() { synchronized (mAppIdleLock) { + mAppIdleHistory.writeAppIdleTimes(); mAppIdleHistory.writeAppIdleDurations(); } } @@ -1818,9 +1812,9 @@ public class AppStandbyController implements AppStandbyInternal { } @Override - public void dumpUser(IndentingPrintWriter idpw, int userId, List<String> pkgs) { + public void dumpUsers(IndentingPrintWriter idpw, int[] userIds, List<String> pkgs) { synchronized (mAppIdleLock) { - mAppIdleHistory.dump(idpw, userId, pkgs); + mAppIdleHistory.dumpUsers(idpw, userIds, pkgs); } } |