Bug 1315206 - Move getIsInAutomationFromEnvironment from BrowserApp to IntentUtils. r?ahunt,walkingice draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Wed, 02 Nov 2016 20:00:45 +0100
changeset 433818 5e62d8f1dd966e8835f1ef0f2ae243faf16b7223
parent 432230 3e73fd638e687a4d7f46613586e5156b8e2af846
child 433819 79b42c58731bba691d20dbc895ed5f74d0734362
push id34663
push users.kaspari@gmail.com
push dateFri, 04 Nov 2016 10:33:17 +0000
reviewersahunt, walkingice
bugs1315206
milestone52.0a1
Bug 1315206 - Move getIsInAutomationFromEnvironment from BrowserApp to IntentUtils. r?ahunt,walkingice MozReview-Commit-ID: AAFW9PzoVVN
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/IntentUtils.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -597,17 +597,17 @@ public class BrowserApp extends GeckoApp
     public void onCreate(Bundle savedInstanceState) {
         if (!HardwareUtils.isSupportedSystem()) {
             // This build does not support the Android version of the device; Exit early.
             super.onCreate(savedInstanceState);
             return;
         }
 
         final SafeIntent intent = new SafeIntent(getIntent());
-        final boolean isInAutomation = getIsInAutomationFromEnvironment(intent);
+        final boolean isInAutomation = IntentUtils.getIsInAutomationFromEnvironment(intent);
 
         // This has to be prepared prior to calling GeckoApp.onCreate, because
         // widget code and BrowserToolbar need it, and they're created by the
         // layout, which GeckoApp takes care of.
         ((GeckoApplication) getApplication()).prepareLightweightTheme();
 
         super.onCreate(savedInstanceState);
 
@@ -825,32 +825,16 @@ public class BrowserApp extends GeckoApp
         }
 
         // We want to get an understanding of how our user base is spread (bug 1221646).
         final String installerPackageName = getPackageManager().getInstallerPackageName(getPackageName());
         Telemetry.sendUIEvent(TelemetryContract.Event.LAUNCH, TelemetryContract.Method.SYSTEM, "installer_" + installerPackageName);
     }
 
     /**
-     * Gets whether or not we're in automation from the passed in environment variables.
-     *
-     * We need to read environment variables from the intent string
-     * extra because environment variables from our test harness aren't set
-     * until Gecko is loaded, and we need to know this before then.
-     *
-     * The return value of this method should be used early since other
-     * initialization may depend on its results.
-     */
-    @CheckResult
-    private boolean getIsInAutomationFromEnvironment(final SafeIntent intent) {
-        final HashMap<String, String> envVars = IntentUtils.getEnvVarMap(intent);
-        return !TextUtils.isEmpty(envVars.get(IntentUtils.ENV_VAR_IN_AUTOMATION));
-    }
-
-    /**
      * Initializes the default Switchboard URLs the first time.
      * @param intent
      */
     private static void initSwitchboard(final Context context, final SafeIntent intent, final boolean isInAutomation) {
         if (isInAutomation) {
             Log.d(LOGTAG, "Switchboard disabled - in automation");
             return;
         } else if (!AppConstants.MOZ_SWITCHBOARD) {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/IntentUtils.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/IntentUtils.java
@@ -3,17 +3,20 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, you can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 package org.mozilla.gecko.util;
 
 import android.content.Intent;
 import android.os.Bundle;
+import android.support.annotation.CheckResult;
 import android.support.annotation.NonNull;
+import android.text.TextUtils;
+
 import org.mozilla.gecko.mozglue.SafeIntent;
 
 import java.util.HashMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 /**
  * Utilities for Intents.
@@ -82,9 +85,25 @@ public class IntentUtils {
 
     public static String getStringExtraSafe(final Intent intent, final String name) {
         return new SafeIntent(intent).getStringExtra(name);
     }
 
     public static boolean getBooleanExtraSafe(final Intent intent, final String name, final boolean defaultValue) {
         return new SafeIntent(intent).getBooleanExtra(name, defaultValue);
     }
+
+    /**
+     * Gets whether or not we're in automation from the passed in environment variables.
+     *
+     * We need to read environment variables from the intent string
+     * extra because environment variables from our test harness aren't set
+     * until Gecko is loaded, and we need to know this before then.
+     *
+     * The return value of this method should be used early since other
+     * initialization may depend on its results.
+     */
+    @CheckResult
+    public static boolean getIsInAutomationFromEnvironment(final SafeIntent intent) {
+        final HashMap<String, String> envVars = IntentUtils.getEnvVarMap(intent);
+        return !TextUtils.isEmpty(envVars.get(IntentUtils.ENV_VAR_IN_AUTOMATION));
+    }
 }