Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-5308

Contact.save() calls failure callback even though contact data is successfully saved on device

    XMLWordPrintableJSON

Details

    Description

      When I run contact mobile-spec, following specs sometimes fail.

      • contacts.spec.6
      • contacts.spec.20
      • contacts.spec.21
      • contacts.spec.24

      In Java side, it looks that ContactAccessorSdk5.save() returns contact id but ContactAccessorSdk5.getContactById() returns null instead of contact data associated with the id. Actually some of contact data such as "Test Delete" are found on my device so the save operation is actually done.

      This save() returns "newId" in the following code.

      ContactAccessorSdk5.java
      	    //Add contact
              try {
                  ContentProviderResult[] cpResults = mApp.getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
                  if (cpResults.length >= 0) {
                      newId = cpResults[0].uri.getLastPathSegment();
                  }
              } catch (RemoteException e) {
                  Log.e(LOG_TAG, e.getMessage(), e);
              } catch (OperationApplicationException e) {
                  Log.e(LOG_TAG, e.getMessage(), e);
              }
              return newId;
      

      When I debug it, cpResults[0].uri is content://com.android.contacts/raw_contacts/xxxx so, this is just my assumption, I think save() returns raw contact id.
      But at getContactById(), query filter uses CONTACT_ID column as a projection.

      ContactAccessorSdk5.java
              Cursor c = mApp.getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
                      null,
                      ContactsContract.Data.CONTACT_ID + " = ? ",
                      new String[] { id },
                      ContactsContract.Data.CONTACT_ID + " ASC");
      

      So if contact id and raw contact id is different then fetching contact data might fail. Actually in my case, if I fail the specs, they are always different.

      I try modifying getContactById() to process following code if contact JSONObject doesn't have id property, then I didn't get failure for those specs even if I run them some times.

      ContactAccessorSdk5.java
              Cursor c = mApp.getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
                      null,
                      ContactsContract.Data.RAW_CONTACT_ID + " = ? ",
                      new String[] { rawid },
                      ContactsContract.Data.RAW_CONTACT_ID + " ASC");
      

      I am just learning how contact data is managed on Android so I might be wrong for some use cases, but it works fine for mobile-spec.

      Attachments

        Issue Links

          Activity

            People

              vladimir.kotikov Vladimir Kotikov
              shingot Shingo Toda
              Votes:
              3 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: