Bug 1277214 - Move remaining SafeIntentUtils functions to IntentUtils. r=grisha draft
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 01 Jun 2016 15:32:41 -0700
changeset 374143 c03e0c52b9b5a16d651547fb7176dd79c0ed0ecf
parent 374142 c6ab0adc687381281fb819c836c74897252b3daf
child 374144 362a73a76f94e1f7403b1c08f804a97f41fbdd26
push id19946
push usermichael.l.comella@gmail.com
push dateWed, 01 Jun 2016 23:55:51 +0000
reviewersgrisha
bugs1277214
milestone49.0a1
Bug 1277214 - Move remaining SafeIntentUtils functions to IntentUtils. r=grisha I feel this better follows the util class pattern: IntentUtils acts on Intents as StringUtils would act on Strings. MozReview-Commit-ID: 7n2B9q1KlSy
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
mobile/android/base/java/org/mozilla/gecko/mozglue/SafeIntentUtils.java
mobile/android/base/java/org/mozilla/gecko/overlays/ui/ShareDialog.java
mobile/android/base/java/org/mozilla/gecko/util/IntentUtils.java
mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -48,17 +48,16 @@ import org.mozilla.gecko.home.HomePager;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenInBackgroundListener;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 import org.mozilla.gecko.home.HomePanelsManager;
 import org.mozilla.gecko.home.SearchEngine;
 import org.mozilla.gecko.javaaddons.JavaAddonManager;
 import org.mozilla.gecko.media.AudioFocusAgent;
 import org.mozilla.gecko.menu.GeckoMenu;
 import org.mozilla.gecko.menu.GeckoMenuItem;
-import org.mozilla.gecko.mozglue.SafeIntentUtils;
 import org.mozilla.gecko.util.SafeIntent;
 import org.mozilla.gecko.overlays.ui.ShareDialog;
 import org.mozilla.gecko.permissions.Permissions;
 import org.mozilla.gecko.preferences.ClearOnShutdownPref;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.promotion.AddToHomeScreenPromotion;
 import org.mozilla.gecko.delegates.BookmarkStateChangeDelegate;
 import org.mozilla.gecko.promotion.ReaderViewBookmarkPromotion;
