summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard MacGregor <rmacgregor@cyngn.com>2015-05-21 23:00:39 (GMT)
committerRichard MacGregor <rmacgregor@cyngn.com>2015-05-29 00:25:21 (GMT)
commit93634c9468b4c466c3ed4604ffd7285bd40f5e12 (patch)
tree72cab54e85b4202ac2c13d73795fad8d166025df /src
parent0d4fca36a06c9b03005a4c8ccc55e152849beff8 (diff)
downloadandroid_packages_providers_ThemesProvider-93634c9468b4c466c3ed4604ffd7285bd40f5e12.zip
android_packages_providers_ThemesProvider-93634c9468b4c466c3ed4604ffd7285bd40f5e12.tar.gz
android_packages_providers_ThemesProvider-93634c9468b4c466c3ed4604ffd7285bd40f5e12.tar.bz2
Delete preview table rows on theme update
Handle the case where a theme is updated with less wallpapers than it had when originally installed. Delete the rows for previews associated with the updated theme Change-Id: I79abf4d69f7656cbff2c0847cd3f82a737f9e6c2
Diffstat (limited to 'src')
-rw-r--r--src/org/cyanogenmod/themes/provider/PreviewGenerationService.java8
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemesProvider.java31
2 files changed, 34 insertions, 5 deletions
diff --git a/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java b/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java
index c1c0b16..bf838d9 100644
--- a/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java
+++ b/src/org/cyanogenmod/themes/provider/PreviewGenerationService.java
@@ -30,6 +30,7 @@ import android.os.Bundle;
import android.os.FileUtils;
import android.provider.ThemesContract.ThemesColumns;
import android.provider.ThemesContract.PreviewColumns;
+import android.text.TextUtils;
import android.util.Log;
import org.cyanogenmod.themes.provider.util.BootAnimationPreviewGenerator;
import org.cyanogenmod.themes.provider.util.IconPreviewGenerator;
@@ -179,6 +180,7 @@ public class PreviewGenerationService extends IntentService {
filesDir + File.separator + PREVIEWS_DIR + File.separator + pkgName;
String path = null;
clearThemePreviewsDir(themePreviewsDir);
+ clearThemeFromPreviewDB(resolver, pkgName);
if (items != null) {
path = compressAndSavePng(items.statusbarBackground, filesDir, pkgName,
@@ -443,6 +445,12 @@ public class PreviewGenerationService extends IntentService {
directory.delete();
}
+ private static void clearThemeFromPreviewDB(ContentResolver resolver, String pkgName) {
+ String selection = ThemesColumns.PKG_NAME + "=?";
+ String[] selectionArgs = new String[]{ String.valueOf(pkgName) };
+ resolver.delete(PreviewColumns.CONTENT_URI, selection, selectionArgs);
+ }
+
private static Cursor queryTheme(Context context, String pkgName) {
String selection = ThemesColumns.PKG_NAME + "=?";
String[] selectionArgs = { pkgName };
diff --git a/src/org/cyanogenmod/themes/provider/ThemesProvider.java b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
index 384d814..418faf0 100644
--- a/src/org/cyanogenmod/themes/provider/ThemesProvider.java
+++ b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
@@ -102,15 +102,20 @@ public class ThemesProvider extends ContentProvider {
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
+ SQLiteDatabase sqlDB = null;
+ int idx = -1;
+ String[] columns = null;
+ Cursor c = null;
+ int rowsDeleted = 0;
int match = sUriMatcher.match(uri);
switch (match) {
case THEMES:
- SQLiteDatabase sqlDB = mDatabase.getWritableDatabase();
+ sqlDB = mDatabase.getWritableDatabase();
// Get the theme's _id and delete preview images
- int idx = -1;
- String[] columns = new String[] { ThemesColumns._ID, ThemesColumns.PKG_NAME };
- Cursor c = sqlDB.query(ThemesTable.TABLE_NAME, columns, selection,
+ idx = -1;
+ columns = new String[] { ThemesColumns._ID, ThemesColumns.PKG_NAME };
+ c = sqlDB.query(ThemesTable.TABLE_NAME, columns, selection,
selectionArgs, null, null, null);
if (c == null) return 0;
if (c.moveToFirst()) {
@@ -128,9 +133,25 @@ public class ThemesProvider extends ContentProvider {
}
c.close();
- int rowsDeleted = sqlDB.delete(ThemesTable.TABLE_NAME, selection, selectionArgs);
+ rowsDeleted = sqlDB.delete(ThemesTable.TABLE_NAME, selection, selectionArgs);
getContext().getContentResolver().notifyChange(uri, null);
return rowsDeleted;
+ case PREVIEWS:
+ sqlDB = mDatabase.getWritableDatabase();
+
+ // Get the theme's _id and delete preview images
+ idx = -1;
+ columns = new String[] { ThemesColumns._ID };
+ c = sqlDB.query(ThemesTable.TABLE_NAME, columns, selection,
+ selectionArgs, null, null, null);
+ if (c == null) return 0;
+ if (c.moveToFirst()) {
+ idx = c.getColumnIndex(ThemesColumns._ID);
+ rowsDeleted = sqlDB.delete(PreviewsTable.TABLE_NAME,
+ PreviewColumns.THEME_ID + "=" + c.getInt(idx), null);
+ }
+ c.close();
+ return rowsDeleted;
case MIXNMATCH:
throw new UnsupportedOperationException("Cannot delete rows in MixNMatch table");
}