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

Commit c089b0d2 authored by Jay Shrauner's avatar Jay Shrauner
Browse files

Change cached info to interface

Change AOSP cache API to interface and move DB data types to GoogleDialer

Bug:10980951
Change-Id: I37eb07f672458ab4d8789ecc4e9f2f60745de862
parent 990c95f1
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.text.TextUtils;
import com.android.contacts.common.util.Constants;
import com.android.contacts.common.util.UriUtils;
import com.android.dialer.service.CachedNumberLookupService;
import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo;
import com.android.dialerbind.ObjectFactory;

import org.json.JSONException;
@@ -228,7 +229,9 @@ public class ContactInfoHelper {
        if (info != null && info != ContactInfo.EMPTY) {
            info.formattedNumber = formatPhoneNumber(number, null, countryIso);
        } else if (mCachedNumberLookupService != null) {
            info = mCachedNumberLookupService.lookupCachedContactFromNumber(mContext, number);
            CachedContactInfo cacheInfo = mCachedNumberLookupService
                .lookupCachedContactFromNumber(mContext, number);
            info = cacheInfo != null ? cacheInfo.getContactInfo() : null;
        }
        return info;
    }
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ public class RegularSearchFragment extends SearchFragment {
            final RegularSearchListAdapter adapter =
                (RegularSearchListAdapter) getAdapter();
            mCachedNumberLookupService.addContact(getContext(),
                    adapter.getContactInfo(position));
                    adapter.getContactInfo(mCachedNumberLookupService, position));
        }
    }
}
+15 −9
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.text.TextUtils;

import com.android.contacts.common.list.DirectoryPartition;
import com.android.contacts.common.list.PhoneNumberListAdapter;
import com.android.dialer.calllog.ContactInfo;
import com.android.dialer.service.CachedNumberLookupService;
import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo;

/**
@@ -34,8 +36,10 @@ public class RegularSearchListAdapter extends DialerPhoneNumberListAdapter {
        super(context);
    }

    public CachedContactInfo getContactInfo(int position) {
        CachedContactInfo info = new CachedContactInfo();
    public CachedContactInfo getContactInfo(
            CachedNumberLookupService lookupService, int position) {
        ContactInfo info = new ContactInfo();
        CachedContactInfo cacheInfo = lookupService.buildCachedContactInfo(info);
        final Cursor item = (Cursor) getItem(position);
        if (item != null) {
            info.name = item.getString(PhoneQuery.DISPLAY_NAME);
@@ -44,19 +48,21 @@ public class RegularSearchListAdapter extends DialerPhoneNumberListAdapter {
            info.number = item.getString(PhoneQuery.PHONE_NUMBER);
            final String photoUriStr = item.getString(PhoneQuery.PHOTO_URI);
            info.photoUri = photoUriStr == null ? null : Uri.parse(photoUriStr);
            info.lookupKey = item.getString(PhoneQuery.LOOKUP_KEY);

            cacheInfo.setLookupKey(item.getString(PhoneQuery.LOOKUP_KEY));

            final int partitionIndex = getPartitionForPosition(position);
            final DirectoryPartition partition =
                (DirectoryPartition) getPartition(partitionIndex);
            final long directoryId = partition.getDirectoryId();
            info.sourceName = partition.getLabel();
            info.sourceType = isExtendedDirectory(directoryId) ?
                CachedContactInfo.SOURCE_TYPE_EXTENDED :
                CachedContactInfo.SOURCE_TYPE_DIRECTORY;
            info.sourceId = (int) directoryId;
            final String sourceName = partition.getLabel();
            if (isExtendedDirectory(directoryId)) {
                cacheInfo.setExtendedSource(sourceName, directoryId);
            } else {
                cacheInfo.setDirectorySource(sourceName, directoryId);
            }
        }
        return info;
        return cacheInfo;
    }

    @Override
+10 −12
Original line number Diff line number Diff line
@@ -7,29 +7,27 @@ import com.android.dialer.calllog.ContactInfo;

public interface CachedNumberLookupService {

    public class CachedContactInfo extends ContactInfo {
        public static final int SOURCE_TYPE_DIRECTORY = 1;
        public static final int SOURCE_TYPE_EXTENDED = 2;
        public static final int SOURCE_TYPE_PLACES = 3;
        public static final int SOURCE_TYPE_PROFILE = 4;

        public String sourceName;
        public int    sourceType;
        public int    sourceId;
        public String lookupKey;
    public interface CachedContactInfo {
        public ContactInfo getContactInfo();

        public void setDirectorySource(String name, long directoryId);
        public void setExtendedSource(String name, long directoryId);
        public void setLookupKey(String lookupKey);
    }

    public CachedContactInfo buildCachedContactInfo(ContactInfo info);

    /**
     * Perform a lookup using the cached number lookup service to return contact
     * information stored in the cache that corresponds to the given number.
     *
     * @param context Valid context
     * @param number Phone number to lookup the cache for
     * @return A {@link ContactInfo} containing the contact information if the phone
     * @return A {@link CachedContactInfo} containing the contact information if the phone
     * number is found in the cache, {@link ContactInfo#EMPTY} if the phone number was
     * not found in the cache, and null if there was an error when querying the cache.
     */
    public ContactInfo lookupCachedContactFromNumber(Context context, String number);
    public CachedContactInfo lookupCachedContactFromNumber(Context context, String number);

    public void addContact(Context context, CachedContactInfo info);