summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2015-07-14 17:19:16 -0700
committerd34d <clark@cyngn.com>2016-05-27 12:56:16 -0700
commit93e949f1a9931bf7188f4d2a43630603d7a388a8 (patch)
tree2a703665ea18868b7c9bb52aa3de8152dd7487c0 /src
parentcb3431d16c22bba38a6560640d1efa1807486add (diff)
downloadandroid_packages_apps_Trebuchet-93e949f1a9931bf7188f4d2a43630603d7a388a8.zip
android_packages_apps_Trebuchet-93e949f1a9931bf7188f4d2a43630603d7a388a8.tar.gz
android_packages_apps_Trebuchet-93e949f1a9931bf7188f4d2a43630603d7a388a8.tar.bz2
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
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/Partner.java27
-rw-r--r--src/com/android/launcher3/Utilities.java24
2 files changed, 45 insertions, 6 deletions
diff --git a/src/com/android/launcher3/Partner.java b/src/com/android/launcher3/Partner.java
index 380078b..564421d 100644
--- a/src/com/android/launcher3/Partner.java
+++ b/src/com/android/launcher3/Partner.java
@@ -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;
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 8ffc471..c7ff19f 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -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.