Loading apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java +3 −5 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -150,9 +150,7 @@ public interface AppStandbyInternal { void clearCarrierPrivilegedApps(); void flushToDisk(int userId); void flushDurationsToDisk(); void flushToDisk(); void initializeDefaultsForSystemApps(int userId); Loading @@ -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); Loading apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java +20 −2 Original line number Diff line number Diff line Loading @@ -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)); Loading Loading @@ -743,7 +751,17 @@ public class AppIdleHistory { } } public void dump(IndentingPrintWriter idpw, int userId, List<String> pkgs) { 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); Loading apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java +6 −12 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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(); Loading Loading @@ -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(); } } Loading Loading @@ -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); } } Loading services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java +1 −1 Original line number Diff line number Diff line Loading @@ -516,7 +516,7 @@ public class AppStandbyControllerTests { UsageEvents.Event ev = new UsageEvents.Event(); ev.mPackage = packageName; ev.mEventType = eventType; controller.reportEvent(ev, elapsedTime, USER_ID); controller.reportEvent(ev, USER_ID); } private int getStandbyBucket(AppStandbyController controller, String packageName) { Loading services/usage/java/com/android/server/usage/UsageStatsService.java +66 −51 Original line number Diff line number Diff line Loading @@ -681,6 +681,8 @@ public class UsageStatsService extends SystemService implements reportEventToAllUserId(event); flushToDiskLocked(); } mAppStandby.flushToDisk(); } /** Loading Loading @@ -806,8 +808,6 @@ public class UsageStatsService extends SystemService implements return; } final long elapsedRealtime = SystemClock.elapsedRealtime(); switch (event.mEventType) { case Event.ACTIVITY_RESUMED: FrameworkStatsLog.write( Loading Loading @@ -914,9 +914,9 @@ public class UsageStatsService extends SystemService implements return; // user was stopped or removed } service.reportEvent(event); mAppStandby.reportEvent(event, elapsedRealtime, userId); } mAppStandby.reportEvent(event, userId); } /** Loading Loading @@ -948,6 +948,7 @@ public class UsageStatsService extends SystemService implements reportEventToAllUserId(event); flushToDiskLocked(); } mAppStandby.flushToDisk(); } /** Loading @@ -957,9 +958,9 @@ public class UsageStatsService extends SystemService implements synchronized (mLock) { Slog.i(TAG, "Removing user " + userId + " and all data."); mUserState.remove(userId); mAppStandby.onUserRemoved(userId); mAppTimeLimit.onUserRemoved(userId); } mAppStandby.onUserRemoved(userId); // Cancel any scheduled jobs for this user since the user is being removed. UsageStatsIdleService.cancelJob(getContext(), userId); UsageStatsIdleService.cancelUpdateMappingsJob(getContext()); Loading Loading @@ -1158,10 +1159,7 @@ public class UsageStatsService extends SystemService implements if (service != null) { service.persistActiveStats(); } mAppStandby.flushToDisk(userId); } mAppStandby.flushDurationsToDisk(); mHandler.removeMessages(MSG_FLUSH_TO_DISK); } Loading @@ -1169,7 +1167,6 @@ public class UsageStatsService extends SystemService implements * Called by the Binder stub. */ void dump(String[] args, PrintWriter pw) { synchronized (mLock) { IndentingPrintWriter idpw = new IndentingPrintWriter(pw, " "); boolean checkin = false; Loading @@ -1184,13 +1181,17 @@ public class UsageStatsService extends SystemService implements } else if ("-c".equals(arg)) { compact = true; } else if ("flush".equals(arg)) { synchronized (mLock) { flushToDiskLocked(); } mAppStandby.flushToDisk(); pw.println("Flushed stats to disk"); return; } else if ("is-app-standby-enabled".equals(arg)) { pw.println(mAppStandby.isAppIdleEnabled()); return; } else if ("apptimelimit".equals(arg)) { synchronized (mLock) { if (i + 1 >= args.length) { mAppTimeLimit.dump(null, pw); } else { Loading @@ -1199,8 +1200,10 @@ public class UsageStatsService extends SystemService implements mAppTimeLimit.dump(remainingArgs, pw); } return; } } else if ("file".equals(arg)) { final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); synchronized (mLock) { if (i + 1 >= args.length) { // dump everything for all users final int numUsers = mUserState.size(); Loading @@ -1224,8 +1227,10 @@ public class UsageStatsService extends SystemService implements } } return; } } else if ("database-info".equals(arg)) { final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); synchronized (mLock) { if (i + 1 >= args.length) { // dump info for all users final int numUsers = mUserState.size(); Loading @@ -1247,24 +1252,29 @@ public class UsageStatsService extends SystemService implements } } return; } } else if ("appstandby".equals(arg)) { mAppStandby.dumpState(args, pw); return; } else if ("stats-directory".equals(arg)) { final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); synchronized (mLock) { final int userId = parseUserIdFromArgs(args, i, ipw); if (userId != UserHandle.USER_NULL) { ipw.println(new File(Environment.getDataSystemCeDirectory(userId), "usagestats").getAbsolutePath()); } return; } } else if ("mappings".equals(arg)) { final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); final int userId = parseUserIdFromArgs(args, i, ipw); synchronized (mLock) { if (userId != UserHandle.USER_NULL) { mUserState.get(userId).dumpMappings(ipw); } return; } } else if (arg != null && !arg.startsWith("-")) { // Anything else that doesn't start with '-' is a pkg to filter pkgs.add(arg); Loading @@ -1272,9 +1282,13 @@ public class UsageStatsService extends SystemService implements } } final int[] userIds; synchronized (mLock) { final int userCount = mUserState.size(); userIds = new int[userCount]; for (int i = 0; i < userCount; i++) { int userId = mUserState.keyAt(i); final int userId = mUserState.keyAt(i); userIds[i] = userId; idpw.printPair("user", userId); idpw.println(); idpw.increaseIndent(); Loading @@ -1286,21 +1300,22 @@ public class UsageStatsService extends SystemService implements idpw.println(); } } mAppStandby.dumpUser(idpw, userId, pkgs); idpw.decreaseIndent(); } if (CollectionUtils.isEmpty(pkgs)) { pw.println(); mAppStandby.dumpState(args, pw); } idpw.println(); idpw.printPair("Usage Source", UsageStatsManager.usageSourceToString(mUsageSource)); idpw.println(); mAppTimeLimit.dump(null, pw); } mAppStandby.dumpUsers(idpw, userIds, pkgs); if (CollectionUtils.isEmpty(pkgs)) { pw.println(); mAppStandby.dumpState(args, pw); } } private int parseUserIdFromArgs(String[] args, int index, IndentingPrintWriter ipw) { Loading Loading
apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java +3 −5 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -150,9 +150,7 @@ public interface AppStandbyInternal { void clearCarrierPrivilegedApps(); void flushToDisk(int userId); void flushDurationsToDisk(); void flushToDisk(); void initializeDefaultsForSystemApps(int userId); Loading @@ -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); Loading
apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java +20 −2 Original line number Diff line number Diff line Loading @@ -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)); Loading Loading @@ -743,7 +751,17 @@ public class AppIdleHistory { } } public void dump(IndentingPrintWriter idpw, int userId, List<String> pkgs) { 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); Loading
apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java +6 −12 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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(); Loading Loading @@ -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(); } } Loading Loading @@ -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); } } Loading
services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java +1 −1 Original line number Diff line number Diff line Loading @@ -516,7 +516,7 @@ public class AppStandbyControllerTests { UsageEvents.Event ev = new UsageEvents.Event(); ev.mPackage = packageName; ev.mEventType = eventType; controller.reportEvent(ev, elapsedTime, USER_ID); controller.reportEvent(ev, USER_ID); } private int getStandbyBucket(AppStandbyController controller, String packageName) { Loading
services/usage/java/com/android/server/usage/UsageStatsService.java +66 −51 Original line number Diff line number Diff line Loading @@ -681,6 +681,8 @@ public class UsageStatsService extends SystemService implements reportEventToAllUserId(event); flushToDiskLocked(); } mAppStandby.flushToDisk(); } /** Loading Loading @@ -806,8 +808,6 @@ public class UsageStatsService extends SystemService implements return; } final long elapsedRealtime = SystemClock.elapsedRealtime(); switch (event.mEventType) { case Event.ACTIVITY_RESUMED: FrameworkStatsLog.write( Loading Loading @@ -914,9 +914,9 @@ public class UsageStatsService extends SystemService implements return; // user was stopped or removed } service.reportEvent(event); mAppStandby.reportEvent(event, elapsedRealtime, userId); } mAppStandby.reportEvent(event, userId); } /** Loading Loading @@ -948,6 +948,7 @@ public class UsageStatsService extends SystemService implements reportEventToAllUserId(event); flushToDiskLocked(); } mAppStandby.flushToDisk(); } /** Loading @@ -957,9 +958,9 @@ public class UsageStatsService extends SystemService implements synchronized (mLock) { Slog.i(TAG, "Removing user " + userId + " and all data."); mUserState.remove(userId); mAppStandby.onUserRemoved(userId); mAppTimeLimit.onUserRemoved(userId); } mAppStandby.onUserRemoved(userId); // Cancel any scheduled jobs for this user since the user is being removed. UsageStatsIdleService.cancelJob(getContext(), userId); UsageStatsIdleService.cancelUpdateMappingsJob(getContext()); Loading Loading @@ -1158,10 +1159,7 @@ public class UsageStatsService extends SystemService implements if (service != null) { service.persistActiveStats(); } mAppStandby.flushToDisk(userId); } mAppStandby.flushDurationsToDisk(); mHandler.removeMessages(MSG_FLUSH_TO_DISK); } Loading @@ -1169,7 +1167,6 @@ public class UsageStatsService extends SystemService implements * Called by the Binder stub. */ void dump(String[] args, PrintWriter pw) { synchronized (mLock) { IndentingPrintWriter idpw = new IndentingPrintWriter(pw, " "); boolean checkin = false; Loading @@ -1184,13 +1181,17 @@ public class UsageStatsService extends SystemService implements } else if ("-c".equals(arg)) { compact = true; } else if ("flush".equals(arg)) { synchronized (mLock) { flushToDiskLocked(); } mAppStandby.flushToDisk(); pw.println("Flushed stats to disk"); return; } else if ("is-app-standby-enabled".equals(arg)) { pw.println(mAppStandby.isAppIdleEnabled()); return; } else if ("apptimelimit".equals(arg)) { synchronized (mLock) { if (i + 1 >= args.length) { mAppTimeLimit.dump(null, pw); } else { Loading @@ -1199,8 +1200,10 @@ public class UsageStatsService extends SystemService implements mAppTimeLimit.dump(remainingArgs, pw); } return; } } else if ("file".equals(arg)) { final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); synchronized (mLock) { if (i + 1 >= args.length) { // dump everything for all users final int numUsers = mUserState.size(); Loading @@ -1224,8 +1227,10 @@ public class UsageStatsService extends SystemService implements } } return; } } else if ("database-info".equals(arg)) { final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); synchronized (mLock) { if (i + 1 >= args.length) { // dump info for all users final int numUsers = mUserState.size(); Loading @@ -1247,24 +1252,29 @@ public class UsageStatsService extends SystemService implements } } return; } } else if ("appstandby".equals(arg)) { mAppStandby.dumpState(args, pw); return; } else if ("stats-directory".equals(arg)) { final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); synchronized (mLock) { final int userId = parseUserIdFromArgs(args, i, ipw); if (userId != UserHandle.USER_NULL) { ipw.println(new File(Environment.getDataSystemCeDirectory(userId), "usagestats").getAbsolutePath()); } return; } } else if ("mappings".equals(arg)) { final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); final int userId = parseUserIdFromArgs(args, i, ipw); synchronized (mLock) { if (userId != UserHandle.USER_NULL) { mUserState.get(userId).dumpMappings(ipw); } return; } } else if (arg != null && !arg.startsWith("-")) { // Anything else that doesn't start with '-' is a pkg to filter pkgs.add(arg); Loading @@ -1272,9 +1282,13 @@ public class UsageStatsService extends SystemService implements } } final int[] userIds; synchronized (mLock) { final int userCount = mUserState.size(); userIds = new int[userCount]; for (int i = 0; i < userCount; i++) { int userId = mUserState.keyAt(i); final int userId = mUserState.keyAt(i); userIds[i] = userId; idpw.printPair("user", userId); idpw.println(); idpw.increaseIndent(); Loading @@ -1286,21 +1300,22 @@ public class UsageStatsService extends SystemService implements idpw.println(); } } mAppStandby.dumpUser(idpw, userId, pkgs); idpw.decreaseIndent(); } if (CollectionUtils.isEmpty(pkgs)) { pw.println(); mAppStandby.dumpState(args, pw); } idpw.println(); idpw.printPair("Usage Source", UsageStatsManager.usageSourceToString(mUsageSource)); idpw.println(); mAppTimeLimit.dump(null, pw); } mAppStandby.dumpUsers(idpw, userIds, pkgs); if (CollectionUtils.isEmpty(pkgs)) { pw.println(); mAppStandby.dumpState(args, pw); } } private int parseUserIdFromArgs(String[] args, int index, IndentingPrintWriter ipw) { Loading