OSDN Git Service

Fix ANR in installed app details.
authorFan Zhang <zhfan@google.com>
Mon, 24 Apr 2017 23:57:35 +0000 (16:57 -0700)
committerFan Zhang <zhfan@google.com>
Tue, 25 Apr 2017 04:51:32 +0000 (21:51 -0700)
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

src/com/android/settings/applications/InstalledAppDetails.java
tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java

index 16621f4..c0d2dd8 100755 (executable)
@@ -454,6 +454,10 @@ public class InstalledAppDetails extends AppInfoBase
 
     @Override
     public void onPackageSizeChanged(String packageName) {
+        if (!TextUtils.equals(packageName, mPackageName)) {
+            Log.d(LOG_TAG, "Package change irrelevant, skipping");
+          return;
+        }
         refreshUi();
     }
 
index 9c91ccf..6cf4a59 100644 (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
@@ -182,6 +184,24 @@ public final class InstalledAppDetailsTest {
     }
 
     @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;
         mAppDetail.mSipper = mBatterySipper;