Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | package org.mozilla.gecko; |
michael@0 | 7 | |
michael@0 | 8 | import android.app.Activity; |
michael@0 | 9 | import android.content.Intent; |
michael@0 | 10 | import android.os.Bundle; |
michael@0 | 11 | import android.util.Log; |
michael@0 | 12 | |
michael@0 | 13 | public class Restarter extends Activity { |
michael@0 | 14 | private static final String LOGTAG = "GeckoRestarter"; |
michael@0 | 15 | |
michael@0 | 16 | @Override |
michael@0 | 17 | public void onCreate(Bundle savedInstanceState) { |
michael@0 | 18 | super.onCreate(savedInstanceState); |
michael@0 | 19 | |
michael@0 | 20 | Log.i(LOGTAG, "Trying to restart " + AppConstants.MOZ_APP_NAME); |
michael@0 | 21 | try { |
michael@0 | 22 | int countdown = 40; |
michael@0 | 23 | while (GeckoAppShell.checkForGeckoProcs() && --countdown > 0) { |
michael@0 | 24 | // Wait for the old process to die before we continue |
michael@0 | 25 | try { |
michael@0 | 26 | Thread.sleep(100); |
michael@0 | 27 | } catch (InterruptedException ie) {} |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | if (countdown <= 0) { |
michael@0 | 31 | // if the countdown expired, something is hung |
michael@0 | 32 | GeckoAppShell.killAnyZombies(); |
michael@0 | 33 | countdown = 10; |
michael@0 | 34 | // wait for the kill to take effect |
michael@0 | 35 | while (GeckoAppShell.checkForGeckoProcs() && --countdown > 0) { |
michael@0 | 36 | try { |
michael@0 | 37 | Thread.sleep(100); |
michael@0 | 38 | } catch (InterruptedException ie) {} |
michael@0 | 39 | } |
michael@0 | 40 | } |
michael@0 | 41 | } catch (Exception e) { |
michael@0 | 42 | Log.i(LOGTAG, e.toString()); |
michael@0 | 43 | } |
michael@0 | 44 | try { |
michael@0 | 45 | Intent intent = new Intent(Intent.ACTION_MAIN); |
michael@0 | 46 | intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, |
michael@0 | 47 | AppConstants.BROWSER_INTENT_CLASS_NAME); |
michael@0 | 48 | Bundle b = getIntent().getExtras(); |
michael@0 | 49 | if (b != null) |
michael@0 | 50 | intent.putExtras(b); |
michael@0 | 51 | Log.i(LOGTAG, intent.toString()); |
michael@0 | 52 | startActivity(intent); |
michael@0 | 53 | } catch (Exception e) { |
michael@0 | 54 | Log.i(LOGTAG, e.toString()); |
michael@0 | 55 | } |
michael@0 | 56 | } |
michael@0 | 57 | } |