Backing out android bug 607939 - fail to opened a URL / link from another application after launching. This caused a regression filed as bug 614801. a=me

This commit is contained in:
Doug Turner 2010-11-25 22:02:06 -08:00
parent ed9e78b8a6
commit 76721219af
3 changed files with 85 additions and 122 deletions

View File

@ -71,28 +71,6 @@ abstract public class GeckoApp
public static boolean mFullscreen = false;
ProgressDialog mProgressDialog;
enum LaunchState {PreLaunch, Launching, WaitButton,
Launched, GeckoRunning, GeckoExiting};
private LaunchState mLaunchState = LaunchState.PreLaunch;
synchronized boolean checkLaunchState(LaunchState checkState) {
return mLaunchState == checkState;
}
synchronized void setLaunchState(LaunchState setState) {
mLaunchState = setState;
}
// if mLaunchState is equal to checkState this sets mLaunchState to setState
// and return true. Otherwise we return false.
synchronized boolean checkAndSetLaunchState(LaunchState checkState, LaunchState setState) {
if (mLaunchState != checkState)
return false;
mLaunchState = setState;
return true;
}
void showErrorDialog(String message)
{
new AlertDialog.Builder(this)
@ -108,40 +86,28 @@ abstract public class GeckoApp
}).show();
}
// Returns true when the intent is going to be handled by gecko launch
boolean launch(Intent i)
void launch()
{
if (!checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched))
return false;
// unpack files in the components directory
try {
unpackComponents();
} catch (FileNotFoundException fnfe) {
showErrorDialog(getString(R.string.error_loading_file));
return false;
return;
} catch (IOException ie) {
String msg = ie.getMessage();
if (msg.equalsIgnoreCase("No space left on device"))
showErrorDialog(getString(R.string.no_space_to_start_error));
else
showErrorDialog(getString(R.string.error_loading_file));
return false;
return;
}
mProgressDialog =
ProgressDialog.show(GeckoApp.this, "",
getString(R.string.splash_screen_label),
true);
// and then fire us up
if (i == null)
i = getIntent();
Intent i = getIntent();
String env = i.getStringExtra("env0");
GeckoAppShell.runGecko(getApplication().getPackageResourcePath(),
i.getStringExtra("args"),
i.getDataString());
return true;
}
/** Called when the activity is first created. */
@ -170,81 +136,11 @@ abstract public class GeckoApp
setContentView(mainLayout,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT));
if (!checkAndSetLaunchState(LaunchState.PreLaunch,
LaunchState.Launching))
return;
checkAndLaunchUpdate();
if (!checkCPUCompatability())
return;
// Load our JNI libs
GeckoAppShell.loadGeckoLibs(getApplication().getPackageResourcePath());
}
boolean checkCPUCompatability() {
try {
BufferedReader reader =
new BufferedReader(new FileReader("/proc/cpuinfo"));
String line;
while ((line = reader.readLine()) != null) {
int index = line.indexOf("Processor");
if (index == -1)
continue;
int version = 5;
if (line.indexOf("(v8l)") != -1)
version = 8;
if (line.indexOf("(v7l)") != -1)
version = 7;
if (line.indexOf("(v6l)") != -1)
version = 6;
if (version < getMinCPUVersion()) {
showErrorDialog(
getString(R.string.incompatable_cpu_error));
return false;
}
else {
break;
}
}
} catch (Exception ex) {
// Not much we can do here, just continue assuming we're okay
Log.i("GeckoApp", "exception: " + ex);
}
return true;
}
@Override
protected void onNewIntent(Intent intent) {
if (checkLaunchState(LaunchState.GeckoExiting)) {
// We're exiting and shouldn't try to do anything else just incase
// we're hung for some reason we'll force the process to exit
System.exit(0);
return;
}
final String action = intent.getAction();
if (action.equals("org.mozilla.gecko.DEBUG") &&
checkAndSetLaunchState(LaunchState.Launching, LaunchState.WaitButton)) {
final Button launchButton = new Button(this);
launchButton.setText("Launch"); // don't need to localize
launchButton.setOnClickListener(new Button.OnClickListener() {
public void onClick (View v) {
// hide the button so we can't be launched again
mainLayout.removeView(launchButton);
setLaunchState(LaunchState.Launching);
launch(null);
}
});
mainLayout.addView(launchButton, 300, 200);
return;
}
if (checkLaunchState(LaunchState.WaitButton) || launch(intent))
return;
if (Intent.ACTION_VIEW.equals(action)) {
String uri = intent.getDataString();
GeckoAppShell.sendEventToGecko(new GeckoEvent(uri));
@ -281,16 +177,11 @@ abstract public class GeckoApp
public void onResume()
{
Log.i("GeckoApp", "resume");
if (checkLaunchState(LaunchState.GeckoRunning))
if (GeckoAppShell.sGeckoRunning)
GeckoAppShell.onResume();
// After an onPause, the activity is back in the foreground.
// Undo whatever we did in onPause.
super.onResume();
// Just in case. Normally we start in onNewIntent
if (checkLaunchState(LaunchState.PreLaunch) ||
checkLaunchState(LaunchState.Launching))
onNewIntent(getIntent());
}
@Override
@ -325,6 +216,75 @@ abstract public class GeckoApp
{
Log.i("GeckoApp", "start");
super.onStart();
boolean useLaunchButton = false;
String intentAction = getIntent().getAction();
if (intentAction != null && intentAction.equals("org.mozilla.gecko.DEBUG"))
useLaunchButton = true;
if (!GeckoAppShell.sGeckoRunning) {
checkAndLaunchUpdate();
try {
BufferedReader reader =
new BufferedReader(new FileReader("/proc/cpuinfo"));
String line;
while ((line = reader.readLine()) != null) {
int index = line.indexOf("Processor");
if (index == -1)
continue;
int version = 5;
if (line.indexOf("(v8l)") != -1)
version = 8;
if (line.indexOf("(v7l)") != -1)
version = 7;
if (line.indexOf("(v6l)") != -1)
version = 6;
if (version < getMinCPUVersion()) {
showErrorDialog(
getString(R.string.incompatable_cpu_error));
return;
}
else {
break;
}
}
} catch (Exception ex) {
// Not much we can do here, just continue assuming we're okay
Log.i("GeckoApp", "exception: " + ex);
}
if (!useLaunchButton) {
mProgressDialog =
ProgressDialog.show(GeckoApp.this, "",
getString(R.string.splash_screen_label),
true);
}
// Load our JNI libs; we need to do this before launch() because
// setInitialSize will be called even before Gecko is actually up
// and running.
GeckoAppShell.loadGeckoLibs(getApplication().getPackageResourcePath());
if (useLaunchButton) {
final Button b = new Button(this);
b.setText("Launch"); // don't need to localize
b.setOnClickListener(new Button.OnClickListener() {
public void onClick (View v) {
// hide the button so we can't be launched again
mainLayout.removeView(b);
launch();
}
});
mainLayout.addView(b, 300, 200);
} else {
launch();
}
}
}
@Override
@ -351,7 +311,7 @@ abstract public class GeckoApp
public void onLowMemory()
{
Log.i("GeckoApp", "low memory");
if (checkLaunchState(LaunchState.GeckoRunning))
if (GeckoAppShell.sGeckoRunning)
GeckoAppShell.onLowMemory();
super.onLowMemory();
}

View File

@ -61,9 +61,14 @@ import android.net.Uri;
class GeckoAppShell
{
static {
sGeckoRunning = false;
}
// static members only
private GeckoAppShell() { }
static boolean sGeckoRunning;
static private GeckoEvent gPendingResize = null;
static private boolean gRestartScheduled = false;
@ -144,7 +149,7 @@ class GeckoAppShell
private static GeckoEvent mLastDrawEvent;
public static void sendEventToGecko(GeckoEvent e) {
if (GeckoApp.mAppContext.checkLaunchState(GeckoApp.LaunchState.GeckoRunning)) {
if (sGeckoRunning) {
if (gPendingResize != null) {
notifyGeckoOfEvent(gPendingResize);
gPendingResize = null;
@ -333,8 +338,7 @@ class GeckoAppShell
static void onAppShellReady()
{
// mLaunchState can only be Launched at this point
GeckoApp.mAppContext.setLaunchState(GeckoApp.LaunchState.GeckoRunning);
sGeckoRunning = true;
if (gPendingResize != null) {
notifyGeckoOfEvent(gPendingResize);
gPendingResize = null;
@ -342,8 +346,7 @@ class GeckoAppShell
}
static void onXreExit() {
// mLaunchState can only be Launched or GeckoRunning at this point
GeckoApp.mAppContext.setLaunchState(GeckoApp.LaunchState.GeckoExiting);
sGeckoRunning = false;
Log.i("GeckoAppJava", "XRE exited");
if (gRestartScheduled) {
GeckoApp.mAppContext.doRestart();

View File

@ -113,8 +113,8 @@ class GeckoSurfaceView
mSoftwareBuffer.capacity() < (width * height * 2) ||
mWidth != width || mHeight != height)
mSoftwareBuffer = ByteBuffer.allocateDirect(width * height * 2);
boolean doSyncDraw = m2DMode && mSoftwareBuffer != null &&
GeckoApp.mAppContext.checkLaunchState(GeckoApp.LaunchState.GeckoRunning);
boolean doSyncDraw = GeckoAppShell.sGeckoRunning && m2DMode &&
mSoftwareBuffer != null;
mSyncDraw = doSyncDraw;
mFormat = format;