Merge "Filter on volume for category storage view." into oc-dev
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index 559204b..505a04f 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -416,20 +416,28 @@
         if (mListType == LIST_TYPE_HIGH_POWER) {
             mFilterAdapter.enableFilter(FILTER_APPS_POWER_WHITELIST_ALL);
         }
-        if (mListType == LIST_TYPE_STORAGE) {
-            AppFilter filter = new VolumeFilter(mVolumeUuid);
-            if (mStorageType == STORAGE_TYPE_MUSIC) {
+        // Storage filters below.
+        mApplications.setOverrideFilter(getStorageFilter(mListType, mStorageType, mVolumeUuid));
+    }
+
+    @VisibleForTesting
+    static AppFilter getStorageFilter(int listType, int storageType, String volumeUuid) {
+        AppFilter filter = new VolumeFilter(volumeUuid);
+        if (listType == LIST_TYPE_STORAGE) {
+            if (storageType == STORAGE_TYPE_MUSIC) {
                 filter = new CompoundFilter(ApplicationsState.FILTER_AUDIO, filter);
             } else {
                 filter = new CompoundFilter(ApplicationsState.FILTER_OTHER_APPS, filter);
             }
-            mApplications.setOverrideFilter(filter);
+            return filter;
         }
-        if (mListType == LIST_TYPE_GAMES) {
-            mApplications.setOverrideFilter(ApplicationsState.FILTER_GAMES);
-        } else if (mListType == LIST_TYPE_MOVIES) {
-            mApplications.setOverrideFilter(ApplicationsState.FILTER_MOVIES);
+        if (listType == LIST_TYPE_GAMES) {
+            return new CompoundFilter(ApplicationsState.FILTER_GAMES, filter);
+        } else if (listType == LIST_TYPE_MOVIES) {
+            return new CompoundFilter(ApplicationsState.FILTER_MOVIES, filter);
         }
+
+        return filter;
     }
 
     private int getDefaultFilter() {
diff --git a/tests/unit/src/com/android/settings/applications/ManageApplicationsTest.java b/tests/unit/src/com/android/settings/applications/ManageApplicationsTest.java
new file mode 100644
index 0000000..92ea22f
--- /dev/null
+++ b/tests/unit/src/com/android/settings/applications/ManageApplicationsTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.applications;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+
+import android.content.pm.ApplicationInfo;
+
+import com.android.settingslib.applications.ApplicationsState;
+
+import org.junit.Test;
+
+public class ManageApplicationsTest {
+    @Test
+    public void getStorageFilter_filtersVolumeForAudio() {
+        ApplicationsState.AppFilter filter =
+                ManageApplications.getStorageFilter(
+                        ManageApplications.LIST_TYPE_STORAGE,
+                        ManageApplications.STORAGE_TYPE_MUSIC,
+                        "uuid");
+        final ApplicationInfo info = new ApplicationInfo();
+        info.volumeUuid = "uuid";
+        info.category = ApplicationInfo.CATEGORY_AUDIO;
+        final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
+        appEntry.info = info;
+
+        assertThat(filter.filterApp(appEntry)).isTrue();
+    }
+
+    @Test
+    public void getStorageFilter_filtersVolumeForVideo() {
+        ApplicationsState.AppFilter filter =
+                ManageApplications.getStorageFilter(
+                        ManageApplications.LIST_TYPE_MOVIES,
+                        ManageApplications.STORAGE_TYPE_DEFAULT,
+                        "uuid");
+        final ApplicationInfo info = new ApplicationInfo();
+        info.volumeUuid = "uuid";
+        info.category = ApplicationInfo.CATEGORY_VIDEO;
+        final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
+        appEntry.info = info;
+
+        assertThat(filter.filterApp(appEntry)).isTrue();
+    }
+
+    @Test
+    public void getStorageFilter_filtersVolumeForGames() {
+        ApplicationsState.AppFilter filter =
+                ManageApplications.getStorageFilter(
+                        ManageApplications.LIST_TYPE_GAMES,
+                        ManageApplications.STORAGE_TYPE_DEFAULT,
+                        "uuid");
+        final ApplicationInfo info = new ApplicationInfo();
+        info.volumeUuid = "uuid";
+        info.category = ApplicationInfo.CATEGORY_GAME;
+        final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
+        appEntry.info = info;
+
+        assertThat(filter.filterApp(appEntry)).isTrue();
+    }
+}