@@ -784,17 +783,17 @@ public class BrowserApp extends GeckoApp
      * Initializes the default Switchboard URLs the first time.
      * @param intent
      */
     private void initSwitchboard(final Intent intent) {
         if (Experiments.isDisabled() || !AppConstants.MOZ_SWITCHBOARD) {
             return;
         }
 
-        final String hostExtra = SafeIntentUtils.getStringExtra(intent, INTENT_KEY_SWITCHBOARD_HOST);
+        final String hostExtra = IntentUtils.getStringExtraSafe(intent, INTENT_KEY_SWITCHBOARD_HOST);
         final String host = TextUtils.isEmpty(hostExtra) ? DEFAULT_SWITCHBOARD_HOST : hostExtra;
 
         final String serverUrl;
         try {
             serverUrl = new URL("https", host, "v2").toString();
         } catch (MalformedURLException e) {
             Log.e(LOGTAG, "Error creating Switchboard server URL", e);
             return;
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -19,17 +19,17 @@ import org.mozilla.gecko.gfx.LayerView;
 import org.mozilla.gecko.gfx.PluginLayer;
 import org.mozilla.gecko.health.HealthRecorder;
 import org.mozilla.gecko.health.SessionInformation;
 import org.mozilla.gecko.health.StubbedHealthRecorder;
 import org.mozilla.gecko.home.HomeConfig.PanelType;
 import org.mozilla.gecko.menu.GeckoMenu;
 import org.mozilla.gecko.menu.GeckoMenuInflater;
 import org.mozilla.gecko.menu.MenuPanel;
-import org.mozilla.gecko.mozglue.SafeIntentUtils;
+import org.mozilla.gecko.util.IntentUtils;
 import org.mozilla.gecko.util.SafeIntent;
 import org.mozilla.gecko.mozglue.GeckoLoader;
 import org.mozilla.gecko.permissions.Permissions;
 import org.mozilla.gecko.preferences.ClearOnShutdownPref;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.prompts.PromptService;
 import org.mozilla.gecko.restrictions.Restrictions;
 import org.mozilla.gecko.tabqueue.TabQueueHelper;
@@ -1219,17 +1219,17 @@ public abstract class GeckoApp
             "ToggleChrome:Hide",
             "ToggleChrome:Show",
             "Update:Check",
             "Update:Download",
             "Update:Install");
 
         GeckoThread.launch();
 
-        Bundle stateBundle = SafeIntentUtils.getBundleExtra(getIntent(), EXTRA_STATE_BUNDLE);
+        Bundle stateBundle = IntentUtils.getBundleExtraSafe(getIntent(), EXTRA_STATE_BUNDLE);
         if (stateBundle != null) {
             // Use the state bundle if it was given as an intent extra. This is
             // only intended to be used internally via Robocop, so a boolean
             // is read from a private shared pref to prevent other apps from
             // injecting states.
             final SharedPreferences prefs = getSharedPreferences();
             if (prefs.getBoolean(PREFS_ALLOW_STATE_BUNDLE, false)) {
                 prefs.edit().remove(PREFS_ALLOW_STATE_BUNDLE).apply();
@@ -1827,17 +1827,17 @@ public abstract class GeckoApp
         return prefs.getBoolean(GeckoPreferences.PREFS_RESTORE_SESSION_FROM_CRASH, true);
     }
 
     private String getSessionRestorePreference(SharedPreferences prefs) {
         return prefs.getString(GeckoPreferences.PREFS_RESTORE_SESSION, "always");
     }
 
     private boolean getRestartFromIntent() {
-        return SafeIntentUtils.getBooleanExtra(getIntent(), "didRestart", false);
+        return IntentUtils.getBooleanExtraSafe(getIntent(), "didRestart", false);
     }
 
     /**
      * Enable Android StrictMode checks (for supported OS versions).
      * http://developer.android.com/reference/android/os/StrictMode.html
      */
     private void enableStrictMode() {
         Log.d(LOGTAG, "Enabling Android StrictMode");
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
@@ -19,21 +19,21 @@ import org.json.JSONObject;
 import org.mozilla.gecko.GeckoProfileDirectories.NoMozillaDirectoryException;
 import org.mozilla.gecko.GeckoProfileDirectories.NoSuchProfileException;
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.LocalBrowserDB;
 import org.mozilla.gecko.db.StubBrowserDB;
 import org.mozilla.gecko.distribution.Distribution;
 import org.mozilla.gecko.firstrun.FirstrunAnimationContainer;
-import org.mozilla.gecko.mozglue.SafeIntentUtils;
 import org.mozilla.gecko.preferences.DistroSharedPrefsImport;
 import org.mozilla.gecko.util.FileUtils;
 import org.mozilla.gecko.util.INIParser;
 import org.mozilla.gecko.util.INISection;
+import org.mozilla.gecko.util.IntentUtils;
 
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
@@ -222,17 +222,17 @@ public final class GeckoProfile {
             // If no profile info was passed in, look for the active profile or a default profile.
             final GeckoProfile profile = GeckoThread.getActiveProfile();
             if (profile != null) {
                 return profile;
             }
 
             final String args;
             if (context instanceof Activity) {
-                args = SafeIntentUtils.getStringExtra(((Activity) context).getIntent(), "args");
+                args = IntentUtils.getStringExtraSafe(((Activity) context).getIntent(), "args");
             } else {
                 args = null;
             }
 
             return GeckoProfile.initFromArgs(context, args);
 
         } else if (profileName == null) {
             // If only profile dir was passed in, use custom (anonymous) profile.
deleted file mode 100644
--- a/mobile/android/base/java/org/mozilla/gecko/mozglue/SafeIntentUtils.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * 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.mozglue;
-
-import android.content.Intent;
-import android.os.Bundle;
-import org.mozilla.gecko.util.SafeIntent;
-
-public class SafeIntentUtils {
-
-    public static Bundle getBundleExtra(final Intent intent, final String name) {
-        return new SafeIntent(intent).getBundleExtra(name);
-    }
-
-    public static String getStringExtra(final Intent intent, final String name) {
-        return new SafeIntent(intent).getStringExtra(name);
-    }
-
-    public static boolean getBooleanExtra(Intent intent, String name, boolean defaultValue) {
-        return new SafeIntent(intent).getBooleanExtra(name, defaultValue);
-    }
-
-}
--- a/mobile/android/base/java/org/mozilla/gecko/overlays/ui/ShareDialog.java
+++ b/mobile/android/base/java/org/mozilla/gecko/overlays/ui/ShareDialog.java
@@ -15,17 +15,17 @@ import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.LocalBrowserDB;
 import org.mozilla.gecko.db.RemoteClient;
 import org.mozilla.gecko.overlays.OverlayConstants;
 import org.mozilla.gecko.overlays.service.OverlayActionService;
 import org.mozilla.gecko.overlays.service.sharemethods.SendTab;
 import org.mozilla.gecko.overlays.service.sharemethods.ShareMethod;
 import org.mozilla.gecko.sync.setup.activities.WebURLFinder;
-import org.mozilla.gecko.mozglue.SafeIntentUtils;
+import org.mozilla.gecko.util.IntentUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.util.UIAsyncTask;
 
 import android.content.BroadcastReceiver;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
@@ -203,17 +203,17 @@ public class ShareDialog extends Locales
                 State.DEVICES_ONLY : State.DEFAULT;
 
         // If the Activity is being reused, we need to reset the state. Ideally, we create a
         // new instance for each call, but Android L breaks this (bug 1137928).
         sendTabList.switchState(SendTabList.State.LOADING);
         bookmarkButton.setBackgroundDrawable(bookmarkButtonDrawable);
 
         // The URL is usually hiding somewhere in the extra text. Extract it.
-        final String extraText = SafeIntentUtils.getStringExtra(intent, Intent.EXTRA_TEXT);
+        final String extraText = IntentUtils.getStringExtraSafe(intent, Intent.EXTRA_TEXT);
         if (TextUtils.isEmpty(extraText)) {
             abortDueToNoURL();
             return;
         }
 
         final String pageUrl = new WebURLFinder(extraText).bestWebURL();
         if (TextUtils.isEmpty(pageUrl)) {
             abortDueToNoURL();
--- a/mobile/android/base/java/org/mozilla/gecko/util/IntentUtils.java
+++ b/mobile/android/base/java/org/mozilla/gecko/util/IntentUtils.java
@@ -2,16 +2,17 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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.NonNull;
 
 import java.util.HashMap;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 /**
  * Utilities for Intents.
@@ -51,9 +52,21 @@ public class IntentUtils {
                 final String envVarValue = matcher.group(2);
                 out.put(envVarName, envVarValue);
             }
             envValue = intent.getStringExtra("env" + i);
             i += 1;
         }
         return out;
     }
+
+    public static Bundle getBundleExtraSafe(final Intent intent, final String name) {
+        return new SafeIntent(intent).getBundleExtra(name);
+    }
+
+    public static String getStringExtraSafe(final Intent intent, final String name) {
+        return new SafeIntent(intent).getStringExtra(name);
+    }
+
+    public static boolean getBooleanExtraSafe(Intent intent, String name, boolean defaultValue) {
+        return new SafeIntent(intent).getBooleanExtra(name, defaultValue);
+    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java
@@ -11,20 +11,20 @@ import android.support.design.widget.Sna
 import android.util.Base64;
 import android.view.Menu;
 
 import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.SnackbarHelper;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
-import org.mozilla.gecko.mozglue.SafeIntentUtils;
 import org.mozilla.gecko.overlays.ui.ShareDialog;
 import org.mozilla.gecko.menu.MenuItemSwitcherLayout;
 import org.mozilla.gecko.util.IOUtils;
+import org.mozilla.gecko.util.IntentUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.view.MenuItem;
 import android.view.MenuItem.OnMenuItemClickListener;
@@ -284,17 +284,17 @@ public class GeckoActionProvider {
 
     /**
      * Downloads the URI pointed to by a share intent, and alters the intent to point to the
      * locally stored file.
      *
      * @param intent share intent to alter in place.
      */
     public void downloadImageForIntent(final Intent intent) {
-        final String src = SafeIntentUtils.getStringExtra(intent, Intent.EXTRA_TEXT);
+        final String src = IntentUtils.getStringExtraSafe(intent, Intent.EXTRA_TEXT);
         final File dir = GeckoApp.getTempDirectory();
 
         if (src == null || dir == null) {
             // We should be, but currently aren't, statically guaranteed an Activity context.
             // Try our best.
             if (mContext instanceof Activity) {
                 SnackbarHelper.showSnackbar((Activity) mContext,
                         mContext.getApplicationContext().getString(R.string.share_image_failed),