From 2e5284a26b02180d88906b9dd33f3e2da99f7a37 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Wed, 23 Jun 2021 15:41:04 -0700 Subject: [PATCH] Do not list Android or iOS devices when feature disabled (#85145) --- .../lib/src/android/android_workflow.dart | 8 ++- .../lib/src/ios/ios_workflow.dart | 4 +- .../android/android_workflow_test.dart | 52 +++++++++++++++++++ .../general.shard/ios/ios_workflow_test.dart | 18 ++++++- 4 files changed, 73 insertions(+), 9 deletions(-) diff --git a/packages/flutter_tools/lib/src/android/android_workflow.dart b/packages/flutter_tools/lib/src/android/android_workflow.dart index 6499bc20078..dc970c8cf33 100644 --- a/packages/flutter_tools/lib/src/android/android_workflow.dart +++ b/packages/flutter_tools/lib/src/android/android_workflow.dart @@ -57,18 +57,16 @@ class AndroidWorkflow implements Workflow { && _operatingSystemUtils.hostPlatform != HostPlatform.linux_arm64; @override - bool get canListDevices => _androidSdk != null + bool get canListDevices => appliesToHostPlatform && _androidSdk != null && _androidSdk?.adbPath != null; @override - bool get canLaunchDevices => _androidSdk != null + bool get canLaunchDevices => appliesToHostPlatform && _androidSdk != null && _androidSdk?.adbPath != null && _androidSdk?.validateSdkWellFormed().isEmpty == true; @override - bool get canListEmulators => _androidSdk != null - && _androidSdk?.adbPath != null - && _androidSdk?.emulatorPath != null; + bool get canListEmulators => canListDevices && _androidSdk?.emulatorPath != null; } /// A validator that checks if the Android SDK and Java SDK are available and diff --git a/packages/flutter_tools/lib/src/ios/ios_workflow.dart b/packages/flutter_tools/lib/src/ios/ios_workflow.dart index 44297241312..a8d8f032cb6 100644 --- a/packages/flutter_tools/lib/src/ios/ios_workflow.dart +++ b/packages/flutter_tools/lib/src/ios/ios_workflow.dart @@ -25,12 +25,12 @@ class IOSWorkflow implements Workflow { // We need xcode (+simctl) to list simulator devices, and libimobiledevice to list real devices. @override - bool get canListDevices => _xcode.isInstalledAndMeetsVersionCheck && _xcode.isSimctlInstalled; + bool get canListDevices => appliesToHostPlatform && _xcode.isInstalledAndMeetsVersionCheck && _xcode.isSimctlInstalled; // We need xcode to launch simulator devices, and ios-deploy // for real devices. @override - bool get canLaunchDevices => _xcode.isInstalledAndMeetsVersionCheck; + bool get canLaunchDevices => appliesToHostPlatform && _xcode.isInstalledAndMeetsVersionCheck; @override bool get canListEmulators => false; diff --git a/packages/flutter_tools/test/general.shard/android/android_workflow_test.dart b/packages/flutter_tools/test/general.shard/android/android_workflow_test.dart index 6f0ad4a010b..ae30c28b63e 100644 --- a/packages/flutter_tools/test/general.shard/android/android_workflow_test.dart +++ b/packages/flutter_tools/test/general.shard/android/android_workflow_test.dart @@ -73,6 +73,55 @@ void main() { ); expect(androidWorkflow.appliesToHostPlatform, false); + expect(androidWorkflow.canLaunchDevices, false); + expect(androidWorkflow.canListDevices, false); + expect(androidWorkflow.canListEmulators, false); + }); + + testWithoutContext('AndroidWorkflow is disabled if feature is disabled', () { + final FakeAndroidSdk androidSdk = FakeAndroidSdk(); + androidSdk.adbPath = 'path/to/adb'; + final AndroidWorkflow androidWorkflow = AndroidWorkflow( + featureFlags: TestFeatureFlags(isAndroidEnabled: false), + androidSdk: androidSdk, + operatingSystemUtils: FakeOperatingSystemUtils(), + ); + + expect(androidWorkflow.appliesToHostPlatform, false); + expect(androidWorkflow.canLaunchDevices, false); + expect(androidWorkflow.canListDevices, false); + expect(androidWorkflow.canListEmulators, false); + }); + + testWithoutContext('AndroidWorkflow cannot list emulators if emulatorPath is null', () { + final FakeAndroidSdk androidSdk = FakeAndroidSdk(); + androidSdk.adbPath = 'path/to/adb'; + final AndroidWorkflow androidWorkflow = AndroidWorkflow( + featureFlags: TestFeatureFlags(), + androidSdk: androidSdk, + operatingSystemUtils: FakeOperatingSystemUtils(), + ); + + expect(androidWorkflow.appliesToHostPlatform, true); + expect(androidWorkflow.canLaunchDevices, true); + expect(androidWorkflow.canListDevices, true); + expect(androidWorkflow.canListEmulators, false); + }); + + testWithoutContext('AndroidWorkflow can list emulators', () { + final FakeAndroidSdk androidSdk = FakeAndroidSdk(); + androidSdk.adbPath = 'path/to/adb'; + androidSdk.emulatorPath = 'path/to/emulator'; + final AndroidWorkflow androidWorkflow = AndroidWorkflow( + featureFlags: TestFeatureFlags(), + androidSdk: androidSdk, + operatingSystemUtils: FakeOperatingSystemUtils(), + ); + + expect(androidWorkflow.appliesToHostPlatform, true); + expect(androidWorkflow.canLaunchDevices, true); + expect(androidWorkflow.canListDevices, true); + expect(androidWorkflow.canListEmulators, true); }); testWithoutContext('licensesAccepted returns LicensesAccepted.unknown if cannot find sdkmanager', () async { @@ -496,6 +545,9 @@ class FakeAndroidSdk extends Fake implements AndroidSdk { @override AndroidSdkVersion latestVersion; + @override + String emulatorPath; + @override List validateSdkWellFormed() => []; diff --git a/packages/flutter_tools/test/general.shard/ios/ios_workflow_test.dart b/packages/flutter_tools/test/general.shard/ios/ios_workflow_test.dart index 91622e51a3e..0ef988a3080 100644 --- a/packages/flutter_tools/test/general.shard/ios/ios_workflow_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/ios_workflow_test.dart @@ -21,6 +21,8 @@ void main() { ); expect(iosWorkflow.appliesToHostPlatform, false); + expect(iosWorkflow.canLaunchDevices, false); + expect(iosWorkflow.canListDevices, false); }); testWithoutContext('iOS workflow is disabled on Linux', () { @@ -31,6 +33,8 @@ void main() { ); expect(iosWorkflow.appliesToHostPlatform, false); + expect(iosWorkflow.canLaunchDevices, false); + expect(iosWorkflow.canListDevices, false); }); testWithoutContext('iOS workflow is disabled on windows', () { @@ -41,16 +45,25 @@ void main() { ); expect(iosWorkflow.appliesToHostPlatform, false); + expect(iosWorkflow.canLaunchDevices, false); + expect(iosWorkflow.canListDevices, false); }); - testWithoutContext('iOS workflow is enabled on macOS', () { + testWithoutContext('iOS workflow applies on macOS, no Xcode', () { final IOSWorkflow iosWorkflow = IOSWorkflow( platform: FakePlatform(operatingSystem: 'macos'), - xcode: Xcode.test(processManager: FakeProcessManager.any()), + xcode: Xcode.test(processManager: FakeProcessManager.any(), + xcodeProjectInterpreter: XcodeProjectInterpreter.test( + processManager: FakeProcessManager.any(), + version: null, + ), + ), featureFlags: TestFeatureFlags(isIOSEnabled: true), ); expect(iosWorkflow.appliesToHostPlatform, true); + expect(iosWorkflow.canLaunchDevices, false); + expect(iosWorkflow.canListDevices, false); expect(iosWorkflow.canListEmulators, false); }); @@ -74,5 +87,6 @@ void main() { expect(xcode.isSimctlInstalled, true); expect(iosWorkflow.canLaunchDevices, true); expect(iosWorkflow.canListDevices, true); + expect(iosWorkflow.canListEmulators, false); }); }