|
14 | 14 | import warnings |
15 | 15 | import builtins |
16 | 16 | import logging |
17 | | -import atexit |
18 | 17 | import grpc |
19 | 18 |
|
20 | 19 | from urllib.parse import quote |
21 | 20 | from collections import defaultdict |
22 | 21 | from os.path import basename, dirname, expanduser, join as joinpath |
| 22 | +from google.protobuf.json_format import MessageToDict, MessageToJson |
23 | 23 | from grpc_interceptor import ClientInterceptor |
24 | | -from google.protobuf.json_format import MessageToDict |
25 | 24 | from google.protobuf.message import Message |
26 | 25 | from asn1crypto import pem, x509 |
27 | 26 |
|
|
71 | 70 | "Point", |
72 | 71 | "Bound", |
73 | 72 | "load_proto", |
| 73 | + "to_dict", |
74 | 74 | "Device", |
75 | 75 | "logger", |
76 | 76 | ] |
@@ -219,6 +219,11 @@ def load_proto(name): |
219 | 219 | return grpc.protos_and_services(name) |
220 | 220 |
|
221 | 221 |
|
| 222 | +def to_dict(prot): |
| 223 | + r = MessageToJson(prot, preserving_proto_field_name=True) |
| 224 | + return json.loads(r) |
| 225 | + |
| 226 | + |
222 | 227 | class BaseServiceStub(object): |
223 | 228 | def __init__(self, stub): |
224 | 229 | self.stub = stub |
@@ -868,7 +873,7 @@ def query_launch_activity(self): |
868 | 873 | """ |
869 | 874 | req = protos.ApplicationRequest(name=self.applicationId) |
870 | 875 | r = self.stub.queryLaunchActivity(req) |
871 | | - return r |
| 876 | + return to_dict(r) |
872 | 877 | def is_permission_granted(self, permission): |
873 | 878 | """ |
874 | 879 | 检查是否已经授予应用某权限(应用需要运行时获取的权限) |
@@ -984,6 +989,13 @@ def enumerate_all_pkg_names(self): |
984 | 989 | """ |
985 | 990 | r = self.stub.enumerateAllPkgNames(protos.Empty()) |
986 | 991 | return r.names |
| 992 | + def get_last_activities(self, count=3): |
| 993 | + """ |
| 994 | + 获取系统中最后一个活动的详细信息 |
| 995 | + """ |
| 996 | + req = protos.Integer(value=count) |
| 997 | + r = self.stub.getLastActivities(req).activities |
| 998 | + return list(map(to_dict, r)) |
987 | 999 | def start_activity(self, **activity): |
988 | 1000 | """ |
989 | 1001 | 启动 activity(任意, always return true) |
@@ -1637,6 +1649,8 @@ def enumerate_all_pkg_names(self): |
1637 | 1649 | return self.stub("Application").enumerate_all_pkg_names() |
1638 | 1650 | def enumerate_running_processes(self): |
1639 | 1651 | return self.stub("Application").enumerate_running_processes() |
| 1652 | + def get_last_activities(self, count=3): |
| 1653 | + return self.stub("Application").get_last_activities(count=count) |
1640 | 1654 | def start_activity(self, **activity): |
1641 | 1655 | return self.stub("Application").start_activity(**activity) |
1642 | 1656 | def application(self, applicationId): |
@@ -1807,7 +1821,8 @@ def __exit__(self, type, value, traceback): |
1807 | 1821 | help="service ip address") |
1808 | 1822 | parser.add_argument("-port", type=int, default=65000, |
1809 | 1823 | help="service port") |
1810 | | - parser.add_argument("-cert", type=str, default=None, |
| 1824 | + crt = os.environ.get("CERTIFICATE", None) |
| 1825 | + parser.add_argument("-cert", type=str, default=crt, |
1811 | 1826 | help="ssl cert") |
1812 | 1827 | args = parser.parse_args() |
1813 | 1828 |
|
|
0 commit comments