Skip to content

Commit

Permalink
Do not start logcat service when the Andriod device is in fastboot mo…
Browse files Browse the repository at this point in the history
…de. (#881)
  • Loading branch information
xpconanfan committed Apr 25, 2023
1 parent 791b49c commit 031aa94
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mobly/controllers/android_device_lib/services/logcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ def start(self):
The collection runs in a separate subprocess and saves logs in a file.
"""
if self._ad.is_bootloader:
self._ad.log.warning(
'Skip starting logcat because the device is in fastboot mode.')
return
self._assert_not_running()
if self._config.clear_log:
self.clear_adb_log()
Expand Down
17 changes: 17 additions & 0 deletions tests/mobly/controllers/android_device_lib/services/logcat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,23 @@ def test_start_and_stop(self, get_timestamp_mock, open_logcat_mock,
self.assertIsNone(logcat_service._adb_logcat_process)
self.assertEqual(logcat_service.adb_logcat_file_path, expected_log_path)

@mock.patch('mobly.controllers.android_device_lib.adb.AdbProxy',
return_value=mock_android_device.MockAdbProxy('1'))
@mock.patch('mobly.controllers.android_device_lib.fastboot.FastbootProxy',
return_value=mock_android_device.MockFastbootProxy('1'))
@mock.patch('mobly.utils.start_standing_subprocess')
@mock.patch('mobly.controllers.android_device.list_fastboot_devices',
return_value='1')
def test_start_in_fastboot_mode(self, _, start_proc_mock, FastbootProxy,
MockAdbProxy):
mock_serial = '1'
ad = android_device.AndroidDevice(serial=mock_serial)
logcat_service = logcat.Logcat(ad)
logcat_service.start()
# Verify start is not performed
self.assertFalse(logcat_service._adb_logcat_process)
start_proc_mock.assert_not_called()

@mock.patch('mobly.controllers.android_device_lib.adb.AdbProxy',
return_value=mock_android_device.MockAdbProxy('1'))
@mock.patch('mobly.controllers.android_device_lib.fastboot.FastbootProxy',
Expand Down
10 changes: 10 additions & 0 deletions tests/mobly/controllers/android_device_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,16 @@ def test_AndroidDevice_is_emulator_when_emulator_serial(
ad = android_device.AndroidDevice(serial='emulator-5554')
self.assertTrue(ad.is_emulator)

@mock.patch('mobly.controllers.android_device_lib.adb.AdbProxy',
return_value=mock_android_device.MockAdbProxy('1'))
@mock.patch('mobly.controllers.android_device_lib.fastboot.FastbootProxy',
return_value=mock_android_device.MockFastbootProxy('1'))
@mock.patch('mobly.controllers.android_device.list_fastboot_devices',
return_value='1')
def test_AndroidDevice_is_fastboot(self, _, MockFastboot, MockAdbProxy):
ad = android_device.AndroidDevice(serial='1')
self.assertTrue(ad.is_bootloader)

@mock.patch('mobly.controllers.android_device_lib.adb.AdbProxy',
return_value=mock_android_device.MockAdbProxy('1'))
@mock.patch('mobly.controllers.android_device_lib.fastboot.FastbootProxy',
Expand Down

0 comments on commit 031aa94

Please sign in to comment.