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>( ...@@ -94,6 +94,7 @@ Future<T> runInContext<T>(
flutterVersion: globals.flutterVersion, flutterVersion: globals.flutterVersion,
environment: globals.platform.environment, environment: globals.platform.environment,
clientIde: globals.platform.environment['FLUTTER_HOST'], clientIde: globals.platform.environment['FLUTTER_HOST'],
config: globals.config,
), ),
AndroidBuilder: () => AndroidGradleBuilder( AndroidBuilder: () => AndroidGradleBuilder(
java: globals.java, java: globals.java,
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
import 'package:unified_analytics/unified_analytics.dart'; import 'package:unified_analytics/unified_analytics.dart';
import '../base/config.dart';
import '../base/io.dart'; import '../base/io.dart';
import '../features.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
import '../version.dart'; import '../version.dart';
...@@ -22,6 +24,7 @@ Analytics getAnalytics({ ...@@ -22,6 +24,7 @@ Analytics getAnalytics({
required FlutterVersion flutterVersion, required FlutterVersion flutterVersion,
required Map<String, String> environment, required Map<String, String> environment,
required String? clientIde, required String? clientIde,
required Config config,
bool enableAsserts = false, bool enableAsserts = false,
FakeAnalytics? analyticsOverride, FakeAnalytics? analyticsOverride,
}) { }) {
...@@ -52,9 +55,24 @@ Analytics getAnalytics({ ...@@ -52,9 +55,24 @@ Analytics getAnalytics({
dartVersion: flutterVersion.dartSdkVersion, dartVersion: flutterVersion.dartSdkVersion,
enableAsserts: enableAsserts, enableAsserts: enableAsserts,
clientIde: clientIde, 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]. /// Function to safely grab the max rss from [ProcessInfo].
int? getMaxRss(ProcessInfo processInfo) { int? getMaxRss(ProcessInfo processInfo) {
try { try {
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:file/memory.dart'; 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/base/file_system.dart';
import 'package:flutter_tools/src/reporting/unified_analytics.dart'; import 'package:flutter_tools/src/reporting/unified_analytics.dart';
import 'package:unified_analytics/unified_analytics.dart'; import 'package:unified_analytics/unified_analytics.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart';
import '../src/fakes.dart'; import '../src/fakes.dart';
void main() { void main() {
...@@ -16,10 +16,12 @@ void main() { ...@@ -16,10 +16,12 @@ void main() {
const String clientIde = 'VSCode'; const String clientIde = 'VSCode';
late FileSystem fs; late FileSystem fs;
late Config config;
late FakeAnalytics analyticsOverride; late FakeAnalytics analyticsOverride;
setUp(() { setUp(() {
fs = MemoryFileSystem.test(); fs = MemoryFileSystem.test();
config = Config.test();
analyticsOverride = getInitializedFakeAnalyticsInstance( analyticsOverride = getInitializedFakeAnalyticsInstance(
fs: fs, fs: fs,
...@@ -30,14 +32,32 @@ void main() { ...@@ -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', () { group('Unit testing getAnalytics', () {
testWithoutContext('Successfully creates the instance for standard branch', () { testWithoutContext('Successfully creates the instance for standard branch',
() {
final Analytics analytics = getAnalytics( final Analytics analytics = getAnalytics(
runningOnBot: false, runningOnBot: false,
flutterVersion: FakeFlutterVersion(), flutterVersion: FakeFlutterVersion(),
environment: const <String, String>{}, environment: const <String, String>{},
analyticsOverride: analyticsOverride, analyticsOverride: analyticsOverride,
clientIde: clientIde, clientIde: clientIde,
config: config,
); );
expect(analytics.clientId, isNot(NoOpAnalytics.staticClientId), expect(analytics.clientId, isNot(NoOpAnalytics.staticClientId),
...@@ -55,6 +75,7 @@ void main() { ...@@ -55,6 +75,7 @@ void main() {
environment: const <String, String>{}, environment: const <String, String>{},
analyticsOverride: analyticsOverride, analyticsOverride: analyticsOverride,
clientIde: clientIde, clientIde: clientIde,
config: config,
); );
expect( expect(
...@@ -74,6 +95,7 @@ void main() { ...@@ -74,6 +95,7 @@ void main() {
environment: const <String, String>{}, environment: const <String, String>{},
analyticsOverride: analyticsOverride, analyticsOverride: analyticsOverride,
clientIde: clientIde, clientIde: clientIde,
config: config,
); );
expect( expect(
...@@ -91,6 +113,7 @@ void main() { ...@@ -91,6 +113,7 @@ void main() {
environment: const <String, String>{}, environment: const <String, String>{},
analyticsOverride: analyticsOverride, analyticsOverride: analyticsOverride,
clientIde: clientIde, clientIde: clientIde,
config: config,
); );
expect( expect(
...@@ -108,6 +131,7 @@ void main() { ...@@ -108,6 +131,7 @@ void main() {
environment: const <String, String>{'FLUTTER_SUPPRESS_ANALYTICS': 'true'}, environment: const <String, String>{'FLUTTER_SUPPRESS_ANALYTICS': 'true'},
analyticsOverride: analyticsOverride, analyticsOverride: analyticsOverride,
clientIde: clientIde, clientIde: clientIde,
config: config,
); );
expect( expect(
...@@ -130,13 +154,14 @@ void main() { ...@@ -130,13 +154,14 @@ void main() {
expect(analyticsOverride.sentEvents, hasLength(1)); 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( final Analytics analytics = getAnalytics(
runningOnBot: false, runningOnBot: false,
flutterVersion: FakeFlutterVersion(), flutterVersion: FakeFlutterVersion(),
environment: const <String, String>{}, environment: const <String, String>{},
analyticsOverride: analyticsOverride, analyticsOverride: analyticsOverride,
clientIde: clientIde, clientIde: clientIde,
config: config,
); );
analytics as FakeAnalytics; analytics as FakeAnalytics;
......
...@@ -322,6 +322,7 @@ FakeAnalytics getInitializedFakeAnalyticsInstance({ ...@@ -322,6 +322,7 @@ FakeAnalytics getInitializedFakeAnalyticsInstance({
required FileSystem fs, required FileSystem fs,
required FakeFlutterVersion fakeFlutterVersion, required FakeFlutterVersion fakeFlutterVersion,
String? clientIde, String? clientIde,
String? enabledFeatures,
}) { }) {
final Directory homeDirectory = fs.directory('/'); final Directory homeDirectory = fs.directory('/');
final FakeAnalytics initialAnalytics = FakeAnalytics( final FakeAnalytics initialAnalytics = FakeAnalytics(
...@@ -346,6 +347,7 @@ FakeAnalytics getInitializedFakeAnalyticsInstance({ ...@@ -346,6 +347,7 @@ FakeAnalytics getInitializedFakeAnalyticsInstance({
flutterChannel: fakeFlutterVersion.channel, flutterChannel: fakeFlutterVersion.channel,
flutterVersion: fakeFlutterVersion.getVersionString(), flutterVersion: fakeFlutterVersion.getVersionString(),
clientIde: clientIde, 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