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

Commit 581697fc authored by Clark Scheff's avatar Clark Scheff Committed by Brint E. Kriebel
Browse files

CM11 Themes: load wp from apk if uri is null

When setting a default theme on first start, the provider may
not have processed the theme and the uri for the wp will be null.
If this happens try to load the wallpaper from the themes assets.

Change-Id: I883b9dd796920e66e4729e78d41cd8899916fa42
(cherry picked from commit fd55c3e3)
parent 501aef3c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -508,6 +508,12 @@ public class ThemeUtils {
        return null;
    }

    public static String getWallpaperPath(AssetManager assetManager) throws IOException {
        String[] assets = assetManager.list("wallpapers");
        if (assets == null || assets.length == 0) return null;
        return "wallpapers/" + assets[0];
    }

    public static String getDefaultThemePackageName(Context context) {
        final String defaultThemePkg = Settings.Secure.getString(context.getContentResolver(),
                Settings.Secure.DEFAULT_THEME_PACKAGE);
+17 −3
Original line number Diff line number Diff line
@@ -507,11 +507,25 @@ public class ThemeService extends IThemeService.Stub {
                        c.getColumnIndex(ThemesContract.ThemesColumns.IS_LEGACY_THEME)) == 1;
                if (!isLegacyTheme) {
                    String wallpaper = c.getString(c.getColumnIndex(ThemesContract.ThemesColumns.WALLPAPER_URI));
                    if (wallpaper != null) {
                        if (URLUtil.isAssetUrl(wallpaper)) {
                            in = ThemeUtils.getInputStreamFromAsset(themeContext, wallpaper);
                        } else {
                            in = mContext.getContentResolver().openInputStream(Uri.parse(wallpaper));
                        }
                    } else {
                        // try and get the wallpaper directly from the apk if the URI was null
                        Context themeCtx = mContext.createPackageContext(mPkgName,
                                Context.CONTEXT_IGNORE_SECURITY);
                        AssetManager assetManager = themeCtx.getAssets();
                        String wpPath = ThemeUtils.getWallpaperPath(assetManager);
                        if (wpPath == null) {
                            Log.w(TAG, "Not setting wp because wallpaper file was not found.");
                            return false;
                        }
                        in = ThemeUtils.getInputStreamFromAsset(themeCtx, "file:///android_asset/"
                                + wpPath);
                    }
                    WallpaperManager.getInstance(mContext).setStream(in);
                } else {
                    PackageManager pm = mContext.getPackageManager();