[flutter_tools] prevent creation of android devices if adb is not located (#65184)

More work to prevent current #2 crash issue on stable. If adb is not located do not list/create android devices.
This commit is contained in:
Jonah Williams
2020-09-03 11:01:43 -07:00
committed by GitHub
parent 33c619c9ac
commit 08e3ed9e2d
3 changed files with 23 additions and 3 deletions

View File

@@ -58,13 +58,18 @@ class AndroidWorkflow implements Workflow {
bool get appliesToHostPlatform => _featureFlags.isAndroidEnabled;
@override
bool get canListDevices => _androidSdk != null && _androidSdk.adbPath != null;
bool get canListDevices => _androidSdk != null
&& _androidSdk.adbPath != null;
@override
bool get canLaunchDevices => _androidSdk != null && _androidSdk.validateSdkWellFormed().isEmpty;
bool get canLaunchDevices => _androidSdk != null
&& _androidSdk.adbPath != null
&& _androidSdk.validateSdkWellFormed().isEmpty;
@override
bool get canListEmulators => _androidSdk != null && _androidSdk.emulatorPath != null;
bool get canListEmulators => _androidSdk != null
&& _androidSdk.adbPath != null
&& _androidSdk.emulatorPath != null;
}
class AndroidValidator extends DoctorValidator {

View File

@@ -68,6 +68,20 @@ void main() {
expect(androidWorkflow.canListEmulators, false);
});
testWithoutContext('AndroidWorkflow handles a null adb', () {
final MockAndroidSdk androidSdk = MockAndroidSdk();
when(androidSdk.adbPath).thenReturn(null);
final AndroidWorkflow androidWorkflow = AndroidWorkflow(
featureFlags: TestFeatureFlags(),
androidSdk: androidSdk,
);
expect(androidWorkflow.canLaunchDevices, false);
expect(androidWorkflow.canListDevices, false);
expect(androidWorkflow.canListEmulators, false);
});
testUsingContext('licensesAccepted returns LicensesAccepted.unknown if cannot find sdkmanager', () async {
processManager.canRunSucceeds = false;
when(sdk.sdkManagerPath).thenReturn('/foo/bar/sdkmanager');

View File

@@ -58,6 +58,7 @@ void main() {
when(mockSdk.avdManagerPath).thenReturn('avdmanager');
when(mockSdk.getAvdManagerPath()).thenReturn('avdmanager');
when(mockSdk.emulatorPath).thenReturn('emulator');
when(mockSdk.adbPath).thenReturn('adb');
});
group('EmulatorManager', () {