@u4/adbkit
Version:
A Typescript client for the Android Debug Bridge.
40 lines • 2.16 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = __importDefault(require("../../command"));
const utils_1 = __importDefault(require("../../utils"));
class MonkeyCommand extends command_1.default {
constructor(connection, timeout = 1000, options) {
super(connection, options);
this.timeout = timeout;
}
async execute(port) {
// Some devices have broken /sdcard (i.e. /mnt/sdcard), which monkey will
// attempt to use to write log files to. We can cheat and set the location
// with an environment variable, because most logs use
// Environment.getLegacyExternalStorageDirectory() like they should. There
// are some hardcoded logs, though. Anyway, this should enable most things.
// Check https://github.com/android/platform_frameworks_base/blob/master/
// core/java/android/os/Environment.java for the variables.
this.sendCommand(`shell:EXTERNAL_STORAGE=/data/local/tmp monkey --port ${port} -v`);
await this.readOKAY();
// The monkey command is a bit weird in that it doesn't look like
// it starts in daemon mode, but it actually does. So even though
// the command leaves the terminal "hanging", Ctrl-C (or just
// ending the connection) will not end the daemon. HOWEVER, on
// some devices, such as SO-02C by Sony, it is required to leave
// the command hanging around. In any case, if the command exits
// by itself, it means that something went wrong.
// On some devices (such as F-08D by Fujitsu), the monkey
// command gives no output no matter how many verbose flags you
// give it. So we use a fallback timeout.
const pTimeout = utils_1.default.delay(this.timeout);
const parse = this.parser.searchLine(/^:Monkey:/);
await Promise.race([pTimeout, parse]);
return this.parser.raw();
}
}
exports.default = MonkeyCommand;
//# sourceMappingURL=monkey.js.map