Skip to content

Commit cad578a

Browse files
committed
fix(android): await helper admission for transient capture
1 parent 952d055 commit cad578a

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎packages/platform-android/src/__tests__/text-input-fill.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,6 @@ test('a live text read keeps the resolved identity when its old point covers a s
858858
);
859859
assert.equal(
860860
readAndroidTextAtPointInHierarchy(xml.replace('app-state', 'window-state'), 50, 50, target),
861-
null,
861+
'active',
862862
);
863863
});

‎packages/platform-android/src/automation-helper-fallback.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test.each([undefined, 'true', 'unknown'])(
9191
},
9292
);
9393

94-
test.each([
94+
test.each<Record<string, string>>([
9595
{
9696
ok: 'false',
9797
errorType: 'java.lang.IllegalStateException',

‎packages/platform-android/src/fill-verification.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,14 @@ export function readAndroidTextAtPointInHierarchy(
244244
}
245245
// Reads are point-targeted: a focused sibling may be a different app field or an IME
246246
// composing surface, so it must not override the node that contains the requested point.
247-
return inspectAndroidTextAtPointInHierarchy(xml, x, y).targetInput?.text ?? null;
247+
const pointTarget = inspectAndroidTextAtPointInHierarchy(xml, x, y).targetInput;
248+
if (
249+
!pointTarget ||
250+
(target?.bundleId && pointTarget.packageName !== target.bundleId) ||
251+
(target?.type && pointTarget.className !== target.type)
252+
)
253+
return null;
254+
return pointTarget.text;
248255
}
249256

250257
export function androidFillFailureMessage(verification: AndroidFillVerification | null): string {

‎packages/platform-android/src/snapshot.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ async function captureAndroidUiHierarchyWithHelper(
313313
artifact: AndroidSnapshotHelperArtifact,
314314
): Promise<AndroidUiHierarchyCapture> {
315315
const helperDeviceKey = getAndroidSnapshotHelperSessionDeviceKey(device);
316-
const releaseHelperSession = releasesHelperSessionAfterCapture(options, helperDeviceKey);
316+
const releaseHelperSession = await releasesHelperSessionAfterCapture(options, helperDeviceKey);
317317
try {
318318
return await captureAndroidHelperContentWithinWindow({
319319
options,
@@ -385,11 +385,12 @@ function resolveContentRecaptureDeadlineMs(options: AndroidSnapshotOptions): num
385385
}
386386

387387
/** A transient read keeps a session it found running and releases one it had to start. */
388-
function releasesHelperSessionAfterCapture(
388+
async function releasesHelperSessionAfterCapture(
389389
options: AndroidSnapshotOptions,
390390
helperDeviceKey: string,
391-
): boolean {
392-
if (options.transient) return getLiveAndroidSnapshotHelperSession(helperDeviceKey) === undefined;
391+
): Promise<boolean> {
392+
if (options.transient)
393+
return (await getLiveAndroidSnapshotHelperSession(helperDeviceKey)) === undefined;
393394
return options.helperSessionScope !== 'daemon-session';
394395
}
395396

0 commit comments

Comments
 (0)