pyamsoft / tetherfi

TetherFi - Internet sharing without Root
Apache License 2.0
428 stars 36 forks source link

Unable to start hotspot when the USB Tethering hotspot type is used. #351

Closed brlin-tw closed 2 weeks ago

brlin-tw commented 2 weeks ago

The phone is connected to the PC, and the USB network sharing mode is enabled, but the hotspot failed to start with the following error:

java.lang.IllegalStateException: Missing USB Tethering connection
 at com.pyamsoft.tetherfi.server.broadcast.rndis.RNDISServer$resolveRNDISNetwork$2.invokeSuspend(SourceFile:93)
 at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(SourceFile:9)
 at kotlinx.coroutines.DispatchedTask.run(SourceFile:107)
 at com.google.android.gms.tasks.zzi.run(SourceFile:11)
 at kotlinx.coroutines.scheduling.TaskImpl.run(SourceFile:3)
 at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(SourceFile:93)
 Missing USB Tethering connection

Developer log:

[D] Starting Proxy! 
[D] Stopping runner! 
[D] #################################### 
[D] Acquire CPU wakelock: com.pyamsoft.tetherfi:PROXY_WAKE_LOCK 
[D] #################################### 
[D] Create new wake lock with PARTIAL_WAKE_LOCK 
[D] #################################### 
[D] Acquire WiFi wakelock: com.pyamsoft.tetherfi:PROXY_WIFI_LOCK 
[D] #################################### 
[D] Starting Wifi Network... 
[D] WiDi Status Changed: Starting 
[D] START NEW NETWORK 
[D] Updated foreground notification: NotifyId(id=42069): ServerNotificationData(status=Starting, clientCount=0, blockCount=0) 
[D] Starting broadcast network 
[W] Error during broadcast startup, stop network 
[D] Reset last info refresh times 
[W] Stopping network after startup failed 
[D] WiDi Status Changed: HotspotError(throwable=java.lang.IllegalStateException: Missing USB Tethering connection) 
[D] Shutdown event received! 
[D] Shutdown event received! 
[D] Stopping Wifi Network... 
[D] STOP NETWORK 
[D] Shutting down network 
[D] Reset last info refresh times 
[E] Error running WiDi network
java.lang.IllegalStateException: Missing USB Tethering connection
 at com.pyamsoft.tetherfi.server.broadcast.rndis.RNDISServer$resolveRNDISNetwork$2.invokeSuspend(SourceFile:93)
 at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(SourceFile:9)
 at kotlinx.coroutines.DispatchedTask.run(SourceFile:107)
 at com.google.android.gms.tasks.zzi.run(SourceFile:11)
 at kotlinx.coroutines.scheduling.TaskImpl.run(SourceFile:3)
 at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(SourceFile:93)
 Missing USB Tethering connection
[D] Updated foreground notification: NotifyId(id=42069): ServerNotificationData(status=HotspotError(throwable=java.lang.IllegalStateException: Missing USB Tethering connection), clientCount=0, blockCount=0) 
[D] Stop Foreground Service! 
[D] Shutdown event received! 
[D] Shutdown event received! 
[D] Network was stopped 
[D] #################################### 
[D] Release CPU wakelock: com.pyamsoft.tetherfi:PROXY_WAKE_LOCK 
[D] #################################### 
[D] #################################### 
[D] Release WIFI wakelock: com.pyamsoft.tetherfi:PROXY_WIFI_LOCK 
[D] #################################### 
[D] Destroying service 
[D] Execute prepareStop() before cancelling service scope 
[D] Stop Foreground Service! 
[D] Mark hotspot stopping 
[D] Unhandled Proxy status event Stopping 
[D] Broadcast stop-request 
[D] Proxy Status Changed: Stopping 
[D] Cancel Service Scope 
[D] Notification scope is done, cancel notification! 
[D] Stop foreground notification 

Additional information

TetherFi

49 from Google Play

Android

14 (AP2A.240905.003)

Phone

Google Pixel 8 Pro

pyamsoft commented 2 weeks ago

The USB tethering mode is looking for an interface identified as RNDIS.

Do you have access to an Android Studio environment?

If you do, you can build a simple test app and copy the code from RNDISServer.kt in the function resolveRNDISNetwork

This function goes through all of the various internet devices and attempts to pick the one labelled RNDIS, maybe yours is something different that I also need to look for?

brlin-tw commented 2 weeks ago

@pyamsoft

This function goes through all of the various internet devices and attempts to pick the one labelled RNDIS, maybe yours is something different that I also need to look for?

I hooked up a debugger and it seems that the NetworkInterface.getNetworkInterfaces() call returns null on my phone.

I'm going to rebuild the app and try to verify it again just to be sure, after building ktor which took ages for some reason:

Screenshot

pyamsoft commented 2 weeks ago

You can use the upstream ktor if you don't need to use the preferred network feature.

If you change the ktor dep back to upstream, I think you just have to change the 2 lines where I call connectWithConfiguration to connect

Thanks for getting deep in the code here!

If you device is returning null for this, I'll need a different API to enumerated the devices

brlin-tw commented 2 weeks ago

@pyamsoft

If you device is returning null for this, I'll need a different API to enumerated the devices

After successfully building TetherFi from the source I can verify that the NetworkInterface.getNetworkInterfaces() call returns proper results, just not the ones we were expecting:

Screenshot

The ncm0 interface seems to be the one that is responsible for USB network sharing.

brlin-tw commented 2 weeks ago

I can verify that changing the "EXPECTED_RNDIS_NAME_PREFIX" string value to "ncm" I can successfully launch the hotspot.

pyamsoft commented 2 weeks ago

Awesome find, thank you

I will patch the code to look for both interface name prefixes

brlin-tw commented 2 weeks ago

I hooked up a debugger and it seems that the NetworkInterface.getNetworkInterfaces() call returns null on my phone.

No longer reproduced on either emulator/phone, likely a false alarm.

pyamsoft commented 2 weeks ago

I have added support for the ncm prefix, and will look at making another production release hopefully sometime next week.

Thank you for your contribution to the project!

pyamsoft commented 2 weeks ago

Version 51 is in production testing and includes the ncm change.