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

Commit 97da5187 authored by Doris Ling's avatar Doris Ling
Browse files

Fix null pointer exception when logging suggestions.

In monkey test, the suggestions list can become null. So, add check
for valid suggestions list before trying to iterate through the
suggestions.

Fixes: 64757618
Test: make RunSettingsRoboTests
Change-Id: Ib670808a4f222187b9cd53d7d939e71b5ce8dbae
parent 595627c6
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -329,7 +329,11 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
    }

    private void logSuggestions() {
        for (Tile suggestion : mDashboardData.getSuggestions()) {
        final List<Tile> suggestions = mDashboardData.getSuggestions();
        if (suggestions == null) {
            return;
        }
        for (Tile suggestion : suggestions) {
            final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
                mContext, suggestion);
            if (!mSuggestionsShownLogged.contains(suggestionId)) {
+15 −0
Original line number Diff line number Diff line
@@ -318,6 +318,21 @@ public class DashboardAdapterTest {
        assertThat(mActionCategoryCaptor.getAllValues().toArray()).isEqualTo(expectedActions);
    }

    @Test
    public void testSuggestionsLogs_nullSuggestionsList_shouldNotCrash() {
        setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3", "pkg4", "pkg5"));
        mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);

        // set suggestions to null
        final DashboardData prevData = mDashboardAdapter.mDashboardData;
        mDashboardAdapter.mDashboardData = new DashboardData.Builder(prevData)
                .setSuggestions(null)
                .build();

        mSuggestionHolder.itemView.callOnClick();
        // no crash
    }

    @Test
    public void testSuggestionDismissed_notOnlySuggestion_updateSuggestionOnly() {
        final DashboardAdapter adapter =