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

Commit 43b2518d authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

Add support for LiveWallpaper options

Support optional options for a theme's LiveWallpaper in the
theme spec, and allow for extending classes to apply them
by making ThemeManager "injectable".

Bug: 133793299
Change-Id: Id9187d7a38f6714c0e1ec6e07b9aa8b041800c39
parent 2803b61f
Loading
Loading
Loading
Loading
+17 −7
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.customization.model.theme;

import static android.content.res.Resources.ID_NULL;

import static com.android.customization.model.ResourceConstants.ANDROID_PACKAGE;
import static com.android.customization.model.ResourceConstants.ICONS_FOR_PREVIEW;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR;
@@ -86,6 +88,7 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
    private static final String WALLPAPER_ATTRIBUTION_PREFIX = "theme_wallpaper_attribution_";
    private static final String WALLPAPER_THUMB_PREFIX = "theme_wallpaper_thumbnail_";
    private static final String WALLPAPER_ACTION_PREFIX = "theme_wallpaper_action_";
    private static final String WALLPAPER_OPTIONS_PREFIX = "theme_wallpaper_options_";

    private static final String DEFAULT_THEME_NAME= "default";
    private static final String THEME_TITLE_FIELD = "_theme_title";
@@ -187,7 +190,7 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
            String wallpaperThumbnailResName = WALLPAPER_THUMB_PREFIX + themeName;
            int wallpaperThumbnailResId = mStubApkResources.getIdentifier(wallpaperThumbnailResName,
                    "drawable", mStubPackageName);
            if (wallpaperResId != Resources.ID_NULL) {
            if (wallpaperResId != ID_NULL) {
                builder.setWallpaperInfo(mStubPackageName, wallpaperResName,
                        themeName, wallpaperResId,
                        mStubApkResources.getIdentifier(WALLPAPER_TITLE_PREFIX + themeName,
@@ -197,20 +200,26 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
                                mStubPackageName),
                        mStubApkResources.getIdentifier(WALLPAPER_ACTION_PREFIX + themeName,
                                "string", mStubPackageName))
                        .setWallpaperAsset(wallpaperThumbnailResId != Resources.ID_NULL ?
                        .setWallpaperAsset(wallpaperThumbnailResId != ID_NULL ?
                                getDrawableResourceAsset(WALLPAPER_THUMB_PREFIX, themeName)
                                : getDrawableResourceAsset(WALLPAPER_PREFIX, themeName));
            } else {
                // Try to see if it's a live wallpaper reference
                wallpaperResId = mStubApkResources.getIdentifier(wallpaperResName,
                        "string", mStubPackageName);
                if (wallpaperResId != Resources.ID_NULL) {
                if (wallpaperResId != ID_NULL) {
                    String wpComponent = mStubApkResources.getString(wallpaperResId);

                    int wallpaperOptionsResId = mStubApkResources.getIdentifier(
                            WALLPAPER_OPTIONS_PREFIX + themeName, "string", mStubPackageName);
                    String wallpaperOptions = wallpaperOptionsResId != ID_NULL
                            ? mStubApkResources.getString(wallpaperOptionsResId) : null;

                    String[] componentParts = wpComponent.split("/");
                    Intent liveWpIntent =  new Intent(WallpaperService.SERVICE_INTERFACE);
                    liveWpIntent.setComponent(
                            new ComponentName(componentParts[0],
                                    componentParts[0] + componentParts[1]));
                            new ComponentName(componentParts[0], componentParts[1]));

                    Context appContext = mContext.getApplicationContext();
                    PackageManager pm = appContext.getPackageManager();
                    ResolveInfo resolveInfo =
@@ -221,9 +230,10 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
                            wallpaperInfo = new android.app.WallpaperInfo(appContext, resolveInfo);
                            LiveWallpaperInfo liveInfo = new LiveWallpaperInfo(wallpaperInfo);
                            builder.setLiveWallpaperInfo(liveInfo).setWallpaperAsset(
                                    wallpaperThumbnailResId != Resources.ID_NULL ?
                                    wallpaperThumbnailResId != ID_NULL ?
                                        getDrawableResourceAsset(WALLPAPER_THUMB_PREFIX, themeName)
                                        : liveInfo.getThumbAsset(mContext));
                                        : liveInfo.getThumbAsset(mContext))
                                    .setWallpaperOptions(wallpaperOptions);
                        } catch (XmlPullParserException | IOException e) {
                            Log.w(TAG, "Skipping wallpaper " + resolveInfo.serviceInfo, e);
                        }
+15 −2
Original line number Diff line number Diff line
@@ -75,17 +75,19 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
    private final boolean mIsDefault;
    protected final Map<String, String> mPackagesByCategory;
    @Nullable private final WallpaperInfo mWallpaperInfo;
    @Nullable private final String mWallpaperOptions;
    private WallpaperInfo mOverrideWallpaper;
    private Asset mOverrideWallpaperAsset;
    private CharSequence mContentDescription;

    protected ThemeBundle(String title, Map<String, String> overlayPackages,
            boolean isDefault, @Nullable WallpaperInfo wallpaperInfo,
            PreviewInfo previewInfo) {
            @Nullable String wallpaperOptions, PreviewInfo previewInfo) {
        mTitle = title;
        mIsDefault = isDefault;
        mPreviewInfo = previewInfo;
        mWallpaperInfo = wallpaperInfo;
        mWallpaperOptions = wallpaperOptions;
        mPackagesByCategory = Collections.unmodifiableMap(overlayPackages);
    }

@@ -179,6 +181,11 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
        return mWallpaperInfo;
    }

    @Nullable
    public String getWallpaperOptions() {
        return mWallpaperOptions;
    }

    boolean isDefault() {
        return mIsDefault;
    }
@@ -300,11 +307,12 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
        @Dimension private int mCornerRadius;
        private Asset mWallpaperAsset;
        private WallpaperInfo mWallpaperInfo;
        private String mWallpaperOptions;
        protected Map<String, String> mPackages = new HashMap<>();
        private List<Drawable> mAppIcons = new ArrayList<>();

        public ThemeBundle build(Context context) {
            return new ThemeBundle(mTitle, mPackages, mIsDefault, mWallpaperInfo,
            return new ThemeBundle(mTitle, mPackages, mIsDefault, mWallpaperInfo, mWallpaperOptions,
                    createPreviewInfo(context));
        }

@@ -409,6 +417,11 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
            return this;
        }

        public Builder setWallpaperOptions(String wallpaperOptions) {
            mWallpaperOptions = wallpaperOptions;
            return this;
        }

        public Builder asDefault() {
            mIsDefault = true;
            return this;
+8 −2
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@ import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY

import android.graphics.Point;
import android.provider.Settings;

import android.text.TextUtils;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

@@ -42,6 +42,7 @@ import com.android.wallpaper.module.WallpaperPersister.SetWallpaperCallback;
import com.android.wallpaper.module.WallpaperSetter;
import com.android.wallpaper.picker.SetWallpaperDialogFragment.Listener;
import com.android.wallpaper.util.WallpaperCropUtils;

import org.json.JSONObject;

import java.util.HashSet;
@@ -67,7 +68,7 @@ public class ThemeManager implements CustomizationManager<ThemeBundle> {
    private final OverlayManagerCompat mOverlayManagerCompat;

    private final WallpaperSetter mWallpaperSetter;
    private final FragmentActivity mActivity;
    protected final FragmentActivity mActivity;
    private final ThemesUserEventLogger mEventLogger;

    private Map<String, String> mCurrentOverlays;
@@ -122,6 +123,7 @@ public class ThemeManager implements CustomizationManager<ThemeBundle> {
        return new SetWallpaperCallback() {
            @Override
            public void onSuccess() {
                applyWallpaperOptions(theme);
                applyOverlays(theme, callback);
            }

@@ -132,6 +134,10 @@ public class ThemeManager implements CustomizationManager<ThemeBundle> {
        };
    }

    protected void applyWallpaperOptions(ThemeBundle theme) {
        //Do nothing.
    }

    private void applyWallpaper(ThemeBundle theme, int destination,
            SetWallpaperCallback callback) {
        Point defaultCropSurfaceSize = WallpaperCropUtils.getDefaultCropSurfaceSize(
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ public class CustomTheme extends ThemeBundle {

    public CustomTheme(@NonNull String id, String title, Map<String, String> overlayPackages,
            @Nullable PreviewInfo previewInfo) {
        super(title, overlayPackages, false, null, previewInfo);
        super(title, overlayPackages, false, null, null, previewInfo);
        mId = id;
    }

+10 −0
Original line number Diff line number Diff line
@@ -17,9 +17,19 @@ package com.android.customization.module;

import android.content.Context;

import androidx.fragment.app.FragmentActivity;

import com.android.customization.model.theme.OverlayManagerCompat;
import com.android.customization.model.theme.ThemeBundleProvider;
import com.android.customization.model.theme.ThemeManager;
import com.android.wallpaper.module.Injector;
import com.android.wallpaper.module.WallpaperSetter;

public interface CustomizationInjector extends Injector {

    CustomizationPreferences getCustomizationPreferences(Context context);

    ThemeManager getThemeManager(ThemeBundleProvider provider, FragmentActivity activity,
            WallpaperSetter wallpaperSetter, OverlayManagerCompat overlayManagerCompat,
            ThemesUserEventLogger logger);
}
Loading