Merge "Add checks before casting entry.extraInfo."
This commit is contained in:
committed by
Android (Google) Code Review
commit
6a74a151fd
@@ -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)));
|
||||
|
@@ -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[]{});
|
||||
|
Reference in New Issue
Block a user