mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Handles parsing APK manifests with additional namespaces or attributes (#34535)
This commit is contained in:
parent
5f521eea22
commit
07dc236237
@ -490,15 +490,16 @@ class ApkManifestData {
|
||||
final List<String> lines = data.split('\n');
|
||||
assert(lines.length > 3);
|
||||
|
||||
final _Element manifest = _Element.fromLine(lines[1], null);
|
||||
final int manifestLine = lines.indexWhere((String line) => line.contains('E: manifest'));
|
||||
final _Element manifest = _Element.fromLine(lines[manifestLine], null);
|
||||
_Element currentElement = manifest;
|
||||
|
||||
for (String line in lines.skip(2)) {
|
||||
for (String line in lines.skip(manifestLine)) {
|
||||
final String trimLine = line.trimLeft();
|
||||
final int level = line.length - trimLine.length;
|
||||
|
||||
// Handle level out
|
||||
while (level <= currentElement.level) {
|
||||
while (currentElement.parent != null && level <= currentElement.level) {
|
||||
currentElement = currentElement.parent;
|
||||
}
|
||||
|
||||
|
||||
@ -138,12 +138,21 @@ void main() {
|
||||
expect(data.packageName, 'io.flutter.examples.hello_world');
|
||||
expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity2');
|
||||
}, overrides: noColorTerminalOverride);
|
||||
|
||||
testUsingContext('Parses manifest with an Activity that has no value for its enabled field, action set to android.intent.action.MAIN and category set to android.intent.category.LAUNCHER', () {
|
||||
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithDefaultEnabledAndMainLauncherActivity);
|
||||
expect(data, isNotNull);
|
||||
expect(data.packageName, 'io.flutter.examples.hello_world');
|
||||
expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity2');
|
||||
}, overrides: noColorTerminalOverride);
|
||||
|
||||
testUsingContext('Parses manifest with a dist namespace', () {
|
||||
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithDistNamespace);
|
||||
expect(data, isNotNull);
|
||||
expect(data.packageName, 'io.flutter.examples.hello_world');
|
||||
expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity');
|
||||
}, overrides: noColorTerminalOverride);
|
||||
|
||||
testUsingContext('Error when parsing manifest with no Activity that has enabled set to true nor has no value for its enabled field', () {
|
||||
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithNoEnabledActivity);
|
||||
expect(data, isNull);
|
||||
@ -151,6 +160,7 @@ void main() {
|
||||
expect(
|
||||
logger.errorText, 'Error running io.flutter.examples.hello_world. Default activity not found\n');
|
||||
}, overrides: noColorTerminalOverride);
|
||||
|
||||
testUsingContext('Error when parsing manifest with no Activity that has action set to android.intent.action.MAIN', () {
|
||||
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithNoMainActivity);
|
||||
expect(data, isNull);
|
||||
@ -158,6 +168,7 @@ void main() {
|
||||
expect(
|
||||
logger.errorText, 'Error running io.flutter.examples.hello_world. Default activity not found\n');
|
||||
}, overrides: noColorTerminalOverride);
|
||||
|
||||
testUsingContext('Error when parsing manifest with no Activity that has category set to android.intent.category.LAUNCHER', () {
|
||||
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithNoLauncherActivity);
|
||||
expect(data, isNull);
|
||||
@ -174,6 +185,7 @@ void main() {
|
||||
Platform: _kNoColorTerminalPlatform,
|
||||
OperatingSystemUtils: () => MockOperatingSystemUtils(),
|
||||
};
|
||||
|
||||
testUsingContext('Error on non-existing file', () {
|
||||
final PrebuiltIOSApp iosApp =
|
||||
IOSApp.fromPrebuiltApp(fs.file('not_existing.ipa'));
|
||||
@ -184,6 +196,7 @@ void main() {
|
||||
'File "not_existing.ipa" does not exist. Use an app bundle or an ipa.\n',
|
||||
);
|
||||
}, overrides: overrides);
|
||||
|
||||
testUsingContext('Error on non-app-bundle folder', () {
|
||||
fs.directory('regular_folder').createSync();
|
||||
final PrebuiltIOSApp iosApp =
|
||||
@ -193,6 +206,7 @@ void main() {
|
||||
expect(
|
||||
logger.errorText, 'Folder "regular_folder" is not an app bundle.\n');
|
||||
}, overrides: overrides);
|
||||
|
||||
testUsingContext('Error on no info.plist', () {
|
||||
fs.directory('bundle.app').createSync();
|
||||
final PrebuiltIOSApp iosApp = IOSApp.fromPrebuiltApp(fs.file('bundle.app'));
|
||||
@ -203,6 +217,7 @@ void main() {
|
||||
'Invalid prebuilt iOS app. Does not contain Info.plist.\n',
|
||||
);
|
||||
}, overrides: overrides);
|
||||
|
||||
testUsingContext('Error on bad info.plist', () {
|
||||
fs.directory('bundle.app').createSync();
|
||||
fs.file('bundle.app/Info.plist').writeAsStringSync(badPlistData);
|
||||
@ -215,6 +230,7 @@ void main() {
|
||||
'Invalid prebuilt iOS app. Info.plist does not contain bundle identifier\n'),
|
||||
);
|
||||
}, overrides: overrides);
|
||||
|
||||
testUsingContext('Success with app bundle', () {
|
||||
fs.directory('bundle.app').createSync();
|
||||
fs.file('bundle.app/Info.plist').writeAsStringSync(plistData);
|
||||
@ -225,6 +241,7 @@ void main() {
|
||||
expect(iosApp.id, 'fooBundleId');
|
||||
expect(iosApp.bundleName, 'bundle.app');
|
||||
}, overrides: overrides);
|
||||
|
||||
testUsingContext('Bad ipa zip-file, no payload dir', () {
|
||||
fs.file('app.ipa').createSync();
|
||||
when(os.unzip(fs.file('app.ipa'), any)).thenAnswer((Invocation _) { });
|
||||
@ -236,6 +253,7 @@ void main() {
|
||||
'Invalid prebuilt iOS ipa. Does not contain a "Payload" directory.\n',
|
||||
);
|
||||
}, overrides: overrides);
|
||||
|
||||
testUsingContext('Bad ipa zip-file, two app bundles', () {
|
||||
fs.file('app.ipa').createSync();
|
||||
when(os.unzip(any, any)).thenAnswer((Invocation invocation) {
|
||||
@ -257,6 +275,7 @@ void main() {
|
||||
expect(logger.errorText,
|
||||
'Invalid prebuilt iOS ipa. Does not contain a single app bundle.\n');
|
||||
}, overrides: overrides);
|
||||
|
||||
testUsingContext('Success with ipa', () {
|
||||
fs.file('app.ipa').createSync();
|
||||
when(os.unzip(any, any)).thenAnswer((Invocation invocation) {
|
||||
@ -313,6 +332,7 @@ void main() {
|
||||
Platform: _kNoColorTerminalPlatform,
|
||||
OperatingSystemUtils: () => MockOperatingSystemUtils(),
|
||||
};
|
||||
|
||||
testUsingContext('Error on non-existing file', () {
|
||||
final PrebuiltFuchsiaApp fuchsiaApp =
|
||||
FuchsiaApp.fromPrebuiltApp(fs.file('not_existing.far'));
|
||||
@ -521,6 +541,42 @@ const String _aaptDataWithNoLauncherActivity =
|
||||
E: action (line=43)
|
||||
A: android:name(0x01010003)="android.intent.action.MAIN" (Raw: "android.intent.action.MAIN")''';
|
||||
|
||||
const String _aaptDataWithDistNamespace =
|
||||
'''N: android=http://schemas.android.com/apk/res/android
|
||||
N: dist=http://schemas.android.com/apk/distribution
|
||||
E: manifest (line=7)
|
||||
A: android:versionCode(0x0101021b)=(type 0x10)0x1
|
||||
A: android:versionName(0x0101021c)="1.0" (Raw: "1.0")
|
||||
A: android:compileSdkVersion(0x01010572)=(type 0x10)0x1c
|
||||
A: android:compileSdkVersionCodename(0x01010573)="9" (Raw: "9")
|
||||
A: package="io.flutter.examples.hello_world" (Raw: "io.flutter.examples.hello_world")
|
||||
A: platformBuildVersionCode=(type 0x10)0x1
|
||||
A: platformBuildVersionName=(type 0x4)0x3f800000
|
||||
E: uses-sdk (line=13)
|
||||
A: android:minSdkVersion(0x0101020c)=(type 0x10)0x10
|
||||
A: android:targetSdkVersion(0x01010270)=(type 0x10)0x1c
|
||||
E: dist:module (line=17)
|
||||
A: dist:instant=(type 0x12)0xffffffff
|
||||
E: uses-permission (line=24)
|
||||
A: android:name(0x01010003)="android.permission.INTERNET" (Raw: "android.permission.INTERNET")
|
||||
E: application (line=32)
|
||||
A: android:label(0x01010001)="hello_world" (Raw: "hello_world")
|
||||
A: android:icon(0x01010002)=@0x7f010000
|
||||
A: android:name(0x01010003)="io.flutter.app.FlutterApplication" (Raw: "io.flutter.app.FlutterApplication")
|
||||
E: activity (line=36)
|
||||
A: android:theme(0x01010000)=@0x01030009
|
||||
A: android:name(0x01010003)="io.flutter.examples.hello_world.MainActivity" (Raw: "io.flutter.examples.hello_world.MainActivity")
|
||||
A: android:launchMode(0x0101001d)=(type 0x10)0x1
|
||||
A: android:configChanges(0x0101001f)=(type 0x11)0x400037b4
|
||||
A: android:windowSoftInputMode(0x0101022b)=(type 0x11)0x10
|
||||
A: android:hardwareAccelerated(0x010102d3)=(type 0x12)0xffffffff
|
||||
E: intent-filter (line=43)
|
||||
E: action (line=44)
|
||||
A: android:name(0x01010003)="android.intent.action.MAIN" (Raw: "android.intent.action.MAIN")
|
||||
E: category (line=46)
|
||||
A: android:name(0x01010003)="android.intent.category.LAUNCHER" (Raw: "android.intent.category.LAUNCHER")
|
||||
''';
|
||||
|
||||
|
||||
class MockIosWorkFlow extends Mock implements IOSWorkflow {
|
||||
@override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user