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

Commit b2556019 authored by Yanting Yang's avatar Yanting Yang Committed by Automerger Merge Worker
Browse files

Merge "Fix NPE of ApplicationsState" into udc-dev am: fc9a5df1

parents 196a7a7d fc9a5df1
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -734,7 +734,10 @@ public class ApplicationsState {

    private AppEntry getEntryLocked(ApplicationInfo info) {
        int userId = UserHandle.getUserId(info.uid);
        AppEntry entry = mEntriesMap.get(userId).get(info.packageName);
        AppEntry entry = null;
        if (mEntriesMap.contains(userId)) {
            entry = mEntriesMap.get(userId).get(info.packageName);
        }
        if (DEBUG) {
            Log.i(TAG, "Looking up entry of pkg " + info.packageName + ": " + entry);
        }
+18 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ import org.robolectric.util.ReflectionHelpers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

@@ -801,4 +802,21 @@ public class ApplicationsStateRoboTest {
        assertThat(nonPrimaryUserApp1.shouldShowInPersonalTab(um, appInfo1.uid)).isTrue();
        assertThat(nonPrimaryUserApp2.shouldShowInPersonalTab(um, appInfo2.uid)).isFalse();
    }

    @Test
    public void getEntry_validUserId_shouldReturnEntry() {
        mApplicationsState.mEntriesMap.put(/* userId= */ 0, new HashMap<>());
        addApp(PKG_1, /* id= */ 1);

        assertThat(mApplicationsState.getEntry(PKG_1, /* userId= */ 0).info.packageName)
                .isEqualTo(PKG_1);
    }

    @Test
    public void getEntry_invalidUserId_shouldReturnNull() {
        mApplicationsState.mEntriesMap.put(/* userId= */ 0, new HashMap<>());
        addApp(PKG_1, /* id= */ 1);

        assertThat(mApplicationsState.getEntry(PKG_1, /* userId= */ -1)).isNull();
    }
}