Merge pull request #26 from tailscale/linkproperties

ui: more robust isConnected check.
bradfitz/qr_firestick
Denton Gentry 3 years ago committed by GitHub
commit 7cb3c9a427
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,6 +26,7 @@ import android.provider.Settings;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
import android.net.Uri;
import android.net.VpnService;
@ -98,14 +99,23 @@ public class App extends Application {
private void registerNetworkCallback() {
ConnectivityManager cMgr = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
cMgr.registerNetworkCallback(new NetworkRequest.Builder().build(), new ConnectivityManager.NetworkCallback() {
private void reportConnectivityChange() {
NetworkInfo active = cMgr.getActiveNetworkInfo();
// https://developer.android.com/training/monitoring-device-state/connectivity-status-type
boolean isConnected = active != null && active.isConnectedOrConnecting();
onConnectivityChanged(isConnected);
}
@Override
public void onLost(Network network) {
onConnectivityChanged(false);
super.onLost(network);
this.reportConnectivityChange();
}
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
onConnectivityChanged(true);
super.onLinkPropertiesChanged(network, linkProperties);
this.reportConnectivityChange();
}
});
}

@ -471,6 +471,9 @@ func (a *App) runBackend() error {
}
}
case connected := <-onConnectivityChange:
if state.LostInternet != !connected {
log.Printf("LostInternet state change: %v -> %v", state.LostInternet, !connected)
}
state.LostInternet = !connected
if b != nil {
go b.LinkChange()

Loading…
Cancel
Save