aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2010-10-27 01:55:24 +0200
committerHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2010-10-27 01:55:24 +0200
commit04001207adcf5575c813797d9897e5dd2a672938 (patch)
tree349534e435c7a6333988119b4736a98e73960f6a
parentd8b89a578820620079353293cab0776f0d72e101 (diff)
parent442660e78d09eacc40ff1ac8545a13c23c0355b7 (diff)
downloadBlueGPS-04001207adcf5575c813797d9897e5dd2a672938.zip
BlueGPS-04001207adcf5575c813797d9897e5dd2a672938.tar.gz
BlueGPS-04001207adcf5575c813797d9897e5dd2a672938.tar.bz2
merging refs/heads/BlueGPS4Droid_1.1.x into master (1.2.x)
-rw-r--r--AndroidManifest.xml134
-rw-r--r--res/values-fr/strings.xml11
-rw-r--r--res/values/constants.xml74
-rw-r--r--res/values/strings.xml73
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java66
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java23
-rw-r--r--src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java119
-rw-r--r--version.txt11
8 files changed, 303 insertions, 208 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 017ed6a..031b17a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1,67 +1,67 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2010 Herbert von Broeuschmeul
- Copyright (C) 2010 BluetoothGPS4Droid Project
-
- This file is part of BluetoothGPS4Droid.
-
- BluetoothGPS4Droid is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- BluetoothGPS4Droid is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with BluetoothGPS4Droid. If not, see : http://www.gnu.org/licenses/.
--->
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="org.broeuschmeul.android.gps.bluetooth.provider"
- android:versionCode="4"
- android:versionName="1.2.alpha">
- <application android:icon="@drawable/icon" android:label="@string/app_name" android:allowClearUserData="true">
- <activity android:name=".BluetoothGpsActivity"
- android:label="@string/app_name"
- android:launchMode="singleTask" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
-
-<!--
- <service android:name=".BluetoothGpsProviderService" android:enabled="true" android:exported="true" android:process=":BluetoothGpsProviderService" >
--->
- <service android:name=".BluetoothGpsProviderService" android:enabled="true" android:exported="true" >
- <intent-filter>
- <action android:name="org.broeuschmeul.android.gps.bluetooth.tracker.nmea.intent.action.START_TRACK_RECORDING">
- <category android:name="android.intent.category.DEFAULT" />
- </action>
- <action android:name="org.broeuschmeul.android.gps.bluetooth.tracker.nmea.intent.action.STOP_TRACK_RECORDING">
- <category android:name="android.intent.category.DEFAULT" />
- </action>
- <action android:name="org.broeuschmeul.android.gps.bluetooth.provider.nmea.intent.action.START_GPS_PROVIDER">
- <category android:name="android.intent.category.DEFAULT" />
- </action>
- <action android:name="org.broeuschmeul.android.gps.bluetooth.provider.nmea.intent.action.STOP_GPS_PROVIDER">
- <category android:name="android.intent.category.DEFAULT" />
- </action>
- <action android:name="org.broeuschmeul.android.gps.bluetooth.provider.nmea.intent.action.CONFIGURE_SIRF_GPS">
- <category android:name="android.intent.category.DEFAULT" />
- </action>
- </intent-filter>
- </service>
-
- </application>
-
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.BLUETOOTH" />
- <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
- <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
-
- <uses-sdk android:targetSdkVersion="5" android:minSdkVersion="5" />
-</manifest> \ No newline at end of file
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2010 Herbert von Broeuschmeul
+ Copyright (C) 2010 BluetoothGPS4Droid Project
+
+ This file is part of BluetoothGPS4Droid.
+
+ BluetoothGPS4Droid is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ BluetoothGPS4Droid is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with BluetoothGPS4Droid. If not, see : http://www.gnu.org/licenses/.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.broeuschmeul.android.gps.bluetooth.provider"
+ android:versionCode="120"
+ android:versionName="1.2.0">
+ <application android:icon="@drawable/icon" android:label="@string/app_name" android:allowClearUserData="true">
+ <activity android:name=".BluetoothGpsActivity"
+ android:label="@string/app_name"
+ android:launchMode="singleTask" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+<!--
+ <service android:name=".BluetoothGpsProviderService" android:enabled="true" android:exported="true" android:process=":BluetoothGpsProviderService" >
+-->
+ <service android:name=".BluetoothGpsProviderService" android:enabled="true" android:exported="true" >
+ <intent-filter>
+ <action android:name="org.broeuschmeul.android.gps.bluetooth.tracker.nmea.intent.action.START_TRACK_RECORDING">
+ <category android:name="android.intent.category.DEFAULT" />
+ </action>
+ <action android:name="org.broeuschmeul.android.gps.bluetooth.tracker.nmea.intent.action.STOP_TRACK_RECORDING">
+ <category android:name="android.intent.category.DEFAULT" />
+ </action>
+ <action android:name="org.broeuschmeul.android.gps.bluetooth.provider.nmea.intent.action.START_GPS_PROVIDER">
+ <category android:name="android.intent.category.DEFAULT" />
+ </action>
+ <action android:name="org.broeuschmeul.android.gps.bluetooth.provider.nmea.intent.action.STOP_GPS_PROVIDER">
+ <category android:name="android.intent.category.DEFAULT" />
+ </action>
+ <action android:name="org.broeuschmeul.android.gps.bluetooth.provider.nmea.intent.action.CONFIGURE_SIRF_GPS">
+ <category android:name="android.intent.category.DEFAULT" />
+ </action>
+ </intent-filter>
+ </service>
+
+ </application>
+
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.BLUETOOTH" />
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+ <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
+
+ <uses-sdk android:targetSdkVersion="5" android:minSdkVersion="5" />
+</manifest>
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index d8215d8..c13a079 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -19,6 +19,8 @@
along with BluetoothGPS4Droid. If not, see : http://www.gnu.org/licenses/.
-->
<resources>
+ <string name="app_name">BlueGps</string>
+
<string name="pref_start_gps_title">Start/Stop GPS</string>
<string name="pref_start_gps_summary_off">Le GPS Bluetooth est arrêté</string>
<string name="pref_start_gps_summary_on">Le GPS Bluetooth est démarré</string>
@@ -76,6 +78,13 @@
<string name="msg_gps_provider_started">GPS Bluetooth... démarré</string>
<string name="msg_gps_provider_stopped">GPS Bluetooth... arrêté</string>
<string name="msg_gps_provider_already_started">GPS Bluetooth... déjà démarré</string>
+ <string name="msg_gps_provider_stopped_by_problem">"Oups ! %s"</string>
+ <string name="msg_two_many_connection_problems">Problèmes de connexion</string>
+ <string name="msg_gps_provider_disabled">Le GPS est désactivé</string>
+ <string name="msg_bluetooth_unsupported">Bluetooth non disponible</string>
+ <string name="msg_bluetooth_disabled">Bluetooth désactivé</string>
+ <string name="msg_mock_location_disabled">Postitions fictives non autorisées</string>
+ <string name="msg_bluetooth_gps_unavaible">Impossible de se connecter au GPS</string>
<string name="msg_nmea_recording_started">Enregistrement des traces NMEA... démarré</string>
<string name="msg_nmea_recording_stopped">Enregistrement des traces NMEA... arrêté</string>
<string name="msg_nmea_recording_already_started">Enregistrement des traces GPS... déjà démarré</string>
@@ -88,5 +97,5 @@
<item quantity="other">"Encore %d essais avant fermeture"</item>
</plurals>
<string name="service_closed_because_connection_problem_notification_title">BlueGps arrêté</string>
- <string name="service_closed_because_connection_problem_notification">Motif : problèmes de connexion</string>
+ <string name="service_closed_because_connection_problem_notification">"Motif : %s"</string>
</resources>
diff --git a/res/values/constants.xml b/res/values/constants.xml
new file mode 100644
index 0000000..b46b97d
--- /dev/null
+++ b/res/values/constants.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2010 Herbert von Broeuschmeul
+ Copyright (C) 2010 BluetoothGPS4Droid Project
+
+ This file is part of BluetoothGPS4Droid.
+
+ BluetoothGPS4Droid is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ BluetoothGPS4Droid is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with BluetoothGPS4Droid. If not, see : http://www.gnu.org/licenses/.
+-->
+<resources>
+ <string name="pref_start_gps_key">startGps</string>
+ <string name="pref_gps_location_provider_key">gpsLocationProviderKey</string>
+ <string name="pref_replace_std_gps_key">replaceStdtGps</string>
+ <string name="pref_mock_gps_name_key">mockGpsName</string>
+ <string name="pref_connection_retries_key">connectionRetries</string>
+ <string name="pref_recording_key">trackRecording</string>
+ <string name="pref_trackfile_directory_key">trackFileDirectory</string>
+ <string name="pref_trackfile_prefix_key">trackFilePrefix</string>
+ <string name="pref_bluetooth_device_key">bluetoothDevice</string>
+
+ <string name="pref_sirf_gps_key">sirfGps</string>
+ <string name="pref_sirf_enable_gll_key">enableGLL</string>
+ <string name="pref_sirf_enable_vtg_key">enableVTG</string>
+ <string name="pref_sirf_enable_gsa_key">enableGSA</string>
+ <string name="pref_sirf_enable_gsv_key">enableGSV</string>
+ <string name="pref_sirf_enable_zda_key">enableZDA</string>
+ <string name="pref_sirf_enable_sbas_key">enableSBAS</string>
+ <string name="pref_sirf_enable_nmea_key">enableNMEA</string>
+ <string name="pref_sirf_enable_static_navigation_key">enableStaticNavigation</string>
+
+ <string name="defaultConnectionRetries">0</string>
+ <string name="defaultTrackFileDirectory">/sdcard/nmea</string>
+ <string name="defaultTrackFilePrefix">btnmeatrack</string>
+ <string name="defaultMockGpsName">bluetooth_gps</string>
+
+
+ <string name="sirf_nmea_gga_on">PSRF103,00,00,01,01</string>
+ <string name="sirf_nmea_rmc_on">PSRF103,04,00,01,01</string>
+ <string name="sirf_nmea_gll_on">PSRF103,01,00,01,01</string>
+ <string name="sirf_nmea_gll_off">PSRF103,01,00,00,01</string>
+ <string name="sirf_nmea_gsa_on">PSRF103,02,00,05,01</string>
+ <string name="sirf_nmea_gsa_off">PSRF103,02,00,00,01</string>
+ <string name="sirf_nmea_gsv_on">PSRF103,03,00,05,01</string>
+ <string name="sirf_nmea_gsv_off">PSRF103,03,00,00,01</string>
+ <string name="sirf_nmea_vtg_on">PSRF103,05,00,01,01</string>
+ <string name="sirf_nmea_vtg_off">PSRF103,05,00,00,01</string>
+ <string name="sirf_nmea_zda_on">PSRF103,08,00,01,01</string>
+ <string name="sirf_nmea_zda_off">PSRF103,08,00,00,01</string>
+
+ <string name="sirf_nmea_to_binary">PSRF100,0,38400,8,1,0</string>
+
+ <string name="sirf_nmea_sbas_on">PSRF151,01</string>
+ <string name="sirf_nmea_sbas_off">PSRF151,00</string>
+
+ <string name="sirf_bin_static_nav_on">8F01</string>
+ <string name="sirf_bin_static_nav_off">8F00</string>
+ <string name="sirf_bin_to_nmea">8702</string>
+ <string name="sirf_bin_to_nmea_38400">810201010001050105010001000100010001000100019600</string>
+ <string name="sirf_bin_to_nmea_38400_alt">8102%02X01%02X01%02X01%02X01%02X01%02X01%02X01%02X01%02X0100019600</string>
+ <string name="sirf_bin_dgps_ext_on">85020000000000</string>
+ <string name="sirf_bin_dgps_sbas_on">85010000000000</string>
+ <string name="sirf_software_version">8400</string>
+</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 4876fc2..98403fe 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -21,70 +21,6 @@
<resources>
<string name="app_name">BlueGps</string>
- <string name="sirf_nmea_gga_on">PSRF103,00,00,01,01</string>
- <string name="sirf_nmea_rmc_on">PSRF103,04,00,01,01</string>
- <string name="sirf_nmea_gll_on">PSRF103,01,00,01,01</string>
- <string name="sirf_nmea_gll_off">PSRF103,01,00,00,01</string>
- <string name="sirf_nmea_gsa_on">PSRF103,02,00,05,01</string>
- <string name="sirf_nmea_gsa_off">PSRF103,02,00,00,01</string>
- <string name="sirf_nmea_gsv_on">PSRF103,03,00,05,01</string>
- <string name="sirf_nmea_gsv_off">PSRF103,03,00,00,01</string>
- <string name="sirf_nmea_vtg_on">PSRF103,05,00,01,01</string>
- <string name="sirf_nmea_vtg_off">PSRF103,05,00,00,01</string>
- <string name="sirf_nmea_zda_on">PSRF103,08,00,01,01</string>
- <string name="sirf_nmea_zda_off">PSRF103,08,00,00,01</string>
-
- <string name="sirf_nmea_to_binary">PSRF100,0,38400,8,1,0</string>
-
- <string name="sirf_nmea_sbas_on">PSRF151,01</string>
- <string name="sirf_nmea_sbas_off">PSRF151,00</string>
-
-<!--
- <string name="sirf_sbas_on">$PSRF151,01*0F</string>
- <string name="sirf_sbas_off">$PSRF151,00*0E</string>
--->
- <string name="sirf_bin_static_nav_on">8F01</string>
- <string name="sirf_bin_static_nav_off">8F00</string>
- <string name="sirf_bin_to_nmea">8702</string>
- <string name="sirf_bin_to_nmea_38400">810201010001050105010001000100010001000100019600</string>
- <string name="sirf_bin_to_nmea_38400_alt">8102%02X01%02X01%02X01%02X01%02X01%02X01%02X01%02X01%02X0100019600</string>
- <string name="sirf_bin_dgps_ext_on">85020000000000</string>
- <string name="sirf_bin_dgps_sbas_on">85010000000000</string>
- <string name="sirf_software_version">8400</string>
-
-
- <!--
- <string name="sirf_bin_to_nmea4800_1">A0A20018 8102010100010501050100010001000100010001000112C0 016AB0B3</string>
- <string name="sirf_bin_to_nmea_on_2">A0A20002 8702 0089B0B3</string>
- <string name="sirf_bin_dgps_ext_on">A0A20007 85020000000000 0087B0B3</string>
- <string name="sirf_bin_dgps_sbas_on">A0A20007 85010000000000 0086B0B3</string>
- -->
-
- <string name="pref_start_gps_key">startGps</string>
- <string name="pref_gps_location_provider_key">gpsLocationProviderKey</string>
- <string name="pref_replace_std_gps_key">replaceStdtGps</string>
- <string name="pref_mock_gps_name_key">mockGpsName</string>
- <string name="pref_connection_retries_key">connectionRetries</string>
- <string name="pref_recording_key">trackRecording</string>
- <string name="pref_trackfile_directory_key">trackFileDirectory</string>
- <string name="pref_trackfile_prefix_key">trackFilePrefix</string>
- <string name="pref_bluetooth_device_key">bluetoothDevice</string>
-
- <string name="pref_sirf_gps_key">sirfGps</string>
- <string name="pref_sirf_enable_gll_key">enableGLL</string>
- <string name="pref_sirf_enable_vtg_key">enableVTG</string>
- <string name="pref_sirf_enable_gsa_key">enableGSA</string>
- <string name="pref_sirf_enable_gsv_key">enableGSV</string>
- <string name="pref_sirf_enable_zda_key">enableZDA</string>
- <string name="pref_sirf_enable_sbas_key">enableSBAS</string>
- <string name="pref_sirf_enable_nmea_key">enableNMEA</string>
- <string name="pref_sirf_enable_static_navigation_key">enableStaticNavigation</string>
-
- <string name="defaultConnectionRetries">5</string>
- <string name="defaultTrackFileDirectory">/sdcard/nmea</string>
- <string name="defaultTrackFilePrefix">btnmeatrack</string>
- <string name="defaultMockGpsName">bluetooth_gps</string>
-
<string name="pref_start_gps_title">Start/Stop GPS</string>
<string name="pref_start_gps_summary_off">Bluetooth GPS is off</string>
<string name="pref_start_gps_summary_on">Bluetooth GPS is on</string>
@@ -145,6 +81,13 @@
<string name="msg_gps_provider_started">Bluetooth GPS... started</string>
<string name="msg_gps_provider_stopped">Bluetooth GPS... stopped</string>
<string name="msg_gps_provider_already_started">Bluetooth GPS... is already on</string>
+ <string name="msg_gps_provider_stopped_by_problem">"Cannot start: %s"</string>
+ <string name="msg_two_many_connection_problems">Too many connection problems</string>
+ <string name="msg_gps_provider_disabled">GPS is disabled</string>
+ <string name="msg_bluetooth_unsupported">Bluetooth is not supported</string>
+ <string name="msg_bluetooth_disabled">Bluetooth is disabled</string>
+ <string name="msg_mock_location_disabled">Mock location is disabled</string>
+ <string name="msg_bluetooth_gps_unavaible">Cannot connect to bluetooth GPS</string>
<string name="msg_nmea_recording_started">GPS NMEA recording... started</string>
<string name="msg_nmea_recording_stopped">GPS NMEA recording... stopped</string>
<string name="msg_nmea_recording_already_started">GPS track recording... is already on</string>
@@ -157,5 +100,5 @@
<item quantity="other">Will retry %d more times before closing</item>
</plurals>
<string name="service_closed_because_connection_problem_notification_title">BlueGps stopped</string>
- <string name="service_closed_because_connection_problem_notification">Reason: too many connection problems</string>
+ <string name="service_closed_because_connection_problem_notification">"Reason: %"</string>
</resources>
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
index 1bf766c..ad17857 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
@@ -48,7 +48,6 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.content.SharedPreferences;
-import android.location.Criteria;
import android.content.Intent;
import android.location.LocationManager;
import android.location.GpsStatus.NmeaListener;
@@ -162,6 +161,7 @@ public class BlueetoothGpsManager {
private LocationManager locationManager;
private SharedPreferences sharedPreferences;
private ConnectedGps connectedGps;
+ private int disableReason = 0;
private Notification connectionProblemNotification;
private Notification serviceStoppedNotification;
private Context appContext;
@@ -196,9 +196,16 @@ public class BlueetoothGpsManager {
appContext.getString(R.string.service_closed_because_connection_problem_notification_title),
appContext.getString(R.string.service_closed_because_connection_problem_notification),
restartPendingIntent);
+ }
-
+ private void setDisableReason(int reasonId){
+ disableReason = reasonId;
}
+
+ public int getDisableReason(){
+ return disableReason;
+ }
+
/**
* @return true if the bluetooth GPS is enabled
*/
@@ -213,29 +220,36 @@ public class BlueetoothGpsManager {
if (bluetoothAdapter == null) {
// Device does not support Bluetooth
Log.e("BT test", "Device does not support Bluetooth");
+ disable(R.string.msg_bluetooth_unsupported);
} else if (!bluetoothAdapter.isEnabled()) {
// Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
// startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
Log.e("BT test", "Bluetooth is not enabled");
+ disable(R.string.msg_bluetooth_disabled);
} else if (Settings.Secure.getInt(callingService.getContentResolver(),Settings.Secure.ALLOW_MOCK_LOCATION, 0)==0){
Log.e("BT test", "Mock location provider OFF");
- } else if ( (! locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
- // && (sharedPreferences.getBoolean(BluetoothGpsProviderService.PREF_REPLACE_STD_GPS, true))
- ) {
- Log.e("BT test", "GPS location provider OFF");
+ disable(R.string.msg_mock_location_disabled);
+// } else if ( (! locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
+// && (sharedPreferences.getBoolean(BluetoothGpsProviderService.PREF_REPLACE_STD_GPS, true))
+// ) {
+// Log.e("BT test", "GPS location provider OFF");
+// disable(R.string.msg_gps_provider_disabled);
} else {
final BluetoothDevice gpsDevice = bluetoothAdapter.getRemoteDevice(gpsDeviceAddress);
if (gpsDevice == null){
Log.e("BT test", "GPS device not found");
+ disable(R.string.msg_bluetooth_gps_unavaible);
} else {
Log.e("BT test", "current device: "+gpsDevice.getName() + " -- " + gpsDevice.getAddress());
try {
gpsSocket = gpsDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
} catch (IOException e) {
Log.e("BT test", "Error during connection", e);
+ gpsSocket = null;
}
if (gpsSocket == null){
Log.e("BT test", "Error while establishing connection: no socket");
+ disable(R.string.msg_bluetooth_gps_unavaible);
} else {
Runnable connectThread = new Runnable() {
@Override
@@ -256,9 +270,11 @@ public class BlueetoothGpsManager {
gpsSocket = gpsDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
} catch (IOException e) {
Log.e("BT test", "Error during connection", e);
+ gpsSocket = null;
}
if (gpsSocket == null){
Log.e("BT test", "Error while establishing connection: no socket");
+ disable(R.string.msg_bluetooth_gps_unavaible);
} else {
// Cancel discovery because it will slow down the connection
bluetoothAdapter.cancelDiscovery();
@@ -268,15 +284,20 @@ public class BlueetoothGpsManager {
gpsSocket.connect();
// connection obtained so reset the number of connection try
connected = true;
+ // reset eventual disabling cause
+// setDisableReason(0);
nbRetriesRemaining = 1+maxConnectionRetries ;
notificationManager.cancel(R.string.connection_problem_notification_title);
connectedGps = new ConnectedGps(gpsSocket);
connectionAndReadingPool.execute(connectedGps);
}
+// } else if (! bluetoothAdapter.isEnabled()) {
+// setDisableReason(R.string.msg_bluetooth_disabled);
}
} catch (IOException connectException) {
// Unable to connect
Log.e("BT test", "error while connecting to socket", connectException);
+ // disable(R.string.msg_bluetooth_gps_unavaible);
} finally {
nbRetriesRemaining--;
if (! connected) {
@@ -309,15 +330,29 @@ public class BlueetoothGpsManager {
connectionProblemNotification.number = 1 + maxConnectionRetries - nbRetriesRemaining;
notificationManager.notify(R.string.connection_problem_notification_title, connectionProblemNotification);
} else {
- notificationManager.cancel(R.string.connection_problem_notification_title);
- serviceStoppedNotification.when = System.currentTimeMillis();
- notificationManager.notify(R.string.service_closed_because_connection_problem_notification_title, serviceStoppedNotification);
- disable();
+// notificationManager.cancel(R.string.connection_problem_notification_title);
+// serviceStoppedNotification.when = System.currentTimeMillis();
+// notificationManager.notify(R.string.service_closed_because_connection_problem_notification_title, serviceStoppedNotification);
+ disable(R.string.msg_two_many_connection_problems);
}
}
}
+ public synchronized void disable(int reasonId) {
+ setDisableReason(reasonId);
+ disable();
+ }
+
public synchronized void disable() {
+ notificationManager.cancel(R.string.connection_problem_notification_title);
+ if (getDisableReason() != 0){
+ serviceStoppedNotification.when = System.currentTimeMillis();
+ serviceStoppedNotification.setLatestEventInfo(appContext,
+ appContext.getString(R.string.service_closed_because_connection_problem_notification_title),
+ appContext.getString(R.string.service_closed_because_connection_problem_notification, appContext.getString(getDisableReason())),
+ serviceStoppedNotification.contentIntent);
+ notificationManager.notify(R.string.service_closed_because_connection_problem_notification_title, serviceStoppedNotification);
+ }
if (enabled){
enabled = false;
if (gpsSocket != null){
@@ -331,7 +366,6 @@ public class BlueetoothGpsManager {
disableMockLocationProvider();
notificationPool.shutdown();
connectionAndReadingPool.shutdown();
- notificationManager.cancel(R.string.connection_problem_notification_title);
callingService.stopSelf();
}
}
@@ -388,7 +422,15 @@ public class BlueetoothGpsManager {
private void notifyNmeaSentence(final String nmeaSentence){
if (enabled){
- final String recognizedSentence = parser.parseNmeaSentence(nmeaSentence);
+ String sentence = null;
+ try {
+ sentence = parser.parseNmeaSentence(nmeaSentence);
+ } catch (SecurityException e){
+ // a priori Mock Location is disabled
+ sentence = null;
+ disable(R.string.msg_mock_location_disabled);
+ }
+ final String recognizedSentence = sentence;
final long timestamp = System.currentTimeMillis();
if (recognizedSentence != null){
Log.e("BT test", "NMEA : "+timestamp+" "+recognizedSentence);
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
index 47b5cf2..37ce43a 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
@@ -107,17 +107,12 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
}
if (ACTION_START_GPS_PROVIDER.equals(intent.getAction())){
if (gpsManager == null){
- Notification notification = new Notification(R.drawable.icon, this.getString(R.string.foreground_gps_provider_started_notification), System.currentTimeMillis());
- Intent myIntent = new Intent(this, BluetoothGpsActivity.class);
- PendingIntent myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
- notification.setLatestEventInfo(getApplicationContext(), this.getString(R.string.foreground_service_started_notification_title), this.getString(R.string.foreground_gps_provider_started_notification), myPendingIntent);
if (BluetoothAdapter.checkBluetoothAddress(deviceAddress)){
String mockProvider = LocationManager.GPS_PROVIDER;
if (! sharedPreferences.getBoolean(PREF_REPLACE_STD_GPS, true)){
mockProvider = sharedPreferences.getString(PREF_MOCK_GPS_NAME, getString(R.string.defaultMockGpsName));
}
gpsManager = new BlueetoothGpsManager(this, deviceAddress, maxConRetries);
- gpsManager.enableMockLocationProvider(mockProvider);
boolean enabled = gpsManager.enable();
// Bundle extras = intent.getExtras();
if (sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, false) != enabled){
@@ -125,12 +120,19 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
edit.commit();
}
if (enabled) {
+ gpsManager.enableMockLocationProvider(mockProvider);
+ Notification notification = new Notification(R.drawable.icon, this.getString(R.string.foreground_gps_provider_started_notification), System.currentTimeMillis());
+ Intent myIntent = new Intent(this, BluetoothGpsActivity.class);
+ PendingIntent myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
+ notification.setLatestEventInfo(getApplicationContext(), this.getString(R.string.foreground_service_started_notification_title), this.getString(R.string.foreground_gps_provider_started_notification), myPendingIntent);
startForeground(R.string.foreground_gps_provider_started_notification, notification);
if (sharedPreferences.getBoolean(PREF_SIRF_GPS, false)){
enableSirfConfig(sharedPreferences);
}
toast.setText(this.getString(R.string.msg_gps_provider_started));
toast.show();
+ } else {
+ stopSelf();
}
} else {
stopSelf();
@@ -352,6 +354,13 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
BlueetoothGpsManager manager = gpsManager;
gpsManager = null;
if (manager != null){
+ if (manager.getDisableReason() != 0){
+ toast.setText(getString(R.string.msg_gps_provider_stopped_by_problem, getString(manager.getDisableReason())));
+ toast.show();
+ } else {
+ toast.setText(R.string.msg_gps_provider_stopped);
+ toast.show();
+ }
manager.removeNmeaListener(this);
manager.disableMockLocationProvider();
manager.disable();
@@ -367,10 +376,6 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
edit.putBoolean(PREF_START_GPS_PROVIDER,false);
edit.commit();
}
-// toast.setText(this.getString(R.string.msg_nmea_recording_stopped));
-// toast.show();
- toast.setText(this.getString(R.string.msg_gps_provider_stopped));
- toast.show();
super.onDestroy();
}
diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
index 426855f..dbfae17 100644
--- a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
+++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
@@ -36,19 +36,20 @@ import android.text.TextUtils.SimpleStringSplitter;
import android.util.Log;
public class NmeaParser {
- private String fixTime;
+ private String fixTime = null;
private long fixTimestamp;
private boolean hasGGA = false;
private boolean hasRMC = false;
private LocationManager lm;
private float precision = 10f;
+ private boolean mockGpsAutoEnabled = false;
private boolean mockGpsEnabled = false;
private String mockLocationProvider = null;
private int mockStatus = LocationProvider.OUT_OF_SERVICE;
- private Location fix = new Location(mockLocationProvider);
+ private Location fix = null;
public NmeaParser(){
this(5f);
@@ -62,65 +63,81 @@ 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)){
- 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)){
- 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);
+ mockGpsAutoEnabled = false;
+ mockStatus = LocationProvider.OUT_OF_SERVICE;
}
- mockLocationProvider = null;
- mockGpsEnabled = false;
- mockStatus = LocationProvider.OUT_OF_SERVICE;
}
/**
@@ -141,7 +158,7 @@ public class NmeaParser {
return mockLocationProvider;
}
- private void notifyFix(Location fix){
+ private void notifyFix(Location fix) throws SecurityException {
fixTime = null;
hasGGA = false;
hasRMC=false;
@@ -173,7 +190,7 @@ public class NmeaParser {
}
// parse NMEA Sentence
- public String 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");
diff --git a/version.txt b/version.txt
index bc23134..17d9240 100644
--- a/version.txt
+++ b/version.txt
@@ -1,5 +1,10 @@
-BlueGps4Droid 1.2 alpha version
- * SiRF configuration (NMEA sentences - SBAS - Static Navigation)
+BlueGps4Droid 1.2
+ * SiRF configuration management (NMEA sentences - SBAS - Static Navigation)
+
+BlueGps4Droid 1.1.2
+ * Add verifications: if bluetooth or mock locations are not enabled, the service is not started.
+ * Add alert messages to explain why the service cannot be started if bluetooth or mock locations are not enabled
+ * If device doesn't have an internal GPS, the bluetooth GPS provider will be enabled automatically
BlueGps4Droid 1.1.1
* Bug fix (Ticket #4: Connection service is not properly closed https://sourceforge.net/p/bluegps4droid/tickets/4/).
@@ -15,4 +20,4 @@ BlueGps4Droid 1.0
* Connect to bluetooth GPS (NMEA) and replace the internal GPS of an Android device.
* Record GPS tracks in NMEA files
* Compatible with Android version 2.0 and above
- * English and French translations \ No newline at end of file
+ * English and French translations