package com.android.settings.applications;
-import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
-
import android.Manifest.permission;
import android.app.Activity;
import android.app.ActivityManager;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.IWebViewUpdateService;
import android.widget.Button;
import java.util.HashSet;
import java.util.List;
+import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+
/**
* Activity to display application information from Settings. This activity presents
* extended information associated with a package like code, data, total size, permissions
super.onCreate(icicle);
final Activity activity = getActivity();
+ if (!ensurePackageInfoAvailable(activity)) {
+ return;
+ }
+
setHasOptionsMenu(true);
addPreferencesFromResource(R.xml.installed_app_details_ia);
addDynamicPrefs();
refreshUi();
}
+ /**
+ * Ensures the {@link PackageInfo} is available to proceed. If it's not available, the fragment
+ * will finish.
+ *
+ * @return true if packageInfo is available.
+ */
+ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ boolean ensurePackageInfoAvailable(Activity activity) {
+ if (mPackageInfo == null) {
+ mFinishing = true;
+ Log.w(LOG_TAG, "Package info not available. Is this package already uninstalled?");
+ activity.finishAndRemoveTask();
+ return false;
+ }
+ return true;
+ }
+
private void prepareUninstallAndStop() {
mForceStopButton = (Button) mFooter.findViewById(R.id.right_button);
mForceStopButton.setText(R.string.force_stop);
package com.android.settings.applications;
-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;
+import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
+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.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public final class InstalledAppDetailsTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private UserManager mUserManager;
@Mock
+ private Activity mActivity;
+ @Mock
private DevicePolicyManager mDevicePolicyManager;
+ private InstalledAppDetails mAppDetail;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mAppDetail = new InstalledAppDetails();
}
@Test
public void getInstallationStatus_notInstalled_shouldReturnUninstalled() {
- final InstalledAppDetails mAppDetail = new InstalledAppDetails();
assertThat(mAppDetail.getInstallationStatus(new ApplicationInfo()))
- .isEqualTo(R.string.not_installed);
+ .isEqualTo(R.string.not_installed);
}
@Test
public void getInstallationStatus_enabled_shouldReturnInstalled() {
- final InstalledAppDetails mAppDetail = new InstalledAppDetails();
final ApplicationInfo info = new ApplicationInfo();
info.flags = ApplicationInfo.FLAG_INSTALLED;
info.enabled = true;
@Test
public void getInstallationStatus_disabled_shouldReturnDisabled() {
- final InstalledAppDetails mAppDetail = new InstalledAppDetails();
final ApplicationInfo info = new ApplicationInfo();
info.flags = ApplicationInfo.FLAG_INSTALLED;
info.enabled = false;
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();
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();
assertThat(InstalledAppDetails.getStorageSummary(context, stats, false))
.isEqualTo("1.00B used in Internal storage");
+ }
+
+ @Test
+ public void launchFragment_hasNoPackageInfo_shouldFinish() {
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", null);
+
+ assertThat(mAppDetail.ensurePackageInfoAvailable(mActivity)).isFalse();
+ verify(mActivity).finishAndRemoveTask();
+ }
+
+ @Test
+ public void launchFragment_hasPackageInfo_shouldReturnTrue() {
+ final PackageInfo packageInfo = mock(PackageInfo.class);
+ ReflectionHelpers.setField(mAppDetail, "mPackageInfo", packageInfo);
+ assertThat(mAppDetail.ensurePackageInfoAvailable(mActivity)).isTrue();
+ verify(mActivity, never()).finishAndRemoveTask();
}
}