Merge "Make WallpaperPreferenceController available when only style picker present."

This commit is contained in:
Matthew Mintz
2020-07-30 05:32:55 +00:00
committed by Android (Google) Code Review
2 changed files with 51 additions and 6 deletions

View File

@@ -62,8 +62,11 @@ public class WallpaperPreferenceController extends BasePreferenceController {
}
public ComponentName getComponentName() {
return new ComponentName(mWallpaperPackage,
areStylesAvailable() ? mStylesAndWallpaperClass : mWallpaperClass);
return new ComponentName(mWallpaperPackage, getComponentClassString());
}
public String getComponentClassString() {
return areStylesAvailable() ? mStylesAndWallpaperClass : mWallpaperClass;
}
public String getKeywords() {
@@ -76,11 +79,12 @@ public class WallpaperPreferenceController extends BasePreferenceController {
@Override
public int getAvailabilityStatus() {
if (TextUtils.isEmpty(mWallpaperPackage) || TextUtils.isEmpty(mWallpaperClass)) {
if ((TextUtils.isEmpty(mWallpaperClass) && TextUtils.isEmpty(mStylesAndWallpaperClass))
|| TextUtils.isEmpty(mWallpaperPackage)) {
Log.e(TAG, "No Wallpaper picker specified!");
return UNSUPPORTED_ON_DEVICE;
}
return canResolveWallpaperComponent(mWallpaperClass)
return canResolveWallpaperComponent(getComponentClassString())
? AVAILABLE_UNSEARCHABLE : CONDITIONALLY_UNAVAILABLE;
}

View File

@@ -73,21 +73,62 @@ public class WallpaperPreferenceControllerTest {
}
@Test
public void isAvailable_wallpaperPickerEnabled_shouldReturnTrue() {
public void isAvailable_wallpaperPickerEnabledAndStylePickerEnabled_returnsTrue() {
mShadowPackageManager.setResolveInfosForIntent(
mWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
mShadowPackageManager.setResolveInfosForIntent(
mStylesAndWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_wallpaperPickerDisabled_shouldReturnFalse() {
public void isAvailable_wallpaperPickerEnabledAndStylePickerDisabled_returnsTrue() {
mShadowPackageManager.setResolveInfosForIntent(
mWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
mShadowPackageManager.setResolveInfosForIntent(
mStylesAndWallpaperIntent, Lists.newArrayList());
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_wallpaperPickerDisabledAndStylePickerEnabled_returnsTrue() {
mShadowPackageManager.setResolveInfosForIntent(
mWallpaperIntent, Lists.newArrayList());
mShadowPackageManager.setResolveInfosForIntent(
mStylesAndWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_wallpaperPickerDisabledAndStylePickerDisabled_returnsFalse() {
mShadowPackageManager.setResolveInfosForIntent(
mWallpaperIntent, Lists.newArrayList());
mShadowPackageManager.setResolveInfosForIntent(
mStylesAndWallpaperIntent, Lists.newArrayList());
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void getComponentClassString_stylesAvailable_returnsStylePickerClassString() {
mShadowPackageManager.setResolveInfosForIntent(
mStylesAndWallpaperIntent,
Lists.newArrayList(mock(ResolveInfo.class)));
assertThat(mController.getComponentClassString())
.isEqualTo(mContext.getString(R.string.config_styles_and_wallpaper_picker_class));
}
@Test
public void getComponentClassString_stylesUnavailable_returnsWallpaperPickerClassString() {
mShadowPackageManager.setResolveInfosForIntent(
mStylesAndWallpaperIntent, Lists.newArrayList());
assertThat(mController.getComponentClassString())
.isEqualTo(mContext.getString(R.string.config_wallpaper_picker_class));
}
@Test
public void areStylesAvailable_noComponentSpecified() {
SettingsShadowResources.overrideResource(