Skip to content

Commit cd944b8

Browse files
committed
Add retry to Android app launch to maybe fix "Unable to resolve Intent"
Still happening maybe 5 times a day, and this will be breaking ADB setup, it'd be nice to retry just to see if waiting a little make this work.
1 parent 7324f55 commit cd944b8

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/interceptors/android/adb-commands.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,34 @@ export async function bringToFront(
331331
await adbClient.shell(deviceId, [
332332
"am", "start", "--activity-single-top", activityName
333333
]);
334+
}
335+
336+
export async function startActivity(
337+
adbClient: adb.AdbClient,
338+
deviceId: string,
339+
options: {
340+
action?: string,
341+
data?: string,
342+
retries?: number
343+
}
344+
): Promise<void> {
345+
const retries = options.retries ?? 0;
346+
347+
try {
348+
await adbClient.startActivity(deviceId, {
349+
wait: true,
350+
action: options.action,
351+
data: options.data
352+
});
353+
} catch (e) {
354+
if (retries <= 0) throw e;
355+
else {
356+
await delay(1000);
357+
358+
return startActivity(adbClient, deviceId, {
359+
...options,
360+
retries: retries - 1
361+
});
362+
}
363+
}
334364
}

src/interceptors/android/android-adb-interceptor.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
stringAsStream,
1818
hasCertInstalled,
1919
bringToFront,
20-
setChromeFlags
20+
setChromeFlags,
21+
startActivity
2122
} from './adb-commands';
2223
import { streamLatestApk, clearAllApks } from './fetch-apk';
2324
import { parseCert, getCertificateFingerprint, getCertificateSubjectHash } from '../../certificates';
@@ -109,10 +110,10 @@ export class AndroidAdbInterceptor implements Interceptor {
109110
await this.adbClient.reverse(options.deviceId, 'tcp:' + proxyPort, 'tcp:' + proxyPort).catch(() => {});
110111

111112
// Use ADB to launch the app with the proxy details
112-
await this.adbClient.startActivity(options.deviceId, {
113-
wait: true,
113+
await startActivity(this.adbClient, options.deviceId, {
114114
action: 'tech.httptoolkit.android.ACTIVATE',
115-
data: `https://android.httptoolkit.tech/connect/?data=${intentData}`
115+
data: `https://android.httptoolkit.tech/connect/?data=${intentData}`,
116+
retries: 10
116117
});
117118

118119
this.deviceProxyMapping[proxyPort] = this.deviceProxyMapping[proxyPort] || [];

0 commit comments

Comments
 (0)