def connect(): adb = Client(host="127.0.0.1", port=5037) devices = adb.devices() if len(devices) == 0: print("No device found!") quit(1) return devices[0]
def __init__(self): self.log = MyLogger('ADB', LOG_LEVEL=logging.INFO) client = Client(host='127.0.0.1', port=5037) self.log.debug(client.version()) devices = client.devices() if len(devices) == 0: self.log.debug("no devices") quit() self.device = devices[0] self.log.debug(f'updating info for {self.device}') number = 5 touch_id = 0 lines = self.device.shell('getevent -p').split("\n") for line in lines: if "/dev/input" in line: number = line[-1] if "Touch" in line: touch_id = number self.touch = f"sendevent /dev/input/event{number}" if "max" in line and "ABS" in line and number == touch_id: values = line.split(', ') for value in values: if "max" in value: self.max = int(value[4:]) self.log.debug(f"found max: {self.max}")
def connect(deviceid): try: cnx = initmysql() cursor = mysqlCursor(cnx) query = execQuery( cursor, "SELECT port,name FROM lords.devices where id=" + str(deviceid)) field_name = [field[0] for field in query.description] result_set = query.fetchone() if result_set != None: row = dict(zip(field_name, result_set)) portNo = int(row['port']) emulatorname = row['name'] else: portNo = 5037 print("name ", emulatorname) adb = Client(host='127.0.0.1', port=portNo) devices = adb.devices() if len(devices) == 0: print('no device attached') quit() device = adb.device(emulatorname) return device except (): quit()
def connect_device(): adb = Client(host='127.0.0.1',port=5037) devices = adb.devices() if len(devices) == 0: print("No Devices Attached") quit() return devices[0]
def connect(self): # connect to android device self.adb = Client(host=self.host, port=self.port) try: self.device = self.adb.devices()[0] except: print("Cannot connect to phone!")
def init(): os.system('adb devices -l') adb = Client(host='127.0.0.1', port=5037) devices = adb.devices() if len(devices) == 0: print('no devices found') quit() device = devices[0] return device
def check_device(): global current_device adb = Client(host='127.0.0.1', port=5037) devices = adb.devices() if len(devices) == 0: print('no device attached') print('exit') quit() else: current_device = devices[0] print(f"device found {current_device.serial} ") create_folder(folder) start()
def main(): logging.info('before adb') adb = Client(host='127.0.0.1', port=5037) devices = adb.devices() logging.info('after adb') if len(devices) == 0: print('no device attached') quit() device = devices[0] logging.info('before adb swipe') device.shell('input touchscreen swipe 500 500 500 500 10') logging.info('after adb swipe') logging.info('before adb swipe2') device.shell('input touchscreen swipe 200 200 200 200 10') logging.info('after adb swipe2') logging.info('before touch')
from ppadb.client import Client def dump_logcat_by_line(connect): file_obj = connect.socket.makefile() while True: print("Line: {}".format(file_obj.readline().strip())) file_obj.close() connect.close() client = Client() device = client.device("4c9a5ecc") device.shell("logcat", handler=dump_logcat_by_line)
# import os # device = os.popen("adb devices").read() # print(device) from ppadb.client import Client from PIL import Image import pytesseract import copy from sudoku import solve, print_board adb = Client() devices = adb.devices() if len(devices) == 0: print("No devices attached") quit() device = devices[0] result = device.screencap() with open("screen.png", "wb") as fp: fp.write(result) im = Image.open("screen.png") # im.show() # imcrop = im.crop((0,280,120,400)) # imcrop.show() # print(pytesseract.image_to_string(imcrop, config='--psm 10')) x, y = 3, 285 dx, dy = 112, 114 grid = []
def get_device(): client = Client(host='127.0.0.1', port=5037) device = client.device('127.0.0.1:62001') return device
import numpy from PIL import Image from ppadb.client import Client # ADB api, lets you integrate adb shell with python import time # Setting up adb shell service adb = Client(host="127.0.0.1", port = 5037) # default hostname = localhost, default port = 5037 devices = adb.devices() # initalise adb module # Method checks if devices are connected if len(devices) == 0: print("No device Connected") quit() device = devices[0] # If device detected, make it primary device. # driver program while True: image = device.screencap() # Take screenshot of mobile device with open("screen.png", "wb") as f: # Open Screenshot as binary file and write to it f.write(image) image = Image.open("screen.png") image = numpy.array(image, dtype = numpy.uint8) # convert image into numpy array # Following method looks for black pixels in pillars, :3 represents to include only rgb values and not alpha values # 1680 was my screen's Y coordinate from where black pillar started, adjust the value according to your screen. pixels = [list(i[:3]) for i in image[1680]] # Finding transition from black pixel in pillar to color to again black pixel in pillars
def connect(self, always_log_errors=True): """Connect to an Android TV / Fire TV device. Parameters ---------- always_log_errors : bool If True, errors will always be logged; otherwise, errors will only be logged on the first failed reconnect attempt Returns ------- bool Whether or not the connection was successfully established and the device is available """ try: with _acquire(self._adb_lock): # Catch exceptions try: self._adb_client = Client(host=self.adb_server_ip, port=self.adb_server_port) self._adb_device = self._adb_client.device('{}:{}'.format( self.host, self.port)) # ADB connection successfully established if self._adb_device: _LOGGER.debug( "ADB connection to %s:%d via ADB server %s:%d successfully established", self.host, self.port, self.adb_server_ip, self.adb_server_port) self._available = True return True # ADB connection attempt failed (without an exception) if self._available or always_log_errors: _LOGGER.warning( "Couldn't connect to %s:%d via ADB server %s:%d", self.host, self.port, self.adb_server_ip, self.adb_server_port) self.close() self._available = False return False # ADB connection attempt failed except Exception as exc: # noqa pylint: disable=broad-except if self._available or always_log_errors: _LOGGER.warning( "Couldn't connect to %s:%d via ADB server %s:%d, error: %s", self.host, self.port, self.adb_server_ip, self.adb_server_port, exc) self.close() self._available = False return False except LockNotAcquiredException: _LOGGER.warning( "Couldn't connect to %s:%d via ADB server %s:%d because pure-python-adb lock not acquired.", self.host, self.port, self.adb_server_ip, self.adb_server_port) self.close() self._available = False return False
def setup_device(self) -> bool: """ Sets up device through Android Debug Bridge in local port 5037. Returns whether or not successful. Currently only supports 16x9 aspect ratios. """ adb = Client(host='127.0.0.1', port=5037) devices = adb.devices() if len(devices) == 0: return False device = devices[0] # Configure movements based on resolution. res_str = device.shell('wm size').replace('Physical size: ', '') res_width, res_height = list(map(int, res_str.split('x'))) # Account for status bar/nav bar. navbar_str = device.shell( "dumpsys window windows | sed -n '/Window .*NavigationBar.*" \ ":/,/Window .*:/p' | grep 'Requested'" ) statusbar_str = device.shell( "dumpsys window windows | sed -n '/Window .*StatusBar.*" \ ":/,/Window .*:/p' | grep 'Requested'" ) nav_match = re.search('h=(\d+)', navbar_str) navbar_height = int(nav_match.group(1)) if nav_match else 0 status_match = re.search('h=(\d+)', statusbar_str) statusbar_height = int(status_match.group(1)) if status_match else 0 # Adjust res width/height to fit actually usable screen. usable_res_height = res_height - statusbar_height - navbar_height # PAD uses black bars to pad screen in order to fit aspect ratio. # Calculate the height of the bars so that we can locate lower left corner. game_res_height = (res_width * self.height_ratio) // self.width_ratio bar_height = (usable_res_height - game_res_height) bottom_y = res_height - (navbar_height + bar_height) # Calculate radius of orbs and how much to shift when moving. radius = (res_width // self.board_cols) // 2 change = (res_width) // self.board_cols top_y = bottom_y - self.board_rows * change # Create 2d array of actual coordinates. coordinates = \ [ [ (radius + col * change, top_y + radius + row * change) for col in range(self.board_cols) ] for row in range(self.board_rows) ] # Set private variables. self.coordinates = coordinates self.device = AutomatorDevice() # For PAD board dimensions/coordinates self.bottom = bottom_y self.top = top_y self.left = 0 self.right = res_width return True
def getDevices(host='127.0.0.1', port=5037): client = Client(host, port) waitForDevice() return client.devices()
orange = [None] * 9 blue = [None] * 9 green = [None] * 9 whitet = [None] * 9 yellowt = [None] * 9 redt = [None] * 9 oranget = [None] * 9 bluet = [None] * 9 greent = [None] * 9 dic = {'pos': [], 'color': []} big_list = [white, yellow, red, orange, green, blue] adb = Client(host="127.0.0.1", port=5037) devices = adb.devices() device = devices[0] yellowc = cv2.imread( r"E:\Sanath\whatsapp_det-20200904T181330Z-001\whatsapp_det\rubik\yellow.jpg" ) redc = cv2.imread( r"E:\Sanath\whatsapp_det-20200904T181330Z-001\whatsapp_det\rubik\red.jpg") bluec = cv2.imread( r"E:\Sanath\whatsapp_det-20200904T181330Z-001\whatsapp_det\rubik\blue.jpg") greenc = cv2.imread( r"E:\Sanath\whatsapp_det-20200904T181330Z-001\whatsapp_det\rubik\green.jpg" ) whitec = cv2.imread( r"E:\Sanath\whatsapp_det-20200904T181330Z-001\whatsapp_det\rubik\white.jpg"
from ppadb.client import Client import os import time os.system('adb start-server') adb = Client(host='localhost', port=5037) devices = adb.devices() if len(devices) == 0: print( "No devices found") device = devices[0] def findandtap(device): try: k = device.shell('uiautomator dump /dev/tty') count = k.count('inline_retweet') for i in range(count): i = k.index('inline_retweet')+277 k=k[i:] s = k[:k.index(']')] x,y = s.split(',') print(x,y) tap(device,x,y) tap(device,163,2095) except Exception as e:
#################### # IMPORTS #################### from ppadb.client import Client import numpy as np import TextPositions #################### # SETTING UP #################### adb = Client(host='127.0.0.1', port=5037) devices = adb.devices() device = devices[0] #################### # MAIN #################### def PrintText(text,start_x,start_y,font_size=80): x_off = 0 y_off = 0 for c in range(len(text)): if x_off + (TextPositions.text_positions[text[c]]['Size'][0]*font_size) > 800: x_off = 0 y_off += (1*font_size) for elm in TextPositions.text_positions[text[c]]["Vectors"]: for i in range(len(elm)): x1 = start_x + (elm[i-1][0]*font_size) + x_off y1 = start_y - (elm[i-1][1]*font_size) + y_off x2 = start_x + (elm[i ][0]*font_size) + x_off y2 = start_y - (elm[i ][1]*font_size) + y_off dist = numpy.linalg.norm(np.array([x1,y1]) - np.array([x2,y2]))
def __init__(self, host, port): self._client = Client(host, port)