зеркало из 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()
|
void doRestart()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
String action = "org.mozilla.gecko.restart@MOZ_APP_NAME@";
|
String action = "android.intent.action.MAIN";
|
||||||
String amCmd = "/system/bin/am broadcast -a " + action +
|
Intent intent = new Intent(action);
|
||||||
" -n org.mozilla.@MOZ_APP_NAME@/org.mozilla.@MOZ_APP_NAME@.Restarter";
|
intent.setClassName("org.mozilla.@MOZ_APP_NAME@",
|
||||||
Log.i("GeckoCrashReporter", amCmd);
|
"org.mozilla.@MOZ_APP_NAME@.App");
|
||||||
Runtime.getRuntime().exec(amCmd);
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
Log.i("GeckoCrashReporter", intent.toString());
|
||||||
|
startActivity(intent);
|
||||||
} catch (Exception e) {
|
} 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());
|
outFile.setLastModified(fileEntry.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEnvString() {
|
public void addEnvToIntent(Intent intent) {
|
||||||
Map<String,String> envMap = System.getenv();
|
Map<String,String> envMap = System.getenv();
|
||||||
Set<Map.Entry<String,String>> envSet = envMap.entrySet();
|
Set<Map.Entry<String,String>> envSet = envMap.entrySet();
|
||||||
Iterator<Map.Entry<String,String>> envIter = envSet.iterator();
|
Iterator<Map.Entry<String,String>> envIter = envSet.iterator();
|
||||||
|
@ -434,39 +434,26 @@ abstract public class GeckoApp
|
||||||
int c = 0;
|
int c = 0;
|
||||||
while (envIter.hasNext()) {
|
while (envIter.hasNext()) {
|
||||||
Map.Entry<String,String> entry = envIter.next();
|
Map.Entry<String,String> entry = envIter.next();
|
||||||
// No need to pass env vars that we know the system provides
|
intent.putExtra("env" + c, entry.getKey() + "="
|
||||||
// Unnecessary vars need to be trimmed since amount of data
|
+ entry.getValue());
|
||||||
// we can pass this way is limited
|
c++;
|
||||||
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() + "="
|
|
||||||
+ entry.getValue());
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return envstr.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doRestart() {
|
public void doRestart() {
|
||||||
try {
|
try {
|
||||||
String action = "org.mozilla.gecko.restart" + getAppName();
|
String action = "org.mozilla.gecko.restart" + getAppName();
|
||||||
String amCmd = "/system/bin/am broadcast -a " + action + getEnvString() + " -n org.mozilla." + getAppName() + "/org.mozilla." + getAppName() + ".Restarter";
|
Intent intent = new Intent(action);
|
||||||
Log.i("GeckoAppJava", amCmd);
|
intent.setClassName("org.mozilla." + getAppName(),
|
||||||
Runtime.getRuntime().exec(amCmd);
|
"org.mozilla." + getAppName() + ".Restarter");
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
addEnvToIntent(intent);
|
||||||
|
Log.i("GeckoAppJava", intent.toString());
|
||||||
|
sendBroadcast(intent);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.i("GeckoAppJava", e.toString());
|
Log.i("GeckoAppJava", e.toString());
|
||||||
}
|
}
|
||||||
System.exit(0);
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleNotification(String action, String alertName, String alertCookie) {
|
public void handleNotification(String action, String alertName, String alertCookie) {
|
||||||
|
|
|
@ -332,7 +332,7 @@ class GeckoAppShell
|
||||||
GeckoApp.mAppContext.doRestart();
|
GeckoApp.mAppContext.doRestart();
|
||||||
} else {
|
} else {
|
||||||
Log.i("GeckoAppJava", "we're done, good bye");
|
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 *****
|
* ***** BEGIN LICENSE BLOCK *****
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
*
|
*
|
||||||
|
@ -39,24 +39,25 @@
|
||||||
package org.mozilla.@MOZ_APP_NAME@;
|
package org.mozilla.@MOZ_APP_NAME@;
|
||||||
|
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.util.Log;
|
import android.util.*;
|
||||||
|
import android.os.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public class Restarter extends BroadcastReceiver {
|
public class Restarter extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context aContext, Intent aIntent) {
|
||||||
Log.i("Restarter", "trying to restart @MOZ_APP_NAME@");
|
Log.i("Restarter", "trying to restart @MOZ_APP_NAME@");
|
||||||
try {
|
try {
|
||||||
boolean stillRunning;
|
boolean stillRunning;
|
||||||
do {
|
do {
|
||||||
stillRunning = false;
|
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()));
|
BufferedReader psOut = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||||
String line;
|
String line;
|
||||||
Log.i("Restarter", "pid: " + new Integer(android.os.Process.myPid()).toString());
|
Log.i("Restarter", "pid: " + new Integer(android.os.Process.myPid()).toString());
|
||||||
while((line = psOut.readLine()) != null) {
|
while((line = psOut.readLine()) != null) {
|
||||||
Log.i("Restarter", "ps: " + line);
|
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())){
|
if (!line.contains(new Integer(android.os.Process.myPid()).toString())){
|
||||||
Log.i("Restarter", "app still running, wait a bit");
|
Log.i("Restarter", "app still running, wait a bit");
|
||||||
stillRunning = true;
|
stillRunning = true;
|
||||||
|
@ -69,23 +70,22 @@ public class Restarter extends BroadcastReceiver {
|
||||||
}
|
}
|
||||||
} while(stillRunning);
|
} while(stillRunning);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.i("Restarter", e.toString());
|
Log.i("Restarter", e.toString());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String action = "android.intent.action.MAIN";
|
String action = "android.intent.action.MAIN";
|
||||||
String env;
|
Intent intent = new Intent(action);
|
||||||
StringBuffer envstr = new StringBuffer();
|
intent.setClassName("org.mozilla.@MOZ_APP_NAME@",
|
||||||
for (int c = 0; (env = intent.getStringExtra("env" + c)) != null; c++) {
|
"org.mozilla.@MOZ_APP_NAME@.App");
|
||||||
envstr.append(" --es env" + c + " " + env);
|
Bundle b = aIntent.getExtras();
|
||||||
}
|
if (b != null)
|
||||||
String amCmd = "/system/bin/am start -a " + action + envstr.toString() +
|
intent.putExtras(b);
|
||||||
" -n org.mozilla.@MOZ_APP_NAME@/org.mozilla.@MOZ_APP_NAME@.App";
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
Log.i("Restarter", amCmd);
|
Log.i("GeckoAppJava", intent.toString());
|
||||||
|
aContext.startActivity(intent);
|
||||||
Runtime.getRuntime().exec(amCmd);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.i("Restarter", e.toString());
|
Log.i("Restarter", e.toString());
|
||||||
}
|
}
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Загрузка…
Ссылка в новой задаче