mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1277214 - Move SafeIntent to its own class. r=grisha
This gets used often enough that it's annoying to do full class name imports. MozReview-Commit-ID: 7Yhp1NCgwQw --HG-- extra : rebase_source : 4e4875153d171d8eb4c8ce49f8a6e6170ac5c616
This commit is contained in:
parent
9fda412bd8
commit
200e23d1c7
@ -52,7 +52,7 @@ 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.mozglue.SafeIntentUtils.SafeIntent;
|
||||
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;
|
||||
|
@ -25,7 +25,7 @@ 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.mozglue.SafeIntentUtils.SafeIntent;
|
||||
import org.mozilla.gecko.util.SafeIntent;
|
||||
import org.mozilla.gecko.mozglue.GeckoLoader;
|
||||
import org.mozilla.gecko.permissions.Permissions;
|
||||
import org.mozilla.gecko.preferences.ClearOnShutdownPref;
|
||||
|
@ -12,7 +12,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.gfx.BitmapUtils;
|
||||
import org.mozilla.gecko.mozglue.SafeIntentUtils.SafeIntent;
|
||||
import org.mozilla.gecko.util.SafeIntent;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
|
@ -20,7 +20,7 @@ import org.mozilla.gecko.annotation.RobocopTarget;
|
||||
import org.mozilla.gecko.AppConstants.Versions;
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.favicons.Favicons;
|
||||
import org.mozilla.gecko.mozglue.SafeIntentUtils.SafeIntent;
|
||||
import org.mozilla.gecko.util.SafeIntent;
|
||||
import org.mozilla.gecko.notifications.WhatsNewReceiver;
|
||||
import org.mozilla.gecko.reader.ReaderModeUtils;
|
||||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
|
@ -24,7 +24,7 @@ import android.util.Log;
|
||||
import org.mozilla.gecko.annotation.JNITarget;
|
||||
import org.mozilla.gecko.annotation.RobocopTarget;
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.mozglue.SafeIntentUtils.SafeIntent;
|
||||
import org.mozilla.gecko.util.SafeIntent;
|
||||
|
||||
public final class GeckoLoader {
|
||||
private static final String LOGTAG = "GeckoLoader";
|
||||
|
@ -5,12 +5,10 @@
|
||||
package org.mozilla.gecko.mozglue;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import org.mozilla.gecko.util.SafeIntent;
|
||||
|
||||
public class SafeIntentUtils {
|
||||
private static final String LOGTAG = "GeckoContextUtils";
|
||||
|
||||
public static Bundle getBundleExtra(final Intent intent, final String name) {
|
||||
return new SafeIntent(intent).getBundleExtra(name);
|
||||
@ -24,84 +22,4 @@ public class SafeIntentUtils {
|
||||
return new SafeIntent(intent).getBooleanExtra(name, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* External applications can pass values into Intents that can cause us to crash: in defense,
|
||||
* we wrap {@link Intent} and catch the exceptions they may force us to throw. See bug 1090385
|
||||
* for more.
|
||||
*/
|
||||
public static class SafeIntent {
|
||||
private final Intent intent;
|
||||
|
||||
public SafeIntent(final Intent intent) {
|
||||
this.intent = intent;
|
||||
}
|
||||
|
||||
public boolean getBooleanExtra(final String name, final boolean defaultValue) {
|
||||
try {
|
||||
return intent.getBooleanExtra(name, defaultValue);
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?");
|
||||
return defaultValue;
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras.", e);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public String getStringExtra(final String name) {
|
||||
try {
|
||||
return intent.getStringExtra(name);
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?");
|
||||
return null;
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Bundle getBundleExtra(final String name) {
|
||||
try {
|
||||
return intent.getBundleExtra(name);
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?");
|
||||
return null;
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return intent.getAction();
|
||||
}
|
||||
|
||||
public String getDataString() {
|
||||
try {
|
||||
return intent.getDataString();
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent data string: OOM. Malformed?");
|
||||
return null;
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent data string.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Uri getData() {
|
||||
try {
|
||||
return intent.getData();
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent data: OOM. Malformed?");
|
||||
return null;
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent data.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Intent getUnsafe() {
|
||||
return intent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,12 +11,12 @@ import org.mozilla.gecko.Locales;
|
||||
import org.mozilla.gecko.Telemetry;
|
||||
import org.mozilla.gecko.TelemetryContract;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.mozglue.SafeIntentUtils;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import org.mozilla.gecko.util.SafeIntent;
|
||||
|
||||
/**
|
||||
* This class takes over external url loads (Intent.VIEW) from the BrowserApp class. It determines if
|
||||
@ -40,7 +40,7 @@ public class TabQueueDispatcher extends Locales.LocaleAwareActivity {
|
||||
int flags = intent.getFlags() & ~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
|
||||
intent.setFlags(flags);
|
||||
|
||||
SafeIntentUtils.SafeIntent safeIntent = new SafeIntentUtils.SafeIntent(intent);
|
||||
SafeIntent safeIntent = new SafeIntent(intent);
|
||||
|
||||
// For the moment lets exit early and start fennec as normal if we're not in nightly with
|
||||
// the tab queue build flag.
|
||||
|
@ -11,7 +11,6 @@ import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.Telemetry;
|
||||
import org.mozilla.gecko.TelemetryContract;
|
||||
import org.mozilla.gecko.mozglue.SafeIntentUtils;
|
||||
import org.mozilla.gecko.preferences.GeckoPreferences;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
@ -40,6 +39,7 @@ import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import org.mozilla.gecko.util.SafeIntent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@ -131,7 +131,7 @@ public class TabQueueService extends Service {
|
||||
|
||||
final String lastUrl = sharedPreferences.getString(GeckoPreferences.PREFS_TAB_QUEUE_LAST_SITE, "");
|
||||
|
||||
final SafeIntentUtils.SafeIntent safeIntent = new SafeIntentUtils.SafeIntent(intent);
|
||||
final SafeIntent safeIntent = new SafeIntent(intent);
|
||||
final String intentUrl = safeIntent.getDataString();
|
||||
|
||||
final long lastRunTime = sharedPreferences.getLong(GeckoPreferences.PREFS_TAB_QUEUE_LAST_TIME, 0);
|
||||
@ -277,7 +277,7 @@ public class TabQueueService extends Service {
|
||||
Log.w(LOGTAG, "Error adding URL to tab queue - invalid intent passed in.");
|
||||
return;
|
||||
}
|
||||
final SafeIntentUtils.SafeIntent safeIntent = new SafeIntentUtils.SafeIntent(intent);
|
||||
final SafeIntent safeIntent = new SafeIntent(intent);
|
||||
final String intentData = safeIntent.getDataString();
|
||||
|
||||
// As we're doing disk IO, let's run this stuff in a separate thread.
|
||||
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* External applications can pass values into Intents that can cause us to crash: in defense,
|
||||
* we wrap {@link Intent} and catch the exceptions they may force us to throw. See bug 1090385
|
||||
* for more.
|
||||
*/
|
||||
public class SafeIntent {
|
||||
private static final String LOGTAG = "Gecko" + SafeIntent.class.getSimpleName();
|
||||
|
||||
private final Intent intent;
|
||||
|
||||
public SafeIntent(final Intent intent) {
|
||||
this.intent = intent;
|
||||
}
|
||||
|
||||
public boolean getBooleanExtra(final String name, final boolean defaultValue) {
|
||||
try {
|
||||
return intent.getBooleanExtra(name, defaultValue);
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?");
|
||||
return defaultValue;
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras.", e);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public String getStringExtra(final String name) {
|
||||
try {
|
||||
return intent.getStringExtra(name);
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?");
|
||||
return null;
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Bundle getBundleExtra(final String name) {
|
||||
try {
|
||||
return intent.getBundleExtra(name);
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras: OOM. Malformed?");
|
||||
return null;
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent extras.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return intent.getAction();
|
||||
}
|
||||
|
||||
public String getDataString() {
|
||||
try {
|
||||
return intent.getDataString();
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent data string: OOM. Malformed?");
|
||||
return null;
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent data string.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Uri getData() {
|
||||
try {
|
||||
return intent.getData();
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent data: OOM. Malformed?");
|
||||
return null;
|
||||
} catch (RuntimeException e) {
|
||||
Log.w(LOGTAG, "Couldn't get intent data.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Intent getUnsafe() {
|
||||
return intent;
|
||||
}
|
||||
}
|
@ -128,6 +128,7 @@ gujar.sources += ['java/org/mozilla/gecko/' + x for x in [
|
||||
'util/PrefUtils.java',
|
||||
'util/ProxySelector.java',
|
||||
'util/RawResource.java',
|
||||
'util/SafeIntent.java',
|
||||
'util/StringUtils.java',
|
||||
'util/ThreadUtils.java',
|
||||
'util/UIAsyncTask.java',
|
||||
|
Loading…
Reference in New Issue
Block a user