aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2010-10-23 00:40:57 +0200
committerHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2010-10-23 00:40:57 +0200
commit32d6cc92009c2212fcacd03529b99ffc87ea1a4d (patch)
treea1291de65a5c1113e2bff4b8f323d9311f02473b /src
parent94c5532b243d746d7c53067fad600fb3f35246d7 (diff)
downloadBlueGPS-32d6cc92009c2212fcacd03529b99ffc87ea1a4d.zip
BlueGPS-32d6cc92009c2212fcacd03529b99ffc87ea1a4d.tar.gz
BlueGPS-32d6cc92009c2212fcacd03529b99ffc87ea1a4d.tar.bz2
auto-enable gps provider if it doesn't exist and prevent forceclose if Mock Locations is disabled
Diffstat (limited to 'src')
-rw-r--r--src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java120
1 files changed, 68 insertions, 52 deletions
diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
index be4e973..a86f17a 100644
--- a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
+++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
@@ -43,6 +43,7 @@ public class NmeaParser {
private boolean hasRMC = false;
private LocationManager lm;
private float precision = 10f;
+ private boolean mockGpsAutoEnabled = false;
private boolean mockGpsEnabled = false;
private String mockLocationProvider = null;
@@ -60,67 +61,80 @@ public class NmeaParser {
}
public void enableMockLocationProvider(String gpsName){
- LocationProvider prov;
- if (gpsName != null && gpsName != "" ){
- if (! gpsName.equals(mockLocationProvider)){
- disableMockLocationProvider();
- mockLocationProvider = gpsName;
- }
- if (! mockGpsEnabled){
+ try {
+ LocationProvider prov;
+ if (gpsName != null && gpsName != "" ){
+ if (! gpsName.equals(mockLocationProvider)){
+ disableMockLocationProvider();
+ mockLocationProvider = gpsName;
+ }
+ if (! mockGpsEnabled){
+ prov = lm.getProvider(mockLocationProvider);
+ if (prov != null){
+ Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ }
+ lm.addTestProvider(mockLocationProvider, false, true,false, false, true, true, true, Criteria.POWER_HIGH, Criteria.ACCURACY_FINE);
+ if ((prov == null)
+ // || (! LocationManager.GPS_PROVIDER.equals(mockLocationProvider))
+ ){
+ Log.e("BT test", "enabling Mock provider: "+mockLocationProvider);
+ lm.setTestProviderEnabled(mockLocationProvider, true);
+ mockGpsAutoEnabled = true;
+ }
+ mockGpsEnabled = true;
+ } else {
+ Log.e("BT test", "Mock provider already enabled: "+mockLocationProvider);
+ }
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
- lm.addTestProvider(mockLocationProvider, false, true,false, false, true, true, true, Criteria.POWER_HIGH, Criteria.ACCURACY_FINE);
- if (! LocationManager.GPS_PROVIDER.equals(mockLocationProvider)){
- // mockGpsEnabled = locationManager.isProviderEnabled(mockLocationProvider);
- lm.setTestProviderEnabled(mockLocationProvider, true);
- }
- mockGpsEnabled = true;
- } else {
- Log.e("BT test", "Mock provider already enabled: "+mockLocationProvider);
- }
- prov = lm.getProvider(mockLocationProvider);
- if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
+ } catch (SecurityException e){
+ Log.e("BT test", "Error while enabling Mock Mocations Provider", e);
+ disableMockLocationProvider();
}
}
public void disableMockLocationProvider(){
- LocationProvider prov;
- if (mockLocationProvider != null && mockLocationProvider != "" && mockGpsEnabled){
- prov = lm.getProvider(mockLocationProvider);
- if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ try {
+ LocationProvider prov;
+ if (mockLocationProvider != null && mockLocationProvider != "" && mockGpsEnabled){
+ prov = lm.getProvider(mockLocationProvider);
+ if (prov != null){
+ Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ }
+ mockGpsEnabled = false;
+ if ( mockGpsAutoEnabled ) {
+ Log.e("BT test", "disabling Mock provider: "+mockLocationProvider);
+ lm.setTestProviderEnabled(mockLocationProvider, false);
+ }
+ prov = lm.getProvider(mockLocationProvider);
+ if (prov != null){
+ Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ }
+ lm.clearTestProviderEnabled(mockLocationProvider);
+ prov = lm.getProvider(mockLocationProvider);
+ if (prov != null){
+ Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ }
+ lm.clearTestProviderStatus(mockLocationProvider);
+ lm.removeTestProvider(mockLocationProvider);
+ prov = lm.getProvider(mockLocationProvider);
+ if (prov != null){
+ Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ }
+ Log.e("BT test", "removed mock GPS");
+ } else {
+ Log.e("BT test", "Mock provider already disabled: "+mockLocationProvider);
}
+ } catch (SecurityException e){
+ Log.e("BT test", "Error while enabling Mock Mocations Provider", e);
+ } finally {
+ mockLocationProvider = null;
mockGpsEnabled = false;
- if (! LocationManager.GPS_PROVIDER.equals(mockLocationProvider)){
- // mockGpsEnabled = locationManager.isProviderEnabled(mockLocationProvider);
- lm.setTestProviderEnabled(mockLocationProvider, false);
- }
- // locationManager.setTestProviderEnabled(mockLocationProvider, mockGpsEnabled);
- prov = lm.getProvider(mockLocationProvider);
- if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
- }
- lm.clearTestProviderEnabled(mockLocationProvider);
- prov = lm.getProvider(mockLocationProvider);
- if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
- }
- lm.clearTestProviderStatus(mockLocationProvider);
- lm.removeTestProvider(mockLocationProvider);
- prov = lm.getProvider(mockLocationProvider);
- if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
- }
- Log.e("BT test", "removed mock GPS");
- } else {
- Log.e("BT test", "Mock provider already disabled: "+mockLocationProvider);
+ mockGpsAutoEnabled = false;
}
- mockLocationProvider = null;
- mockGpsEnabled = false;
}
/**
@@ -137,8 +151,7 @@ public class NmeaParser {
return mockLocationProvider;
}
- private void notifyFix(Location fix){
- //R.drawable.stat
+ private void notifyFix(Location fix) throws SecurityException {
fixTime = null;
hasGGA = false;
hasRMC=false;
@@ -153,11 +166,13 @@ public class NmeaParser {
}
// parse NMEA Sentence
- public void parseNmeaSentence(String gpsSentence){
+ public String parseNmeaSentence(String gpsSentence) throws SecurityException {
+ String nmeaSentence = null;
Log.e("BT test", "data: "+System.currentTimeMillis()+" "+gpsSentence);
Pattern xx = Pattern.compile("\\$([^*$]*)\\*([0-9A-F][0-9A-F])?\r\n");
Matcher m = xx.matcher(gpsSentence);
if (m.matches()){
+ nmeaSentence = m.group(0);
String sentence = m.group(1);
String checkSum = m.group(2);
Log.e("BT test", "data: "+System.currentTimeMillis()+" "+sentence+" cheksum; "+checkSum +" control: "+String.format("%X",computeChecksum(sentence)));
@@ -405,6 +420,7 @@ public class NmeaParser {
// Mode indicator, (A=autonomous, D=differential, E=Estimated, N=not valid, S=Simulator )
}
}
+ return nmeaSentence;
}
public double parseNmeaLatitude(String lat,String orientation){