Skip to content

Commit

Permalink
fix: 修正Auto.js使用说明;打印shell日志;
Browse files Browse the repository at this point in the history
  • Loading branch information
plus1998 committed Feb 21, 2023
1 parent 0f51204 commit 10dd6ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ curl --location --request POST 'http://localhost:8999' \

```shell
# Auto.js
http.postJson('http://localhost:8999', 'input tap 500 500')
http.post('http://localhost:8999', 'input tap 540 277', { contentType: 'text/plain' })
```
40 changes: 27 additions & 13 deletions app/src/main/java/com/happyplus/adbshell/ADB.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,40 @@ public ADB(File dataDir) {

public String ExecCommand(String command) {
try {
AdbStream stream = connection.open("shell:" + command);
while (!stream.isClosed()) try {
String res = new String(stream.read(), "US-ASCII");
Log.e("HAPPYPLUS", res);
} catch (UnsupportedEncodingException e) {
final AdbStream adbStream;
try {
adbStream = connection.open("shell:");
} catch (InterruptedException | IOException e) {
e.printStackTrace();
return e.getMessage();
} catch (InterruptedException e) {
e.printStackTrace();
return e.getMessage();
} catch (IOException e) {
}
// Start the receiving thread
new Thread(new Runnable() {
@Override
public void run() {
while (!adbStream.isClosed())
try {
// Print each thing we read from the shell stream
Log.d("ADB OUTPUT", new String(adbStream.read(), "US-ASCII"));
} catch (InterruptedException | IOException e) {
e.printStackTrace();
return;
}
}
}).start();
try {
adbStream.write(command + '\n');
} catch (IOException | InterruptedException e) {
e.printStackTrace();
Log.e(TAG, "ExecCommand Error " + e.getMessage());
return e.getMessage();
}
} catch (Exception e) {
String res = e.toString();
Log.e("HAPPYPULS", "SHELL FAILED: " + e.toString());
return res;
Log.e("HAPPYPULS", "SHELL FAILED: " + e);
return res;
}
return "成功";
return "ok";
}

public Boolean adbConnect(String host, int port) {
Expand All @@ -88,7 +102,7 @@ public Boolean adbConnect(String host, int port) {
} catch (IOException | InterruptedException e) {
String res = e.toString();
Log.e("HAPPYPLUS", res);
return false;
return false;
}
}

Expand Down

0 comments on commit 10dd6ed

Please sign in to comment.