Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethernet support #98

Draft
wants to merge 27 commits into
base: development
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e178515
Initial work for supporting wired NICs
aaronjwood Nov 21, 2017
c3b5030
Organize the networking classes in a better way
aaronjwood Mar 25, 2018
fde6362
Instantiate class for working with a wired interface and share the co…
aaronjwood Mar 25, 2018
593ed87
Allow for multiple levels of checking connectivity
aaronjwood Mar 26, 2018
580147c
Merge branch 'development' into ethernet
aaronjwood Mar 26, 2018
05fd27d
Reuse context
aaronjwood Mar 28, 2018
7d5ac0a
Reuse resources
aaronjwood Mar 28, 2018
ba1e6da
Merge branch 'development' into ethernet
aaronjwood Nov 26, 2018
841254a
Simplify connection checks for both wireless and wired connections
aaronjwood Nov 26, 2018
ea69ce5
Merge branch 'development' into ethernet
aaronjwood Nov 26, 2018
d88f0f7
Add support for getting ethernet MAC addresses
aaronjwood Jan 15, 2019
3ba82b3
Add support for getting the subnet of an ethernet device
aaronjwood Jan 15, 2019
56b5e47
Share more network code
aaronjwood Jan 15, 2019
a33f22c
Clean up naming
aaronjwood Jan 15, 2019
07f632b
Share getting the WAN IP between network classes
aaronjwood Jan 15, 2019
9075e4a
Merge branch 'development' into ethernet
aaronjwood Jan 15, 2019
52906ac
Merge remote-tracking branch 'origin/development' into ethernet
aaronjwood Feb 24, 2020
a3ec399
Merge branch 'development' into ethernet
aaronjwood Sep 14, 2020
5ca2c17
Bump min sdk version to work with newer connectivity APIs
aaronjwood Sep 14, 2020
1ce4843
Use connectivity APIs to get subnet info
aaronjwood Sep 14, 2020
848c4ed
Shift most of the networking code to use new system APIs so that we c…
aaronjwood Sep 15, 2020
b94f5a3
Bump build tools
aaronjwood Sep 15, 2020
ec9195a
Merge branch 'development' into ethernet
aaronjwood Nov 23, 2020
ed5d6d5
Merge branch 'development' into ethernet
aaronjwood Nov 23, 2020
dc0a830
Cleanup
aaronjwood Nov 23, 2020
8659a00
Merge branch 'development' into ethernet
aaronjwood Nov 23, 2020
b0265cc
Merge branch 'development' into ethernet
aaronjwood Jan 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify connection checks for both wireless and wired connections
aaronjwood committed Nov 26, 2018

Verified

This commit was signed with the committer’s verified signature.
aaronjwood Aaron Wood
commit 841254aac8eb818352d0a39888d70c368bc510c8
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ jdk:
android:
components:
- tools
- build-tools-27.0.2
- build-tools-28.0.3
- android-27
- extra-android-m2repository

Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
@@ -24,6 +25,9 @@
import com.aaronjwood.portauthority.db.Database;
import com.aaronjwood.portauthority.listener.ScanPortsListener;
import com.aaronjwood.portauthority.network.Host;
import com.aaronjwood.portauthority.network.Network;
import com.aaronjwood.portauthority.network.Wired;
import com.aaronjwood.portauthority.network.Wireless;
import com.aaronjwood.portauthority.response.HostAsyncResponse;
import com.aaronjwood.portauthority.utils.Constants;
import com.aaronjwood.portauthority.utils.Errors;
@@ -37,6 +41,8 @@

public abstract class HostActivity extends AppCompatActivity implements HostAsyncResponse {

protected Wireless wifi;
protected Wired wired;
protected int layout;
protected ArrayAdapter<String> adapter;
protected ListView portList;
@@ -56,7 +62,10 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layout);

db = Database.getInstance(getApplicationContext());
Context ctx = getApplicationContext();
db = Database.getInstance(ctx);
wifi = new Wireless(ctx);
wired = new Wired(ctx);
handler = new Handler(Looper.getMainLooper());

