mirror of
https://github.com/revanced/jadb.git
synced 2025-05-04 00:24:25 +02:00
Refactor: Extracting method.
This commit is contained in:
parent
de0c65d922
commit
15f49dde6a
@ -22,38 +22,42 @@ public class AndroidDevice {
|
|||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectTransport() throws IOException, JadbException {
|
private void ensureTransportIsSelected() throws IOException, JadbException {
|
||||||
if (!selected)
|
if (!selected)
|
||||||
{
|
{
|
||||||
if (serial == null)
|
selectTransport();
|
||||||
{
|
|
||||||
transport.send("host:transport-any");
|
|
||||||
transport.verifyResponse();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
transport.send("host:transport:" + serial);
|
|
||||||
transport.verifyResponse();
|
|
||||||
|
|
||||||
}
|
|
||||||
selected = true;
|
selected = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSerial()
|
private void selectTransport() throws IOException, JadbException {
|
||||||
|
if (serial == null)
|
||||||
|
{
|
||||||
|
transport.send("host:transport-any");
|
||||||
|
transport.verifyResponse();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
transport.send("host:transport:" + serial);
|
||||||
|
transport.verifyResponse();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSerial()
|
||||||
{
|
{
|
||||||
return serial;
|
return serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getState() throws IOException, JadbException {
|
public String getState() throws IOException, JadbException {
|
||||||
selectTransport();
|
ensureTransportIsSelected();
|
||||||
transport.send("get-state");
|
transport.send("get-state");
|
||||||
transport.verifyResponse();
|
transport.verifyResponse();
|
||||||
return transport.readString();
|
return transport.readString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeShell(String command, String ... args) throws IOException, JadbException {
|
public void executeShell(String command, String ... args) throws IOException, JadbException {
|
||||||
selectTransport();
|
ensureTransportIsSelected();
|
||||||
|
|
||||||
StringBuilder shellLine = new StringBuilder(command);
|
StringBuilder shellLine = new StringBuilder(command);
|
||||||
for (String arg : args)
|
for (String arg : args)
|
||||||
@ -67,7 +71,7 @@ public class AndroidDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<RemoteFile> list(String remotePath) throws IOException, JadbException {
|
public List<RemoteFile> list(String remotePath) throws IOException, JadbException {
|
||||||
selectTransport();
|
ensureTransportIsSelected();
|
||||||
SyncTransport sync = transport.startSync();
|
SyncTransport sync = transport.startSync();
|
||||||
sync.send("LIST", remotePath);
|
sync.send("LIST", remotePath);
|
||||||
|
|
||||||
@ -85,7 +89,7 @@ public class AndroidDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void push(String localPath, String remotePath) throws IOException, JadbException {
|
public void push(String localPath, String remotePath) throws IOException, JadbException {
|
||||||
selectTransport();
|
ensureTransportIsSelected();
|
||||||
SyncTransport sync = transport.startSync();
|
SyncTransport sync = transport.startSync();
|
||||||
File local = new File(localPath);
|
File local = new File(localPath);
|
||||||
sync.send("SEND", remotePath + "," + Integer.toString(getMode(local)));
|
sync.send("SEND", remotePath + "," + Integer.toString(getMode(local)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user