first commit

This commit is contained in:
2026-09-08 20:28:54 +08:00
commit 2ada8d3d5a
37380 changed files with 4886169 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
var Command, ForwardCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
ForwardCommand = (function(superClass) {
extend(ForwardCommand, superClass);
function ForwardCommand() {
return ForwardCommand.__super__.constructor.apply(this, arguments);
}
ForwardCommand.prototype.execute = function(serial, local, remote) {
this._send("host-serial:" + serial + ":forward:" + local + ";" + remote);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readAscii(4).then(function(reply) {
switch (reply) {
case Protocol.OKAY:
return true;
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return ForwardCommand;
})(Command);
module.exports = ForwardCommand;
+38
View File
@@ -0,0 +1,38 @@
var Command, GetDevicePathCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
GetDevicePathCommand = (function(superClass) {
extend(GetDevicePathCommand, superClass);
function GetDevicePathCommand() {
return GetDevicePathCommand.__super__.constructor.apply(this, arguments);
}
GetDevicePathCommand.prototype.execute = function(serial) {
this._send("host-serial:" + serial + ":get-devpath");
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readValue().then(function(value) {
return value.toString();
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return GetDevicePathCommand;
})(Command);
module.exports = GetDevicePathCommand;
+38
View File
@@ -0,0 +1,38 @@
var Command, GetSerialNoCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
GetSerialNoCommand = (function(superClass) {
extend(GetSerialNoCommand, superClass);
function GetSerialNoCommand() {
return GetSerialNoCommand.__super__.constructor.apply(this, arguments);
}
GetSerialNoCommand.prototype.execute = function(serial) {
this._send("host-serial:" + serial + ":get-serialno");
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readValue().then(function(value) {
return value.toString();
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return GetSerialNoCommand;
})(Command);
module.exports = GetSerialNoCommand;
+38
View File
@@ -0,0 +1,38 @@
var Command, GetStateCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
GetStateCommand = (function(superClass) {
extend(GetStateCommand, superClass);
function GetStateCommand() {
return GetStateCommand.__super__.constructor.apply(this, arguments);
}
GetStateCommand.prototype.execute = function(serial) {
this._send("host-serial:" + serial + ":get-state");
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readValue().then(function(value) {
return value.toString();
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return GetStateCommand;
})(Command);
module.exports = GetStateCommand;
+56
View File
@@ -0,0 +1,56 @@
var Command, ListForwardsCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
ListForwardsCommand = (function(superClass) {
extend(ListForwardsCommand, superClass);
function ListForwardsCommand() {
return ListForwardsCommand.__super__.constructor.apply(this, arguments);
}
ListForwardsCommand.prototype.execute = function(serial) {
this._send("host-serial:" + serial + ":list-forward");
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readValue().then(function(value) {
return _this._parseForwards(value);
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
ListForwardsCommand.prototype._parseForwards = function(value) {
var forward, forwards, i, len, local, ref, ref1, remote, serial;
forwards = [];
ref = value.toString().split('\n');
for (i = 0, len = ref.length; i < len; i++) {
forward = ref[i];
if (forward) {
ref1 = forward.split(/\s+/), serial = ref1[0], local = ref1[1], remote = ref1[2];
forwards.push({
serial: serial,
local: local,
remote: remote
});
}
}
return forwards;
};
return ListForwardsCommand;
})(Command);
module.exports = ListForwardsCommand;
+45
View File
@@ -0,0 +1,45 @@
var Command, Protocol, WaitForDeviceCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
WaitForDeviceCommand = (function(superClass) {
extend(WaitForDeviceCommand, superClass);
function WaitForDeviceCommand() {
return WaitForDeviceCommand.__super__.constructor.apply(this, arguments);
}
WaitForDeviceCommand.prototype.execute = function(serial) {
this._send("host-serial:" + serial + ":wait-for-any");
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readAscii(4).then(function(reply) {
switch (reply) {
case Protocol.OKAY:
return serial;
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return WaitForDeviceCommand;
})(Command);
module.exports = WaitForDeviceCommand;
+45
View File
@@ -0,0 +1,45 @@
var ClearCommand, Command, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
ClearCommand = (function(superClass) {
extend(ClearCommand, superClass);
function ClearCommand() {
return ClearCommand.__super__.constructor.apply(this, arguments);
}
ClearCommand.prototype.execute = function(pkg) {
this._send("shell:pm clear " + pkg);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.searchLine(/^(Success|Failed)$/)["finally"](function() {
return _this.parser.end();
}).then(function(result) {
switch (result[0]) {
case 'Success':
return true;
case 'Failed':
throw new Error("Package '" + pkg + "' could not be cleared");
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return ClearCommand;
})(Command);
module.exports = ClearCommand;
+114
View File
@@ -0,0 +1,114 @@
var Assert, Command, FrameBufferCommand, Protocol, RgbTransform, debug, spawn,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Assert = require('assert');
spawn = require('child_process').spawn;
debug = require('debug')('adb:command:framebuffer');
Command = require('../../command');
Protocol = require('../../protocol');
RgbTransform = require('../../framebuffer/rgbtransform');
FrameBufferCommand = (function(superClass) {
extend(FrameBufferCommand, superClass);
function FrameBufferCommand() {
return FrameBufferCommand.__super__.constructor.apply(this, arguments);
}
FrameBufferCommand.prototype.execute = function(format) {
this._send('framebuffer:');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readBytes(52).then(function(header) {
var meta, stream;
meta = _this._parseHeader(header);
switch (format) {
case 'raw':
stream = _this.parser.raw();
stream.meta = meta;
return stream;
default:
stream = _this._convert(meta, format);
stream.meta = meta;
return stream;
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
FrameBufferCommand.prototype._convert = function(meta, format, raw) {
var proc, transform;
debug("Converting raw framebuffer stream into " + (format.toUpperCase()));
switch (meta.format) {
case 'rgb':
case 'rgba':
break;
default:
debug("Silently transforming '" + meta.format + "' into 'rgb' for `gm`");
transform = new RgbTransform(meta);
meta.format = 'rgb';
raw = this.parser.raw().pipe(transform);
}
proc = spawn('gm', ['convert', '-size', meta.width + "x" + meta.height, meta.format + ":-", format + ":-"]);
raw.pipe(proc.stdin);
return proc.stdout;
};
FrameBufferCommand.prototype._parseHeader = function(header) {
var meta, offset;
meta = {};
offset = 0;
meta.version = header.readUInt32LE(offset);
if (meta.version === 16) {
throw new Error('Old-style raw images are not supported');
}
offset += 4;
meta.bpp = header.readUInt32LE(offset);
offset += 4;
meta.size = header.readUInt32LE(offset);
offset += 4;
meta.width = header.readUInt32LE(offset);
offset += 4;
meta.height = header.readUInt32LE(offset);
offset += 4;
meta.red_offset = header.readUInt32LE(offset);
offset += 4;
meta.red_length = header.readUInt32LE(offset);
offset += 4;
meta.blue_offset = header.readUInt32LE(offset);
offset += 4;
meta.blue_length = header.readUInt32LE(offset);
offset += 4;
meta.green_offset = header.readUInt32LE(offset);
offset += 4;
meta.green_length = header.readUInt32LE(offset);
offset += 4;
meta.alpha_offset = header.readUInt32LE(offset);
offset += 4;
meta.alpha_length = header.readUInt32LE(offset);
meta.format = meta.blue_offset === 0 ? 'bgr' : 'rgb';
if (meta.bpp === 32 || meta.alpha_length) {
meta.format += 'a';
}
return meta;
};
return FrameBufferCommand;
})(Command);
module.exports = FrameBufferCommand;
+51
View File
@@ -0,0 +1,51 @@
var Command, GetFeaturesCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
GetFeaturesCommand = (function(superClass) {
var RE_FEATURE;
extend(GetFeaturesCommand, superClass);
function GetFeaturesCommand() {
return GetFeaturesCommand.__super__.constructor.apply(this, arguments);
}
RE_FEATURE = /^feature:(.*?)(?:=(.*?))?\r?$/gm;
GetFeaturesCommand.prototype.execute = function() {
this._send('shell:pm list features 2>/dev/null');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readAll().then(function(data) {
return _this._parseFeatures(data.toString());
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
GetFeaturesCommand.prototype._parseFeatures = function(value) {
var features, match;
features = {};
while (match = RE_FEATURE.exec(value)) {
features[match[1]] = match[2] || true;
}
return features;
};
return GetFeaturesCommand;
})(Command);
module.exports = GetFeaturesCommand;
+51
View File
@@ -0,0 +1,51 @@
var Command, GetPackagesCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
GetPackagesCommand = (function(superClass) {
var RE_PACKAGE;
extend(GetPackagesCommand, superClass);
function GetPackagesCommand() {
return GetPackagesCommand.__super__.constructor.apply(this, arguments);
}
RE_PACKAGE = /^package:(.*?)\r?$/gm;
GetPackagesCommand.prototype.execute = function() {
this._send('shell:pm list packages 2>/dev/null');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readAll().then(function(data) {
return _this._parsePackages(data.toString());
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
GetPackagesCommand.prototype._parsePackages = function(value) {
var features, match;
features = [];
while (match = RE_PACKAGE.exec(value)) {
features.push(match[1]);
}
return features;
};
return GetPackagesCommand;
})(Command);
module.exports = GetPackagesCommand;
+51
View File
@@ -0,0 +1,51 @@
var Command, GetPropertiesCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
GetPropertiesCommand = (function(superClass) {
var RE_KEYVAL;
extend(GetPropertiesCommand, superClass);
function GetPropertiesCommand() {
return GetPropertiesCommand.__super__.constructor.apply(this, arguments);
}
RE_KEYVAL = /^\[([\s\S]*?)\]: \[([\s\S]*?)\]\r?$/gm;
GetPropertiesCommand.prototype.execute = function() {
this._send('shell:getprop');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readAll().then(function(data) {
return _this._parseProperties(data.toString());
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
GetPropertiesCommand.prototype._parseProperties = function(value) {
var match, properties;
properties = {};
while (match = RE_KEYVAL.exec(value)) {
properties[match[1]] = match[2];
}
return properties;
};
return GetPropertiesCommand;
})(Command);
module.exports = GetPropertiesCommand;
+48
View File
@@ -0,0 +1,48 @@
var Command, InstallCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
InstallCommand = (function(superClass) {
extend(InstallCommand, superClass);
function InstallCommand() {
return InstallCommand.__super__.constructor.apply(this, arguments);
}
InstallCommand.prototype.execute = function(apk) {
this._send("shell:pm install -r " + (this._escapeCompat(apk)));
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.searchLine(/^(Success|Failure \[(.*?)\])$/).then(function(match) {
var code, err;
if (match[1] === 'Success') {
return true;
} else {
code = match[2];
err = new Error(apk + " could not be installed [" + code + "]");
err.code = code;
throw err;
}
})["finally"](function() {
return _this.parser.readAll();
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return InstallCommand;
})(Command);
module.exports = InstallCommand;
+47
View File
@@ -0,0 +1,47 @@
var Command, IsInstalledCommand, Parser, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
Parser = require('../../parser');
IsInstalledCommand = (function(superClass) {
extend(IsInstalledCommand, superClass);
function IsInstalledCommand() {
return IsInstalledCommand.__super__.constructor.apply(this, arguments);
}
IsInstalledCommand.prototype.execute = function(pkg) {
this._send("shell:pm path " + pkg + " 2>/dev/null");
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readAscii(8).then(function(reply) {
switch (reply) {
case 'package:':
return true;
default:
return _this.parser.unexpected(reply, "'package:'");
}
})["catch"](Parser.PrematureEOFError, function(err) {
return false;
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return IsInstalledCommand;
})(Command);
module.exports = IsInstalledCommand;
+55
View File
@@ -0,0 +1,55 @@
var Command, ListReversesCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
ListReversesCommand = (function(superClass) {
extend(ListReversesCommand, superClass);
function ListReversesCommand() {
return ListReversesCommand.__super__.constructor.apply(this, arguments);
}
ListReversesCommand.prototype.execute = function() {
this._send("reverse:list-forward");
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readValue().then(function(value) {
return _this._parseReverses(value);
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
ListReversesCommand.prototype._parseReverses = function(value) {
var i, len, local, ref, ref1, remote, reverse, reverses, serial;
reverses = [];
ref = value.toString().split('\n');
for (i = 0, len = ref.length; i < len; i++) {
reverse = ref[i];
if (reverse) {
ref1 = reverse.split(/\s+/), serial = ref1[0], remote = ref1[1], local = ref1[2];
reverses.push({
remote: remote,
local: local
});
}
}
return reverses;
};
return ListReversesCommand;
})(Command);
module.exports = ListReversesCommand;
+36
View File
@@ -0,0 +1,36 @@
var Command, LocalCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
LocalCommand = (function(superClass) {
extend(LocalCommand, superClass);
function LocalCommand() {
return LocalCommand.__super__.constructor.apply(this, arguments);
}
LocalCommand.prototype.execute = function(path) {
this._send(/:/.test(path) ? path : "localfilesystem:" + path);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.raw();
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return LocalCommand;
})(Command);
module.exports = LocalCommand;
+36
View File
@@ -0,0 +1,36 @@
var Command, LogCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
LogCommand = (function(superClass) {
extend(LogCommand, superClass);
function LogCommand() {
return LogCommand.__super__.constructor.apply(this, arguments);
}
LogCommand.prototype.execute = function(name) {
this._send("log:" + name);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.raw();
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return LogCommand;
})(Command);
module.exports = LogCommand;
+48
View File
@@ -0,0 +1,48 @@
var Command, LineTransform, LogcatCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
LineTransform = require('../../linetransform');
LogcatCommand = (function(superClass) {
extend(LogcatCommand, superClass);
function LogcatCommand() {
return LogcatCommand.__super__.constructor.apply(this, arguments);
}
LogcatCommand.prototype.execute = function(options) {
var cmd;
if (options == null) {
options = {};
}
cmd = 'logcat -B *:I 2>/dev/null';
if (options.clear) {
cmd = "logcat -c 2>/dev/null && " + cmd;
}
this._send("shell:echo && " + cmd);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.raw().pipe(new LineTransform({
autoDetect: true
}));
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return LogcatCommand;
})(Command);
module.exports = LogcatCommand;
+42
View File
@@ -0,0 +1,42 @@
var Command, MonkeyCommand, Promise, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Promise = require('bluebird');
Command = require('../../command');
Protocol = require('../../protocol');
MonkeyCommand = (function(superClass) {
extend(MonkeyCommand, superClass);
function MonkeyCommand() {
return MonkeyCommand.__super__.constructor.apply(this, arguments);
}
MonkeyCommand.prototype.execute = function(port) {
this._send("shell:EXTERNAL_STORAGE=/data/local/tmp monkey --port " + port + " -v");
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.searchLine(/^:Monkey:/).timeout(1000).then(function() {
return _this.parser.raw();
})["catch"](Promise.TimeoutError, function(err) {
return _this.parser.raw();
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return MonkeyCommand;
})(Command);
module.exports = MonkeyCommand;
+36
View File
@@ -0,0 +1,36 @@
var Command, Protocol, RebootCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
RebootCommand = (function(superClass) {
extend(RebootCommand, superClass);
function RebootCommand() {
return RebootCommand.__super__.constructor.apply(this, arguments);
}
RebootCommand.prototype.execute = function() {
this._send('reboot:');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readAll()["return"](true);
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return RebootCommand;
})(Command);
module.exports = RebootCommand;
+36
View File
@@ -0,0 +1,36 @@
var Command, Protocol, RemountCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
RemountCommand = (function(superClass) {
extend(RemountCommand, superClass);
function RemountCommand() {
return RemountCommand.__super__.constructor.apply(this, arguments);
}
RemountCommand.prototype.execute = function() {
this._send('remount:');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return true;
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return RemountCommand;
})(Command);
module.exports = RemountCommand;
+45
View File
@@ -0,0 +1,45 @@
var Command, Protocol, ReverseCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
ReverseCommand = (function(superClass) {
extend(ReverseCommand, superClass);
function ReverseCommand() {
return ReverseCommand.__super__.constructor.apply(this, arguments);
}
ReverseCommand.prototype.execute = function(remote, local) {
this._send("reverse:forward:" + remote + ";" + local);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readAscii(4).then(function(reply) {
switch (reply) {
case Protocol.OKAY:
return true;
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return ReverseCommand;
})(Command);
module.exports = ReverseCommand;
+46
View File
@@ -0,0 +1,46 @@
var Command, Protocol, RootCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
RootCommand = (function(superClass) {
var RE_OK;
extend(RootCommand, superClass);
function RootCommand() {
return RootCommand.__super__.constructor.apply(this, arguments);
}
RE_OK = /restarting adbd as root/;
RootCommand.prototype.execute = function() {
this._send('root:');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readAll().then(function(value) {
if (RE_OK.test(value)) {
return true;
} else {
throw new Error(value.toString().trim());
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return RootCommand;
})(Command);
module.exports = RootCommand;
+52
View File
@@ -0,0 +1,52 @@
var Command, LineTransform, Parser, Promise, Protocol, ScreencapCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Promise = require('bluebird');
Command = require('../../command');
Protocol = require('../../protocol');
Parser = require('../../parser');
LineTransform = require('../../linetransform');
ScreencapCommand = (function(superClass) {
extend(ScreencapCommand, superClass);
function ScreencapCommand() {
return ScreencapCommand.__super__.constructor.apply(this, arguments);
}
ScreencapCommand.prototype.execute = function() {
this._send('shell:echo && screencap -p 2>/dev/null');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
var transform;
switch (reply) {
case Protocol.OKAY:
transform = new LineTransform;
return _this.parser.readBytes(1).then(function(chunk) {
transform = new LineTransform({
autoDetect: true
});
transform.write(chunk);
return _this.parser.raw().pipe(transform);
})["catch"](Parser.PrematureEOFError, function() {
throw new Error('No support for the screencap command');
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return ScreencapCommand;
})(Command);
module.exports = ScreencapCommand;
+39
View File
@@ -0,0 +1,39 @@
var Command, Protocol, ShellCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
ShellCommand = (function(superClass) {
extend(ShellCommand, superClass);
function ShellCommand() {
return ShellCommand.__super__.constructor.apply(this, arguments);
}
ShellCommand.prototype.execute = function(command) {
if (Array.isArray(command)) {
command = command.map(this._escape).join(' ');
}
this._send("shell:" + command);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.raw();
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return ShellCommand;
})(Command);
module.exports = ShellCommand;
+184
View File
@@ -0,0 +1,184 @@
var Command, Parser, Protocol, StartActivityCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
Parser = require('../../parser');
StartActivityCommand = (function(superClass) {
var EXTRA_TYPES, RE_ERROR;
extend(StartActivityCommand, superClass);
function StartActivityCommand() {
return StartActivityCommand.__super__.constructor.apply(this, arguments);
}
RE_ERROR = /^Error: (.*)$/;
EXTRA_TYPES = {
string: 's',
"null": 'sn',
bool: 'z',
int: 'i',
long: 'l',
float: 'l',
uri: 'u',
component: 'cn'
};
StartActivityCommand.prototype.execute = function(options) {
var args;
args = this._intentArgs(options);
if (options.debug) {
args.push('-D');
}
if (options.wait) {
args.push('-W');
}
if (options.user || options.user === 0) {
args.push('--user', this._escape(options.user));
}
return this._run('start', args);
};
StartActivityCommand.prototype._run = function(command, args) {
this._send("shell:am " + command + " " + (args.join(' ')));
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.searchLine(RE_ERROR)["finally"](function() {
return _this.parser.end();
}).then(function(match) {
throw new Error(match[1]);
})["catch"](Parser.PrematureEOFError, function(err) {
return true;
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
StartActivityCommand.prototype._intentArgs = function(options) {
var args;
args = [];
if (options.extras) {
args.push.apply(args, this._formatExtras(options.extras));
}
if (options.action) {
args.push('-a', this._escape(options.action));
}
if (options.data) {
args.push('-d', this._escape(options.data));
}
if (options.mimeType) {
args.push('-t', this._escape(options.mimeType));
}
if (options.category) {
if (Array.isArray(options.category)) {
options.category.forEach((function(_this) {
return function(category) {
return args.push('-c', _this._escape(category));
};
})(this));
} else {
args.push('-c', this._escape(options.category));
}
}
if (options.component) {
args.push('-n', this._escape(options.component));
}
if (options.flags) {
args.push('-f', this._escape(options.flags));
}
return args;
};
StartActivityCommand.prototype._formatExtras = function(extras) {
if (!extras) {
return [];
}
if (Array.isArray(extras)) {
return extras.reduce((function(_this) {
return function(all, extra) {
return all.concat(_this._formatLongExtra(extra));
};
})(this), []);
} else {
return Object.keys(extras).reduce((function(_this) {
return function(all, key) {
return all.concat(_this._formatShortExtra(key, extras[key]));
};
})(this), []);
}
};
StartActivityCommand.prototype._formatShortExtra = function(key, value) {
var sugared;
sugared = {
key: key
};
if (value === null) {
sugared.type = 'null';
} else if (Array.isArray(value)) {
throw new Error("Refusing to format array value '" + key + "' using short syntax; empty array would cause unpredictable results due to unknown type. Please use long syntax instead.");
} else {
switch (typeof value) {
case 'string':
sugared.type = 'string';
sugared.value = value;
break;
case 'boolean':
sugared.type = 'bool';
sugared.value = value;
break;
case 'number':
sugared.type = 'int';
sugared.value = value;
break;
case 'object':
sugared = value;
sugared.key = key;
}
}
return this._formatLongExtra(sugared);
};
StartActivityCommand.prototype._formatLongExtra = function(extra) {
var args, type;
args = [];
if (!extra.type) {
extra.type = 'string';
}
type = EXTRA_TYPES[extra.type];
if (!type) {
throw new Error("Unsupported type '" + extra.type + "' for extra '" + extra.key + "'");
}
if (extra.type === 'null') {
args.push("--e" + type);
args.push(this._escape(extra.key));
} else if (Array.isArray(extra.value)) {
args.push("--e" + type + "a");
args.push(this._escape(extra.key));
args.push(this._escape(extra.value.join(',')));
} else {
args.push("--e" + type);
args.push(this._escape(extra.key));
args.push(this._escape(extra.value));
}
return args;
};
return StartActivityCommand;
})(Command);
module.exports = StartActivityCommand;
+33
View File
@@ -0,0 +1,33 @@
var Command, Parser, Protocol, StartActivityCommand, StartServiceCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
Parser = require('../../parser');
StartActivityCommand = require('./startactivity');
StartServiceCommand = (function(superClass) {
extend(StartServiceCommand, superClass);
function StartServiceCommand() {
return StartServiceCommand.__super__.constructor.apply(this, arguments);
}
StartServiceCommand.prototype.execute = function(options) {
var args;
args = this._intentArgs(options);
if (options.user || options.user === 0) {
args.push('--user', this._escape(options.user));
}
return this._run('startservice', args);
};
return StartServiceCommand;
})(StartActivityCommand);
module.exports = StartServiceCommand;
+38
View File
@@ -0,0 +1,38 @@
var Command, Protocol, Sync, SyncCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
Sync = require('../../sync');
SyncCommand = (function(superClass) {
extend(SyncCommand, superClass);
function SyncCommand() {
return SyncCommand.__super__.constructor.apply(this, arguments);
}
SyncCommand.prototype.execute = function() {
this._send('sync:');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return new Sync(_this.connection);
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return SyncCommand;
})(Command);
module.exports = SyncCommand;
+36
View File
@@ -0,0 +1,36 @@
var Command, Protocol, TcpCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
TcpCommand = (function(superClass) {
extend(TcpCommand, superClass);
function TcpCommand() {
return TcpCommand.__super__.constructor.apply(this, arguments);
}
TcpCommand.prototype.execute = function(port, host) {
this._send(("tcp:" + port) + (host ? ":" + host : ''));
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.raw();
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return TcpCommand;
})(Command);
module.exports = TcpCommand;
+46
View File
@@ -0,0 +1,46 @@
var Command, Protocol, TcpIpCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
TcpIpCommand = (function(superClass) {
var RE_OK;
extend(TcpIpCommand, superClass);
function TcpIpCommand() {
return TcpIpCommand.__super__.constructor.apply(this, arguments);
}
RE_OK = /restarting in/;
TcpIpCommand.prototype.execute = function(port) {
this._send("tcpip:" + port);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readAll().then(function(value) {
if (RE_OK.test(value)) {
return port;
} else {
throw new Error(value.toString().trim());
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return TcpIpCommand;
})(Command);
module.exports = TcpIpCommand;
+120
View File
@@ -0,0 +1,120 @@
var Command, EventEmitter, Parser, Promise, Protocol, TrackJdwpCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
EventEmitter = require('events').EventEmitter;
Promise = require('bluebird');
Command = require('../../command');
Protocol = require('../../protocol');
Parser = require('../../parser');
TrackJdwpCommand = (function(superClass) {
var Tracker;
extend(TrackJdwpCommand, superClass);
function TrackJdwpCommand() {
return TrackJdwpCommand.__super__.constructor.apply(this, arguments);
}
TrackJdwpCommand.prototype.execute = function() {
this._send('track-jdwp');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return new Tracker(_this);
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
Tracker = (function(superClass1) {
extend(Tracker, superClass1);
function Tracker(command) {
this.command = command;
this.pids = [];
this.pidMap = Object.create(null);
this.reader = this.read()["catch"](Parser.PrematureEOFError, (function(_this) {
return function(err) {
return _this.emit('end');
};
})(this))["catch"](Promise.CancellationError, (function(_this) {
return function(err) {
_this.command.connection.end();
return _this.emit('end');
};
})(this))["catch"]((function(_this) {
return function(err) {
_this.command.connection.end();
_this.emit('error', err);
return _this.emit('end');
};
})(this));
}
Tracker.prototype.read = function() {
return this.command.parser.readValue().cancellable().then((function(_this) {
return function(list) {
var maybeEmpty, pids;
pids = list.toString().split('\n');
if (maybeEmpty = pids.pop()) {
pids.push(maybeEmpty);
}
return _this.update(pids);
};
})(this));
};
Tracker.prototype.update = function(newList) {
var changeSet, i, j, len, len1, newMap, pid, ref;
changeSet = {
removed: [],
added: []
};
newMap = Object.create(null);
for (i = 0, len = newList.length; i < len; i++) {
pid = newList[i];
if (!this.pidMap[pid]) {
changeSet.added.push(pid);
this.emit('add', pid);
newMap[pid] = pid;
}
}
ref = this.pids;
for (j = 0, len1 = ref.length; j < len1; j++) {
pid = ref[j];
if (!newMap[pid]) {
changeSet.removed.push(pid);
this.emit('remove', pid);
}
}
this.pids = newList;
this.pidMap = newMap;
this.emit('changeSet', changeSet, newList);
return this;
};
Tracker.prototype.end = function() {
this.reader.cancel();
return this;
};
return Tracker;
})(EventEmitter);
return TrackJdwpCommand;
})(Command);
module.exports = TrackJdwpCommand;
+44
View File
@@ -0,0 +1,44 @@
var Command, Protocol, UninstallCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
UninstallCommand = (function(superClass) {
extend(UninstallCommand, superClass);
function UninstallCommand() {
return UninstallCommand.__super__.constructor.apply(this, arguments);
}
UninstallCommand.prototype.execute = function(pkg) {
this._send("shell:pm uninstall " + pkg);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.searchLine(/^(Success|Failure.*|.*Unknown package:.*)$/).then(function(match) {
if (match[1] === 'Success') {
return true;
} else {
return true;
}
})["finally"](function() {
return _this.parser.readAll();
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, "OKAY or FAIL");
}
};
})(this));
};
return UninstallCommand;
})(Command);
module.exports = UninstallCommand;
+46
View File
@@ -0,0 +1,46 @@
var Command, Protocol, UsbCommand,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
UsbCommand = (function(superClass) {
var RE_OK;
extend(UsbCommand, superClass);
function UsbCommand() {
return UsbCommand.__super__.constructor.apply(this, arguments);
}
RE_OK = /restarting in/;
UsbCommand.prototype.execute = function() {
this._send('usb:');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readAll().then(function(value) {
if (RE_OK.test(value)) {
return true;
} else {
throw new Error(value.toString().trim());
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return UsbCommand;
})(Command);
module.exports = UsbCommand;
+42
View File
@@ -0,0 +1,42 @@
var Command, Protocol, WaitBootCompleteCommand, debug,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
debug = require('debug')('adb:command:waitboot');
Command = require('../../command');
Protocol = require('../../protocol');
WaitBootCompleteCommand = (function(superClass) {
extend(WaitBootCompleteCommand, superClass);
function WaitBootCompleteCommand() {
return WaitBootCompleteCommand.__super__.constructor.apply(this, arguments);
}
WaitBootCompleteCommand.prototype.execute = function() {
this._send('shell:while getprop sys.boot_completed 2>/dev/null; do sleep 1; done');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.searchLine(/^1$/)["finally"](function() {
return _this.parser.end();
}).then(function() {
return true;
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return WaitBootCompleteCommand;
})(Command);
module.exports = WaitBootCompleteCommand;
+46
View File
@@ -0,0 +1,46 @@
var Command, ConnectCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
ConnectCommand = (function(superClass) {
var RE_OK;
extend(ConnectCommand, superClass);
function ConnectCommand() {
return ConnectCommand.__super__.constructor.apply(this, arguments);
}
RE_OK = /connected to|already connected/;
ConnectCommand.prototype.execute = function(host, port) {
this._send("host:connect:" + host + ":" + port);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readValue().then(function(value) {
if (RE_OK.test(value)) {
return host + ":" + port;
} else {
throw new Error(value.toString());
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return ConnectCommand;
})(Command);
module.exports = ConnectCommand;
+64
View File
@@ -0,0 +1,64 @@
var Command, HostDevicesCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
HostDevicesCommand = (function(superClass) {
extend(HostDevicesCommand, superClass);
function HostDevicesCommand() {
return HostDevicesCommand.__super__.constructor.apply(this, arguments);
}
HostDevicesCommand.prototype.execute = function() {
this._send('host:devices');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this._readDevices();
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
HostDevicesCommand.prototype._readDevices = function() {
return this.parser.readValue().then((function(_this) {
return function(value) {
return _this._parseDevices(value);
};
})(this));
};
HostDevicesCommand.prototype._parseDevices = function(value) {
var devices, i, id, len, line, ref, ref1, type;
devices = [];
if (!value.length) {
return devices;
}
ref = value.toString('ascii').split('\n');
for (i = 0, len = ref.length; i < len; i++) {
line = ref[i];
if (line) {
ref1 = line.split('\t'), id = ref1[0], type = ref1[1];
devices.push({
id: id,
type: type
});
}
}
return devices;
};
return HostDevicesCommand;
})(Command);
module.exports = HostDevicesCommand;
+65
View File
@@ -0,0 +1,65 @@
var Command, HostDevicesWithPathsCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
HostDevicesWithPathsCommand = (function(superClass) {
extend(HostDevicesWithPathsCommand, superClass);
function HostDevicesWithPathsCommand() {
return HostDevicesWithPathsCommand.__super__.constructor.apply(this, arguments);
}
HostDevicesWithPathsCommand.prototype.execute = function() {
this._send('host:devices-l');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this._readDevices();
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
HostDevicesWithPathsCommand.prototype._readDevices = function() {
return this.parser.readValue().then((function(_this) {
return function(value) {
return _this._parseDevices(value);
};
})(this));
};
HostDevicesWithPathsCommand.prototype._parseDevices = function(value) {
var devices, i, id, len, line, path, ref, ref1, type;
devices = [];
if (!value.length) {
return devices;
}
ref = value.toString('ascii').split('\n');
for (i = 0, len = ref.length; i < len; i++) {
line = ref[i];
if (line) {
ref1 = line.split(/\s+/), id = ref1[0], type = ref1[1], path = ref1[2];
devices.push({
id: id,
type: type,
path: path
});
}
}
return devices;
};
return HostDevicesWithPathsCommand;
})(Command);
module.exports = HostDevicesWithPathsCommand;
+46
View File
@@ -0,0 +1,46 @@
var Command, DisconnectCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
DisconnectCommand = (function(superClass) {
var RE_OK;
extend(DisconnectCommand, superClass);
function DisconnectCommand() {
return DisconnectCommand.__super__.constructor.apply(this, arguments);
}
RE_OK = /^$/;
DisconnectCommand.prototype.execute = function(host, port) {
this._send("host:disconnect:" + host + ":" + port);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readValue().then(function(value) {
if (RE_OK.test(value)) {
return host + ":" + port;
} else {
throw new Error(value.toString());
}
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return DisconnectCommand;
})(Command);
module.exports = DisconnectCommand;
+36
View File
@@ -0,0 +1,36 @@
var Command, HostKillCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
HostKillCommand = (function(superClass) {
extend(HostKillCommand, superClass);
function HostKillCommand() {
return HostKillCommand.__super__.constructor.apply(this, arguments);
}
HostKillCommand.prototype.execute = function() {
this._send('host:kill');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return true;
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return HostKillCommand;
})(Command);
module.exports = HostKillCommand;
+40
View File
@@ -0,0 +1,40 @@
var Command, HostDevicesCommand, HostTrackDevicesCommand, Protocol, Tracker,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
Tracker = require('../../tracker');
HostDevicesCommand = require('./devices');
HostTrackDevicesCommand = (function(superClass) {
extend(HostTrackDevicesCommand, superClass);
function HostTrackDevicesCommand() {
return HostTrackDevicesCommand.__super__.constructor.apply(this, arguments);
}
HostTrackDevicesCommand.prototype.execute = function() {
this._send('host:track-devices');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return new Tracker(_this);
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return HostTrackDevicesCommand;
})(HostDevicesCommand);
module.exports = HostTrackDevicesCommand;
+36
View File
@@ -0,0 +1,36 @@
var Command, HostTransportCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
HostTransportCommand = (function(superClass) {
extend(HostTransportCommand, superClass);
function HostTransportCommand() {
return HostTransportCommand.__super__.constructor.apply(this, arguments);
}
HostTransportCommand.prototype.execute = function(serial) {
this._send("host:transport:" + serial);
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return true;
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this.parser.unexpected(reply, 'OKAY or FAIL');
}
};
})(this));
};
return HostTransportCommand;
})(Command);
module.exports = HostTransportCommand;
+42
View File
@@ -0,0 +1,42 @@
var Command, HostVersionCommand, Protocol,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Command = require('../../command');
Protocol = require('../../protocol');
HostVersionCommand = (function(superClass) {
extend(HostVersionCommand, superClass);
function HostVersionCommand() {
return HostVersionCommand.__super__.constructor.apply(this, arguments);
}
HostVersionCommand.prototype.execute = function() {
this._send('host:version');
return this.parser.readAscii(4).then((function(_this) {
return function(reply) {
switch (reply) {
case Protocol.OKAY:
return _this.parser.readValue().then(function(value) {
return _this._parseVersion(value);
});
case Protocol.FAIL:
return _this.parser.readError();
default:
return _this._parseVersion(reply);
}
};
})(this));
};
HostVersionCommand.prototype._parseVersion = function(version) {
return parseInt(version, 16);
};
return HostVersionCommand;
})(Command);
module.exports = HostVersionCommand;