for (int i=0; i<N; i++) {
if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
mBgAllAppsList.updatePackage(context, packages[i]);
- WidgetPreviewLoader.removeFromDb(
+ WidgetPreviewLoader.removePackageFromDb(
mApp.getWidgetPreviewCacheDb(), packages[i]);
}
break;
for (int i=0; i<N; i++) {
if (DEBUG_LOADERS) Log.d(TAG, "mAllAppsList.removePackage " + packages[i]);
mBgAllAppsList.removePackage(packages[i]);
- WidgetPreviewLoader.removeFromDb(
+ WidgetPreviewLoader.removePackageFromDb(
mApp.getWidgetPreviewCacheDb(), packages[i]);
}
break;
}
public Bitmap getPreview(final Object o) {
- String name = getObjectName(o);
+ final String name = getObjectName(o);
+ final String packageName = getObjectPackage(o);
// check if the package is valid
boolean packageValid = true;
synchronized(sInvalidPackages) {
- packageValid = !sInvalidPackages.contains(getObjectPackage(o));
+ packageValid = !sInvalidPackages.contains(packageName);
}
if (!packageValid) {
return null;
db.insert(CacheDb.TABLE_NAME, null, values);
}
- public static void removeFromDb(final CacheDb cacheDb, final String packageName) {
+ public static void removePackageFromDb(final CacheDb cacheDb, final String packageName) {
synchronized(sInvalidPackages) {
sInvalidPackages.add(packageName);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
+ public static void removeItemFromDb(final CacheDb cacheDb, final String objectName) {
+ new AsyncTask<Void, Void, Void>() {
+ public Void doInBackground(Void ... args) {
+ SQLiteDatabase db = cacheDb.getWritableDatabase();
+ db.delete(CacheDb.TABLE_NAME,
+ CacheDb.COLUMN_NAME + " = ? ", // SELECT query
+ new String[] { objectName }); // args to SELECT query
+ return null;
+ }
+ }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
+ }
+
private Bitmap readFromDb(String name, Bitmap b) {
if (mCachedSelectQuery == null) {
mCachedSelectQuery = CacheDb.COLUMN_NAME + " = ? AND " +
final BitmapFactory.Options opts = mCachedBitmapFactoryOptions.get();
opts.inBitmap = b;
opts.inSampleSize = 1;
- Bitmap out = BitmapFactory.decodeByteArray(blob, 0, blob.length, opts);
- return out;
+ try {
+ return BitmapFactory.decodeByteArray(blob, 0, blob.length, opts);
+ } catch (IllegalArgumentException e) {
+ removeItemFromDb(mDb, name);
+ return null;
+ }
} else {
result.close();
return null;