Unverified Commit efcf2c66 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] check if process manager can find adb (#74672)

parent 6358f481
...@@ -64,7 +64,7 @@ class AndroidDevices extends PollingDeviceDiscovery { ...@@ -64,7 +64,7 @@ class AndroidDevices extends PollingDeviceDiscovery {
@override @override
Future<List<Device>> pollingGetDevices({ Duration timeout }) async { Future<List<Device>> pollingGetDevices({ Duration timeout }) async {
if (_androidSdk == null || _androidSdk.adbPath == null) { if (_doesNotHaveAdb()) {
return <AndroidDevice>[]; return <AndroidDevice>[];
} }
String text; String text;
...@@ -88,7 +88,7 @@ class AndroidDevices extends PollingDeviceDiscovery { ...@@ -88,7 +88,7 @@ class AndroidDevices extends PollingDeviceDiscovery {
@override @override
Future<List<String>> getDiagnostics() async { Future<List<String>> getDiagnostics() async {
if (_androidSdk == null || _androidSdk.adbPath == null) { if (_doesNotHaveAdb()) {
return <String>[]; return <String>[];
} }
...@@ -104,6 +104,12 @@ class AndroidDevices extends PollingDeviceDiscovery { ...@@ -104,6 +104,12 @@ class AndroidDevices extends PollingDeviceDiscovery {
return diagnostics; return diagnostics;
} }
bool _doesNotHaveAdb() {
return _androidSdk == null ||
_androidSdk.adbPath == null ||
!_processManager.canRun(_androidSdk.adbPath);
}
// 015d172c98400a03 device usb:340787200X product:nakasi model:Nexus_7 device:grouper // 015d172c98400a03 device usb:340787200X product:nakasi model:Nexus_7 device:grouper
static final RegExp _kDeviceRegex = RegExp(r'^(\S+)\s+(\S+)(.*)'); static final RegExp _kDeviceRegex = RegExp(r'^(\S+)\s+(\S+)(.*)');
......
...@@ -44,6 +44,25 @@ void main() { ...@@ -44,6 +44,25 @@ void main() {
expect(await androidDevices.getDiagnostics(), isEmpty); expect(await androidDevices.getDiagnostics(), isEmpty);
}); });
testWithoutContext('AndroidDevices returns empty device list and diagnostics when adb cannot be run', () async {
final AndroidDevices androidDevices = AndroidDevices(
androidSdk: FakeAndroidSdk(null),
logger: BufferLogger.test(),
androidWorkflow: AndroidWorkflow(
androidSdk: FakeAndroidSdk('adb'),
featureFlags: TestFeatureFlags(),
),
// Will throw an exception if anything other than canRun is invoked
processManager: FakeProcessManger(),
fileSystem: MemoryFileSystem.test(),
platform: FakePlatform(),
userMessages: UserMessages(),
);
expect(await androidDevices.pollingGetDevices(), isEmpty);
expect(await androidDevices.getDiagnostics(), isEmpty);
});
testWithoutContext('AndroidDevices returns empty device list and diagnostics on null Android SDK', () async { testWithoutContext('AndroidDevices returns empty device list and diagnostics on null Android SDK', () async {
final AndroidDevices androidDevices = AndroidDevices( final AndroidDevices androidDevices = AndroidDevices(
androidSdk: null, androidSdk: null,
...@@ -218,3 +237,10 @@ class FakeAndroidSdk extends Fake implements AndroidSdk { ...@@ -218,3 +237,10 @@ class FakeAndroidSdk extends Fake implements AndroidSdk {
@override @override
final String adbPath; final String adbPath;
} }
class FakeProcessManger extends Fake implements ProcessManager {
@override
bool canRun(dynamic executable, {String workingDirectory}) {
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment