Align the profile calculation with other screens.
The profile fragment was accidentally adding all of the app's
code data to the profile, even if it was already attributed to the
primary user.
Change-Id: I47000bbe1fcf98d5e9f252eb74b22fee05b7034d
Fixes: 35919232
Test: Settings Robotest
diff --git a/src/com/android/settings/deviceinfo/StorageProfileFragment.java b/src/com/android/settings/deviceinfo/StorageProfileFragment.java
index 6ae03da..d6071c7 100644
--- a/src/com/android/settings/deviceinfo/StorageProfileFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageProfileFragment.java
@@ -24,6 +24,7 @@
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
+import android.support.annotation.VisibleForTesting;
import android.util.SparseArray;
import com.android.internal.logging.nano.MetricsProto;
@@ -119,10 +120,26 @@
@Override
public void onLoadFinished(Loader<SparseArray<AppsStorageResult>> loader,
SparseArray<AppsStorageResult> result) {
- mPreferenceController.onLoadFinished(result.get(mUserId));
+ mPreferenceController.onLoadFinished(scrubAppsFromResult(result.get(mUserId)));
}
@Override
public void onLoaderReset(Loader<SparseArray<AppsStorageResult>> loader) {
}
+
+ @VisibleForTesting
+ void setPreferenceController(StorageItemPreferenceController controller) {
+ mPreferenceController = controller;
+ }
+
+ private AppsStorageResult scrubAppsFromResult(AppsStorageResult result) {
+ if (result == null) {
+ return null;
+ }
+
+ result.gamesSize = 0;
+ result.musicAppsSize = 0;
+ result.otherAppsSize = 0;
+ return result;
+ }
}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
index 7487b28..2fa1b18 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
@@ -173,6 +173,8 @@
}
public void onLoadFinished(StorageAsyncLoader.AppsStorageResult data) {
+ // TODO(b/35927909): Figure out how to split out apps which are only installed for work
+ // profiles in order to attribute those app's code bytes only to that profile.
mPhotoPreference.setStorageSize(
data.externalStats.imageBytes + data.externalStats.videoBytes);
mAudioPreference.setStorageSize(data.musicAppsSize + data.externalStats.audioBytes);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java
new file mode 100644
index 0000000..8da2a9c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/StorageProfileFragmentTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+package com.android.settings.deviceinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import android.util.SparseArray;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
+import com.android.settings.deviceinfo.storage.StorageItemPreferenceController;
+import com.android.settingslib.applications.StorageStatsSource;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class StorageProfileFragmentTest {
+ @Test
+ public void verifyAppSizesAreZeroedOut() {
+ StorageItemPreferenceController controller = mock(StorageItemPreferenceController.class);
+ StorageProfileFragment fragment = new StorageProfileFragment();
+ StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
+ result.musicAppsSize = 100;
+ result.otherAppsSize = 200;
+ result.gamesSize = 300;
+ result.externalStats = new StorageStatsSource.ExternalStorageStats(6, 1, 2, 3);
+ SparseArray<StorageAsyncLoader.AppsStorageResult> resultsArray = new SparseArray<>();
+ resultsArray.put(0, result);
+ fragment.setPreferenceController(controller);
+
+ fragment.onLoadFinished(null, resultsArray);
+
+ ArgumentCaptor<StorageAsyncLoader.AppsStorageResult> resultCaptor = ArgumentCaptor.forClass(
+ StorageAsyncLoader.AppsStorageResult.class);
+ verify(controller).onLoadFinished(resultCaptor.capture());
+
+ StorageAsyncLoader.AppsStorageResult extractedResult = resultCaptor.getValue();
+ assertThat(extractedResult.musicAppsSize).isEqualTo(0);
+ assertThat(extractedResult.otherAppsSize).isEqualTo(0);
+ assertThat(extractedResult.gamesSize).isEqualTo(0);
+ assertThat(extractedResult.externalStats.audioBytes).isEqualTo(1);
+ assertThat(extractedResult.externalStats.videoBytes).isEqualTo(2);
+ assertThat(extractedResult.externalStats.imageBytes).isEqualTo(3);
+ assertThat(extractedResult.externalStats.totalBytes).isEqualTo(6);
+ }
+}