xpdc 0.1.1__py3-none-any.whl → 0.1.2__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.
xpdc/_base/device.py CHANGED
@@ -41,6 +41,10 @@ class DeviceBase(ABC):
41
41
  def launch_app(self, bundle: str, ability: str) -> str:
42
42
  pass
43
43
 
44
+ @abstractmethod
45
+ def stop_app(self, bundle: str) -> str:
46
+ pass
47
+
44
48
  @abstractmethod
45
49
  def type_text(self, text: str) -> str:
46
50
  pass
@@ -56,3 +60,19 @@ class DeviceBase(ABC):
56
60
  @abstractmethod
57
61
  def get_current_app(self) -> str:
58
62
  pass
63
+
64
+ @abstractmethod
65
+ def dump_bundles(self) -> str:
66
+ pass
67
+
68
+ @abstractmethod
69
+ def dump_bundle(self, bundle: str, *, shortcut: bool = False) -> str:
70
+ pass
71
+
72
+ @abstractmethod
73
+ def clean_cache(self, bundle: str) -> str:
74
+ pass
75
+
76
+ @abstractmethod
77
+ def clean_data(self, bundle: str) -> str:
78
+ pass
xpdc/adb/connection.py CHANGED
@@ -38,5 +38,5 @@ class ADBConnection(ConnectionBase):
38
38
 
39
39
  return devices
40
40
 
41
- def device(self, device_id: str = None) -> 'ADBDevice':
41
+ def device(self, device_id: str) -> 'ADBDevice':
42
42
  return ADBDevice(device_id=device_id, adb=self._adb)
xpdc/adb/device.py CHANGED
@@ -52,6 +52,9 @@ class ADBDevice(DeviceBase):
52
52
  def launch_app(self, bundle: str, ability: str = None) -> str:
53
53
  return self.shell(['monkey', '-p', bundle, '-c', 'android.intent.category.LAUNCHER', '1'])
54
54
 
55
+ def stop_app(self, bundle: str) -> str:
56
+ return self.shell(['am', 'force-stop', bundle])
57
+
55
58
  def type_text(self, text: str) -> str:
56
59
  encoded_text = base64.b64encode(text.encode('utf-8')).decode('utf-8')
57
60
 
@@ -84,13 +87,11 @@ class ADBDevice(DeviceBase):
84
87
  def screenshot(self, path: Path = None) -> Screenshot:
85
88
  path = path or Path(f'adb-{self.device_id}-{now_str()}.png')
86
89
 
90
+ cmd = [self._adb, '-s', self.device_id, 'shell', 'screencap', '-p']
91
+ logger.debug(f'Executing command: {cmd}')
92
+
87
93
  with open(path, 'wb') as f:
88
- subprocess.run( # noqa: S603
89
- [self._adb, '-s', self.device_id, 'shell', 'screencap', '-p'],
90
- stdout=f,
91
- check=True,
92
- timeout=30,
93
- )
94
+ subprocess.run(cmd, stdout=f, check=True, timeout=30) # noqa: S603
94
95
 
95
96
  return Screenshot(path)
96
97
 
@@ -104,3 +105,17 @@ class ADBDevice(DeviceBase):
104
105
  return m['bundle']
105
106
 
106
107
  return ''
108
+
109
+ def dump_bundles(self) -> str:
110
+ return self.shell(['pm', 'list', 'packages'])
111
+
112
+ def dump_bundle(self, bundle: str, *, shortcut: bool = False) -> str:
113
+ cmd = ['dumpsys', 'package', '--checkin', bundle] if shortcut else ['dumpsys', 'package', bundle]
114
+
115
+ return self.shell(cmd)
116
+
117
+ def clean_cache(self, bundle: str) -> str:
118
+ return self.shell(['pm', 'clear', '--cache-only', bundle])
119
+
120
+ def clean_data(self, bundle: str) -> str:
121
+ return self.shell(['pm', 'clear', bundle])
xpdc/hdc/connection.py CHANGED
@@ -31,7 +31,7 @@ class HDCConnection(ConnectionBase):
31
31
  devices = []
32
32
 
33
33
  for line in out.split('\n'):
34
- if not line.strip():
34
+ if not line.strip() or line.strip() == '[Empty]':
35
35
  continue
36
36
 
37
37
  devices.append(HDCDevice(device_id=line.split()[0], hdc=self._hdc))
xpdc/hdc/device.py CHANGED
@@ -47,6 +47,9 @@ class HDCDevice(DeviceBase):
47
47
  def launch_app(self, bundle: str, ability: str = 'EntryAbility') -> str:
48
48
  return self.shell(['aa', 'start', '-b', bundle, '-a', ability])
49
49
 
50
+ def stop_app(self, bundle: str) -> str:
51
+ return self.shell(['aa', 'force-stop', bundle])
52
+
50
53
  def type_text(self, text: str) -> str:
51
54
  return self.shell(['uitest', 'uiInput', 'text', text])
