Show Styles & Wallpaper in Settings
Show "Styles & Wallpaper" in Settings based on whether the ThemePicker component is availalable. Also update dashboard summary for display. Bug: 129874298 Test: m RunSettingsRoboTests Change-Id: Id7e0bb9cbc689bb9e637919a10a7d1006397afab
This commit is contained in:
@@ -39,14 +39,13 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class TopLevelDisplayPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
@@ -88,6 +87,19 @@ public class TopLevelDisplayPreferenceControllerTest {
|
||||
.isEqualTo(mContext.getText(R.string.display_dashboard_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_hasWallpaperWithStyles_shouldReturnWallpaperSummary() {
|
||||
when(mContext.getString(R.string.config_styles_and_wallpaper_picker_class))
|
||||
.thenReturn("any.nonempty.class");
|
||||
final List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
resolveInfos.add(mock(ResolveInfo.class));
|
||||
when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt()))
|
||||
.thenReturn(resolveInfos);
|
||||
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getText(R.string.display_dashboard_summary_with_style));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_hasWallpaper_shouldReturnNoWallpaperSummary() {
|
||||
final List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
|
@@ -18,74 +18,132 @@ package com.android.settings.display;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowPackageManager;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {SettingsShadowResources.class})
|
||||
public class WallpaperPreferenceControllerTest {
|
||||
|
||||
private static final String WALLPAPER_PACKAGE = "TestPkg";
|
||||
private static final String WALLPAPER_CLASS = "TestCls";
|
||||
private static final String TEST_KEY = "test_key";
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
private Intent mWallpaperIntent;
|
||||
private Intent mStylesAndWallpaperIntent;
|
||||
private FragmentActivity mContext;
|
||||
private ShadowPackageManager mShadowPackageManager;
|
||||
|
||||
private WallpaperPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getString(R.string.config_wallpaper_picker_package))
|
||||
.thenReturn(WALLPAPER_PACKAGE);
|
||||
when(mContext.getString(R.string.config_wallpaper_picker_class))
|
||||
.thenReturn(WALLPAPER_CLASS);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
|
||||
mContext = Robolectric.buildActivity(FragmentActivity.class).get();
|
||||
SettingsShadowResources.overrideResource(
|
||||
R.string.config_wallpaper_picker_package, "bogus.package.for.testing");
|
||||
SettingsShadowResources.overrideResource(
|
||||
R.string.config_styles_and_wallpaper_picker_class, "bogus.package.class");
|
||||
mWallpaperIntent = new Intent().setComponent(new ComponentName(
|
||||
mContext.getString(R.string.config_wallpaper_picker_package),
|
||||
mContext.getString(R.string.config_wallpaper_picker_class)));
|
||||
mStylesAndWallpaperIntent = new Intent().setComponent(new ComponentName(
|
||||
mContext.getString(R.string.config_wallpaper_picker_package),
|
||||
mContext.getString(R.string.config_styles_and_wallpaper_picker_class)));
|
||||
mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
|
||||
mController = new WallpaperPreferenceController(mContext, TEST_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_wallpaperPickerEnabled_shouldReturnTrue() {
|
||||
final List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
resolveInfos.add(mock(ResolveInfo.class));
|
||||
when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt()))
|
||||
.thenReturn(resolveInfos);
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_wallpaperPickerDisabled_shouldReturnFalse() {
|
||||
when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt())).thenReturn(null);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
|
||||
final List<ResolveInfo> resolveInfos = new ArrayList<>();
|
||||
when(mPackageManager.queryIntentActivities(any(Intent.class), anyInt()))
|
||||
.thenReturn(resolveInfos);
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mWallpaperIntent, Lists.newArrayList());
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void areStylesAvailable_noComponentSpecified() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
R.string.config_styles_and_wallpaper_picker_class, "");
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mStylesAndWallpaperIntent, Lists.newArrayList());
|
||||
|
||||
assertThat(mController.areStylesAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void areStylesAvailable_componentUnresolveable() {
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mStylesAndWallpaperIntent, Lists.newArrayList());
|
||||
|
||||
assertThat(mController.areStylesAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void areStylesAvailable_componentResolved() {
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mStylesAndWallpaperIntent,
|
||||
Lists.newArrayList(mock(ResolveInfo.class)));
|
||||
|
||||
assertThat(mController.areStylesAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_wallpaperOnly() {
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mStylesAndWallpaperIntent, Lists.newArrayList());
|
||||
Preference preference = new Preference(mContext);
|
||||
preference.setKey(TEST_KEY);
|
||||
|
||||
mController.handlePreferenceTreeClick(preference);
|
||||
|
||||
assertThat(Shadows.shadowOf(mContext)
|
||||
.getNextStartedActivityForResult().intent.getComponent().getClassName())
|
||||
.isEqualTo(mContext.getString(R.string.config_wallpaper_picker_class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_stylesAndWallpaper() {
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mWallpaperIntent, Lists.newArrayList());
|
||||
mShadowPackageManager.setResolveInfosForIntent(
|
||||
mStylesAndWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
|
||||
Preference preference = new Preference(mContext);
|
||||
preference.setKey(TEST_KEY);
|
||||
|
||||
mController.handlePreferenceTreeClick(preference);
|
||||
|
||||
assertThat(Shadows.shadowOf(mContext)
|
||||
.getNextStartedActivityForResult().intent.getComponent().getClassName())
|
||||
.isEqualTo(mContext.getString(R.string.config_styles_and_wallpaper_picker_class));
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import androidx.annotation.ArrayRes;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.RealObject;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
import org.robolectric.shadows.ShadowResources;
|
||||
import org.robolectric.util.ReflectionHelpers.ClassParameter;
|
||||
|
||||
@@ -40,6 +41,7 @@ public class SettingsShadowResources extends ShadowResources {
|
||||
overrideResource(resId, value);
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sResourceOverrides.clear();
|
||||
}
|
||||
|
Reference in New Issue
Block a user