From 04614d0e3d75cf0179059a8452a7261e59b0aa05 Mon Sep 17 00:00:00 2001 From: Brian Nicholson Date: Fri, 15 Nov 2013 22:59:17 -0800 Subject: [PATCH] Bug 874985 - Part 2: Add stateBundle extra to allow injecting fake state bundles. r=mfinkle,gbrown --- mobile/android/base/GeckoApp.java | 54 ++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index d50cf7b65fce1..9e840ee80ce5d 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -139,21 +139,26 @@ private static enum StartupAction { PREFETCH /* launched with a passed URL that we prefetch */ } - public static final String ACTION_ALERT_CALLBACK = "org.mozilla.gecko.ACTION_ALERT_CALLBACK"; - public static final String ACTION_WEBAPP_PREFIX = "org.mozilla.gecko.WEBAPP"; - public static final String ACTION_DEBUG = "org.mozilla.gecko.DEBUG"; - public static final String ACTION_BOOKMARK = "org.mozilla.gecko.BOOKMARK"; - public static final String ACTION_LOAD = "org.mozilla.gecko.LOAD"; - public static final String ACTION_LAUNCH_SETTINGS = "org.mozilla.gecko.SETTINGS"; - public static final String ACTION_INIT_PW = "org.mozilla.gecko.INIT_PW"; - public static final String SAVED_STATE_IN_BACKGROUND = "inBackground"; + public static final String ACTION_ALERT_CALLBACK = "org.mozilla.gecko.ACTION_ALERT_CALLBACK"; + public static final String ACTION_BOOKMARK = "org.mozilla.gecko.BOOKMARK"; + public static final String ACTION_DEBUG = "org.mozilla.gecko.DEBUG"; + public static final String ACTION_LAUNCH_SETTINGS = "org.mozilla.gecko.SETTINGS"; + public static final String ACTION_LOAD = "org.mozilla.gecko.LOAD"; + public static final String ACTION_INIT_PW = "org.mozilla.gecko.INIT_PW"; + public static final String ACTION_WEBAPP_PREFIX = "org.mozilla.gecko.WEBAPP"; + + public static final String EXTRA_STATE_BUNDLE = "stateBundle"; + + public static final String PREFS_ALLOW_STATE_BUNDLE = "allowStateBundle"; + public static final String PREFS_CRASHED = "crashed"; + public static final String PREFS_NAME = "GeckoApp"; + public static final String PREFS_OOM_EXCEPTION = "OOMException"; + public static final String PREFS_VERSION_CODE = "versionCode"; + public static final String PREFS_WAS_STOPPED = "wasStopped"; + + public static final String SAVED_STATE_IN_BACKGROUND = "inBackground"; public static final String SAVED_STATE_PRIVATE_SESSION = "privateSession"; - public static final String PREFS_NAME = "GeckoApp"; - public static final String PREFS_OOM_EXCEPTION = "OOMException"; - public static final String PREFS_WAS_STOPPED = "wasStopped"; - public static final String PREFS_VERSION_CODE = "versionCode"; - static private final String LOCATION_URL = "https://location.services.mozilla.com/v1/submit"; // Delay before running one-time "cleanup" tasks that may be needed @@ -1219,6 +1224,24 @@ public void onCreate(Bundle savedInstanceState) } } + Bundle stateBundle = getIntent().getBundleExtra(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. + SharedPreferences prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); + if (prefs.getBoolean(PREFS_ALLOW_STATE_BUNDLE, false)) { + Log.i(LOGTAG, "Restoring state from intent bundle"); + prefs.edit().remove(PREFS_ALLOW_STATE_BUNDLE).commit(); + savedInstanceState = stateBundle; + } + } else if (savedInstanceState != null) { + // Bug 896992 - This intent has already been handled; reset the intent. + setIntent(new Intent(Intent.ACTION_MAIN)); + } + + super.onCreate(savedInstanceState); mOrientation = getResources().getConfiguration().orientation; @@ -1248,11 +1271,6 @@ public void onCreate(Bundle savedInstanceState) mPrivateBrowsingSession = savedInstanceState.getString(SAVED_STATE_PRIVATE_SESSION); } - if (savedInstanceState != null) { - // Bug 896992 - This intent has already been handled; reset the intent. - setIntent(new Intent(Intent.ACTION_MAIN)); - } - // Perform background initialization. ThreadUtils.postToBackgroundThread(new Runnable() { @Override