Skip to content

Commit 31d7d4a

Browse files
committed
refactor: keep deviceId in a single place in the device debug services
1 parent 670f1c8 commit 31d7d4a

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

lib/definitions/debug.d.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
// TODO: remove IDeviceIdentifier
21
/**
32
* Describes information for starting debug process.
43
*/
5-
interface IDebugData extends Mobile.IDeviceIdentifier, IProjectDir {
4+
interface IDebugData extends IAppDebugData, Mobile.IDeviceIdentifier {
5+
}
6+
7+
/**
8+
* Describes information application that will be debugged.
9+
*/
10+
interface IAppDebugData extends IProjectDir {
611
/**
712
* Application identifier of the app that it will be debugged.
813
*/
@@ -144,11 +149,11 @@ interface IDebugService extends IDebugServiceBase {
144149
interface IPlatformDebugService extends IPlatform, NodeJS.EventEmitter {
145150
/**
146151
* Starts debug operation.
147-
* @param {IDebugData} debugData Describes information for device and application that will be debugged.
152+
* @param {IAppDebugData} debugData Describes information for application that will be debugged.
148153
* @param {IDebugOptions} debugOptions Describe possible options to modify the behaivor of the debug operation, for example stop on the first line.
149154
* @returns {Promise<void>}
150155
*/
151-
debugStart(debugData: IDebugData, debugOptions: IDebugOptions): Promise<void>;
156+
debugStart(debugData: IAppDebugData, debugOptions: IDebugOptions): Promise<void>;
152157

153158
/**
154159
* Stops debug operation.
@@ -158,9 +163,9 @@ interface IPlatformDebugService extends IPlatform, NodeJS.EventEmitter {
158163

159164
/**
160165
* Starts debug operation based on the specified debug data.
161-
* @param {IDebugData} debugData Describes information for device and application that will be debugged.
166+
* @param {IAppDebugData} debugData Describes information for application that will be debugged.
162167
* @param {IDebugOptions} debugOptions Describe possible options to modify the behaivor of the debug operation, for example stop on the first line.
163168
* @returns {Promise<string>} Full url where the frontend client may be connected.
164169
*/
165-
debug(debugData: IDebugData, debugOptions: IDebugOptions): Promise<string>;
170+
debug(debugData: IAppDebugData, debugOptions: IDebugOptions): Promise<string>;
166171
}

lib/services/android-debug-service.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { LiveSyncPaths } from "../common/constants";
44

55
export class AndroidDebugService extends DebugServiceBase implements IPlatformDebugService {
66
private _packageName: string;
7+
private deviceIdentifier: string;
8+
79
public get platform() {
810
return "android";
911
}
@@ -17,7 +19,9 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
1719
private $net: INet,
1820
private $projectDataService: IProjectDataService,
1921
private $deviceLogProvider: Mobile.IDeviceLogProvider) {
22+
2023
super(device, $devicesService);
24+
this.deviceIdentifier = device.deviceInfo.identifier;
2125
}
2226

2327
public async debug(debugData: IDebugData, debugOptions: IDebugOptions): Promise<string> {
@@ -27,10 +31,10 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
2731
: await this.debugOnDevice(debugData, debugOptions);
2832

2933
if (!debugOptions.justlaunch) {
30-
const pid = await this.$androidProcessService.getAppProcessId(debugData.deviceIdentifier, debugData.applicationIdentifier);
34+
const pid = await this.$androidProcessService.getAppProcessId(this.deviceIdentifier, debugData.applicationIdentifier);
3135
if (pid) {
32-
this.$deviceLogProvider.setApplicationPidForDevice(debugData.deviceIdentifier, pid);
33-
const device = await this.$devicesService.getDevice(debugData.deviceIdentifier);
36+
this.$deviceLogProvider.setApplicationPidForDevice(this.deviceIdentifier, pid);
37+
const device = await this.$devicesService.getDevice(this.deviceIdentifier);
3438
await device.openDeviceLogStream();
3539
}
3640
}
@@ -39,7 +43,7 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
3943
}
4044

4145
public async debugStart(debugData: IDebugData, debugOptions: IDebugOptions): Promise<void> {
42-
await this.$devicesService.initialize({ platform: this.platform, deviceId: debugData.deviceIdentifier });
46+
await this.$devicesService.initialize({ platform: this.platform, deviceId: this.deviceIdentifier });
4347
const projectData = this.$projectDataService.getProjectData(debugData.projectDir);
4448
const appData: Mobile.IApplicationData = {
4549
appId: debugData.applicationIdentifier,
@@ -48,7 +52,7 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
4852

4953
const action = (device: Mobile.IAndroidDevice): Promise<void> => this.debugStartCore(appData, debugOptions);
5054

51-
await this.$devicesService.execute(action, this.getCanExecuteAction(debugData.deviceIdentifier));
55+
await this.$devicesService.execute(action, this.getCanExecuteAction(this.deviceIdentifier));
5256
}
5357

5458
public debugStop(): Promise<void> {
@@ -109,7 +113,7 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
109113
this.$logger.out("Using ", packageFile);
110114
}
111115

112-
await this.$devicesService.initialize({ platform: this.platform, deviceId: debugData.deviceIdentifier });
116+
await this.$devicesService.initialize({ platform: this.platform, deviceId: this.deviceIdentifier });
113117

114118
const projectName = this.$projectDataService.getProjectData(debugData.projectDir).projectName;
115119
const appData: Mobile.IApplicationData = {
@@ -119,7 +123,7 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
119123

120124
const action = (device: Mobile.IAndroidDevice): Promise<string> => this.debugCore(device, packageFile, appData, debugOptions);
121125

122-
const deviceActionResult = await this.$devicesService.execute(action, this.getCanExecuteAction(debugData.deviceIdentifier));
126+
const deviceActionResult = await this.$devicesService.execute(action, this.getCanExecuteAction(this.deviceIdentifier));
123127
return deviceActionResult[0].result;
124128
}
125129

0 commit comments

Comments
 (0)