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
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) {
......
......@@ -428,6 +428,7 @@ class TestUsage implements Usage {
final List<dynamic> exceptions = <dynamic>[];
final List<TestTimingEvent> timings = <TestTimingEvent>[];
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<void> ensureAnalyticsSent() async {
ensureAnalyticsSentCalls++;
......@@ -447,7 +451,9 @@ class TestUsage implements Usage {
Stream<Map<String, dynamic>> get onSend => throw UnimplementedError();
@override
void printWelcome() { }
void printWelcome() {
_printedWelcome = true;
}
@override
void sendCommand(String command, {CustomDimensions? parameters}) {
......
......@@ -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(
<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', () {
......
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