aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2010-10-18 21:48:53 +0200
committerHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2010-10-18 21:48:53 +0200
commiteddc206850ad7b7b624c3a71cae70ae37789602c (patch)
tree61c25331281bc1966cee416976a9ed14b00e2fb3
parentb45e9c31bd9812359b21b285a0867c435644155b (diff)
downloadBlueGPS-eddc206850ad7b7b624c3a71cae70ae37789602c.zip
BlueGPS-eddc206850ad7b7b624c3a71cae70ae37789602c.tar.gz
BlueGPS-eddc206850ad7b7b624c3a71cae70ae37789602c.tar.bz2
autodisable when needed
When Bluetooth, Mock Location or GPS are not enabled, the service cannot be started correctly and so it will auto-disable itself.
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java4
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java16
2 files changed, 12 insertions, 8 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
index e114b45..2ccc28d 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
@@ -147,13 +147,12 @@ public class BlueetoothGpsManager {
/**
* @return true if the bluetooth GPS is enabled
*/
- public boolean isEnabled() {
+ public synchronized boolean isEnabled() {
return enabled;
}
public synchronized void enable() {
if (! enabled){
- this.enabled = true;
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
// Device does not support Bluetooth
@@ -228,6 +227,7 @@ public class BlueetoothGpsManager {
}
}
};
+ this.enabled = true;
notificationPool = Executors.newSingleThreadExecutor();
notificationPool.execute(connectThread);
// enableMockLocationProvider(LocationManager.GPS_PROVIDER);
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
index 0ab972b..2a30ea8 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
@@ -105,14 +105,18 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
startForeground(R.string.foreground_gps_provider_started_notification, notification);
if (BluetoothAdapter.checkBluetoothAddress(deviceAddress)){
gpsManager = new BlueetoothGpsManager(this, deviceAddress);
- gpsManager.enableMockLocationProvider(LocationManager.GPS_PROVIDER);
gpsManager.enable();
- if (! sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, false)){
- edit.putBoolean(PREF_START_GPS_PROVIDER,true);
- edit.commit();
+ if (gpsManager.isEnabled()){
+ gpsManager.enableMockLocationProvider(LocationManager.GPS_PROVIDER);
+ if (! sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, false)){
+ edit.putBoolean(PREF_START_GPS_PROVIDER,true);
+ edit.commit();
+ }
+ toast.setText(this.getString(R.string.msg_gps_provider_started));
+ toast.show();
+ } else {
+ stopSelf();
}
- toast.setText(this.getString(R.string.msg_gps_provider_started));
- toast.show();
} else {
// if (! sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, true)){
// edit.putBoolean(PREF_START_GPS_PROVIDER,false);