Guard NPE when using search view
Test: This crash pattern was observed from monkey test, I can't reproduce it. So, just rebuild rom. Fixes: 132819226 Change-Id: I0726524dcf8e1622d64f75c17b3600a7440b58c2
This commit is contained in:
@@ -151,7 +151,8 @@ public class ManageApplications extends InstrumentedFragment
|
||||
private static final String EXTRA_HAS_ENTRIES = "hasEntries";
|
||||
private static final String EXTRA_HAS_BRIDGE = "hasBridge";
|
||||
private static final String EXTRA_FILTER_TYPE = "filterType";
|
||||
private static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view";
|
||||
@VisibleForTesting
|
||||
static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view";
|
||||
|
||||
// attributes used as keys when passing values to AppInfoDashboardFragment activity
|
||||
public static final String APP_CHG = "chg";
|
||||
@@ -505,11 +506,13 @@ public class ManageApplications extends InstrumentedFragment
|
||||
super.onSaveInstanceState(outState);
|
||||
mResetAppsHelper.onSaveInstanceState(outState);
|
||||
outState.putInt(EXTRA_SORT_ORDER, mSortOrder);
|
||||
outState.putInt(EXTRA_FILTER_TYPE, mFilter.getFilterType());
|
||||
outState.putBoolean(EXTRA_SHOW_SYSTEM, mShowSystem);
|
||||
outState.putBoolean(EXTRA_HAS_ENTRIES, mApplications.mHasReceivedLoadEntries);
|
||||
outState.putBoolean(EXTRA_HAS_BRIDGE, mApplications.mHasReceivedBridgeCallback);
|
||||
outState.putBoolean(EXTRA_EXPAND_SEARCH_VIEW, !mSearchView.isIconified());
|
||||
outState.putInt(EXTRA_FILTER_TYPE, mFilter.getFilterType());
|
||||
if(mSearchView != null) {
|
||||
outState.putBoolean(EXTRA_EXPAND_SEARCH_VIEW, !mSearchView.isIconified());
|
||||
}
|
||||
if (mApplications != null) {
|
||||
mApplications.onSaveInstanceState(outState);
|
||||
}
|
||||
|
@@ -494,6 +494,36 @@ public class ManageApplicationsTest {
|
||||
assertThat(mFragment.mRecyclerView.getPaddingTop()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSaveInstanceState_noSearchView_shouldNotSetBundleValue() {
|
||||
final Bundle bundle = new Bundle();
|
||||
ReflectionHelpers.setField(mFragment, "mResetAppsHelper", mock(ResetAppsHelper.class));
|
||||
ReflectionHelpers.setField(mFragment, "mFilter", mock(AppFilterItem.class));
|
||||
ReflectionHelpers.setField(mFragment, "mApplications",
|
||||
mock(ManageApplications.ApplicationsAdapter.class));
|
||||
|
||||
mFragment.onSaveInstanceState(bundle);
|
||||
|
||||
assertThat(bundle.containsKey(ManageApplications.EXTRA_EXPAND_SEARCH_VIEW)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSaveInstanceState_searchViewSet_shouldSetBundleValue() {
|
||||
final SearchView searchView = mock(SearchView.class);
|
||||
final Bundle bundle = new Bundle();
|
||||
ReflectionHelpers.setField(mFragment, "mResetAppsHelper", mock(ResetAppsHelper.class));
|
||||
ReflectionHelpers.setField(mFragment, "mFilter", mock(AppFilterItem.class));
|
||||
ReflectionHelpers.setField(mFragment, "mApplications",
|
||||
mock(ManageApplications.ApplicationsAdapter.class));
|
||||
ReflectionHelpers.setField(mFragment, "mSearchView", searchView);
|
||||
when(searchView.isIconified()).thenReturn(true);
|
||||
|
||||
mFragment.onSaveInstanceState(bundle);
|
||||
|
||||
assertThat(bundle.containsKey(ManageApplications.EXTRA_EXPAND_SEARCH_VIEW)).isTrue();
|
||||
assertThat(bundle.getBoolean(ManageApplications.EXTRA_EXPAND_SEARCH_VIEW)).isFalse();
|
||||
}
|
||||
|
||||
private void setUpOptionMenus() {
|
||||
when(mMenu.findItem(anyInt())).thenAnswer(invocation -> {
|
||||
final Object[] args = invocation.getArguments();
|
||||
|
Reference in New Issue
Block a user