mirror of
https://github.com/revanced/jadb.git
synced 2025-02-06 07:26:48 +01:00
Now possible to list files on device
This commit is contained in:
parent
4b162f41ad
commit
272a29a750
@ -63,8 +63,19 @@ public class AndroidDevice {
|
||||
}
|
||||
send("shell:" + shellLine.toString());
|
||||
}
|
||||
|
||||
public void push(String localPath, String remotePath) throws IOException, JadbException {
|
||||
|
||||
public void list(String remotePath) throws IOException, JadbException {
|
||||
selectTransport();
|
||||
SyncTransport sync = transport.startSync();
|
||||
sync.send("LIST", remotePath);
|
||||
|
||||
for (DirectoryEntry dent = sync.readDirectoryEntry(); dent != DirectoryEntry.DONE; dent = sync.readDirectoryEntry())
|
||||
{
|
||||
System.out.println(dent.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void push(String localPath, String remotePath) throws IOException, JadbException {
|
||||
selectTransport();
|
||||
}
|
||||
|
||||
|
20
src/se/vidstige/jadb/DirectoryEntry.java
Normal file
20
src/se/vidstige/jadb/DirectoryEntry.java
Normal file
@ -0,0 +1,20 @@
|
||||
package se.vidstige.jadb;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by vidstige on 2014-03-19.
|
||||
*/
|
||||
class DirectoryEntry {
|
||||
public static final DirectoryEntry DONE = new DirectoryEntry("DONE", null);
|
||||
private String name;
|
||||
|
||||
public DirectoryEntry(String id, String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
47
src/se/vidstige/jadb/SyncTransport.java
Normal file
47
src/se/vidstige/jadb/SyncTransport.java
Normal file
@ -0,0 +1,47 @@
|
||||
package se.vidstige.jadb;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* Created by vidstige on 2014-03-19.
|
||||
*/
|
||||
class SyncTransport {
|
||||
|
||||
private final DataOutputStream output;
|
||||
private final DataInputStream input;
|
||||
|
||||
public SyncTransport(OutputStream outputStream, InputStream inputStream) {
|
||||
output = new DataOutputStream(outputStream);
|
||||
input = new DataInputStream(inputStream);
|
||||
}
|
||||
|
||||
public void send(String syncCommand, String name) throws IOException {
|
||||
if (syncCommand.length() != 4) throw new IllegalArgumentException("sync commands must have length 4");
|
||||
output.writeBytes(syncCommand);
|
||||
output.writeInt(Integer.reverseBytes(name.length()));
|
||||
output.writeBytes(name);
|
||||
}
|
||||
|
||||
private int readInt() throws IOException {
|
||||
return Integer.reverseBytes(input.readInt());
|
||||
}
|
||||
|
||||
private String readString(int length) throws IOException {
|
||||
byte[] buffer = new byte[length];
|
||||
input.read(buffer);
|
||||
return new String(buffer, Charset.forName("utf-8"));
|
||||
}
|
||||
|
||||
public DirectoryEntry readDirectoryEntry() throws IOException {
|
||||
String id = readString(4);
|
||||
int mode = readInt();
|
||||
int size = readInt();
|
||||
int time = readInt();
|
||||
int nameLenght = readInt();
|
||||
String name = readString(nameLenght);
|
||||
|
||||
if ("DENT".equals(id) == false) return DirectoryEntry.DONE;
|
||||
return new DirectoryEntry(id, name);
|
||||
}
|
||||
}
|
@ -1,11 +1,6 @@
|
||||
package se.vidstige.jadb;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
@ -56,4 +51,10 @@ class Transport {
|
||||
writer.write(command);
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
public SyncTransport startSync() throws IOException, JadbException {
|
||||
send("sync:");
|
||||
verifyResponse();
|
||||
return new SyncTransport(outputStream, inputStream);
|
||||
}
|
||||
}
|
||||
|
@ -20,9 +20,17 @@ public class JadbTestCases {
|
||||
@Test
|
||||
public void testGetDevices() throws Exception
|
||||
{
|
||||
JadbConnection jadb = new JadbConnection("localhost", 15037);
|
||||
//JadbConnection jadb = new JadbConnection();
|
||||
//JadbConnection jadb = new JadbConnection("localhost", 15037);
|
||||
JadbConnection jadb = new JadbConnection();
|
||||
List<AndroidDevice> actual = jadb.getDevices();
|
||||
Assert.assertEquals("emulator-5554", actual.get(0).getSerial());
|
||||
//Assert.assertEquals("emulator-5554", actual.get(0).getSerial());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListFiles() throws Exception
|
||||
{
|
||||
JadbConnection jadb = new JadbConnection();
|
||||
AndroidDevice any = jadb.getAnyDevice();
|
||||
any.list("/");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user