diff options
author | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2015-12-29 12:45:56 +0100 |
---|---|---|
committer | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2015-12-29 12:45:56 +0100 |
commit | e2ac781361a1c14e83ea294a00c80ad9ec89844c (patch) | |
tree | 55b597c08776e7f566c1ebe550517b8b490a7dbe | |
parent | d81abddc3c8c1966d4e80081cd822fa5ed737c86 (diff) | |
download | BlueGPS-e2ac781361a1c14e83ea294a00c80ad9ec89844c.zip BlueGPS-e2ac781361a1c14e83ea294a00c80ad9ec89844c.tar.gz BlueGPS-e2ac781361a1c14e83ea294a00c80ad9ec89844c.tar.bz2 |
The check for mock location doesn't work on Marshmallow, so add a function that works on Marshmallow and older Android versions
code comes from here: https://stackoverflow.com/questions/33003553/how-to-read-selected-mock-location-app-in-android-m-api-23
Signed-off-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
-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))
|