droidrun 0.3.2__py3-none-any.whl → 0.3.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
droidrun/portal.py CHANGED
@@ -2,8 +2,9 @@ import requests
2
2
  import tempfile
3
3
  import os
4
4
  import contextlib
5
- from droidrun.adb import Device, DeviceManager
6
- import asyncio
5
+ from adbutils import adb, AdbDevice
6
+ from droidrun.tools import AdbTools
7
+ from rich.console import Console
7
8
 
8
9
  REPO = "droidrun/droidrun-portal"
9
10
  ASSET_NAME = "droidrun-portal"
@@ -37,8 +38,10 @@ def get_latest_release_assets(debug: bool = False):
37
38
 
38
39
  @contextlib.contextmanager
39
40
  def download_portal_apk(debug: bool = False):
41
+ console = Console()
40
42
  assets = get_latest_release_assets(debug)
41
43
 
44
+ asset_version = None
42
45
  asset_url = None
43
46
  for asset in assets:
44
47
  if (
@@ -47,11 +50,15 @@ def download_portal_apk(debug: bool = False):
47
50
  and asset["name"].startswith(ASSET_NAME)
48
51
  ):
49
52
  asset_url = asset["browser_download_url"]
53
+ asset_version = asset["name"].split("-")[-1]
54
+ asset_version = asset_version.removesuffix(".apk")
50
55
  break
51
56
  elif "downloadUrl" in asset and os.path.basename(
52
57
  asset["downloadUrl"]
53
58
  ).startswith(ASSET_NAME):
54
59
  asset_url = asset["downloadUrl"]
60
+ asset_version: str = asset["name"].split("-")[-1]
61
+ asset_version = asset_version.removesuffix(".apk")
55
62
  break
56
63
  else:
57
64
  if debug:
@@ -60,6 +67,10 @@ def download_portal_apk(debug: bool = False):
60
67
  if not asset_url:
61
68
  raise Exception(f"Asset named '{ASSET_NAME}' not found in the latest release.")
62
69
 
70
+ console.print(f"Found Portal APK [bold]{asset_version}[/bold]")
71
+ if debug:
72
+ console.print(f"Asset URL: {asset_url}")
73
+
63
74
  tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".apk")
64
75
  try:
65
76
  r = requests.get(asset_url, stream=True)
@@ -74,23 +85,21 @@ def download_portal_apk(debug: bool = False):
74
85
  os.unlink(tmp.name)
75
86
 
76
87
 
