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

Commit f4d01799 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Moving getWallpaperArrayResourceId to a separate functions, so that

it can be overriden by dependent projects

Change-Id: I565d85d9126e41cec3dd2cdb8f2c75283bce4b13
parent 7f9e00a4
Loading
Loading
Loading
Loading
+24 −11
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.util.Pair;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuInflater;
@@ -478,17 +479,15 @@ public class WallpaperPickerActivity extends WallpaperCropActivity
            }
        }

        // Context.getPackageName() may return the "original" package name,
        // com.android.launcher3; Resources needs the real package name,
        // com.android.launcher3. So we ask Resources for what it thinks the
        // package name should be.
        Pair<ApplicationInfo, Integer> r = getWallpaperArrayResourceId();
        if (r != null) {
            try {
            final String packageName = getResources().getResourcePackageName(R.array.wallpapers);
            ApplicationInfo info = getPackageManager().getApplicationInfo(packageName, 0);
                Resources wallpaperRes = getContext().getPackageManager()
                    .getResourcesForApplication(info);
            addWallpapers(bundled, wallpaperRes, info.packageName, R.array.wallpapers);
        } catch (PackageManager.NameNotFoundException e) { }
                        .getResourcesForApplication(r.first);
                addWallpapers(bundled, wallpaperRes, r.first.packageName, r.second);
            } catch (PackageManager.NameNotFoundException e) {
            }
        }

        if (partner == null || !partner.hideDefaultWallpaper()) {
            // Add an entry for the default wallpaper (stored in system resources)
@@ -500,6 +499,20 @@ public class WallpaperPickerActivity extends WallpaperCropActivity
        return bundled;
    }

    public Pair<ApplicationInfo, Integer> getWallpaperArrayResourceId() {
        // Context.getPackageName() may return the "original" package name,
        // com.android.launcher3; Resources needs the real package name,
        // com.android.launcher3. So we ask Resources for what it thinks the
        // package name should be.
        final String packageName = getResources().getResourcePackageName(R.array.wallpapers);
        try {
            ApplicationInfo info = getContext().getPackageManager().getApplicationInfo(packageName, 0);
            return new Pair<ApplicationInfo, Integer>(info, R.array.wallpapers);
        } catch (PackageManager.NameNotFoundException e) {
            return null;
        }
    }

    private void addWallpapers(ArrayList<WallpaperTileInfo> known, Resources res,
            String packageName, int listResId) {
        final String[] extras = res.getStringArray(listResId);