mirror of
https://github.com/revanced/jadb.git
synced 2025-02-11 17:46:47 +01:00
Fixing a bug where jadb would hang if no devices where found.
This commit is contained in:
parent
59cc2e9d1e
commit
fa74fd88bd
@ -52,7 +52,9 @@ public class JadbConnection {
|
|||||||
for (String line : lines)
|
for (String line : lines)
|
||||||
{
|
{
|
||||||
String[] parts = line.split("\t");
|
String[] parts = line.split("\t");
|
||||||
|
if (parts.length > 1) {
|
||||||
devices.add(new JadbDevice(parts[0], parts[1], main));
|
devices.add(new JadbDevice(parts[0], parts[1], main));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package se.vidstige.jadb.server;
|
package se.vidstige.jadb.server;
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.*;
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
@ -47,11 +44,14 @@ public class AdbProtocolHandler implements Runnable {
|
|||||||
output.write("OKAY");
|
output.write("OKAY");
|
||||||
}
|
}
|
||||||
else if ("host:devices".equals(command)) {
|
else if ("host:devices".equals(command)) {
|
||||||
output.write("OKAY");
|
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream writer = new DataOutputStream(tmp);
|
||||||
for (AdbDeviceResponder d : responder.getDevices())
|
for (AdbDeviceResponder d : responder.getDevices())
|
||||||
{
|
{
|
||||||
send(output, d.getSerial() + "\t" + d.getType() + "\n");
|
writer.writeBytes(d.getSerial() + "\t" + d.getType() + "\n");
|
||||||
}
|
}
|
||||||
|
output.write("OKAY");
|
||||||
|
send(output, new String(tmp.toByteArray(), Charset.forName("utf-8")));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -61,7 +61,7 @@ public class AdbProtocolHandler implements Runnable {
|
|||||||
output.flush();
|
output.flush();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println("IO Error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,6 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import se.vidstige.jadb.JadbConnection;
|
import se.vidstige.jadb.JadbConnection;
|
||||||
import se.vidstige.jadb.JadbDevice;
|
import se.vidstige.jadb.JadbDevice;
|
||||||
import se.vidstige.jadb.server.AdbServer;
|
|
||||||
import se.vidstige.jadb.server.SocketServer;
|
|
||||||
import se.vidstige.jadb.test.fakes.FakeAdbServer;
|
import se.vidstige.jadb.test.fakes.FakeAdbServer;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -36,4 +34,11 @@ public class MockedTestCases {
|
|||||||
List<JadbDevice> devices = connection.getDevices();
|
List<JadbDevice> devices = connection.getDevices();
|
||||||
Assert.assertEquals("serial-123", devices.get(0).getSerial());
|
Assert.assertEquals("serial-123", devices.get(0).getSerial());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListNoDevices() throws Exception {
|
||||||
|
List<JadbDevice> devices = connection.getDevices();
|
||||||
|
Assert.assertEquals(0, devices.size());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user