Remove more references to deprecated package:usage (executable, runner) (#160369)

Helps https://github.com/flutter/flutter/issues/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
This commit is contained in:
Andrew Kolos 2024-12-16 15:39:43 -05:00 committed by GitHub
parent 98e5ce7ed7
commit c803c1346f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 233 deletions

View File

@ -169,7 +169,7 @@ List<FlutterCommand> generateCommands({
platform: globals.platform,
),
],
suppressAnalytics: globals.flutterUsage.suppressAnalytics,
suppressAnalytics: !globals.analytics.okToSend,
),
AssembleCommand(verboseHelp: verboseHelp, buildSystem: globals.buildSystem),
AttachCommand(

View File

@ -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<int> 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<int> _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(

View File

@ -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<int> 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<int> exitWithHooks(int code, {required ShutdownHooks shutdownHooks}) asyn
final Completer<void> completer = Completer<void>();
// 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.

View File

@ -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: <Type, Generator>{
Platform: () => FakePlatform(environment: <String, String>{
@ -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: <Type, Generator>{
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(
<String>[],
() => <FlutterCommand>[],
// 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: <Type, Generator>{
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(
<String>[],
() => <FlutterCommand>[],
// 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: <Type, Generator>{
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<Map<String, dynamic>> get onSend => _impl.onSend;
@override
Future<void> ensureAnalyticsSent() => _impl.ensureAnalyticsSent();
@override
void printWelcome() => _impl.printWelcome();
}
class CustomBugInstructions extends UserMessages {
@override
String get flutterToolBugInstructions => kCustomBugInstructions;