This commit is contained in:
wangzz
2024-12-29 18:31:52 +08:00
commit c6cfb31d69
7 changed files with 400 additions and 0 deletions

90
script/devices.py Normal file
View File

@@ -0,0 +1,90 @@
import adb
import random
class _Action:
def __init__(self, id, scr_w, scr_h):
self.id = id
self.scr_w = scr_w
self.scr_h = scr_h
self.operator = adb.Operator(self.id)
# 唤醒
def wakeup(self):
pass
# 解锁
def unlock(self):
pass
# 锁屏
def lock(self):
self.operator.home()
self.operator.power()
# 返回
def back(self):
self.operator.back()
# 划动
def swipe(self, x1, y1, x2, y2, time):
self.operator.swipe(x1, y1, x2, y2, time)
# 上滑
def swipe_up(self, dist, speed):
x1 = int(self.scr_w * 0.25) + int(random.uniform(-10, 10))
x2 = x1 + int(random.uniform(-10, 10))
y1 = int(self.scr_w * 0.7) + int(random.uniform(-10, 10))
y2 = y1 - dist + int(random.uniform(-10, 10))
time = speed - int(random.uniform(-10, 10))
self.operator.swipe(x1, y1, x2, y2, time)
# 下滑
def swipe_down(self, dist, speed):
x1 = int(self.scr_w * 0.75) + int(random.uniform(-10, 10))
x2 = x1 + int(random.uniform(-10, 10))
y1 = int(self.scr_w * 0.5) + int(random.uniform(-10, 10))
y2 = y1 + dist + int(random.uniform(-10, 10))
time = speed + int(random.uniform(-10, 10))
self.operator.swipe(x1, y1, x2, y2, time)
# 左滑
def swipe_left(self, dist, speed):
x1 = int(self.scr_w * 0.7) + int(random.uniform(-10, 10))
x2 = x1 - dist + int(random.uniform(-10, 10))
y1 = int(self.scr_w * 0.75) + int(random.uniform(-10, 10))
y2 = y1 + int(random.uniform(-10, 10))
time = speed + int(random.uniform(-10, 10))
self.operator.swipe(x1, y1, x2, y2, time)
# 右滑
def swipe_right(self, dist, speed):
x1 = int(self.scr_w * 0.25) + int(random.uniform(-10, 10))
x2 = x1 + dist + int(random.uniform(-10, 10))
y1 = int(self.scr_w * 0.75) + int(random.uniform(-10, 10))
y2 = y1 + int(random.uniform(-10, 10))
time = speed + int(random.uniform(-10, 10))
self.operator.swipe(x1, y1, x2, y2, time)
# 点击
def click(self, point):
self.operator.touch(point.x, point.y)
class _Device(_Action):
def __init__(self, id, scr_w, scr_h):
super().__init__(id, scr_w, scr_h)
self.id = id
self.scr_w = scr_w
self.scr_h = scr_h
self.apps = []
def screen_width(self):
return self.scr_w
def screen_height(self):
return self.scr_h
class WikoHi70m(_Device):
def __init__(self, id):
super().__init__(id, 900, 1600)