Bug 1313316 - Show activity stream setting if build flag is enabled or user is enrolled in experiment. r=ahunt draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Fri, 28 Oct 2016 14:01:02 +0200
changeset 430968 c66b3b7a7b05a6bd84488de4827abd9c3f6225d8
parent 430958 3cc6155f05fc6bf603209d50b06afca47e2e1ee8
child 431009 91f46c156cbfe7f0b2f30757116c3e0a93835dba
push id33952
push users.kaspari@gmail.com
push dateFri, 28 Oct 2016 12:20:25 +0000
reviewersahunt
bugs1313316
milestone52.0a1
Bug 1313316 - Show activity stream setting if build flag is enabled or user is enrolled in experiment. r=ahunt MozReview-Commit-ID: CEchCITzX0O
mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStream.java
mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStream.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/ActivityStream.java
@@ -4,17 +4,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.activitystream;
 
 import android.content.Context;
 import android.net.Uri;
 import android.text.TextUtils;
 
+import com.keepsafe.switchboard.SwitchBoard;
+
 import org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.Experiments;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.util.StringUtils;
 import org.mozilla.gecko.util.publicsuffix.PublicSuffix;
 
 import java.util.Arrays;
 import java.util.List;
 
@@ -40,25 +43,47 @@ public class ActivityStream {
      */
     private static final List<String> UNDESIRED_LABELS = Arrays.asList(
             "render",
             "login",
             "edit"
     );
 
     public static boolean isEnabled(Context context) {
-        if (!AppConstants.MOZ_ANDROID_ACTIVITY_STREAM) {
+        if (!isUserEligible(context)) {
+            // If the user is not eligible then disable activity stream. Even if it has been
+            //  enabled before.
             return false;
         }
 
         return GeckoSharedPrefs.forApp(context)
                 .getBoolean(GeckoPreferences.PREFS_ACTIVITY_STREAM, false);
     }
 
     /**
+     * Is the user eligible to use activity stream or should we hide it from settings etc.?
+     */
+    public static boolean isUserEligible(Context context) {
+        if (AppConstants.MOZ_ANDROID_ACTIVITY_STREAM) {
+            // If the build flag is enabled then just show the option to the user.
+            return true;
+        }
+
+        if (AppConstants.NIGHTLY_BUILD && SwitchBoard.isInExperiment(context, Experiments.ACTIVITY_STREAM)) {
+            // If this is a nightly build and the user is part of the activity stream experiment then
+            // the option should be visible too. The experiment is limited to Nightly too but I want
+            // to make really sure that this isn't riding the trains accidentally.
+            return true;
+        }
+
+        // For everyone else activity stream is not available yet.
+        return false;
+    }
+
+    /**
      * Query whether we want to display Activity Stream as a Home Panel (within the HomePager),
      * or as a HomePager replacement.
      */
     public static boolean isHomePanel() {
         return true;
     }
 
     /**
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
@@ -24,16 +24,17 @@ import org.mozilla.gecko.GeckoSharedPref
 import org.mozilla.gecko.LocaleManager;
 import org.mozilla.gecko.Locales;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.SnackbarBuilder;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.TelemetryContract.Method;
+import org.mozilla.gecko.activitystream.ActivityStream;
 import org.mozilla.gecko.background.common.GlobalConstants;
 import org.mozilla.gecko.db.BrowserContract.SuggestedSites;
 import org.mozilla.gecko.feeds.FeedService;
 import org.mozilla.gecko.feeds.action.CheckForUpdatesAction;
 import org.mozilla.gecko.permissions.Permissions;
 import org.mozilla.gecko.restrictions.Restrictable;
 import org.mozilla.gecko.restrictions.Restrictions;
 import org.mozilla.gecko.tabqueue.TabQueueHelper;
@@ -878,17 +879,17 @@ OnSharedPreferenceChangeListener
                         preferences.removePreference(pref);
                         i--;
                         continue;
                     }
                 } else if (PREFS_CUSTOM_TABS.equals(key) && !AppConstants.MOZ_ANDROID_CUSTOM_TABS) {
                     preferences.removePreference(pref);
                     i--;
                     continue;
-                } else if (PREFS_ACTIVITY_STREAM.equals(key) && !AppConstants.MOZ_ANDROID_ACTIVITY_STREAM) {
+                } else if (PREFS_ACTIVITY_STREAM.equals(key) && !ActivityStream.isUserEligible(this)) {
                     preferences.removePreference(pref);
                     i--;
                     continue;
                 }
 
                 // Some Preference UI elements are not actually preferences,
                 // but they require a key to work correctly. For example,
                 // "Clear private data" requires a key for its state to be