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

Commit 8eaa0288 authored by Andy Mast's avatar Andy Mast Committed by Richard MacGregor
Browse files

[1/2] Themes: Multiwallpaper support

1. Add wallpaper component id to ThemeChangeRequest

2. Query themes provider for the wallpaper path given a pkgName and wallpaper id.
   Previously the path was only assumed from the pkgName.

3. Update the mix'n'match table to reflect the component id

Change-Id: Ia38da1c36b3c2f7f038d0a34054aff2257a294dc
parent 74aae7b6
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -28,9 +28,12 @@ import static android.provider.ThemesContract.ThemesColumns.*;

/** @hide */
public final class ThemeChangeRequest implements Parcelable {
    public static final int DEFAULT_WALLPAPER_ID = -1;

    private final Map<String, String> mThemeComponents = new HashMap<String, String>();
    private final Map<String, String> mPerAppOverlays = new HashMap<String, String>();
    private RequestType mRequestType;
    private long mWallpaperId = -1;

    public String getOverlayThemePackageName() {
        return getThemePackageNameForComponent(MODIFIES_OVERLAYS);
@@ -80,6 +83,10 @@ public final class ThemeChangeRequest implements Parcelable {
        return Collections.unmodifiableMap(mThemeComponents);
    }

    public long getWallpaperId() {
        return mWallpaperId;
    }

    /**
     * Get the mapping for per app themes
     * @return A mapping of apps and the theme to apply for each one. or null if none set.
@@ -101,7 +108,7 @@ public final class ThemeChangeRequest implements Parcelable {
    }

    private ThemeChangeRequest(Map<String, String> components, Map<String, String> perAppThemes,
            RequestType requestType) {
            RequestType requestType, long wallpaperId) {
        if (components != null) {
            mThemeComponents.putAll(components);
        }
@@ -109,6 +116,7 @@ public final class ThemeChangeRequest implements Parcelable {
            mPerAppOverlays.putAll(perAppThemes);
        }
        mRequestType = requestType;
        mWallpaperId = wallpaperId;
    }

    private ThemeChangeRequest(Parcel source) {
@@ -122,6 +130,7 @@ public final class ThemeChangeRequest implements Parcelable {
            mPerAppOverlays.put(source.readString(), source.readString());
        }
        mRequestType = RequestType.values()[source.readInt()];
        mWallpaperId = source.readLong();
    }

    @Override
@@ -142,6 +151,7 @@ public final class ThemeChangeRequest implements Parcelable {
            dest.writeString(mPerAppOverlays.get(appPkgName));
        }
        dest.writeInt(mRequestType.ordinal());
        dest.writeLong(mWallpaperId);
    }

    public static final Parcelable.Creator<ThemeChangeRequest> CREATOR =
@@ -169,6 +179,7 @@ public final class ThemeChangeRequest implements Parcelable {
        Map<String, String> mThemeComponents = new HashMap<String, String>();
        Map<String, String> mPerAppOverlays = new HashMap<String, String>();
        RequestType mRequestType = RequestType.USER_REQUEST;
        long mWallpaperId;

        public Builder() {}

@@ -206,6 +217,12 @@ public final class ThemeChangeRequest implements Parcelable {
            return setComponent(MODIFIES_LAUNCHER, pkgName);
        }

        // Used in the case that more than one wallpaper exists for a given pkg name
        public Builder setWallpaperId(long id) {
            mWallpaperId = id;
            return this;
        }

        public Builder setLockWallpaper(String pkgName) {
            return setComponent(MODIFIES_LOCKSCREEN, pkgName);
        }
@@ -249,7 +266,8 @@ public final class ThemeChangeRequest implements Parcelable {
        }

        public ThemeChangeRequest build() {
            return new ThemeChangeRequest(mThemeComponents, mPerAppOverlays, mRequestType);
            return new ThemeChangeRequest(mThemeComponents, mPerAppOverlays,
                    mRequestType, mWallpaperId);
        }

        private void buildChangeRequestFromThemeConfig(ThemeConfig themeConfig) {
+7 −0
Original line number Diff line number Diff line
@@ -295,6 +295,13 @@ public class ThemesContract {
         */
        public static final String COL_UPDATE_TIME = "update_time";

        /*
         * The unique ID for the component within a theme.
         * Always 0 unless multiples of a component exist.
         * <P>Type: INTEGER (long)</P>
         */
        public static final String COL_COMPONENT_ID = "component_id";

        /**
         * Valid keys
         */
+40 −5
Original line number Diff line number Diff line
@@ -180,7 +180,8 @@ public class ImageUtils {
     *
     * @return a new InputStream of the cropped image/*"
     */
    public static InputStream getCroppedWallpaperStream(String pkgName, Context context) {
    public static InputStream getCroppedWallpaperStream(String pkgName, long wallpaperId,
            Context context) {
        if (TextUtils.isEmpty(pkgName)) {
            throw new IllegalArgumentException("'pkgName' cannot be null or empty!");
        }
@@ -191,7 +192,7 @@ public class ImageUtils {
        InputStream cropped = null;
        InputStream stream = null;
        try {
            stream = getOriginalWallpaperStream(pkgName, context);
            stream = getOriginalWallpaperStream(pkgName, wallpaperId, context);
            if (stream == null) {
                return null;
            }
@@ -203,7 +204,7 @@ public class ImageUtils {
            WallpaperManager wm = WallpaperManager.getInstance(context);
            int outWidth = wm.getDesiredMinimumWidth();
            int outHeight = wm.getDesiredMinimumHeight();
            stream = getOriginalWallpaperStream(pkgName, context);
            stream = getOriginalWallpaperStream(pkgName, wallpaperId, context);
            if (stream == null) {
                return null;
            }
@@ -240,7 +241,9 @@ public class ImageUtils {
        return inputStream;
    }

    private static InputStream getOriginalWallpaperStream(String pkgName, Context context) {
    private static InputStream getOriginalWallpaperStream(String pkgName, long componentId,
            Context context) {
        String wpPath;
        if (TextUtils.isEmpty(pkgName) || context == null) {
            return null;
        }
@@ -277,7 +280,8 @@ public class ImageUtils {
                Context themeCtx = context.createPackageContext(pkgName,
                        Context.CONTEXT_IGNORE_SECURITY);
                AssetManager assetManager = themeCtx.getAssets();
                String wpPath = ThemeUtils.getWallpaperPath(assetManager);
                wpPath = queryWpPathFromComponentId(context, pkgName, componentId);
                if (wpPath == null) wpPath = ThemeUtils.getWallpaperPath(assetManager);
                if (wpPath == null) {
                    Log.e(TAG, "Not setting wp because wallpaper file was not found.");
                } else {
@@ -293,5 +297,36 @@ public class ImageUtils {

        return inputStream;
    }

    private static String queryWpPathFromComponentId(Context context, String pkgName,
            long componentId) {
        String wpPath = null;
        String[] projection = new String[] { ThemesContract.PreviewColumns.COL_VALUE };
        String selection = ThemesColumns.PKG_NAME + "=? AND " +
                ThemesContract.PreviewColumns.COMPONENT_ID + "=? AND " +
                ThemesContract.PreviewColumns.COL_KEY + "=?";
        String[] selectionArgs = new String[] {
                pkgName,
                Long.toString(componentId),
                ThemesContract.PreviewColumns.WALLPAPER_FULL
        };

        Cursor c = context.getContentResolver()
                .query(ThemesContract.PreviewColumns.COMPONENTS_URI,
                        projection, selection, selectionArgs, null);
        if (c != null) {
            try {
                if (c.moveToFirst()) {
                    int valIdx = c.getColumnIndex(ThemesContract.PreviewColumns.COL_VALUE);
                    wpPath = c.getString(valIdx);
                }
            } catch(Exception e) {
                Log.e(TAG, "Could not get wallpaper path", e);
            } finally {
                c.close();
            }
        }
        return wpPath;
    }
}
+10 −3
Original line number Diff line number Diff line
@@ -398,7 +398,8 @@ public class ThemeService extends IThemeService.Stub {
        }

        if (request.getWallpaperThemePackageName() != null) {
            if (updateWallpaper(request.getWallpaperThemePackageName())) {
            if (updateWallpaper(request.getWallpaperThemePackageName(),
                    request.getWallpaperId())) {
                mWallpaperChangedByUs = true;
            }
            incrementProgress(progressIncrement);
@@ -498,6 +499,12 @@ public class ThemeService extends IThemeService.Stub {
            if (selectionArgs[0] == null) {
                continue; // No equivalence between mixnmatch and theme
            }

            // Add component ID for multiwallpaper
            if (ThemesColumns.MODIFIES_LAUNCHER.equals(component)) {
                values.put(MixnMatchColumns.COL_COMPONENT_ID, request.getWallpaperId());
            }

            mContext.getContentResolver().update(MixnMatchColumns.CONTENT_URI, values, where,
                    selectionArgs);
        }
@@ -685,7 +692,7 @@ public class ThemeService extends IThemeService.Stub {
        return true;
    }

    private boolean updateWallpaper(String pkgName) {
    private boolean updateWallpaper(String pkgName, long id) {
        WallpaperManager wm = WallpaperManager.getInstance(mContext);
        if (SYSTEM_DEFAULT.equals(pkgName)) {
            try {
@@ -702,7 +709,7 @@ public class ThemeService extends IThemeService.Stub {
        } else {
            InputStream in = null;
            try {
                in = ImageUtils.getCroppedWallpaperStream(pkgName, mContext);
                in = ImageUtils.getCroppedWallpaperStream(pkgName, id, mContext);
                if (in != null)
                    wm.setStream(in);
            } catch (Exception e) {