52
55
 
@@ -84,3 +87,19 @@ class HDCDevice(DeviceBase):
84
87
  current_bundle = None
85
88
 
86
89
  return foreground_bundle or ''
90
+
91
+ def dump_bundles(self) -> str:
92
+ return self.shell(['bm', 'dump', '-a'])
93
+
94
+ def dump_bundle(self, bundle: str, *, shortcut: bool = False) -> str:
95
+ cmd = ['bm', 'dump', '-n', bundle]
96
+ if shortcut:
97
+ cmd.append('-s')
98
+
99
+ return self.shell(cmd)
100
+
101
+ def clean_cache(self, bundle: str) -> str:
102
+ return self.shell(['bm', 'clean', '-c', '-n', bundle])
103
+
104
+ def clean_data(self, bundle: str) -> str:
105
+ return self.shell(['bm', 'clean', '-d', '-n', bundle])
xpdc/screenshot.py CHANGED
@@ -6,8 +6,7 @@ from PIL import Image
6
6
  from PIL.ImageFile import ImageFile
7
7
 
8
8
 
9
- # https://lanbaoshen.github.io/blog/2025/10/13/subclassing-of-pathlibpath/#solution
10
- class Screenshot(type(Path()), Path):
9
+ class Screenshot(Path):
11
10
  def __init__(self, *args):
12
11
  super().__init__(*args)
