Skip to content

Commit

Permalink
Merge pull request #1629 from freakboy3742/macos-android-device-id
Browse files Browse the repository at this point in the history
Fix macOS android device parsing
  • Loading branch information
freakboy3742 committed Feb 3, 2024
2 parents 2618510 + 0054cc3 commit c119031
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions changes/1627.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The detection of physical Android devices on macOS was made more resilient.
10 changes: 7 additions & 3 deletions src/briefcase/integrations/android_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,12 @@ def devices(self) -> dict[str, dict[str, str | bool]]:

details = {}
for part in parts[2:]:
key, value = part.split(":")
details[key] = value
try:
key, value = part.split(":")
details[key] = value
except ValueError:
# Ignore any entry that isn't in "key:value" format.
pass

if parts[1] == "device":
try:
Expand All @@ -877,7 +881,7 @@ def devices(self) -> dict[str, dict[str, str | bool]]:
name = "Unknown device (offline)"
authorized = False
else:
name = "Unknown device (not authorized for development)"
name = f"Device not available for development ({' '.join(parts[1:])})"
authorized = False

devices[parts[0]] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
List of devices attached
200ABCDEFGHIJK no permissions (user russell is not in the plugdev group); see [http://developer.android.com/tools/device.html] usb:5-4.4.1 transport_id:1
300ABCDEFGHIJK no permissions (missing udev rules? user is in the plugdev group); see [http://developer.android.com/tools/device.html] usb:5-4.4.1 transport_id:1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
List of devices attached
200ABCDEFGHIJK device 231-1 product:panther model:Pixel_7 device:panther transport_id:1
46 changes: 45 additions & 1 deletion tests/integrations/android_sdk/AndroidSDK/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def test_multiple_devices(mock_tools, android_sdk):

assert android_sdk.devices() == {
"041234567892009a": {
"name": "Unknown device (not authorized for development)",
"name": (
"Device not available for development "
"(unauthorized usb:336675328X transport_id:2)"
),
"authorized": False,
},
"KABCDABCDA1513": {
Expand Down Expand Up @@ -81,3 +84,44 @@ def test_daemon_start(mock_tools, android_sdk):
mock_tools.subprocess.check_output.return_value = devices_result("daemon_start")

assert android_sdk.devices() == {}


def test_physical_device_macOS(mock_tools, android_sdk):
"""An extra piece of device detail is returned on macOS for physical devices."""
mock_tools.subprocess.check_output.return_value = devices_result(
"physical_device_macOS"
)

assert android_sdk.devices() == {
"200ABCDEFGHIJK": {
"authorized": True,
"name": "Pixel 7",
}
}


def test_device_permissions(mock_tools, android_sdk):
"""If AndroidSDK doesn't have access to the device, the error message can be
parsed."""
mock_tools.subprocess.check_output.return_value = devices_result("no_permissions")

assert android_sdk.devices() == {
"200ABCDEFGHIJK": {
"authorized": False,
"name": (
"Device not available for development (no permissions "
"(user russell is not in the plugdev group); "
"see [http://developer.android.com/tools/device.html] "
"usb:5-4.4.1 transport_id:1)"
),
},
"300ABCDEFGHIJK": {
"authorized": False,
"name": (
"Device not available for development (no permissions "
"(missing udev rules? user is in the plugdev group); "
"see [http://developer.android.com/tools/device.html] "
"usb:5-4.4.1 transport_id:1)"
),
},
}

0 comments on commit c119031

Please sign in to comment.