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

Commit 750c44fe authored by Clark Scheff's avatar Clark Scheff Committed by Gerrit Code Review
Browse files

Themes: Allow clearing the wallpaper and ls wallpaper

By providing an empty string for the MODS_LAUNCHER and
MODS_LOCKSCREEN components, the theme service will clear out any
existing wallpaper the user had set.  This provides the same
functionality as if the user was picking "No wallpaper" from the
picker.

Change-Id: I0c349ad4afa2bcef2c302105315709786510c0aa
parent eee4e973
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -1221,7 +1221,18 @@ public class WallpaperManager {
     * wallpaper.
     */
    public void clear() throws IOException {
        clear(true);
    }

    /** @hide */
    public void clear(boolean setToDefault) throws IOException {
        if (setToDefault) {
            setResource(com.android.internal.R.drawable.default_wallpaper);
        } else {
            Bitmap blackBmp = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565);
            blackBmp.setPixel(0, 0, mContext.getResources().getColor(android.R.color.black));
            setBitmap(blackBmp);
        }
    }

    /**
+15 −7
Original line number Diff line number Diff line
@@ -473,11 +473,14 @@ public class ThemeService extends IThemeService.Stub {
    }

    private boolean setCustomLockScreenWallpaper(String pkgName) {
        WallpaperManager wm = WallpaperManager.getInstance(mContext);
        try {
            if (HOLO_DEFAULT.equals(pkgName)) {
                final Bitmap bmp = BitmapFactory.decodeResource(mContext.getResources(),
                        com.android.internal.R.drawable.default_wallpaper);
                WallpaperManager.getInstance(mContext).setKeyguardBitmap(bmp);
                wm.setKeyguardBitmap(bmp);
            } else if (TextUtils.isEmpty(pkgName)) {
                wm.clearKeyguardWallpaper();
            } else {
                //Get input WP stream from the theme
                Context themeCtx = mContext.createPackageContext(pkgName,
@@ -491,7 +494,7 @@ public class ThemeService extends IThemeService.Stub {
                InputStream is = ThemeUtils.getInputStreamFromAsset(themeCtx,
                        "file:///android_asset/" + wpPath);

                WallpaperManager.getInstance(mContext).setKeyguardStream(is);
                wm.setKeyguardStream(is);
            }
        } catch (Exception e) {
            Log.e(TAG, "There was an error setting lockscreen wp for pkg " + pkgName, e);
@@ -507,10 +510,16 @@ public class ThemeService extends IThemeService.Stub {
                null, selection,
                selectionArgs, null);
        c.moveToFirst();

        WallpaperManager wm = WallpaperManager.getInstance(mContext);
        if (HOLO_DEFAULT.equals(pkgName)) {
            try {
                WallpaperManager.getInstance(mContext).clear();
                wm.clear();
            } catch (IOException e) {
                return false;
            }
        } else if (TextUtils.isEmpty(pkgName)) {
            try {
                wm.clear(false);
            } catch (IOException e) {
                return false;
            }
@@ -544,13 +553,12 @@ public class ThemeService extends IThemeService.Stub {
                        in = ThemeUtils.getInputStreamFromAsset(themeCtx, "file:///android_asset/"
                                + wpPath);
                    }
                    WallpaperManager.getInstance(mContext).setStream(in);
                    wm.setStream(in);
                } else {
                    PackageManager pm = mContext.getPackageManager();
                    PackageInfo pi = pm.getPackageInfo(pkgName, 0);
                    if (pi.legacyThemeInfos != null && pi.legacyThemeInfos.length > 0) {
                        WallpaperManager.getInstance(themeContext)
                                .setResource(pi.legacyThemeInfos[0].wallpaperResourceId);
                        wm.setResource(pi.legacyThemeInfos[0].wallpaperResourceId);
                    } else {
                        return false;
                    }