Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 866272e4 authored by Matthias Yzusqui's avatar Matthias Yzusqui Committed by Gerrit Code Review
Browse files

wifi: show devices behind a firewall that are connected to the WiFi hotspot

* Clients that are behind a firewall, in particular Windows-PCs tend
to not respond to the request invoked by the isReached(val)-method.
Executing a ping instead and evaluating the outcome enables us to
bypass the firewall.

Change-Id: If857545c7a4d5fbc9d2dc919096a9c84e64d6877
parent b926a16b
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -26,8 +26,9 @@ import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.lang.InterruptedException;
import java.lang.Process;
import java.lang.Runtime;
import java.util.ArrayList;

public class ClientsList {
@@ -35,7 +36,7 @@ public class ClientsList {
    private static final String TAG = "ClientsList";

    /**
     * Gets a list of the clients connected to the Hotspot, reachable timeout is 3000
     * Gets a list of the clients connected to the Hotspot, reachable deadline(-w) is 3(sec)
     *
     * @param onlyReachables {@code false} if the list should contain unreachable
     *                       (probably disconnected) clients, {@code true} otherwise
@@ -57,10 +58,11 @@ public class ClientsList {
                    String mac = splitted[3];

                    if (mac.matches("..:..:..:..:..:..")) {
                        InetAddress address = InetAddress.getByName(splitted[0]);
                        boolean isReachable = address.isReachable(3000);

                        if (!onlyReachables || isReachable) {
                        boolean isReachable = false;
                        if (onlyReachables) {
                           isReachable = isReachableByPing(splitted[0]);
                        }
                        if (!onlyReachables || (onlyReachables && isReachable)) {
                            ClientScanResult client = new ClientScanResult();
                            client.ipAddr = splitted[0];
                            if (mac.equals("00:00:00:00:00:00")) {
@@ -76,8 +78,6 @@ public class ClientsList {
                    }
                }
            }
        } catch (UnknownHostException e) {
            Log.d(TAG, "catch UnknownHostException hit in run", e);
        } catch (FileNotFoundException e) {
            Log.d(TAG, "catch FileNotFoundException hit in run", e);
        } catch (IOException e) {
@@ -136,6 +136,20 @@ public class ClientsList {
        return "";
    }

    private static boolean isReachableByPing(String client) {
        try {
            Runtime runtime = Runtime.getRuntime();
            Process mIpAddrProcess = runtime.exec("/system/bin/ping -c 1 -w 3 " + client);
            int mExitValue = mIpAddrProcess.waitFor();
            return (mExitValue == 0);
        } catch (InterruptedException e) {
            // Ignore
        } catch (IOException e) {
            // Ignore
        }
        return false;
    }

    public static class ClientScanResult {
        public String ipAddr;
        public String hwAddr;