diff --git a/packages/flutter_tools/lib/src/http_host_validator.dart b/packages/flutter_tools/lib/src/http_host_validator.dart index 76b748a871..1cde82bbaf 100644 --- a/packages/flutter_tools/lib/src/http_host_validator.dart +++ b/packages/flutter_tools/lib/src/http_host_validator.dart @@ -18,16 +18,21 @@ const String kDoctorHostTimeout = 'FLUTTER_DOCTOR_HOST_TIMEOUT'; const String kPubDevHttpHost = 'https://pub.dev/'; const String kgCloudHttpHost = 'https://cloud.google.com/'; -/// Android specific required HTTP hosts. -const List androidRequiredHttpHosts = [ - 'https://maven.google.com/', -]; - /// MacOS specific required HTTP hosts. const List macOSRequiredHttpHosts = [ 'https://cocoapods.org/', ]; +/// Android specific required HTTP hosts. +List androidRequiredHttpHosts(Platform platform) { + return [ + // If kEnvCloudUrl is set, it will be used as the maven host + if (!platform.environment.containsKey(kEnvCloudUrl)) + 'https://maven.google.com/', + ]; +} + + // Validator that checks all provided hosts are reachable and responsive class HttpHostValidator extends DoctorValidator { HttpHostValidator( @@ -49,7 +54,7 @@ class HttpHostValidator extends DoctorValidator { List get _requiredHosts => [ if (_featureFlags.isMacOSEnabled) ...macOSRequiredHttpHosts, - if (_featureFlags.isAndroidEnabled) ...androidRequiredHttpHosts, + if (_featureFlags.isAndroidEnabled) ...androidRequiredHttpHosts(_platform), _platform.environment[kEnvPubHostedUrl] ?? kPubDevHttpHost, _platform.environment[kEnvCloudUrl] ?? kgCloudHttpHost, ]; diff --git a/packages/flutter_tools/test/commands.shard/hermetic/http_host_validator_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/http_host_validator_test.dart index 97a20d6274..0fab21a442 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/http_host_validator_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/http_host_validator_test.dart @@ -48,12 +48,13 @@ void main() { testWithoutContext('all http hosts are not available', () async { // Run the check for all operating systems one by one for(final String os in osTested) { + final Platform platform = FakePlatform(operatingSystem: os); final HttpHostValidator httpHostValidator = HttpHostValidator( - platform: FakePlatform(operatingSystem: os), + platform: platform, featureFlags: TestFeatureFlags(), httpClient: FakeHttpClient.list([ FakeRequest(Uri.parse(kgCloudHttpHost), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), - FakeRequest(Uri.parse(androidRequiredHttpHosts[0]), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), + FakeRequest(Uri.parse(androidRequiredHttpHosts(platform)[0]), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), FakeRequest(Uri.parse(kPubDevHttpHost), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), FakeRequest(Uri.parse(macOSRequiredHttpHosts[0]), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), ]), @@ -70,12 +71,13 @@ void main() { testWithoutContext('one http hosts are not available', () async { // Run the check for all operating systems one by one for(final String os in osTested) { + final Platform platform = FakePlatform(operatingSystem: os); final HttpHostValidator httpHostValidator = HttpHostValidator( - platform: FakePlatform(operatingSystem: os), + platform: platform, featureFlags: TestFeatureFlags(), httpClient: FakeHttpClient.list([ FakeRequest(Uri.parse(kgCloudHttpHost), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), - FakeRequest(Uri.parse(androidRequiredHttpHosts[0]), method: HttpMethod.head), + FakeRequest(Uri.parse(androidRequiredHttpHosts(platform)[0]), method: HttpMethod.head), FakeRequest(Uri.parse(kPubDevHttpHost), method: HttpMethod.head), FakeRequest(Uri.parse(macOSRequiredHttpHosts[0]), method: HttpMethod.head), ]), @@ -92,12 +94,13 @@ void main() { testWithoutContext('one http hosts are not available', () async { // Run the check for all operating systems one by one for(final String os in osTested) { + final Platform platform = FakePlatform(operatingSystem: os); final HttpHostValidator httpHostValidator = HttpHostValidator( - platform: FakePlatform(operatingSystem: os), + platform: platform, featureFlags: TestFeatureFlags(), httpClient: FakeHttpClient.list([ FakeRequest(Uri.parse(kgCloudHttpHost), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), - FakeRequest(Uri.parse(androidRequiredHttpHosts[0]), method: HttpMethod.head), + FakeRequest(Uri.parse(androidRequiredHttpHosts(platform)[0]), method: HttpMethod.head), FakeRequest(Uri.parse(kPubDevHttpHost), method: HttpMethod.head), FakeRequest(Uri.parse(macOSRequiredHttpHosts[0]), method: HttpMethod.head), ]), @@ -135,12 +138,12 @@ void main() { testWithoutContext('all http hosts are not available', () async { // Run the check for all operating systems one by one for(final String os in osTested) { + final Platform platform = FakePlatform(operatingSystem: os, environment: kTestEnvironment); final HttpHostValidator httpHostValidator = HttpHostValidator( - platform: FakePlatform(operatingSystem: os, environment: kTestEnvironment), + platform: platform, featureFlags: TestFeatureFlags(), httpClient: FakeHttpClient.list([ FakeRequest(Uri.parse(kTestEnvGCloudHost), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), - FakeRequest(Uri.parse(androidRequiredHttpHosts[0]), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), FakeRequest(Uri.parse(kTestEnvPubHost), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), FakeRequest(Uri.parse(macOSRequiredHttpHosts[0]), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), ]), @@ -157,12 +160,12 @@ void main() { testWithoutContext('one http hosts are not available', () async { // Run the check for all operating systems one by one for(final String os in osTested) { + final Platform platform = FakePlatform(operatingSystem: os, environment: kTestEnvironment); final HttpHostValidator httpHostValidator = HttpHostValidator( - platform: FakePlatform(operatingSystem: os, environment: kTestEnvironment), + platform: platform, featureFlags: TestFeatureFlags(), httpClient: FakeHttpClient.list([ FakeRequest(Uri.parse(kTestEnvGCloudHost), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), - FakeRequest(Uri.parse(androidRequiredHttpHosts[0]), method: HttpMethod.head), FakeRequest(Uri.parse(kTestEnvPubHost), method: HttpMethod.head), FakeRequest(Uri.parse(macOSRequiredHttpHosts[0]), method: HttpMethod.head), ]), @@ -179,12 +182,12 @@ void main() { testWithoutContext('one http hosts are not available', () async { // Run the check for all operating systems one by one for(final String os in osTested) { + final Platform platform = FakePlatform(operatingSystem: os, environment: kTestEnvironment); final HttpHostValidator httpHostValidator = HttpHostValidator( - platform: FakePlatform(operatingSystem: os, environment: kTestEnvironment), + platform: platform, featureFlags: TestFeatureFlags(), httpClient: FakeHttpClient.list([ FakeRequest(Uri.parse(kTestEnvGCloudHost), method: HttpMethod.head, responseError: const OSError('Name or service not known', -2)), - FakeRequest(Uri.parse(androidRequiredHttpHosts[0]), method: HttpMethod.head), FakeRequest(Uri.parse(kTestEnvPubHost), method: HttpMethod.head), FakeRequest(Uri.parse(macOSRequiredHttpHosts[0]), method: HttpMethod.head), ]), @@ -224,13 +227,14 @@ void main() { testWithoutContext('all http hosts are available - iOS disabled', () async { // Run the check for all operating systems one by one for(final String os in osTested) { + final Platform platform = FakePlatform(operatingSystem: os); final HttpHostValidator httpHostValidator = HttpHostValidator( - platform: FakePlatform(operatingSystem: os), + platform: platform, featureFlags: TestFeatureFlags(isIOSEnabled: false), httpClient: FakeHttpClient.list([ FakeRequest(Uri.parse(kgCloudHttpHost), method: HttpMethod.head), FakeRequest(Uri.parse(kPubDevHttpHost), method: HttpMethod.head), - FakeRequest(Uri.parse(androidRequiredHttpHosts[0]), method: HttpMethod.head), + FakeRequest(Uri.parse(androidRequiredHttpHosts(platform)[0]), method: HttpMethod.head), ]), );