Skip to content

Commit

Permalink
Bug 874985 - Part 2: Add stateBundle extra to allow injecting fake st…
Browse files Browse the repository at this point in the history
…ate bundles. r=mfinkle,gbrown
  • Loading branch information
thebnich committed Nov 16, 2013
1 parent 226d3be commit 04614d0
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions mobile/android/base/GeckoApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 04614d0

Please sign in to comment.