Merge "Storage Settings Apps category shows image/video/audio APPs" into sc-dev am: 8d1fd73e89
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/14186629
Change-Id: I4cf006558fda517dd7db111ee09e84cf17f7454d
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index a92f539..a08c540 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -511,7 +511,7 @@
if (storageType == STORAGE_TYPE_MUSIC) {
filter = new CompoundFilter(ApplicationsState.FILTER_AUDIO, filter);
} else if (storageType == STORAGE_TYPE_DEFAULT) {
- filter = new CompoundFilter(ApplicationsState.FILTER_OTHER_APPS, filter);
+ filter = new CompoundFilter(ApplicationsState.FILTER_APPS_EXCEPT_GAMES, filter);
}
return filter;
}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
index 9d10a1d..f53b68f 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageAsyncLoader.java
@@ -120,7 +120,9 @@
// This isn't quite right because it slams the first user by user id with the whole code
// size, but this ensures that we count all apps seen once.
+ boolean isAddCodeBytesForFirstUserId = false;
if (!mSeenPackages.contains(app.packageName)) {
+ isAddCodeBytesForFirstUserId = true;
blamedSize += stats.getCodeBytes();
mSeenPackages.add(app.packageName);
}
@@ -130,13 +132,34 @@
result.gamesSize += blamedSize;
break;
case CATEGORY_AUDIO:
+ // TODO(b/170918505): Should revamp audio size calculation with the data
+ // from media provider.
result.musicAppsSize += blamedSize;
+ if (isAddCodeBytesForFirstUserId) {
+ result.musicAppsSize -= stats.getCodeBytes();
+ }
+
+ result.otherAppsSize += blamedSize;
break;
case CATEGORY_VIDEO:
+ // TODO(b/170918505): Should revamp video size calculation with the data
+ // from media provider.
result.videoAppsSize += blamedSize;
+ if (isAddCodeBytesForFirstUserId) {
+ result.videoAppsSize -= stats.getCodeBytes();
+ }
+
+ result.otherAppsSize += blamedSize;
break;
case CATEGORY_IMAGE:
+ // TODO(b/170918505): Should revamp image size calculation with the data
+ // from media provider.
result.photosAppsSize += blamedSize;
+ if (isAddCodeBytesForFirstUserId) {
+ result.photosAppsSize -= stats.getCodeBytes();
+ }
+
+ result.otherAppsSize += blamedSize;
break;
default:
// The deprecated game flag does not set the category.
diff --git a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
index f2349bb..a271e9b 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/storage/StorageAsyncLoaderTest.java
@@ -22,7 +22,9 @@
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -30,20 +32,22 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.UserInfo;
+import android.content.res.Resources;
import android.net.TrafficStats;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.SparseArray;
+import androidx.test.core.app.ApplicationProvider;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
+import com.android.settings.R;
import com.android.settingslib.applications.StorageStatsSource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -57,11 +61,11 @@
private static final int SECONDARY_USER_ID = 10;
private static final String PACKAGE_NAME_1 = "com.blah.test";
private static final String PACKAGE_NAME_2 = "com.blah.test2";
+ private static final String PACKAGE_NAME_3 = "com.blah.test3";
private static final long DEFAULT_QUOTA = 64 * TrafficStats.MB_IN_BYTES;
@Mock
private StorageStatsSource mSource;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
private PackageManager mPackageManager;
@@ -76,6 +80,7 @@
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
+ mContext = spy(ApplicationProvider.getApplicationContext());
mInfo = new ArrayList<>();
mLoader = new StorageAsyncLoader(mContext, mUserManager, "id", mSource, mPackageManager);
when(mPackageManager.getInstalledApplicationsAsUser(eq(PRIMARY_USER_ID), anyInt()))
@@ -85,6 +90,10 @@
mUsers.add(info);
when(mUserManager.getUsers()).thenReturn(mUsers);
when(mSource.getCacheQuotaBytes(anyString(), anyInt())).thenReturn(DEFAULT_QUOTA);
+ final Resources resources = spy(mContext.getResources());
+ when(mContext.getResources()).thenReturn(resources);
+ doReturn("content://com.android.providers.media.documents/root/videos_root")
+ .when(resources).getString(R.string.config_videos_storage_category_uri);
}
@Test
@@ -169,8 +178,8 @@
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(1);
- assertThat(result.get(PRIMARY_USER_ID).videoAppsSize).isEqualTo(11L);
- assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(0);
+ // Code size is not included for file based video category.
+ assertThat(result.get(PRIMARY_USER_ID).videoAppsSize).isEqualTo(10L);
}
@Test
@@ -206,7 +215,8 @@
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(2);
- assertThat(result.get(PRIMARY_USER_ID).videoAppsSize).isEqualTo(11L);
+ // Code size is not included for file based video category.
+ assertThat(result.get(PRIMARY_USER_ID).videoAppsSize).isEqualTo(10L);
// No code size for the second user.
assertThat(result.get(SECONDARY_USER_ID).videoAppsSize).isEqualTo(10L);
}
@@ -221,6 +231,18 @@
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(DEFAULT_QUOTA + 11);
}
+ @Test
+ public void testAppsAreFiltered() throws Exception {
+ addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_IMAGE);
+ addPackage(PACKAGE_NAME_2, 0, 1, 10, ApplicationInfo.CATEGORY_VIDEO);
+ addPackage(PACKAGE_NAME_3, 0, 1, 10, ApplicationInfo.CATEGORY_AUDIO);
+
+ SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
+
+ assertThat(result.size()).isEqualTo(1);
+ assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(33L);
+ }
+
private ApplicationInfo addPackage(String packageName, long cacheSize, long codeSize,
long dataSize, int category) throws Exception {
StorageStatsSource.AppStorageStats storageStats =