Merge "Move AppStandbyController calls out of UsageStats lock" into rvc-dev

This commit is contained in:
Michael Wachenschwanz
2020-06-20 06:07:00 +00:00
committed by Android (Google) Code Review
5 changed files with 94 additions and 69 deletions

View File

@@ -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);

View File

@@ -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();

View File

@@ -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);
}
}