зеркало из https://github.com/mozilla/pjs.git
bug 606178 - Android Fennec can not restart r=mwu a=blocking-fennec
This commit is contained in:
Родитель
0e65c47842
Коммит
c53112bf03
|
@ -266,13 +266,15 @@ public class CrashReporter extends Activity
|
|||
void doRestart()
|
||||
{
|
||||
try {
|
||||
String action = "org.mozilla.gecko.restart@MOZ_APP_NAME@";
|
||||
String amCmd = "/system/bin/am broadcast -a " + action +
|
||||
" -n org.mozilla.@MOZ_APP_NAME@/org.mozilla.@MOZ_APP_NAME@.Restarter";
|
||||
Log.i("GeckoCrashReporter", amCmd);
|
||||
Runtime.getRuntime().exec(amCmd);
|
||||
String action = "android.intent.action.MAIN";
|
||||
Intent intent = new Intent(action);
|
||||
intent.setClassName("org.mozilla.@MOZ_APP_NAME@",
|
||||
"org.mozilla.@MOZ_APP_NAME@.App");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Log.i("GeckoCrashReporter", intent.toString());
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
Log.i("GeckoCrashReporter", e.toString());
|
||||
Log.e("GeckoCrashReporter", "error while trying to restart", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -426,7 +426,7 @@ abstract public class GeckoApp
|
|||
outFile.setLastModified(fileEntry.getTime());
|
||||
}
|
||||
|
||||
public String getEnvString() {
|
||||
public void addEnvToIntent(Intent intent) {
|
||||
Map<String,String> envMap = System.getenv();
|
||||
Set<Map.Entry<String,String>> envSet = envMap.entrySet();
|
||||
Iterator<Map.Entry<String,String>> envIter = envSet.iterator();
|
||||
|
@ -434,39 +434,26 @@ abstract public class GeckoApp
|
|||
int c = 0;
|
||||
while (envIter.hasNext()) {
|
||||
Map.Entry<String,String> entry = envIter.next();
|
||||
// No need to pass env vars that we know the system provides
|
||||
// Unnecessary vars need to be trimmed since amount of data
|
||||
// we can pass this way is limited
|
||||
if (!entry.getKey().equals("BOOTCLASSPATH") &&
|
||||
!entry.getKey().equals("ANDROID_SOCKET_zygote") &&
|
||||
!entry.getKey().equals("TMPDIR") &&
|
||||
!entry.getKey().equals("ANDROID_BOOTLOGO") &&
|
||||
!entry.getKey().equals("EXTERNAL_STORAGE") &&
|
||||
!entry.getKey().equals("ANDROID_ASSETS") &&
|
||||
!entry.getKey().equals("PATH") &&
|
||||
!entry.getKey().equals("TERMINFO") &&
|
||||
!entry.getKey().equals("LD_LIBRARY_PATH") &&
|
||||
!entry.getKey().equals("ANDROID_DATA") &&
|
||||
!entry.getKey().equals("ANDROID_PROPERTY_WORKSPACE") &&
|
||||
!entry.getKey().equals("ANDROID_ROOT")) {
|
||||
envstr.append(" --es env" + c + " " + entry.getKey() + "="
|
||||
intent.putExtra("env" + c, entry.getKey() + "="
|
||||
+ entry.getValue());
|
||||
c++;
|
||||
}
|
||||
}
|
||||
return envstr.toString();
|
||||
}
|
||||
|
||||
public void doRestart() {
|
||||
try {
|
||||
String action = "org.mozilla.gecko.restart" + getAppName();
|
||||
String amCmd = "/system/bin/am broadcast -a " + action + getEnvString() + " -n org.mozilla." + getAppName() + "/org.mozilla." + getAppName() + ".Restarter";
|
||||
Log.i("GeckoAppJava", amCmd);
|
||||
Runtime.getRuntime().exec(amCmd);
|
||||
Intent intent = new Intent(action);
|
||||
intent.setClassName("org.mozilla." + getAppName(),
|
||||
"org.mozilla." + getAppName() + ".Restarter");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
addEnvToIntent(intent);
|
||||
Log.i("GeckoAppJava", intent.toString());
|
||||
sendBroadcast(intent);
|
||||
} catch (Exception e) {
|
||||
Log.i("GeckoAppJava", e.toString());
|
||||
}
|
||||
System.exit(0);
|
||||
finish();
|
||||
}
|
||||
|
||||
public void handleNotification(String action, String alertName, String alertCookie) {
|
||||
|
|
|
@ -332,7 +332,7 @@ class GeckoAppShell
|
|||
GeckoApp.mAppContext.doRestart();
|
||||
} else {
|
||||
Log.i("GeckoAppJava", "we're done, good bye");
|
||||
System.exit(0);
|
||||
GeckoApp.mAppContext.finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: Java; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
|
@ -39,24 +39,25 @@
|
|||
package org.mozilla.@MOZ_APP_NAME@;
|
||||
|
||||
import android.content.*;
|
||||
import android.util.Log;
|
||||
import android.util.*;
|
||||
import android.os.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Restarter extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
public void onReceive(Context aContext, Intent aIntent) {
|
||||
Log.i("Restarter", "trying to restart @MOZ_APP_NAME@");
|
||||
try {
|
||||
boolean stillRunning;
|
||||
do {
|
||||
stillRunning = false;
|
||||
Process p = Runtime.getRuntime().exec("/system/bin/ps");
|
||||
java.lang.Process p = Runtime.getRuntime().exec("/system/bin/ps");
|
||||
BufferedReader psOut = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
String line;
|
||||
Log.i("Restarter", "pid: " + new Integer(android.os.Process.myPid()).toString());
|
||||
while((line = psOut.readLine()) != null) {
|
||||
Log.i("Restarter", "ps: " + line);
|
||||
if (line.contains("org.mozilla.@MOZ_APP_NAME@.App")){
|
||||
if (line.contains("org.mozilla.@MOZ_APP_NAME@")){
|
||||
if (!line.contains(new Integer(android.os.Process.myPid()).toString())){
|
||||
Log.i("Restarter", "app still running, wait a bit");
|
||||
stillRunning = true;
|
||||
|
@ -73,16 +74,15 @@ public class Restarter extends BroadcastReceiver {
|
|||
}
|
||||
try {
|
||||
String action = "android.intent.action.MAIN";
|
||||
String env;
|
||||
StringBuffer envstr = new StringBuffer();
|
||||
for (int c = 0; (env = intent.getStringExtra("env" + c)) != null; c++) {
|
||||
envstr.append(" --es env" + c + " " + env);
|
||||
}
|
||||
String amCmd = "/system/bin/am start -a " + action + envstr.toString() +
|
||||
" -n org.mozilla.@MOZ_APP_NAME@/org.mozilla.@MOZ_APP_NAME@.App";
|
||||
Log.i("Restarter", amCmd);
|
||||
|
||||
Runtime.getRuntime().exec(amCmd);
|
||||
Intent intent = new Intent(action);
|
||||
intent.setClassName("org.mozilla.@MOZ_APP_NAME@",
|
||||
"org.mozilla.@MOZ_APP_NAME@.App");
|
||||
Bundle b = aIntent.getExtras();
|
||||
if (b != null)
|
||||
intent.putExtras(b);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
Log.i("GeckoAppJava", intent.toString());
|
||||
aContext.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
Log.i("Restarter", e.toString());
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче