aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2010-10-24 23:41:55 +0200
committerHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2010-10-24 23:41:55 +0200
commit5b11f327cf16eeecd279aaed8b384385c0f5fa10 (patch)
tree28a400fd5be3b31b6841f0bb20ee7a1610a620da /src
parent5d9af268996d502b840608e5f2b3b6ffc68b3c2a (diff)
downloadBlueGPS-5b11f327cf16eeecd279aaed8b384385c0f5fa10.zip
BlueGPS-5b11f327cf16eeecd279aaed8b384385c0f5fa10.tar.gz
BlueGPS-5b11f327cf16eeecd279aaed8b384385c0f5fa10.tar.bz2
add alert messages when bluetooth GPS connection cannot be enabled
Diffstat (limited to 'src')
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java35
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java19
2 files changed, 45 insertions, 9 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
index 91489a5..bb52922 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
@@ -105,6 +105,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;
@@ -140,6 +141,15 @@ public class BlueetoothGpsManager {
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
*/
@@ -154,29 +164,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");
+ 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
@@ -197,9 +214,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();
@@ -218,6 +237,7 @@ public class BlueetoothGpsManager {
} 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) {
@@ -259,6 +279,11 @@ public class BlueetoothGpsManager {
}
}
+ public synchronized void disable(int reasonId) {
+ setDisableReason(reasonId);
+ disable();
+ }
+
public synchronized void disable() {
if (enabled){
enabled = false;
@@ -330,7 +355,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 22b6a0c..1b5c238 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
@@ -94,10 +94,6 @@ 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)){
@@ -111,6 +107,10 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
}
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);
toast.setText(this.getString(R.string.msg_gps_provider_started));
toast.show();
@@ -180,6 +180,13 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
BlueetoothGpsManager manager = gpsManager;
gpsManager = null;
if (manager != null){
+ if (manager.getDisableReason() != 0){
+ toast.setText(manager.getDisableReason());
+ toast.show();
+ } else {
+ toast.setText(R.string.msg_gps_provider_stopped);
+ toast.show();
+ }
manager.removeNmeaListener(this);
manager.disableMockLocationProvider();
manager.disable();
@@ -195,10 +202,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();
}