diff options
| author | 2017-01-11 17:46:42 -0800 | |
|---|---|---|
| committer | 2017-01-20 15:13:38 -0800 | |
| commit | abb4bd212801d5661eb2b8975438cad39eaab2fa (patch) | |
| tree | f733c02ba66811f9eb318baf0de161f7839b6369 | |
| parent | 8e8269fc11bbc8f212be67b19b7f5b4b16b1fa24 (diff) | |
Add a games filter to the ApplicationsState.
This allows us to filter on game apps in Settings.
Bug: 33199077
Test: SettingsLib integ tests
Change-Id: I8cbd7f77ab95e2ce19e56a5af3597334f804885e
3 files changed, 89 insertions, 1 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java index 2b1582d14830..24a3aa92b315 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java @@ -1429,6 +1429,23 @@ public class ApplicationsState { } }; + public static final AppFilter FILTER_GAMES = new AppFilter() { + @Override + public void init() { + } + + @Override + public boolean filterApp(ApplicationsState.AppEntry info) { + // TODO: Update for the new game category. + boolean isGame; + synchronized (info.info) { + isGame = ((info.info.flags & ApplicationInfo.FLAG_IS_GAME) != 0) + || info.info.category == ApplicationInfo.CATEGORY_GAME; + } + return isGame; + } + }; + public static class VolumeFilter implements AppFilter { private final String mVolumeUuid; diff --git a/packages/SettingsLib/tests/integ/Android.mk b/packages/SettingsLib/tests/integ/Android.mk index 98bce0ca42b2..bd910dd190db 100644 --- a/packages/SettingsLib/tests/integ/Android.mk +++ b/packages/SettingsLib/tests/integ/Android.mk @@ -28,7 +28,8 @@ LOCAL_STATIC_JAVA_LIBRARIES := \ android-support-test \ espresso-core \ mockito-target-minus-junit4 \ - legacy-android-test + legacy-android-test \ + truth-prebuilt include frameworks/base/packages/SettingsLib/common.mk diff --git a/packages/SettingsLib/tests/integ/src/com/android/settingslib/applications/ApplicationsStateTest.java b/packages/SettingsLib/tests/integ/src/com/android/settingslib/applications/ApplicationsStateTest.java new file mode 100644 index 000000000000..4f2347d845be --- /dev/null +++ b/packages/SettingsLib/tests/integ/src/com/android/settingslib/applications/ApplicationsStateTest.java @@ -0,0 +1,70 @@ +/* + * 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.settingslib.applications; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.mock; + +import android.content.pm.ApplicationInfo; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ApplicationsStateTest { + private ApplicationsState.AppFilter mFilter; + private ApplicationsState.AppEntry mEntry; + + @Before + public void setUp() { + mFilter = ApplicationsState.FILTER_GAMES; + mEntry = mock(ApplicationsState.AppEntry.class); + mEntry.info = mock(ApplicationInfo.class); + } + + @Test + public void testGamesFilterAcceptsGameDeprecated() { + mEntry.info.flags = ApplicationInfo.FLAG_IS_GAME; + + assertThat(mFilter.filterApp(mEntry)).isTrue(); + } + + @Test + public void testGameFilterAcceptsCategorizedGame() { + mEntry.info.category = ApplicationInfo.CATEGORY_GAME; + + assertThat(mFilter.filterApp(mEntry)).isTrue(); + } + + @Test + public void testGameFilterAcceptsCategorizedGameAndDeprecatedIsGame() { + mEntry.info.flags = ApplicationInfo.FLAG_IS_GAME; + mEntry.info.category = ApplicationInfo.CATEGORY_GAME; + + assertThat(mFilter.filterApp(mEntry)).isTrue(); + } + + @Test + public void testGamesFilterRejectsNotGame() { + mEntry.info.category = ApplicationInfo.CATEGORY_UNDEFINED; + + assertThat(mFilter.filterApp(mEntry)).isFalse(); + } +} |