From a0e43d3053ebb1716d8468b427c6cc44b6f8b7e7 Mon Sep 17 00:00:00 2001 From: Sigurd Meldgaard Date: Thu, 25 Jan 2024 16:29:42 +0100 Subject: [PATCH] Don't show legacy welcome message when analytics are disabled (#140956) The legacy welcome message would be printed even if `CI=true` confusing parsers of the output. This fixes: https://github.com/flutter/flutter/issues/139737 --------- Co-authored-by: eliasyishak <42216813+eliasyishak@users.noreply.github.com> --- .../flutter_tools/lib/src/base/process.dart | 4 ++- .../lib/src/reporting/usage.dart | 8 +++++- .../general.shard/runner/runner_test.dart | 25 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index d0acf2b5d8..032127ac93 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart @@ -623,7 +623,9 @@ Future exitWithHooks(int code, {required ShutdownHooks shutdownHooks}) asyn messenger.shouldDisplayLicenseTerms(); // Prints the welcome message if needed for legacy analytics. - globals.flutterUsage.printWelcome(); + if (!(await globals.isRunningOnBot)) { + globals.flutterUsage.printWelcome(); + } // Ensure that the consent message has been displayed for unified analytics if (globals.analytics.shouldShowMessage) { diff --git a/packages/flutter_tools/lib/src/reporting/usage.dart b/packages/flutter_tools/lib/src/reporting/usage.dart index d130ae9f49..9341e66bd5 100644 --- a/packages/flutter_tools/lib/src/reporting/usage.dart +++ b/packages/flutter_tools/lib/src/reporting/usage.dart @@ -428,6 +428,7 @@ class TestUsage implements Usage { final List exceptions = []; final List timings = []; int ensureAnalyticsSentCalls = 0; + bool _printedWelcome = false; @override bool enabled = true; @@ -438,6 +439,9 @@ class TestUsage implements Usage { @override String get clientId => 'test-client'; + /// Confirms if the [printWelcome] method was invoked. + bool get printedWelcome => _printedWelcome; + @override Future ensureAnalyticsSent() async { ensureAnalyticsSentCalls++; @@ -447,7 +451,9 @@ class TestUsage implements Usage { Stream> get onSend => throw UnimplementedError(); @override - void printWelcome() { } + void printWelcome() { + _printedWelcome = true; + } @override void sendCommand(String command, {CustomDimensions? parameters}) { diff --git a/packages/flutter_tools/test/general.shard/runner/runner_test.dart b/packages/flutter_tools/test/general.shard/runner/runner_test.dart index f2cd4cff88..f7e3577144 100644 --- a/packages/flutter_tools/test/general.shard/runner/runner_test.dart +++ b/packages/flutter_tools/test/general.shard/runner/runner_test.dart @@ -7,6 +7,7 @@ import 'dart:async'; import 'package:file/memory.dart'; import 'package:flutter_tools/runner.dart' as runner; import 'package:flutter_tools/src/artifacts.dart'; +import 'package:flutter_tools/src/base/bot_detector.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart' as io; import 'package:flutter_tools/src/base/net.dart'; @@ -33,6 +34,7 @@ void main() { group('runner', () { late FakeAnalytics fakeAnalytics; + late TestUsage testUsage; setUp(() { // Instead of exiting with dart:io exit(), this causes an exception to @@ -57,6 +59,8 @@ void main() { fs: fileSystem, fakeFlutterVersion: FakeFlutterVersion(), ); + + testUsage = TestUsage(); }); tearDown(() { @@ -323,6 +327,27 @@ void main() { HttpClientFactory: () => () => FakeHttpClient.any(), }); }); + + testUsingContext('do not print welcome on bots', () async { + io.setExitFunctionForTests((int exitCode) {}); + + await runner.run( + ['--version', '--machine'], + () => [], + // This flutterVersion disables crash reporting. + flutterVersion: '[user-branch]/', + shutdownHooks: ShutdownHooks(), + ); + + expect(testUsage.printedWelcome, false); + }, + overrides: { + FileSystem: () => MemoryFileSystem.test(), + ProcessManager: () => FakeProcessManager.any(), + BotDetector: () => const FakeBotDetector(true), + Usage: () => testUsage, + }, + ); }); group('unified_analytics', () {