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

Commit 56966ce8 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Add checks before casting entry.extraInfo.

Test: make, flash
Change-Id: I1a9d6a51b1f236e711fdb49d9c2f795e7023cfce
Fixes: 113309404
parent d5ddae8f
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -1335,7 +1335,8 @@ public class ManageApplications extends InstrumentedFragment
        private void updateSummary(ApplicationViewHolder holder, AppEntry entry) {
            switch (mManageApplications.mListType) {
                case LIST_TYPE_NOTIFICATION:
                    if (entry.extraInfo != null) {
                    if (entry.extraInfo != null
                            && entry.extraInfo instanceof NotificationsSentState) {
                        holder.setSummary(AppStateNotificationBridge.getSummary(mContext,
                                (NotificationsSentState) entry.extraInfo,
                                (mLastSortMode == R.id.sort_order_recent_notification)));
@@ -1384,7 +1385,8 @@ public class ManageApplications extends InstrumentedFragment
                                    .getSwitchOnClickListener(entry),
                            AppStateNotificationBridge.enableSwitch(entry),
                            AppStateNotificationBridge.checkSwitch(entry));
                    if (entry.extraInfo != null) {
                    if (entry.extraInfo != null
                            && entry.extraInfo instanceof NotificationsSentState) {
                        holder.setSummary(AppStateNotificationBridge.getSummary(mContext,
                                (NotificationsSentState) entry.extraInfo,
                                (mLastSortMode == R.id.sort_order_recent_notification)));
+22 −0
Original line number Diff line number Diff line
@@ -281,6 +281,28 @@ public class ManageApplicationsTest {
        verify(adapter).notifyDataSetChanged();
    }

    @Test
    public void applicationsAdapter_onBindViewHolder_notifications_wrongExtraInfo() {
        when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
        ReflectionHelpers.setField(mFragment, "mUserManager", mUserManager);
        mFragment.mListType = LIST_TYPE_NOTIFICATION;
        ApplicationViewHolder holder = mock(ApplicationViewHolder.class);
        ReflectionHelpers.setField(holder, "itemView", mock(View.class));
        ManageApplications.ApplicationsAdapter adapter =
                new ManageApplications.ApplicationsAdapter(mState,
                        mFragment, mock(AppFilterItem.class),
                        mock(Bundle.class));
        final ArrayList<ApplicationsState.AppEntry> appList = new ArrayList<>();
        final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
        appEntry.info = mock(ApplicationInfo.class);
        appEntry.extraInfo = mock(AppFilterItem.class);
        appList.add(appEntry);
        ReflectionHelpers.setField(adapter, "mEntries", appList);

        adapter.onBindViewHolder(holder, 0);
        // no crash? yay!
    }

    @Test
    public void applicationsAdapter_onBindViewHolder_updateSwitch_notifications() {
        when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});