commit | 8f7edfa108c58e8eb3101e238e349ee9fcdb06a3 | [log] [tgz] |
---|---|---|
author | Doris Ling <dling@google.com> | Thu Feb 22 10:39:13 2018 -0800 |
committer | Doris Ling <dling@google.com> | Thu Feb 22 10:39:13 2018 -0800 |
tree | 941ca9ec847acf270f555b775fd2ff3e224dd15a | |
parent | 38bfe2e43db721da6125db2f2ce9b8532e8d943f [diff] |
Fix NPE in InstantAppButtonsPreferenceController - check for valid install options menu before trying to disable it. Change-Id: Ibe644a506094e66b0f657092a25557f5096d4942 Fixes: 73767192 Test: make RunSettingsRoboTests
diff --git a/src/com/android/settings/applications/appinfo/InstantAppButtonsPreferenceController.java b/src/com/android/settings/applications/appinfo/InstantAppButtonsPreferenceController.java index dcae5ef..df64d76 100644 --- a/src/com/android/settings/applications/appinfo/InstantAppButtonsPreferenceController.java +++ b/src/com/android/settings/applications/appinfo/InstantAppButtonsPreferenceController.java
@@ -112,9 +112,10 @@ @Override public void onPrepareOptionsMenu(Menu menu) { mInstallMenu = menu.findItem(AppInfoDashboardFragment.INSTALL_INSTANT_APP_MENU); - final Intent appStoreIntent = AppStoreUtil.getAppStoreLink(mContext, mPackageName); - if (appStoreIntent == null) { - mInstallMenu.setEnabled(false); + if (mInstallMenu != null) { + if (AppStoreUtil.getAppStoreLink(mContext, mPackageName) == null) { + mInstallMenu.setEnabled(false); + } } }
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/InstantAppButtonsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/InstantAppButtonsPreferenceControllerTest.java index 935389c..24823fe 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/InstantAppButtonsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/InstantAppButtonsPreferenceControllerTest.java
@@ -180,6 +180,15 @@ } @Test + public void onPrepareOptionsMenu_installMenuNotFound_shoulNotCrash() { + final Menu menu = mock(Menu.class); + + mController.onPrepareOptionsMenu(menu); + + // no crash + } + + @Test public void onOptionsItemSelected_shouldOpenAppStore() { final ResolveInfo resolveInfo = mock(ResolveInfo.class); final ActivityInfo activityInfo = mock(ActivityInfo.class);