summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard MacGregor <rmacgregor@cyngn.com>2015-05-20 19:22:05 (GMT)
committerRichard MacGregor <rmacgregor@cyngn.com>2015-05-29 00:10:41 (GMT)
commit0d4fca36a06c9b03005a4c8ccc55e152849beff8 (patch)
tree60786c03cb6cff51b4e86733caba63cb0a4e67f9 /src
parentb83a558be9b40d46dbcf40666550d8b2cc29fb3e (diff)
downloadandroid_packages_providers_ThemesProvider-0d4fca36a06c9b03005a4c8ccc55e152849beff8.zip
android_packages_providers_ThemesProvider-0d4fca36a06c9b03005a4c8ccc55e152849beff8.tar.gz
android_packages_providers_ThemesProvider-0d4fca36a06c9b03005a4c8ccc55e152849beff8.tar.bz2
Handle null parameters when creating query strings
Sometimes parameters, selection, and selection arguments may be null. Handle various null cases to get correct behavior. Change-Id: I8b969b3e1a726498ea3044374b2d235b8f41091a
Diffstat (limited to 'src')
-rw-r--r--src/org/cyanogenmod/themes/provider/util/ProviderUtils.java37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java b/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java
index ab98530..66db924 100644
--- a/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java
+++ b/src/org/cyanogenmod/themes/provider/util/ProviderUtils.java
@@ -26,6 +26,7 @@ import android.provider.ThemesContract;
import android.provider.ThemesContract.MixnMatchColumns;
import android.provider.ThemesContract.PreviewColumns;
import android.provider.ThemesContract.ThemesColumns;
+import android.text.TextUtils;
import org.cyanogenmod.themes.provider.ThemesOpenHelper;
import java.util.ArrayList;
@@ -114,6 +115,8 @@ public class ProviderUtils {
}
public static String[] modifyPreviewsProjection(String[] projection) {
+ if (projection == null) return null;
+
Set<String> validKeys =
new HashSet<String>(Arrays.asList(ThemesContract.PreviewColumns.VALID_KEYS));
ArrayList<String> newProjection = new ArrayList<String>();
@@ -129,15 +132,28 @@ public class ProviderUtils {
public static String modifyDefaultPreviewsSelection(String selection, String[] projection) {
String newSelection = modifyPreviewsSelection(selection, projection);
- newSelection += " AND " + PreviewColumns.COMPONENT_ID + "=0";
+ if (!TextUtils.isEmpty(newSelection)) {
+ newSelection += " AND ";
+ } else {
+ newSelection = "";
+ }
+ newSelection += PreviewColumns.COMPONENT_ID + "=0";
return newSelection;
}
public static String modifyPreviewsSelection(String selection, String[] projection) {
- String newSelection = selection;
+ if (selection == null && projection == null) return null;
+
+ String newSelection = "";
+ if (!TextUtils.isEmpty(selection)) {
+ newSelection += selection;
+ }
List<String> projectionItems = getPreviewProjectionItems(projection);
- if (projectionItems.size() > 0) {
- newSelection += " AND (";
+ if (projectionItems != null && projectionItems.size() > 0) {
+ if (!TextUtils.isEmpty(newSelection)) {
+ newSelection += " AND ";
+ }
+ newSelection += "(";
for (int i = 0; i < projectionItems.size(); i++) {
newSelection += PreviewColumns.COL_KEY + "=?";
if (i < projectionItems.size() - 1) {
@@ -151,16 +167,21 @@ public class ProviderUtils {
public static String[] modifyPreviewsSelectionArgs(String[] selectionArgs,
String[] projection) {
- ArrayList<String> newSelectionArgs =
- new ArrayList<String>(Arrays.asList(selectionArgs));
+ if (selectionArgs == null && projection == null) return null;
+
+ ArrayList<String> newSelectionArgs = new ArrayList<String>();
+ if (selectionArgs != null) {
+ newSelectionArgs.addAll(Arrays.asList(selectionArgs));
+ }
List<String> projectionItems = getPreviewProjectionItems(projection);
- for (String item : projectionItems) {
- newSelectionArgs.add(item);
+ if (projectionItems != null) {
+ newSelectionArgs.addAll(projectionItems);
}
return newSelectionArgs.toArray(new String[newSelectionArgs.size()]);
}
public static List<String> getPreviewProjectionItems(String[] projection) {
+ if (projection == null) return null;
Set<String> validKeys =
new HashSet<String>(Arrays.asList(PreviewColumns.VALID_KEYS));
ArrayList<String> newProjection = new ArrayList<String>();