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
diff --git a/src/com/android/contacts/common/Experiments.java b/src/com/android/contacts/common/Experiments.java
new file mode 100644
index 0000000..be115f7
--- /dev/null
+++ b/src/com/android/contacts/common/Experiments.java
@@ -0,0 +1,32 @@
+/*
+ * 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() {
+ }
+}
diff --git a/src/com/android/contacts/common/list/DefaultContactListAdapter.java b/src/com/android/contacts/common/list/DefaultContactListAdapter.java
index ec91753..a1eac84 100644
--- a/src/com/android/contacts/common/list/DefaultContactListAdapter.java
+++ b/src/com/android/contacts/common/list/DefaultContactListAdapter.java
@@ -30,8 +30,10 @@
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 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 @@
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 "
diff --git a/src/com/android/contacts/commonbind/experiments/Flags.java b/src/com/android/contacts/commonbind/experiments/Flags.java
new file mode 100644
index 0000000..b0264fd
--- /dev/null
+++ b/src/com/android/contacts/commonbind/experiments/Flags.java
@@ -0,0 +1,53 @@
+/*
+ * 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;
+ }
+}