Unverified Commit a0e43d30 authored by Sigurd Meldgaard's avatar Sigurd Meldgaard Committed by GitHub

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: 's avatareliasyishak <42216813+eliasyishak@users.noreply.github.com>
parent 1e24c41c
...@@ -623,7 +623,9 @@ Future<int> exitWithHooks(int code, {required ShutdownHooks shutdownHooks}) asyn ...@@ -623,7 +623,9 @@ Future<int> exitWithHooks(int code, {required ShutdownHooks shutdownHooks}) asyn
messenger.shouldDisplayLicenseTerms(); messenger.shouldDisplayLicenseTerms();
// Prints the welcome message if needed for legacy analytics. // 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 // Ensure that the consent message has been displayed for unified analytics
if (globals.analytics.shouldShowMessage) { if (globals.analytics.shouldShowMessage) {
......
...@@ -428,6 +428,7 @@ class TestUsage implements Usage { ...@@ -428,6 +428,7 @@ class TestUsage implements Usage {
final List<dynamic> exceptions = <dynamic>[]; final List<dynamic> exceptions = <dynamic>[];
final List<TestTimingEvent> timings = <TestTimingEvent>[]; final List<TestTimingEvent> timings = <TestTimingEvent>[];
int ensureAnalyticsSentCalls = 0; int ensureAnalyticsSentCalls = 0;
bool _printedWelcome = false;
@override @override
bool enabled = true; bool enabled = true;
...@@ -438,6 +439,9 @@ class TestUsage implements Usage { ...@@ -438,6 +439,9 @@ class TestUsage implements Usage {
@override @override
String get clientId => 'test-client'; String get clientId => 'test-client';
/// Confirms if the [printWelcome] method was invoked.
bool get printedWelcome => _printedWelcome;
@override @override
Future<void> ensureAnalyticsSent() async { Future<void> ensureAnalyticsSent() async {
ensureAnalyticsSentCalls++; ensureAnalyticsSentCalls++;
...@@ -447,7 +451,9 @@ class TestUsage implements Usage { ...@@ -447,7 +451,9 @@ class TestUsage implements Usage {
Stream<Map<String, dynamic>> get onSend => throw UnimplementedError(); Stream<Map<String, dynamic>> get onSend => throw UnimplementedError();
@override @override
void printWelcome() { } void printWelcome() {
_printedWelcome = true;
}
@override @override
void sendCommand(String command, {CustomDimensions? parameters}) { void sendCommand(String command, {CustomDimensions? parameters}) {
......
...@@ -7,6 +7,7 @@ import 'dart:async'; ...@@ -7,6 +7,7 @@ import 'dart:async';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/runner.dart' as runner; import 'package:flutter_tools/runner.dart' as runner;
import 'package:flutter_tools/src/artifacts.dart'; 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/file_system.dart';
import 'package:flutter_tools/src/base/io.dart' as io; import 'package:flutter_tools/src/base/io.dart' as io;
import 'package:flutter_tools/src/base/net.dart'; import 'package:flutter_tools/src/base/net.dart';
...@@ -33,6 +34,7 @@ void main() { ...@@ -33,6 +34,7 @@ void main() {
group('runner', () { group('runner', () {
late FakeAnalytics fakeAnalytics; late FakeAnalytics fakeAnalytics;
late TestUsage testUsage;
setUp(() { setUp(() {
// Instead of exiting with dart:io exit(), this causes an exception to // Instead of exiting with dart:io exit(), this causes an exception to
...@@ -57,6 +59,8 @@ void main() { ...@@ -57,6 +59,8 @@ void main() {
fs: fileSystem, fs: fileSystem,
fakeFlutterVersion: FakeFlutterVersion(), fakeFlutterVersion: FakeFlutterVersion(),
); );
testUsage = TestUsage();
}); });
tearDown(() { tearDown(() {
...@@ -323,6 +327,27 @@ void main() { ...@@ -323,6 +327,27 @@ void main() {
HttpClientFactory: () => () => FakeHttpClient.any(), HttpClientFactory: () => () => FakeHttpClient.any(),
}); });
}); });
testUsingContext('do not print welcome on bots', () async {
io.setExitFunctionForTests((int exitCode) {});
await runner.run(
<String>['--version', '--machine'],
() => <FlutterCommand>[],
// This flutterVersion disables crash reporting.
flutterVersion: '[user-branch]/',
shutdownHooks: ShutdownHooks(),
);
expect(testUsage.printedWelcome, false);
},
overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
BotDetector: () => const FakeBotDetector(true),
Usage: () => testUsage,
},
);
}); });
group('unified_analytics', () { group('unified_analytics', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment