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

Stop tracking when duty cycling is turned off in fleet mode #236

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="cordova-plugin-em-datacollection"
version="1.9.4">
version="1.9.5">

<name>DataCollection</name>
<description>Background data collection FTW! This is the part that I really
Expand Down
34 changes: 12 additions & 22 deletions src/android/location/TripDiaryStateMachineServiceOngoing.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,19 @@ private void handleAction(Context ctxt, String currState, String actionString) {
// - have initialize function as a reset, which stops any current stuff and starts the new one
UserCacheFactory.getUserCache(ctxt).putSensorData(R.string.key_usercache_battery,
BatteryUtils.getBatteryInfo(ctxt));
if (actionString.equals(ctxt.getString(R.string.transition_initialize))) {

if (isFleet) {
Log.d(this, TAG, "ERROR: Duty cycling turned off in fleet mode, stopping tracking");
stopEverything(ctxt, ctxt.getString(R.string.state_tracking_stopped));
} else if (actionString.equals(ctxt.getString(R.string.transition_initialize))) {
handleStart(ctxt, actionString);
} else if (currState.equals(ctxt.getString(R.string.state_start))) {
handleStart(ctxt, actionString);
} else if (currState.equals(ctxt.getString(R.string.state_waiting_for_trip_start))) {
handleWaitingForTripStart(ctxt, actionString);
} else if (currState.equals(ctxt.getString(R.string.state_ongoing_trip))) {
handleOngoing(ctxt, actionString);
} if (currState.equals(getString(R.string.state_tracking_stopped))) {
} else if (currState.equals(getString(R.string.state_tracking_stopped))) {
handleTrackingStopped(ctxt, actionString);
}
}
Expand All @@ -173,17 +177,9 @@ private void handleStart(Context ctxt, String actionString) {
Log.d(this, TAG, "TripDiaryStateMachineReceiver handleStarted(" + actionString + ") called");
// Get current location
if (actionString.equals(ctxt.getString(R.string.transition_initialize)) &&
!mCurrState.equals(ctxt.getString(R.string.state_tracking_stopped))) {
if (isFleet) {
// Start up the bluetooth service to check for beacons
Intent foregroundStartBluetooth = new Intent(ctxt, TripDiaryStateMachineForegroundService.class);
foregroundStartBluetooth.setAction("foreground_start_bluetooth");
ctxt.startService(foregroundStartBluetooth);
setNewState(ctxt.getString(R.string.state_waiting_for_trip_start));
} else {
startEverything(ctxt, actionString);
}
}
!mCurrState.equals(ctxt.getString(R.string.state_tracking_stopped))) {
startEverything(ctxt, actionString);
}
if (actionString.equals(ctxt.getString(R.string.transition_stop_tracking))) {
// Haven't started anything yet (that's why we are in the start state).
// just move to the stop tracking state
Expand All @@ -208,11 +204,9 @@ private void handleStart(Context ctxt, String actionString) {
// If we stop tracking, we stop everything
// For everything else, go to the ongoing state :)
private void handleWaitingForTripStart(final Context ctxt, final String actionString) {
if (actionString.equals(getString(R.string.transition_exited_geofence)) && !isFleet) {
startEverything(ctxt, actionString);
} else if (actionString.equals(ctxt.getString(R.string.transition_ble_beacon_found)) && isFleet) {
if (actionString.equals(getString(R.string.transition_exited_geofence))) {
startEverything(ctxt, actionString);
} else if (actionString.equals(getString(R.string.transition_start_tracking)) && !isFleet) {
} else if (actionString.equals(getString(R.string.transition_start_tracking))) {
startEverything(ctxt, actionString);
} else if (actionString.equals(ctxt.getString(R.string.transition_stop_tracking))) {
// Haven't started anything yet (that's why we are in the start state).
Expand Down Expand Up @@ -245,11 +239,7 @@ private void handleOngoing(Context ctxt, String actionString) {
private void handleTrackingStopped(final Context ctxt, String actionString) {
Log.d(this, TAG, "TripDiaryStateMachineReceiver handleTrackingStopped(" + actionString + ") called");
if (actionString.equals(ctxt.getString(R.string.transition_start_tracking))) {
if (isFleet) {
setNewState(ctxt.getString(R.string.state_waiting_for_trip_start));
} else {
startEverything(ctxt, actionString);
}
startEverything(ctxt, actionString);
}
if (actionString.equals(ctxt.getString(R.string.transition_tracking_error))) {
Log.i(this, TAG, "Tracking manually turned off, no need to prompt for location");
Expand Down
26 changes: 18 additions & 8 deletions src/ios/Location/TripDiaryStateMachine.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,20 @@ - (id) init {
// currently only in `BEMDataCollection initWithConsent`
// https://github.com/e-mission/e-mission-docs/issues/735#issuecomment-1179774103

if (![ConfigManager instance].is_duty_cycling && self.currState != kTrackingStoppedState && !self.isFleet) {
/* If we are not using geofencing, and the tracking is not manually turned off, then we don't need to listen
to any transitions. We just turn on the tracking here and never stop. Turning off all transitions makes
it easier for us to ignore silent push as well as the transitions generated from here.
*/
[TripDiaryActions oneTimeInitTracking:CFCTransitionInitialize withLocationMgr:self.locMgr];
[self setState:kOngoingTripState withChecks:TRUE];
[TripDiaryActions startTracking:CFCTransitionExitedGeofence withLocationMgr:self.locMgr];
if (![ConfigManager instance].is_duty_cycling && self.currState != kTrackingStoppedState) {
if (!self.isFleet) {
/* If we are not using geofencing, and the tracking is not manually turned off, then we don't need to listen
to any transitions. We just turn on the tracking here and never stop. Turning off all transitions makes
it easier for us to ignore silent push as well as the transitions generated from here.
*/
[TripDiaryActions oneTimeInitTracking:CFCTransitionInitialize withLocationMgr:self.locMgr];
[self setState:kOngoingTripState withChecks:TRUE];
[TripDiaryActions startTracking:CFCTransitionExitedGeofence withLocationMgr:self.locMgr];
} else {
[LocalNotificationManager addNotification:[NSString stringWithFormat:
@"ERROR: Duty cycling turned off in fleet mode, stopping tracking"]];
[self setState:kTrackingStoppedState withChecks:TRUE];
}
}

return [super init];
Expand Down Expand Up @@ -247,6 +253,10 @@ -(void) handleStart:(NSString*) transition withUserInfo:(NSDictionary*) userInfo
[TripDiaryActions oneTimeInitTracking:transition withLocationMgr:self.locMgr];
[self setState:kOngoingTripState withChecks:TRUE];
[TripDiaryActions startTracking:transition withLocationMgr:self.locMgr];
} else {
[LocalNotificationManager addNotification:[NSString stringWithFormat:
@"ERROR: Duty cycling turned off in fleet mode, stopping tracking"]];
[self setState:kTrackingStoppedState withChecks:TRUE];
}
} else if ([transition isEqualToString:CFCTransitionRecievedSilentPush]) {
[[NSNotificationCenter defaultCenter] postNotificationName:CFCTransitionNotificationName
Expand Down