Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 95849d8

Browse files
committed
Add check for platform in all discovery services.
1 parent c6898cf commit 95849d8

File tree

7 files changed

+29
-5
lines changed

7 files changed

+29
-5
lines changed

definitions/mobile.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ declare module Mobile {
413413
startDeviceDetectionInterval(): Promise<void>;
414414
getDeviceByIdentifier(identifier: string): Mobile.IDevice;
415415
mapAbstractToTcpPort(deviceIdentifier: string, appIdentifier: string, framework: string): Promise<string>;
416-
detectCurrentlyAttachedDevices(): Promise<void>;
416+
detectCurrentlyAttachedDevices(options?: Mobile.IDeviceLookingOptions): Promise<void>;
417417
startEmulator(platform?: string, emulatorImage?: string): Promise<void>;
418418
isCompanionAppInstalledOnDevices(deviceIdentifiers: string[], framework: string): Promise<IAppInstalledInfo>[];
419419
getDebuggableApps(deviceIdentifiers: string[]): Promise<Mobile.IDeviceApplicationInformation[]>[];

mobile/mobile-core/android-device-discovery.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export class AndroidDeviceDiscovery extends DeviceDiscovery implements Mobile.IA
1313
private isStarted: boolean;
1414

1515
constructor(private $injector: IInjector,
16-
private $adb: Mobile.IAndroidDebugBridge) {
16+
private $adb: Mobile.IAndroidDebugBridge,
17+
private $mobileHelper: Mobile.IMobileHelper) {
1718
super();
1819
}
1920

@@ -29,7 +30,10 @@ export class AndroidDeviceDiscovery extends DeviceDiscovery implements Mobile.IA
2930
this.removeDevice(deviceIdentifier);
3031
}
3132

32-
public async startLookingForDevices(): Promise<void> {
33+
public async startLookingForDevices(options?: Mobile.IDeviceLookingOptions): Promise<void> {
34+
if (options && options.platform && !this.$mobileHelper.isAndroidPlatform(options.platform)) {
35+
return;
36+
}
3337
await this.ensureAdbServerStarted();
3438
await this.checkForDevices();
3539
}

mobile/mobile-core/devices-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi
256256
* @param identifier parameter passed by the user to --device flag
257257
*/
258258
public async getDevice(deviceOption: string): Promise<Mobile.IDevice> {
259-
await this.detectCurrentlyAttachedDevices();
259+
await this.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform: this._platform });
260260
let device: Mobile.IDevice = null;
261261

262262
let emulatorIdentifier = null;

mobile/mobile-core/ios-device-discovery.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export class IOSDeviceDiscovery extends DeviceDiscovery {
77
constructor(private $injector: IInjector,
88
private $logger: ILogger,
99
private $iTunesValidator: Mobile.IiTunesValidator,
10+
private $mobileHelper: Mobile.IMobileHelper,
1011
private $iosDeviceOperations: IIOSDeviceOperations) {
1112
super();
1213
}
@@ -24,6 +25,9 @@ export class IOSDeviceDiscovery extends DeviceDiscovery {
2425
}
2526

2627
public async startLookingForDevices(options?: Mobile.IDeviceLookingOptions): Promise<void> {
28+
if (options && options.platform && !this.$mobileHelper.isiOSPlatform(options.platform)) {
29+
return;
30+
}
2731
if (this.validateiTunes()) {
2832
await this.$iosDeviceOperations.startLookingForDevices((deviceInfo: IOSDeviceLib.IDeviceActionInfo) => {
2933
this.createAndAddDevice(deviceInfo);

mobile/mobile-core/ios-simulator-discovery.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ export class IOSSimulatorDiscovery extends DeviceDiscovery {
77
constructor(private $injector: IInjector,
88
private $childProcess: IChildProcess,
99
private $iOSSimResolver: Mobile.IiOSSimResolver,
10+
private $mobileHelper: Mobile.IMobileHelper,
1011
private $hostInfo: IHostInfo) {
1112
super();
1213
}
1314

14-
public async startLookingForDevices(): Promise<void> {
15+
public async startLookingForDevices(options?: Mobile.IDeviceLookingOptions): Promise<void> {
16+
if (options && options.platform && !this.$mobileHelper.isiOSPlatform(options.platform)) {
17+
return;
18+
}
19+
1520
return new Promise<void>((resolve, reject) => {
1621
return this.checkForDevices(resolve, reject);
1722
});

test/unit-tests/mobile/android-device-discovery.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ function createTestInjector(): IInjector {
4040
injector.register("errors", {});
4141
injector.register("logger", {});
4242
injector.register("androidDebugBridgeResultHandler", AndroidDebugBridgeResultHandler);
43+
injector.register("mobileHelper", {
44+
isAndroidPlatform: () => {
45+
return true;
46+
}
47+
});
4348
injector.register("childProcess", {
4449
spawn: (command: string, args?: string[], options?: any) => {
4550
mockChildProcess = new MockEventEmitter();

test/unit-tests/mobile/ios-simulator-discovery.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ function createTestInjector(): IInjector {
2525

2626
injector.register("devicePlatformsConstants", DevicePlatformsConstants);
2727

28+
injector.register("mobileHelper", {
29+
isiOSPlatform: () => {
30+
return true;
31+
}
32+
});
33+
2834
injector.register("iOSSimulatorDiscovery", IOSSimulatorDiscovery);
2935

3036
injector.register("iOSSimulatorLogProvider", {});

0 commit comments

Comments
 (0)