No debugging and extra env & params processing on sealed packages

A "sealed" package is a *release build and signed* Qt for Android package
with no debugging capabilities.
By default sealed packages have no debugging capabilities, but the user
can force debugging capabilities also on a sealed package. This is useful
in corner cases when the user really needs to debug a sealed package.

Change-Id: I840526092556067f2659facf1525861bbabe0edd
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
BogDan Vatra 2017-11-15 19:19:12 +02:00 committed by Jani Heikkinen
parent 4870282117
commit 4d8ae444c2

View File

@ -720,184 +720,189 @@ public class QtActivityDelegate
Bundle extras = m_activity.getIntent().getExtras(); Bundle extras = m_activity.getIntent().getExtras();
if (extras != null) { if (extras != null) {
if ( /*(ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0 try {
&&*/ extras.containsKey("debug_ping") final String dc = "--Added-by-androiddeployqt--/debugger.command";
&& extras.getString("debug_ping").equals("true")) { String debuggerCommand =
try { new BufferedReader(new InputStreamReader(m_activity.getAssets().open(dc))).readLine();
final String dc = "--Added-by-androiddeployqt--/debugger.command"; if ( /*(ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0
String debuggerCommand = &&*/ extras.containsKey("debug_ping")
new BufferedReader(new InputStreamReader(m_activity.getAssets().open(dc))).readLine(); && extras.getString("debug_ping").equals("true")) {
String packagePath = try {
m_activity.getPackageManager().getApplicationInfo(m_activity.getPackageName(), String packagePath =
PackageManager.GET_CONFIGURATIONS).dataDir + "/"; m_activity.getPackageManager().getApplicationInfo(m_activity.getPackageName(),
PackageManager.GET_CONFIGURATIONS).dataDir + "/";
debugLog("extra parameters: " + extras); debugLog("extra parameters: " + extras);
String packageName = m_activity.getPackageName(); String packageName = m_activity.getPackageName();
String pingFile = extras.getString("ping_file"); String pingFile = extras.getString("ping_file");
String pongFile = extras.getString("pong_file"); String pongFile = extras.getString("pong_file");
String gdbserverSocket = extras.getString("gdbserver_socket"); String gdbserverSocket = extras.getString("gdbserver_socket");
String gdbserverCommand = packagePath + debuggerCommand + gdbserverSocket; String gdbserverCommand = packagePath + debuggerCommand + gdbserverSocket;
String pingSocket = extras.getString("ping_socket"); String pingSocket = extras.getString("ping_socket");
boolean usePing = pingFile != null; boolean usePing = pingFile != null;
boolean usePong = pongFile != null; boolean usePong = pongFile != null;
boolean useSocket = gdbserverSocket != null; boolean useSocket = gdbserverSocket != null;
boolean usePingSocket = pingSocket != null; boolean usePingSocket = pingSocket != null;
int napTime = 200; // milliseconds between file accesses int napTime = 200; // milliseconds between file accesses
int timeOut = 30000; // ms until we give up on ping and pong int timeOut = 30000; // ms until we give up on ping and pong
int maxAttempts = timeOut / napTime; int maxAttempts = timeOut / napTime;
if (gdbserverSocket != null) { if (gdbserverSocket != null) {
debugLog("removing gdb socket " + gdbserverSocket); debugLog("removing gdb socket " + gdbserverSocket);
new File(gdbserverSocket).delete(); new File(gdbserverSocket).delete();
}
if (usePing) {
debugLog("removing ping file " + pingFile);
File ping = new File(pingFile);
if (ping.exists()) {
if (!ping.delete())
debugLog("ping file cannot be deleted");
} }
}
if (usePong) { if (usePing) {
debugLog("removing pong file " + pongFile); debugLog("removing ping file " + pingFile);
File pong = new File(pongFile); File ping = new File(pingFile);
if (pong.exists()) { if (ping.exists()) {
if (!pong.delete()) if (!ping.delete())
debugLog("pong file cannot be deleted"); debugLog("ping file cannot be deleted");
}
}
debugLog("starting " + gdbserverCommand);
m_debuggerProcess = Runtime.getRuntime().exec(gdbserverCommand);
debugLog("gdbserver started");
if (useSocket) {
int i;
for (i = 0; i < maxAttempts; ++i) {
debugLog("waiting for socket at " + gdbserverSocket + ", attempt " + i);
File file = new File(gdbserverSocket);
if (file.exists()) {
file.setReadable(true, false);
file.setWritable(true, false);
file.setExecutable(true, false);
break;
} }
Thread.sleep(napTime);
} }
if (i == maxAttempts) { if (usePong) {
debugLog("time out when waiting for debug socket"); debugLog("removing pong file " + pongFile);
return false; File pong = new File(pongFile);
if (pong.exists()) {
if (!pong.delete())
debugLog("pong file cannot be deleted");
}
} }
debugLog("socket ok"); debugLog("starting " + gdbserverCommand);
} else { m_debuggerProcess = Runtime.getRuntime().exec(gdbserverCommand);
debugLog("socket not used"); debugLog("gdbserver started");
}
if (usePingSocket) { if (useSocket) {
DebugWaitRunnable runnable = new DebugWaitRunnable(pingSocket); int i;
Thread waitThread = new Thread(runnable); for (i = 0; i < maxAttempts; ++i) {
waitThread.start(); debugLog("waiting for socket at " + gdbserverSocket + ", attempt " + i);
File file = new File(gdbserverSocket);
if (file.exists()) {
file.setReadable(true, false);
file.setWritable(true, false);
file.setExecutable(true, false);
break;
}
Thread.sleep(napTime);
}
int i; if (i == maxAttempts) {
for (i = 0; i < maxAttempts && waitThread.isAlive(); ++i) { debugLog("time out when waiting for debug socket");
debugLog("Waiting for debug socket connect"); return false;
debugLog("go to sleep"); }
Thread.sleep(napTime);
}
if (i == maxAttempts) { debugLog("socket ok");
debugLog("time out when waiting for ping socket");
runnable.shutdown();
return false;
}
if (runnable.wasFailure) {
debugLog("Could not connect to debug client");
return false;
} else { } else {
debugLog("Got pid acknowledgment"); debugLog("socket not used");
} }
}
if (usePing) { if (usePingSocket) {
// Tell we are ready. DebugWaitRunnable runnable = new DebugWaitRunnable(pingSocket);
debugLog("writing ping at " + pingFile); Thread waitThread = new Thread(runnable);
FileWriter writer = new FileWriter(pingFile); waitThread.start();
writer.write("" + android.os.Process.myPid());
writer.close();
File file = new File(pingFile);
file.setReadable(true, false);
file.setWritable(true, false);
file.setExecutable(true, false);
debugLog("wrote ping");
} else {
debugLog("ping not requested");
}
// Wait until other side is ready. int i;
if (usePong) { for (i = 0; i < maxAttempts && waitThread.isAlive(); ++i) {
int i; debugLog("Waiting for debug socket connect");
for (i = 0; i < maxAttempts; ++i) { debugLog("go to sleep");
debugLog("waiting for pong at " + pongFile + ", attempt " + i); Thread.sleep(napTime);
File file = new File(pongFile);
if (file.exists()) {
file.delete();
break;
} }
debugLog("go to sleep");
Thread.sleep(napTime);
}
debugLog("Removing pingFile " + pingFile);
new File(pingFile).delete();
if (i == maxAttempts) { if (i == maxAttempts) {
debugLog("time out when waiting for pong file"); debugLog("time out when waiting for ping socket");
return false; runnable.shutdown();
return false;
}
if (runnable.wasFailure) {
debugLog("Could not connect to debug client");
return false;
} else {
debugLog("Got pid acknowledgment");
}
} }
debugLog("got pong " + pongFile); if (usePing) {
} else { // Tell we are ready.
debugLog("pong not requested"); debugLog("writing ping at " + pingFile);
FileWriter writer = new FileWriter(pingFile);
writer.write("" + android.os.Process.myPid());
writer.close();
File file = new File(pingFile);
file.setReadable(true, false);
file.setWritable(true, false);
file.setExecutable(true, false);
debugLog("wrote ping");
} else {
debugLog("ping not requested");
}
// Wait until other side is ready.
if (usePong) {
int i;
for (i = 0; i < maxAttempts; ++i) {
debugLog("waiting for pong at " + pongFile + ", attempt " + i);
File file = new File(pongFile);
if (file.exists()) {
file.delete();
break;
}
debugLog("go to sleep");
Thread.sleep(napTime);
}
debugLog("Removing pingFile " + pingFile);
new File(pingFile).delete();
if (i == maxAttempts) {
debugLog("time out when waiting for pong file");
return false;
}
debugLog("got pong " + pongFile);
} else {
debugLog("pong not requested");
}
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (SecurityException se) {
se.printStackTrace();
} }
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (SecurityException se) {
se.printStackTrace();
} }
}
if (/*(ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0 if (/*(ai.flags&ApplicationInfo.FLAG_DEBUGGABLE) != 0
&&*/ extras.containsKey("qml_debug") &&*/ extras.containsKey("qml_debug")
&& extras.getString("qml_debug").equals("true")) { && extras.getString("qml_debug").equals("true")) {
String qmljsdebugger; String qmljsdebugger;
if (extras.containsKey("qmljsdebugger")) { if (extras.containsKey("qmljsdebugger")) {
qmljsdebugger = extras.getString("qmljsdebugger"); qmljsdebugger = extras.getString("qmljsdebugger");
qmljsdebugger.replaceAll("\\s", ""); // remove whitespace for security qmljsdebugger.replaceAll("\\s", ""); // remove whitespace for security
} else { } else {
qmljsdebugger = "port:3768"; qmljsdebugger = "port:3768";
}
m_applicationParameters += "\t-qmljsdebugger=" + qmljsdebugger;
} }
m_applicationParameters += "\t-qmljsdebugger=" + qmljsdebugger;
}
if (extras.containsKey("extraenvvars")) { if (extras.containsKey("extraenvvars")) {
try { try {
m_environmentVariables += "\t" + new String(Base64.decode(extras.getString("extraenvvars"), Base64.DEFAULT), "UTF-8"); m_environmentVariables += "\t" + new String(Base64.decode(extras.getString("extraenvvars"), Base64.DEFAULT), "UTF-8");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}
} }
}
if (extras.containsKey("extraappparams")) { if (extras.containsKey("extraappparams")) {
try { try {
m_applicationParameters += "\t" + new String(Base64.decode(extras.getString("extraappparams"), Base64.DEFAULT), "UTF-8"); m_applicationParameters += "\t" + new String(Base64.decode(extras.getString("extraappparams"), Base64.DEFAULT), "UTF-8");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}
} }
} catch (Exception e) {
// This is not an error, so keep it silent
// e.printStackTrace();
} }
} // extras != null } // extras != null