Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32439206 authored by Matthew Mintz's avatar Matthew Mintz
Browse files

Make WallpaperPreferenceController available when only style picker present.

WallpaperPreferenceController prefers the style picker over the basic wallpaper picker. However, the entire setting is disabled when only the style picker is available, even though the basic wallpaper picker is not used. This change corrects that.

Fixes: 162395248
Test: Added unit tests. Also built, flashed and tested setting with all four combinations of CategoryPickerActivity and CustomizationPickerActivity enabled/disabled.
Change-Id: I4184f834ed771359cef13b64aacf2072e592d6d8
parent c1a02930
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -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;
    }

+43 −2
Original line number Diff line number Diff line
@@ -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_wallpaperPickerEnabledAndStylePickerDisabled_returnsTrue() {
        mShadowPackageManager.setResolveInfosForIntent(
                mWallpaperIntent, Lists.newArrayList(mock(ResolveInfo.class)));
        mShadowPackageManager.setResolveInfosForIntent(
                mStylesAndWallpaperIntent, Lists.newArrayList());

        assertThat(mController.isAvailable()).isTrue();
    }

    @Test
    public void isAvailable_wallpaperPickerDisabled_shouldReturnFalse() {
    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(