[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:
2026-11-17 18:57:14 +01:00
parent a93ef09956
commit 9e3d389f82
7 changed files with 208 additions and 39 deletions
+36 -18
View File
@@ -80,7 +80,11 @@ async function firstVisit(page: Page): Promise<void> {
/** After the app was closed and opened again: she is still watered. */
async function secondVisit(page: Page): Promise<void> {
await garden(page);
await page.getByRole('button', { name: en.rose.numbers }).click();
// By keyboard: on the tablet a pointer click once waited 30 s for the button to stop moving
// while the garden animated (review). Enter is a real activation, as for a keyboard player.
const numbers = page.getByRole('button', { name: en.rose.numbers });
await numbers.focus();
await numbers.press('Enter');
await expect(page.locator('#rose-numbers')).toContainText(`${en.rose.daysOfCare}1`);
await storedCare(page, 1);
report['afterRestart'] = 'still watered: 1 day of care, the care log kept';
@@ -157,35 +161,49 @@ async function desktop(exe: string): Promise<void> {
}
async function androidDevice(serial: string | undefined): Promise<void> {
// The USB link to a real tablet drops now and then ("device offline"); a dropped link is waited
// for and the command tried again, up to three times. A command that fails for another reason
// fails the check at once.
const adb = (...args: string[]): string => {
const r = spawnSync('adb', [...(serial ? ['-s', serial] : []), ...args], { encoding: 'utf8' });
if (r.status !== 0) throw new Error(`adb ${args.join(' ')} failed: ${r.stderr}`);
return r.stdout;
const target = serial ? ['-s', serial] : [];
for (let attempt = 1; ; attempt++) {
const r = spawnSync('adb', [...target, ...args], { encoding: 'utf8' });
if (r.status === 0) return r.stdout;
const dropped = /offline|closed|not found|no devices/i.test(r.stderr);
if (!dropped || attempt === 3) throw new Error(`adb ${args.join(' ')} failed: ${r.stderr}`);
spawnSync('adb', [...target, 'wait-for-device'], { timeout: 30_000 });
}
};
// Playwright's handle to the device dies with the link, so it is found again for each visit.
const open = async (): Promise<{ page: Page; close: () => Promise<void> }> => {
adb('wait-for-device');
const devices = await android.devices();
const device = serial ? devices.find((d) => d.serial() === serial) : devices[0];
if (!device) throw new Error('no Android device over adb');
report['device'] = `${device.model()} (${device.serial()})`;
adb('shell', 'monkey', '-p', PACKAGE_ID, '-c', 'android.intent.category.LAUNCHER', '1');
const webView = await device.webView({ pkg: PACKAGE_ID }, { timeout: 30_000 });
return { page: await webView.page(), close: () => device.close() };
};
const devices = await android.devices();
const device = serial ? devices.find((d) => d.serial() === serial) : devices[0];
if (!device) throw new Error('no Android device over adb');
report['device'] = `${device.model()} (${device.serial()})`;
const dump = adb('shell', 'dumpsys', 'package', PACKAGE_ID);
if (!dump.includes(`Package [${PACKAGE_ID}]`)) throw new Error(`${PACKAGE_ID} is not installed; adb install -r <apk>`);
report['internetPermission'] = /android\.permission\.INTERNET/.test(dump);
report['allowBackupFlag'] = /flags=\[[^\]]*ALLOW_BACKUP/.test(dump);
let session: { page: Page; close: () => Promise<void> } | undefined;
try {
adb('shell', 'pm', 'clear', PACKAGE_ID);
adb('shell', 'monkey', '-p', PACKAGE_ID, '-c', 'android.intent.category.LAUNCHER', '1');
let webView = await device.webView({ pkg: PACKAGE_ID }, { timeout: 30_000 });
let page = await webView.page();
await firstVisit(page);
session = await open();
await firstVisit(session.page);
await session.close();
adb('shell', 'am', 'force-stop', PACKAGE_ID);
await new Promise((r) => setTimeout(r, 1500));
adb('shell', 'monkey', '-p', PACKAGE_ID, '-c', 'android.intent.category.LAUNCHER', '1');
webView = await device.webView({ pkg: PACKAGE_ID }, { timeout: 30_000 });
page = await webView.page();
await secondVisit(page);
await trySave(page);
session = await open();
await secondVisit(session.page);
await trySave(session.page);
} finally {
adb('shell', 'am', 'force-stop', PACKAGE_ID);
await device.close();
await session?.close().catch((error: unknown) => console.error('check-garden: closing the device handle failed', error));
}
}