setupPortsAdapter();
@@ -342,4 +351,17 @@ public void run() {
}
});
}

/**
* Determines if there is an active network connection.
*
* @return True if there's a connection, otherwise false.
*/
protected boolean isConnected() {
try {
return wifi.isConnected() || wired.isConnected();
} catch (Network.NoConnectivityManagerException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -12,13 +12,13 @@
import com.aaronjwood.portauthority.R;
import com.aaronjwood.portauthority.listener.ScanPortsListener;
import com.aaronjwood.portauthority.network.Host;
import com.aaronjwood.portauthority.network.Wireless;
import com.aaronjwood.portauthority.utils.Constants;
import com.aaronjwood.portauthority.utils.Errors;
import com.aaronjwood.portauthority.utils.UserPreference;

import java.util.Objects;

public final class LanHostActivity extends HostActivity {
private Wireless wifi;
private Host host;

/**
@@ -40,13 +40,9 @@ protected void onCreate(Bundle savedInstanceState) {
return;
}

wifi = new Wireless(getApplicationContext());
host = (Host) extras.get("HOST");
if (host == null) {
return;
}

hostMacVendor.setText(host.getVendor());
hostMacVendor.setText(Objects.requireNonNull(host).getVendor());
hostName.setText(host.getHostname());
hostMac.setText(host.getMac());
ipAddress.setText(host.getIp());
@@ -92,13 +88,7 @@ private void scanWellKnownPortsClick() {
@Override
public void onClick(View v) {
super.onClick(v);

try {
if (!wifi.isConnected()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
} catch (Wireless.NoConnectivityManagerException e) {
if (!isConnected()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
@@ -131,12 +121,7 @@ private void scanPortRangeClick() {
*/
@Override
public void onClick(View v) {
try {
if (!wifi.isConnected()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
} catch (Wireless.NoConnectivityManagerException e) {
if (!isConnected()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
@@ -173,12 +158,7 @@ private void setupWol() {

@Override
public void onClick(View v) {
try {
if (!wifi.isConnected()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
} catch (Wireless.NoConnectivityManagerException e) {
if (!isConnected()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
@@ -209,6 +189,7 @@ public void processFinish(boolean output) {
if (output && scanProgressDialog != null && scanProgressDialog.isShowing()) {
scanProgressDialog.dismiss();
}

if (output && portRangeDialog != null && portRangeDialog.isShowing()) {
portRangeDialog.dismiss();
}
Original file line number Diff line number Diff line change
@@ -20,14 +20,10 @@ public class NoConnectivityManagerException extends Exception {
*
* @return Network information
*/
NetworkInfo getNetworkInfo() throws NoConnectivityManagerException {
private NetworkInfo getNetworkInfo() throws NoConnectivityManagerException {
return getConnectivityManager().getActiveNetworkInfo();
}

NetworkInfo getNetworkInfo(int type) throws NoConnectivityManagerException {
return getConnectivityManager().getNetworkInfo(type);
}

/**
* Gets the Android connectivity manager in the context of the current activity
*
14 changes: 0 additions & 14 deletions app/src/main/java/com/aaronjwood/portauthority/network/Wired.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
package com.aaronjwood.portauthority.network;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Wired extends Network {

public Wired(Context context) {
super(context);
}

/**
* Checks if ethernet is connected.
*
* @return True if connected or in the process of connecting, false otherwise.
* @throws NoConnectivityManagerException
*/
@Override
public boolean isConnected() throws NoConnectivityManagerException {
NetworkInfo info = getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
return info != null && info.isConnectedOrConnecting();
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.aaronjwood.portauthority.network;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

@@ -270,17 +268,4 @@ private WifiInfo getWifiInfo() throws NoWifiManagerException {
return getWifiManager().getConnectionInfo();
}

/**
* Checks if WiFi is connected.
*
* @return True if connected or in the process of connecting, false otherwise.
* @throws NoConnectivityManagerException
*/
@Override
public boolean isConnected() throws NoConnectivityManagerException {
NetworkInfo info = getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return info != null && info.isConnectedOrConnecting();
}


}