Fix ANR in installed app details.

InstalledAppDetails tries to refreshUi whenever something about a
package changes. It does not need to refresh when the changing package
is different from what's being displayed.

Change-Id: Ib45289c39ee402cf8974bf52c881f44d225b8be5
Fix: 37424866
Test: make RunSettingsRoboTests
This commit is contained in:
Fan Zhang
2017-04-24 16:57:35 -07:00
parent 0cdade8a78
commit f6126e7a00
2 changed files with 25 additions and 1 deletions

View File

@@ -18,7 +18,6 @@ package com.android.settings.applications;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
@@ -69,6 +68,9 @@ import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public final class InstalledAppDetailsTest {
private static final String PACKAGE_NAME = "test_package_name";
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
@@ -181,6 +183,24 @@ public final class InstalledAppDetailsTest {
verify(mActivity, never()).finishAndRemoveTask();
}
@Test
public void packageSizeChange_isOtherPackage_shouldNotRefreshUi() {
ReflectionHelpers.setField(mAppDetail, "mPackageName", PACKAGE_NAME);
mAppDetail.onPackageSizeChanged("Not_" + PACKAGE_NAME);
verify(mAppDetail, never()).refreshUi();
}
@Test
public void packageSizeChange_isOwnPackage_shouldRefreshUi() {
doReturn(Boolean.TRUE).when(mAppDetail).refreshUi();
ReflectionHelpers.setField(mAppDetail, "mPackageName", PACKAGE_NAME);
mAppDetail.onPackageSizeChanged(PACKAGE_NAME);
verify(mAppDetail).refreshUi();
}
@Test
public void launchPowerUsageDetailFragment_shouldNotCrash() {
mAppDetail.mBatteryPreference = mBatteryPreference;