Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronjwood committed Feb 2, 2018
2 parents 0bc488f + f569732 commit 337ef63
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 91 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
- secure: "em+bEb3nWLV7f+Dt4y9/OH2Lpf6mscT9E52kXhSEm/PiFpTtzlx7BgHGlpsYVwsMf0e7x2AdF/yzq4c7ugoMqWmFXMthgFUKcLTXqW/IeARGz3smMXnyScRoaFElDm0Q33fxiqDlU7UVA4j1FysR5GqTU10MasJgGpoyTthRQvra0LU8zwI4IMiASfa8Tij5LclsbaTpcgB4TdXtBmbpKQAUzjvV/ZfLsYQ950C0rbVKk9T1xtc8d5BTbggwHWbMMqGn6RFvSCQioeI/Q6Daak6zDglUY+JE/1BnzlGzoba9C7TLZV4+TQkmB5kc6FtKqSXycjwJSKm3wQFYOzJrLMPqMtlmaAeTEs5yBIYtIIAiID+hbeUKvWTpoUxwUYz7s7XLikJRdxe7iBlhdy3qv+FdGOJjV9g/xeSVXISvXzcKp2sNdU+FABBBDAA2CKWrZOXuzPAh8iYxLnt649hQFAw99ylkn75+LpJgq7gRUO87Fde0Zw3vYhLIS8UH3OBtggV1yrYHuKXWUyfkiA/xcm+NSFgIXJzGvYlOZWS+uZvXeh7wJz5CF0t3m6emBoqX6JAXQ/t9SgwGX8lwbLPK3HiYBnTMEDxb6qpIiYa8E8tfudA1YNyeszG8mZtiErJf9YleagACuASwPFsLb8Bg9BNJX5X89+VrbzPbncZD9Tc="

before_install:
- yes | sdkmanager "platforms;android-27"
- echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-

