Skip to content

Commit

Permalink
Merge pull request #680 from AirtestProject/dev
Browse files Browse the repository at this point in the history
1.1.3 Android10支持增强,更新yosemite.apk,重构了touch的底层逻辑
  • Loading branch information
yimelia authored Jan 21, 2020
2 parents 41a1789 + 7688e57 commit 081c023
Show file tree
Hide file tree
Showing 41 changed files with 720 additions and 7,760 deletions.
4 changes: 2 additions & 2 deletions airtest/core/android/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,8 @@ def file_size(self, filepath):
Returns:
The file size
"""
out = self.shell(["ls", "-l", filepath])
file_size = int(out.split()[3])
out = self.shell(["stat", "-c", "%s", filepath])
file_size = int(out)
return file_size

def _cleanup_forwards(self):
Expand Down
27 changes: 22 additions & 5 deletions airtest/core/android/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from airtest.core.android.adb import ADB
from airtest.core.android.minicap import Minicap
from airtest.core.android.minitouch import Minitouch
from airtest.core.android.maxtouch import Maxtouch
from airtest.core.android.javacap import Javacap
from airtest.core.android.rotation import RotationWatcher, XYTransformer
from airtest.core.android.recorder import Recorder
Expand Down Expand Up @@ -42,16 +43,17 @@ def __init__(self, serialno=None, host=None,
self.adb = ADB(self.serialno, server_addr=host, display_id=self.display_id, input_event=self.input_event)
self.adb.wait_for_device()
self.sdk_version = self.adb.sdk_version
# Android10 temporary solution, using adbtouch instead of minitouch
if self.sdk_version >= SDK_VERISON_ANDROID10 and self.touch_method != TOUCH_METHOD.ADBTOUCH:
self.touch_method = TOUCH_METHOD.ADBTOUCH
if self.sdk_version >= SDK_VERISON_ANDROID10 and self.touch_method == TOUCH_METHOD.MINITOUCH:
self.touch_method = TOUCH_METHOD.MAXTOUCH
self._display_info = {}
self._current_orientation = None
# init components
self.rotation_watcher = RotationWatcher(self.adb)
self.minicap = Minicap(self.adb, ori_function=self.get_display_info, display_id=self.display_id)
self.javacap = Javacap(self.adb)
self.minitouch = Minitouch(self.adb, ori_function=self.get_display_info,input_event=self.input_event)
self.minitouch = Minitouch(self.adb, ori_function=self.get_display_info, input_event=self.input_event)
self.maxtouch = Maxtouch(self.adb, ori_function=self.get_display_info)

self.yosemite_ime = YosemiteIme(self.adb)
self.recorder = Recorder(self.adb)
self._register_rotation_watcher()
Expand Down Expand Up @@ -355,6 +357,9 @@ def touch(self, pos, duration=0.01):
if self.touch_method == TOUCH_METHOD.MINITOUCH:
pos = self._touch_point_by_orientation(pos)
self.minitouch.touch(pos, duration=duration)
elif self.touch_method == TOUCH_METHOD.MAXTOUCH:
pos = self._touch_point_by_orientation(pos)
self.maxtouch.touch(pos, duration=duration)
else:
self.adb.touch(pos)

Expand Down Expand Up @@ -387,6 +392,15 @@ def swipe(self, p1, p2, duration=0.5, steps=5, fingers=1):
self.minitouch.two_finger_swipe(p1, p2, duration=duration, steps=steps)
else:
raise Exception("param fingers should be 1 or 2")
elif self.touch_method == TOUCH_METHOD.MAXTOUCH:
p1 = self._touch_point_by_orientation(p1)
p2 = self._touch_point_by_orientation(p2)
if fingers == 1:
self.maxtouch.swipe(p1, p2, duration=duration, steps=steps)
elif fingers == 2:
self.maxtouch.two_finger_swipe(p1, p2, duration=duration, steps=steps)
else:
raise Exception("param fingers should be 1 or 2")
else:
duration *= 1000 # adb的swipe操作时间是以毫秒为单位的。
self.adb.swipe(p1, p2, duration=duration)
Expand All @@ -403,7 +417,10 @@ def pinch(self, *args, **kwargs):
None
"""
return self.minitouch.pinch(*args, **kwargs)
if self.touch_method == TOUCH_METHOD.MAXTOUCH:
return self.maxtouch.pinch(*args, **kwargs)
else:
return self.minitouch.pinch(*args, **kwargs)

def logcat(self, *args, **kwargs):
"""
Expand Down
Loading

0 comments on commit 081c023

Please sign in to comment.