mirror of
https://github.com/revanced/jadb.git
synced 2024-11-19 10:39:23 +01:00
Made the list method return the files rather than print them on stdout
This commit is contained in:
parent
d456c1d79a
commit
0bc737adab
@ -1,6 +1,8 @@
|
||||
package se.vidstige.jadb;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AndroidDevice {
|
||||
private String serial;
|
||||
@ -64,15 +66,17 @@ public class AndroidDevice {
|
||||
send("shell:" + shellLine.toString());
|
||||
}
|
||||
|
||||
public void list(String remotePath) throws IOException, JadbException {
|
||||
public List<RemoteFile> list(String remotePath) throws IOException, JadbException {
|
||||
selectTransport();
|
||||
SyncTransport sync = transport.startSync();
|
||||
sync.send("LIST", remotePath);
|
||||
|
||||
List<RemoteFile> result = new ArrayList<RemoteFile>();
|
||||
for (RemoteFile dent = sync.readDirectoryEntry(); dent != RemoteFile.DONE; dent = sync.readDirectoryEntry())
|
||||
{
|
||||
System.out.println(dent.getName());
|
||||
result.add(dent);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void push(String localPath, String remotePath) throws IOException, JadbException {
|
||||
|
@ -3,16 +3,35 @@ package se.vidstige.jadb;
|
||||
/**
|
||||
* Created by vidstige on 2014-03-19.
|
||||
*/
|
||||
class RemoteFile {
|
||||
public static final RemoteFile DONE = new RemoteFile("DONE", null);
|
||||
private String name;
|
||||
public class RemoteFile {
|
||||
public static final RemoteFile DONE = new RemoteFile("DONE", null, 0, 0, 0);
|
||||
|
||||
public RemoteFile(String id, String name) {
|
||||
private final String name;
|
||||
private final int mode;
|
||||
private final int size;
|
||||
private final long lastModified;
|
||||
|
||||
public RemoteFile(String id, String name, int mode, int size, long lastModified) {
|
||||
this.name = name;
|
||||
this.mode = mode;
|
||||
this.size = size;
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public long getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
public boolean isDirectory() {
|
||||
return (mode & (1 << 14)) == (1 << 14);
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,6 @@ class SyncTransport {
|
||||
String name = readString(nameLenght);
|
||||
|
||||
if ("DENT".equals(id) == false) return RemoteFile.DONE;
|
||||
return new RemoteFile(id, name);
|
||||
return new RemoteFile(id, name, mode, size, time);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import org.junit.Test;
|
||||
|
||||
import se.vidstige.jadb.AndroidDevice;
|
||||
import se.vidstige.jadb.JadbConnection;
|
||||
import se.vidstige.jadb.RemoteFile;
|
||||
import se.vidstige.jadb.test.fakes.AdbServer;
|
||||
|
||||
public class JadbTestCases {
|
||||
@ -31,6 +32,10 @@ public class JadbTestCases {
|
||||
{
|
||||
JadbConnection jadb = new JadbConnection();
|
||||
AndroidDevice any = jadb.getAnyDevice();
|
||||
any.list("/");
|
||||
List<RemoteFile> files = any.list("/");
|
||||
for (RemoteFile f : files)
|
||||
{
|
||||
System.out.println(f.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user