[tauri] TauriPlatforms: Read the built APK's own values, carry Rosea's launcher icon into gen/android, survive a dropped USB link
This commit is contained in:
@@ -156,21 +156,25 @@ export function ruleProblems(xml: string, sections: readonly string[]): string[]
|
||||
*/
|
||||
export function apkProblems(permissions: string, manifestTree: string): string[] {
|
||||
const problems: string[] = [];
|
||||
const asked = [...permissions.matchAll(/uses-permission: name='([^']+)'/g)].map((m) => m[1]!);
|
||||
// Tauri's stock app asks for nothing else today; a new one is a review question, not a pass.
|
||||
const allowed = new Set<string>([]);
|
||||
for (const name of asked) {
|
||||
if (name.endsWith('.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION')) continue; // androidx's own, signature-level
|
||||
if (!allowed.has(name)) problems.push(`the APK asks for ${name}`);
|
||||
const tree = manifestTree.replaceAll('\r\n', '\n');
|
||||
const pkg = /^package: (\S+)$/m.exec(permissions.replaceAll('\r\n', '\n'))?.[1];
|
||||
for (const m of permissions.matchAll(/uses-permission: name='([^']+)'/g)) {
|
||||
const name = m[1]!;
|
||||
// androidx's receiver guard: a signature permission the app declares for itself, granting nothing.
|
||||
if (pkg !== undefined && name === `${pkg}.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION`) continue;
|
||||
// Any other is a review question, not a pass: Rosea asks for no permission yet.
|
||||
problems.push(`the APK asks for ${name}`);
|
||||
}
|
||||
if (!/allowBackup\([^)]*\)=false/.test(manifestTree)) problems.push('the APK does not set allowBackup=false');
|
||||
if (!/:allowBackup\(0x[0-9a-f]+\)=false$/m.test(tree)) problems.push('the APK does not set allowBackup=false');
|
||||
for (const [name, value] of Object.entries(META_DATA)) {
|
||||
const at = manifestTree.indexOf(`"${name}"`);
|
||||
if (at < 0) problems.push(`the APK has no meta-data ${name}`);
|
||||
else if (!manifestTree.slice(at, at + 300).includes(value === 'true' ? '=true' : '=false') &&
|
||||
!manifestTree.slice(at, at + 300).includes(`"${value}"`)) {
|
||||
problems.push(`the APK's meta-data ${name} is not ${value}`);
|
||||
}
|
||||
// aapt2 prints a meta-data element's name attribute, then its value attribute on the next line:
|
||||
// A: http://schemas.android.com/apk/res/android:name(0x01010003)="<name>" (Raw: "<name>")
|
||||
// A: http://schemas.android.com/apk/res/android:value(0x01010024)=true
|
||||
const found = new RegExp(
|
||||
`:name\\(0x[0-9a-f]+\\)="${escape(name)}"[^\\n]*\\n\\s*A: [^\\n]*:value\\(0x[0-9a-f]+\\)=(\\S+)`
|
||||
).exec(tree);
|
||||
if (!found) problems.push(`the APK has no meta-data ${name}`);
|
||||
else if (found[1] !== value && found[1] !== `"${value}"`) problems.push(`the APK's meta-data ${name} is ${found[1]}, not ${value}`);
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user