summaryrefslogtreecommitdiffstats
path: root/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java')
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java88
1 files changed, 87 insertions, 1 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
index cab5da9dbc..f44465b4c5 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
@@ -50,6 +50,8 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.drawable.ColorDrawable;
+import android.net.LocalServerSocket;
+import android.net.LocalSocket;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -72,8 +74,11 @@ import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
import java.io.File;
import java.io.FileWriter;
+import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -488,6 +493,59 @@ public class QtActivityDelegate
Log.i(QtNative.QtTAG, "DEBUGGER: " + msg);
}
+ private class DebugWaitRunnable implements Runnable {
+
+ public DebugWaitRunnable(String pingPongSocket) throws IOException {
+ socket = new LocalServerSocket(pingPongSocket);
+ }
+
+ public boolean wasFailure;
+ private LocalServerSocket socket;
+
+ public void run() {
+ final int napTime = 200; // milliseconds between file accesses
+ final int timeOut = 30000; // ms until we give up on ping and pong
+ final int maxAttempts = timeOut / napTime;
+
+ try {
+ LocalSocket connectionFromClient = socket.accept();
+ debugLog("Debug socket accepted");
+ BufferedReader inFromClient =
+ new BufferedReader(new InputStreamReader(connectionFromClient.getInputStream()));
+ DataOutputStream outToClient = new DataOutputStream(connectionFromClient.getOutputStream());
+ outToClient.writeBytes("" + android.os.Process.myPid());
+
+ for (int i = 0; i < maxAttempts; i++) {
+ String clientData = inFromClient.readLine();
+ debugLog("Incoming socket " + clientData);
+ if (!clientData.isEmpty())
+ break;
+
+ if (connectionFromClient.isClosed()) {
+ wasFailure = true;
+ break;
+ }
+ Thread.sleep(napTime);
+ }
+ } catch (IOException ioEx) {
+ ioEx.printStackTrace();
+ wasFailure = true;
+ Log.e(QtNative.QtTAG,"Can't start debugger" + ioEx.getMessage());
+ } catch (InterruptedException interruptEx) {
+ wasFailure = true;
+ Log.e(QtNative.QtTAG,"Can't start debugger" + interruptEx.getMessage());
+ }
+ }
+
+ public void shutdown() throws IOException
+ {
+ wasFailure = true;
+ try {
+ socket.close();
+ } catch (IOException ignored) { }
+ }
+ };
+
public boolean startApplication()
{
// start application
@@ -544,9 +602,11 @@ public class QtActivityDelegate
String pongFile = extras.getString("pong_file");
String gdbserverSocket = extras.getString("gdbserver_socket");
String gdbserverCommand = extras.getString("gdbserver_command");
+ String pingSocket = extras.getString("ping_socket");
boolean usePing = pingFile != null;
boolean usePong = pongFile != null;
boolean useSocket = gdbserverSocket != null;
+ boolean usePingSocket = pingSocket != null;
int napTime = 200; // milliseconds between file accesses
int timeOut = 30000; // ms until we give up on ping and pong
int maxAttempts = timeOut / napTime;
@@ -593,7 +653,7 @@ public class QtActivityDelegate
}
if (i == maxAttempts) {
- debugLog("time out when waiting for socket");
+ debugLog("time out when waiting for debug socket");
return false;
}
@@ -602,6 +662,32 @@ public class QtActivityDelegate
debugLog("socket not used");
}
+ if (usePingSocket) {
+ DebugWaitRunnable runnable = new DebugWaitRunnable(pingSocket);
+ Thread waitThread = new Thread(runnable);
+ waitThread.start();
+
+ int i;
+ for (i = 0; i < maxAttempts && waitThread.isAlive(); ++i) {
+ debugLog("Waiting for debug socket connect");
+ debugLog("go to sleep");
+ Thread.sleep(napTime);
+ }
+
+ if (i == maxAttempts) {
+ 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 {
+ debugLog("Got pid acknowledgment");
+ }
+ }
+
if (usePing) {
// Tell we are ready.
debugLog("writing ping at " + pingFile);