diff --git a/packages/flutter_tools/lib/executable.dart b/packages/flutter_tools/lib/executable.dart index ce0a5a66a1..fb23a3be66 100644 --- a/packages/flutter_tools/lib/executable.dart +++ b/packages/flutter_tools/lib/executable.dart @@ -169,7 +169,7 @@ List generateCommands({ platform: globals.platform, ), ], - suppressAnalytics: globals.flutterUsage.suppressAnalytics, + suppressAnalytics: !globals.analytics.okToSend, ), AssembleCommand(verboseHelp: verboseHelp, buildSystem: globals.buildSystem), AttachCommand( diff --git a/packages/flutter_tools/lib/runner.dart b/packages/flutter_tools/lib/runner.dart index f9a4362387..73785c3463 100644 --- a/packages/flutter_tools/lib/runner.dart +++ b/packages/flutter_tools/lib/runner.dart @@ -23,7 +23,6 @@ import 'src/doctor.dart'; import 'src/features.dart'; import 'src/globals.dart' as globals; import 'src/reporting/crash_reporting.dart'; -import 'src/reporting/reporting.dart'; import 'src/runner/flutter_command.dart'; import 'src/runner/flutter_command_runner.dart'; @@ -97,18 +96,6 @@ Future run( globals.printStatus('Analytics reporting enabled.'); } - // Send an event to GA3 for any users that are opted into GA3 - // analytics but have opted out of GA4 (package:unified_analytics) - // TODO(eliasyishak): remove once GA3 sunset, https://github.com/flutter/flutter/issues/128251 - if (!globals.analytics.telemetryEnabled && - globals.flutterUsage.enabled) { - UsageEvent( - 'ga4_and_ga3_status_mismatch', - 'opted_out_of_ga4', - flutterUsage: globals.flutterUsage, - ).send(); - } - await runner.run(args); // Triggering [runZoned]'s error callback does not necessarily mean that @@ -188,8 +175,6 @@ Future _handleToolError( return exitWithHooks(1, shutdownHooks: shutdownHooks); } - // Report to both [Usage] and [CrashReportSender]. - globals.flutterUsage.sendException(error); globals.analytics.send(Event.exception(exception: error.runtimeType.toString())); await asyncGuard(() async { final CrashReportSender crashReportSender = CrashReportSender( diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index 96df867826..7a63cc0b8c 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart @@ -9,7 +9,6 @@ import 'package:process/process.dart'; import '../convert.dart'; import '../globals.dart' as globals; -import '../reporting/first_run.dart'; import 'io.dart'; import 'logger.dart'; @@ -677,56 +676,12 @@ class _DefaultProcessUtils implements ProcessUtils { } Future exitWithHooks(int code, {required ShutdownHooks shutdownHooks}) async { - // Need to get the boolean returned from `messenger.shouldDisplayLicenseTerms()` - // before invoking the print welcome method because the print welcome method - // will set `messenger.shouldDisplayLicenseTerms()` to false - final FirstRunMessenger messenger = - FirstRunMessenger(persistentToolState: globals.persistentToolState!); - final bool legacyAnalyticsMessageShown = - messenger.shouldDisplayLicenseTerms(); - - // Prints the welcome message if needed for legacy analytics. - if (!(await globals.isRunningOnBot)) { - globals.flutterUsage.printWelcome(); - } - - // Ensure that the consent message has been displayed for unified analytics if (globals.analytics.shouldShowMessage) { globals.logger.printStatus(globals.analytics.getConsentMessage); - if (!globals.flutterUsage.enabled) { - globals.printStatus( - 'Please note that analytics reporting was already disabled, ' - 'and will continue to be disabled.\n'); - } - - // Because the legacy analytics may have also sent a message, - // the conditional below will print additional messaging informing - // users that the two consent messages they are receiving is not a - // bug - if (legacyAnalyticsMessageShown) { - globals.logger - .printStatus('You have received two consent messages because ' - 'the flutter tool is migrating to a new analytics system. ' - 'Disabling analytics collection will disable both the legacy ' - 'and new analytics collection systems. ' - 'You can disable analytics reporting by running `flutter --disable-analytics`\n'); - } - - // Invoking this will onboard the flutter tool onto - // the package on the developer's machine and will - // allow for events to be sent to Google Analytics - // on subsequent runs of the flutter tool (ie. no events - // will be sent on the first run to allow developers to - // opt out of collection) globals.analytics.clientShowedMessage(); - } - // Send any last analytics calls that are in progress without overly delaying - // the tool's exit (we wait a maximum of 250ms). - if (globals.flutterUsage.enabled) { - final Stopwatch stopwatch = Stopwatch()..start(); - await globals.flutterUsage.ensureAnalyticsSent(); - globals.printTrace('ensureAnalyticsSent: ${stopwatch.elapsedMilliseconds}ms'); + // This trace is searched for in tests. + globals.logger.printTrace('Showed analytics consent message.'); } // Run shutdown hooks before flushing logs @@ -734,10 +689,6 @@ Future exitWithHooks(int code, {required ShutdownHooks shutdownHooks}) asyn final Completer completer = Completer(); - // Allow any pending analytics events to send and close the http connection - // - // By default, we will wait 250 ms before canceling any pending events, we - // can change the [delayDuration] in the close method if it needs to be changed await globals.analytics.close(); // Give the task / timer queue one cycle through before we hard exit. 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 619b1547f2..1c5813f195 100644 --- a/packages/flutter_tools/test/general.shard/runner/runner_test.dart +++ b/packages/flutter_tools/test/general.shard/runner/runner_test.dart @@ -18,7 +18,6 @@ import 'package:flutter_tools/src/base/user_messages.dart'; import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/reporting/crash_reporting.dart'; -import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/runner/flutter_command.dart'; import 'package:test/fake.dart'; import 'package:unified_analytics/unified_analytics.dart'; @@ -99,8 +98,6 @@ void main() { // exception on the first attempt, the second attempt tries to report the // *original* crash, and not the crash from the first crash report // attempt. - final CrashingUsage crashingUsage = globals.flutterUsage as CrashingUsage; - expect(crashingUsage.sentException.toString(), 'Exception: an exception % --'); expect(fakeAnalytics.sentEvents, contains(Event.exception(exception: '_Exception'))); }, overrides: { Platform: () => FakePlatform(environment: { @@ -109,7 +106,6 @@ void main() { }), FileSystem: () => fileSystem, ProcessManager: () => FakeProcessManager.any(), - Usage: () => CrashingUsage(), Artifacts: () => Artifacts.test(), HttpClientFactory: () => () => FakeHttpClient.any(), Analytics: () => fakeAnalytics, @@ -411,13 +407,16 @@ void main() { shutdownHooks: ShutdownHooks(), ); - expect((globals.flutterUsage as TestUsage).printedWelcome, false); + expect( + (globals.logger as BufferLogger).traceText, + isNot(contains('Showed analytics consent message.')), + ); }, overrides: { + Logger: () => BufferLogger.test(), FileSystem: () => MemoryFileSystem.test(), ProcessManager: () => FakeProcessManager.any(), BotDetector: () => const FakeBotDetector(true), - Usage: () => TestUsage(), }, ); }); @@ -425,7 +424,6 @@ void main() { group('unified_analytics', () { late FakeAnalytics fakeAnalytics; late MemoryFileSystem fs; - late TestUsage testUsage; setUp(() { fs = MemoryFileSystem.test(); @@ -434,7 +432,6 @@ void main() { fs: fs, fakeFlutterVersion: FakeFlutterVersion(), ); - testUsage = TestUsage(); }); testUsingContext( @@ -461,85 +458,6 @@ void main() { }, ); - testUsingContext( - 'runner sends mismatch event to ga3 if user opted in to ga3 but out of ga4 analytics', - () async { - io.setExitFunctionForTests((int exitCode) {}); - - // Begin by opting out of telemetry for package:unified_analytics - // and leaving legacy analytics opted in - await fakeAnalytics.setTelemetry(false); - expect(fakeAnalytics.telemetryEnabled, false); - expect(testUsage.enabled, true); - - await runner.run( - [], - () => [], - // This flutterVersion disables crash reporting. - flutterVersion: '[user-branch]/', - shutdownHooks: ShutdownHooks(), - ); - - expect( - testUsage.events, - contains(const TestUsageEvent( - 'ga4_and_ga3_status_mismatch', - 'opted_out_of_ga4', - )), - ); - expect(fakeAnalytics.telemetryEnabled, false); - expect(testUsage.enabled, true); - expect(fakeAnalytics.sentEvents, isEmpty); - - }, - overrides: { - Analytics: () => fakeAnalytics, - FileSystem: () => MemoryFileSystem.test(), - ProcessManager: () => FakeProcessManager.any(), - Usage: () => testUsage, - }, - ); - - testUsingContext( - 'runner does not send mismatch event to ga3 if user opted out of ga3 & ga4 analytics', - () async { - io.setExitFunctionForTests((int exitCode) {}); - - // Begin by opting out of telemetry for package:unified_analytics - // and legacy analytics - await fakeAnalytics.setTelemetry(false); - testUsage.enabled = false; - expect(fakeAnalytics.telemetryEnabled, false); - expect(testUsage.enabled, false); - - await runner.run( - [], - () => [], - // This flutterVersion disables crash reporting. - flutterVersion: '[user-branch]/', - shutdownHooks: ShutdownHooks(), - ); - - expect( - testUsage.events, - isNot(contains(const TestUsageEvent( - 'ga4_and_ga3_status_mismatch', - 'opted_out_of_ga4', - ))), - ); - expect(fakeAnalytics.telemetryEnabled, false); - expect(testUsage.enabled, false); - expect(fakeAnalytics.sentEvents, isEmpty); - - }, - overrides: { - Analytics: () => fakeAnalytics, - FileSystem: () => MemoryFileSystem.test(), - ProcessManager: () => FakeProcessManager.any(), - Usage: () => testUsage, - }, - ); - testUsingContext( '--enable-analytics and --disable-analytics enables/disables telemetry', () async { @@ -721,85 +639,6 @@ class _GitNotFoundFlutterCommand extends FlutterCommand { } } -class CrashingUsage implements Usage { - CrashingUsage() : _impl = Usage( - versionOverride: '[user-branch]', - runningOnBot: true, - ); - - final Usage _impl; - - dynamic get sentException => _sentException; - dynamic _sentException; - - bool _firstAttempt = true; - - // Crash while crashing. - @override - void sendException(dynamic exception) { - if (_firstAttempt) { - _firstAttempt = false; - throw Exception('CrashingUsage.sendException'); - } - _sentException = exception; - } - - @override - bool get suppressAnalytics => _impl.suppressAnalytics; - - @override - set suppressAnalytics(bool value) { - _impl.suppressAnalytics = value; - } - - @override - bool get enabled => _impl.enabled; - - @override - set enabled(bool value) { - _impl.enabled = value; - } - - @override - String get clientId => _impl.clientId; - - @override - void sendCommand(String command, {CustomDimensions? parameters}) => - _impl.sendCommand(command, parameters: parameters); - - @override - void sendEvent( - String category, - String parameter, { - String? label, - int? value, - CustomDimensions? parameters, - }) => _impl.sendEvent( - category, - parameter, - label: label, - value: value, - parameters: parameters, - ); - - @override - void sendTiming( - String category, - String variableName, - Duration duration, { - String? label, - }) => _impl.sendTiming(category, variableName, duration, label: label); - - @override - Stream> get onSend => _impl.onSend; - - @override - Future ensureAnalyticsSent() => _impl.ensureAnalyticsSent(); - - @override - void printWelcome() => _impl.printWelcome(); -} - class CustomBugInstructions extends UserMessages { @override String get flutterToolBugInstructions => kCustomBugInstructions;