Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8958d5d0 authored by Varun Shah's avatar Varun Shah
Browse files

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
parent fd74d764
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -347,7 +347,7 @@ public class UsageStatsService extends SystemService implements
                Slog.i(TAG, "Attempted to unlock stopped or removed user " + userId);
                Slog.i(TAG, "Attempted to unlock stopped or removed user " + userId);
                return;
                return;
            }
            }
            userService.userUnlocked(System.currentTimeMillis());

            // Process all the pending reported events
            // Process all the pending reported events
            while (pendingEvents.peek() != null) {
            while (pendingEvents.peek() != null) {
                reportEvent(pendingEvents.poll(), userId);
                reportEvent(pendingEvents.poll(), userId);
@@ -466,6 +466,7 @@ public class UsageStatsService extends SystemService implements
            if (mUserUnlockedStates.get(userId)) {
            if (mUserUnlockedStates.get(userId)) {
                try {
                try {
                    service.init(currentTimeMillis);
                    service.init(currentTimeMillis);
                    mUserState.put(userId, service);
                } catch (Exception e) {
                } catch (Exception e) {
                    if (mUserManager.isUserUnlocked(userId)) {
                    if (mUserManager.isUserUnlocked(userId)) {
                        throw e; // rethrow exception - user is unlocked
                        throw e; // rethrow exception - user is unlocked
@@ -476,7 +477,6 @@ public class UsageStatsService extends SystemService implements
                    }
                    }
                }
                }
            }
            }
            mUserState.put(userId, service);
        }
        }
        return service;
        return service;
    }
    }
+0 −4
Original line number Original line Diff line number Diff line
@@ -165,10 +165,6 @@ class UserUsageStatsService {
        }
        }
    }
    }


    void userUnlocked(long currentTimeMillis) {
        init(currentTimeMillis);
    }

    void userStopped() {
    void userStopped() {
        // Flush events to disk immediately to guarantee persistence.
        // Flush events to disk immediately to guarantee persistence.
        persistActiveStats();
        persistActiveStats();