mirror of
https://github.com/revanced/jadb.git
synced 2025-05-23 18:37:12 +02: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;
|
package se.vidstige.jadb;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class AndroidDevice {
|
public class AndroidDevice {
|
||||||
private String serial;
|
private String serial;
|
||||||
@ -64,15 +66,17 @@ public class AndroidDevice {
|
|||||||
send("shell:" + shellLine.toString());
|
send("shell:" + shellLine.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void list(String remotePath) throws IOException, JadbException {
|
public List<RemoteFile> list(String remotePath) throws IOException, JadbException {
|
||||||
selectTransport();
|
selectTransport();
|
||||||
SyncTransport sync = transport.startSync();
|
SyncTransport sync = transport.startSync();
|
||||||
sync.send("LIST", remotePath);
|
sync.send("LIST", remotePath);
|
||||||
|
|
||||||
|
List<RemoteFile> result = new ArrayList<RemoteFile>();
|
||||||
for (RemoteFile dent = sync.readDirectoryEntry(); dent != RemoteFile.DONE; dent = sync.readDirectoryEntry())
|
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 {
|
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.
|
* Created by vidstige on 2014-03-19.
|
||||||
*/
|
*/
|
||||||
class RemoteFile {
|
public class RemoteFile {
|
||||||
public static final RemoteFile DONE = new RemoteFile("DONE", null);
|
public static final RemoteFile DONE = new RemoteFile("DONE", null, 0, 0, 0);
|
||||||
private String name;
|
|
||||||
|
|
||||||
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.name = name;
|
||||||
|
this.mode = mode;
|
||||||
|
this.size = size;
|
||||||
|
this.lastModified = lastModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
||||||
return name;
|
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);
|
String name = readString(nameLenght);
|
||||||
|
|
||||||
if ("DENT".equals(id) == false) return RemoteFile.DONE;
|
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.AndroidDevice;
|
||||||
import se.vidstige.jadb.JadbConnection;
|
import se.vidstige.jadb.JadbConnection;
|
||||||
|
import se.vidstige.jadb.RemoteFile;
|
||||||
import se.vidstige.jadb.test.fakes.AdbServer;
|
import se.vidstige.jadb.test.fakes.AdbServer;
|
||||||
|
|
||||||
public class JadbTestCases {
|
public class JadbTestCases {
|
||||||
@ -31,6 +32,10 @@ public class JadbTestCases {
|
|||||||
{
|
{
|
||||||
JadbConnection jadb = new JadbConnection();
|
JadbConnection jadb = new JadbConnection();
|
||||||
AndroidDevice any = jadb.getAnyDevice();
|
AndroidDevice any = jadb.getAnyDevice();
|
||||||
any.list("/");
|
List<RemoteFile> files = any.list("/");
|
||||||
|
for (RemoteFile f : files)
|
||||||
|
{
|
||||||
|
System.out.println(f.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user