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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
buildToolsVersion '30.0.3'

defaultConfig {
minSdkVersion 14
minSdkVersion 23
targetSdkVersion 30
versionCode 62
versionName "2.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@
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.response.HostAsyncResponse;
import com.aaronjwood.portauthority.utils.Constants;
import com.aaronjwood.portauthority.utils.Errors;
Expand All @@ -37,7 +39,6 @@
import java.util.List;

public abstract class HostActivity extends AppCompatActivity implements HostAsyncResponse {

protected int layout;
protected ArrayAdapter<String> adapter;
protected ListView portList;
Expand All @@ -57,7 +58,8 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layout);

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

setupPortsAdapter();
Expand Down Expand Up @@ -315,4 +317,18 @@ private void addOpenPort(final String port) {
public <T extends Throwable> void processFinish(final T output) {
handler.post(() -> Errors.showError(getApplicationContext(), output.getLocalizedMessage()));
}

/**
* Determines if there is an active network connection.
*
* @return True if there's a connection, otherwise false.
*/
protected boolean isConnected() {
Context ctx = getApplicationContext();
try {
return Network.isConnected(ctx);
} catch (Network.NoConnectivityManagerException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,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;

/**
Expand All @@ -42,13 +42,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());
Expand Down Expand Up @@ -94,13 +90,7 @@ private void scanWellKnownPortsClick() {
@Override
public void onClick(View v) {
super.onClick(v);

try {
if (!wifi.isConnectedWifi()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
} catch (Wireless.NoConnectivityManagerException e) {
if (!isConnected()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
Expand Down Expand Up @@ -133,12 +123,7 @@ private void scanPortRangeClick() {
*/
@Override
public void onClick(View v) {
try {
if (!wifi.isConnectedWifi()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
} catch (Wireless.NoConnectivityManagerException e) {
if (!isConnected()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
Expand Down Expand Up @@ -170,13 +155,9 @@ public void onClick(View v) {
*/
private void setupWol() {
Button wakeUpButton = findViewById(R.id.wakeOnLan);

wakeUpButton.setOnClickListener(v -> {
try {
if (!wifi.isConnectedWifi()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
} catch (Wireless.NoConnectivityManagerException e) {
if (!isConnected()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
Expand Down Expand Up @@ -206,6 +187,7 @@ public void processFinish(boolean output) {
if (output && scanProgressDialog != null && scanProgressDialog.isShowing()) {
scanProgressDialog.dismiss();
}

if (output && portRangeDialog != null && portRangeDialog.isShowing()) {
portRangeDialog.dismiss();
}
Expand Down
Loading