Fixes crash from selecting uninstalled app info from recents.
- when the package is uninstalled, also remove it from the recent tasks - move retrieveAppEntry() from onCreate() to getPreferenceControllers() so that if the package info is invalid, do not create any controllers, as the activity will be finished anyway. Change-Id: Ibbfa16e3d1f941a0a200e78ec73a06ca8511f82b Fixes: 72656345 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -162,13 +162,12 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
mUserManager = (UserManager) activity.getSystemService(Context.USER_SERVICE);
|
||||
mPm = activity.getPackageManager();
|
||||
|
||||
retrieveAppEntry();
|
||||
startListeningToPackageRemove();
|
||||
|
||||
if (!ensurePackageInfoAvailable(activity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
startListeningToPackageRemove();
|
||||
|
||||
mForceStopOptionsMenuController =
|
||||
new ForceStopOptionsMenuController(activity, this /* parent */, mDpm,
|
||||
mMetricsFeatureProvider, getLifecycle());
|
||||
@@ -205,6 +204,10 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||
retrieveAppEntry();
|
||||
if (mPackageInfo == null) {
|
||||
return null;
|
||||
}
|
||||
final String packageName = getPackageName();
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
final Lifecycle lifecycle = getLifecycle();
|
||||
@@ -262,9 +265,6 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
}
|
||||
|
||||
ApplicationsState.AppEntry getAppEntry() {
|
||||
if (mAppEntry == null) {
|
||||
retrieveAppEntry();
|
||||
}
|
||||
return mAppEntry;
|
||||
}
|
||||
|
||||
@@ -273,9 +273,6 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
}
|
||||
|
||||
PackageInfo getPackageInfo() {
|
||||
if (mAppEntry == null) {
|
||||
retrieveAppEntry();
|
||||
}
|
||||
return mPackageInfo;
|
||||
}
|
||||
|
||||
@@ -361,7 +358,12 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER)
|
||||
.execute((Object) null);
|
||||
}
|
||||
// continue with following operations
|
||||
if (!refreshUi()) {
|
||||
onPackageRemoved();
|
||||
} else {
|
||||
startListeningToPackageRemove();
|
||||
}
|
||||
break;
|
||||
case REQUEST_REMOVE_DEVICE_ADMIN:
|
||||
if (!refreshUi()) {
|
||||
setIntentAndFinish(true, true);
|
||||
@@ -622,7 +624,8 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
||||
return mPackageName;
|
||||
}
|
||||
|
||||
private void retrieveAppEntry() {
|
||||
@VisibleForTesting
|
||||
void retrieveAppEntry() {
|
||||
final Activity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.applications.appinfo;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -190,6 +191,22 @@ public final class AppInfoDashboardFragmentTest {
|
||||
verify(mActivity).invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onActivityResult_packageUninstalled_shouldFinishAndRemoveTask() {
|
||||
doReturn(false).when(mFragment).refreshUi();
|
||||
|
||||
mFragment.onActivityResult(mFragment.REQUEST_UNINSTALL, 0, mock(Intent.class));
|
||||
|
||||
verify(mActivity).finishAndRemoveTask();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceControllers_noPackageInfo_shouldReturnNull() {
|
||||
doNothing().when(mFragment).retrieveAppEntry();
|
||||
|
||||
assertThat(mFragment.getPreferenceControllers(mShadowContext)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNumberOfUserWithPackageInstalled_twoUsersInstalled_shouldReturnTwo()
|
||||
throws PackageManager.NameNotFoundException{
|
||||
|
Reference in New Issue
Block a user