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

Commit 93e949f1 authored by d34d's avatar d34d
Browse files

Wallpaper: Allow multiple partners to be loaded

Current implementation only allowed for one partner, and any
additional partner wallpapers would not be loaded.
Partrner.get() still returns the first partner and a new method,
getAllPartners is introduced which returns a list of all partners.

Change-Id: I06b6cd4817d3f812e2110967f075d68ee31cb318
parent cb3431d1
Loading
Loading
Loading
Loading
+38 −31
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class WallpaperPickerActivity extends WallpaperCropActivity {
    static final String TAG = "Launcher.WallpaperPickerActivity";
@@ -927,8 +928,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
        final PackageManager pm = getContext().getPackageManager();
        final ArrayList<WallpaperTileInfo> bundled = new ArrayList<WallpaperTileInfo>(24);

        Partner partner = Partner.get(pm);
        if (partner != null) {
        List<Partner> partners = Partner.getAllPartners(pm);
        boolean hideDefault = false;
        if (partners != null) {
            for (Partner partner : partners) {
                final Resources partnerRes = partner.getResources();
                final int resId = partnerRes.getIdentifier(Partner.RES_WALLPAPERS, "array",
                        partner.getPackageName());
@@ -963,6 +966,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
                        }
                    }
                }
                if (partner.hideDefaultWallpaper()) {
                    hideDefault = true;
                }
            }
        }

        Pair<ApplicationInfo, Integer> r = getWallpaperArrayResourceId();
@@ -975,7 +982,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
            }
        }

        if (partner == null || !partner.hideDefaultWallpaper()) {
        if (!hideDefault) {
            // Add an entry for the default wallpaper (stored in system resources)
            WallpaperTileInfo defaultWallpaperInfo = Utilities.ATLEAST_KITKAT
                    ? getDefaultWallpaper() : getPreKKDefaultWallpaperInfo();
+21 −6
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.util.Log;
import android.util.Pair;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Utilities to discover and interact with partner customizations. There can
@@ -52,20 +54,33 @@ public class Partner {
    public static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";

    private static boolean sSearched = false;
    private static Partner sPartner;
    private static List<Partner> sPartners;

    static {
        sPartners = new ArrayList<Partner>();
    }

    /**
     * Find and return partner details, or {@code null} if none exists.
     * Find and return first partner details, or {@code null} if none exists.
     */
    public static synchronized Partner get(PackageManager pm) {
        getAllPartners(pm);
        return sPartners.size() > 0 ? sPartners.get(0) : null;
    }

    /**
     * Find and return all partner details, or {@code null} if none exists.
     */
    public static synchronized List<Partner> getAllPartners(PackageManager pm) {
        if (!sSearched) {
            Pair<String, Resources> apkInfo = Utilities.findSystemApk(ACTION_PARTNER_CUSTOMIZATION, pm);
            if (apkInfo != null) {
                sPartner = new Partner(apkInfo.first, apkInfo.second);
            List<Pair<String, Resources>> apkInfos =
                    Utilities.findSystemApks(ACTION_PARTNER_CUSTOMIZATION, pm);
            for (Pair<String, Resources> apkInfo : apkInfos) {
                sPartners.add(new Partner(apkInfo.first, apkInfo.second));
            }
            sSearched = true;
        }
        return sPartner;
        return sPartners;
    }

    private final String mPackageName;
+24 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import com.android.launcher3.settings.SettingsProvider;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Matcher;
@@ -527,6 +528,29 @@ public final class Utilities {
        }
    }

    /*
     * Finds all system apks which had a broadcast receiver listening to a particular action.
     * @param action intent action used to find the apk
     * @return a list of pairs of apk package name and the resources.
     */
    static List<Pair<String, Resources>> findSystemApks(String action, PackageManager pm) {
        final Intent intent = new Intent(action);
        List<Pair<String, Resources>> systemApks = new ArrayList<Pair<String, Resources>>();
        for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
            if (info.activityInfo != null &&
                    (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                final String packageName = info.activityInfo.packageName;
                try {
                    final Resources res = pm.getResourcesForApplication(packageName);
                    systemApks.add(Pair.create(packageName, res));
                } catch (NameNotFoundException e) {
                    Log.w(TAG, "Failed to find resources for " + packageName);
                }
            }
        }
        return systemApks;
    }

    /**
     * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
     * provided by the same package which is set to be global search activity.