From e4ca92af6b367f162320fcdb899606bf7798ccb8 Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Tue, 12 Dec 2017 16:44:53 -0800 Subject: [PATCH] Introduce config_show_wallpaper_attribution. This introduces a boolean flag in which when set to true, Wallpaper Attribution will be shown in the Legal page. When set to false, it will be hidden. Wallpaper has always been removed from search results, so that has not changed. Bug: 62378616 Test: make RunSettingsRoboTests ROBOTEST_FILTER=LegalSettings passes. Change-Id: Ia6f3e7d1ef471eecf79f1b46616fa4ba27d35748 --- res/values/bools.xml | 3 ++ src/com/android/settings/LegalSettings.java | 15 +++++- tests/robotests/res/values-mcc999/config.xml | 3 +- .../android/settings/LegalSettingsTest.java | 47 +++++++++++++++++-- 4 files changed, 62 insertions(+), 6 deletions(-) diff --git a/res/values/bools.xml b/res/values/bools.xml index c896a45015e..c8836300253 100644 --- a/res/values/bools.xml +++ b/res/values/bools.xml @@ -51,4 +51,7 @@ true + + + true diff --git a/src/com/android/settings/LegalSettings.java b/src/com/android/settings/LegalSettings.java index d5b998891b5..e9b2694b82a 100644 --- a/src/com/android/settings/LegalSettings.java +++ b/src/com/android/settings/LegalSettings.java @@ -24,13 +24,14 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.provider.SearchIndexableResource; +import android.support.annotation.VisibleForTesting; import android.support.v7.preference.PreferenceGroup; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import com.android.settings.R; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -40,7 +41,7 @@ public class LegalSettings extends SettingsPreferenceFragment implements Indexab private static final String KEY_LICENSE = "license"; private static final String KEY_COPYRIGHT = "copyright"; private static final String KEY_WEBVIEW_LICENSE = "webview_license"; - private static final String KEY_WALLPAPER_ATTRIBUTIONS = "wallpaper_attributions"; + @VisibleForTesting static final String KEY_WALLPAPER_ATTRIBUTIONS = "wallpaper_attributions"; public void onCreate(Bundle icicle) { super.onCreate(icicle); @@ -57,6 +58,8 @@ public class LegalSettings extends SettingsPreferenceFragment implements Indexab Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY); Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_WEBVIEW_LICENSE, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY); + + checkWallpaperAttributionAvailability(act); } @Override @@ -64,6 +67,14 @@ public class LegalSettings extends SettingsPreferenceFragment implements Indexab return MetricsEvent.ABOUT_LEGAL_SETTINGS; } + @VisibleForTesting + void checkWallpaperAttributionAvailability(Context context) { + if (!context.getResources().getBoolean( + R.bool.config_show_wallpaper_attribution)) { + removePreference(KEY_WALLPAPER_ATTRIBUTIONS); + } + } + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider() { diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml index e25fa188b23..b327446aed1 100644 --- a/tests/robotests/res/values-mcc999/config.xml +++ b/tests/robotests/res/values-mcc999/config.xml @@ -21,4 +21,5 @@ false false false - \ No newline at end of file + false + diff --git a/tests/robotests/src/com/android/settings/LegalSettingsTest.java b/tests/robotests/src/com/android/settings/LegalSettingsTest.java index 3d50c6366aa..db9afc47d39 100644 --- a/tests/robotests/src/com/android/settings/LegalSettingsTest.java +++ b/tests/robotests/src/com/android/settings/LegalSettingsTest.java @@ -15,23 +15,49 @@ */ package com.android.settings; +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; + import android.content.Context; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.XmlTestUtils; + +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import java.util.List; -import static com.google.common.truth.Truth.assertThat; - @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) public class LegalSettingsTest { + private Context mContext; + private LegalSettings mFragment; + private boolean mWallpaperRemoved; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = spy(RuntimeEnvironment.application); + mFragment = new LegalSettings() { + @Override + protected boolean removePreference(String key) { + if (LegalSettings.KEY_WALLPAPER_ATTRIBUTIONS.equals(key)) { + mWallpaperRemoved = true; + + return true; + } + return false; + } + }; + } + @Test public void testNonIndexableKeys_existInXmlLayout() { final Context context = RuntimeEnvironment.application; @@ -43,4 +69,19 @@ public class LegalSettingsTest { assertThat(keys).containsAllIn(niks); } -} \ No newline at end of file + + @Test + public void testWallpaperAttributions_byDefault_shouldBeShown() { + mFragment.checkWallpaperAttributionAvailability(mContext); + + assertThat(mWallpaperRemoved).isEqualTo(false); + } + + @Test + @Config(qualifiers = "mcc999") + public void testWallpaperAttributions_ifDisabled_shouldNotBeShown() { + mFragment.checkWallpaperAttributionAvailability(mContext); + + assertThat(mWallpaperRemoved).isEqualTo(true); + } +}