Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a41a190a authored by Daniel Nishi's avatar Daniel Nishi Committed by Android (Google) Code Review
Browse files

Merge "Filter on volume for category storage view." into oc-dev

parents b4937f45 5aeb6c4f
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -416,20 +416,28 @@ public class ManageApplications extends InstrumentedPreferenceFragment
        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() {
+77 −0
Original line number Diff line number Diff line
/*
 * 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();
    }
}