Skip to content

Commit aa4ecfe

Browse files
refactor: Set logFilter's project name when starting iOS application
When strating iOS Application, set the projectName to the log filter, so we can filter the logs by it. Same logic is used for Android, where we are using the PID of the started application. So introduce IDeviceLogOptions, where logLevel, pid and projectName can be set. Pass the projectName wherever is required in order to get it in startApplication.
1 parent eb4f8b5 commit aa4ecfe

11 files changed

+53
-39
lines changed

lib/definitions/platform.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ interface IPlatformService extends IBuildPlatformAction, NodeJS.EventEmitter {
125125
* @param {IProjectData} projectData DTO with information about the project.
126126
* @returns {void}
127127
*/
128-
startApplication(platform: string, runOptions: IRunPlatformOptions, projectId: string): Promise<void>;
128+
startApplication(platform: string, runOptions: IRunPlatformOptions, projectId: string, projectName: string): Promise<void>;
129129

130130
cleanDestinationApp(platformInfo: IPreparePlatformInfo): Promise<void>;
131131
validatePlatformInstalled(platform: string, projectData: IProjectData): void;

lib/helpers/livesync-command-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
151151
};
152152

153153
await this.$platformService.deployPlatform(deployPlatformInfo);
154-
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, this.$projectData.projectId);
154+
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, this.$projectData.projectId, this.$projectData.projectName);
155155
this.$platformService.trackProjectType(this.$projectData);
156156
}
157157
}

lib/services/android-debug-service.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
1313
private $logger: ILogger,
1414
private $androidDeviceDiscovery: Mobile.IDeviceDiscovery,
1515
private $androidProcessService: Mobile.IAndroidProcessService,
16-
private $net: INet) {
16+
private $net: INet,
17+
private $projectDataService: IProjectDataService) {
1718
super(device, $devicesService);
1819
}
1920

@@ -25,8 +26,9 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
2526
}
2627

2728
public async debugStart(debugData: IDebugData, debugOptions: IDebugOptions): Promise<void> {
29+
const projectData = this.$projectDataService.getProjectData(debugData.projectDir);
2830
await this.$devicesService.initialize({ platform: this.platform, deviceId: debugData.deviceIdentifier });
29-
const action = (device: Mobile.IAndroidDevice): Promise<void> => this.debugStartCore(debugData.applicationIdentifier, debugOptions);
31+
const action = (device: Mobile.IAndroidDevice): Promise<void> => this.debugStartCore(debugData.applicationIdentifier, debugOptions, projectData.projectName);
3032

3133
await this.$devicesService.execute(action, this.getCanExecuteAction(debugData.deviceIdentifier));
3234
}
@@ -91,23 +93,24 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
9193

9294
await this.$devicesService.initialize({ platform: this.platform, deviceId: debugData.deviceIdentifier });
9395

94-
const action = (device: Mobile.IAndroidDevice): Promise<string> => this.debugCore(device, packageFile, debugData.applicationIdentifier, debugOptions);
96+
const packageName = this.$projectDataService.getProjectData(debugData.projectDir).projectName;
97+
const action = (device: Mobile.IAndroidDevice): Promise<string> => this.debugCore(device, packageFile, debugData.applicationIdentifier, packageName, debugOptions);
9598

9699
const deviceActionResult = await this.$devicesService.execute(action, this.getCanExecuteAction(debugData.deviceIdentifier));
97100
return deviceActionResult[0].result;
98101
}
99102

100-
private async debugCore(device: Mobile.IAndroidDevice, packageFile: string, packageName: string, debugOptions: IDebugOptions): Promise<string> {
101-
await this.printDebugPort(device.deviceInfo.identifier, packageName);
103+
private async debugCore(device: Mobile.IAndroidDevice, packageFile: string, appId: string, packageName: string, debugOptions: IDebugOptions): Promise<string> {
104+
await this.printDebugPort(device.deviceInfo.identifier, appId);
102105

103106
if (debugOptions.start) {
104-
return await this.attachDebugger(device.deviceInfo.identifier, packageName, debugOptions);
107+
return await this.attachDebugger(device.deviceInfo.identifier, appId, debugOptions);
105108
} else if (debugOptions.stop) {
106109
await this.removePortForwarding();
107110
return null;
108111
} else {
109-
await this.debugStartCore(packageName, debugOptions);
110-
return await this.attachDebugger(device.deviceInfo.identifier, packageName, debugOptions);
112+
await this.debugStartCore(appId, debugOptions, packageName);
113+
return await this.attachDebugger(device.deviceInfo.identifier, appId, debugOptions);
111114
}
112115
}
113116

@@ -126,22 +129,22 @@ export class AndroidDebugService extends DebugServiceBase implements IPlatformDe
126129
return this.getChromeDebugUrl(debugOptions, port);
127130
}
128131

