"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getAdbPath=getAdbPath,exports.tryRunAdbReverse=tryRunAdbReverse;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),fs_extra_1=tslib_1.__importDefault(require("fs-extra")),child_process_1=require("child_process"),env_1=require("../../../utils/env");function getAdbPath(){const e=(0,env_1.getProcessEnv)();let t;return e.ANDROID_HOME?(t=path_1.default.join(e.ANDROID_HOME,"platform-tools","adb"),fs_extra_1.default.existsSync(t)||(t="adb")):t="adb","adb"}function tryRunAdbReverse(e){try{const{packagerPort:t,device:r,recorder:s}=e,n=getAdbPath(),o=["reverse","tcp:"+t,"tcp:"+t];r&&o.unshift("-s",r),s.progress("Connecting to the development server..."),console.log(`Running command "${n} ${o.join(" ")}"`),(0,child_process_1.execFileSync)(n,o,{stdio:"inherit",env:(0,env_1.getProcessEnv)()})}catch(e){throw new Error('Failed to connect to development server using "adb reverse": '+e.message)}}