1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/Restarter.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko; 1.10 + 1.11 +import android.app.Activity; 1.12 +import android.content.Intent; 1.13 +import android.os.Bundle; 1.14 +import android.util.Log; 1.15 + 1.16 +public class Restarter extends Activity { 1.17 + private static final String LOGTAG = "GeckoRestarter"; 1.18 + 1.19 + @Override 1.20 + public void onCreate(Bundle savedInstanceState) { 1.21 + super.onCreate(savedInstanceState); 1.22 + 1.23 + Log.i(LOGTAG, "Trying to restart " + AppConstants.MOZ_APP_NAME); 1.24 + try { 1.25 + int countdown = 40; 1.26 + while (GeckoAppShell.checkForGeckoProcs() && --countdown > 0) { 1.27 + // Wait for the old process to die before we continue 1.28 + try { 1.29 + Thread.sleep(100); 1.30 + } catch (InterruptedException ie) {} 1.31 + } 1.32 + 1.33 + if (countdown <= 0) { 1.34 + // if the countdown expired, something is hung 1.35 + GeckoAppShell.killAnyZombies(); 1.36 + countdown = 10; 1.37 + // wait for the kill to take effect 1.38 + while (GeckoAppShell.checkForGeckoProcs() && --countdown > 0) { 1.39 + try { 1.40 + Thread.sleep(100); 1.41 + } catch (InterruptedException ie) {} 1.42 + } 1.43 + } 1.44 + } catch (Exception e) { 1.45 + Log.i(LOGTAG, e.toString()); 1.46 + } 1.47 + try { 1.48 + Intent intent = new Intent(Intent.ACTION_MAIN); 1.49 + intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, 1.50 + AppConstants.BROWSER_INTENT_CLASS_NAME); 1.51 + Bundle b = getIntent().getExtras(); 1.52 + if (b != null) 1.53 + intent.putExtras(b); 1.54 + Log.i(LOGTAG, intent.toString()); 1.55 + startActivity(intent); 1.56 + } catch (Exception e) { 1.57 + Log.i(LOGTAG, e.toString()); 1.58 + } 1.59 + } 1.60 +}