def init_screencap_mode(cls, mode): consts = UtilConsts.ScreenCapMode cls.screencap_mode = mode if cls.screencap_mode == consts.ASCREENCAP: # Prepare for ascreencap, push the required libraries Adb.exec_out('rm /data/local/tmp/ascreencap') cpuArc = Adb.exec_out('getprop ro.product.cpu.abi').decode( 'utf-8').strip() sdkVer = int( Adb.exec_out('getprop ro.build.version.sdk').decode( 'utf-8').strip()) ascreencaplib = 'ascreencap_{}'.format(cpuArc) if sdkVer in range(21, 26) and os.path.isfile(ascreencaplib): Adb.cmd( 'push {} /data/local/tmp/ascreencap'.format(ascreencaplib)) else: Logger.log_warning( 'No suitable version of aScreenCap lib is available locally, using ascreencap_local...' ) if os.path.isfile('ascreencap_local'): Adb.cmd('push ascreencap_local /data/local/tmp/ascreencap') else: Logger.log_error( 'File "ascreencap_local" not found. Please download the appropriate version of aScreenCap for your device from github.com/ClnViewer/Android-fast-screen-capture and save it as "ascreencap_local"' ) Logger.log_warning( 'Since aScreenCap is not ready, falling back to normal adb screencap' ) Utils.useAScreenCap = False Adb.shell('chmod 0777 /data/local/tmp/ascreencap')
def screencapInit(cls, config): """Method that loads the required infos for screen_update and touch to work (screen resolution, emulator name, shared folder path), loads ascreencap in shared folder or through adb push depending on the device Args: config (Config): ALAuto Config instance. """ cls.resolution = config.resolution cls.emulator = config.network['emulator'] cls.sharedfolder = config.network['sharedfolder'] #loading acreencap in shared folder if not present if config.network['emulator'] == ('Memu' or 'BlueStacks'): if not os.path.exists(config.network['sharedfolder'] + 'ascreencap'): Logger.log_info('loading ascreencap in shared folder...') shutil.copy('ascreencap/x86/ascreencap', config.network['sharedfolder']) #loading ascreencap for other devices elif useAScreenCap == True: cpuArch = str(Adb.shell('getprop ro.product.cpu.abi')) #supported ascreencap cpu achitectures for arch in ['arm64-v8a', 'armeabi-v7a', 'x86_64', 'x86']: if cpuArch.find(arch) != -1: Logger.log_debug("CPU achitecture found: " + arch) Adb.push( 'ascreencap/{}/ascreencap /data/local/tmp/'.format( arch)) Adb.shell('chmod 0777 /data/local/tmp/ascreencap') return Logger.log_error("CPU architecture not supported: {}".format(arch)) sys.exit()
def touch(cls, coords): """Sends an input command to touch the device screen at the specified coordinates via ADB Args: coords (array): An array containing the x and y coordinate of where to touch the screen """ Adb.shell("input swipe {} {} {} {} {}".format(coords[0], coords[1], coords[0], coords[1], randint(50, 120))) cls.script_sleep()
def swipe(cls, x1, y1, x2, y2, ms): """Sends an input command to swipe the device screen between the specified coordinates via ADB Args: x1 (int): x-coordinate to begin the swipe at. y1 (int): x-coordinate to end the swipe at. x2 (int): y-coordinate to begin the swipe at. y2 (int): y-coordinate to begin the swipe at. ms (int): Duration in ms of swipe. """ Adb.shell("input swipe {} {} {} {} {}".format(x1, y1, x2, y2, ms))
def swipe(cls, x1, y1, x2, y2, ms): """Sends an input command to swipe the device screen between the specified coordinates via ADB Args: x1 (int): x-coordinate to begin the swipe at. y1 (int): y-coordinate to begin the swipe at. x2 (int): x-coordinate to end the swipe at. y2 (int): y-coordinate to end the swipe at. ms (int): Duration in ms of swipe. This value shouldn't be lower than 300, better if it is higher. """ Adb.shell("input swipe {} {} {} {} {}".format(x1, y1, x2, y2, ms)) cls.update_screen()
def touch(cls, coords): """Sends an input command to touch the device screen at the specified coordinates via ADB Args: coords (array): An array containing the x and y coordinate of where to touch the screen """ #scaling the touch coords depending on screen resolution if re.search('1920x1080|1080x1920', cls.resolution): coords = (int(coords[0]), int(coords[1])) else: #for 720p coords = (int(coords[0] / 1.5), int(coords[1] / 1.5)) Adb.shell("input swipe {} {} {} {} {}".format(coords[0], coords[1], coords[0], coords[1], randint(50, 120))) cls.script_sleep()
def swipe(cls, x1, y1, x2, y2, ms): """Sends an input command to swipe the device screen between the specified coordinates via ADB Args: x1 (int): x-coordinate to begin the swipe at. y1 (int): y-coordinate to begin the swipe at. x2 (int): x-coordinate to end the swipe at. y2 (int): y-coordinate to end the swipe at. ms (int): Duration in ms of swipe. This value shouldn't be lower than 300, better if it is higher. """ #scaling the swipe coords depending on screen resolution if re.search('1920x1080|1080x1920', cls.resolution): Adb.shell("input swipe {} {} {} {} {}".format(x1, y1, x2, y2, ms)) else: #for 720p Adb.shell("input swipe {} {} {} {} {}".format( x1 / 1.5, y1 / 1.5, x2 / 1.5, y2 / 1.5, ms)) cls.update_screen()
Adb.cmd('push {} /data/local/tmp/ascreencap'.format(ascreencaplib)) else: Logger.log_warning( 'No suitable version of aScreenCap lib is available locally, using ascreencap_local...' ) if os.path.isfile('ascreencap_local'): Adb.cmd('push ascreencap_local /data/local/tmp/ascreencap') else: Logger.log_error( 'File "ascreencap_local" not found. Please download the appropriate version of aScreenCap for your device from github.com/ClnViewer/Android-fast-screen-capture and save it as "ascreencap_local"' ) Logger.log_warning( 'Since aScreenCap is not ready, falling back to normal adb screencap' ) Utils.useAScreenCap = False Adb.shell('chmod 0777 /data/local/tmp/ascreencap') else: Logger.log_error('Unable to connect to the service.') sys.exit() try: while True: Utils.update_screen() # temporal solution to event alerts if not Utils.find("menu/button_battle"): Utils.touch_randomly(Region(54, 57, 67, 67)) Utils.script_sleep(1) continue if Utils.find("commission/alert_completed"):