summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Mast <andy@cyngn.com>2014-06-04 15:05:12 -0700
committerAndy Mast <andy@cyngn.com>2014-06-04 16:11:20 -0700
commit71cd2fbaa9153fb7bd420974ef163cfe9978cf75 (patch)
treea955b1a32b41b55e962ef147d205bac473b46958 /src
parent3c8b34bd6e29a0318899746452201872e96abc3d (diff)
downloadandroid_packages_providers_ThemesProvider-71cd2fbaa9153fb7bd420974ef163cfe9978cf75.zip
android_packages_providers_ThemesProvider-71cd2fbaa9153fb7bd420974ef163cfe9978cf75.tar.gz
android_packages_providers_ThemesProvider-71cd2fbaa9153fb7bd420974ef163cfe9978cf75.tar.bz2
Cleanup cached preview images on uninstall
Change-Id: I9267a160fbabeb67ade2f18fdaf8d8c6acc539da
Diffstat (limited to 'src')
-rw-r--r--src/org/cyanogenmod/themes/provider/CopyImageService.java110
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemePackageHelper.java2
-rw-r--r--src/org/cyanogenmod/themes/provider/ThemesProvider.java16
3 files changed, 91 insertions, 37 deletions
diff --git a/src/org/cyanogenmod/themes/provider/CopyImageService.java b/src/org/cyanogenmod/themes/provider/CopyImageService.java
index 8a0362a..cbf7be2 100644
--- a/src/org/cyanogenmod/themes/provider/CopyImageService.java
+++ b/src/org/cyanogenmod/themes/provider/CopyImageService.java
@@ -37,7 +37,8 @@ import java.io.InputStream;
* Copies images from the theme APK to the local provider's cache
*/
public class CopyImageService extends IntentService {
-
+ public static final String ACTION_INSERT = "org.cyanogenmod.themes.provider.action.insert";
+ public static final String ACTION_DELETE = "org.cyanogenmod.themes.provider.action.delete";
public static final String EXTRA_PKG_NAME = "extra_pkg_name";
private static final String TAG = CopyImageService.class.getName();
@@ -59,47 +60,21 @@ public class CopyImageService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
-
- if (intent.getExtras() == null)
+ if (intent.getExtras() == null || intent.getExtras().getString(EXTRA_PKG_NAME) == null) {
+ Log.e(TAG, "No package name or extras provided");
return;
+ }
String pkgName = intent.getExtras().getString(EXTRA_PKG_NAME);
-
- if (pkgName != null) {
- generate(this, pkgName);
+ if (ACTION_INSERT.equals(intent.getAction())) {
+ createPreviewImages(this, pkgName);
+ insertPreviewValuesIntoDb(pkgName);
+ } else if (ACTION_DELETE.equals(intent.getAction())) {
+ deletePreviewImages(pkgName);
}
-
- String homescreen = Environment.getDataDirectory().getPath()
- + IMAGES_PATH + pkgName
- + ".homescreen.jpg";
- String lockscreen = Environment.getDataDirectory().getPath()
- + IMAGES_PATH + pkgName
- + ".lockscreen.jpg";
- String stylePreview = Environment.getDataDirectory().getPath()
- + IMAGES_PATH + pkgName
- + ".stylepreview.jpg";
- String wallpaper = ContentResolver.SCHEME_FILE + "://" + Environment.getDataDirectory().getPath()
- + WALLPAPER_PATH + pkgName
- + ".wallpaper1.jpg";
- Uri hsUri = Uri.parse(homescreen);
- Uri lsUri = Uri.parse(lockscreen);
- Uri wpUri = Uri.parse(wallpaper);
- Uri styleUri = Uri.parse(stylePreview);
-
- String where = ThemesColumns.PKG_NAME + "=?";
- String[] selectionArgs = { pkgName };
-
- ContentValues values = new ContentValues();
- values.put(ThemesColumns.HOMESCREEN_URI, hsUri.toString());
- values.put(ThemesColumns.LOCKSCREEN_URI, lsUri.toString());
- values.put(ThemesColumns.STYLE_URI, styleUri.toString());
- values.put(ThemesColumns.WALLPAPER_URI, "file:///android_asset/wallpapers/wallpaper1.jpg");
-
- getContentResolver().update(ThemesColumns.CONTENT_URI, values,
- where, selectionArgs);
}
- public static void generate(Context context, String pkgName) {
+ public static void createPreviewImages(Context context, String pkgName) {
// Presently this is just mocked up. IE We expect the theme APK to
// provide the bitmap.
Context themeContext = null;
@@ -159,6 +134,69 @@ public class CopyImageService extends IntentService {
}
}
+ private void insertPreviewValuesIntoDb(String pkgName) {
+ String homescreen = getHomeScreenPreviewPath(pkgName);
+ String lockscreen = getLockScreenPreviewPath(pkgName);
+ String stylePreview = getStylesPreviewPath(pkgName);
+ String wallpaper = getWallpaperPreviewPath(pkgName);
+
+ Uri hsUri = Uri.parse(homescreen);
+ Uri lsUri = Uri.parse(lockscreen);
+ Uri wpUri = Uri.parse(wallpaper);
+ Uri styleUri = Uri.parse(stylePreview);
+
+ String where = ThemesColumns.PKG_NAME + "=?";
+ String[] selectionArgs = { pkgName };
+
+ ContentValues values = new ContentValues();
+ values.put(ThemesColumns.HOMESCREEN_URI, hsUri.toString());
+ values.put(ThemesColumns.LOCKSCREEN_URI, lsUri.toString());
+ values.put(ThemesColumns.STYLE_URI, styleUri.toString());
+ values.put(ThemesColumns.WALLPAPER_URI, "file:///android_asset/wallpapers/wallpaper1.jpg");
+
+ getContentResolver().update(ThemesColumns.CONTENT_URI, values,
+ where, selectionArgs);
+ }
+
+ private void deletePreviewImages(String pkgName) {
+ File home = new File(getHomeScreenPreviewPath(pkgName));
+ home.delete();
+
+ File lockscreen = new File(getLockScreenPreviewPath(pkgName));
+ lockscreen.delete();
+
+ File style = new File(getStylesPreviewPath(pkgName));
+ style.delete();
+
+ File wallpaper = new File(getWallpaperPreviewPath(pkgName));
+ wallpaper.delete();
+ }
+
+ private static String getHomeScreenPreviewPath(String pkgName) {
+ return Environment.getDataDirectory().getPath()
+ + IMAGES_PATH + pkgName
+ + ".homescreen.jpg";
+ }
+
+ private static String getLockScreenPreviewPath(String pkgName) {
+ return Environment.getDataDirectory().getPath()
+ + IMAGES_PATH + pkgName
+ + ".lockscreen.jpg";
+ }
+
+ private static String getStylesPreviewPath(String pkgName) {
+ return Environment.getDataDirectory().getPath()
+ + IMAGES_PATH + pkgName
+ + ".stylepreview.jpg";
+ }
+
+ private static String getWallpaperPreviewPath(String pkgName) {
+ return ContentResolver.SCHEME_FILE + "://"
+ + Environment.getDataDirectory().getPath()
+ + WALLPAPER_PATH + pkgName
+ + ".wallpaper1.jpg";
+ }
+
private static InputStream getPreviewAsset(AssetManager am, String preview) throws IOException {
InputStream is = null;
try {
diff --git a/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java b/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
index ed1a740..74e4aa6 100644
--- a/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
+++ b/src/org/cyanogenmod/themes/provider/ThemePackageHelper.java
@@ -240,7 +240,7 @@ public class ThemePackageHelper {
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
+ // installed. If it is not installed, we need to set the component back to the default theme
List<String> moveToDefault = new LinkedList<String>(); // components to move back to default
Cursor mixnmatch = context.getContentResolver().query(MixnMatchColumns.CONTENT_URI, null,
null, null, null);
diff --git a/src/org/cyanogenmod/themes/provider/ThemesProvider.java b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
index 4154b3e..ba50d72 100644
--- a/src/org/cyanogenmod/themes/provider/ThemesProvider.java
+++ b/src/org/cyanogenmod/themes/provider/ThemesProvider.java
@@ -89,6 +89,21 @@ public class ThemesProvider extends ContentProvider {
switch (match) {
case THEMES:
SQLiteDatabase sqlDB = mDatabase.getWritableDatabase();
+
+ // Determine the pkg name and delete preview images
+ String[] columns = new String[] {ThemesColumns.PKG_NAME};
+ Cursor c = sqlDB.query(ThemesTable.TABLE_NAME, columns, selection,
+ selectionArgs, null, null, null);
+ if (c == null) return 0;
+ if (c.moveToFirst()) {
+ String pkgName = c.getString(0);
+ Intent intent = new Intent(getContext(), CopyImageService.class);
+ intent.setAction(CopyImageService.ACTION_DELETE);
+ intent.putExtra(CopyImageService.EXTRA_PKG_NAME, pkgName);
+ getContext().startService(intent);
+ }
+ c.close();
+
int rowsDeleted = sqlDB.delete(ThemesTable.TABLE_NAME, selection, selectionArgs);
getContext().getContentResolver().notifyChange(uri, null);
return rowsDeleted;
@@ -124,6 +139,7 @@ public class ThemesProvider extends ContentProvider {
case THEMES:
id = sqlDB.insert(ThemesOpenHelper.ThemesTable.TABLE_NAME, null, values);
Intent intent = new Intent(getContext(), CopyImageService.class);
+ intent.setAction(CopyImageService.ACTION_INSERT);
intent.putExtra(CopyImageService.EXTRA_PKG_NAME,
values.getAsString(ThemesColumns.PKG_NAME));
getContext().startService(intent);