Skip to content

fix: remove persisted emulator's data on deviceLost event #4055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/common/definitions/mobile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,12 @@ declare module Mobile {
* @returns {Promise<IStartEmulatorOutput>} Starts the emulator and returns the errors if some error occurs.
*/
startEmulator(options: Mobile.IStartEmulatorOptions): Promise<IStartEmulatorOutput>;

/**
* Called when emulator is lost. Its purpose is to clean any resources used by the instance.
* @returns {void}
*/
detach?(deviceInfo: Mobile.IDeviceInfo): void;
}

interface IStartEmulatorOutput {
Expand Down Expand Up @@ -772,6 +778,11 @@ declare module Mobile {
* @param imageIdentifier - The imagerIdentifier of the emulator.
*/
startEmulatorArgs(imageIdentifier: string): string[];
/**
* Called when emulator is lost. Its purpose is to clean any resources used by the instance.
* @returns {void}
*/
detach?(deviceInfo: Mobile.IDeviceInfo): void;
}

interface IVirtualBoxService {
Expand Down
6 changes: 6 additions & 0 deletions lib/common/mobile/android/android-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
}
}

public detach(): void {
if (this.isEmulator) {
this.$androidEmulatorServices.detach(this.deviceInfo);
}
}

private async getDeviceDetails(shellCommandArgs: string[]): Promise<IAndroidDeviceDetails> {
const parsedDetails: any = {};

Expand Down
4 changes: 4 additions & 0 deletions lib/common/mobile/android/android-emulator-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export class AndroidEmulatorServices implements Mobile.IEmulatorPlatformService
};
}

public detach(deviceInfo: Mobile.IDeviceInfo) {
this.$androidVirtualDeviceService.detach(deviceInfo);
}

private async startEmulatorCore(options: Mobile.IAndroidStartEmulatorOptions): Promise<{runningEmulator: Mobile.IDeviceInfo, errors: string[], endTimeEpoch: number}> {
const timeout = options.timeout || AndroidVirtualDevice.TIMEOUT_SECONDS;
const endTimeEpoch = getCurrentEpochTime() + this.$utils.getMilliSecondsTimeout(timeout);
Expand Down
6 changes: 6 additions & 0 deletions lib/common/mobile/android/android-virtual-device-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ export class AndroidVirtualDeviceService implements Mobile.IAndroidVirtualDevice
});
}

public detach(deviceInfo: Mobile.IDeviceInfo) {
if (this.mapEmulatorIdToImageIdentifier[deviceInfo.identifier]) {
delete this.mapEmulatorIdToImageIdentifier[deviceInfo.identifier];
}
}

private async getEmulatorImagesCore(): Promise<Mobile.IEmulatorImagesOutput> {
let result: ISpawnResult = null;
let devices: Mobile.IDeviceInfo[] = [];
Expand Down