Fix the NPE when reading the call log or SMS if a device has multiple user profiles

Change-Id: Iec6485653367f2f005c2b7e17f23ab611e39e13b
Bug: 148918224
Test: atest com.android.server.people.data.DataManagerTest
This commit is contained in:
Danning Chen
2020-02-05 11:52:46 -08:00
parent 098584d234
commit b3f852127e
2 changed files with 6 additions and 1 deletions

View File

@@ -299,7 +299,8 @@ public class DataManager {
private void forAllUnlockedUsers(Consumer<UserData> consumer) {
for (int i = 0; i < mUserDataArray.size(); i++) {
UserData userData = mUserDataArray.get(i);
int userId = mUserDataArray.keyAt(i);
UserData userData = mUserDataArray.get(userId);
if (userData.isUnlocked()) {
consumer.accept(userData);
}

View File

@@ -263,6 +263,7 @@ public final class DataManagerTest {
@Test
public void testContactsChanged() {
mDataManager.onUserUnlocked(USER_ID_PRIMARY);
mDataManager.onUserUnlocked(USER_ID_SECONDARY);
ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID,
buildPerson());
@@ -289,6 +290,7 @@ public final class DataManagerTest {
@Test
public void testNotificationListener() {
mDataManager.onUserUnlocked(USER_ID_PRIMARY);
mDataManager.onUserUnlocked(USER_ID_SECONDARY);
ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID,
buildPerson());
@@ -341,6 +343,7 @@ public final class DataManagerTest {
@Test
public void testCallLogContentObserver() {
mDataManager.onUserUnlocked(USER_ID_PRIMARY);
mDataManager.onUserUnlocked(USER_ID_SECONDARY);
ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID,
buildPerson());
@@ -368,6 +371,7 @@ public final class DataManagerTest {
@Test
public void testMmsSmsContentObserver() {
mDataManager.onUserUnlocked(USER_ID_PRIMARY);
mDataManager.onUserUnlocked(USER_ID_SECONDARY);
ShortcutInfo shortcut = buildShortcutInfo(TEST_PKG_NAME, USER_ID_PRIMARY, TEST_SHORTCUT_ID,
buildPerson());