Merge "Introduce config_show_wallpaper_attribution."

This commit is contained in:
TreeHugger Robot
2017-12-18 20:46:59 +00:00
committed by Android (Google) Code Review
4 changed files with 62 additions and 6 deletions

View File

@@ -51,4 +51,7 @@
<!-- Whether location mode is available or not. --> <!-- Whether location mode is available or not. -->
<bool name="config_location_mode_available">true</bool> <bool name="config_location_mode_available">true</bool>
<!-- Whether wallpaper attribution should be shown or not. -->
<bool name="config_show_wallpaper_attribution">true</bool>
</resources> </resources>

View File

@@ -24,13 +24,14 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.provider.SearchIndexableResource; import android.provider.SearchIndexableResource;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.PreferenceGroup; import android.support.v7.preference.PreferenceGroup;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable; import com.android.settings.search.Indexable;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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_LICENSE = "license";
private static final String KEY_COPYRIGHT = "copyright"; private static final String KEY_COPYRIGHT = "copyright";
private static final String KEY_WEBVIEW_LICENSE = "webview_license"; 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) { public void onCreate(Bundle icicle) {
super.onCreate(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.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_WEBVIEW_LICENSE, Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_WEBVIEW_LICENSE,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY); Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
checkWallpaperAttributionAvailability(act);
} }
@Override @Override
@@ -64,6 +67,14 @@ public class LegalSettings extends SettingsPreferenceFragment implements Indexab
return MetricsEvent.ABOUT_LEGAL_SETTINGS; 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 = public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() { new BaseSearchIndexProvider() {

View File

@@ -21,4 +21,5 @@
<bool name="config_show_connectivity_monitor">false</bool> <bool name="config_show_connectivity_monitor">false</bool>
<bool name="config_display_recent_apps">false</bool> <bool name="config_display_recent_apps">false</bool>
<bool name="config_location_mode_available">false</bool> <bool name="config_location_mode_available">false</bool>
</resources> <bool name="config_show_wallpaper_attribution">false</bool>
</resources>

View File

@@ -15,23 +15,49 @@
*/ */
package com.android.settings; 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 android.content.Context;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.XmlTestUtils; import com.android.settings.testutils.XmlTestUtils;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import java.util.List; import java.util.List;
import static com.google.common.truth.Truth.assertThat;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class LegalSettingsTest { 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 @Test
public void testNonIndexableKeys_existInXmlLayout() { public void testNonIndexableKeys_existInXmlLayout() {
final Context context = RuntimeEnvironment.application; final Context context = RuntimeEnvironment.application;
@@ -43,4 +69,19 @@ public class LegalSettingsTest {
assertThat(keys).containsAllIn(niks); assertThat(keys).containsAllIn(niks);
} }
}
@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);
}
}