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

Commit b5f64321 authored by Flavio Lerda's avatar Flavio Lerda
Browse files

Use the content of the call log to predict the contact info.

This change re-instroduces the cache stored in the call log table for
the contact info associated with a call.

This is the first part of the necessary changes. In this change, I also
use the stored information, I do not update it when the contact is
actually looked up in the call log.

Bug: 5101753
Change-Id: Ib906e9af06410c2cc295192cd4623b011fa0ad09
parent de4f16aa
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -541,6 +541,8 @@ public final class CallLogAdapter extends GroupingListAdapter
        final String formattedNumber;
        final String countryIso = c.getString(CallLogQuery.COUNTRY_ISO);

        final ContactInfo cachedContactInfo = getContactInfoFromCallLog(c);

        views.primaryActionView.setTag(
                IntentProvider.getCallDetailIntentProvider(
                        this, c.getPosition(), c.getLong(CallLogQuery.ID), count));
@@ -592,6 +594,10 @@ public final class CallLogAdapter extends GroupingListAdapter
            }
        }

        if (info == null || info == ContactInfo.EMPTY) {
            info = cachedContactInfo;
        }

        final long personId = info.personId;
        final String name = info.name;
        final int ntype = info.type;
@@ -623,6 +629,22 @@ public final class CallLogAdapter extends GroupingListAdapter
        }
    }

    /** Returns the contact information as stored in the call log. */
    private ContactInfo getContactInfoFromCallLog(Cursor c) {
        ContactInfo info = new ContactInfo();
        info.personId = -1;
        info.name = c.getString(CallLogQuery.CACHED_NAME);
        info.type = c.getInt(CallLogQuery.CACHED_NUMBER_TYPE);
        info.label = c.getString(CallLogQuery.CACHED_NUMBER_LABEL);
        // TODO: This should be added to the call log cached values.
        info.number = c.getString(CallLogQuery.NUMBER);
        info.formattedNumber = info.number;
        info.normalizedNumber = info.number;
        info.thumbnailUri = null;
        info.lookupKey = null;
        return info;
    }

    /**
     * Returns the call types for the given number of items in the cursor.
     * <p>
+7 −1
Original line number Diff line number Diff line
@@ -34,6 +34,9 @@ public final class CallLogQuery {
            Calls.COUNTRY_ISO,
            Calls.VOICEMAIL_URI,
            Calls.GEOCODED_LOCATION,
            Calls.CACHED_NAME,
            Calls.CACHED_NUMBER_TYPE,
            Calls.CACHED_NUMBER_LABEL,
    };

    public static final int ID = 0;
@@ -44,6 +47,9 @@ public final class CallLogQuery {
    public static final int COUNTRY_ISO = 5;
    public static final int VOICEMAIL_URI = 6;
    public static final int GEOCODED_LOCATION = 7;
    public static final int CACHED_NAME = 8;
    public static final int CACHED_NUMBER_TYPE = 9;
    public static final int CACHED_NUMBER_LABEL = 10;

    /**
     * The name of the synthetic "section" column.
@@ -53,7 +59,7 @@ public final class CallLogQuery {
     */
    public static final String SECTION_NAME = "section";
    /** The index of the "section" column in the projection. */
    public static final int SECTION = 8;
    public static final int SECTION = 11;
    /** The value of the "section" column for the header of the new section. */
    public static final int SECTION_NEW_HEADER = 0;
    /** The value of the "section" column for the items of the new section. */
+1 −1
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ import javax.annotation.concurrent.GuardedBy;
                new MatrixCursor(CallLogQuery.EXTENDED_PROJECTION);
        // The values in this row correspond to default values for _PROJECTION from CallLogQuery
        // plus the section value.
        matrixCursor.addRow(new Object[]{ -1L, "", 0L, 0L, 0, "", "", "", section });
        matrixCursor.addRow(new Object[]{ -1L, "", 0L, 0L, 0, "", "", "", null, 0, null, section });
        return matrixCursor;
    }

+7 −12
Original line number Diff line number Diff line
@@ -62,17 +62,6 @@ import java.util.Random;
@LargeTest
public class CallLogActivityTests
        extends ActivityInstrumentationTestCase2<CallLogActivity> {
    private static final String[] EXTENDED_CALL_LOG_PROJECTION = new String[] {
            Calls._ID,
            Calls.NUMBER,
            Calls.DATE,
            Calls.DURATION,
            Calls.TYPE,
            Calls.COUNTRY_ISO,
            Calls.VOICEMAIL_URI,
            Calls.GEOCODED_LOCATION,
            CallLogQuery.SECTION_NAME,
    };
    private static final int RAND_DURATION = -1;
    private static final long NOW = -1L;

@@ -133,7 +122,7 @@ public class CallLogActivityTests
        mAdapter.disableRequestProcessingForTest();
        mAdapter.stopRequestProcessing();
        mParentView = new FrameLayout(mActivity);
        mCursor = new MatrixCursor(EXTENDED_CALL_LOG_PROJECTION);
        mCursor = new MatrixCursor(CallLogQuery.EXTENDED_PROJECTION);
        buildIconMap();
    }

@@ -508,6 +497,9 @@ public class CallLogActivityTests
        row.add(TEST_COUNTRY_ISO);  // country ISO
        row.add(null);  // voicemail_uri
        row.add(null);  // geocoded_location
        row.add(null);  // cached_name
        row.add(0);  // cached_number_type
        row.add(null);  // cached_number_label
        row.add(CallLogQuery.SECTION_OLD_ITEM);  // section
    }

@@ -539,6 +531,9 @@ public class CallLogActivityTests
        row.add(TEST_COUNTRY_ISO);  // country ISO
        row.add(voicemailUri);  // voicemail_uri
        row.add(null);  // geocoded_location
        row.add(null);  // cached_name
        row.add(0);  // cached_number_type
        row.add(null);  // cached_number_label
        row.add(CallLogQuery.SECTION_OLD_ITEM);  // section
    }

+4 −3
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.contacts.calllog;

import static com.google.android.collect.Lists.newArrayList;


import android.database.MatrixCursor;
import android.provider.CallLog.Calls;
import android.test.AndroidTestCase;
@@ -223,7 +222,7 @@ public class CallLogGroupBuilderTest extends AndroidTestCase {
        }
        mCursor.moveToNext();
        mCursor.addRow(new Object[]{
                mCursor.getPosition(), number, 0L, 0L, type, "", "", "", section
                mCursor.getPosition(), number, 0L, 0L, type, "", "", "", null, 0, null, section
        });
    }

@@ -244,7 +243,9 @@ public class CallLogGroupBuilderTest extends AndroidTestCase {
            throw new IllegalArgumentException("not a header section: " + section);
        }
        mCursor.moveToNext();
        mCursor.addRow(new Object[]{ mCursor.getPosition(), "", 0L, 0L, 0, "", "", "", section });
        mCursor.addRow(new Object[]{
                mCursor.getPosition(), "", 0L, 0L, 0, "", "", "", null, 0, null, section
        });
    }

    /** Asserts that the group matches the given values. */