export function adb()

in lib/utils.ts [86:130]


export function adb(
    sdkPath: string, port: number, command: string, timeout: number,
    args?: string[]): Promise<string> {
  return new Promise<string>((resolve, reject) => {
    let child = spawn(
        path.resolve(sdkPath, 'platform-tools', 'adb'),
        ['-s', 'emulator-' + port, command].concat(args || []), 'pipe');
    let done = false;
    let buffer: (string|Buffer)[] = [];
    child.stdout.on('data', buffer.push.bind(buffer));
    child.on('error', (err: Error) => {
      if (!done) {
        done = true;
        reject(err);
      }
    });
    child.on('exit', (code: number, signal: string) => {
      if (!done) {
        done = true;
        if (code === 0) {
          resolve(buffer.join(''));
        } else {
          reject({
            code: code,
            message: 'abd command "' + command + '" ' +
                (signal ? 'received signal ' + signal : 'returned with a non-zero exit code') +
                'for emulator-' + port
          });
        }
      }
    });
    if (timeout) {
      setTimeout(() => {
        if (!done) {
          done = true;
          child.kill();
          reject({
            code: 'TIMEOUT',
            message: 'adb command "' + command + '" timed out for emulator-' + port
          });
        }
      }, timeout);
    }
  });
}