michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko; michael@0: michael@0: import android.app.Activity; michael@0: import android.content.Intent; michael@0: import android.os.Bundle; michael@0: import android.util.Log; michael@0: michael@0: public class Restarter extends Activity { michael@0: private static final String LOGTAG = "GeckoRestarter"; michael@0: michael@0: @Override michael@0: public void onCreate(Bundle savedInstanceState) { michael@0: super.onCreate(savedInstanceState); michael@0: michael@0: Log.i(LOGTAG, "Trying to restart " + AppConstants.MOZ_APP_NAME); michael@0: try { michael@0: int countdown = 40; michael@0: while (GeckoAppShell.checkForGeckoProcs() && --countdown > 0) { michael@0: // Wait for the old process to die before we continue michael@0: try { michael@0: Thread.sleep(100); michael@0: } catch (InterruptedException ie) {} michael@0: } michael@0: michael@0: if (countdown <= 0) { michael@0: // if the countdown expired, something is hung michael@0: GeckoAppShell.killAnyZombies(); michael@0: countdown = 10; michael@0: // wait for the kill to take effect michael@0: while (GeckoAppShell.checkForGeckoProcs() && --countdown > 0) { michael@0: try { michael@0: Thread.sleep(100); michael@0: } catch (InterruptedException ie) {} michael@0: } michael@0: } michael@0: } catch (Exception e) { michael@0: Log.i(LOGTAG, e.toString()); michael@0: } michael@0: try { michael@0: Intent intent = new Intent(Intent.ACTION_MAIN); michael@0: intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, michael@0: AppConstants.BROWSER_INTENT_CLASS_NAME); michael@0: Bundle b = getIntent().getExtras(); michael@0: if (b != null) michael@0: intent.putExtras(b); michael@0: Log.i(LOGTAG, intent.toString()); michael@0: startActivity(intent); michael@0: } catch (Exception e) { michael@0: Log.i(LOGTAG, e.toString()); michael@0: } michael@0: } michael@0: }