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

Commit 18fecf78 authored by Danning Chen's avatar Danning Chen
Browse files

Fix the bug that queries UsageStatsService for locked users

In addition to the bug fix, this also changes the user lifecycle callbacks People Service is using:

1) onUserUnlocking() -> onUserUnlocked()
2) onUserStopped() -> onUserStopping()

The user lifecycle callback changes are based on a recent callback API
change in ag/10396717. This change will make the service run safer: it
avoids performing queries on locked users.

Change-Id: I4d0ebdb80f2181b5eb5a636d345c53a01c7df210
Test: Manual test
Test: atest com.android.server.people.data.DataManagerTest
Bug: 150882079
parent b7050a36
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -72,13 +72,13 @@ public class PeopleService extends SystemService {
    }

    @Override
    public void onUserUnlocking(@NonNull TargetUser targetUser) {
        mDataManager.onUserUnlocked(targetUser.getUserIdentifier());
    public void onUserUnlocked(@NonNull TargetUser user) {
        mDataManager.onUserUnlocked(user.getUserIdentifier());
    }

    @Override
    public void onUserStopping(@NonNull TargetUser targetUser) {
        mDataManager.onUserStopped(targetUser.getUserIdentifier());
    public void onUserStopping(@NonNull TargetUser user) {
        mDataManager.onUserStopping(user.getUserIdentifier());
    }

    @VisibleForTesting
+3 −3
Original line number Diff line number Diff line
@@ -198,13 +198,13 @@ public class DataManager {
        DataMaintenanceService.scheduleJob(mContext, userId);
    }

    /** This method is called when a user is stopped. */
    public void onUserStopped(int userId) {
    /** This method is called when a user is stopping. */
    public void onUserStopping(int userId) {
        if (mUserDataArray.indexOfKey(userId) >= 0) {
            mUserDataArray.get(userId).setUserStopped();
        }
        if (mUsageStatsQueryFutures.indexOfKey(userId) >= 0) {
            mUsageStatsQueryFutures.valueAt(userId).cancel(true);
            mUsageStatsQueryFutures.get(userId).cancel(true);
        }
        if (mBroadcastReceivers.indexOfKey(userId) >= 0) {
            mContext.unregisterReceiver(mBroadcastReceivers.get(userId));
+1 −1
Original line number Diff line number Diff line
@@ -269,7 +269,7 @@ public final class DataManagerTest {
        assertEquals(1, conversations.size());
        assertEquals("sc_1", conversations.get(0).getShortcutId());

        mDataManager.onUserStopped(USER_ID_PRIMARY);
        mDataManager.onUserStopping(USER_ID_PRIMARY);
        conversations = getConversationsInPrimary();
        assertTrue(conversations.isEmpty());
    }