addons:
Expand Down
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ sonarqube {
android {
compileSdkVersion 27
buildToolsVersion '27.0.2'
useLibrary 'org.apache.http.legacy'

defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode 53
versionName "2.2.4"
versionCode 54
versionName "2.2.6"
applicationId "com.aaronjwood.portauthority"
setProperty("archivesBaseName", "PortAuthority-$versionName")
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes {
Expand Down Expand Up @@ -68,6 +67,7 @@ android {
dependencies {
compile 'com.android.support:support-v4:27.0.2'
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'jcifs:jcifs:1.3.17'
compile 'dnsjava:dnsjava:2.1.7'
//This does absolutely nothing
Expand Down
8 changes: 7 additions & 1 deletion app/proguard.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
-dontwarn org.xbill.DNS.spi.DNSJavaNameServiceDescriptor
-keep class org.xbill.** { *; }
-keepattributes EnclosingMethod
-keepattributes InnerClasses
-keepattributes InnerClasses

-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".PortAuthority"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/com/aaronjwood/portauthority/PortAuthority.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.aaronjwood.portauthority;

import android.app.Application;
import android.os.Process;

import com.squareup.leakcanary.LeakCanary;

public class PortAuthority extends Application {

@Override
public void onCreate() {
super.onCreate();

if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}

LeakCanary.install(this);
checkReplacingState(); // Workaround for https://issuetracker.google.com/issues/36972466
}

/**
* Kills the process if we can't get our own resources.
*/
private void checkReplacingState() {
if (getResources() == null) {
Process.killProcess(Process.myPid());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.database.sqlite.SQLiteException;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
Expand All @@ -32,7 +33,6 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aaronjwood.portauthority.BuildConfig;
import com.aaronjwood.portauthority.R;
import com.aaronjwood.portauthority.adapter.HostAdapter;
import com.aaronjwood.portauthority.async.DownloadAsyncTask;
Expand All @@ -47,13 +47,12 @@
import com.aaronjwood.portauthority.response.MainAsyncResponse;
import com.aaronjwood.portauthority.utils.Errors;
import com.aaronjwood.portauthority.utils.UserPreference;
import com.squareup.leakcanary.LeakCanary;

import java.io.IOException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -76,7 +75,6 @@ public final class MainActivity extends AppCompatActivity implements MainAsyncRe
private ProgressDialog scanProgressDialog;
private Handler signalHandler = new Handler();
private Handler scanHandler;
private BroadcastReceiver receiver;
private IntentFilter intentFilter = new IntentFilter();
private HostAdapter hostAdapter;
private List<Host> hosts = Collections.synchronizedList(new ArrayList<Host>());
Expand All @@ -85,6 +83,25 @@ public final class MainActivity extends AppCompatActivity implements MainAsyncRe
private DownloadAsyncTask portTask;
private boolean sortAscending;

private BroadcastReceiver receiver = new BroadcastReceiver() {

/**
* Detect if a network connection has been lost or established
* @param context
* @param intent
*/
@Override
public void onReceive(Context context, Intent intent) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (info == null) {
return;
}

getNetworkInfo(info);
}

};

/**
* Activity created
*
Expand All @@ -94,10 +111,6 @@ public final class MainActivity extends AppCompatActivity implements MainAsyncRe
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (BuildConfig.DEBUG) {
LeakCanary.install(getApplication());
}

setContentView(R.layout.activity_main);

internalIp = findViewById(R.id.internalIpAddress);
Expand All @@ -117,8 +130,9 @@ protected void onCreate(Bundle savedInstanceState) {

setupHostsAdapter();
setupDrawer();
setupReceivers();
setupHostDiscovery();

intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
}

/**
Expand Down Expand Up @@ -214,26 +228,28 @@ private void setupHostDiscovery() {
*/
@Override
public void onClick(View v) {
Resources resources = getResources();
Context context = getApplicationContext();
try {
if (!wifi.isEnabled()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.wifiDisabled));
Errors.showError(context, resources.getString(R.string.wifiDisabled));
return;
}

if (!wifi.isConnectedWifi()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedWifi));
Errors.showError(context, resources.getString(R.string.notConnectedWifi));
return;
}
} catch (Wireless.NoWifiManagerException | Wireless.NoConnectivityManagerException e) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.failedWifiManager));
Errors.showError(context, resources.getString(R.string.failedWifiManager));
return;
}

int numSubnetHosts;
try {
numSubnetHosts = wifi.getNumberOfHostsInWifiSubnet();
} catch (Wireless.NoWifiManagerException e) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.failedSubnetHosts));
Errors.showError(context, resources.getString(R.string.failedSubnetHosts));
return;
}

Expand All @@ -245,20 +261,20 @@ public void onClick(View v) {

scanProgressDialog = new ProgressDialog(MainActivity.this, R.style.DialogTheme);
scanProgressDialog.setCancelable(false);
scanProgressDialog.setTitle(getResources().getString(R.string.hostScan));
scanProgressDialog.setMessage(String.format(getResources().getString(R.string.subnetHosts), numSubnetHosts));
scanProgressDialog.setTitle(resources.getString(R.string.hostScan));
scanProgressDialog.setMessage(String.format(resources.getString(R.string.subnetHosts), numSubnetHosts));
scanProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
scanProgressDialog.setProgress(0);
scanProgressDialog.setMax(numSubnetHosts);
scanProgressDialog.show();

try {
Integer ip = wifi.getInternalWifiIpAddress(Integer.class);
new ScanHostsAsyncTask(MainActivity.this, db).execute(ip, wifi.getInternalWifiSubnet(), UserPreference.getHostSocketTimeout(getApplicationContext()));
new ScanHostsAsyncTask(MainActivity.this, db).execute(ip, wifi.getInternalWifiSubnet(), UserPreference.getHostSocketTimeout(context));
discoverHostsBtn.setAlpha(.3f);
discoverHostsBtn.setEnabled(false);
} catch (UnknownHostException | Wireless.NoWifiManagerException e) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedWifi));
Errors.showError(context, resources.getString(R.string.notConnectedWifi));
}
}
});
Expand Down Expand Up @@ -384,40 +400,15 @@ private void setClip(CharSequence label, String text) {
}
}

