diff options
-rw-r--r-- | src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java index da76754..6460d35 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java @@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit; import org.broeuschmeul.android.gps.nmea.util.NmeaParser;
import org.broeuschmeul.android.gps.sirf.util.SirfUtils;
+import android.app.AppOpsManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -287,6 +288,30 @@ public class BlueetoothGpsManager { }
/**
+ * @return true if mock locations are enabled, respectively if BlueGps is set as the mock location provider
+ */
+ public boolean isMockLocationProviderEnabled()
+ {
+ boolean isMockLocation = false;
+ try {
+ //if marshmallow
+ if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
+ AppOpsManager opsManager = (AppOpsManager) appContext.getSystemService(Context.APP_OPS_SERVICE);
+ isMockLocation = (opsManager.checkOp(AppOpsManager.OPSTR_MOCK_LOCATION, android.os.Process.myUid(), "org.broeuschmeul.android.gps.bluetooth.provider")== AppOpsManager.MODE_ALLOWED);
+ }
+ else {
+ // in marshmallow this will always return true
+ isMockLocation = !android.provider.Settings.Secure.getString(appContext.getContentResolver(), "mock_location").equals("0");
+ }
+ }
+ catch (Exception e) {
+ return isMockLocation;
+ }
+
+ return isMockLocation;
+ }
+
+ /**
* Enables the bluetooth GPS Provider.
* @return
*/
@@ -304,7 +329,7 @@ public class BlueetoothGpsManager { // startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
Log.e(LOG_TAG, "Bluetooth is not enabled");
disable(R.string.msg_bluetooth_disabled);
- } else if (Settings.Secure.getInt(callingService.getContentResolver(),Settings.Secure.ALLOW_MOCK_LOCATION, 0)==0){
+ } else if (!isMockLocationProviderEnabled()){
Log.e(LOG_TAG, "Mock location provider OFF");
disable(R.string.msg_mock_location_disabled);
// } else if ( (! locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
|