Skip to content
Snippets Groups Projects
Commit 85b35042 authored by Torsten Grote's avatar Torsten Grote
Browse files

Merge branch '2036-detect-connection' into 'master'

Check if peer has connected

See merge request !10
parents 38d1758f 7186a898
No related branches found
No related tags found
1 merge request!10Check if peer has connected
......@@ -38,6 +38,8 @@ class HotspotManager implements ActionListener {
void onHotspotStarted(NetworkConfig networkConfig);
void onDeviceConnected();
void onHotspotStopped();
void onHotspotError(String error);
......@@ -105,6 +107,7 @@ class HotspotManager implements ActionListener {
wifiP2pManager.createGroup(channel, this);
}
} catch (SecurityException e) {
// this should never happen, because we request permissions before
throw new AssertionError(e);
}
}
......@@ -204,11 +207,35 @@ class HotspotManager implements ActionListener {
listener.onHotspotStarted(new NetworkConfig(
group.getNetworkName(), group.getPassphrase(),
frequency));
requestGroupInfoForConnection();
} else {
retryRequestingGroupInfo(attempt + 1);
}
};
try {
if (channel == null) return;
wifiP2pManager.requestGroupInfo(channel, groupListener);
} catch (SecurityException e) {
throw new AssertionError(e);
}
}
private void requestGroupInfoForConnection() {
if (LOG.isLoggable(INFO))
LOG.info("requestGroupInfo for connection");
WifiP2pManager.GroupInfoListener groupListener = group -> {
if (group == null || group.getClientList().isEmpty()) {
handler.postDelayed(this::requestGroupInfoForConnection,
RETRY_DELAY_MILLIS);
} else {
if (LOG.isLoggable(INFO)) {
LOG.info("client list " + group.getClientList());
}
listener.onDeviceConnected();
}
};
try {
if (channel == null) return;
wifiP2pManager.requestGroupInfo(channel, groupListener);
} catch (SecurityException e) {
throw new AssertionError(e);
......
......@@ -2,6 +2,7 @@ package org.briarproject.hotspot;
import android.app.Application;
import android.net.wifi.WifiManager;
import android.widget.Toast;
import org.briarproject.hotspot.HotspotState.HotspotError;
import org.briarproject.hotspot.HotspotState.HotspotStarted;
......@@ -21,6 +22,7 @@ import androidx.lifecycle.MutableLiveData;
import static android.content.Context.WIFI_SERVICE;
import static android.os.Build.VERSION.SDK_INT;
import static android.widget.Toast.LENGTH_LONG;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.hotspot.HotspotManager.HotspotListener;
import static org.briarproject.hotspot.WebServerManager.WebServerListener;
......@@ -97,6 +99,12 @@ public class MainViewModel extends AndroidViewModel
webServerManager.startWebServer();
}
@Override
public void onDeviceConnected() {
Toast.makeText(getApplication(), R.string.connected_toast, LENGTH_LONG)
.show();
}
@Override
public void onHotspotStopped() {
status.setValue(new HotspotStopped());
......
......@@ -29,7 +29,8 @@
<string name="no_wifi_manager">Device does not support Wi-Fi</string>
<string name="no_wifi_direct">Device does not support Wi-Fi Direct</string>
<string name="wifi_5ghz_supported">5Ghz Wi-Fi is supported</string>
<string name="connected">Peer connected</string>
<string name="connected">Peer has connected</string>
<string name="connected_toast">Peer has connected, press button for download info</string>
<string name="web_server_error">Error starting web server!</string>
<string name="server_info">Visit this site on the other phone either by scanning the QR code or by typing this link manually.</string>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment