Skip to content

Commit

Permalink
Restart app process on Android when launching app (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmagiera authored Oct 15, 2024
1 parent 65cf1e9 commit 61d200c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ export class AndroidEmulatorDevice extends DeviceBase {
if (build.platform !== DevicePlatform.Android) {
throw new Error("Invalid platform");
}
// terminate the app before launching, otherwise launch commands won't actually start the process which
// may be in a bad state
await exec(ADB_PATH, ["-s", this.serial!, "shell", "am", "force-stop", build.packageName]);

const deepLinkChoice =
build.packageName === EXPO_GO_PACKAGE_NAME ? "expo-go" : "expo-dev-client";
const expoDeeplink = await fetchExpoLaunchDeeplink(metroPort, "android", deepLinkChoice);
Expand Down
13 changes: 10 additions & 3 deletions packages/vscode-extension/src/project/deviceSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,24 @@ export class DeviceSession implements Disposable {
Logger.debug("Will wait for app ready and for preview");
this.eventDelegate.onStateChange(StartupMessage.WaitingForAppToLoad);

let previewURL: string | undefined;
if (shouldWaitForAppLaunch) {
const reportWaitingStuck = setTimeout(() => {
Logger.info("App is taking very long to boot up, it might be stuck");
Logger.info(
"App is taking very long to boot up, it might be stuck. Device preview URL:",
previewURL
);
getTelemetryReporter().sendTelemetryEvent("app:launch:waiting-stuck", {
platform: this.device.platform,
});
}, 30000);
waitForAppReady.then(() => clearTimeout(reportWaitingStuck));
}

const [previewUrl] = await Promise.all([this.device.startPreview(), waitForAppReady]);
await Promise.all([
this.device.startPreview().then((url) => (previewURL = url)),
waitForAppReady,
]);
Logger.debug("App and preview ready, moving on...");
this.eventDelegate.onStateChange(StartupMessage.AttachingDebugger);
await this.startDebugger();
Expand All @@ -151,7 +158,7 @@ export class DeviceSession implements Disposable {
{ durationSec: launchDurationSec }
);

return previewUrl;
return previewURL!;
}

private async bootDevice(deviceSettings: DeviceSettings) {
Expand Down

0 comments on commit 61d200c

Please sign in to comment.