final MenuItem uninstallUpdatesItem = menu.findItem(UNINSTALL_UPDATES);
final boolean uninstallUpdateDisabled = getContext().getResources().getBoolean(
R.bool.config_disable_uninstall_update);
- uninstallUpdatesItem.setVisible(
- mUpdatedSysApp && !mAppsControlDisallowedBySystem && !uninstallUpdateDisabled);
+ uninstallUpdatesItem.setVisible(mUserManager.isAdminUser()
+ && mUpdatedSysApp
+ && !mAppsControlDisallowedBySystem
+ && !uninstallUpdateDisabled);
if (uninstallUpdatesItem.isVisible()) {
RestrictedLockUtils.setMenuItemAsDisabledByAdmin(getActivity(),
uninstallUpdatesItem, mAppsControlDisallowedAdmin);
doReturn(mActivity).when(mFragment).getActivity();
doReturn(mShadowContext).when(mFragment).getContext();
doReturn(mPackageManager).when(mActivity).getPackageManager();
+ when(mUserManager.isAdminUser()).thenReturn(true);
+ ReflectionHelpers.setField(mFragment, "mUserManager", mUserManager);
// Default to not considering any apps to be instant (individual tests can override this).
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
(InstantAppDataProvider) (i -> false));
when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
when(mUserManager.getUsers().size()).thenReturn(2);
ReflectionHelpers.setField(mFragment, "mDpm", mDevicePolicyManager);
- ReflectionHelpers.setField(mFragment, "mUserManager", mUserManager);
+
final ApplicationInfo info = new ApplicationInfo();
info.enabled = true;
final AppEntry appEntry = mock(AppEntry.class);
when(mDevicePolicyManager.packageHasActiveAdmins(nullable(String.class))).thenReturn(false);
when(mUserManager.getUsers().size()).thenReturn(2);
ReflectionHelpers.setField(mFragment, "mDpm", mDevicePolicyManager);
- ReflectionHelpers.setField(mFragment, "mUserManager", mUserManager);
final ApplicationInfo info = new ApplicationInfo();
info.flags = ApplicationInfo.FLAG_INSTALLED;
info.enabled = true;
final PackageInfo packageInfo = mock(PackageInfo.class);
ReflectionHelpers.setField(mFragment, "mDpm", mDevicePolicyManager);
- ReflectionHelpers.setField(mFragment, "mUserManager", mUserManager);
ReflectionHelpers.setField(mFragment, "mPackageInfo", packageInfo);
assertThat(mFragment.shouldShowUninstallForAll(appEntry)).isFalse();
userInfos.add(new UserInfo(userID1, "User1", UserInfo.FLAG_PRIMARY));
userInfos.add(new UserInfo(userID2, "yue", UserInfo.FLAG_GUEST));
when(mUserManager.getUsers(true)).thenReturn(userInfos);
- ReflectionHelpers.setField(mFragment, "mUserManager", mUserManager);
final ApplicationInfo appInfo = new ApplicationInfo();
appInfo.flags = ApplicationInfo.FLAG_INSTALLED;
when(mPackageManager.getApplicationInfoAsUser(
userInfos.add(new UserInfo(userID1, "User1", UserInfo.FLAG_PRIMARY));
userInfos.add(new UserInfo(userID2, "yue", UserInfo.FLAG_GUEST));
when(mUserManager.getUsers(true)).thenReturn(userInfos);
- ReflectionHelpers.setField(mFragment, "mUserManager", mUserManager);
final ApplicationInfo appInfo = new ApplicationInfo();
appInfo.flags = ApplicationInfo.FLAG_INSTALLED;
when(mPackageManager.getApplicationInfoAsUser(