diff --git a/NetworkLocation/AndroidManifest.xml b/NetworkLocation/AndroidManifest.xml index 68a7761..fea16a1 100644 --- a/NetworkLocation/AndroidManifest.xml +++ b/NetworkLocation/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="1302" + android:versionName="1.3.2"> 4.0.0 org.microg.networklocation NetworkLocation - 1.3.1 + 1.3.2 apk NetworkLocation diff --git a/NetworkLocation/src/org/microg/networklocation/MainService.java b/NetworkLocation/src/org/microg/networklocation/MainService.java index ea01065..7bb8d64 100644 --- a/NetworkLocation/src/org/microg/networklocation/MainService.java +++ b/NetworkLocation/src/org/microg/networklocation/MainService.java @@ -22,6 +22,7 @@ import org.microg.networklocation.data.LocationCalculator; import org.microg.networklocation.data.LocationRetriever; import org.microg.networklocation.data.WifiSpec; +import org.microg.networklocation.database.GeocodeDatabase; import org.microg.networklocation.database.LocationDatabase; import org.microg.networklocation.helper.Reflected; import org.microg.networklocation.platform.PlatformFactory; @@ -118,6 +119,8 @@ public void onCreate() { wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); nlprovider = PlatformFactory.newNetworkLocationProvider(); geoprovider = PlatformFactory.newGeocodeProvider(); + GeocodeDatabase geocodeDatabase = new GeocodeDatabase(); + geoprovider.setGeocodeDatabase(geocodeDatabase); WifiSpecRetriever wifiSpecRetriever = PlatformFactory.newWifiSpecRetriever(context); CellSpecRetriever cellSpecRetriever = PlatformFactory.newCellSpecRetriever(context); LocationDatabase locationDatabase = new LocationDatabase(context); diff --git a/NetworkLocation/src/org/microg/networklocation/database/GeocodeDatabase.java b/NetworkLocation/src/org/microg/networklocation/database/GeocodeDatabase.java index 96d12b5..7b915b1 100644 --- a/NetworkLocation/src/org/microg/networklocation/database/GeocodeDatabase.java +++ b/NetworkLocation/src/org/microg/networklocation/database/GeocodeDatabase.java @@ -1,6 +1,8 @@ package org.microg.networklocation.database; import android.location.Address; +import android.util.Log; +import org.microg.networklocation.MainService; import java.util.HashMap; import java.util.List; @@ -10,6 +12,7 @@ * This provides basic caching capabilities until the real database is ready. */ public class GeocodeDatabase { + private static final String TAG = "GeocodeDatabase"; private Map> intDb = new HashMap>(); private Map> stringDb = new HashMap>(); @@ -22,18 +25,44 @@ private static long dbIdent(double latitude, double longitude) { } public List
get(String locationName) { - return stringDb.get(locationName); + try { + return stringDb.get(locationName); + } catch (Throwable t) { + if (MainService.DEBUG) { + Log.w(TAG, t); + } + return null; + } } public List
get(double latitude, double longitude) { - return intDb.get(dbIdent(latitude, longitude)); + try { + return intDb.get(dbIdent(latitude, longitude)); + } catch (Throwable t) { + if (MainService.DEBUG) { + Log.w(TAG, t); + } + return null; + } } public void put(double latitude, double longitude, List
addresses) { - intDb.put(dbIdent(latitude, longitude), addresses); + try { + intDb.put(dbIdent(latitude, longitude), addresses); + } catch (Throwable t) { + if (MainService.DEBUG) { + Log.w(TAG, t); + } + } } public void put(String locationName, List
addresses) { - stringDb.put(locationName, addresses); + try { + stringDb.put(locationName, addresses); + } catch (Throwable t) { + if (MainService.DEBUG) { + Log.w(TAG, t); + } + } } } diff --git a/NetworkLocation/src/org/microg/networklocation/platform/GeocodeProvider.java b/NetworkLocation/src/org/microg/networklocation/platform/GeocodeProvider.java index 1cb9522..91f6400 100644 --- a/NetworkLocation/src/org/microg/networklocation/platform/GeocodeProvider.java +++ b/NetworkLocation/src/org/microg/networklocation/platform/GeocodeProvider.java @@ -17,17 +17,34 @@ class GeocodeProvider extends internal.com.android.location.provider.GeocodeProv private GeocodeDatabase geocodeDatabase; private List sources; + @Override + public void setGeocodeDatabase(GeocodeDatabase geocodeDatabase) { + this.geocodeDatabase = geocodeDatabase; + } + @Override public String onGetFromLocation(double latitude, double longitude, int maxResults, GeocoderParams params, List
addrs) { - List
addresses = geocodeDatabase.get(latitude, longitude); + if (MainService.DEBUG) { + Log.d(TAG, "Reverse request: " + latitude + "/" + longitude); + } + List
addresses = null; + if (geocodeDatabase != null) { + addresses = geocodeDatabase.get(latitude, longitude); + } if ((addresses != null) && !addresses.isEmpty()) { // database hit + if (MainService.DEBUG) { + Log.d(TAG, "Using database entry: " + addrs.get(0)); + } addrs.addAll(addresses); return null; } for (GeocodeSource source : sources) { if (source.isSourceAvailable()) { + if (MainService.DEBUG) { + Log.d(TAG, "Try reverse using: " + source.getName()); + } try { addresses = source.getFromLocation(latitude, longitude, params.getClientPackage(), params.getLocale()); @@ -54,6 +71,9 @@ public String onGetFromLocation(double latitude, double longitude, int maxResult public String onGetFromLocationName(String locationName, double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude, double upperRightLongitude, int maxResults, GeocoderParams params, List
addrs) { + if (MainService.DEBUG) { + Log.d(TAG, "Forward request: " + locationName); + } List
addresses = geocodeDatabase.get(locationName); if ((addresses != null) && !addresses.isEmpty()) { // database hit diff --git a/NetworkLocation/src/org/microg/networklocation/provider/GeocodeProvider.java b/NetworkLocation/src/org/microg/networklocation/provider/GeocodeProvider.java index da9f08b..cf692aa 100644 --- a/NetworkLocation/src/org/microg/networklocation/provider/GeocodeProvider.java +++ b/NetworkLocation/src/org/microg/networklocation/provider/GeocodeProvider.java @@ -1,6 +1,7 @@ package org.microg.networklocation.provider; import android.os.IBinder; +import org.microg.networklocation.database.GeocodeDatabase; import org.microg.networklocation.source.GeocodeSource; import java.util.List; @@ -8,5 +9,7 @@ public interface GeocodeProvider { IBinder getBinder(); + void setGeocodeDatabase(GeocodeDatabase geocodeDatabase); + void setSources(List geocodeSources); }