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

Commit 171a7438 authored by d34d's avatar d34d Committed by Gerrit Code Review
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 d2e4bae8
Loading
Loading
Loading
Loading
+38 −31
Original line number Diff line number Diff line
@@ -78,6 +78,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";
@@ -972,8 +973,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
        final PackageManager pm = 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());
@@ -1008,6 +1011,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
                        }
                    }
                }
                if (partner.hideDefaultWallpaper()) {
                    hideDefault = true;
                }
            }
        }

        Pair<ApplicationInfo, Integer> r = getWallpaperArrayResourceId();
@@ -1019,7 +1026,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 =
                    (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
+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
@@ -54,20 +56,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
@@ -50,6 +50,7 @@ import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

/**
 * Various utilities shared amongst the Launcher's classes.
@@ -561,6 +562,29 @@ public final class Utilities {
        return null;
    }

    /*
     * 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;
    }

    public static float convertDpToPixel(float dp, Context context){
        Resources resources = context.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();