summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Mast <andy@cyngn.com>2014-06-08 12:27:36 -0700
committerAndy Mast <andy@cyngn.com>2014-06-08 12:27:36 -0700
commita5e79ba54a2142b07f2d427e3ac0ddb6ce146eab (patch)
treec17723147dfea10deea3e677d7f7b91a278d3caf /src
parent3c8b34bd6e29a0318899746452201872e96abc3d (diff)
downloadandroid_packages_providers_ThemesProvider-a5e79ba54a2142b07f2d427e3ac0ddb6ce146eab.tar.gz
android_packages_providers_ThemesProvider-a5e79ba54a2142b07f2d427e3ac0ddb6ce146eab.tar.bz2
android_packages_providers_ThemesProvider-a5e79ba54a2142b07f2d427e3ac0ddb6ce146eab.zip
Insert instead of update if theme doesn't exist
This handles the case where an app is being upgraded and previously was not a theme. and therefore wasn't in the provider. Change-Id: I7b3f64aed2b78081822cb0f9daf0cbd638e0b15b
Diffstat (limited to 'src')
-rw-r--r--src/org/cyanogenmod/themes/provider/AppReceiver.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/org/cyanogenmod/themes/provider/AppReceiver.java b/src/org/cyanogenmod/themes/provider/AppReceiver.java
index 881ac21..3fd36f3 100644
--- a/src/org/cyanogenmod/themes/provider/AppReceiver.java
+++ b/src/org/cyanogenmod/themes/provider/AppReceiver.java
@@ -19,7 +19,9 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.database.Cursor;
import android.net.Uri;
+import android.provider.ThemesContract;
import android.util.Log;
public class AppReceiver extends BroadcastReceiver {
@@ -37,10 +39,30 @@ public class AppReceiver extends BroadcastReceiver {
} else if (intent.getAction().equals(Intent.ACTION_PACKAGE_BEING_REMOVED)) {
ThemePackageHelper.removePackage(context, pkgName);
} else if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
- ThemePackageHelper.updatePackage(context, pkgName);
+ if (themeExistsInProvider(context, pkgName)) {
+ ThemePackageHelper.updatePackage(context, pkgName);
+ } else {
+ // Edge case where app was not a theme in previous install
+ ThemePackageHelper.insertPackage(context, pkgName);
+ }
}
} catch(NameNotFoundException e) {
Log.e(TAG, "Unable to add package to theme's provider ", e);
}
}
+
+ private static boolean themeExistsInProvider(Context context, String pkgName) {
+ boolean exists = false;
+ String[] projection = new String[] { ThemesContract.ThemesColumns.PKG_NAME };
+ String selection = ThemesContract.ThemesColumns.PKG_NAME + "?";
+ String[] selectionArgs = new String[] { pkgName };
+ Cursor c = context.getContentResolver().query(ThemesContract.ThemesColumns.CONTENT_URI,
+ projection, selection, selectionArgs, null);
+
+ if (c != null) {
+ exists = c.getCount() >= 1;
+ c.close();
+ }
+ return exists;
+ }
}