#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
@file: adb.py
@author: kessil
@contact: https://github.com/kessil/
@time: 2019年06月02日 15:57:23
@desc: Life is short, you need Python
'''

import os
import subprocess
from config import Config
from time import sleep

def pull_xml(filename):
    while True:
        if os.path.exists(filename):
            os.remove(filename)
        os.system('adb shell uiautomator dump /sdcard/ui.xml')
        sleep(1)
        os.system('adb pull /sdcard/ui.xml %s'%filename)
        if os.path.getsize(filename):
            break


def tap_screen(x, y):
    # print('tap (%d, %d)'%(x, y))
    # os.system('adb shell input tap %d %d'%(x, y))

    os.system('adb shell input swipe %d %d %d %d 50'%(x, y, x, y))

def connect_mumu():
    os.system('adb connect 127.0.0.1:7555')

if __name__ == "__main__":
    subprocess.check_call('adb shell uiautomator dump /sdcard/ui.xml', shell=True, stdout=subprocess.PIPE)
    print(subprocess.check_call('adb pull /sdcard/ui.xml ui-test.xml', shell=True, stdout=subprocess.PIPE))

