Skip to content
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

Fixed use of FBApplicationLaunchMode for FBDevice #648

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
22 changes: 20 additions & 2 deletions FBDeviceControl/Commands/FBDeviceApplicationCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,26 @@ - (instancetype)initWithDevice:(FBDevice *)device
}

- (FBFuture<id<FBLaunchedApplication>> *)launchApplication:(FBApplicationLaunchConfiguration *)configuration
{
if (configuration.launchMode == FBApplicationLaunchModeFailIfRunning) {
return [[self processIDWithBundleID:configuration.bundleID] onQueue:self.device.asyncQueue chain:^ (FBFuture<NSNumber *>* processIdQueryResult) {
if (processIdQueryResult.state == FBFutureStateDone) {
return [[FBDeviceControlError
describeFormat:@"Application %@ already running with pid %@", configuration.bundleID, processIdQueryResult.result]
failFuture];
} else if (processIdQueryResult.state == FBFutureStateFailed) {
return (FBFuture*)[self launchApplicationIgnoreCurrentState:configuration];
} else {
return (FBFuture*)processIdQueryResult;
}
Comment on lines +249 to +251
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final branch herer looks a little suspicious. If the app is running then we fail, but in all other conditions we should probably attempt to launch the app

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably right but maybe we should still not launch it if the future state is cancelled?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you might be right and we should just propagate the cancel. @lawrencelomax I'm guessing cancelling will be so rare that either is fine

}];
}
return [self launchApplicationIgnoreCurrentState:configuration];
}

#pragma mark Private

- (FBFuture<id<FBLaunchedProcess>> *)launchApplicationIgnoreCurrentState:(FBApplicationLaunchConfiguration *)configuration
{
return [[[self
remoteInstrumentsClient]
Expand All @@ -248,8 +268,6 @@ - (instancetype)initWithDevice:(FBDevice *)device
}];
}

#pragma mark Private

- (FBFuture<NSNull *> *)killApplicationWithProcessIdentifier:(pid_t)processIdentifier
{
return [[self
Expand Down
3 changes: 2 additions & 1 deletion FBDeviceControl/Management/FBInstrumentsClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ - (instancetype)initWithConnection:(FBAMDServiceConnection *)connection channels
onQueue:self.queue resolveValue:^ NSNumber * (NSError **error) {
NSDictionary<NSString *, NSNumber *> *options = @{
@"StartSuspendedKey": @(configuration.waitForDebugger),
@"KillExisting": @(configuration.launchMode != FBApplicationLaunchModeFailIfRunning),
// FBApplicationLaunchModeFailIfRunning needs to be taken care of prior to this call.
@"KillExisting": @(configuration.launchMode == FBApplicationLaunchModeRelaunchIfRunning),
};
ResponsePayload response = [self
onChannelIdentifier:ProcessControlChannel
Expand Down