From 7f8f85443d5be239d813d0ec55ee8a39ce87a759 Mon Sep 17 00:00:00 2001 From: Ayush Sharma <47772616+ayush5harma@users.noreply.github.com> Date: Tue, 15 Oct 2024 22:59:55 +0300 Subject: [PATCH 1/3] accessibiltiyaudit: fix `AXAuditElement_v1.identifier` implementation --- pymobiledevice3/services/accessibilityaudit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymobiledevice3/services/accessibilityaudit.py b/pymobiledevice3/services/accessibilityaudit.py index 2cc9a01e..97330a9b 100644 --- a/pymobiledevice3/services/accessibilityaudit.py +++ b/pymobiledevice3/services/accessibilityaudit.py @@ -37,7 +37,7 @@ def __init__(self, fields): @property def identifier(self) -> bytes: - return self._fields['PlatformElementValue_v1'].NSdata + return self._fields['PlatformElementValue_v1'] def __repr__(self): return f'' From 1b57f4e5124bca64334bf8e1ac94dd3887db2358 Mon Sep 17 00:00:00 2001 From: Ayush Sharma <47772616+ayush5harma@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:00:35 +0300 Subject: [PATCH 2/3] accessibiltiyaudit: enrich `AXAuditInspectorFocus_v1` --- .../services/accessibilityaudit.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/pymobiledevice3/services/accessibilityaudit.py b/pymobiledevice3/services/accessibilityaudit.py index 97330a9b..32d5d4f7 100644 --- a/pymobiledevice3/services/accessibilityaudit.py +++ b/pymobiledevice3/services/accessibilityaudit.py @@ -23,10 +23,54 @@ def __init__(self, fields): def caption(self) -> str: return self._fields.get('CaptionTextValue_v1') + @property + def spoken_description(self) -> str: + return self._fields.get('SpokenDescriptionValue_v1') + @property def element(self) -> bytes: return self._fields.get('ElementValue_v1') + @property + def platform_identifier(self) -> str: + """Converts the element bytes to a hexadecimal string.""" + return self.element.identifier.hex().upper() + + @property + def estimated_uid(self) -> str: + """Generates a UID from the platform identifier.""" + hex_value = self.platform_identifier + + if len(hex_value) % 2 != 0: + raise ValueError("Hex value length must be even.") + + hex_bytes = bytes.fromhex(hex_value) + + if len(hex_bytes) < 16: + raise ValueError("Hex value must contain at least 16 bytes.") + + # Extract TimeLow bytes (indexes 12 to 15) + time_low_bytes = hex_bytes[12:16] + time_low = time_low_bytes.hex().upper() + + # Extract ClockSeq bytes (indexes 0 to 1) + clock_seq_bytes = hex_bytes[0:2] + clock_seq = clock_seq_bytes.hex().upper() + + # Construct UID with placeholder values for unused parts + uid = f"{time_low}-0000-0000-{clock_seq}-000000000000" + + return uid + + def to_dict(self) -> dict: + """Serializes the focus element into a dictionary.""" + return { + 'platform_identifier': self.platform_identifier, + 'estimated_uid': self.estimated_uid, + 'caption': self.caption, + 'spoken_description': self.spoken_description + } + def __str__(self): return f'' From d9e4218f1961da284eff1646372a925e92479d66 Mon Sep 17 00:00:00 2001 From: Ayush Sharma <47772616+ayush5harma@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:05:27 +0300 Subject: [PATCH 3/3] cli: accessibility: refactor output into an enriched json --- pymobiledevice3/cli/developer.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pymobiledevice3/cli/developer.py b/pymobiledevice3/cli/developer.py index 85ccad2b..d5ba2aca 100644 --- a/pymobiledevice3/cli/developer.py +++ b/pymobiledevice3/cli/developer.py @@ -860,7 +860,7 @@ def accessibility_notifications(service_provider: LockdownClient): @accessibility.command('list-items', cls=Command) def accessibility_list_items(service_provider: LockdownClient): - """ list items available in currently shown menu """ + """List items available in the currently shown menu.""" service = AccessibilityAudit(service_provider) iterator = service.iter_events() @@ -869,6 +869,7 @@ def accessibility_list_items(service_provider: LockdownClient): service.move_focus_next() first_item = None + items = [] for event in iterator: if event.name != 'hostInspectorCurrentElementChanged:': @@ -880,14 +881,13 @@ def accessibility_list_items(service_provider: LockdownClient): if first_item is None: first_item = current_item - else: - if first_item.caption == current_item.caption: - return + elif first_item.caption == current_item.caption: + return # Break if we encounter the first item again (loop) - print(f'{current_item.caption}: {current_item.element.identifier}') + items.append(current_item.to_dict()) + print_json(items) service.move_focus_next() - @developer.group('condition') def condition(): """ Force a predefined condition """