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

Commit 6a74a151 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add checks before casting entry.extraInfo."

parents 7686eb4f 56966ce8
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[]{});