summaryrefslogtreecommitdiffstats
path: root/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2015-03-02 15:31:05 -0800
committerd34d <clark@cyngn.com>2015-03-03 13:36:04 -0800
commitd56651ee27f618762440fa0efe5b16c137814854 (patch)
tree14762526351fb0c79f2136d1b0f0ae20ad3148e0 /src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
parent59c61579c13cb257e603c28b1c51f6eff64fe2dc (diff)
downloadandroid_packages_providers_ThemesProvider-d56651ee27f618762440fa0efe5b16c137814854.tar.gz
android_packages_providers_ThemesProvider-d56651ee27f618762440fa0efe5b16c137814854.tar.bz2
android_packages_providers_ThemesProvider-d56651ee27f618762440fa0efe5b16c137814854.zip
Themes: Update ThemesContract with install state [2/3]
This provider will be responsible for keeping track of the installed state of themes. This includes two intermedite states, INSTALLING and UPDATING. When a theme is installed from PackageManager the provider will receive this broadcast and add the theme to its DB and set the state to INSTALLING if the ThemeService is processing the theme, or INSTALLED if not and broadcast the ACTION_THEME_INSTALLED action. When a theme is updated the provider will receive another broadcast indicating that the current version of the theme is being replaced. If the ThemeService needs to do some processing, we'll update the state to UPDATING. Once the theme service is done processing a theme, the provider will receive a broadcast from the ThemeService. At this point, the themes provider will update the state to INSTALLED, if it is not already set to that state. The provider will broadcast the ACTION_THEME_INSTALLED action if the previous state was INSTALLING and the ACTION_THEME_UPDATED action if the previous state was UPDATING. Change-Id: Ie37f85463e472d96b8393801007537db1e3eefc6
Diffstat (limited to 'src/org/cyanogenmod/themes/provider/ThemePackageHelper.java')
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemePackageHelper.java39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java b/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
index 053473e..254e658 100644
--- a/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
+++ b/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
@@ -15,6 +15,7 @@
*/
package org.cyanogenmod.themes.provider;
+import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.pm.PackageInfo;
@@ -31,7 +32,9 @@ import android.database.Cursor;
import android.provider.ThemesContract;
import android.provider.ThemesContract.MixnMatchColumns;
import android.provider.ThemesContract.ThemesColumns;
+import android.provider.ThemesContract.ThemesColumns.InstallState;
import android.util.Log;
+import org.cyanogenmod.themes.provider.util.ProviderUtils;
import java.io.IOException;
import java.util.Collections;
@@ -66,7 +69,7 @@ public class ThemePackageHelper {
"overlays/com.android.systemui");
}
- public static boolean insertPackage(Context context, String pkgName, boolean processPreviews)
+ public static boolean insertPackage(Context context, String pkgName, boolean isProcessing)
throws NameNotFoundException {
PackageInfo pi = context.getPackageManager().getPackageInfo(pkgName, 0);
if (pi == null)
@@ -74,18 +77,18 @@ public class ThemePackageHelper {
Map<String, Boolean> capabilities = getCapabilities(context, pkgName);
if (pi.themeInfo != null) {
- insertPackageInternal(context, pi, capabilities, processPreviews);
+ insertPackageInternal(context, pi, capabilities, isProcessing);
} 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,processPreviews);
+ insertLegacyIconPackInternal(context, pi, capabilities, isProcessing);
}
return true;
}
private static void insertPackageInternal(Context context, PackageInfo pi,
- Map<String, Boolean> capabilities, boolean processPreviews) {
+ Map<String, Boolean> capabilities, boolean isProcessing) {
ThemeInfo info = pi.themeInfo;
boolean isPresentableTheme = isPresentableTheme(capabilities);
@@ -100,8 +103,9 @@ public class ThemePackageHelper {
ThemeUtils.getDefaultThemePackageName(context).equals(pi.packageName) ? 1 : 0);
values.put(ThemesColumns.LAST_UPDATE_TIME, pi.lastUpdateTime);
values.put(ThemesColumns.INSTALL_TIME, pi.firstInstallTime);
- values.put(ThemesProvider.KEY_PROCESS_PREVIEWS, processPreviews);
values.put(ThemesColumns.TARGET_API, pi.applicationInfo.targetSdkVersion);
+ values.put(ThemesColumns.INSTALL_STATE, isProcessing ? InstallState.INSTALLING :
+ InstallState.INSTALLED);
// Insert theme capabilities
insertCapabilities(capabilities, values);
@@ -110,7 +114,7 @@ public class ThemePackageHelper {
}
private static void insertLegacyIconPackInternal(Context context, PackageInfo pi,
- Map<String, Boolean> capabilities, boolean processPreviews) {
+ Map<String, Boolean> capabilities, boolean isProcessing) {
PackageManager pm = context.getPackageManager();
CharSequence labelName = pm.getApplicationLabel(pi.applicationInfo);
if (labelName == null) labelName = context.getString(R.string.unknown_app_name);
@@ -123,8 +127,9 @@ public class ThemePackageHelper {
values.put(ThemesColumns.LAST_UPDATE_TIME, pi.lastUpdateTime);
values.put(ThemesColumns.INSTALL_TIME, pi.firstInstallTime);
values.put(ThemesColumns.IS_LEGACY_ICONPACK, 1);
- values.put(ThemesProvider.KEY_PROCESS_PREVIEWS, processPreviews);
values.put(ThemesColumns.TARGET_API, pi.applicationInfo.targetSdkVersion);
+ values.put(ThemesColumns.INSTALL_STATE, isProcessing ? InstallState.INSTALLING :
+ InstallState.INSTALLED);
// Insert theme capabilities
insertCapabilities(capabilities, values);
@@ -132,16 +137,17 @@ public class ThemePackageHelper {
context.getContentResolver().insert(ThemesColumns.CONTENT_URI, values);
}
- public static void updatePackage(Context context, String pkgName) throws NameNotFoundException {
+ public static void updatePackage(Context context, String pkgName, boolean isProcessing)
+ throws NameNotFoundException {
if (SYSTEM_DEFAULT.equals(pkgName)) {
updateSystemPackageInternal(context);
} else {
PackageInfo pi = context.getPackageManager().getPackageInfo(pkgName, 0);
Map<String, Boolean> capabilities = getCapabilities(context, pkgName);
if (pi.themeInfo != null) {
- updatePackageInternal(context, pi, capabilities);
+ updatePackageInternal(context, pi, capabilities, isProcessing);
} else if (pi.isLegacyIconPackApk) {
- updateLegacyIconPackInternal(context, pi, capabilities);
+ updateLegacyIconPackInternal(context, pi, capabilities, isProcessing);
}
// We should reapply any components that are currently applied for this theme.
@@ -150,7 +156,7 @@ public class ThemePackageHelper {
}
private static void updatePackageInternal(Context context, PackageInfo pi,
- Map<String, Boolean> capabilities) {
+ Map<String, Boolean> capabilities, boolean isProcessing) {
ThemeInfo info = pi.themeInfo;
boolean isPresentableTheme = ThemePackageHelper.isPresentableTheme(capabilities);
ContentValues values = new ContentValues();
@@ -164,6 +170,8 @@ public class ThemePackageHelper {
ThemeUtils.getDefaultThemePackageName(context).equals(pi.packageName) ? 1 : 0);
values.put(ThemesColumns.LAST_UPDATE_TIME, pi.lastUpdateTime);
values.put(ThemesColumns.INSTALL_TIME, pi.firstInstallTime);
+ values.put(ThemesColumns.INSTALL_STATE,
+ isProcessing ? InstallState.UPDATING : InstallState.INSTALLED);
// Insert theme capabilities
insertCapabilities(capabilities, values);
@@ -183,7 +191,7 @@ public class ThemePackageHelper {
}
private static void updateLegacyIconPackInternal(Context context, PackageInfo pi,
- Map<String, Boolean> capabilities) {
+ Map<String, Boolean> capabilities, boolean isProcessing) {
PackageManager pm = context.getPackageManager();
CharSequence labelName = pm.getApplicationLabel(pi.applicationInfo);
if (labelName == null) labelName = context.getString(R.string.unknown_app_name);
@@ -195,6 +203,8 @@ public class ThemePackageHelper {
values.put(ThemesColumns.DATE_CREATED, System.currentTimeMillis());
values.put(ThemesColumns.LAST_UPDATE_TIME, pi.lastUpdateTime);
values.put(ThemesColumns.INSTALL_TIME, pi.firstInstallTime);
+ values.put(ThemesColumns.INSTALL_STATE,
+ isProcessing ? InstallState.UPDATING : InstallState.INSTALLED);
String where = ThemesColumns.PKG_NAME + "=?";
String[] args = { pi.packageName };
@@ -240,7 +250,10 @@ public class ThemePackageHelper {
// Delete the theme from the db
String selection = ThemesColumns.PKG_NAME + "= ?";
String[] selectionArgs = { pkgToRemove };
- context.getContentResolver().delete(ThemesColumns.CONTENT_URI, selection, selectionArgs);
+ final ContentResolver resolver = context.getContentResolver();
+ if (resolver.delete(ThemesColumns.CONTENT_URI, selection, selectionArgs) > 0) {
+ ProviderUtils.sendThemeRemovedBroadcast(context, pkgToRemove);
+ }
}
/**