Skip to content

Commit 08e3ed9

Browse files
[flutter_tools] prevent creation of android devices if adb is not located (flutter#65184)
More work to prevent current #2 crash issue on stable. If adb is not located do not list/create android devices.
1 parent 33c619c commit 08e3ed9

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

packages/flutter_tools/lib/src/android/android_workflow.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ class AndroidWorkflow implements Workflow {
5858
bool get appliesToHostPlatform => _featureFlags.isAndroidEnabled;
5959

6060
@override
61-
bool get canListDevices => _androidSdk != null && _androidSdk.adbPath != null;
61+
bool get canListDevices => _androidSdk != null
62+
&& _androidSdk.adbPath != null;
6263

6364
@override
64-
bool get canLaunchDevices => _androidSdk != null && _androidSdk.validateSdkWellFormed().isEmpty;
65+
bool get canLaunchDevices => _androidSdk != null
66+
&& _androidSdk.adbPath != null
67+
&& _androidSdk.validateSdkWellFormed().isEmpty;
6568

6669
@override
67-
bool get canListEmulators => _androidSdk != null && _androidSdk.emulatorPath != null;
70+
bool get canListEmulators => _androidSdk != null
71+
&& _androidSdk.adbPath != null
72+
&& _androidSdk.emulatorPath != null;
6873
}
6974

7075
class AndroidValidator extends DoctorValidator {

packages/flutter_tools/test/general.shard/android/android_workflow_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ void main() {
6868
expect(androidWorkflow.canListEmulators, false);
6969
});
7070

71+
testWithoutContext('AndroidWorkflow handles a null adb', () {
72+
final MockAndroidSdk androidSdk = MockAndroidSdk();
73+
when(androidSdk.adbPath).thenReturn(null);
74+
final AndroidWorkflow androidWorkflow = AndroidWorkflow(
75+
featureFlags: TestFeatureFlags(),
76+
androidSdk: androidSdk,
77+
);
78+
79+
expect(androidWorkflow.canLaunchDevices, false);
80+
expect(androidWorkflow.canListDevices, false);
81+
expect(androidWorkflow.canListEmulators, false);
82+
});
83+
84+
7185
testUsingContext('licensesAccepted returns LicensesAccepted.unknown if cannot find sdkmanager', () async {
7286
processManager.canRunSucceeds = false;
7387
when(sdk.sdkManagerPath).thenReturn('/foo/bar/sdkmanager');

packages/flutter_tools/test/general.shard/emulator_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void main() {
5858
when(mockSdk.avdManagerPath).thenReturn('avdmanager');
5959
when(mockSdk.getAvdManagerPath()).thenReturn('avdmanager');
6060
when(mockSdk.emulatorPath).thenReturn('emulator');
61+
when(mockSdk.adbPath).thenReturn('adb');
6162
});
6263

6364
group('EmulatorManager', () {

0 commit comments

Comments
 (0)