Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edge cases around changing of location authorization #412

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/services/LocationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PushNotification from 'react-native-push-notification';
import { isPlatformAndroid } from '../Util';
import languages from '../locales/languages';

let hasBeenStarted = false;
let isBackgroundGeolocationConfigured = false;

export class LocationData {
constructor() {
Expand Down Expand Up @@ -133,11 +133,10 @@ export default class LocationServices {

// handles edge cases around Android where start might get called again even though
// the service is already created. Make sure the listeners are still bound and exit
if (hasBeenStarted) {
if (isBackgroundGeolocationConfigured) {
BackgroundGeolocation.start();
return;
}
hasBeenStarted = true;

PushNotification.configure({
// (required) Called when a remote or local notification is opened or received
Expand Down Expand Up @@ -291,6 +290,7 @@ export default class LocationServices {
);

BackgroundGeolocation.start(); //triggers start on start event
isBackgroundGeolocationConfigured = true;

if (!status.locationServicesEnabled) {
// we need to set delay or otherwise alert may not be shown
Expand Down Expand Up @@ -345,15 +345,15 @@ export default class LocationServices {
});
}

static stop(nav) {
static stop() {
// unregister all event listeners
PushNotification.localNotification({
title: languages.t('label.location_disabled_title'),
message: languages.t('label.location_disabled_message'),
});
BackgroundGeolocation.removeAllListeners();
BackgroundGeolocation.stop();
instanceCount -= 1;
isBackgroundGeolocationConfigured = false;
SetStoreData('PARTICIPATE', 'false').then(() => {
// nav.navigate('LocationTrackingScreen', {});
});
Expand Down
9 changes: 5 additions & 4 deletions app/views/LocationTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ class LocationTracking extends Component {
.then(result => {
switch (result) {
case RESULTS.GRANTED:
LocationServices.start();
this.checkIfUserAtRisk();
return;
case RESULTS.UNAVAILABLE:
case RESULTS.BLOCKED:
console.log('NO LOCATION');
LocationServices.stop();
this.setState({ currentState: StateEnum.UNKNOWN });
}
})
Expand Down Expand Up @@ -293,21 +295,20 @@ class LocationTracking extends Component {

willParticipate = () => {
SetStoreData('PARTICIPATE', 'true').then(() => {
LocationServices.start();
// Turn of bluetooth for v1
// Turn off bluetooth for v1
//BroadcastingServices.start();
});

// Check and see if they actually authorized in the system dialog.
// If not, stop services and set the state to !isLogging
// Fixes tripleblindmarket/private-kit#129
BackgroundGeolocation.checkStatus(({ authorization }) => {
if (authorization === BackgroundGeolocation.AUTHORIZED) {
LocationServices.start();
this.setState({
isLogging: true,
});
} else if (authorization === BackgroundGeolocation.NOT_AUTHORIZED) {
LocationServices.stop(this.props.navigation);
LocationServices.stop();
// Turn of bluetooth for v1
//BroadcastingServices.stop(this.props.navigation);
this.setState({
Expand Down