Skip to content

Commit

Permalink
fruity: Fix unreliable modeswitch activation
Browse files Browse the repository at this point in the history
Where its Promise could be resolved more than once.
  • Loading branch information
oleavr committed Sep 18, 2024
1 parent f48ced3 commit 24dc7f4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/fruity/device-monitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,6 @@ namespace Frida.Fruity {
public async void activate_modeswitch_support (Cancellable? cancellable) throws IOError {
modeswitch_allowed = true;

modeswitch_activated = new Promise<bool> ();
modeswitch_udids_pending = new Gee.HashSet<string> ();
foreach (var transport in usb_transports.to_array ()) {
var usb_device = transport.usb_device;
Expand All @@ -825,12 +824,15 @@ namespace Frida.Fruity {
}
}
if (!modeswitch_udids_pending.is_empty) {
modeswitch_activated = new Promise<bool> ();
try {
yield modeswitch_activated.future.wait_async (cancellable);
} catch (Error e) {
assert_not_reached ();
}
modeswitch_activated = null;
}
modeswitch_udids_pending = null;
}

private void perform_usb_work () {
Expand Down Expand Up @@ -971,9 +973,8 @@ namespace Frida.Fruity {
if (AtomicUint.dec_and_test (ref pending_usb_device_arrivals) && state == STARTING)
usb_started.resolve (true);

if (device != null && modeswitch_udids_pending != null) {
modeswitch_udids_pending.remove (device.udid);
if (modeswitch_udids_pending.is_empty)
if (device != null && modeswitch_udids_pending != null && modeswitch_udids_pending.remove (device.udid)) {
if (modeswitch_udids_pending.is_empty && modeswitch_activated != null)
modeswitch_activated.resolve (true);
}
}
Expand Down

0 comments on commit 24dc7f4

Please sign in to comment.