summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2015-07-15 00:19:16 (GMT)
committerd34d <clark@cyngn.com>2016-05-27 19:56:16 (GMT)
commit93e949f1a9931bf7188f4d2a43630603d7a388a8 (patch)
tree2a703665ea18868b7c9bb52aa3de8152dd7487c0
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
-rw-r--r--WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java69
-rw-r--r--src/com/android/launcher3/Partner.java27
-rw-r--r--src/com/android/launcher3/Utilities.java24
3 files changed, 83 insertions, 37 deletions
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
index abf2026..4047ae8 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -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,41 +928,47 @@ 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) {
- final Resources partnerRes = partner.getResources();
- final int resId = partnerRes.getIdentifier(Partner.RES_WALLPAPERS, "array",
- partner.getPackageName());
- if (resId != 0) {
- addWallpapers(bundled, partnerRes, partner.getPackageName(), resId);
- }
+ 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());
+ if (resId != 0) {
+ addWallpapers(bundled, partnerRes, partner.getPackageName(), resId);
+ }
- // Add system wallpapers
- File systemDir = partner.getWallpaperDirectory();
- if (systemDir != null && systemDir.isDirectory()) {
- for (File file : systemDir.listFiles()) {
- if (!file.isFile()) {
- continue;
- }
- String name = file.getName();
- int dotPos = name.lastIndexOf('.');
- String extension = "";
- if (dotPos >= -1) {
- extension = name.substring(dotPos);
- name = name.substring(0, dotPos);
- }
+ // Add system wallpapers
+ File systemDir = partner.getWallpaperDirectory();
+ if (systemDir != null && systemDir.isDirectory()) {
+ for (File file : systemDir.listFiles()) {
+ if (!file.isFile()) {
+ continue;
+ }
+ String name = file.getName();
+ int dotPos = name.lastIndexOf('.');
+ String extension = "";
+ if (dotPos >= -1) {
+ extension = name.substring(dotPos);
+ name = name.substring(0, dotPos);
+ }
- if (name.endsWith("_small")) {
- // it is a thumbnail
- continue;
- }
+ if (name.endsWith("_small")) {
+ // it is a thumbnail
+ continue;
+ }
- File thumbnail = new File(systemDir, name + "_small" + extension);
- Bitmap thumb = BitmapFactory.decodeFile(thumbnail.getAbsolutePath());
- if (thumb != null) {
- bundled.add(new FileWallpaperInfo(file, new BitmapDrawable(thumb)));
+ File thumbnail = new File(systemDir, name + "_small" + extension);
+ Bitmap thumb = BitmapFactory.decodeFile(thumbnail.getAbsolutePath());
+ if (thumb != null) {
+ bundled.add(new FileWallpaperInfo(file, new BitmapDrawable(thumb)));
+ }
}
}
+ if (partner.hideDefaultWallpaper()) {
+ hideDefault = true;
+ }
}
}
@@ -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();
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.