2010-10-24 13:26:19 -07:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2010-06-02 14:55:28 -07:00
|
|
|
|
|
|
|
#filter substitution
|
2010-12-21 17:56:07 -08:00
|
|
|
package @ANDROID_PACKAGE_NAME@;
|
2010-06-02 14:55:28 -07:00
|
|
|
|
2010-10-26 18:57:29 -07:00
|
|
|
import android.app.*;
|
2010-06-02 14:55:28 -07:00
|
|
|
import android.content.*;
|
2010-10-24 13:26:19 -07:00
|
|
|
import android.util.*;
|
|
|
|
import android.os.*;
|
2010-06-02 14:55:28 -07:00
|
|
|
import java.io.*;
|
2011-03-04 15:00:52 -08:00
|
|
|
import org.mozilla.gecko.GeckoAppShell;
|
2010-06-02 14:55:28 -07:00
|
|
|
|
2010-10-26 18:57:29 -07:00
|
|
|
public class Restarter extends Activity {
|
2011-02-28 14:10:40 -08:00
|
|
|
|
2010-10-24 13:26:19 -07:00
|
|
|
@Override
|
2010-10-26 18:57:29 -07:00
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2010-06-02 14:55:28 -07:00
|
|
|
Log.i("Restarter", "trying to restart @MOZ_APP_NAME@");
|
2010-10-24 13:26:19 -07:00
|
|
|
try {
|
2011-03-04 15:00:52 -08:00
|
|
|
int countdown = 40;
|
|
|
|
while (GeckoAppShell.checkForGeckoProcs() && --countdown > 0) {
|
|
|
|
// Wait for the old process to die before we continue
|
|
|
|
try {
|
|
|
|
Thread.currentThread().sleep(100);
|
|
|
|
} catch (InterruptedException ie) {}
|
|
|
|
}
|
|
|
|
|
2011-03-10 19:52:50 -08:00
|
|
|
if (countdown <= 0) {
|
|
|
|
// if the countdown expired, something is hung
|
2011-03-04 15:00:52 -08:00
|
|
|
GeckoAppShell.killAnyZombies();
|
2011-03-10 19:52:50 -08:00
|
|
|
countdown = 10;
|
|
|
|
// wait for the kill to take effect
|
|
|
|
while (GeckoAppShell.checkForGeckoProcs() && --countdown > 0) {
|
|
|
|
try {
|
|
|
|
Thread.currentThread().sleep(100);
|
|
|
|
} catch (InterruptedException ie) {}
|
|
|
|
}
|
|
|
|
}
|
2010-06-02 14:55:28 -07:00
|
|
|
} catch (Exception e) {
|
2010-10-24 13:26:19 -07:00
|
|
|
Log.i("Restarter", e.toString());
|
2010-06-02 14:55:28 -07:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
String action = "android.intent.action.MAIN";
|
2010-10-24 13:26:19 -07:00
|
|
|
Intent intent = new Intent(action);
|
2010-12-21 17:56:07 -08:00
|
|
|
intent.setClassName("@ANDROID_PACKAGE_NAME@",
|
|
|
|
"@ANDROID_PACKAGE_NAME@.App");
|
2010-10-26 18:57:29 -07:00
|
|
|
Bundle b = getIntent().getExtras();
|
2010-10-24 13:26:19 -07:00
|
|
|
if (b != null)
|
|
|
|
intent.putExtras(b);
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
Log.i("GeckoAppJava", intent.toString());
|
2010-10-26 18:57:29 -07:00
|
|
|
startActivity(intent);
|
2010-06-02 14:55:28 -07:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.i("Restarter", e.toString());
|
|
|
|
}
|
2011-03-04 15:00:52 -08:00
|
|
|
// Give the new process time to start before we die
|
|
|
|
GeckoAppShell.waitForAnotherGeckoProc();
|
2010-10-24 13:26:19 -07:00
|
|
|
System.exit(0);
|
2010-06-02 14:55:28 -07:00
|
|
|
}
|
|
|
|
};
|