From a5e79ba54a2142b07f2d427e3ac0ddb6ce146eab Mon Sep 17 00:00:00 2001 From: Andy Mast Date: Sun, 8 Jun 2014 12:27:36 -0700 Subject: 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 --- .../cyanogenmod/themes/provider/AppReceiver.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src') 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; + } } -- cgit v1.2.3