Skip to content

Commit

Permalink
Merge pull request #433 from paulproteus/simpler-rely-on-model
Browse files Browse the repository at this point in the history
Rely on Android device model, in device list
  • Loading branch information
freakboy3742 committed Jun 25, 2020
2 parents 2613b14 + 16cbb2f commit 00204f3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
3 changes: 3 additions & 0 deletions changes/433.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The device list returned by ``briefcase run android`` now uses the Android
device model name and unique ID e.g. a Pixel 3a shows up as ``Pixel 3a
(adbDeviceId)``.
16 changes: 8 additions & 8 deletions src/briefcase/integrations/android_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def devices(self):
details[key] = value

if parts[1] == "device":
name = details["device"]
name = details["model"].replace("_", " ")
authorized = True
elif parts[1] == "offline":
name = "Unknown device (offline)"
Expand Down Expand Up @@ -377,8 +377,8 @@ def select_target_device(self, device_or_avd):
if avd:
# It's a running emulator
running_avds[avd] = d
full_name = "@{avd} ({name} emulator)".format(
avd=avd, name=name,
full_name = "@{avd} (running emulator)".format(
avd=avd,
)
choices.append((d, full_name))

Expand All @@ -390,8 +390,9 @@ def select_target_device(self, device_or_avd):
device_choices["@" + avd] = full_name
else:
# It's a physical device (might be disabled)
choices.append((d, name))
device_choices[d] = name
full_name = "{name} ({d})".format(name=name, d=d)
choices.append((d, full_name))
device_choices[d] = full_name

# Add any non-running emulator AVDs to the list of candidate devices
for avd in self.emulators():
Expand Down Expand Up @@ -687,9 +688,8 @@ def start_emulator(self, avd):
if device_avd == avd:
# Found an active device that matches
# the AVD we are starting.
name = details["name"]
full_name = "@{avd} ({name} emulator)".format(
avd=avd, name=name,
full_name = "@{avd} (running emulator)".format(
avd=avd,
)
break
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/android_sdk/AndroidSDK/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_one_emulator(mock_sdk):

assert mock_sdk.devices() == {
'emulator-5554': {
'name': 'generic_x86',
'name': 'Android SDK built for x86',
'authorized': True,
},
}
Expand All @@ -42,11 +42,11 @@ def test_multiple_devices(mock_sdk):
'authorized': False,
},
'KABCDABCDA1513': {
'name': 'Kogan_Agora_9',
'name': 'Kogan Agora 9',
'authorized': True,
},
'emulator-5554': {
'name': 'generic_x86',
'name': 'Android SDK built for x86',
'authorized': True,
},
'emulator-5556': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def mock_sdk(tmp_path):
'authorized': False,
},
'KABCDABCDA1513': {
'name': 'Kogan_Agora_9',
'name': 'Kogan Agora 9',
'authorized': True,
},
'emulator-5554': {
'name': 'generic_x86',
'name': 'Android SDK built for x86',
'authorized': True,
},
})
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_explicit_device(mock_sdk):

# Physical running device, so no AVD
assert device == 'KABCDABCDA1513'
assert name == 'Kogan_Agora_9'
assert name == 'Kogan Agora 9 (KABCDABCDA1513)'
assert avd is None

# No input was requested
Expand All @@ -85,7 +85,7 @@ def test_explicit_running_emulator_by_id(mock_sdk):

# Emulator is running, so there is a device ID
assert device == 'emulator-5554'
assert name == '@runningEmulator (generic_x86 emulator)'
assert name == '@runningEmulator (running emulator)'
assert avd == "runningEmulator"

# No input was requested
Expand All @@ -100,7 +100,7 @@ def test_explicit_running_emulator_by_avd(mock_sdk):

# Emulator is running, so there is a device ID
assert device == 'emulator-5554'
assert name == '@runningEmulator (generic_x86 emulator)'
assert name == '@runningEmulator (running emulator)'
assert avd == "runningEmulator"

# No input was requested
Expand Down Expand Up @@ -147,14 +147,14 @@ def test_explicit_invalid_avd(mock_sdk):
def test_select_device(mock_sdk, capsys):
"If the user manually selects a physical device, details are returned"
# Mock the user input
mock_sdk.command.input.values = ["1"]
mock_sdk.command.input.values = ["2"]

