Create adb.js

This commit is contained in:
Namhyeon Go 2022-03-02 03:15:24 +09:00 committed by GitHub
parent 41aac72513
commit 36efb8bc07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

50
lib/adb.js Normal file
View File

@ -0,0 +1,50 @@
////////////////////////////////////////////////////////////////////////
// LDPlayer API
///////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
var SYS = require("lib/system");
function ADBObject() {
this.binPath = "bin\\platform-tools_r33.0.0-windows\platform-tools\\adb.exe";
this.setBinPath = function(binPath) {
this.binPath = binPath;
};
this.getDevices = function() {
var devices = [];
var result = SHELL.exec([this.binPath, "devices"]);
splitLn(result).forEach(function(line) {
var row = line.split(/\s+/);
if(row.length == 2) {
devices.push({
id: row[0],
hostname: this.getHostname(row[0]),
type: row[1]
});
}
});
};
this.getHostname = function(id) {
return SHELL.exec([this.binPath, "-s", id, "shell", "getprop", "net.hostname"]).trim();
};
this.disableService = function(id, name) {
return SHELL.exec([this.binPath, "-s", id, "shell", "svc", name, "disable"]);
};
this.enableService = function(id, name) {
return SHELL.exec([this.binPath, "-s", id, "shell", "svc", name, "enable"]);
};
}
exports.VERSIONINFO = "Android Debug Bridge Interface (adb.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.create = function() {
return new ADBObject();
};