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

Commit 01dec571 authored by Walter Jang's avatar Walter Jang
Browse files

Read autocomplete timeout from phenotype (1/2)

Test: see Ie4fd41153541cbe554291e234f9c36ffb491b396

Bug: 30921207
Bug: 30436991

Change-Id: I6fe23632d48b0efa447a60fb480360e0ddbf336f
parent e4f23ba7
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -52,6 +52,10 @@ public final class Experiments {
     */
    public static final String SEARCH_YENTA = "Search__yenta";

    /**
     * The time to wait for Yenta search results before giving up.
     */
    public static final String SEARCH_YENTA_TIMEOUT_MILLIS = "Search__yenta_timeout";

    private Experiments() {
    }
+7 −6
Original line number Diff line number Diff line
@@ -23,7 +23,9 @@ import android.os.Bundle;
import android.provider.ContactsContract.Contacts;
import android.util.Log;

import com.android.contacts.common.Experiments;
import com.android.contactsbind.ObjectFactory;
import com.android.contactsbind.experiments.Flags;
import com.android.contactsbind.search.AutocompleteHelper;
import com.google.common.collect.Lists;

@@ -37,8 +39,6 @@ import java.util.concurrent.TimeUnit;
 */
public class FavoritesAndContactsLoader extends CursorLoader implements AutocompleteHelper.Listener {

    private static final int AUTOCOMPLETE_TIMEOUT_MS = 1000;

    private boolean mLoadFavorites;

    private String[] mProjection;
@@ -46,9 +46,12 @@ public class FavoritesAndContactsLoader extends CursorLoader implements Autocomp
    private String mAutocompleteQuery;
    private CountDownLatch mAutocompleteLatch = new CountDownLatch(1);
    private Cursor mAutocompleteCursor;
    private int mAutocompleteTimeout;

    public FavoritesAndContactsLoader(Context context) {
        super(context);
        mAutocompleteTimeout = Flags.getInstance(context).getInteger(
                Experiments.SEARCH_YENTA_TIMEOUT_MILLIS);
    }

    /** Whether to load favorites and merge results in before any other results. */
@@ -80,7 +83,7 @@ public class FavoritesAndContactsLoader extends CursorLoader implements Autocomp
                autocompleteHelper.setProjection(mProjection);
                autocompleteHelper.setQuery(mAutocompleteQuery);
                try {
                    if (!mAutocompleteLatch.await(AUTOCOMPLETE_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
                    if (!mAutocompleteLatch.await(mAutocompleteTimeout, TimeUnit.MILLISECONDS)) {
                        logw("Timeout expired before receiving autocompletions");
                    }
                } catch (InterruptedException e) {
@@ -129,9 +132,7 @@ public class FavoritesAndContactsLoader extends CursorLoader implements Autocomp

    @Override
    public void onAutocompletesAvailable(Cursor cursor) {
        if (cursor == null || cursor.getCount() == 0) {
            logw("Ignoring null or empty autocompletions");
        } else {
        if (cursor != null && cursor.getCount() > 0) {
            mAutocompleteCursor = cursor;
            mAutocompleteLatch.countDown();
        }