Skip to content

Commit

Permalink
fix: add touch time out
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Nov 15, 2022
1 parent f7f1bbf commit 4f95fa4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class SonicPluginTouchService(var width: Int = 0, var handler: Handler?) :
private val TAG = "SonicPluginTouchService"
private val SOCKET = "sonictouchservice"
private val DEFAULT_MAX_CONTACTS = 10
val LINK_SOCKET_TIMEOUT = 30 * 1000
val LINK_SOCKET_TIMEOUT = 15 * 1000
private var isConnect = false;

private var serverSocket: LocalServerSocket? = null

Expand Down Expand Up @@ -202,11 +203,19 @@ class SonicPluginTouchService(var width: Int = 0, var handler: Handler?) :
return
}

Thread() {
sleep(LINK_SOCKET_TIMEOUT.toLong())
if (!isConnect) {
exitProcess(0)
}
}.start()

Log.i(TAG, String.format("Listening on %s", SOCKET))
var clientSocket: LocalSocket?
try {
clientSocket = serverSocket!!.accept()
Log.i(TAG, "client connected")
isConnect = true
processLoop(clientSocket)
} catch (e: IOException) {
Log.i(TAG, "error")
Expand Down
25 changes: 25 additions & 0 deletions app/src/test/java/org/cloud/sonic/android/SocketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,29 @@ public void test2() throws IOException, InterruptedException {
socket.close();
Runtime.getRuntime().exec("adb forward --remove tcp:2222");
}

@Test
public void test3() throws IOException, InterruptedException {
Runtime.getRuntime().exec("adb shell am start -n org.cloud.sonic.android/.plugin.audioPlugin.AudioActivity");
Runtime.getRuntime().exec("adb forward tcp:2222 localabstract:sonicaudioservice");
Thread.sleep(1000);
Socket socket = new Socket("localhost",2222);
System.out.println(socket.isConnected());
Thread.sleep(1000);
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String s;
while (true){
try {
if ((s = br.readLine()) == null) break;
}catch (IOException e){
e.printStackTrace();
break;
}
System.out.println(s);
}
socket.close();
Runtime.getRuntime().exec("adb forward --remove tcp:2222");
}
}

0 comments on commit 4f95fa4

Please sign in to comment.