summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan@kde.org>2014-11-19 18:43:18 +0200
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>2014-11-20 16:14:32 +0100
commit52f5bf9cd5dd5586dc18b2d7efd833232c2f508a (patch)
tree0b90f2d7a2180bc63c6eb2ae712a9d8bfb6f554d /src/android
parent34985d676a6683d6c342b68f8bfb4442b7ce27b1 (diff)
Android: Use LocalServerSocket instead of ServerSocket
Using LocalServerSocket is way much safer than ServerSocket because is not using ports which might be in use by other applications. Change-Id: I0e2be0b4561362939950861024f1f95ab819f2c2 Reviewed-by: BogDan Vatra <bogdan@kde.org> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com> Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/android')
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java53
1 files changed, 32 insertions, 21 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 12b606b89f..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;
@@ -79,9 +81,6 @@ import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.reflect.Method;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.SocketException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -496,12 +495,12 @@ public class QtActivityDelegate
private class DebugWaitRunnable implements Runnable {
- public DebugWaitRunnable(int socketPort) throws IOException {
- socket = new ServerSocket(socketPort);
+ public DebugWaitRunnable(String pingPongSocket) throws IOException {
+ socket = new LocalServerSocket(pingPongSocket);
}
public boolean wasFailure;
- private ServerSocket socket;
+ private LocalServerSocket socket;
public void run() {
final int napTime = 200; // milliseconds between file accesses
@@ -509,9 +508,7 @@ public class QtActivityDelegate
final int maxAttempts = timeOut / napTime;
try {
- socket.setSoTimeout(timeOut);
- debugLog("Waiting for debug socket on port: " + socket.getLocalPort());
- Socket connectionFromClient = socket.accept();
+ LocalSocket connectionFromClient = socket.accept();
debugLog("Debug socket accepted");
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader(connectionFromClient.getInputStream()));
@@ -524,7 +521,7 @@ public class QtActivityDelegate
if (!clientData.isEmpty())
break;
- if (socket.isClosed()) {
+ if (connectionFromClient.isClosed()) {
wasFailure = true;
break;
}
@@ -539,6 +536,14 @@ public class QtActivityDelegate
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()
@@ -597,17 +602,11 @@ public class QtActivityDelegate
String pongFile = extras.getString("pong_file");
String gdbserverSocket = extras.getString("gdbserver_socket");
String gdbserverCommand = extras.getString("gdbserver_command");
- String pingViaSocket = extras.getString("ping_socketport");
+ String pingSocket = extras.getString("ping_socket");
boolean usePing = pingFile != null;
boolean usePong = pongFile != null;
boolean useSocket = gdbserverSocket != null;
- int pingSocket = 0;
- if (pingViaSocket != null) {
- try {
- pingSocket = Integer.parseInt(pingViaSocket);
- } catch (NumberFormatException ignored) { }
- }
- boolean usePingViaSocket = (pingViaSocket != null && pingSocket > 0);
+ 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;
@@ -654,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;
}
@@ -663,11 +662,23 @@ public class QtActivityDelegate
debugLog("socket not used");
}
- if (usePingViaSocket) {
+ if (usePingSocket) {
DebugWaitRunnable runnable = new DebugWaitRunnable(pingSocket);
Thread waitThread = new Thread(runnable);
waitThread.start();
- waitThread.join();
+
+ 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");