Skip to content

Commit 76a362f

Browse files
author
Fatme
authored
Merge pull request #4055 from NativeScript/fatme/fix-emulator-lost
fix: remove persisted emulator's data on deviceLost event
2 parents 3527ef2 + a60b0aa commit 76a362f

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

lib/common/definitions/mobile.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,12 @@ declare module Mobile {
730730
* @returns {Promise<IStartEmulatorOutput>} Starts the emulator and returns the errors if some error occurs.
731731
*/
732732
startEmulator(options: Mobile.IStartEmulatorOptions): Promise<IStartEmulatorOutput>;
733+
734+
/**
735+
* Called when emulator is lost. Its purpose is to clean any resources used by the instance.
736+
* @returns {void}
737+
*/
738+
detach?(deviceInfo: Mobile.IDeviceInfo): void;
733739
}
734740

735741
interface IStartEmulatorOutput {
@@ -772,6 +778,11 @@ declare module Mobile {
772778
* @param imageIdentifier - The imagerIdentifier of the emulator.
773779
*/
774780
startEmulatorArgs(imageIdentifier: string): string[];
781+
/**
782+
* Called when emulator is lost. Its purpose is to clean any resources used by the instance.
783+
* @returns {void}
784+
*/
785+
detach?(deviceInfo: Mobile.IDeviceInfo): void;
775786
}
776787

777788
interface IVirtualBoxService {

lib/common/mobile/android/android-device.ts

+6
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
121121
}
122122
}
123123

124+
public detach(): void {
125+
if (this.isEmulator) {
126+
this.$androidEmulatorServices.detach(this.deviceInfo);
127+
}
128+
}
129+
124130
private async getDeviceDetails(shellCommandArgs: string[]): Promise<IAndroidDeviceDetails> {
125131
const parsedDetails: any = {};
126132

lib/common/mobile/android/android-emulator-services.ts

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export class AndroidEmulatorServices implements Mobile.IEmulatorPlatformService
5959
};
6060
}
6161

62+
public detach(deviceInfo: Mobile.IDeviceInfo) {
63+
this.$androidVirtualDeviceService.detach(deviceInfo);
64+
}
65+
6266
private async startEmulatorCore(options: Mobile.IAndroidStartEmulatorOptions): Promise<{runningEmulator: Mobile.IDeviceInfo, errors: string[], endTimeEpoch: number}> {
6367
const timeout = options.timeout || AndroidVirtualDevice.TIMEOUT_SECONDS;
6468
const endTimeEpoch = getCurrentEpochTime() + this.$utils.getMilliSecondsTimeout(timeout);

lib/common/mobile/android/android-virtual-device-service.ts

+6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ export class AndroidVirtualDeviceService implements Mobile.IAndroidVirtualDevice
142142
});
143143
}
144144

145+
public detach(deviceInfo: Mobile.IDeviceInfo) {
146+
if (this.mapEmulatorIdToImageIdentifier[deviceInfo.identifier]) {
147+
delete this.mapEmulatorIdToImageIdentifier[deviceInfo.identifier];
148+
}
149+
}
150+
145151
private async getEmulatorImagesCore(): Promise<Mobile.IEmulatorImagesOutput> {
146152
let result: ISpawnResult = null;
147153
let devices: Mobile.IDeviceInfo[] = [];

0 commit comments

Comments
 (0)