Remove UserUsageStatsService#userUnlocked.

UsageStatsDatabase#init was being called twice every time - once when
the usage stats service was initialized and once when the user was
unlocked. However, this was unnecessary and doing duplicate work since
on user unlock, when the service is initialized, the database is also
initialized.

Bug: n/a
Test: atest UsageStatsTest
Change-Id: Ic74ba3ff8a0b68c97340ffe25b19065e1a046731
This commit is contained in:
Varun Shah
2019-11-20 17:08:16 -08:00
parent fd74d7645a
commit 8958d5d0bc
2 changed files with 2 additions and 6 deletions

View File

@@ -347,7 +347,7 @@ public class UsageStatsService extends SystemService implements
Slog.i(TAG, "Attempted to unlock stopped or removed user " + userId);
return;
}
userService.userUnlocked(System.currentTimeMillis());
// Process all the pending reported events
while (pendingEvents.peek() != null) {
reportEvent(pendingEvents.poll(), userId);
@@ -466,6 +466,7 @@ public class UsageStatsService extends SystemService implements
if (mUserUnlockedStates.get(userId)) {
try {
service.init(currentTimeMillis);
mUserState.put(userId, service);
} catch (Exception e) {
if (mUserManager.isUserUnlocked(userId)) {
throw e; // rethrow exception - user is unlocked
@@ -476,7 +477,6 @@ public class UsageStatsService extends SystemService implements
}
}
}
mUserState.put(userId, service);
}
return service;
}

View File

@@ -165,10 +165,6 @@ class UserUsageStatsService {
}
}
void userUnlocked(long currentTimeMillis) {
init(currentTimeMillis);
}
void userStopped() {
// Flush events to disk immediately to guarantee persistence.
persistActiveStats();