77
- async def enable_portal_accessibility(device: Device):
78
- await device.shell(
88
+ def enable_portal_accessibility(device: AdbDevice):
89
+ device.shell(
79
90
  f"settings put secure enabled_accessibility_services {A11Y_SERVICE_NAME}"
80
91
  )
81
- await device.shell("settings put secure accessibility_enabled 1")
92
+ device.shell("settings put secure accessibility_enabled 1")
82
93
 
83
94
 
84
- async def check_portal_accessibility(device: Device, debug: bool = False) -> bool:
85
- a11y_services = await device.shell(
86
- "settings get secure enabled_accessibility_services"
87
- )
95
+ def check_portal_accessibility(device: AdbDevice, debug: bool = False) -> bool:
96
+ a11y_services = device.shell("settings get secure enabled_accessibility_services")
88
97
  if not A11Y_SERVICE_NAME in a11y_services:
89
98
  if debug:
90
99
  print(a11y_services)
91
100
  return False
92
101
 
93
- a11y_enabled = await device.shell("settings get secure accessibility_enabled")
102
+ a11y_enabled = device.shell("settings get secure accessibility_enabled")
94
103
  if a11y_enabled != "1":
95
104
  if debug:
96
105
  print(a11y_enabled)
@@ -99,12 +108,12 @@ async def check_portal_accessibility(device: Device, debug: bool = False) -> boo
99
108
  return True
100
109
 
101
110
 
102
- async def ping_portal(device: Device, debug: bool = False):
111
+ def ping_portal(device: AdbDevice, debug: bool = False):
103
112
  """
104
113
  Ping the Droidrun Portal to check if it is installed and accessible.
105
114
  """
106
115
  try:
107
- packages = await device.list_packages()
116
+ packages = device.list_packages()
108
117
  except Exception as e:
109
118
  raise Exception(f"Failed to list packages: {e}")
110
119
 
@@ -113,27 +122,33 @@ async def ping_portal(device: Device, debug: bool = False):
113
122
  print(packages)
114
123
  raise Exception("Portal is not installed on the device")
115
124
 
116
- if not await check_portal_accessibility(device, debug):
117
- await device.shell("am start -a android.settings.ACCESSIBILITY_SETTINGS")
125
+ if not check_portal_accessibility(device, debug):
126
+ device.shell("am start -a android.settings.ACCESSIBILITY_SETTINGS")
118
127
  raise Exception(
119
128
  "Droidrun Portal is not enabled as an accessibility service on the device"
120
129
  )
121
130
 
131
+
132
+ def ping_portal_content(device: AdbDevice, debug: bool = False):
122
133
  try:
123
- state = await device.shell(
124
- "content query --uri content://com.droidrun.portal/state"
125
- )
134
+ state = device.shell("content query --uri content://com.droidrun.portal/state")
126
135
  if not "Row: 0 result=" in state:
127
136
  raise Exception("Failed to get state from Droidrun Portal")
128
-
129
137
  except Exception as e:
130
138
  raise Exception(f"Droidrun Portal is not reachable: {e}")
131
139
 
132
140
 
133
- async def test():
134
- device = await DeviceManager().get_device()
135
- await ping_portal(device, debug=False)
141
+ def ping_portal_tcp(device: AdbDevice, debug: bool = False):
142
+ try:
143
+ tools = AdbTools(serial=device.serial, use_tcp=True)
144
+ except Exception as e:
145
+ raise Exception(f"Failed to setup TCP forwarding: {e}")
146
+
147
+
148
+ def test():
149
+ device = adb.device()
150
+ ping_portal(device, debug=False)
136
151
 
137
152
 
138
153
  if __name__ == "__main__":
139
- asyncio.run(test())
154
+ test()
@@ -17,7 +17,7 @@ class DroidAgentInitEvent(TelemetryEvent):
17
17
  reflection: bool
18
18
  enable_tracing: bool
19
19
  debug: bool
20
- save_trajectories: bool
20
+ save_trajectories: str
21
21
 
22
22
 
23
23
  class DroidAgentFinalizeEvent(TelemetryEvent):
@@ -45,6 +45,7 @@ print_telemetry_message()
45
45
  def get_user_id() -> str:
46
46
  try:
47
47
  if not USER_ID_PATH.exists():
48
+ USER_ID_PATH.parent.mkdir(parents=True, exist_ok=True)
48
49
  USER_ID_PATH.touch()
49
50
  USER_ID_PATH.write_text(str(uuid4()))
50
51
  logger.debug(f"User ID: {USER_ID_PATH.read_text()}")
@@ -54,7 +55,7 @@ def get_user_id() -> str:
54
55
  return "unknown"
55
56
 
56
57
 
57
- def capture(event: TelemetryEvent):
58
+ def capture(event: TelemetryEvent, user_id: str | None = None):
58
59
  try:
59
60
  if not is_telemetry_enabled():
60
61
  logger.debug(f"Telemetry disabled, skipping capture of {event}")
@@ -66,7 +67,7 @@ def capture(event: TelemetryEvent):
66
67
  **event_data,
67
68
  }
68
69
 
69
- posthog.capture(event_name, distinct_id=get_user_id(), properties=properties)
70
+ posthog.capture(event_name, distinct_id=user_id or get_user_id(), properties=properties)
70
71
  logger.debug(f"Captured event: {event_name} with properties: {event}")
71
72
  except Exception as e:
72
73
  logger.error(f"Error capturing event: {e}")