Skip to content

Commit 696df77

Browse files
committed
perf(android-tools): skip loading Android mechanics when app-bundle identity is known
inferOpenedAppBundleId always loaded Android mechanics before delegating, even when currentAppBundleId already made the delegate's own fast-return a no-op. Check it first so the load is skipped entirely once the identity is already known, and add a regression test asserting the loader is never called in that case. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0167UVzrdzVMCZqXgxtzWoTD
1 parent 03f3564 commit 696df77

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎src/__tests__/platform-runtime-android-application-tools-infer-open-target.test.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test, vi } from 'vitest';
1+
import { beforeEach, expect, test, vi } from 'vitest';
22
import type { DeviceInfo } from '@agent-device/kernel/device';
33

44
vi.mock('../platform-runtime-android-mechanics.ts', () => ({
@@ -7,8 +7,15 @@ vi.mock('../platform-runtime-android-mechanics.ts', () => ({
77
}),
88
}));
99

10+
import { loadAndroidMechanics } from '../platform-runtime-android-mechanics.ts';
1011
import { createAndroidApplicationTools } from '../platform-runtime-android-application-tools.ts';
1112

13+
const mockLoadAndroidMechanics = vi.mocked(loadAndroidMechanics);
14+
15+
beforeEach(() => {
16+
mockLoadAndroidMechanics.mockClear();
17+
});
18+
1219
const device: DeviceInfo = {
1320
platform: 'android',
1421
id: 'emulator-5554',
@@ -22,3 +29,14 @@ test('inferOpenedAppBundleId stays best-effort when Android mechanics fails to l
2229
createAndroidApplicationTools().inferOpenedAppBundleId(device, undefined, undefined),
2330
).resolves.toBeUndefined();
2431
});
32+
33+
test('inferOpenedAppBundleId skips loading Android mechanics when the app-bundle identity is already known', async () => {
34+
await expect(
35+
createAndroidApplicationTools().inferOpenedAppBundleId(
36+
device,
37+
'exp://127.0.0.1:8082',
38+
'com.example.demo',
39+
),
40+
).resolves.toBe('com.example.demo');
41+
expect(mockLoadAndroidMechanics).not.toHaveBeenCalled();
42+
});

‎src/platform-runtime-android-application-tools.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function createAndroidApplicationTools(): AndroidApplicationTools {
2525
return Object.freeze({
2626
resolveOpenTarget: async (device, input) => await resolveAndroidOpenTarget(device, input),
2727
inferOpenedAppBundleId: async (device, target, currentAppBundleId) => {
28+
if (currentAppBundleId) return currentAppBundleId;
2829
try {
2930
const { inferAndroidPackageAfterOpen } = await loadAndroidMechanics();
3031
return await inferAndroidPackageAfterOpen(device, target, currentAppBundleId);

0 commit comments

Comments
 (0)