@@ -65,22 +65,21 @@ impl Default for ConnectionStatus {
6565
6666impl ConnectionStatus {
6767 fn usb_ready ( & self ) -> bool {
68- matches ! ( self . usb, UsbState :: Configured )
68+ matches ! ( self . usb, UsbState :: Configured | UsbState :: Suspended )
6969 }
7070
7171 fn ble_ready ( & self ) -> bool {
7272 matches ! ( self . ble. state, BleState :: Connected )
7373 }
7474
75- /// Pick the active transport from current readiness + preference. Ready
76- /// transports win first; suspended USB stays selected when nothing else
77- /// is so remote wakeup remains reachable .
75+ /// Pick the active transport from current readiness + preference. Suspended
76+ /// USB remains routable for remote wakeup, so it participates in the same
77+ /// preference tie-break as configured USB .
7878 pub fn decide_active ( & self ) -> Option < ConnectionType > {
7979 match ( self . usb_ready ( ) , self . ble_ready ( ) ) {
8080 ( true , false ) => Some ( ConnectionType :: Usb ) ,
8181 ( false , true ) => Some ( ConnectionType :: Ble ) ,
8282 ( true , true ) => Some ( self . preferred ) ,
83- ( false , false ) if matches ! ( self . usb, UsbState :: Suspended ) => Some ( ConnectionType :: Usb ) ,
8483 ( false , false ) => None ,
8584 }
8685 }
@@ -132,15 +131,19 @@ mod tests {
132131 fn suspended_usb_stays_routable_for_remote_wakeup ( ) {
133132 let s = status ( UsbState :: Suspended , BleState :: Advertising , ConnectionType :: Ble ) ;
134133 assert_eq ! ( s. decide_active( ) , Some ( ConnectionType :: Usb ) ) ;
135- assert ! ( ! s. usb_ready( ) ) ;
134+ assert ! ( s. usb_ready( ) ) ;
136135 }
137136
138137 #[ test]
139- fn suspended_usb_yields_to_connected_ble ( ) {
140- // Laptop sleep with phone still BLE-connected: cascade picks BLE.
138+ fn suspended_usb_with_connected_ble_prefers_preference ( ) {
141139 let s = status ( UsbState :: Suspended , BleState :: Connected , ConnectionType :: Usb ) ;
140+ assert_eq ! ( s. decide_active( ) , Some ( ConnectionType :: Usb ) ) ;
141+ assert ! ( s. usb_ready( ) ) ;
142+ assert ! ( s. ble_ready( ) ) ;
143+
144+ let s = status ( UsbState :: Suspended , BleState :: Connected , ConnectionType :: Ble ) ;
142145 assert_eq ! ( s. decide_active( ) , Some ( ConnectionType :: Ble ) ) ;
143- assert ! ( ! s. usb_ready( ) ) ;
146+ assert ! ( s. usb_ready( ) ) ;
144147 assert ! ( s. ble_ready( ) ) ;
145148 }
146149}
0 commit comments