mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] check if process manager can find adb (#74672)
This commit is contained in:
parent
6358f481f7
commit
efcf2c664e
@ -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 {
|
|||||||
|
|
||||||
@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 {
|
|||||||
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() {
|
|||||||
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 {
|
|||||||
@override
|
@override
|
||||||
final String adbPath;
|
final String adbPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class FakeProcessManger extends Fake implements ProcessManager {
|
||||||
|
@override
|
||||||
|
bool canRun(dynamic executable, {String workingDirectory}) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user