# Run the selection with no pre-existing choice
device, name, avd = mock_sdk.select_target_device(None)

# Physical running device, so no AVD
assert device == 'KABCDABCDA1513'
assert name == 'Kogan_Agora_9'
assert name == 'Kogan Agora 9 (KABCDABCDA1513)'
assert avd is None

# The user was asked to select a device
Expand All @@ -168,7 +168,7 @@ def test_select_device(mock_sdk, capsys):
def test_select_unauthorized_device(mock_sdk):
"If the user manually selects an unauthorized running device, an error is raised"
# Mock the user input
mock_sdk.command.input.values = ['2']
mock_sdk.command.input.values = ['3']

# Run the selection with no pre-existing choice
with pytest.raises(AndroidDeviceNotAuthorized):
Expand All @@ -178,14 +178,14 @@ def test_select_unauthorized_device(mock_sdk):
def test_select_running_emulator(mock_sdk, capsys):
"If the user manually selects a running emulator, details are returned"
# Mock the user input
mock_sdk.command.input.values = ['3']
mock_sdk.command.input.values = ['1']

# Run the selection with no pre-existing choice
device, name, avd = mock_sdk.select_target_device(None)

# Emulator is running, so there is a device ID
assert device == 'emulator-5554'
assert name == '@runningEmulator (generic_x86 emulator)'
assert name == '@runningEmulator (running emulator)'
assert avd == "runningEmulator"

# A re-run prompt has been provided
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_input_disabled_one_device(mock_sdk):
# Set up a single device.
mock_sdk.devices = MagicMock(return_value={
'KABCDABCDA1513': {
'name': 'Kogan_Agora_9',
'name': 'Kogan Agora 9',
'authorized': True,
},
})
Expand All @@ -279,7 +279,7 @@ def test_input_disabled_one_device(mock_sdk):

# The only device is returned
assert device == 'KABCDABCDA1513'
assert name == "Kogan_Agora_9"
assert name == "Kogan Agora 9 (KABCDABCDA1513)"
assert avd is None

# No input was requested
Expand Down
16 changes: 8 additions & 8 deletions tests/integrations/android_sdk/AndroidSDK/test_start_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def test_start_emulator(mock_sdk):
'authorized': False,
},
'KABCDABCDA1513': {
'name': 'Kogan_Agora_9',
'name': 'Kogan Agora 9',
'authorized': True,
},
'emulator-5554': {
'name': 'generic_x86',
'name': 'Android SDK built for x86',
'authorized': True,
},
}
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_start_emulator(mock_sdk):

# The device details are as expected
assert device == 'emulator-5556'
assert name == '@idleEmulator (generic_x86 emulator)'
assert name == '@idleEmulator (running emulator)'

# The process was started.
mock_sdk.command.subprocess.Popen.assert_called_with(
Expand Down Expand Up @@ -141,11 +141,11 @@ def test_emulator_fail_to_start(mock_sdk):
'authorized': False,
},
'KABCDABCDA1513': {
'name': 'Kogan_Agora_9',
'name': 'Kogan Agora 9',
'authorized': True,
},
'emulator-5554': {
'name': 'generic_x86',
'name': 'Android SDK built for x86',
'authorized': True,
},
}
Expand Down Expand Up @@ -224,11 +224,11 @@ def test_emulator_fail_to_boot(mock_sdk):
'authorized': False,
},
'KABCDABCDA1513': {
'name': 'Kogan_Agora_9',
'name': 'Kogan Agora 9',
'authorized': True,
},
'emulator-5554': {
'name': 'generic_x86',
'name': 'Android SDK built for x86',
'authorized': True,
},
}
Expand All @@ -239,7 +239,7 @@ def test_emulator_fail_to_boot(mock_sdk):
}
devices_4 = devices.copy()
devices_4['emulator-5556'] = {
'name': 'generic_x86',
'name': 'Android SDK built for x86',
'authorized': True,
}

Expand Down

0 comments on commit 00204f3

Please sign in to comment.