Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ coverage
libs
release
*IntegrationTest.java
caches
37 changes: 37 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Development

## Developing Using Docker

Benefits:

* no need to modify your environment
* can try new dependencies by changing the Dockerfile
* use any text editor to maintaining

Downsides:

* slow
* no nice IDE
* some challenges keeping image and host directory in sync

Pull the docker image, run it and run ```gradle build```:

```
./build-on-docker.sh
```

First time builds takes about 20 minutes (downloading dependencies, compilation and testing).

Caches are stored in the ```caches/``` directory of the host.

Edit-compiled-run is done as:

```
gradle --continuous assembleDebug
```

You can install as follows (```brew install android-platform-tools```):

```
adb install -r -g app-debug.apk
```
6 changes: 3 additions & 3 deletions app/build.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Build Properties
#Sat Nov 24 09:14:14 EST 2018
#Sun Dec 09 09:54:21 UTC 2018
version_minor=0
version_build=0
version_patch=3
version_store=44
version_patch=4
version_major=2
version_store=45
58 changes: 57 additions & 1 deletion app/src/main/java/com/vrem/wifianalyzer/wifi/model/WiFiData.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
package com.vrem.wifianalyzer.wifi.model;

import android.support.annotation.NonNull;
import android.widget.Toast;

import com.vrem.wifianalyzer.MainContext;
import com.vrem.wifianalyzer.vendor.model.VendorService;
import com.vrem.wifianalyzer.MainContext;
import com.vrem.util.FileUtils;
import com.vrem.wifianalyzer.R;
import android.content.res.Resources;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.IterableUtils;
Expand All @@ -33,13 +38,29 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import org.json.JSONObject;

public class WiFiData {
public static final WiFiData EMPTY = new WiFiData(Collections.emptyList(), WiFiConnection.EMPTY, Collections.emptyList());

private final List<WiFiDetail> wiFiDetails;
private final WiFiConnection wiFiConnection;
private final List<String> wiFiConfigurations;
private final WiFiConnection wiFiConnection;
private static JSONObject wiFiLocations = new JSONObject();
static
{
try {
String content = FileUtils.readFile(MainContext.INSTANCE.getResources(), R.raw.shanghai);
wiFiLocations = new JSONObject(content);
Toast.makeText(MainContext.INSTANCE.getContext(), "Loaded locations with " + wiFiLocations.length() + " MAC -> location mappings", Toast.LENGTH_LONG).show();
} catch(Exception e) {
Toast.makeText(MainContext.INSTANCE.getContext(), "Failed to load locations", Toast.LENGTH_LONG).show();
}
}
private static String lastNotified = "";

public WiFiData(@NonNull List<WiFiDetail> wiFiDetails, @NonNull WiFiConnection wiFiConnection, @NonNull List<String> wiFiConfigurations) {
this.wiFiDetails = wiFiDetails;
Expand All @@ -65,6 +86,7 @@ public List<WiFiDetail> getWiFiDetails(@NonNull Predicate<WiFiDetail> predicate,
results = sortAndGroup(results, sortBy, groupBy);
}
Collections.sort(results, sortBy.comparator());
notifyLocation(results);
return results;
}

Expand All @@ -91,6 +113,40 @@ List<WiFiDetail> sortAndGroup(@NonNull List<WiFiDetail> wiFiDetails, @NonNull So
return results;
}

private void notifyLocation(List<WiFiDetail> wifiDetails) {
if(wifiDetails.size() < 3) {
return;
}
try {
String lookupKey = (wifiDetails.get(0).getBSSID() + " " + wifiDetails.get(1).getBSSID() + " " + wifiDetails.get(2).getBSSID()).toUpperCase();
String location = wiFiLocations.getString(lookupKey);
if(location == null) {
location = wiFiLocations.getString((wifiDetails.get(1).getBSSID() + " " + wifiDetails.get(0).getBSSID() + " " + wifiDetails.get(2).getBSSID()).toUpperCase());
}
if(location == null) {
location = wiFiLocations.getString((wifiDetails.get(0).getBSSID() + " " + wifiDetails.get(1).getBSSID()).toUpperCase());
}
if(location == null) {
location = wiFiLocations.getString((wifiDetails.get(1).getBSSID() + " " + wifiDetails.get(0).getBSSID()).toUpperCase());
}
if(location == null) {
location = wiFiLocations.getString(wifiDetails.get(0).getBSSID().toUpperCase());
}
if(location == null) {
location = wiFiLocations.getString(wifiDetails.get(1).getBSSID().toUpperCase());
}
if(location != null) {
if(!lastNotified.equals(location)) {
Toast.makeText(MainContext.INSTANCE.getContext(), "You are in " + location, Toast.LENGTH_LONG).show();
lastNotified = location;
}
} else {
//Toast.makeText(MainContext.INSTANCE.getContext(), "Nothing found " + lookupKey, Toast.LENGTH_SHORT).show();
}
} catch(Exception e) {
}
}

@NonNull
private List<WiFiDetail> getWiFiDetails(@NonNull Predicate<WiFiDetail> predicate) {
Collection<WiFiDetail> selected = CollectionUtils.select(wiFiDetails, predicate);
Expand Down
Loading