Merge "Move AppStandbyController calls out of UsageStats lock" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5d544ddff0
@@ -71,7 +71,7 @@ public interface AppStandbyInternal {
|
|||||||
*/
|
*/
|
||||||
void postOneTimeCheckIdleStates();
|
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);
|
void setLastJobRunTime(String packageName, int userId, long elapsedRealtime);
|
||||||
|
|
||||||
@@ -150,9 +150,7 @@ public interface AppStandbyInternal {
|
|||||||
|
|
||||||
void clearCarrierPrivilegedApps();
|
void clearCarrierPrivilegedApps();
|
||||||
|
|
||||||
void flushToDisk(int userId);
|
void flushToDisk();
|
||||||
|
|
||||||
void flushDurationsToDisk();
|
|
||||||
|
|
||||||
void initializeDefaultsForSystemApps(int userId);
|
void initializeDefaultsForSystemApps(int userId);
|
||||||
|
|
||||||
@@ -162,7 +160,7 @@ public interface AppStandbyInternal {
|
|||||||
|
|
||||||
void postReportExemptedSyncStart(String packageName, int userId);
|
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);
|
void dumpState(String[] args, PrintWriter pw);
|
||||||
|
|
||||||
|
|||||||
@@ -675,6 +675,14 @@ public class AppIdleHistory {
|
|||||||
return Long.parseLong(value);
|
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) {
|
public void writeAppIdleTimes(int userId) {
|
||||||
FileOutputStream fos = null;
|
FileOutputStream fos = null;
|
||||||
AtomicFile appIdleFile = new AtomicFile(getUserFile(userId));
|
AtomicFile appIdleFile = new AtomicFile(getUserFile(userId));
|
||||||
@@ -743,8 +751,18 @@ public class AppIdleHistory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump(IndentingPrintWriter idpw, int userId, List<String> pkgs) {
|
public void dumpUsers(IndentingPrintWriter idpw, int[] userIds, List<String> pkgs) {
|
||||||
idpw.println("App Standby States:");
|
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();
|
idpw.increaseIndent();
|
||||||
ArrayMap<String, AppUsageHistory> userHistory = mIdleHistory.get(userId);
|
ArrayMap<String, AppUsageHistory> userHistory = mIdleHistory.get(userId);
|
||||||
final long elapsedRealtime = SystemClock.elapsedRealtime();
|
final long elapsedRealtime = SystemClock.elapsedRealtime();
|
||||||
|
|||||||
@@ -866,7 +866,7 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reportEvent(UsageEvents.Event event, long elapsedRealtime, int userId) {
|
public void reportEvent(UsageEvents.Event event, int userId) {
|
||||||
if (!mAppIdleEnabled) return;
|
if (!mAppIdleEnabled) return;
|
||||||
final int eventType = event.getEventType();
|
final int eventType = event.getEventType();
|
||||||
if ((eventType == UsageEvents.Event.ACTIVITY_RESUMED
|
if ((eventType == UsageEvents.Event.ACTIVITY_RESUMED
|
||||||
@@ -880,6 +880,7 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
final String pkg = event.getPackageName();
|
final String pkg = event.getPackageName();
|
||||||
final List<UserHandle> linkedProfiles = getCrossProfileTargets(pkg, userId);
|
final List<UserHandle> linkedProfiles = getCrossProfileTargets(pkg, userId);
|
||||||
synchronized (mAppIdleLock) {
|
synchronized (mAppIdleLock) {
|
||||||
|
final long elapsedRealtime = mInjector.elapsedRealtime();
|
||||||
reportEventLocked(pkg, eventType, elapsedRealtime, userId);
|
reportEventLocked(pkg, eventType, elapsedRealtime, userId);
|
||||||
|
|
||||||
final int size = linkedProfiles.size();
|
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
|
@Override
|
||||||
public void flushDurationsToDisk() {
|
public void flushToDisk() {
|
||||||
// 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.
|
|
||||||
synchronized (mAppIdleLock) {
|
synchronized (mAppIdleLock) {
|
||||||
|
mAppIdleHistory.writeAppIdleTimes();
|
||||||
mAppIdleHistory.writeAppIdleDurations();
|
mAppIdleHistory.writeAppIdleDurations();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1818,9 +1812,9 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dumpUser(IndentingPrintWriter idpw, int userId, List<String> pkgs) {
|
public void dumpUsers(IndentingPrintWriter idpw, int[] userIds, List<String> pkgs) {
|
||||||
synchronized (mAppIdleLock) {
|
synchronized (mAppIdleLock) {
|
||||||
mAppIdleHistory.dump(idpw, userId, pkgs);
|
mAppIdleHistory.dumpUsers(idpw, userIds, pkgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -516,7 +516,7 @@ public class AppStandbyControllerTests {
|
|||||||
UsageEvents.Event ev = new UsageEvents.Event();
|
UsageEvents.Event ev = new UsageEvents.Event();
|
||||||
ev.mPackage = packageName;
|
ev.mPackage = packageName;
|
||||||
ev.mEventType = eventType;
|
ev.mEventType = eventType;
|
||||||
controller.reportEvent(ev, elapsedTime, USER_ID);
|
controller.reportEvent(ev, USER_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getStandbyBucket(AppStandbyController controller, String packageName) {
|
private int getStandbyBucket(AppStandbyController controller, String packageName) {
|
||||||
|
|||||||
@@ -681,6 +681,8 @@ public class UsageStatsService extends SystemService implements
|
|||||||
reportEventToAllUserId(event);
|
reportEventToAllUserId(event);
|
||||||
flushToDiskLocked();
|
flushToDiskLocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mAppStandby.flushToDisk();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -806,8 +808,6 @@ public class UsageStatsService extends SystemService implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final long elapsedRealtime = SystemClock.elapsedRealtime();
|
|
||||||
|
|
||||||
switch (event.mEventType) {
|
switch (event.mEventType) {
|
||||||
case Event.ACTIVITY_RESUMED:
|
case Event.ACTIVITY_RESUMED:
|
||||||
FrameworkStatsLog.write(
|
FrameworkStatsLog.write(
|
||||||
@@ -914,9 +914,9 @@ public class UsageStatsService extends SystemService implements
|
|||||||
return; // user was stopped or removed
|
return; // user was stopped or removed
|
||||||
}
|
}
|
||||||
service.reportEvent(event);
|
service.reportEvent(event);
|
||||||
|
|
||||||
mAppStandby.reportEvent(event, elapsedRealtime, userId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mAppStandby.reportEvent(event, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -948,6 +948,7 @@ public class UsageStatsService extends SystemService implements
|
|||||||
reportEventToAllUserId(event);
|
reportEventToAllUserId(event);
|
||||||
flushToDiskLocked();
|
flushToDiskLocked();
|
||||||
}
|
}
|
||||||
|
mAppStandby.flushToDisk();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -957,9 +958,9 @@ public class UsageStatsService extends SystemService implements
|
|||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
Slog.i(TAG, "Removing user " + userId + " and all data.");
|
Slog.i(TAG, "Removing user " + userId + " and all data.");
|
||||||
mUserState.remove(userId);
|
mUserState.remove(userId);
|
||||||
mAppStandby.onUserRemoved(userId);
|
|
||||||
mAppTimeLimit.onUserRemoved(userId);
|
mAppTimeLimit.onUserRemoved(userId);
|
||||||
}
|
}
|
||||||
|
mAppStandby.onUserRemoved(userId);
|
||||||
// Cancel any scheduled jobs for this user since the user is being removed.
|
// Cancel any scheduled jobs for this user since the user is being removed.
|
||||||
UsageStatsIdleService.cancelJob(getContext(), userId);
|
UsageStatsIdleService.cancelJob(getContext(), userId);
|
||||||
UsageStatsIdleService.cancelUpdateMappingsJob(getContext());
|
UsageStatsIdleService.cancelUpdateMappingsJob(getContext());
|
||||||
@@ -1158,10 +1159,7 @@ public class UsageStatsService extends SystemService implements
|
|||||||
if (service != null) {
|
if (service != null) {
|
||||||
service.persistActiveStats();
|
service.persistActiveStats();
|
||||||
}
|
}
|
||||||
mAppStandby.flushToDisk(userId);
|
|
||||||
}
|
}
|
||||||
mAppStandby.flushDurationsToDisk();
|
|
||||||
|
|
||||||
mHandler.removeMessages(MSG_FLUSH_TO_DISK);
|
mHandler.removeMessages(MSG_FLUSH_TO_DISK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1169,7 +1167,6 @@ public class UsageStatsService extends SystemService implements
|
|||||||
* Called by the Binder stub.
|
* Called by the Binder stub.
|
||||||
*/
|
*/
|
||||||
void dump(String[] args, PrintWriter pw) {
|
void dump(String[] args, PrintWriter pw) {
|
||||||
synchronized (mLock) {
|
|
||||||
IndentingPrintWriter idpw = new IndentingPrintWriter(pw, " ");
|
IndentingPrintWriter idpw = new IndentingPrintWriter(pw, " ");
|
||||||
|
|
||||||
boolean checkin = false;
|
boolean checkin = false;
|
||||||
@@ -1184,13 +1181,17 @@ public class UsageStatsService extends SystemService implements
|
|||||||
} else if ("-c".equals(arg)) {
|
} else if ("-c".equals(arg)) {
|
||||||
compact = true;
|
compact = true;
|
||||||
} else if ("flush".equals(arg)) {
|
} else if ("flush".equals(arg)) {
|
||||||
|
synchronized (mLock) {
|
||||||
flushToDiskLocked();
|
flushToDiskLocked();
|
||||||
|
}
|
||||||
|
mAppStandby.flushToDisk();
|
||||||
pw.println("Flushed stats to disk");
|
pw.println("Flushed stats to disk");
|
||||||
return;
|
return;
|
||||||
} else if ("is-app-standby-enabled".equals(arg)) {
|
} else if ("is-app-standby-enabled".equals(arg)) {
|
||||||
pw.println(mAppStandby.isAppIdleEnabled());
|
pw.println(mAppStandby.isAppIdleEnabled());
|
||||||
return;
|
return;
|
||||||
} else if ("apptimelimit".equals(arg)) {
|
} else if ("apptimelimit".equals(arg)) {
|
||||||
|
synchronized (mLock) {
|
||||||
if (i + 1 >= args.length) {
|
if (i + 1 >= args.length) {
|
||||||
mAppTimeLimit.dump(null, pw);
|
mAppTimeLimit.dump(null, pw);
|
||||||
} else {
|
} else {
|
||||||
@@ -1199,8 +1200,10 @@ public class UsageStatsService extends SystemService implements
|
|||||||
mAppTimeLimit.dump(remainingArgs, pw);
|
mAppTimeLimit.dump(remainingArgs, pw);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
} else if ("file".equals(arg)) {
|
} else if ("file".equals(arg)) {
|
||||||
final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
|
final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
|
||||||
|
synchronized (mLock) {
|
||||||
if (i + 1 >= args.length) {
|
if (i + 1 >= args.length) {
|
||||||
// dump everything for all users
|
// dump everything for all users
|
||||||
final int numUsers = mUserState.size();
|
final int numUsers = mUserState.size();
|
||||||
@@ -1224,8 +1227,10 @@ public class UsageStatsService extends SystemService implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
} else if ("database-info".equals(arg)) {
|
} else if ("database-info".equals(arg)) {
|
||||||
final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
|
final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
|
||||||
|
synchronized (mLock) {
|
||||||
if (i + 1 >= args.length) {
|
if (i + 1 >= args.length) {
|
||||||
// dump info for all users
|
// dump info for all users
|
||||||
final int numUsers = mUserState.size();
|
final int numUsers = mUserState.size();
|
||||||
@@ -1247,24 +1252,29 @@ public class UsageStatsService extends SystemService implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
} else if ("appstandby".equals(arg)) {
|
} else if ("appstandby".equals(arg)) {
|
||||||
mAppStandby.dumpState(args, pw);
|
mAppStandby.dumpState(args, pw);
|
||||||
return;
|
return;
|
||||||
} else if ("stats-directory".equals(arg)) {
|
} else if ("stats-directory".equals(arg)) {
|
||||||
final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
|
final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
|
||||||
|
synchronized (mLock) {
|
||||||
final int userId = parseUserIdFromArgs(args, i, ipw);
|
final int userId = parseUserIdFromArgs(args, i, ipw);
|
||||||
if (userId != UserHandle.USER_NULL) {
|
if (userId != UserHandle.USER_NULL) {
|
||||||
ipw.println(new File(Environment.getDataSystemCeDirectory(userId),
|
ipw.println(new File(Environment.getDataSystemCeDirectory(userId),
|
||||||
"usagestats").getAbsolutePath());
|
"usagestats").getAbsolutePath());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
} else if ("mappings".equals(arg)) {
|
} else if ("mappings".equals(arg)) {
|
||||||
final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
|
final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
|
||||||
final int userId = parseUserIdFromArgs(args, i, ipw);
|
final int userId = parseUserIdFromArgs(args, i, ipw);
|
||||||
|
synchronized (mLock) {
|
||||||
if (userId != UserHandle.USER_NULL) {
|
if (userId != UserHandle.USER_NULL) {
|
||||||
mUserState.get(userId).dumpMappings(ipw);
|
mUserState.get(userId).dumpMappings(ipw);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
} else if (arg != null && !arg.startsWith("-")) {
|
} else if (arg != null && !arg.startsWith("-")) {
|
||||||
// Anything else that doesn't start with '-' is a pkg to filter
|
// Anything else that doesn't start with '-' is a pkg to filter
|
||||||
pkgs.add(arg);
|
pkgs.add(arg);
|
||||||
@@ -1272,9 +1282,13 @@ public class UsageStatsService extends SystemService implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int[] userIds;
|
||||||
|
synchronized (mLock) {
|
||||||
final int userCount = mUserState.size();
|
final int userCount = mUserState.size();
|
||||||
|
userIds = new int[userCount];
|
||||||
for (int i = 0; i < userCount; i++) {
|
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.printPair("user", userId);
|
||||||
idpw.println();
|
idpw.println();
|
||||||
idpw.increaseIndent();
|
idpw.increaseIndent();
|
||||||
@@ -1286,21 +1300,22 @@ public class UsageStatsService extends SystemService implements
|
|||||||
idpw.println();
|
idpw.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mAppStandby.dumpUser(idpw, userId, pkgs);
|
|
||||||
idpw.decreaseIndent();
|
idpw.decreaseIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(pkgs)) {
|
|
||||||
pw.println();
|
|
||||||
mAppStandby.dumpState(args, pw);
|
|
||||||
}
|
|
||||||
|
|
||||||
idpw.println();
|
idpw.println();
|
||||||
idpw.printPair("Usage Source", UsageStatsManager.usageSourceToString(mUsageSource));
|
idpw.printPair("Usage Source", UsageStatsManager.usageSourceToString(mUsageSource));
|
||||||
idpw.println();
|
idpw.println();
|
||||||
|
|
||||||
mAppTimeLimit.dump(null, pw);
|
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) {
|
private int parseUserIdFromArgs(String[] args, int index, IndentingPrintWriter ipw) {
|
||||||
|
|||||||
Reference in New Issue
Block a user