Skip to content

Commit

Permalink
Find device or suffix
Browse files Browse the repository at this point in the history
Summary:
Instead of just using the name of the app as the device name, do this:

- Try and find an existing and connected device whose name matches the one provided by the app that is trying to connect.
  - Only use a found device if there's a single match.
  - The supplied name may be generic if the right entitlement is not found for the app (`com.apple.developer.user-assigned-device-name`)
- Otherwise, use the OS + "via QR Exchange"

Reviewed By: antonk52

Differential Revision: D55240729

fbshipit-source-id: 8778e9d1e4f26593008c574f7b1aab1ca6fa9ff0
  • Loading branch information
lblasa authored and facebook-github-bot committed Mar 25, 2024
1 parent 20613fe commit 8060f11
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
12 changes: 10 additions & 2 deletions desktop/flipper-server/src/FlipperServerImpl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export class FlipperServerImpl implements FlipperServer {
'Timeout establishing connection. It looks like the app is taking longer than it should to reconnect using the exchanged certificates. ';
message +=
medium === 'WWW'
? `Verify that your mobile device is connected to Lighthouse/VPN and that you are logged in to
Flipper with the same user account used by the app (unfortunately, test accounts are not currently supported),
? `Verify that your mobile device is connected to Lighthouse/VPN and that you are logged in to
Flipper with the same user account used by the app (unfortunately, test accounts are not currently supported),
so that certificates can be exhanged. See: https://fburl.com/flippervpn. Once this is done, re-running the app may solve this issue.`
: 'Re-running the app may solve this issue.';
this.emit('client-setup-error', {
Expand Down Expand Up @@ -719,6 +719,14 @@ export class FlipperServerImpl implements FlipperServer {
return !!this.devices.get(serial);
}

getDeviceWithName(name: string): ServerDevice | undefined {
const devices = this.getDevices();
const matches = devices.filter((device) => device.info.title === name);
if (matches.length === 1) {
return matches[0];
}
}

getDeviceSerials(): string[] {
return Array.from(this.devices.keys());
}
Expand Down
23 changes: 15 additions & 8 deletions desktop/flipper-server/src/app-connectivity/ServerController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,22 @@ export class ServerController
result.certificates?.key,
);

const deviceId = uuid();
this.flipperServer.registerDevice(
new DummyDevice(
this.flipperServer,
deviceId,
clientQuery.app,
clientQuery.os,
),
let deviceId = uuid();
const device = this.flipperServer.getDeviceWithName(
clientQuery.device,
);
if (device) {
deviceId = device.serial;
} else {
this.flipperServer.registerDevice(
new DummyDevice(
this.flipperServer,
deviceId,
`${clientQuery.device} via QR Exchange`,
clientQuery.os,
),
);
}

tracker.track('app-connection-insecure-attempt-fallback', {
app: clientQuery.app,
Expand Down

0 comments on commit 8060f11

Please sign in to comment.