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

Commit c07254e6 authored by Xin Li's avatar Xin Li
Browse files

Fix checkbuild.

Bug: 170697222
Merged-In: I1a854f0d6be46cfd11ada58fa54589147e0f37d7
Change-Id: I2a7aa5f17b334545f79a4552be9f8df2f91f7b82
parent 3355c05a
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -40,12 +40,11 @@ import android.provider.Settings;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

import com.android.customization.model.CustomizationManager.OptionsFetchedListener;
import com.android.customization.model.CustomizationManager.Callback;
import com.android.customization.model.CustomizationManager.OptionsFetchedListener;
import com.android.customization.model.theme.custom.CustomTheme;
import com.android.customization.module.ThemesUserEventLogger;
import com.android.customization.testutils.OverlayManagerMocks;
import com.android.wallpaper.module.WallpaperSetter;

import org.json.JSONObject;
import org.junit.After;
@@ -61,7 +60,6 @@ import org.robolectric.RobolectricTestRunner;
public class ThemeManagerTest {

    @Mock OverlayManagerCompat mMockOm;
    @Mock WallpaperSetter mMockWallpaperSetter;
    @Mock ThemesUserEventLogger mThemesUserEventLogger;
    @Mock ThemeBundleProvider mThemeBundleProvider;
    private OverlayManagerMocks mMockOmHelper;
@@ -75,7 +73,7 @@ public class ThemeManagerTest {
        mActivity = spy(activity);
        mMockOmHelper = new OverlayManagerMocks();
        mMockOmHelper.setUpMock(mMockOm);
        mThemeManager = new ThemeManager(mThemeBundleProvider, activity, mMockWallpaperSetter,
        mThemeManager = new ThemeManager(mThemeBundleProvider, activity,
                mMockOm, mThemesUserEventLogger);
    }

+6 −4
Original line number Diff line number Diff line
@@ -57,22 +57,24 @@ public class GridOptionsManager implements CustomizationManager<GridOption> {

    @Override
    public void fetchOptions(OptionsFetchedListener<GridOption> callback, boolean reload) {
        new FetchTask(mProvider, callback).execute();
        new FetchTask(mProvider, callback, reload).execute();
    }

    /** Call through content provider API to render preview */
    public void renderPreview(Bundle bundle, String gridName) {
        mProvider.renderPreview(gridName, bundle);
    public Bundle renderPreview(Bundle bundle, String gridName) {
        return mProvider.renderPreview(gridName, bundle);
    }

    private static class FetchTask extends AsyncTask<Void, Void, List<GridOption>> {
        private final LauncherGridOptionsProvider mProvider;
        @Nullable private final OptionsFetchedListener<GridOption> mCallback;
        private final boolean mReload;

        private FetchTask(@NonNull LauncherGridOptionsProvider provider,
                @Nullable OptionsFetchedListener<GridOption> callback) {
                @Nullable OptionsFetchedListener<GridOption> callback, boolean reload) {
            mCallback = callback;
            mProvider = provider;
            mReload = reload;
        }

        @Override
+9 −5
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;

import com.android.customization.model.ResourceConstants;
import com.android.systemui.shared.system.SurfaceViewRequestUtils;
import com.android.wallpaper.R;
import com.android.wallpaper.util.PreviewUtils;

@@ -51,6 +50,9 @@ public class LauncherGridOptionsProvider {
    private static final String COL_PREVIEW_COUNT = "preview_count";
    private static final String COL_IS_DEFAULT = "is_default";

    // Normal gird size name
    private static final String GRID_NAME_NORMAL = "normal";

    private static final String METADATA_KEY_PREVIEW_VERSION = "preview_version";

    private final Context mContext;
@@ -91,7 +93,9 @@ public class LauncherGridOptionsProvider {
                int cols = c.getInt(c.getColumnIndex(COL_COLS));
                int previewCount = c.getInt(c.getColumnIndex(COL_PREVIEW_COUNT));
                boolean isSet = Boolean.valueOf(c.getString(c.getColumnIndex(COL_IS_DEFAULT)));
                String title = mContext.getString(R.string.grid_title_pattern, cols, rows);
                String title = GRID_NAME_NORMAL.equals(name)
                        ? mContext.getString(R.string.default_theme_title)
                        : mContext.getString(R.string.grid_title_pattern, cols, rows);
                mOptions.add(new GridOption(title, name, isSet, rows, cols,
                        mPreviewUtils.getUri(PREVIEW), previewCount, iconPath));
            }
@@ -106,11 +110,11 @@ public class LauncherGridOptionsProvider {
     * Request rendering of home screen preview via Launcher to Wallpaper using SurfaceView
     * @param name      the grid option name
     * @param bundle    surface view request bundle generated from
     *                  {@link SurfaceViewRequestUtils#createSurfaceBundle(SurfaceView)}.
     *    {@link com.android.wallpaper.util.SurfaceViewUtils#createSurfaceViewRequest(SurfaceView)}.
     */
    void renderPreview(String name, Bundle bundle) {
    Bundle renderPreview(String name, Bundle bundle) {
        bundle.putString("name", name);
        mPreviewUtils.renderPreview(bundle);
        return mPreviewUtils.renderPreview(bundle);
    }

    int applyGrid(String name) {
+0 −84
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
 */
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;
@@ -29,15 +27,10 @@ import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SHAPE;
import static com.android.customization.model.ResourceConstants.SYSUI_PACKAGE;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Resources.NotFoundException;
import android.service.wallpaper.WallpaperService;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;
@@ -52,7 +45,6 @@ import com.android.customization.model.theme.custom.CustomTheme;
import com.android.customization.module.CustomizationPreferences;
import com.android.wallpaper.R;
import com.android.wallpaper.asset.ResourceAsset;
import com.android.wallpaper.model.LiveWallpaperInfo;

import com.bumptech.glide.request.RequestOptions;
import com.google.android.apps.wallpaper.asset.ThemeBundleThumbAsset;
@@ -60,9 +52,7 @@ import com.google.android.apps.wallpaper.asset.ThemeBundleThumbAsset;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -86,12 +76,6 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
    private static final String ICON_THEMEPICKER_PREFIX = "theme_overlay_icon_themepicker_";
    private static final String ICON_SETTINGS_PREFIX = "theme_overlay_icon_settings_";
    private static final String ICON_SYSUI_PREFIX = "theme_overlay_icon_sysui_";
    private static final String WALLPAPER_PREFIX = "theme_wallpaper_";
    private static final String WALLPAPER_TITLE_PREFIX = "theme_wallpaper_title_";
    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";
@@ -178,8 +162,6 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB

                mOverlayProvider.addNoPreviewIconOverlay(builder, iconSettingsOverlayPackage);

                addWallpaper(themeName, builder);

                mThemes.add(builder.build(mContext));
            } catch (NameNotFoundException | NotFoundException e) {
                Log.w(TAG, String.format("Couldn't load part of theme %s, will skip it", themeName),
@@ -190,70 +172,6 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
        addCustomThemes();
    }

    private void addWallpaper(String themeName, Builder builder) {
        try {
            String wallpaperResName = WALLPAPER_PREFIX + themeName;
            int wallpaperResId = mStubApkResources.getIdentifier(wallpaperResName,
                    "drawable", mStubPackageName);
            // Check in case the theme has a separate thumbnail for the wallpaper
            String wallpaperThumbnailResName = WALLPAPER_THUMB_PREFIX + themeName;
            int wallpaperThumbnailResId = mStubApkResources.getIdentifier(wallpaperThumbnailResName,
                    "drawable", mStubPackageName);
            if (wallpaperResId != ID_NULL) {
                builder.setWallpaperInfo(mStubPackageName, wallpaperResName,
                        themeName, wallpaperResId,
                        mStubApkResources.getIdentifier(WALLPAPER_TITLE_PREFIX + themeName,
                                "string", mStubPackageName),
                        mStubApkResources.getIdentifier(
                                WALLPAPER_ATTRIBUTION_PREFIX + themeName, "string",
                                mStubPackageName),
                        mStubApkResources.getIdentifier(WALLPAPER_ACTION_PREFIX + themeName,
                                "string", mStubPackageName))
                        .setWallpaperAsset(wallpaperThumbnailResId != ID_NULL ?
                                getThumbAsset(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 != 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[1]));

                    Context appContext = mContext.getApplicationContext();
                    PackageManager pm = appContext.getPackageManager();
                    ResolveInfo resolveInfo =
                            pm.resolveService(liveWpIntent, PackageManager.GET_META_DATA);
                    if (resolveInfo != null) {
                        android.app.WallpaperInfo wallpaperInfo;
                        try {
                            wallpaperInfo = new android.app.WallpaperInfo(appContext, resolveInfo);
                            LiveWallpaperInfo liveInfo = new LiveWallpaperInfo(wallpaperInfo);
                            builder.setLiveWallpaperInfo(liveInfo).setWallpaperAsset(
                                    wallpaperThumbnailResId != ID_NULL ?
                                            getThumbAsset(WALLPAPER_THUMB_PREFIX, themeName)
                                        : liveInfo.getThumbAsset(mContext))
                                    .setWallpaperOptions(wallpaperOptions);
                        } catch (XmlPullParserException | IOException e) {
                            Log.w(TAG, "Skipping wallpaper " + resolveInfo.serviceInfo, e);
                        }
                    }
                }
            }
        } catch (NotFoundException e) {
            // Nothing to do here, if there's no wallpaper we'll just omit wallpaper
        }
    }

    /**
     * Default theme requires different treatment: if there are overlay packages specified in the
     * stub apk, we'll use those, otherwise we'll get the System default values. But we cannot skip
@@ -333,8 +251,6 @@ public class DefaultThemeProvider extends ResourcesApkProvider implements ThemeB
            mOverlayProvider.addSystemDefaultIcons(builder, SYSUI_PACKAGE, ICONS_FOR_PREVIEW);
        }

        addWallpaper(DEFAULT_THEME_NAME, builder);

        mThemes.add(builder.build(mContext));
    }

+3 −65
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.PathShape;
import android.icu.text.SimpleDateFormat;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -40,9 +39,7 @@ import android.widget.TextView;

import androidx.annotation.ColorInt;
import androidx.annotation.Dimension;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.core.graphics.PathParser;

import com.android.customization.model.CustomizationManager;
@@ -52,7 +49,6 @@ import com.android.customization.widget.DynamicAdaptiveIconDrawable;
import com.android.wallpaper.R;
import com.android.wallpaper.asset.Asset;
import com.android.wallpaper.asset.BitmapCachingAsset;
import com.android.wallpaper.model.LiveWallpaperInfo;
import com.android.wallpaper.model.WallpaperInfo;

import org.json.JSONException;
@@ -60,12 +56,10 @@ import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@@ -85,20 +79,15 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
    private final PreviewInfo mPreviewInfo;
    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,
            @Nullable String wallpaperOptions, PreviewInfo previewInfo) {
            boolean isDefault, PreviewInfo previewInfo) {
        mTitle = title;
        mIsDefault = isDefault;
        mPreviewInfo = previewInfo;
        mWallpaperInfo = wallpaperInfo;
        mWallpaperOptions = wallpaperOptions;
        mPackagesByCategory = Collections.unmodifiableMap(removeNullValues(overlayPackages));
    }

@@ -171,16 +160,6 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
        mOverrideWallpaperAsset = null;
    }

    public boolean shouldUseThemeWallpaper() {
        return mOverrideWallpaper == null && mWallpaperInfo != null;
    }

    public Asset getWallpaperPreviewAsset(Context context) {
        return mOverrideWallpaper != null ?
                getOverrideWallpaperAsset(context) :
                getPreviewInfo().wallpaperAsset;
    }

    private Asset getOverrideWallpaperAsset(Context context) {
        if (mOverrideWallpaperAsset == null) {
            mOverrideWallpaperAsset = new BitmapCachingAsset(context,
@@ -189,15 +168,6 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
        return mOverrideWallpaperAsset;
    }

    public WallpaperInfo getWallpaperInfo() {
        return mWallpaperInfo;
    }

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

    boolean isDefault() {
        return mIsDefault;
    }
@@ -289,7 +259,6 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
        @ColorInt public final int colorAccentDark;
        public final List<Drawable> icons;
        public final Drawable shapeDrawable;
        @Nullable public final Asset wallpaperAsset;
        public final List<ShapeAppIcon> shapeAppIcons;
        @Dimension public final int bottomSheeetCornerRadius;

@@ -325,8 +294,6 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
            this.icons = icons;
            this.shapeDrawable = shapeDrawable;
            this.bottomSheeetCornerRadius = cornerRadius;
            this.wallpaperAsset = wallpaperAsset == null
                    ? null : new BitmapCachingAsset(context, wallpaperAsset);
            this.shapeAppIcons = shapeAppIcons;
        }

@@ -353,15 +320,11 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
        private Path mShapePath;
        private boolean mIsDefault;
        @Dimension private int mCornerRadius;
        private Asset mWallpaperAsset;
        private WallpaperInfo mWallpaperInfo;
        private String mWallpaperOptions;
        protected Map<String, String> mPackages = new HashMap<>();
        private List<ShapeAppIcon> mAppIcons = new ArrayList<>();

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

        public PreviewInfo createPreviewInfo(Context context) {
@@ -392,8 +355,7 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
                }
            }
            return new PreviewInfo(context, mBodyFontFamily, mHeadlineFontFamily, mColorAccentLight,
                    mColorAccentDark, mIcons, shapeDrawable, mCornerRadius,
                    mWallpaperAsset, shapeIcons);
                    mColorAccentDark, mIcons, shapeDrawable, mCornerRadius, shapeIcons);
        }

        public Map<String, String> getPackages() {
@@ -449,30 +411,6 @@ public class ThemeBundle implements CustomizationOption<ThemeBundle> {
            return this;
        }

        public Builder setWallpaperInfo(String wallpaperPackageName, String wallpaperResName,
                String themeId, @DrawableRes int wallpaperResId, @StringRes int titleResId,
                @StringRes int attributionResId, @StringRes int actionUrlResId) {
            mWallpaperInfo = new ThemeBundledWallpaperInfo(wallpaperPackageName, wallpaperResName,
                    themeId, wallpaperResId, titleResId, attributionResId, actionUrlResId);
            return this;
        }

        public Builder setLiveWallpaperInfo(LiveWallpaperInfo info) {
            mWallpaperInfo = info;
            return this;
        }


        public Builder setWallpaperAsset(Asset wallpaperAsset) {
            mWallpaperAsset = wallpaperAsset;
            return this;
        }

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

        public Builder asDefault() {
            mIsDefault = true;
            return this;
Loading