/**
* Sets up and registers receivers
*/
private void setupReceivers() {
receiver = new BroadcastReceiver() {

/**
* Detect if a network connection has been lost or established
* @param context
* @param intent
*/
@Override
public void onReceive(Context context, Intent intent) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (info == null) {
return;
}

getNetworkInfo(info);
}

};

intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
registerReceiver(receiver, intentFilter);
}

/**
* Gets network information about the device and updates various UI elements
*/
private void getNetworkInfo(NetworkInfo info) {
setupMac();
getExternalIp();

final Resources resources = getResources();
final Context context = getApplicationContext();
try {
boolean enabled = wifi.isEnabled();
if (!info.isConnected() || !enabled) {
Expand All @@ -433,7 +424,7 @@ private void getNetworkInfo(NetworkInfo info) {
return;
}
} catch (Wireless.NoWifiManagerException e) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.failedWifiManager));
Errors.showError(context, resources.getString(R.string.failedWifiManager));
}

if (!info.isConnected()) {
Expand All @@ -452,17 +443,17 @@ public void run() {
try {
speed = wifi.getLinkSpeed();
} catch (Wireless.NoWifiManagerException e) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.failedLinkSpeed));
Errors.showError(context, resources.getString(R.string.failedLinkSpeed));
return;
}
try {
signal = wifi.getSignalStrength();
} catch (Wireless.NoWifiManagerException e) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.failedSignal));
Errors.showError(context, resources.getString(R.string.failedSignal));
return;
}

signalStrength.setText(String.format(getResources().getString(R.string.signalLink), signal, speed));
signalStrength.setText(String.format(resources.getString(R.string.signalLink), signal, speed));
signalHandler.postDelayed(this, TIMER_INTERVAL);
}
}, 0);
Expand All @@ -474,13 +465,13 @@ public void run() {
try {
wifiSsid = wifi.getSSID();
} catch (Wireless.NoWifiManagerException e) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.failedSsid));
Errors.showError(context, resources.getString(R.string.failedSsid));
return;
}
try {
wifiBssid = wifi.getBSSID();
} catch (Wireless.NoWifiManagerException e) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.failedBssid));
Errors.showError(context, resources.getString(R.string.failedBssid));
return;
}

Expand Down Expand Up @@ -604,6 +595,9 @@ private void getExternalIp() {
public void onPause() {
super.onPause();

unregisterReceiver(receiver);
signalHandler.removeCallbacksAndMessages(null);

if (scanProgressDialog != null) {
scanProgressDialog.dismiss();
}
Expand All @@ -622,25 +616,11 @@ public void onPause() {
}

/**
* Activity destroyed
*/
@Override
public void onDestroy() {
super.onDestroy();

signalHandler.removeCallbacksAndMessages(null);

if (receiver != null) {
unregisterReceiver(receiver);
}
}

/**
* Activity restarted
* Activity resumed.
*/
@Override
public void onRestart() {
super.onRestart();
public void onResume() {
super.onResume();

registerReceiver(receiver, intentFilter);
}
Expand Down Expand Up @@ -700,8 +680,8 @@ public void run() {
@Override
public int compare(Host lhs, Host rhs) {
try {
int leftIp = new BigInteger(InetAddress.getByName(lhs.getIp()).getAddress()).intValue();
int rightIp = new BigInteger(InetAddress.getByName(rhs.getIp()).getAddress()).intValue();
int leftIp = ByteBuffer.wrap(InetAddress.getByName(lhs.getIp()).getAddress()).getInt();
int rightIp = ByteBuffer.wrap(InetAddress.getByName(rhs.getIp()).getAddress()).getInt();

return leftIp - rightIp;
} catch (UnknownHostException ignored) {
Expand Down
Loading

0 comments on commit 337ef63

Please sign in to comment.