Do not retrive app detail if the fragment is exiting.

The exit flag can be set by a variety of things, such as when package is
removed, or package is invalid (hidden mainline module). Loading such
packages changes the internal state of ApplicationsState class (an app
singleton), which leads to inconsistencies later.

Fixes: 130166465
Test: robotest
Change-Id: Ib09240cb694fa16692914a7aa9ce354869615c2d
This commit is contained in:
Fan Zhang
2019-04-08 12:29:27 -07:00
parent d8b316f816
commit 276edc8d86
2 changed files with 11 additions and 3 deletions

View File

@@ -112,7 +112,8 @@ public class AppInfoDashboardFragment extends DashboardFragment
private UserManager mUserManager; private UserManager mUserManager;
private PackageManager mPm; private PackageManager mPm;
private boolean mFinishing; @VisibleForTesting
boolean mFinishing;
private boolean mListeningToPackageRemove; private boolean mListeningToPackageRemove;
@@ -544,7 +545,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
@VisibleForTesting @VisibleForTesting
void retrieveAppEntry() { void retrieveAppEntry() {
final Activity activity = getActivity(); final Activity activity = getActivity();
if (activity == null) { if (activity == null || mFinishing) {
return; return;
} }
if (mState == null) { if (mState == null) {
@@ -650,7 +651,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
|| TextUtils.equals(mAppEntry.info.packageName, packageName)) { || TextUtils.equals(mAppEntry.info.packageName, packageName)) {
onPackageRemoved(); onPackageRemoved();
} else if (mAppEntry.info.isResourceOverlay() } else if (mAppEntry.info.isResourceOverlay()
&& TextUtils.equals(mPackageInfo.overlayTarget, packageName)) { && TextUtils.equals(mPackageInfo.overlayTarget, packageName)) {
refreshUi(); refreshUi();
} }
} }

View File

@@ -281,6 +281,13 @@ public final class AppInfoDashboardFragmentTest {
assertThat(mFragment.createPreferenceControllers(mShadowContext)).isNull(); assertThat(mFragment.createPreferenceControllers(mShadowContext)).isNull();
} }
@Test
public void getPreferenceControllers_exiting_shouldReturnNull() {
mFragment.mFinishing = true;
assertThat(mFragment.createPreferenceControllers(mShadowContext)).isNull();
}
@Test @Test
public void getNumberOfUserWithPackageInstalled_twoUsersInstalled_shouldReturnTwo() public void getNumberOfUserWithPackageInstalled_twoUsersInstalled_shouldReturnTwo()
throws PackageManager.NameNotFoundException { throws PackageManager.NameNotFoundException {