Skip to content

Commit 9ff0c49

Browse files
committed
Fixed stupid merge commit issue
1 parent b32f331 commit 9ff0c49

File tree

10 files changed

+213
-169
lines changed

10 files changed

+213
-169
lines changed

app/build.gradle

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2'
99

1010
// This is so we can publish straight to Google Play
11-
classpath 'com.github.triplet.gradle:play-publisher:1.1.5'
11+
classpath 'com.github.triplet.gradle:play-publisher:1.2.2'
1212
}
1313
}
1414

@@ -17,8 +17,8 @@ apply plugin: 'spoon'
1717
apply plugin: 'com.github.triplet.play'
1818

1919
play {
20-
track = 'alpha'
21-
serviceAccountEmail = 'androidnetworktoolspublisher@api-6650335122940819061-609121.iam.gserviceaccount.com'
20+
track = 'beta'
21+
serviceAccountEmail ANDROID_NETWORK_TOOLS_SERVICE_ACCOUNT
2222
pk12File = file('../key.p12')
2323
}
2424

@@ -30,8 +30,8 @@ android {
3030
applicationId "com.stealthcotper.networktools"
3131
minSdkVersion minSdkVer
3232
targetSdkVersion targetSdkVer
33-
versionCode 13
34-
versionName "0.3.08"
33+
versionCode versionName
34+
versionName versionCode
3535
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3636
}
3737

@@ -57,13 +57,6 @@ android {
5757
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
5858
}
5959
}
60-
61-
// productFlavors {
62-
// regular { }
63-
// // Add a CI only flavor that has extra permissions needed for CI to perform
64-
// ci { }
65-
// }
66-
6760
}
6861

6962
// Spoon used for CI / Testing

app/src/androidTest/java/com/stealthcotper/networktools/ApplicationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
88
*/
99
public class ApplicationTest extends ApplicationTestCase<Application> {
10-
public ApplicationTest() {
11-
super(Application.class);
12-
}
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
1313
}

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ subprojects {
3030
ext.targetSdkVer = 27
3131
ext.supportLibVer = "27.1.1"
3232

33-
ext.versionName = "0.3.08"
34-
ext.versionCode = 13
33+
ext.versionName = "0.4.0"
34+
ext.versionCode = 14
3535
}

library/build.gradle

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
apply plugin: 'com.android.library'
1+
apply plugin: 'java'
2+
apply plugin: 'maven'
23

3-
android {
4-
compileSdkVersion compileSdkVer
5-
buildToolsVersion buildToolsVer
6-
7-
defaultConfig {
8-
minSdkVersion minSdkVer
9-
targetSdkVersion targetSdkVer
10-
versionCode 13
11-
versionName "0.3.08"
12-
}
13-
buildTypes {
14-
release {
15-
minifyEnabled false
16-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17-
}
18-
}
19-
}
4+
group = 'com.github.stealthcopter'
205

216
dependencies {
227
testImplementation 'junit:junit:4.12'
238
testImplementation 'org.mockito:mockito-core:2.10.0'
24-
provided 'com.android.support:appcompat-v7:27.1.1'
259
}
10+
11+
sourceCompatibility = "1.7"
12+
targetCompatibility = "1.7"

library/src/main/java/com/stealthcopter/networktools/MACTools.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.stealthcopter.networktools;
22

3-
import android.support.annotation.NonNull;
4-
53
import java.util.regex.Pattern;
64

