The phone was randomly disconnecting if it couldn't access the internet over wifi, so lions eventually figured out how to force it to automatically reconnect. Grok/stackoverflow spat out a lot of garbage answers for this one. The general idea is to use some deprecated APIs in the WifiManager. Every API is really deprecated but somehow all the AI models assume what's not labeled as deprecated is somehow never going to be deprecated.
It begins by detecting what SSID the phone is currently connected to & assuming it's the bridge access point. The only thing that worked was calling WifiManager.getConnectionInfo(), then WifiInfo.getSSID().
Then it polls the current connection state by calling ConnectivityManager.getAllNetworks() & searching all the NetworkCapabilities objects for TRANSPORT_WIFI. Then it can reconnect if there is none.
The WifiManager.reconnect() function is the key, but it won't do anything without a preceding call to WifiManager.enableNetwork(). Search all the available SSIDs with WifiManager.getConfiguredNetworks(). All the SSIDs have extra quotes added to them. Pass the networkID of the desired SSID to WifiManager.enableNetwork(). Then call WifiManager.reconnect().
You can manually disconnect from the access point in the settings & it'll automatically reconnect, unless switching to the settings screen kills it. It's still only running as a foreground app.
Durable wifi in combination with the phonyproxy.sh wrapper make it pretty solid, but the phoneproxy.sh wrapper still doesn't reliably restore your default gateway anymore. The restart probably needs to be in the main function but experience has shown this to be a bad idea.
lion mclionhead
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.