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

Commit 6456baf3 authored by Walter Jang's avatar Walter Jang
Browse files

Read strequent search experment flag from phenotype

* Add a no-op Flags implementation for AOSP
* Put experiment flag name constants in new Experiemnts
  class

Bug 26400050

Change-Id: I2b540189a3234ba7cb0af6a6a0d1c3f0f5142534
parent f7899c04
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */
package com.android.contacts.common;

/**
 * Experiment flag name constants.
 */
public final class Experiments {

    /**
     * Search study boolean indicating whether to order starred and frequently occurring
     * search results first.
     */
    public static final String FLAG_SEARCH_STREQUENTS_FIRST =
            "Search__order_strequent_results_first";

    private Experiments() {
    }
}
+4 −5
Original line number Diff line number Diff line
@@ -30,8 +30,10 @@ import android.provider.ContactsContract.SearchSnippets;
import android.text.TextUtils;
import android.view.View;

import com.android.contacts.common.Experiments;
import com.android.contacts.common.compat.ContactsCompat;
import com.android.contacts.common.preference.ContactsPreferences;
import com.android.contacts.commonbind.experiments.Flags;

import java.util.ArrayList;
import java.util.List;
@@ -44,10 +46,6 @@ public class DefaultContactListAdapter extends ContactListAdapter {
    public static final char SNIPPET_START_MATCH = '[';
    public static final char SNIPPET_END_MATCH = ']';

    // Whether to show strequent contacts before the normal type-to-filter search results.
    // TODO(wjang): set this using phenotype
    private final boolean mShowStrequentsSearchResultsFirst = false;

    public DefaultContactListAdapter(Context context) {
        super(context);
    }
@@ -76,7 +74,8 @@ public class DefaultContactListAdapter extends ContactListAdapter {
                appendSearchParameters(builder, query, directoryId);
                loader.setUri(builder.build());
                loader.setProjection(getProjection(true));
                if (mShowStrequentsSearchResultsFirst) {
                if (Flags.getInstance(mContext).getBoolean(
                        Experiments.FLAG_SEARCH_STREQUENTS_FIRST, false)) {
                    // Filter out starred and frequently contacted contacts from the main loader
                    // query results
                    loader.setSelection(Contacts.TIMES_CONTACTED + "=0 AND "
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */
package com.android.contacts.commonbind.experiments;

import android.content.Context;

/**
 * Provides getters for experiment flags.
 * This stub class is designed to be overwritten by an overlay.
 */
public final class Flags {

    private static Flags sInstance;

    public static Flags getInstance(Context context) {
        if (sInstance == null) {
            sInstance = new Flags();
        }
        return sInstance;
    }

    private Flags() {
    }

    public boolean getBoolean(String flagName, boolean defValue) {
        return false;
    }

    public float getFloat(String flagName, float defValue) {
        return defValue;
    }

    public long getLong(String flagName, long defValue) {
        return defValue;
    }

    public String getString(String flagName, String defValue) {
        return defValue;
    }
}