Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71737051 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Ignore transient rows during re-parenting.

When editing, we create template rows such as StructuredName
and Photo, which may be trimmed before persisting if they
remain empty.  When a background change occurs and we need
to re-parent the users changes, we didn't handle this
special case, and treated these trimmed rows as inserts,
which triggered the reported missing MIME-type exception.

This change watches for "transient" rows that didn't exist
previously, but were inserted and then deleted during the
process of editing.  When encountered, they are ignored
during re-parenting, instead of turning into inserts.

Added a unit test to verify correct behavior, and also wrote
values-level verification for the existing unit tests.

Fixes http://b/2167925
parent 4c129c92
Loading
Loading
Loading
Loading
+12 −2
Original line number Original line Diff line number Diff line
@@ -100,7 +100,8 @@ public class EntityDelta implements Parcelable {
     */
     */
    public static EntityDelta mergeAfter(EntityDelta local, EntityDelta remote) {
    public static EntityDelta mergeAfter(EntityDelta local, EntityDelta remote) {
        // Bail early if trying to merge delete with missing local
        // Bail early if trying to merge delete with missing local
        if (local == null && remote.mValues.isDelete()) return null;
        final ValuesDelta remoteValues = remote.mValues;
        if (local == null && (remoteValues.isDelete() || remoteValues.isTransient())) return null;


        // Create local version if none exists yet
        // Create local version if none exists yet
        if (local == null) local = new EntityDelta();
        if (local == null) local = new EntityDelta();
@@ -513,6 +514,10 @@ public class EntityDelta implements Parcelable {
            return entry;
            return entry;
        }
        }


        public ContentValues getAfter() {
            return mAfter;
        }

        public String getAsString(String key) {
        public String getAsString(String key) {
            if (mAfter != null && mAfter.containsKey(key)) {
            if (mAfter != null && mAfter.containsKey(key)) {
                return mAfter.getAsString(key);
                return mAfter.getAsString(key);
@@ -609,6 +614,11 @@ public class EntityDelta implements Parcelable {
            return beforeExists() && (mAfter == null);
            return beforeExists() && (mAfter == null);
        }
        }


        public boolean isTransient() {
            // When no "before" or "after", is transient
            return (mBefore == null) && (mAfter == null);
        }

        public boolean isUpdate() {
        public boolean isUpdate() {
            // When "after" has some changes, action is "update"
            // When "after" has some changes, action is "update"
            return beforeExists() && (mAfter != null && mAfter.size() > 0);
            return beforeExists() && (mAfter != null && mAfter.size() > 0);
@@ -696,7 +706,7 @@ public class EntityDelta implements Parcelable {
         */
         */
        public static ValuesDelta mergeAfter(ValuesDelta local, ValuesDelta remote) {
        public static ValuesDelta mergeAfter(ValuesDelta local, ValuesDelta remote) {
            // Bail early if trying to merge delete with missing local
            // Bail early if trying to merge delete with missing local
            if (local == null && remote.isDelete()) return null;
            if (local == null && (remote.isDelete() || remote.isTransient())) return null;


            // Create local version if none exists yet
            // Create local version if none exists yet
            if (local == null) local = new ValuesDelta();
            if (local == null) local = new ValuesDelta();
+11 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ import android.content.Context;
import android.content.Entity;
import android.content.Entity;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.test.AndroidTestCase;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.LargeTest;
@@ -89,6 +90,16 @@ public class EntityModifierTests extends AndroidTestCase {
            kind.fieldList.add(new EditField(Phone.LABEL, -1, -1));
            kind.fieldList.add(new EditField(Phone.LABEL, -1, -1));


            addKind(kind);
            addKind(kind);

            // Email is unlimited
            kind = new DataKind(Email.CONTENT_ITEM_TYPE, -1, -1, 10, true);

            kind.typeOverallMax = -1;

            kind.fieldList = Lists.newArrayList();
            kind.fieldList.add(new EditField(Email.DATA, -1, -1));

            addKind(kind);
        }
        }


        @Override
        @Override
+220 −79

File changed.

Preview size limit exceeded, changes collapsed.