Skip to content

Commit

Permalink
7.85 auto-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rev1si0n committed Dec 29, 2024
1 parent 0e90ab4 commit 85fbddc
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 87 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
7.85
* 支持 mDNS 广播服务
* 支持枚举选择器选中的所有元素
* 客户端添加自动重试机制
* 修复 Bound 比较逻辑错误
* 允许从远程加载证书

7.80
* 优化实时投屏流畅度
* 新增持久化 Hook 脚本支持
Expand Down
2 changes: 1 addition & 1 deletion lamda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# Distributed under MIT license.
# See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
__version__ = "7.80"
__version__ = "7.85"
95 changes: 89 additions & 6 deletions lamda/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@

sys.path.append(joinpath(dirname(__file__)))
sys.path.append(joinpath(dirname(__file__), "rpc"))
# use native resolver to support mDNS
os.environ["GRPC_DNS_RESOLVER"] = "native"

protos, services = grpc.protos_and_services("services.proto")
__all__ = [
Expand Down Expand Up @@ -179,6 +181,8 @@ def contain(a, b):
b.right <= a.right])

def equal(a, b):
if not isinstance(b, protos.Bound):
return False
return all([b.top == a.top,
b.left == a.left,
b.bottom == a.bottom,
Expand All @@ -194,6 +198,8 @@ def corner(b, position):
Direction = protos.Direction
GproxyType = protos.GproxyType
GrantType = protos.GrantType
ScriptRuntime = protos.ScriptRuntime
DataEncode = protos.DataEncode

Group = protos.Group
Key = protos.Key
Expand Down Expand Up @@ -256,8 +262,6 @@ def corner(b, position):
TouchSequence.__getitem__ = touchSequenceIndexer
TouchSequence.__iter__ = touchSequenceIter

DataEncode = protos.DataEncode
ScriptRuntime = protos.ScriptRuntime
HookRpcRequest = protos.HookRpcRequest
HookRpcResponse = protos.HookRpcResponse

Expand Down Expand Up @@ -385,13 +389,14 @@ def raise_remote_exception(self, res):


class ObjectUiAutomatorOpStub:
def __init__(self, stub, selector):
def __init__(self, caller, selector):
"""
UiAutomator 子接口,用来模拟出实例的意味
"""
self._selector = selector
self.selector = Selector(**selector)
self.stub = stub
self.stub = caller.stub
self.caller = caller
def __str__(self):
selector = ", ".join(["{}={}".format(k, v) \
for k, v in self._selector.items()])
Expand Down Expand Up @@ -494,6 +499,72 @@ def info_of_all_instances(self):
req = protos.SelectorOnlyRequest(selector=self.selector)
r = self.stub.selectorObjInfoOfAllInstances(req)
return r.objects
def all_instances(self):
"""
获取选择器选中的所有元素控件
"""
return list(self)
def _new_object(self, **kwargs):
selector = copy.deepcopy(self._selector)
selector.update(**kwargs)
instance = self.caller(**selector)
return instance
def text(self, txt):
return self._new_object(text=txt)
def resourceId(self, name):
return self._new_object(resourceId=name)
def description(self, desc):
return self._new_object(description=desc)
def packageName(self, name):
return self._new_object(packageName=name)
def className(self, name):
return self._new_object(className=name)
def textContains(self, needle):
return self._new_object(textContains=needle)
def descriptionContains(self, needle):
return self._new_object(descriptionContains=needle)
def textStartsWith(self, needle):
return self._new_object(textStartsWith=needle)
def descriptionStartsWith(self, needle):
return self._new_object(descriptionStartsWith=needle)
def textMatches(self, match):
return self._new_object(textMatches=match)
def descriptionMatches(self, match):
return self._new_object(descriptionMatches=match)
def resourceIdMatches(self, match):
return self._new_object(resourceIdMatches=match)
def packageNameMatches(self, match):
return self._new_object(packageNameMatches=match)
def classNameMatches(self, match):
return self._new_object(classNameMatches=match)
def checkable(self, value):
return self._new_object(checkable=value)
def clickable(self, value):
return self._new_object(clickable=value)
def focusable(self, value):
return self._new_object(focusable=value)
def scrollable(self, value):
return self._new_object(scrollable=value)
def longClickable(self, value):
return self._new_object(longClickable=value)
def enabled(self, value):
return self._new_object(enabled=value)
def checked(self, value):
return self._new_object(checked=value)
def focused(self, value):
return self._new_object(focused=value)
def selected(self, value):
return self._new_object(selected=value)
def index(self, idx):
return self._new_object(index=idx)
def instance(self, idx):
return self._new_object(instance=idx)
def __iter__(self):
"""
遍历所有符合选择器条件的元素实例
"""
yield from [self.instance(i) for i in \
range(self.count())]
def count(self):
"""
获取选择器选中控件的数量
Expand Down Expand Up @@ -962,7 +1033,7 @@ def wait_for_idle(self, timeout):
r = self.stub.waitForIdle(protos.Integer(value=timeout))
return r.value
def __call__(self, **kwargs):
return ObjectUiAutomatorOpStub(self.stub, kwargs)
return ObjectUiAutomatorOpStub(self, kwargs)


class AppScriptRpcInterface(object):
Expand Down Expand Up @@ -2042,6 +2113,14 @@ def __init__(self, host, port=65000,
session=None):
self.certificate = certificate
self.server = "{0}:{1}".format(host, port)
policy = dict()
policy["maxAttempts"] = 5
policy["retryableStatusCodes"] = ["UNAVAILABLE"]
policy["backoffMultiplier"] = 2
policy["initialBackoff"] = "0.5s"
policy["maxBackoff"] = "15s"
config = json.dumps(dict(methodConfig=[{"name": [{}],
"retryPolicy": policy,}]))
if certificate is not None:
with open(certificate, "rb") as fd:
key, crt, ca = self._parse_certdata(fd.read())
Expand All @@ -2051,10 +2130,14 @@ def __init__(self, host, port=65000,
self._chan = grpc.secure_channel(self.server, creds,
options=(("grpc.ssl_target_name_override",
self._parse_cname(crt)),
("grpc.service_config", config),
("grpc.enable_http_proxy",
0)))
else:
self._chan = grpc.insecure_channel(self.server)
self._chan = grpc.insecure_channel(self.server,
options=(("grpc.service_config", config),
("grpc.enable_http_proxy", 0))
)
session = session or uuid.uuid4().hex
interceptors = [ClientSessionMetadataInterceptor(session),
GrpcRemoteExceptionInterceptor(),
Expand Down
Loading

0 comments on commit 85fbddc

Please sign in to comment.