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 26, 2020
2 parents 01ae163 + 7a5b136 commit ce56779
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 22 deletions.
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ sonarqube {
}

android {
viewBinding.enabled = true
compileSdkVersion 29
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 29
versionCode 58
versionName "2.2.13"
versionCode 59
versionName "2.3.1"
applicationId "com.aaronjwood.portauthority"
setProperty("archivesBaseName", "PortAuthority-$versionName")
}
Expand Down Expand Up @@ -68,7 +69,7 @@ android {
dependencies {
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.squareup.okhttp3:okhttp:4.4.0'
implementation 'com.squareup.okhttp3:okhttp:3.12.9' // Anything past 3.12.x will break our Android 4 support!
implementation 'jcifs:jcifs:1.3.17'
implementation 'dnsjava:dnsjava:3.0.1'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2'
Expand Down
10 changes: 10 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
-dontnote org.xbill.DNS.spi.DNSJavaNameServiceDescriptor
-dontwarn org.xbill.DNS.spi.DNSJavaNameServiceDescriptor
-keep class org.xbill.** { *; }
-keepattributes EnclosingMethod
-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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.aaronjwood.portauthority.activity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
Expand Down Expand Up @@ -49,7 +50,7 @@ protected void onSaveInstanceState(Bundle savedState) {
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);

String recordData = savedInstanceState.getString("records");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public void onClick(View v) {
}

portRangeDialog = new Dialog(LanHostActivity.this, R.style.DialogTheme);
portRangeDialog.setTitle("Select Port Range");
portRangeDialog.setContentView(R.layout.port_range);
portRangeDialog.show();

Expand Down Expand Up @@ -181,7 +180,7 @@ private void setupWol() {
}

host.wakeOnLan();
Toast.makeText(getApplicationContext(), String.format(getResources().getString(R.string.waking), host.getHostname()), Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), String.format(getResources().getString(R.string.waking), host.getHostname()), Toast.LENGTH_SHORT).show();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ClipData;
Expand Down Expand Up @@ -32,18 +33,21 @@
import android.view.animation.LayoutAnimationController;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.aaronjwood.portauthority.R;
import com.aaronjwood.portauthority.adapter.HostAdapter;
import com.aaronjwood.portauthority.async.DownloadAsyncTask;
import com.aaronjwood.portauthority.async.DownloadOuisAsyncTask;
import com.aaronjwood.portauthority.async.DownloadPortDataAsyncTask;
import com.aaronjwood.portauthority.async.ScanHostsAsyncTask;
import com.aaronjwood.portauthority.async.WolAsyncTask;
import com.aaronjwood.portauthority.db.Database;
import com.aaronjwood.portauthority.network.Host;
import com.aaronjwood.portauthority.network.Wireless;
Expand Down Expand Up @@ -548,6 +552,38 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
startActivity(new Intent(MainActivity.this, WanHostActivity.class));
break;
case 1:
Dialog wolDialog = new Dialog(MainActivity.this, R.style.DialogTheme);
wolDialog.setContentView(R.layout.wake_on_lan);
wolDialog.show();
Button wakeUp = wolDialog.findViewById(R.id.wolWake);
wakeUp.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
try {
if (!wifi.isConnectedWifi()) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.notConnectedLan));
return;
}
} catch (Wireless.NoConnectivityManagerException e) {
Errors.showError(getApplicationContext(), getResources().getString(R.string.failedWifiManager));
return;
}

EditText ip = wolDialog.findViewById(R.id.wolIp);
EditText mac = wolDialog.findViewById(R.id.wolMac);
String ipVal = ip.getText().toString();
String macVal = mac.getText().toString();
if (ipVal.isEmpty() || macVal.isEmpty()) {
return;
}

new WolAsyncTask().execute(macVal, ipVal);
Toast.makeText(getApplicationContext(), String.format(getResources().getString(R.string.waking), ipVal), Toast.LENGTH_SHORT).show();
}
});
break;
case 2:
startActivity(new Intent(MainActivity.this, DnsActivity.class));
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ private void scanPortRangeClick() {
public void onClick(View v) {

portRangeDialog = new Dialog(WanHostActivity.this, R.style.DialogTheme);
portRangeDialog.setTitle("Select Port Range");
portRangeDialog.setContentView(R.layout.port_range);
portRangeDialog.show();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ final void doInBackground(String service, Parser parser) {
return;
}

in = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream()), StandardCharsets.UTF_8));
in = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream()), "UTF-8"));
String line;

