diff --git a/plugin.xml b/plugin.xml index 28211e2..8f62e5f 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ + version="1.9.5"> DataCollection Background data collection FTW! This is the part that I really diff --git a/src/android/location/TripDiaryStateMachineServiceOngoing.java b/src/android/location/TripDiaryStateMachineServiceOngoing.java index 2c4ece8..00e6746 100644 --- a/src/android/location/TripDiaryStateMachineServiceOngoing.java +++ b/src/android/location/TripDiaryStateMachineServiceOngoing.java @@ -156,7 +156,11 @@ 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); @@ -164,7 +168,7 @@ private void handleAction(Context ctxt, String currState, String actionString) { 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); } } @@ -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 @@ -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). @@ -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"); diff --git a/src/ios/Location/TripDiaryStateMachine.m b/src/ios/Location/TripDiaryStateMachine.m index c04f739..a0026b8 100644 --- a/src/ios/Location/TripDiaryStateMachine.m +++ b/src/ios/Location/TripDiaryStateMachine.m @@ -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]; @@ -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