Skip to content

Commit c803c13

Browse files
authored
Remove more references to deprecated package:usage (executable, runner) (#160369)
Helps flutter/flutter#150575 <details> <summary> Pre-launch checklist </summary> - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. </details> <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 98e5ce7 commit c803c13

File tree

4 files changed

+8
-233
lines changed

4 files changed

+8
-233
lines changed

packages/flutter_tools/lib/executable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ List<FlutterCommand> generateCommands({
169169
platform: globals.platform,
170170
),
171171
],
172-
suppressAnalytics: globals.flutterUsage.suppressAnalytics,
172+
suppressAnalytics: !globals.analytics.okToSend,
173173
),
174174
AssembleCommand(verboseHelp: verboseHelp, buildSystem: globals.buildSystem),
175175
AttachCommand(

packages/flutter_tools/lib/runner.dart

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import 'src/doctor.dart';
2323
import 'src/features.dart';
2424
import 'src/globals.dart' as globals;
2525
import 'src/reporting/crash_reporting.dart';
26-
import 'src/reporting/reporting.dart';
2726
import 'src/runner/flutter_command.dart';
2827
import 'src/runner/flutter_command_runner.dart';
2928

@@ -97,18 +96,6 @@ Future<int> run(
9796
globals.printStatus('Analytics reporting enabled.');
9897
}
9998

100-
// Send an event to GA3 for any users that are opted into GA3
101-
// analytics but have opted out of GA4 (package:unified_analytics)
102-
// TODO(eliasyishak): remove once GA3 sunset, https://github.com/flutter/flutter/issues/128251
103-
if (!globals.analytics.telemetryEnabled &&
104-
globals.flutterUsage.enabled) {
105-
UsageEvent(
106-
'ga4_and_ga3_status_mismatch',
107-
'opted_out_of_ga4',
108-
flutterUsage: globals.flutterUsage,
109-
).send();
110-
}
111-
11299
await runner.run(args);
113100

114101
// Triggering [runZoned]'s error callback does not necessarily mean that
@@ -188,8 +175,6 @@ Future<int> _handleToolError(
188175
return exitWithHooks(1, shutdownHooks: shutdownHooks);
189176
}
190177

191-
// Report to both [Usage] and [CrashReportSender].
192-
globals.flutterUsage.sendException(error);
193178
globals.analytics.send(Event.exception(exception: error.runtimeType.toString()));
194179
await asyncGuard(() async {
195180
final CrashReportSender crashReportSender = CrashReportSender(

packages/flutter_tools/lib/src/base/process.dart

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:process/process.dart';
99

1010
import '../convert.dart';
1111
import '../globals.dart' as globals;
12-
import '../reporting/first_run.dart';
1312
import 'io.dart';
1413
import 'logger.dart';
1514

@@ -677,67 +676,19 @@ class _DefaultProcessUtils implements ProcessUtils {
677676
}
678677

679678
Future<int> exitWithHooks(int code, {required ShutdownHooks shutdownHooks}) async {
680-
// Need to get the boolean returned from `messenger.shouldDisplayLicenseTerms()`
681-
// before invoking the print welcome method because the print welcome method
682-
// will set `messenger.shouldDisplayLicenseTerms()` to false
683-
final FirstRunMessenger messenger =
684-
FirstRunMessenger(persistentToolState: globals.persistentToolState!);
685-
final bool legacyAnalyticsMessageShown =
686-
messenger.shouldDisplayLicenseTerms();
687-
688-
// Prints the welcome message if needed for legacy analytics.
689-
if (!(await globals.isRunningOnBot)) {
690-
globals.flutterUsage.printWelcome();
691-
}
692-
693-
// Ensure that the consent message has been displayed for unified analytics
694679
if (globals.analytics.shouldShowMessage) {
695680
globals.logger.printStatus(globals.analytics.getConsentMessage);
696-
if (!globals.flutterUsage.enabled) {
697-
globals.printStatus(
698-
'Please note that analytics reporting was already disabled, '
699-
'and will continue to be disabled.\n');
700-
}
701-
702-
// Because the legacy analytics may have also sent a message,
703-
// the conditional below will print additional messaging informing
704-
// users that the two consent messages they are receiving is not a
705-
// bug
706-
if (legacyAnalyticsMessageShown) {
707-
globals.logger
708-
.printStatus('You have received two consent messages because '
709-
'the flutter tool is migrating to a new analytics system. '
710-
'Disabling analytics collection will disable both the legacy '
711-
'and new analytics collection systems. '
712-
'You can disable analytics reporting by running `flutter --disable-analytics`\n');
713-
}
714-
715-
// Invoking this will onboard the flutter tool onto
716-
// the package on the developer's machine and will
717-
// allow for events to be sent to Google Analytics
718-
// on subsequent runs of the flutter tool (ie. no events
719-
// will be sent on the first run to allow developers to
720-
// opt out of collection)
721681
globals.analytics.clientShowedMessage();
722-
}
723682

724-
// Send any last analytics calls that are in progress without overly delaying
725-
// the tool's exit (we wait a maximum of 250ms).
726-
if (globals.flutterUsage.enabled) {
727-
final Stopwatch stopwatch = Stopwatch()..start();
728-
await globals.flutterUsage.ensureAnalyticsSent();
729-
globals.printTrace('ensureAnalyticsSent: ${stopwatch.elapsedMilliseconds}ms');
683+
// This trace is searched for in tests.
684+
globals.logger.printTrace('Showed analytics consent message.');
730685
}
731686

732687
// Run shutdown hooks before flushing logs
733688
await shutdownHooks.runShutdownHooks(globals.logger);
734689

735690
final Completer<void> completer = Completer<void>();
736691

737-
// Allow any pending analytics events to send and close the http connection
738-
//
739-
// By default, we will wait 250 ms before canceling any pending events, we
740-
// can change the [delayDuration] in the close method if it needs to be changed
741692
await globals.analytics.close();
742693

743694
// Give the task / timer queue one cycle through before we hard exit.

packages/flutter_tools/test/general.shard/runner/runner_test.dart

Lines changed: 5 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import 'package:flutter_tools/src/base/user_messages.dart';
1818
import 'package:flutter_tools/src/cache.dart';
1919
import 'package:flutter_tools/src/globals.dart' as globals;
2020
import 'package:flutter_tools/src/reporting/crash_reporting.dart';
21-
import 'package:flutter_tools/src/reporting/reporting.dart';
2221
import 'package:flutter_tools/src/runner/flutter_command.dart';
2322
import 'package:test/fake.dart';
2423
import 'package:unified_analytics/unified_analytics.dart';
@@ -99,8 +98,6 @@ void main() {
9998
// exception on the first attempt, the second attempt tries to report the
10099
// *original* crash, and not the crash from the first crash report
101100
// attempt.
102-
final CrashingUsage crashingUsage = globals.flutterUsage as CrashingUsage;
103-
expect(crashingUsage.sentException.toString(), 'Exception: an exception % --');
104101
expect(fakeAnalytics.sentEvents, contains(Event.exception(exception: '_Exception')));
105102
}, overrides: <Type, Generator>{
106103
Platform: () => FakePlatform(environment: <String, String>{
@@ -109,7 +106,6 @@ void main() {
109106
}),
110107
FileSystem: () => fileSystem,
111108
ProcessManager: () => FakeProcessManager.any(),
112-
Usage: () => CrashingUsage(),
113109
Artifacts: () => Artifacts.test(),
114110
HttpClientFactory: () => () => FakeHttpClient.any(),
115111
Analytics: () => fakeAnalytics,
@@ -411,21 +407,23 @@ void main() {
411407
shutdownHooks: ShutdownHooks(),
412408
);
413409

414-
expect((globals.flutterUsage as TestUsage).printedWelcome, false);
410+
expect(
411+
(globals.logger as BufferLogger).traceText,
412+
isNot(contains('Showed analytics consent message.')),
413+
);
415414
},
416415
overrides: <Type, Generator>{
416+
Logger: () => BufferLogger.test(),
417417
FileSystem: () => MemoryFileSystem.test(),
418418
ProcessManager: () => FakeProcessManager.any(),
419419
BotDetector: () => const FakeBotDetector(true),
420-
Usage: () => TestUsage(),
421420
},
422421
);
423422
});
424423

425424
group('unified_analytics', () {
426425
late FakeAnalytics fakeAnalytics;
427426
late MemoryFileSystem fs;
428-
late TestUsage testUsage;
429427

430428
setUp(() {
431429
fs = MemoryFileSystem.test();
@@ -434,7 +432,6 @@ void main() {
434432
fs: fs,
435433
fakeFlutterVersion: FakeFlutterVersion(),
436434
);
437-
testUsage = TestUsage();
438435
});
439436

440437
testUsingContext(
@@ -461,85 +458,6 @@ void main() {
461458
},
462459
);
463460

464-
testUsingContext(
465-
'runner sends mismatch event to ga3 if user opted in to ga3 but out of ga4 analytics',
466-
() async {
467-
io.setExitFunctionForTests((int exitCode) {});
468-
469-
// Begin by opting out of telemetry for package:unified_analytics
470-
// and leaving legacy analytics opted in
471-
await fakeAnalytics.setTelemetry(false);
472-
expect(fakeAnalytics.telemetryEnabled, false);
473-
expect(testUsage.enabled, true);
474-
475-
await runner.run(
476-
<String>[],
477-
() => <FlutterCommand>[],
478-
// This flutterVersion disables crash reporting.
479-
flutterVersion: '[user-branch]/',
480-
shutdownHooks: ShutdownHooks(),
481-
);
482-
483-
expect(
484-
testUsage.events,
485-
contains(const TestUsageEvent(
486-
'ga4_and_ga3_status_mismatch',
487-
'opted_out_of_ga4',
488-
)),
489-
);
490-
expect(fakeAnalytics.telemetryEnabled, false);
491-
expect(testUsage.enabled, true);
492-
expect(fakeAnalytics.sentEvents, isEmpty);
493-
494-
},
495-
overrides: <Type, Generator>{
496-
Analytics: () => fakeAnalytics,
497-
FileSystem: () => MemoryFileSystem.test(),
498-
ProcessManager: () => FakeProcessManager.any(),
499-
Usage: () => testUsage,
500-
},
501-
);
502-
503-
testUsingContext(
504-
'runner does not send mismatch event to ga3 if user opted out of ga3 & ga4 analytics',
505-
() async {
506-
io.setExitFunctionForTests((int exitCode) {});
507-
508-
// Begin by opting out of telemetry for package:unified_analytics
509-
// and legacy analytics
510-
await fakeAnalytics.setTelemetry(false);
511-
testUsage.enabled = false;
512-
expect(fakeAnalytics.telemetryEnabled, false);
513-
expect(testUsage.enabled, false);
514-
515-
await runner.run(
516-
<String>[],
517-
() => <FlutterCommand>[],
518-
// This flutterVersion disables crash reporting.
519-
flutterVersion: '[user-branch]/',
520-
shutdownHooks: ShutdownHooks(),
521-
);
522-
523-
expect(
524-
testUsage.events,
525-
isNot(contains(const TestUsageEvent(
526-
'ga4_and_ga3_status_mismatch',
527-
'opted_out_of_ga4',
528-
))),
529-
);
530-
expect(fakeAnalytics.telemetryEnabled, false);
531-
expect(testUsage.enabled, false);
532-
expect(fakeAnalytics.sentEvents, isEmpty);
533-
534-
},
535-
overrides: <Type, Generator>{
536-
Analytics: () => fakeAnalytics,
537-
FileSystem: () => MemoryFileSystem.test(),
538-
ProcessManager: () => FakeProcessManager.any(),
539-
Usage: () => testUsage,
540-
},
541-
);
542-
543461
testUsingContext(
544462
'--enable-analytics and --disable-analytics enables/disables telemetry',
545463
() async {
@@ -721,85 +639,6 @@ class _GitNotFoundFlutterCommand extends FlutterCommand {
721639
}
722640
}
723641

724-
class CrashingUsage implements Usage {
725-
CrashingUsage() : _impl = Usage(
726-
versionOverride: '[user-branch]',
727-
runningOnBot: true,
728-
);
729-
730-
final Usage _impl;
731-
732-
dynamic get sentException => _sentException;
733-
dynamic _sentException;
734-
735-
bool _firstAttempt = true;
736-
737-
// Crash while crashing.
738-
@override
739-
void sendException(dynamic exception) {
740-
if (_firstAttempt) {
741-
_firstAttempt = false;
742-
throw Exception('CrashingUsage.sendException');
743-
}
744-
_sentException = exception;
745-
}
746-
747-
@override
748-
bool get suppressAnalytics => _impl.suppressAnalytics;
749-
750-
@override
751-
set suppressAnalytics(bool value) {
752-
_impl.suppressAnalytics = value;
753-
}
754-
755-
@override
756-
bool get enabled => _impl.enabled;
757-
758-
@override
759-
set enabled(bool value) {
760-
_impl.enabled = value;
761-
}
762-
763-
@override
764-
String get clientId => _impl.clientId;
765-
766-
@override
767-
void sendCommand(String command, {CustomDimensions? parameters}) =>
768-
_impl.sendCommand(command, parameters: parameters);
769-
770-
@override
771-
void sendEvent(
772-
String category,
773-
String parameter, {
774-
String? label,
775-
int? value,
776-
CustomDimensions? parameters,
777-
}) => _impl.sendEvent(
778-
category,
779-
parameter,
780-
label: label,
781-
value: value,
782-
parameters: parameters,
783-
);
784-
785-
@override
786-
void sendTiming(
787-
String category,
788-
String variableName,
789-
Duration duration, {
790-
String? label,
791-
}) => _impl.sendTiming(category, variableName, duration, label: label);
792-
793-
@override
794-
Stream<Map<String, dynamic>> get onSend => _impl.onSend;
795-
796-
@override
797-
Future<void> ensureAnalyticsSent() => _impl.ensureAnalyticsSent();
798-
799-
@override
800-
void printWelcome() => _impl.printWelcome();
801-
}
802-
803642
class CustomBugInstructions extends UserMessages {
804643
@override
805644
String get flutterToolBugInstructions => kCustomBugInstructions;

0 commit comments

Comments
 (0)