while ((line = in.readLine()) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ protected Void doInBackground(String... params) {
String mac = params[0];
String ip = params[1];

if (ip == null || mac == null || ip.isEmpty() || mac.isEmpty()) {
return null;
}

byte[] macBytes = new byte[6];
String[] macHex = mac.split("([:\\-])");
if (macHex.length != 6) {
return null;
}

for (int i = 0; i < 6; i++) {
macBytes[i] = (byte) Integer.parseInt(macHex[i], 16);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class UserPreference {
private static final String COARSE_LOCATION_PERM_DIAG = "COARSE_LOCATION";
private static final String FINE_LOCATION_PERM_DIAG = "FINE_LOCATION";

private static final String DEFAULT_WAN_SOCKET_TIMEOUT = "8000";
private static final String DEFAULT_LAN_SOCKET_TIMEOUT = "4000";
private static final String DEFAULT_HOST_SOCKET_TIMEOUT = "150";
private static final String DEFAULT_PORT_SCAN_THREADS = "500";

/**
* Saves the last used host address for later use.
*
Expand Down Expand Up @@ -169,11 +174,12 @@ public static int getPortRangeHigh(@NonNull Context context) {
*/
public static int getPortScanThreads(@NonNull Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
int numThreads = Integer.parseInt(preferences.getString(PORT_SCAN_THREADS, "500"));
if (numThreads == 0) {
return 500;
String threads = preferences.getString(PORT_SCAN_THREADS, DEFAULT_PORT_SCAN_THREADS);
if (threads.isEmpty()) {
return Integer.parseInt(DEFAULT_PORT_SCAN_THREADS);
}
return numThreads;

return Integer.parseInt(threads);
}

/**
Expand All @@ -195,7 +201,12 @@ public static boolean getFetchExternalIp(@NonNull Context context) {
*/
public static int getLanSocketTimeout(@NonNull Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
return Integer.parseInt(preferences.getString(LAN_SOCKET_TIMEOUT, "4000"));
String timeout = preferences.getString(LAN_SOCKET_TIMEOUT, DEFAULT_LAN_SOCKET_TIMEOUT);
if (timeout.isEmpty()) {
return Integer.parseInt(DEFAULT_LAN_SOCKET_TIMEOUT);
}

return Integer.parseInt(timeout);
}

/**
Expand All @@ -206,7 +217,12 @@ public static int getLanSocketTimeout(@NonNull Context context) {
*/
public static int getWanSocketTimeout(@NonNull Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
return Integer.parseInt(preferences.getString(WAN_SOCKET_TIMEOUT, "8000"));
String timeout = preferences.getString(WAN_SOCKET_TIMEOUT, DEFAULT_WAN_SOCKET_TIMEOUT);
if (timeout.isEmpty()) {
return Integer.parseInt(DEFAULT_WAN_SOCKET_TIMEOUT);
}

return Integer.parseInt(timeout);
}

/**
Expand All @@ -217,6 +233,11 @@ public static int getWanSocketTimeout(@NonNull Context context) {
*/
public static int getHostSocketTimeout(@NonNull Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
return Integer.parseInt(preferences.getString(HOST_SOCKET_TIMEOUT, "150"));
String timeout = preferences.getString(HOST_SOCKET_TIMEOUT, DEFAULT_HOST_SOCKET_TIMEOUT);
if (timeout.isEmpty()) {
return Integer.parseInt(DEFAULT_HOST_SOCKET_TIMEOUT);
}

return Integer.parseInt(timeout);
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/port_range.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
android:text="@string/resetPortRange"
android:textColor="@drawable/button_text" />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:padding="6dp">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
Expand Down
47 changes: 47 additions & 0 deletions app/src/main/res/layout/wake_on_lan.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:theme="@style/DialogTheme">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:padding="6dp">

<EditText
android:id="@+id/wolIp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:hint="@string/ipAddress"
android:paddingBottom="5dp" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="6dp">

<EditText
android:id="@+id/wolMac"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:hint="@string/macAddress"
android:paddingBottom="5dp" />
</LinearLayout>

<Button
android:id="@+id/wolWake"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginBottom="10dp"
android:background="@drawable/button"
android:text="@string/wakeOnLan"
android:textColor="@drawable/button_text" />
</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</string-array>
<string-array name="upperDrawer">
<item>\u2601 Scan WAN Host</item>
<item>\u263c Wake Up Host</item>
<item>\u2194 DNS Lookup</item>
</string-array>
<string-array name="lowerDrawer">
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:3.6.0'
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.4'
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jan 01 19:13:52 PST 2020
#Tue Feb 25 19:13:51 PST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

0 comments on commit ce56779

Please sign in to comment.