3

I have an application (call it A) that runs a service that mocks the location obtained from a bluetooth GPS in order to use it in another application (call it B):

  1. A (with service that gets bluetooth GPS location)
  2. Mock location in android system
  3. B (get location from Android System)

Everything works on Android 7.0, but in Android 8.0 (Oreo) the application B does not read the location obtained from the bluetooth, that is, I think, beacuse of a problem in mocking the location, because the log always prints this line:

E PassiveLocationListener_FLP: isFromMockProvider, return

The code I'm using to mock the location is:

 private void changeToMockLocation() {
    Log.i(TAG, "changeToMockLocation()");

    Location newLocation = new Location(PROVIDER_NAME);
    newLocation.setLatitude(mNMEAData.getLatitude());
    newLocation.setLongitude(mNMEAData.getLongitude());
    newLocation.setAccuracy(mNMEAData.getAccuracy());
    newLocation.setTime(System.currentTimeMillis());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        newLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
    }

    // Set mock location.
    if (ActivityCompat.checkSelfPermission(
            mContext, android.Manifest.permission.ACCESS_FINE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        try {
            mLocationManager.setTestProviderLocation(PROVIDER_NAME, newLocation);
        } catch (Exception e) {
            Log.e(TAG, "Error while setting test provider location: " + e);
        }
    }
}

The thing is, I don't see the exception printed, so I think the process is right but is like Android doesn't allow me to do so for some reason I can't figure out.

In the manifest I declared the ALLOW_MOCK_LOCATION permission, and the app is allowed to mock location in Developer Settings.

What am I doing wrong?

Thanks in advance and have a nice day.

Knorf
  • 101
  • 1
  • 11

1 Answers1

0

There seems to be a bug in the (Samsung?) Developer Settings screen in Oreo. I also had my app set up as mock provider and with the permission in the manifest. For me the problem was solved by removing the app as mock location provider and adding it back again:

Developer options -> Mock location app -> No apps
Developer options -> Mock location app -> Your app

I still see these messages in the logcat though:

E/PassiveLocationListener_FLP: isFromMockProvider, return
I/LocationManagerService: remove xxxxxxx 
I/LocationManagerService: removeUpdates, receiver.requestedID = xxxxxxx, receiver.mIdentity.mPid = 2908, receiver.mIdentity.mUid = 1000
D/SLocation: removeGpsStatusListener
D/ListenerMonitor_FLP: removeListener, not existed listener android, xxxxxxx in mListenerIdMap
E/RequestManager_FLP: [LocationManagerService] Location remove xxxxxxx from system
Mister Smith
  • 27,417
  • 21
  • 110
  • 193