75
public class MACTools {
@@ -19,9 +17,8 @@ private MACTools() {
1917
* Validates a provided MAC address
2018
*
2119
* @param macAddress - the MAC address to check
22-
*
2320
* @return - true if it is valid MAC address in IEEE802 format (either hyphen or colon seperated)
24-
* eg: "01:23:45:67:89:AB:CD:EF" or "01-23-45-67-89-AB-CD-EF"
21+
* eg: "01:23:45:67:89:AB" or "01-23-45-67-89-AB"
2522
*/
2623
public static boolean isValidMACAddress(final String macAddress) {
2724
return macAddress != null && PATTERN_MAC.matcher(macAddress).matches();
@@ -32,12 +29,11 @@ public static boolean isValidMACAddress(final String macAddress) {
3229
* Convert a MAC string to bytes
3330
*
3431
* @param macStr - MAC string in IEEE802 format (either hyphen or colon seperated)
35-
* eg: "01:23:45:67:89:AB:CD:EF" or "01-23-45-67-89-AB-CD-EF"
36-
*
32+
* eg: "01:23:45:67:89:AB" or "01-23-45-67-89-AB"
3733
* @return - MAC formatted in bytes
3834
* @throws IllegalArgumentException - if mac address is invalid
3935
*/
40-
public static byte[] getMacBytes(@NonNull String macStr) throws IllegalArgumentException {
36+
public static byte[] getMacBytes(String macStr) throws IllegalArgumentException {
4137

4238
if (macStr == null) throw new IllegalArgumentException("Mac Address cannot be null");
4339

@@ -56,4 +52,4 @@ public static byte[] getMacBytes(@NonNull String macStr) throws IllegalArgumentE
5652
return bytes;
5753
}
5854

59-
}
55+
}

library/src/main/java/com/stealthcopter/networktools/Ping.java

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.stealthcopter.networktools;
22

3-
import android.support.annotation.NonNull;
4-
53
import com.stealthcopter.networktools.ping.PingResult;
64
import com.stealthcopter.networktools.ping.PingStats;
75
import com.stealthcopter.networktools.ping.PingTools;
@@ -14,11 +12,21 @@
1412
*/
1513
public class Ping {
1614

15+
// Only try ping using the java method
16+
public static final int PING_JAVA = 0;
17+
18+
// Only try ping using the native method (will only work if native ping binary is found)
19+
public static final int PING_NATIVE = 1;
20+
21+
// Use a hybrid ping that will attempt to use native binary but fallback to using java method
22+
// if it's not found.
23+
public static final int PING_HYBRID = 2;
24+
1725
// This class is not to be instantiated
1826
private Ping() {
1927
}
2028

21-
public interface PingListener{
29+
public interface PingListener {
2230
void onResult(PingResult pingResult);
2331
void onFinished(PingStats pingStats);
2432
void onError(Exception e);
@@ -40,52 +48,57 @@ public interface PingListener{
4048
* @param address - Address to be pinged
4149
* @return this object to allow chaining
4250
*/
43-
public static Ping onAddress(@NonNull String address) {
51+
public static Ping onAddress(String address) {
4452
Ping ping = new Ping();
4553
ping.setAddressString(address);
4654
return ping;
4755
}
4856

4957
/**
5058
* Set the address to ping
59+
*
5160
* @param ia - Address to be pinged
5261
* @return this object to allow chaining
5362
*/
54-
public static Ping onAddress(@NonNull InetAddress ia) {
63+
public static Ping onAddress(InetAddress ia) {
5564
Ping ping = new Ping();
5665
ping.setAddress(ia);
5766
return ping;
5867
}
5968

6069
/**
6170
* Set the timeout
71+
*
6272
* @param timeOutMillis - the timeout for each ping in milliseconds
6373
* @return this object to allow chaining
6474
*/
65-
public Ping setTimeOutMillis(int timeOutMillis){
66-
if (timeOutMillis<0) throw new IllegalArgumentException("Times cannot be less than 0");
75+
public Ping setTimeOutMillis(int timeOutMillis) {
76+
if (timeOutMillis < 0) throw new IllegalArgumentException("Times cannot be less than 0");
6777
this.timeOutMillis = timeOutMillis;
6878
return this;
6979
}
7080

7181
/**
7282
* Set the delay between each ping
83+
*
7384
* @param delayBetweenScansMillis - the timeout for each ping in milliseconds
7485
* @return this object to allow chaining
7586
*/
76-
public Ping setDelayMillis(int delayBetweenScansMillis){
77-
if (delayBetweenScansMillis<0) throw new IllegalArgumentException("Delay cannot be less than 0");
87+
public Ping setDelayMillis(int delayBetweenScansMillis) {
88+
if (delayBetweenScansMillis < 0)
89+
throw new IllegalArgumentException("Delay cannot be less than 0");
7890
this.delayBetweenScansMillis = delayBetweenScansMillis;
7991
return this;
8092
}
8193

8294
/**
8395
* Set number of times to ping the address
96+
*
8497
* @param noTimes - number of times, 0 = continuous
8598
* @return this object to allow chaining
8699
*/
87-
public Ping setTimes(int noTimes){
88-
if (noTimes<0) throw new IllegalArgumentException("Times cannot be less than 0");
100+
public Ping setTimes(int noTimes) {
101+
if (noTimes < 0) throw new IllegalArgumentException("Times cannot be less than 0");
89102
this.times = noTimes;
90103
return this;
91104
}
@@ -96,6 +109,7 @@ private void setAddress(InetAddress address) {
96109

97110
/**
98111
* Set the address string which will be resolved to an address by resolveAddressString()
112+
*
99113
* @param addressString - String of the address to be pinged
100114
*/
101115
private void setAddressString(String addressString) {
@@ -108,7 +122,7 @@ private void setAddressString(String addressString) {
108122
* @throws UnknownHostException - if host cannot be found
109123
*/
110124
private void resolveAddressString() throws UnknownHostException {
111-
if (address == null && addressString !=null){
125+
if (address == null && addressString != null) {
112126
address = InetAddress.getByName(addressString);
113127
}
114128
}
@@ -125,6 +139,7 @@ public void cancel() {
125139
*
126140
* Note that this should be performed on a background thread as it will perform a network
127141
* request
142+
*
128143
* @return - ping result
129144
*/
130145
public PingResult doPing() throws UnknownHostException {
@@ -135,10 +150,11 @@ public PingResult doPing() throws UnknownHostException {
135150

136151
/**
137152
* Perform an asynchronous ping
153+
*
138154
* @param pingListener - the listener to fire PingResults to.
139155
* @return - this so we can cancel if needed
140156
*/
141-
public Ping doPing(final PingListener pingListener){
157+
public Ping doPing(final PingListener pingListener) {
142158

143159
new Thread(new Runnable() {
144160
@Override
@@ -151,7 +167,7 @@ public void run() {
151167
return;
152168
}
153169

154-
if (address == null){
170+
if (address == null) {
155171
pingListener.onError(new NullPointerException("Address is null"));
156172
return;
157173
}
@@ -166,24 +182,23 @@ public void run() {
166182
int noPings = times;
167183

168184
// times == 0 is the case that we can continuous scanning
169-
while(noPings>0 || times == 0){
185+
while (noPings > 0 || times == 0) {
170186
PingResult pingResult = PingTools.doPing(address, timeOutMillis);
171187

172-
if (pingListener!=null){
188+
if (pingListener != null) {
173189
pingListener.onResult(pingResult);
174190
}
175191

176192
// Update ping stats
177193
pingsCompleted++;
178194

179-
if (pingResult.hasError()){
195+
if (pingResult.hasError()) {
180196
noLostPackets++;
181-
}
182-
else{
197+
} else {
183198
float timeTaken = pingResult.getTimeTaken();
184199
totalPingTime += timeTaken;
185-
if (maxPingTime == - 1 || timeTaken > maxPingTime) maxPingTime = timeTaken;
186-
if (minPingTime == - 1 || timeTaken < minPingTime) minPingTime = timeTaken;
200+
if (maxPingTime == -1 || timeTaken > maxPingTime) maxPingTime = timeTaken;
201+
if (minPingTime == -1 || timeTaken < minPingTime) minPingTime = timeTaken;
187202
}
188203

189204
noPings--;
@@ -196,12 +211,12 @@ public void run() {
196211
}
197212
}
198213

199-
if (pingListener!=null){
214+
if (pingListener != null) {
200215
pingListener.onFinished(new PingStats(address, pingsCompleted, noLostPackets, totalPingTime, minPingTime, maxPingTime));
201216
}
202217
}
203218
}).start();
204219
return this;
205220
}
206221

207-
}
222+
}

0 commit comments

Comments
 (0)