require 'di' require 'ADB' require 'stf/client' require 'stf/log/log' module Stf class StopDebugSessionInteractor include Log include ADB def execute(remote_connect_url) remote_devices = DI[:stf].get_user_devices device = remote_devices.find {|d| d.remoteConnect == true && DI[:device_enhancer].get_tunneled_remote_connect_url(d).eql?(remote_connect_url)} # try to disconnect anyway if DI[:connect_ios].connected_ios_devices.include? remote_connect_url DI[:connect_ios].disconnect() else execute_adb_with 30, "disconnect #{remote_connect_url}" end if device.nil? logger.error "Device #{remote_connect_url} is not available" return false end success = false 1..10.times do begin success = DI[:stf].stop_debug(device.serial) break if success rescue end logger.error 'Can\'t stop debug session. Retrying' end 1..10.times do begin success = DI[:stf].remove_device(device.serial) break if success rescue end logger.error 'Can\'t remove device from user devices. Retrying' end if success logger.info "Successfully removed #{remote_connect_url}" else logger.error "Error removing #{remote_connect_url}" end success end end end