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

Commit 53794c88 authored by Santiago Etchebehere's avatar Santiago Etchebehere Committed by Android (Google) Code Review
Browse files

Merge "Add support for LiveWallpaper options" into ub-launcher3-qt-r1-dev

parents 55e87a93 43b2518d
Loading
Loading
Loading
Loading
+17 −7
Original line number Original line Diff line number Diff line
@@ -15,6 +15,8 @@
 */
 */
package com.android.customization.model.theme;
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.ANDROID_PACKAGE;
import static com.android.customization.model.ResourceConstants.ICONS_FOR_PREVIEW;
import static com.android.customization.model.ResourceConstants.ICONS_FOR_PREVIEW;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR;
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_ATTRIBUTION_PREFIX = "theme_wallpaper_attribution_";
    private static final String WALLPAPER_THUMB_PREFIX = "theme_wallpaper_thumbnail_";
    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_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 DEFAULT_THEME_NAME= "default";
    private static final String THEME_TITLE_FIELD = "_theme_title";
    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;
            String wallpaperThumbnailResName = WALLPAPER_THUMB_PREFIX + themeName;
            int wallpaperThumbnailResId = mStubApkResources.getIdentifier(wallpaperThumbnailResName,
            int wallpaperThumbnailResId = mStubApkResources.getIdentifier(wallpaperThumbnailResName,
                    "drawable", mStubPackageName);
                    "drawable", mStubPackageName);
            if (wallpaperResId != Resources.ID_NULL) {
            if (wallpaperResId != ID_NULL) {
                builder.setWallpaperInfo(mStubPackageName, wallpaperResName,
                builder.setWallpaperInfo(mStubPackageName, wallpaperResName,
                        themeName, wallpaperResId,
                        themeName, wallpaperResId,
                        mStubApkResources.getIdentifier(WALLPAPER_TITLE_PREFIX + themeName,
                        mStubApkResources.getIdentifier(WALLPAPER_TITLE_PREFIX + themeName,
@@ -197,20 +200,26 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
                                mStubPackageName),
                                mStubPackageName),
                        mStubApkResources.getIdentifier(WALLPAPER_ACTION_PREFIX + themeName,
                        mStubApkResources.getIdentifier(WALLPAPER_ACTION_PREFIX + themeName,
                                "string", mStubPackageName))
                                "string", mStubPackageName))
                        .setWallpaperAsset(wallpaperThumbnailResId != Resources.ID_NULL ?
                        .setWallpaperAsset(wallpaperThumbnailResId != ID_NULL ?
                                getDrawableResourceAsset(WALLPAPER_THUMB_PREFIX, themeName)
                                getDrawableResourceAsset(WALLPAPER_THUMB_PREFIX, themeName)
                                : getDrawableResourceAsset(WALLPAPER_PREFIX, themeName));
                                : getDrawableResourceAsset(WALLPAPER_PREFIX, themeName));
            } else {
            } else {
                // Try to see if it's a live wallpaper reference
                // Try to see if it's a live wallpaper reference
                wallpaperResId = mStubApkResources.getIdentifier(wallpaperResName,
                wallpaperResId = mStubApkResources.getIdentifier(wallpaperResName,
                        "string", mStubPackageName);
                        "string", mStubPackageName);
                if (wallpaperResId != Resources.ID_NULL) {
                if (wallpaperResId != ID_NULL) {
                    String wpComponent = mStubApkResources.getString(wallpaperResId);
                    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("/");
                    String[] componentParts = wpComponent.split("/");
                    Intent liveWpIntent =  new Intent(WallpaperService.SERVICE_INTERFACE);
                    Intent liveWpIntent =  new Intent(WallpaperService.SERVICE_INTERFACE);
                    liveWpIntent.setComponent(
                    liveWpIntent.setComponent(
                            new ComponentName(componentParts[0],
                            new ComponentName(componentParts[0], componentParts[1]));
                                    componentParts[0] + componentParts[1]));

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


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


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


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

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


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


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


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

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


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

import android.text.TextUtils;
import android.text.TextUtils;

import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
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.module.WallpaperSetter;
import com.android.wallpaper.picker.SetWallpaperDialogFragment.Listener;
import com.android.wallpaper.picker.SetWallpaperDialogFragment.Listener;
import com.android.wallpaper.util.WallpaperCropUtils;
import com.android.wallpaper.util.WallpaperCropUtils;

import org.json.JSONObject;
import org.json.JSONObject;


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


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


    private Map<String, String> mCurrentOverlays;
    private Map<String, String> mCurrentOverlays;
@@ -122,6 +123,7 @@ public class ThemeManager implements CustomizationManager<ThemeBundle> {
        return new SetWallpaperCallback() {
        return new SetWallpaperCallback() {
            @Override
            @Override
            public void onSuccess() {
            public void onSuccess() {
                applyWallpaperOptions(theme);
                applyOverlays(theme, callback);
                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,
    private void applyWallpaper(ThemeBundle theme, int destination,
            SetWallpaperCallback callback) {
            SetWallpaperCallback callback) {
        Point defaultCropSurfaceSize = WallpaperCropUtils.getDefaultCropSurfaceSize(
        Point defaultCropSurfaceSize = WallpaperCropUtils.getDefaultCropSurfaceSize(
+1 −1
Original line number Original line 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,
    public CustomTheme(@NonNull String id, String title, Map<String, String> overlayPackages,
            @Nullable PreviewInfo previewInfo) {
            @Nullable PreviewInfo previewInfo) {
        super(title, overlayPackages, false, null, previewInfo);
        super(title, overlayPackages, false, null, null, previewInfo);
        mId = id;
        mId = id;
    }
    }


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


import android.content.Context;
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.Injector;
import com.android.wallpaper.module.WallpaperSetter;


public interface CustomizationInjector extends Injector {
public interface CustomizationInjector extends Injector {


    CustomizationPreferences getCustomizationPreferences(Context context);
    CustomizationPreferences getCustomizationPreferences(Context context);

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