129-
private async debugStartCore(packageName: string, debugOptions: IDebugOptions): Promise<void> {
132+
private async debugStartCore(appId: string, debugOptions: IDebugOptions, projectName: string): Promise<void> {
130133
// Arguments passed to executeShellCommand must be in array ([]), but it turned out adb shell "arg with intervals" still works correctly.
131134
// As we need to redirect output of a command on the device, keep using only one argument.
132135
// We could rewrite this with two calls - touch and rm -f , but -f flag is not available on old Android, so rm call will fail when file does not exist.
133136

134-
await this.device.applicationManager.stopApplication(packageName);
137+
await this.device.applicationManager.stopApplication(appId);
135138

136139
if (debugOptions.debugBrk) {
137-
await this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${packageName}-debugbreak`]);
140+
await this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${appId}-debugbreak`]);
138141
}
139142

140-
await this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${packageName}-debugger-started`]);
143+
await this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${appId}-debugger-started`]);
141144

142-
await this.device.applicationManager.startApplication(packageName);
145+
await this.device.applicationManager.startApplication(appId, projectName);
143146

144-
await this.waitForDebugger(packageName);
147+
await this.waitForDebugger(appId);
145148
}
146149

147150
private async waitForDebugger(packageName: String): Promise<void> {

lib/services/ios-debug-service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
3333
private $iOSSocketRequestExecutor: IiOSSocketRequestExecutor,
3434
private $processService: IProcessService,
3535
private $socketProxyFactory: ISocketProxyFactory,
36-
private $net: INet) {
36+
private $net: INet,
37+
private $projectDataService: IProjectDataService) {
3738
super(device, $devicesService);
3839
this.$processService.attachToProcessExitSignals(this, this.debugStop);
3940
this.$socketProxyFactory.on(CONNECTION_ERROR_EVENT_NAME, (e: Error) => this.emit(CONNECTION_ERROR_EVENT_NAME, e));
@@ -173,6 +174,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
173174

174175
private async deviceDebugBrk(debugData: IDebugData, debugOptions: IDebugOptions): Promise<string> {
175176
await this.$devicesService.initialize({ platform: this.platform, deviceId: debugData.deviceIdentifier });
177+
const projectData = this.$projectDataService.getProjectData(debugData.projectDir);
176178
const action = async (device: iOSDevice.IOSDevice): Promise<string> => {
177179
if (device.isEmulator) {
178180
return await this.emulatorDebugBrk(debugData, debugOptions);
@@ -185,7 +187,7 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
185187
};
186188

187189
const promisesResults = await Promise.all<any>([
188-
this.$platformService.startApplication(this.platform, runOptions, debugData.applicationIdentifier),
190+
this.$platformService.startApplication(this.platform, runOptions, debugData.applicationIdentifier, projectData.projectName),
189191
this.debugBrkCore(device, debugData, debugOptions)
190192
]);
191193

lib/services/ios-log-filter.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
1717

1818
private partialLine: string = null;
1919

20-
constructor(
20+
constructor(private $logger: ILogger,
2121
private $loggingLevels: Mobile.ILoggingLevels,
2222
private $fs: IFileSystem,
2323
private $projectData: IProjectData) {
2424
}
2525

26-
public filterData(data: string, logLevel: string, pid?: string): string {
27-
const specifiedLogLevel = (logLevel || '').toUpperCase();
26+
public filterData(data: string, loggingOptions: Mobile.IDeviceLogOptions = <any>{}): string {
27+
const specifiedLogLevel = (loggingOptions.logLevel || '').toUpperCase();
28+
this.$logger.trace("Logging options", loggingOptions);
2829

2930
if (specifiedLogLevel !== this.$loggingLevels.info || !data) {
3031
return data;
@@ -57,8 +58,8 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
5758
// Check if the name of the app equals the name of the CLI project and turn on the filter if not.
5859
// We call initializeProjectData in order to obtain the current project name as the instance
5960
// of this filter may be used accross multiple projects.
60-
this.$projectData.initializeProjectData();
61-
this.filterActive = matchResult[1] !== this.$projectData.projectName;
61+
const projectName = loggingOptions && loggingOptions.projectName;
62+
this.filterActive = matchResult[1] !== projectName;
6263
}
6364

6465
if (this.filterActive) {

lib/services/livesync/android-device-livesync-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl
4242
(localToDevicePath: Mobile.ILocalToDevicePathData) => !this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));
4343

4444
if (!canExecuteFastSync) {
45-
return this.restartApplication(deviceAppData);
45+
return this.restartApplication(deviceAppData, projectData.projectName);
4646
}
4747
}
4848

@@ -57,12 +57,12 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl
5757
await this.$mobileHelper.buildDevicePath(deviceRootPath, LiveSyncPaths.REMOVEDSYNC_DIR_NAME)]);
5858
}
5959

60-
private async restartApplication(deviceAppData: Mobile.IDeviceAppData): Promise<void> {
60+
private async restartApplication(deviceAppData: Mobile.IDeviceAppData, projectName: string): Promise<void> {
6161
const devicePathRoot = `/data/data/${deviceAppData.appIdentifier}/files`;
6262
const devicePath = this.$mobileHelper.buildDevicePath(devicePathRoot, "code_cache", "secondary_dexes", "proxyThumb");
6363
await this.device.adb.executeShellCommand(["rm", "-rf", devicePath]);
6464

65-
await this.device.applicationManager.restartApplication(deviceAppData.appIdentifier);
65+
await this.device.applicationManager.restartApplication(deviceAppData.appIdentifier, projectName);
6666
}
6767

6868
public async beforeLiveSyncAction(deviceAppData: Mobile.IDeviceAppData): Promise<void> {

lib/services/platform-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,11 @@ export class PlatformService extends EventEmitter implements IPlatformService {
543543
await this.$devicesService.execute(action, this.getCanExecuteAction(deployInfo.platform, deployInfo.deployOptions));
544544
}
545545

546-
public async startApplication(platform: string, runOptions: IRunPlatformOptions, projectId: string): Promise<void> {
546+
public async startApplication(platform: string, runOptions: IRunPlatformOptions, projectId: string, projectName: string): Promise<void> {
547547
this.$logger.out("Starting...");
548548

549549
const action = async (device: Mobile.IDevice) => {
550-
await device.applicationManager.startApplication(projectId);
550+
await device.applicationManager.startApplication(projectId, projectName);
551551
this.$logger.out(`Successfully started on device with identifier '${device.deviceInfo.identifier}'.`);
552552
};
553553

test/services/android-debug-service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ class AndroidDebugServiceInheritor extends AndroidDebugService {
1111
$logger: ILogger,
1212
$androidDeviceDiscovery: Mobile.IDeviceDiscovery,
1313
$androidProcessService: Mobile.IAndroidProcessService,
14-
$net: INet) {
15-
super(<any>{}, $devicesService, $errors, $logger, $androidDeviceDiscovery, $androidProcessService, $net);
14+
$net: INet,
15+
$projectDataService: IProjectDataService) {
16+
super(<any>{}, $devicesService, $errors, $logger, $androidDeviceDiscovery, $androidProcessService, $net, $projectDataService);
1617
}
1718

1819
public getChromeDebugUrl(debugOptions: IDebugOptions, port: number): string {
@@ -28,6 +29,7 @@ const createTestInjector = (): IInjector => {
2829
testInjector.register("androidDeviceDiscovery", {});
2930
testInjector.register("androidProcessService", {});
3031
testInjector.register("net", {});
32+
testInjector.register("projectDataService", {});
3133

3234
return testInjector;
3335
};

test/services/ios-debug-service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ class IOSDebugServiceInheritor extends IOSDebugService {
1818
$iOSSocketRequestExecutor: IiOSSocketRequestExecutor,
1919
$processService: IProcessService,
2020
$socketProxyFactory: ISocketProxyFactory,
21-
$net: INet) {
21+
$net: INet,
22+
$projectDataService: IProjectDataService) {
2223
super(<any>{}, $devicesService, $platformService, $iOSEmulatorServices, $childProcess, $hostInfo, $logger, $errors,
23-
$npmInstallationManager, $iOSNotification, $iOSSocketRequestExecutor, $processService, $socketProxyFactory, $net);
24+
$npmInstallationManager, $iOSNotification, $iOSSocketRequestExecutor, $processService, $socketProxyFactory, $net, $projectDataService);
2425
}
2526

2627
public getChromeDebugUrl(debugOptions: IDebugOptions, port: number): string {
@@ -54,6 +55,8 @@ const createTestInjector = (): IInjector => {
5455
waitForPortToListen: async (opts: { port: number, timeout: number, interval?: number }): Promise<boolean> => true
5556
});
5657

58+
testInjector.register("projectDataService", {});
59+
5760
return testInjector;
5861
};
5962

0 commit comments

Comments
 (0)