summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Mast <andy@cyngn.com>2014-04-30 15:31:31 -0700
committerAndy Mast <andy@cyngn.com>2014-05-17 21:07:14 -0700
commit4456de181af115c60aac4696639dc70e162882ce (patch)
tree5295d2b09257e7edadead6c792e11f46b17c576e /src
parentdda7d285c2b77770d09ad2abaf4fa09f909d4636 (diff)
downloadandroid_packages_providers_ThemesProvider-4456de181af115c60aac4696639dc70e162882ce.zip
android_packages_providers_ThemesProvider-4456de181af115c60aac4696639dc70e162882ce.tar.gz
android_packages_providers_ThemesProvider-4456de181af115c60aac4696639dc70e162882ce.tar.bz2
Themes: Support launcher based icon packs [2/2]
Before this patch, icon packs written for Trebuchet/Nova/Apex could not be used with the new theme engine as the formats were different. For full description, see [1/2] in frameworks/base Change-Id: Ifaec3c4b459a74eab19c69a086e117b96aeb3e0f
Diffstat (limited to 'src')
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemePackageHelper.java50
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java15
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemesProvider.java4
3 files changed, 66 insertions, 3 deletions
diff --git a/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java b/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
index 7a6fe42..bc367e0 100644
--- a/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
+++ b/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
@@ -19,6 +19,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.pm.LegacyThemeInfo;
import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ThemeInfo;
import android.content.res.AssetManager;
@@ -68,6 +69,11 @@ public class ThemePackageHelper {
insertPackageInternal(context, pi, capabilities);
} else if (pi.legacyThemeInfos != null && pi.legacyThemeInfos.length > 0) {
insertLegacyPackageInternal(context, pi, capabilities);
+ } else if (pi.isLegacyIconPackApk){
+ // We must be here because it is a legacy icon pack
+ capabilities = new HashMap<String, Boolean>();
+ capabilities.put(ThemesColumns.MODIFIES_ICONS, true);
+ insertLegacyIconPackInternal(context, pi, capabilities);
}
return true;
}
@@ -119,6 +125,30 @@ public class ThemePackageHelper {
context.getContentResolver().insert(ThemesColumns.CONTENT_URI, values);
}
+ private static void insertLegacyIconPackInternal(Context context, PackageInfo pi,
+ Map<String, Boolean> capabilities) {
+ PackageManager pm = context.getPackageManager();
+ CharSequence labelName = pm.getApplicationLabel(pi.applicationInfo);
+ if (labelName == null) labelName = context.getString(R.string.unknown_app_name);
+
+ ContentValues values = new ContentValues();
+ values.put(ThemesColumns.PKG_NAME, pi.packageName);
+ values.put(ThemesColumns.TITLE, labelName.toString());
+ values.put(ThemesColumns.AUTHOR, "");
+ values.put(ThemesColumns.DATE_CREATED, System.currentTimeMillis());
+ values.put(ThemesColumns.LAST_UPDATE_TIME, pi.lastUpdateTime);
+ values.put(ThemesColumns.IS_LEGACY_ICONPACK, 1);
+
+ // Insert theme capabilities
+ for (Map.Entry<String, Boolean> entry : capabilities.entrySet()) {
+ String component = entry.getKey();
+ Boolean isImplemented = entry.getValue();
+ values.put(component, isImplemented);
+ }
+
+ context.getContentResolver().insert(ThemesColumns.CONTENT_URI, values);
+ }
+
public static void updatePackage(Context context, String pkgName) throws NameNotFoundException {
PackageInfo pi = context.getPackageManager().getPackageInfo(pkgName, 0);
Map<String, Boolean> capabilities = getCapabilities(context, pkgName);
@@ -126,6 +156,8 @@ public class ThemePackageHelper {
updatePackageInternal(context, pi, capabilities);
} else if (pi.legacyThemeInfos != null && pi.legacyThemeInfos.length > 0) {
updateLegacyPackageInternal(context, pi, capabilities);
+ } else if (pi.isLegacyIconPackApk) {
+ updateLegacyIconPackInternal(context, pi, capabilities);
}
}
@@ -164,6 +196,24 @@ public class ThemePackageHelper {
context.getContentResolver().update(ThemesColumns.CONTENT_URI, values, where, args);
}
+ private static void updateLegacyIconPackInternal(Context context, PackageInfo pi,
+ Map<String, Boolean> capabilities) {
+ PackageManager pm = context.getPackageManager();
+ CharSequence labelName = pm.getApplicationLabel(pi.applicationInfo);
+ if (labelName == null) labelName = context.getString(R.string.unknown_app_name);
+
+ boolean isPresentableTheme = ThemePackageHelper.isPresentableTheme(capabilities);
+ ContentValues values = new ContentValues();
+ values.put(ThemesColumns.PKG_NAME, pi.packageName);
+ values.put(ThemesColumns.TITLE, labelName.toString());
+ values.put(ThemesColumns.DATE_CREATED, System.currentTimeMillis());
+ values.put(ThemesColumns.LAST_UPDATE_TIME, pi.lastUpdateTime);
+
+ String where = ThemesColumns.PKG_NAME + "=?";
+ String[] args = { pi.packageName };
+ context.getContentResolver().update(ThemesColumns.CONTENT_URI, values, where, args);
+ }
+
public static void removePackage(Context context, String pkgToRemove) {
// Check currently applied components (fonts, wallpapers etc) and verify the theme is still
// installed if it is not installed, we need to set the component back to the default theme
diff --git a/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java b/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
index 915f465..95e4905 100644
--- a/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
+++ b/src/org/cyanogenmod/themes/provider/ThemesOpenHelper.java
@@ -28,7 +28,7 @@ import android.util.Log;
public class ThemesOpenHelper extends SQLiteOpenHelper {
private static final String TAG = ThemesOpenHelper.class.getName();
- private static final int DATABASE_VERSION = 3;
+ private static final int DATABASE_VERSION = 4;
private static final String DATABASE_NAME = "themes.db";
private static final String DEFAULT_PKG_NAME = "default";
@@ -57,6 +57,10 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
upgradeToVersion3(db);
oldVersion = 3;
}
+ if (oldVersion == 3) {
+ upgradeToVersion4(db);
+ oldVersion = 4;
+ }
if (oldVersion != DATABASE_VERSION) {
Log.e(TAG, "Recreating db because unknown database version: " + oldVersion);
dropTables(db);
@@ -85,6 +89,13 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
db.insert(MixnMatchTable.TABLE_NAME, null, values);
}
+ private void upgradeToVersion4(SQLiteDatabase db) {
+ String isLegacyIconPackColumn = String.format("ALTER TABLE %s" +
+ " ADD COLUMN %s INTEGER DEFAULT 0",
+ ThemesTable.TABLE_NAME, ThemesColumns.IS_LEGACY_ICONPACK);
+ db.execSQL(isLegacyIconPackColumn);
+ }
+
private void dropTables(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + ThemesTable.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + MixnMatchTable.TABLE_NAME);
@@ -121,6 +132,7 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
ThemesColumns.MODIFIES_OVERLAYS + " INTEGER DEFAULT 0, " +
ThemesColumns.PRESENT_AS_THEME + " INTEGER DEFAULT 0, " +
ThemesColumns.IS_LEGACY_THEME + " INTEGER DEFAULT 0," +
+ ThemesColumns.IS_LEGACY_ICONPACK + " INTEGER DEFAULT 0," +
ThemesColumns.LAST_UPDATE_TIME + " INTEGER DEFAULT 0" +
")";
@@ -146,6 +158,7 @@ public class ThemesOpenHelper extends SQLiteOpenHelper {
values.put(ThemesColumns.MODIFIES_RINGTONES, 1);
values.put(ThemesColumns.PRESENT_AS_THEME, 1);
values.put(ThemesColumns.IS_LEGACY_THEME, 0);
+ values.put(ThemesColumns.IS_LEGACY_ICONPACK, 0);
values.put(ThemesColumns.MODIFIES_OVERLAYS, 1);
db.insert(TABLE_NAME, null, values);
}
diff --git a/src/org/cyanogenmod/themes/provider/ThemesProvider.java b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
index 6c70709..03c8d44 100644
--- a/src/org/cyanogenmod/themes/provider/ThemesProvider.java
+++ b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
@@ -15,6 +15,7 @@
*/
package org.cyanogenmod.themes.provider;
+
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
@@ -36,7 +37,6 @@ import android.provider.ThemesContract.MixnMatchColumns;
import android.provider.ThemesContract.ThemesColumns;
import android.util.Log;
-import org.cyanogenmod.themes.provider.AppReceiver;
import org.cyanogenmod.themes.provider.ThemesOpenHelper.MixnMatchTable;
import org.cyanogenmod.themes.provider.ThemesOpenHelper.ThemesTable;
@@ -283,7 +283,7 @@ public class ThemesProvider extends ContentProvider {
List<PackageInfo> themePackages = new ArrayList<PackageInfo>();
Map<String, PackageInfo> pmThemes = new HashMap<String, PackageInfo>();
for (PackageInfo info : packages) {
- if (info.isThemeApk || info.isLegacyThemeApk) {
+ if (info.isThemeApk || info.isLegacyThemeApk || info.isLegacyIconPackApk) {
themePackages.add(info);
pmThemes.put(info.packageName, info);
}