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

Commit a75206b1 authored by Marcus Hagerott's avatar Marcus Hagerott
Browse files

Add additional tests of SIM contact importing

Test: ran GoogleContacts unit tests. Also manually verified that SIM
import screen functionality is the same

Change-Id: I21bf392c0e4a12171f73f7f676cadf33183efb4f
parent 2bb4984e
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -293,8 +293,11 @@ public class SimContactDaoImpl extends SimContactDao {
            final String emails = cursor.getString(colEmails);

            final SimContact contact = new SimContact(id, name, number, parseEmails(emails));
            // Only include contact if it has some useful data
            if (contact.hasName() || contact.hasPhone() || contact.hasEmails()) {
                result.add(contact);
            }
        }
        return result;
    }

@@ -381,7 +384,7 @@ public class SimContactDaoImpl extends SimContactDao {
    }

    private String[] parseEmails(String emails) {
        return emails != null ? emails.split(",") : null;
        return !TextUtils.isEmpty(emails) ? emails.split(",") : null;
    }

    private boolean hasTelephony() {
+10 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.text.TextUtils;

import com.android.contacts.common.model.account.AccountWithDataSet;
import com.google.common.collect.ComparisonChain;
@@ -45,6 +46,10 @@ public class SimContact implements Parcelable {
    private final String mPhone;
    private final String[] mEmails;

    public SimContact(long id, String name, String phone) {
        this(id, name, phone, null);
    }

    public SimContact(long id, String name, String phone, String[] emails) {
        mId = id;
        mName = name;
@@ -52,6 +57,10 @@ public class SimContact implements Parcelable {
        mEmails = emails;
    }

    public SimContact(SimContact other) {
        this(other.mId, other.mName, other.mPhone, other.mEmails);
    }

    public long getId() {
        return mId;
    }
@@ -112,7 +121,7 @@ public class SimContact implements Parcelable {
    }

    public boolean hasName() {
        return mName != null;
        return !TextUtils.isEmpty(mName);
    }

    public boolean hasPhone() {
+15 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.contacts.common.model.account;

import android.accounts.Account;
import android.content.ContentProviderOperation;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
@@ -190,6 +191,20 @@ public class AccountWithDataSet implements Parcelable {
        return addStringified(new StringBuilder(), this).toString();
    }

    /**
     * Returns a {@link ContentProviderOperation} that will create a RawContact in this account
     */
    public ContentProviderOperation newRawContactOperation() {
        final ContentProviderOperation.Builder builder =
                ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
                        .withValue(RawContacts.ACCOUNT_NAME, name)
                        .withValue(RawContacts.ACCOUNT_TYPE, type);
        if (dataSet != null) {
            builder.withValue(RawContacts.DATA_SET, dataSet);
        }
        return builder.build();
    }

    /**
     * Unpack a string created by {@link #stringify}.
     *
+489 −28

File changed.

Preview size limit exceeded, changes collapsed.