Merge "Show uninstall for all users option menu in app info."
This commit is contained in:
committed by
Android (Google) Code Review
commit
a9ee4e8649
@@ -490,23 +490,7 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
if (mFinishing) {
|
if (mFinishing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean showIt = true;
|
menu.findItem(UNINSTALL_ALL_USERS_MENU).setVisible(shouldShowUninstallForAll(mAppEntry));
|
||||||
if (mUpdatedSysApp) {
|
|
||||||
showIt = false;
|
|
||||||
} else if (mAppEntry == null) {
|
|
||||||
showIt = false;
|
|
||||||
} else if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
|
||||||
showIt = false;
|
|
||||||
} else if (mPackageInfo == null || mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
|
|
||||||
showIt = false;
|
|
||||||
} else if (UserHandle.myUserId() != 0) {
|
|
||||||
showIt = false;
|
|
||||||
} else if (mUserManager.getUsers().size() < 2) {
|
|
||||||
showIt = false;
|
|
||||||
} else if (PackageUtil.countPackageInUsers(mPm, mUserManager, mPackageName) < 2) {
|
|
||||||
showIt = false;
|
|
||||||
}
|
|
||||||
menu.findItem(UNINSTALL_ALL_USERS_MENU).setVisible(showIt);
|
|
||||||
mUpdatedSysApp = (mAppEntry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
|
mUpdatedSysApp = (mAppEntry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
|
||||||
MenuItem uninstallUpdatesItem = menu.findItem(UNINSTALL_UPDATES);
|
MenuItem uninstallUpdatesItem = menu.findItem(UNINSTALL_UPDATES);
|
||||||
uninstallUpdatesItem.setVisible(mUpdatedSysApp && !mAppsControlDisallowedBySystem);
|
uninstallUpdatesItem.setVisible(mUpdatedSysApp && !mAppsControlDisallowedBySystem);
|
||||||
@@ -572,6 +556,28 @@ public class InstalledAppDetails extends AppInfoBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean shouldShowUninstallForAll(ApplicationsState.AppEntry appEntry) {
|
||||||
|
boolean showIt = true;
|
||||||
|
if (mUpdatedSysApp) {
|
||||||
|
showIt = false;
|
||||||
|
} else if (appEntry == null) {
|
||||||
|
showIt = false;
|
||||||
|
} else if ((appEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
||||||
|
showIt = false;
|
||||||
|
} else if (mPackageInfo == null || mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
|
||||||
|
showIt = false;
|
||||||
|
} else if (UserHandle.myUserId() != 0) {
|
||||||
|
showIt = false;
|
||||||
|
} else if (mUserManager.getUsers().size() < 2) {
|
||||||
|
showIt = false;
|
||||||
|
} else if (PackageUtil.countPackageInUsers(mPm, mUserManager, mPackageName) < 2
|
||||||
|
&& (appEntry.info.flags & ApplicationInfo.FLAG_INSTALLED) != 0) {
|
||||||
|
showIt = false;
|
||||||
|
}
|
||||||
|
return showIt;
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
int getInstallationStatus(ApplicationInfo info) {
|
int getInstallationStatus(ApplicationInfo info) {
|
||||||
if ((info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
|
if ((info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
|
||||||
|
@@ -16,22 +16,44 @@
|
|||||||
|
|
||||||
package com.android.settings.applications;
|
package com.android.settings.applications;
|
||||||
|
|
||||||
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Answers;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Matchers.anyString;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public final class InstalledAppDetailsTest {
|
public final class InstalledAppDetailsTest {
|
||||||
|
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private UserManager mUserManager;
|
||||||
|
@Mock
|
||||||
|
private DevicePolicyManager mDevicePolicyManager;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getInstallationStatus_notInstalled_shouldReturnUninstalled() {
|
public void getInstallationStatus_notInstalled_shouldReturnUninstalled() {
|
||||||
final InstalledAppDetails mAppDetail = new InstalledAppDetails();
|
final InstalledAppDetails mAppDetail = new InstalledAppDetails();
|
||||||
@@ -60,4 +82,39 @@ public final class InstalledAppDetailsTest {
|
|||||||
assertThat(mAppDetail.getInstallationStatus(info)).isEqualTo(R.string.disabled);
|
assertThat(mAppDetail.getInstallationStatus(info)).isEqualTo(R.string.disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldShowUninstallForAll_installForOneOtherUserOnly_shouldReturnTrue() {
|
||||||
|
when(mDevicePolicyManager.packageHasActiveAdmins(anyString())).thenReturn(false);
|
||||||
|
when(mUserManager.getUsers().size()).thenReturn(2);
|
||||||
|
final InstalledAppDetails mAppDetail = new InstalledAppDetails();
|
||||||
|
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
|
||||||
|
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
||||||
|
final ApplicationInfo info = new ApplicationInfo();
|
||||||
|
info.enabled = true;
|
||||||
|
final AppEntry appEntry = mock(AppEntry.class);
|
||||||
|
appEntry.info = info;
|
||||||
|
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||||
|
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||||
|
|
||||||
|
assertThat(mAppDetail.shouldShowUninstallForAll(appEntry)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldShowUninstallForAll_installForSelfOnly_shouldReturnFalse() {
|
||||||
|
when(mDevicePolicyManager.packageHasActiveAdmins(anyString())).thenReturn(false);
|
||||||
|
when(mUserManager.getUsers().size()).thenReturn(2);
|
||||||
|
final InstalledAppDetails mAppDetail = new InstalledAppDetails();
|
||||||
|
ReflectionHelpers.setField(mAppDetail, "mDpm", mDevicePolicyManager);
|
||||||
|
ReflectionHelpers.setField(mAppDetail, "mUserManager", mUserManager);
|
||||||
|
final ApplicationInfo info = new ApplicationInfo();
|
||||||
|
info.flags = ApplicationInfo.FLAG_INSTALLED;
|
||||||
|
info.enabled = true;
|
||||||
|
final AppEntry appEntry = mock(AppEntry.class);
|
||||||
|
appEntry.info = info;
|
||||||
|
final PackageInfo packageInfo = mock(PackageInfo.class);
|
||||||
|
ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
|
||||||
|
|
||||||
|
assertThat(mAppDetail.shouldShowUninstallForAll(appEntry)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user