From 2cc112c753c409abcdaba4e3056125a52572d9d2 Mon Sep 17 00:00:00 2001 From: "K. Shankari" Date: Tue, 7 Jun 2016 18:17:31 -0700 Subject: [PATCH] Turn off UI alerts unless the user wants them for debugging User wants them == "simulateUserInteraction" Unlike iOS, this does not introduce a new dependency, it does have a lot of repeated code, specially in the services when we try to transition to a new state. Fixing it is being tracked in https://github.com/e-mission/e-mission-data-collection/issues/113 Note that the iOS change changes the logging directly, so it is not checked into this repo. The iOS change is at: https://github.com/shankari/cordova-unified-logger/commit/f55fc2dd15f157b1d4a77c496d55a56f717621e2 This is an object case in the pitfalls of both approaches - we just need to refactor and do them right on the second pass. --- ...ctivityRecognitionChangeIntentService.java | 3 +++ .../TripDiaryStateMachineService.java | 25 +++++++++++++++++++ .../TripDiaryStateMachineServiceOngoing.java | 9 +++++++ 3 files changed, 37 insertions(+) diff --git a/src/android/location/ActivityRecognitionChangeIntentService.java b/src/android/location/ActivityRecognitionChangeIntentService.java index 5ce6b580..ee21563a 100644 --- a/src/android/location/ActivityRecognitionChangeIntentService.java +++ b/src/android/location/ActivityRecognitionChangeIntentService.java @@ -5,6 +5,7 @@ import com.google.android.gms.location.ActivityRecognitionResult; import com.google.android.gms.location.DetectedActivity; +import edu.berkeley.eecs.emission.cordova.tracker.ConfigManager; import edu.berkeley.eecs.emission.cordova.unifiedlogger.NotificationHelper; import edu.berkeley.eecs.emission.R; @@ -34,8 +35,10 @@ protected void onHandleIntent(Intent intent) { ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent); DetectedActivity mostProbableActivity = result.getMostProbableActivity(); Log.i(this, TAG, "Detected new activity "+mostProbableActivity); + if (ConfigManager.getConfig(this).isSimulateUserInteraction()) { NotificationHelper.createNotification(this, ACTIVITY_IN_NUMBERS, "Detected new activity "+activityType2Name(mostProbableActivity.getType())); + } // TODO: Do we want to compare activity and only store when different? // Can easily do that by getting the last activity // Let's suck everything up to the server for now and optimize later diff --git a/src/android/location/TripDiaryStateMachineService.java b/src/android/location/TripDiaryStateMachineService.java index 864f84aa..183067d2 100644 --- a/src/android/location/TripDiaryStateMachineService.java +++ b/src/android/location/TripDiaryStateMachineService.java @@ -22,6 +22,7 @@ import java.util.LinkedList; import java.util.List; +import edu.berkeley.eecs.emission.cordova.tracker.ConfigManager; import edu.berkeley.eecs.emission.cordova.tracker.sensors.BatteryUtils; import edu.berkeley.eecs.emission.cordova.unifiedlogger.NotificationHelper; import edu.berkeley.eecs.emission.R; @@ -233,12 +234,16 @@ public void onResult(Status status) { String newState = fCtxt.getString(R.string.state_waiting_for_trip_start); if (status.isSuccess()) { setNewState(newState); + if (ConfigManager.getConfig(ctxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Success moving to " + newState); + } } else { + if (ConfigManager.getConfig(ctxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Failed moving to " + newState); } + } mApiClient.disconnect(); } }); @@ -279,12 +284,16 @@ public void onResult(BatchResult batchResult) { String newState = fCtxt.getString(R.string.state_ongoing_trip); if (batchResult.getStatus().isSuccess()) { setNewState(newState); + if (ConfigManager.getConfig(fCtxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Success moving to "+newState); + } } else { + if (ConfigManager.getConfig(fCtxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Failed moving to "+newState+" failed"); } + } mApiClient.disconnect(); } }); @@ -301,12 +310,16 @@ public void onResult(BatchResult batchResult) { String newState = fCtxt.getString(R.string.state_tracking_stopped); if (batchResult.getStatus().isSuccess()) { setNewState(newState); + if (ConfigManager.getConfig(fCtxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Success moving to "+newState); + } } else { + if (ConfigManager.getConfig(fCtxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Failed moving to "+newState); } + } mApiClient.disconnect(); } }); @@ -348,12 +361,16 @@ public void onResult(BatchResult batchResult) { } if (batchResult.getStatus().isSuccess()) { setNewState(newState); + if (ConfigManager.getConfig(ctxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Success moving to "+newState); + } } else { + if (ConfigManager.getConfig(ctxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Failed moving to "+newState); } + } mApiClient.disconnect(); } }); @@ -373,12 +390,16 @@ public void onResult(BatchResult batchResult) { String newState = fCtxt.getString(R.string.state_tracking_stopped); if (batchResult.getStatus().isSuccess()) { setNewState(newState); + if (ConfigManager.getConfig(ctxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Success moving to " + newState); + } } else { + if (ConfigManager.getConfig(ctxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Failed moving to " + newState); } + } mApiClient.disconnect(); } }); @@ -405,12 +426,16 @@ public void onResult(BatchResult batchResult) { String newState = fCtxt.getString(R.string.state_tracking_stopped); if (batchResult.getStatus().isSuccess()) { setNewState(newState); + if (ConfigManager.getConfig(ctxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Success moving to "+newState); + } } else { + if (ConfigManager.getConfig(ctxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Failed moving to "+newState); } + } mApiClient.disconnect(); } }); diff --git a/src/android/location/TripDiaryStateMachineServiceOngoing.java b/src/android/location/TripDiaryStateMachineServiceOngoing.java index c8a8d3b9..924ead92 100644 --- a/src/android/location/TripDiaryStateMachineServiceOngoing.java +++ b/src/android/location/TripDiaryStateMachineServiceOngoing.java @@ -21,6 +21,7 @@ import java.util.LinkedList; import java.util.List; +import edu.berkeley.eecs.emission.cordova.tracker.ConfigManager; import edu.berkeley.eecs.emission.cordova.unifiedlogger.NotificationHelper; import edu.berkeley.eecs.emission.R; import edu.berkeley.eecs.emission.cordova.tracker.location.actions.ActivityRecognitionActions; @@ -249,12 +250,16 @@ public void onResult(BatchResult batchResult) { String newState = fCtxt.getString(R.string.state_tracking_stopped); if (batchResult.getStatus().isSuccess()) { setNewState(newState); + if (ConfigManager.getConfig(fCtxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Success moving to " + newState); + } } else { + if (ConfigManager.getConfig(fCtxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Failed moving to " + newState); } + } mApiClient.disconnect(); } }); @@ -287,12 +292,16 @@ public void onResult(BatchResult batchResult) { String newState = fCtxt.getString(R.string.state_ongoing_trip); if (batchResult.getStatus().isSuccess()) { setNewState(newState); + if (ConfigManager.getConfig(ctxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Success moving to " + newState); + } } else { + if (ConfigManager.getConfig(ctxt).isSimulateUserInteraction()) { NotificationHelper.createNotification(fCtxt, STATE_IN_NUMBERS, "Failed moving to " + newState + " failed"); } + } mApiClient.disconnect(); } });