summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Mast <andy@cyngn.com>2014-06-10 21:09:32 +0000
committerGerrit Code Review <gerrit@cyanogenmod.org>2014-06-10 21:09:32 +0000
commitbbc11012b56194b9033a8701a0687f66400a78ca (patch)
tree6deb8bd69c8cd96926773d337e3c1a0e911388c1 /src
parentd18ad8f6953f66e7df637abad2f54a8e6bfe8dd5 (diff)
parenta5e79ba54a2142b07f2d427e3ac0ddb6ce146eab (diff)
downloadandroid_packages_providers_ThemesProvider-bbc11012b56194b9033a8701a0687f66400a78ca.zip
android_packages_providers_ThemesProvider-bbc11012b56194b9033a8701a0687f66400a78ca.tar.gz
android_packages_providers_ThemesProvider-bbc11012b56194b9033a8701a0687f66400a78ca.tar.bz2
Merge "Insert instead of update if theme doesn't exist" into cm-11.0
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;
+ }
}