Unverified Commit d180c127 authored by Elias Yishak's avatar Elias Yishak Committed by GitHub

Use new `enabledFeature` param for `Analytics` (#139934)

Related to tracker issue:
- https://github.com/flutter/flutter/issues/128251

This updates the `Analytics` constructor to provide it with the enabled features for the flutter-tool. This will be sent with each event for the flutter-tool.
parent c35c42ac
......@@ -94,6 +94,7 @@ Future<T> runInContext<T>(
flutterVersion: globals.flutterVersion,
environment: globals.platform.environment,
clientIde: globals.platform.environment['FLUTTER_HOST'],
config: globals.config,
),
AndroidBuilder: () => AndroidGradleBuilder(
java: globals.java,
......
......@@ -4,7 +4,9 @@
import 'package:unified_analytics/unified_analytics.dart';
import '../base/config.dart';
import '../base/io.dart';
import '../features.dart';
import '../globals.dart' as globals;
import '../version.dart';
......@@ -22,6 +24,7 @@ Analytics getAnalytics({
required FlutterVersion flutterVersion,
required Map<String, String> environment,
required String? clientIde,
required Config config,
bool enableAsserts = false,
FakeAnalytics? analyticsOverride,
}) {
......@@ -52,9 +55,24 @@ Analytics getAnalytics({
dartVersion: flutterVersion.dartSdkVersion,
enableAsserts: enableAsserts,
clientIde: clientIde,
enabledFeatures: getEnabledFeatures(config),
);
}
/// Uses the [Config] object to get enabled features.
String? getEnabledFeatures(Config config) {
// Create string with all enabled features to send as user property
final Iterable<Feature> enabledFeatures = allFeatures.where((Feature feature) {
final String? configSetting = feature.configSetting;
return configSetting != null && config.getValue(configSetting) == true;
});
return enabledFeatures.isNotEmpty
? enabledFeatures
.map((Feature feature) => feature.configSetting)
.join(',')
: null;
}
/// Function to safely grab the max rss from [ProcessInfo].
int? getMaxRss(ProcessInfo processInfo) {
try {
......
......@@ -3,12 +3,12 @@
// found in the LICENSE file.
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/reporting/unified_analytics.dart';
import 'package:unified_analytics/unified_analytics.dart';
import '../src/common.dart';
import '../src/context.dart';
import '../src/fakes.dart';
void main() {
......@@ -16,10 +16,12 @@ void main() {
const String clientIde = 'VSCode';
late FileSystem fs;
late Config config;
late FakeAnalytics analyticsOverride;
setUp(() {
fs = MemoryFileSystem.test();
config = Config.test();
analyticsOverride = getInitializedFakeAnalyticsInstance(
fs: fs,
......@@ -30,14 +32,32 @@ void main() {
);
});
group('Unit testing util:', () {
test('getEnabledFeatures is null', () {
final String? enabledFeatures = getEnabledFeatures(config);
expect(enabledFeatures, isNull);
});
testWithoutContext('getEnabledFeatures not null', () {
config.setValue('cli-animations', true);
config.setValue('enable-flutter-preview', true);
final String? enabledFeatures = getEnabledFeatures(config);
expect(enabledFeatures, isNotNull);
expect(enabledFeatures!.split(','), unorderedEquals(<String>['enable-flutter-preview', 'cli-animations']));
});
});
group('Unit testing getAnalytics', () {
testWithoutContext('Successfully creates the instance for standard branch', () {
testWithoutContext('Successfully creates the instance for standard branch',
() {
final Analytics analytics = getAnalytics(
runningOnBot: false,
flutterVersion: FakeFlutterVersion(),
environment: const <String, String>{},
analyticsOverride: analyticsOverride,
clientIde: clientIde,
config: config,
);
expect(analytics.clientId, isNot(NoOpAnalytics.staticClientId),
......@@ -55,6 +75,7 @@ void main() {
environment: const <String, String>{},
analyticsOverride: analyticsOverride,
clientIde: clientIde,
config: config,
);
expect(
......@@ -74,6 +95,7 @@ void main() {
environment: const <String, String>{},
analyticsOverride: analyticsOverride,
clientIde: clientIde,
config: config,
);
expect(
......@@ -91,6 +113,7 @@ void main() {
environment: const <String, String>{},
analyticsOverride: analyticsOverride,
clientIde: clientIde,
config: config,
);
expect(
......@@ -108,6 +131,7 @@ void main() {
environment: const <String, String>{'FLUTTER_SUPPRESS_ANALYTICS': 'true'},
analyticsOverride: analyticsOverride,
clientIde: clientIde,
config: config,
);
expect(
......@@ -130,13 +154,14 @@ void main() {
expect(analyticsOverride.sentEvents, hasLength(1));
});
testUsingContext('Client IDE is passed and found in events', () {
testWithoutContext('Client IDE is passed and found in events', () {
final Analytics analytics = getAnalytics(
runningOnBot: false,
flutterVersion: FakeFlutterVersion(),
environment: const <String, String>{},
analyticsOverride: analyticsOverride,
clientIde: clientIde,
config: config,
);
analytics as FakeAnalytics;
......
......@@ -322,6 +322,7 @@ FakeAnalytics getInitializedFakeAnalyticsInstance({
required FileSystem fs,
required FakeFlutterVersion fakeFlutterVersion,
String? clientIde,
String? enabledFeatures,
}) {
final Directory homeDirectory = fs.directory('/');
final FakeAnalytics initialAnalytics = FakeAnalytics(
......@@ -346,6 +347,7 @@ FakeAnalytics getInitializedFakeAnalyticsInstance({
flutterChannel: fakeFlutterVersion.channel,
flutterVersion: fakeFlutterVersion.getVersionString(),
clientIde: clientIde,
enabledFeatures: enabledFeatures,
);
}
......
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