Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions agent/lib/src/adb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ class Adb {
return results;
}

/// Kills and restarts the `adb` server.
///
/// Restarting `adb` helps with keeping device connections alive. When `adb`
/// runs non-stop for too long it loses connections to devices.
static Future restart() async {
int exitCode = await exec(config.adbPath, ['kill-server'], canFail: false);

if (exitCode != 0)
throw 'Failed to kill ADB server';

exitCode = await exec(config.adbPath, ['start-server'], canFail: false);

if (exitCode != 0)
throw 'Failed to start ADB server';
}

static Future<List<String>> get deviceIds async {
List<String> output = (await eval(config.adbPath, ['devices', '-l'], canFail: false))
.trim().split('\n');
Expand Down
4 changes: 4 additions & 0 deletions agent/lib/src/commands/ci.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class ContinuousIntegrationCommand extends Command {
_listenToShutdownSignals();
while(!_exiting) {
try {
// This increases the likelihood of obtaining a healthy connection to
// the device.
Adb.restart();

// Check health before requesting a new task.
health = await _performHealthChecks();

Expand Down