13
12
 
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: xpdc
3
+ Version: 0.1.2
4
+ Summary: XPDC (X-Platform Device Connector) is designed to bridge the gap between devices across multiple platforms (Android, HarmonyOS, iOS).
5
+ Author-email: lanbaoshen <lanbaoshen@icloud.com>
6
+ Requires-Python: >=3.12
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: loguru>=0.7.3
10
+ Requires-Dist: pillow>=12.1.0
11
+ Dynamic: license-file
12
+
13
+ <p align="center">
14
+ <img src="logo.png" alt="pyecharts logo" width=200 />
15
+ </p>
16
+
17
+ # Introduction
18
+
19
+ XPDC (X-Platform Device Connector) is designed to bridge the gap between devices across multiple platforms (Android, HarmonyOS, iOS).
20
+
21
+ It allows users to operate devices on different platforms with the same set of code.
22
+
23
+ **Before using XPDC, you need to install the corresponding debug environment separately for each platform's device.**
24
+
25
+ Android is `adb`, HarmonyOS is `hdc`
26
+
27
+ # Installation
28
+
29
+ ```shell
30
+ # Using uv
31
+ pip install uv
32
+ uv add xpdc
33
+
34
+ # Using pip
35
+ pip install xpdc
36
+ ```
37
+
38
+ # Quick Start
39
+
40
+ ## Install Dependencies
41
+
42
+ ```python
43
+ from xpdc import connection, DeviceType
44
+
45
+ # Specify connect device type
46
+ conn = connection(DeviceType.ADB)
47
+ # conn = connection(DeviceType.HDC)
48
+ # iOS will support it in the future.
49
+
50
+ conn.cmd(['devices'])
51
+
52
+ device = conn.devices[0]
53
+ # You can also specify the device by its device id
54
+ # device = conn.device(device_id='device_id')
55
+
56
+ device.tap(500, 500)
57
+ device.type_text(text='lanbaoshen')
58
+ device.screenshot()
59
+ device.cmd(cmd=['shell', 'ls'])
60
+ device.shell(cmd=['ls'])
61
+
62
+ # For Android devices, additionally install ADBKeyboard.apk and enable it to support Chinese input.
63
+ device.install_and_set_adb_keyboard()
64
+ ```
@@ -0,0 +1,18 @@
1
+ xpdc/__init__.py,sha256=n3sAVfyh4Zo9O4TA3hrrtWmq26hEUAV_6xjI_fs5O7Y,477
2
+ xpdc/screenshot.py,sha256=sZ6_zm2fAtz5hOngarv66VQsKuTop4pHuVOzDD7puEA,674
3
+ xpdc/utils.py,sha256=7qBcoxMRnvK5SvGeWK0fbVP1zhw53X0SNJwxNIcUUiQ,1635
4
+ xpdc/_base/__init__.py,sha256=PLNJFgzcMgKcgPLp1sg-D00DN51kq9PHbFpABER6k_E,114
5
+ xpdc/_base/connection.py,sha256=Ck-PN9GsvyI1UqjL53aiEhog0kKmxHOloe_uKmkb6Hk,375
6
+ xpdc/_base/device.py,sha256=lgnHDtoxz_SdARz1QVcuATNiBtPmqlvctCPBfbgunHQ,1676
7
+ xpdc/adb/__init__.py,sha256=8Jxa4VCB5y7wRQ7wFvF3Uri4xfKN_sjukLtWi1nLdoY,67
8
+ xpdc/adb/connection.py,sha256=Pj-REYcP7hCScHqnvbmPtYG73Uxd1q2zbDWtt0bI46Y,1196
9
+ xpdc/adb/device.py,sha256=aqOPPdoxD_Om6AJtseyN-EVh9FC3QQqSVjhWl5e9klo,4651
10
+ xpdc/hdc/__init__.py,sha256=06bkaAgl_nfc9rBS3h68BtAFx_jatEXnYQ4Xx4PLc-A,67
11
+ xpdc/hdc/connection.py,sha256=umrEUPJQZpoacprvjITdaPGinPXLx403s3F5IDQLPUA,1188
12
+ xpdc/hdc/device.py,sha256=IAdYqP7BJlMzjp4jy39CBn8-EdS0B3I-j2RG6nOFFHU,3757
13
+ xpdc/resource/__init__.py,sha256=-Le9f22S3-Y74Z2uZfuYE4rcja3F0bjWyzK_y1cB_aU,102
14
+ xpdc-0.1.2.dist-info/licenses/LICENSE,sha256=hYRaJ2ed2IMo9RmO96UxUSTt9iwL49leBY5kVtDymRo,1063
15
+ xpdc-0.1.2.dist-info/METADATA,sha256=ymDTkmglIFxNltIz8QHOeSxwQn8NxcCrFY-lwqAsCUg,1635
16
+ xpdc-0.1.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
17
+ xpdc-0.1.2.dist-info/top_level.txt,sha256=qL-jSSwHZ5jrk_TEAvaHIX5_ienD6wrJfsCZDZ86Ji4,5
18
+ xpdc-0.1.2.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: xpdc
3
- Version: 0.1.1
4
- Summary: XPDC (X-Platform Device Connector) is designed to bridge the gap between devices across multiple platforms (Android, HarmonyOS, iOS).
5
- Author-email: lanbaoshen <lanbaoshen@icloud.com>
6
- Requires-Python: >=3.11
7
- License-File: LICENSE
8
- Requires-Dist: loguru>=0.7.3
9
- Requires-Dist: pillow>=12.1.0
10
- Dynamic: license-file
@@ -1,18 +0,0 @@
1
- xpdc/__init__.py,sha256=n3sAVfyh4Zo9O4TA3hrrtWmq26hEUAV_6xjI_fs5O7Y,477
2
- xpdc/screenshot.py,sha256=5TMQkGwHMsZDD-dN1CxDnH4qu63sbKRMEa3Ri6QeuS8,772
3
- xpdc/utils.py,sha256=7qBcoxMRnvK5SvGeWK0fbVP1zhw53X0SNJwxNIcUUiQ,1635
4
- xpdc/_base/__init__.py,sha256=PLNJFgzcMgKcgPLp1sg-D00DN51kq9PHbFpABER6k_E,114
5
- xpdc/_base/connection.py,sha256=Ck-PN9GsvyI1UqjL53aiEhog0kKmxHOloe_uKmkb6Hk,375
6
- xpdc/_base/device.py,sha256=6GMNrVYcM7E2h-PK9nUEWerDbMA2VsMPS4nJuQHKiIg,1260
7
- xpdc/adb/__init__.py,sha256=8Jxa4VCB5y7wRQ7wFvF3Uri4xfKN_sjukLtWi1nLdoY,67
8
- xpdc/adb/connection.py,sha256=Foyy6QFStJu3CagdhJKUBHFJE4CCEL9PLAAwK6bdIH0,1203
9
- xpdc/adb/device.py,sha256=UrD-5s3pKRICr2yQQgnqurimp08kR0W1hDDCUhMDxbI,4044
10
- xpdc/hdc/__init__.py,sha256=06bkaAgl_nfc9rBS3h68BtAFx_jatEXnYQ4Xx4PLc-A,67
11
- xpdc/hdc/connection.py,sha256=6ME28WwXr__k3JzbcQrKEs9--O98Mj6Qy81T7JW0iSs,1159
12
- xpdc/hdc/device.py,sha256=YEK0RtSEGCHqyNd8BjF9ebjUCLeDA30XiLVDKsUKPPQ,3151
13
- xpdc/resource/__init__.py,sha256=-Le9f22S3-Y74Z2uZfuYE4rcja3F0bjWyzK_y1cB_aU,102
14
- xpdc-0.1.1.dist-info/licenses/LICENSE,sha256=hYRaJ2ed2IMo9RmO96UxUSTt9iwL49leBY5kVtDymRo,1063
15
- xpdc-0.1.1.dist-info/METADATA,sha256=mArjTuHmI6xV9lvI58h-0KR9SZs_nDfKfB31ZIP3MMY,367
16
- xpdc-0.1.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
17
- xpdc-0.1.1.dist-info/top_level.txt,sha256=qL-jSSwHZ5jrk_TEAvaHIX5_ienD6wrJfsCZDZ86Ji4,5
18
- xpdc-0.1.1.dist-info/RECORD,,
File without changes