Browse files

adjusted locationFinder, removed useless permission + minor adjustments

  • Loading branch information...
1 parent 570abcd commit b8e4d82a9e79ff6efe307f2fe7844dcf692c7d0e @uberspot committed Apr 2, 2012
View
5 AndroidManifest.xml
@@ -1,16 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ows.OpenWifiStatistics"
- android:versionCode="2"
- android:versionName="1.2" >
+ android:versionCode="3"
+ android:versionName="1.2.5" >
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
- <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
View
BIN bin/OpenWifiStatistics.apk
Binary file not shown.
View
2 res/xml/settings.xml
@@ -33,7 +33,7 @@
<EditTextPreference
android:name="Location scan time"
android:summary="Time in which location is scanned(in seconds)"
- android:defaultValue="120"
+ android:defaultValue="180"
android:title="@string/location_ttl"
android:key="lscan_ttl"
android:inputType="phone" />
View
23 src/com/ows/OpenWifiStatistics/Services/LocationFinder.java
@@ -17,9 +17,11 @@
private LocationManager locationManager;
+ public LocationManager getLocationManager() { return locationManager; }
+
private LocationListener locationListener;
- private Criteria criteria = new Criteria();
+ private Criteria criteria;
private LocationListener innerLocationManager = new LocationListener(){
@@ -55,14 +57,20 @@ public void onStatusChanged(String provider, int status, Bundle extras) {
public LocationFinder(LocationManager lmngr, LocationListener listener) {
locationManager = lmngr;//(LocationManager) app.getSystemService(Context.LOCATION_SERVICE);
locationListener = listener;
+
+ criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
criteria.setSpeedRequired(false);
startedListening = false;
}
+ /** Starts listening for location changes from the LocationManager. Sets the minimum
+ * time interval between updates from providers to 6 seconds and the minimum distance to 1 meter
+ * to consume less energy.
+ */
public void startListening() {
- startListening(0,0,0,0);
+ startListening(6000, 1, 6000, 1);
}
/** Starts listening for location changes from GPS_PROVIDER and NETWORK_PROVIDER if they are enabled.
@@ -81,8 +89,17 @@ public void startListening(int netmintimeinterval, int netmindist, int gpsmintim
startedListening = true;
}
+ /** Location finder stops receiving updates about location changes
+ */
public void stopListening() {
locationManager.removeUpdates(innerLocationManager);
startedListening = false;
- }
+ }
+
+ /** @return false if neither GPS_PROVIDER nor NETWORK_PROVIDER is enabled, true otherwise;
+ */
+ public boolean isEnabled() {
+ return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
+ && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
+ }
}
View
32 src/com/ows/OpenWifiStatistics/Services/MonitoringService.java
@@ -97,10 +97,10 @@
private static int scanTimeout, uploadTimeout, locationTimeout, locationTaskTTL;
/** Listens for results of wifi scans */
- BroadcastReceiver receiver;
+ private BroadcastReceiver receiver;
/** Schedules autoupload tasks and wifi scan tasks */
- Timer scanTimer, uploadTimer, locationTimer, saveTimer;
+ private Timer scanTimer, uploadTimer, locationTimer, saveTimer;
/* Location stuff */
private LocationFinder locationFinder;
@@ -115,13 +115,10 @@
public boolean isProviderDisabled() { return providerDisabled; }
- LocationListener listener = new LocationListener(){
+ private LocationListener listener = new LocationListener(){
public void onLocationChanged(Location location) {
- if(!(location.getProvider().equalsIgnoreCase("gps") || location.getProvider().equalsIgnoreCase("network"))) {
- latitude = LocationFinder.defaultLatitude;
- longitude = LocationFinder.defaultLongitude;
- } else {
+ if(location.getProvider().equalsIgnoreCase("gps") || location.getProvider().equalsIgnoreCase("network")) {
latitude = location.getLatitude();
longitude = location.getLongitude();
providerDisabled = false;
@@ -159,7 +156,7 @@ public void onCreate() {
scanResults = (ConcurrentHashMap<String, EScanResult>) storageUtils.loadObjectFromInternalStorage("scanresults");
- if(scanResults==null)
+ if(scanResults == null)
scanResults = new ConcurrentHashMap<String, EScanResult>(1000);
//start listening for current location
@@ -193,8 +190,13 @@ public void onCreate() {
}
}, 60000, 60000);
- if(!wifi.isWifiEnabled()) {
- Toast.makeText(this,"Please enable wifi first!", Toast.LENGTH_SHORT).show();
+ boolean wifiEnabled = wifi.isWifiEnabled(), locationEnabled = locationFinder.isEnabled();
+ if(!wifiEnabled && !locationEnabled) {
+ Toast.makeText(this,"Please enable wifi and gps/network location to receive scans!", Toast.LENGTH_SHORT).show();
+ } else if(!wifiEnabled) {
+ Toast.makeText(this,"Please enable wifi to receive scans!", Toast.LENGTH_SHORT).show();
+ } else if(!locationEnabled) {
+ Toast.makeText(this,"Please enable gps or network location retrieving!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this,"Monitoring started", Toast.LENGTH_SHORT).show();
}
@@ -215,23 +217,23 @@ public void loadPreferences() {
int usageScenario = Integer.parseInt(prefs.getString("usage_scenario", "1"));
if(usageScenario == 1) {
scanTimeout = 30000; uploadTimeout = 420000;
- locationTimeout = 40000; locationTaskTTL = 120000;
+ locationTimeout = 40000; locationTaskTTL = 240000;
} else if(usageScenario == 2) {
- scanTimeout = 5000; uploadTimeout = 720000;
+ scanTimeout = 7000; uploadTimeout = 720000;
locationTimeout = 10000; locationTaskTTL = Integer.MAX_VALUE;
} else if(usageScenario == 3) {
scanTimeout = 60000; uploadTimeout = 720000;
- locationTimeout = 120000; locationTaskTTL = 120000;
+ locationTimeout = 120000; locationTaskTTL = 150000;
} else {
scanTimeout = Integer.parseInt(prefs.getString("wScanPref", "30")) * 1000;
uploadTimeout = Integer.parseInt(prefs.getString("uploadPref", "420")) * 1000;
locationTimeout = Integer.parseInt(prefs.getString("lScanPref", "60")) * 1000;
- locationTaskTTL = Integer.parseInt(prefs.getString("lscan_ttl", "120")) * 1000;
+ locationTaskTTL = Integer.parseInt(prefs.getString("lscan_ttl", "180")) * 1000;
}
} catch (NumberFormatException e) {
Toast.makeText(this,"Error in loading settings, using defaults", Toast.LENGTH_SHORT).show();
scanTimeout = 30000; uploadTimeout = 420000;
- locationTimeout = 40000; locationTaskTTL = 120000;
+ locationTimeout = 40000; locationTaskTTL = 240000;
}
}
View
2 src/com/ows/OpenWifiStatistics/StartPage.java
@@ -180,7 +180,7 @@ public void toggleMonitoring(View v) {
storage.savePreference(prefName, prefName, "true");
//Set UI handler for service after it starts
- new Timer().schedule(new TimerTask(){
+ new Timer("Temp Handler Timer").schedule(new TimerTask(){
@Override
public void run() {
if(MonitoringService.service!=null)

0 comments on commit b8e4d82

Please sign in to comment.