diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2019-08-28 13:24:45 -0600 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2019-08-28 13:24:47 -0600 |
| commit | 4ef8702ce9391f2be717faa3d2f90c801a40b80e (patch) | |
| tree | c57e0deef3ded6d581b154cf10670fcdb79c9873 /core/java/android/content/ContentProviderOperation.java | |
| parent | 007ecbb8598d631acc35dba4562148f6e706cac8 (diff) | |
Fix subtle bug when using empty withValues().
We still need to populate mValues when the ContentValues was empty.
Bug: 139356941
Test: atest --test-mapping packages/providers/ContactsProvider
Change-Id: Ice90afbb7994e1a1d10076a2aa48b4d1187abe9f
Diffstat (limited to 'core/java/android/content/ContentProviderOperation.java')
| -rw-r--r-- | core/java/android/content/ContentProviderOperation.java | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/core/java/android/content/ContentProviderOperation.java b/core/java/android/content/ContentProviderOperation.java index 621f331b52b2..5c2de57d77a5 100644 --- a/core/java/android/content/ContentProviderOperation.java +++ b/core/java/android/content/ContentProviderOperation.java @@ -684,10 +684,26 @@ public class ContentProviderOperation implements Parcelable { return new ContentProviderOperation(this); } - private void setValue(@NonNull String key, @NonNull Object value) { + private void ensureValues() { if (mValues == null) { mValues = new ArrayMap<>(); } + } + + private void ensureExtras() { + if (mExtras == null) { + mExtras = new ArrayMap<>(); + } + } + + private void ensureSelectionArgs() { + if (mSelectionArgs == null) { + mSelectionArgs = new SparseArray<>(); + } + } + + private void setValue(@NonNull String key, @NonNull Object value) { + ensureValues(); final boolean oldReference = mValues.get(key) instanceof BackReference; final boolean newReference = value instanceof BackReference; if (!oldReference || newReference) { @@ -696,9 +712,7 @@ public class ContentProviderOperation implements Parcelable { } private void setExtra(@NonNull String key, @NonNull Object value) { - if (mExtras == null) { - mExtras = new ArrayMap<>(); - } + ensureExtras(); final boolean oldReference = mExtras.get(key) instanceof BackReference; final boolean newReference = value instanceof BackReference; if (!oldReference || newReference) { @@ -707,9 +721,7 @@ public class ContentProviderOperation implements Parcelable { } private void setSelectionArg(int index, @NonNull Object value) { - if (mSelectionArgs == null) { - mSelectionArgs = new SparseArray<>(); - } + ensureSelectionArgs(); final boolean oldReference = mSelectionArgs.get(index) instanceof BackReference; final boolean newReference = value instanceof BackReference; if (!oldReference || newReference) { @@ -728,6 +740,7 @@ public class ContentProviderOperation implements Parcelable { */ public @NonNull Builder withValues(@NonNull ContentValues values) { assertValuesAllowed(); + ensureValues(); final ArrayMap<String, Object> rawValues = values.getValues(); for (int i = 0; i < rawValues.size(); i++) { setValue(rawValues.keyAt(i), rawValues.valueAt(i)); @@ -815,6 +828,7 @@ public class ContentProviderOperation implements Parcelable { */ public @NonNull Builder withExtras(@NonNull Bundle extras) { assertExtrasAllowed(); + ensureExtras(); for (String key : extras.keySet()) { setExtra(key, extras.get(key)); } @@ -885,6 +899,7 @@ public class ContentProviderOperation implements Parcelable { assertSelectionAllowed(); mSelection = selection; if (selectionArgs != null) { + ensureSelectionArgs(); for (int i = 0; i < selectionArgs.length; i++) { setSelectionArg(i, selectionArgs[i]); } |
