private static final String TAG = "AppInfoDashboard";
// Menu identifiers
- private static final int UNINSTALL_ALL_USERS_MENU = 1;
- private static final int UNINSTALL_UPDATES = 2;
+ @VisibleForTesting static final int UNINSTALL_ALL_USERS_MENU = 1;
+ @VisibleForTesting static final int UNINSTALL_UPDATES = 2;
static final int FORCE_STOP_MENU = 3;
// Result code identifiers
menu.findItem(UNINSTALL_ALL_USERS_MENU).setVisible(shouldShowUninstallForAll(mAppEntry));
mUpdatedSysApp = (mAppEntry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
final MenuItem uninstallUpdatesItem = menu.findItem(UNINSTALL_UPDATES);
- uninstallUpdatesItem.setVisible(mUpdatedSysApp && !mAppsControlDisallowedBySystem);
+ final boolean uninstallUpdateDisabled = getContext().getResources().getBoolean(
+ R.bool.config_disable_uninstall_update);
+ uninstallUpdatesItem.setVisible(
+ mUpdatedSysApp && !mAppsControlDisallowedBySystem && !uninstallUpdateDisabled);
if (uninstallUpdatesItem.isVisible()) {
RestrictedLockUtils.setMenuItemAsDisabledByAdmin(getActivity(),
uninstallUpdatesItem, mAppsControlDisallowedAdmin);
package com.android.settings.applications.appinfo;
+import static com.android.settings.applications.appinfo.AppInfoDashboardFragment
+ .UNINSTALL_ALL_USERS_MENU;
+import static com.android.settings.applications.appinfo.AppInfoDashboardFragment.UNINSTALL_UPDATES;
+
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.os.UserManager;
+import android.view.Menu;
+import android.view.MenuItem;
import com.android.settings.SettingsActivity;
import com.android.settings.TestConfig;
}
@Test
+ public void onPrepareOptionsMenu_setUpdateMenuVisible_byDefaultForSystemApps_shouldBeTrue() {
+ Menu menu = onPrepareOptionsMenuTestsSetup();
+ mFragment.onPrepareOptionsMenu(menu);
+
+ verify(menu.findItem(UNINSTALL_UPDATES), times(1)).setVisible(true);
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void onPrepareOptionsMenu_setUpdateMenuVisible_ifDisabledByDevice_shouldBeFalse() {
+ Menu menu = onPrepareOptionsMenuTestsSetup();
+ mFragment.onPrepareOptionsMenu(menu);
+
+ verify(menu.findItem(UNINSTALL_UPDATES), times(1)).setVisible(false);
+ }
+
+ private Menu onPrepareOptionsMenuTestsSetup() {
+ // Menu mocking
+ Menu menu = mock(Menu.class);
+ final MenuItem uninstallUpdatesMenuItem = mock(MenuItem.class);
+ final MenuItem uninstallForAllMenuItem = mock(MenuItem.class);
+ when(menu.findItem(UNINSTALL_UPDATES)).thenReturn(uninstallUpdatesMenuItem);
+ when(menu.findItem(UNINSTALL_ALL_USERS_MENU)).thenReturn(uninstallForAllMenuItem);
+
+ // Setup work to prevent NPE
+ final ApplicationInfo info = new ApplicationInfo();
+ info.flags = ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
+ info.enabled = true;
+ final AppEntry appEntry = mock(AppEntry.class);
+ appEntry.info = info;
+ mFragment.setAppEntry(appEntry);
+
+ return menu;
+ }
+
+ @Test
public void launchFragment_hasNoPackageInfo_shouldFinish() {
ReflectionHelpers.setField(mFragment, "mPackageInfo", null);