Read AndroidManifest.xml and emit manifest-impeller-(enabled|disabled) analytics (#150791)

Work towards https://github.com/flutter/flutter/issues/132712.

After this PR, after a completed `flutter build apk` command, we:

- Emit a `manifest-impeller-disabled` command if `io.flutter.embedding.android.EnableImpeller` is `'false'`.
- Emit a `manifest-impeller-disabled` command if `io.flutter.embedding.android.EnableImpeller` is _missing_.
- Emit a `manifest-impeller-enabled` command if `io.flutter.embedding.android.EnableImpeller` is `'true'`.

We will need to change the default (see `_impellerEnabledByDefault` in `project.dart`) before releasing, otherwise we will misreport `manifest-impeller-disabled` at a much higher rate than actual. If there is a way to instead compute the default instead of hard-coding, that would have been good.

See <https://docs.flutter.dev/perf/impeller#android> for details on the key-value pair.

---

I also did a tad of TLC, by removing the (now-defunct) `Usage` events for `flutter build ios`, so they are consistent.

/cc @zanderso, @chinmaygarde, @jonahwilliams
This commit is contained in:
Matan Lurey
2024-06-25 15:41:23 -07:00
committed by GitHub
parent 9afd397cd4
commit a6a8caaa73
5 changed files with 166 additions and 24 deletions

View File

@@ -621,14 +621,6 @@ void main() {
const <String>['build', 'ios', '--no-pub']
);
expect(usage.events, contains(
const TestUsageEvent(
'build', 'ios',
label:'plist-impeller-enabled',
parameters:CustomDimensions(),
),
));
expect(fakeAnalytics.sentEvents, contains(
Event.flutterBuildInfo(
label: 'plist-impeller-enabled',
@@ -684,14 +676,6 @@ void main() {
const <String>['build', 'ios', '--no-pub']
);
expect(usage.events, contains(
const TestUsageEvent(
'build', 'ios',
label:'plist-impeller-disabled',
parameters:CustomDimensions(),
),
));
expect(fakeAnalytics.sentEvents, contains(
Event.flutterBuildInfo(
label: 'plist-impeller-disabled',

View File

@@ -127,6 +127,120 @@ void main() {
AndroidBuilder: () => FakeAndroidBuilder(),
Usage: () => testUsage,
});
group('Impeller AndroidManifest.xml setting', () {
// Adds a key-value `<meta-data>` pair to the `<application>` tag in the
// cooresponding `AndroidManifest.xml` file, right before the closing
// `</application>` tag.
void writeManifestMetadata({
required String projectPath,
required String name,
required String value,
}) {
final String manifestPath = globals.fs.path.join(
projectPath,
'android',
'app',
'src',
'main',
'AndroidManifest.xml',
);
// It would be unnecessarily complicated to parse this XML file and
// insert the key-value pair, so we just insert it right before the
// closing </application> tag.
final String oldManifest = globals.fs.file(manifestPath).readAsStringSync();
final String newManifest = oldManifest.replaceFirst(
'</application>',
' <meta-data\n'
' android:name="$name"\n'
' android:value="$value" />\n'
' </application>',
);
globals.fs.file(manifestPath).writeAsStringSync(newManifest);
}
testUsingContext('a default APK build reports Impeller as disabled', () async {
final String projectPath = await createProject(
tempDir,
arguments: <String>['--no-pub', '--template=app', '--platform=android']
);
await runBuildApkCommand(projectPath);
expect(
fakeAnalytics.sentEvents,
contains(
Event.flutterBuildInfo(
label: 'manifest-impeller-disabled',
buildType: 'android',
),
),
);
}, overrides: <Type, Generator>{
Analytics: () => fakeAnalytics,
AndroidBuilder: () => FakeAndroidBuilder(),
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
});
testUsingContext('EnableImpeller="true" reports an enabled event', () async {
final String projectPath = await createProject(
tempDir,
arguments: <String>['--no-pub', '--template=app', '--platform=android']
);
writeManifestMetadata(
projectPath: projectPath,
name: 'io.flutter.embedding.android.EnableImpeller',
value: 'true',
);
await runBuildApkCommand(projectPath);
expect(
fakeAnalytics.sentEvents,
contains(
Event.flutterBuildInfo(
label: 'manifest-impeller-enabled',
buildType: 'android',
),
),
);
}, overrides: <Type, Generator>{
Analytics: () => fakeAnalytics,
AndroidBuilder: () => FakeAndroidBuilder(),
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
});
testUsingContext('EnableImpeller="false" reports an disabled event', () async {
final String projectPath = await createProject(
tempDir,
arguments: <String>['--no-pub', '--template=app', '--platform=android']
);
writeManifestMetadata(
projectPath: projectPath,
name: 'io.flutter.embedding.android.EnableImpeller',
value: 'false',
);
await runBuildApkCommand(projectPath);
expect(
fakeAnalytics.sentEvents,
contains(
Event.flutterBuildInfo(
label: 'manifest-impeller-disabled',
buildType: 'android',
),
),
);
}, overrides: <Type, Generator>{
Analytics: () => fakeAnalytics,
AndroidBuilder: () => FakeAndroidBuilder(),
FlutterProjectFactory: () => FakeFlutterProjectFactory(tempDir),
});
});
});
group('Gradle', () {