mirror of
https://github.com/revanced/jadb.git
synced 2025-02-10 17:26:46 +01:00
Adding the ability to enable tcpip from the library as per https://github.com/aosp-mirror/platform_system_core/blob/master/adb/daemon/services.cpp
This commit is contained in:
parent
7b99c48cb7
commit
6466ee461e
@ -1,11 +1,13 @@
|
||||
package se.vidstige.jadb;
|
||||
|
||||
import se.vidstige.jadb.managers.Bash;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static se.vidstige.jadb.Util.inputStreamToString;
|
||||
|
||||
public class JadbDevice {
|
||||
@SuppressWarnings("squid:S00115")
|
||||
public enum State {
|
||||
@ -146,10 +148,7 @@ public class JadbDevice {
|
||||
* @return success or failure
|
||||
*/
|
||||
public boolean enableTcpip() throws IOException, JadbException {
|
||||
Transport transport = getTransport();
|
||||
|
||||
send(transport, String.format("tcpip: %d", DEFAULT_TCPIP_PORT));
|
||||
return transport.readString().trim().equals(String.format("restarting in TCP Mode: %d", DEFAULT_TCPIP_PORT));
|
||||
return enableTcpip(DEFAULT_TCPIP_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,8 +160,10 @@ public class JadbDevice {
|
||||
*/
|
||||
public boolean enableTcpip(int port) throws IOException, JadbException {
|
||||
Transport transport = getTransport();
|
||||
send(transport, String.format("tcpip: %d", port));
|
||||
return transport.readString().trim().equals(String.format("restarting in TCP Mode: %d", port));
|
||||
send(transport, String.format("tcpip:%d", port));
|
||||
String expectedResult = String.format("restarting in TCP Mode: %d", port);
|
||||
|
||||
return inputStreamToString(transport.getInputStream()).equals(expectedResult);
|
||||
}
|
||||
|
||||
public List<RemoteFile> list(String remotePath) throws IOException, JadbException {
|
||||
|
28
src/se/vidstige/jadb/Util.java
Normal file
28
src/se/vidstige/jadb/Util.java
Normal file
@ -0,0 +1,28 @@
|
||||
package se.vidstige.jadb;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class Util {
|
||||
/**
|
||||
* Convert an input stream to string
|
||||
*
|
||||
* @param inputStream input stream
|
||||
*
|
||||
* @return string representation of the input stream
|
||||
*
|
||||
* @throws IOException if an error ocurrs reading the input stream
|
||||
*/
|
||||
public static String inputStreamToString(InputStream inputStream) throws IOException {
|
||||
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = inputStream.read(buffer)) != -1) {
|
||||
result.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
return result.toString(StandardCharsets.UTF_8.name());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user