I'm having a problem on a One Plus 3T device which is causing the GPS to stay activity after removeLocationUpdates
has been called correctly (waiting for the PendingIntent status to return success, and then disconnecting the API client).
The image shown below shows the GPS remaining active for 19 minutes when it should only have been active for about 10 seconds (when the logs indicated the request was removed successfully). I'm not sure why the GPS is not turning off, this causing very high battery drain which can bee seen below.
This is how the location request is removed and client disconnected:
PendingResult<Status> result = LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener);
result.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status)
// Something went wrong! Throw RunTimeException on main thread
// this will crash the application
if(!status.isSuccess()){
throw new RuntimeException("Could not remove location updates!");
}else{
Log.i(TAG, "Location request removed successfully");
}
mGoogleApiClient.disconnect();
}
});
edit: I've discovered when the location request is removed the location controller (part of the OS?) outputs the following:
05-02 15:52:06.394 21277 21425 I LocationControllerImpl: areActiveHighPowerLocationRequests package:android
05-02 15:52:06.394 21277 21425 I LocationControllerImpl: areActiveHighPowerLocationRequests getOp:42 opEntry:false
05-02 15:52:06.394 21277 21425 I LocationControllerImpl: areActiveHighPowerLocationRequests package:com.google.android.gms
05-02 15:52:06.394 21277 21425 I LocationControllerImpl: areActiveHighPowerLocationRequests getOp:42 opEntry:false
05-02 15:52:06.394 21277 21425 I LocationControllerImpl: areActiveHighPowerLocationRequests package:com.google.android.googlequicksearchbox
05-02 15:52:06.395 21277 21425 I LocationControllerImpl: areActiveHighPowerLocationRequests getOp:42 opEntry:false
05-02 15:52:06.395 21277 21425 I LocationControllerImpl: areActiveHighPowerLocationRequests package:me.twrp.twrpapp
05-02 15:52:06.395 21277 21425 I LocationControllerImpl: areActiveHighPowerLocationRequests getOp:42 opEntry:false
05-02 15:52:06.395 21277 21425 I LocationControllerImpl: areActiveHighPowerLocationRequests package:com.myapp.xxx
05-02 15:52:06.395 21277 21425 I LocationControllerImpl: areActiveHighPowerLocationRequests getOp:42 opEntry:false
But for the times where the GPS is kept alive and GnssLocationProvider
wakelocks is still active nothing is outputted after the removal of the request.
edit: Further to the above, it looks like that output is from when a broadcast happens with the action LocationManager.HIGHPOWER_REQUEST_CHANGE_ACTION
which from the source indicates:
that a high power location requests has either started or stopped being active
More info: Force stopping the app or Google Play services does not clear the wakelock. It appears it can only be removed by restarting the device.