Skip to content

Commit

Permalink
Remove dealing with MODE_CHANGED
Browse files Browse the repository at this point in the history
since we don't receive the messages in API 26 anyway
e-mission/e-mission-docs#325 (comment)
  • Loading branch information
shankari committed Mar 13, 2019
1 parent 3e94966 commit cd6bfea
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
1 change: 0 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
<action android:name="local.transition.stop_tracking"></action>
<action android:name="local.transition.start_tracking"></action>
<action android:name="local.transition.tracking_error"></action>
<action android:name="android.location.MODE_CHANGED"></action>
</intent-filter>
</receiver>
<service
Expand Down
9 changes: 6 additions & 3 deletions src/android/DataCollectionPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void checkAndPromptPermissions() {
private void displayResolution(PendingIntent resolution) {
if (resolution != null) {
try {
// cordova.setActivityResultCallback(this);
cordova.setActivityResultCallback(this);
cordova.getActivity().startIntentSenderForResult(resolution.getIntentSender(), ENABLE_LOCATION_SETTINGS, null, 0, 0, 0, null);
} catch (IntentSender.SendIntentException e) {
NotificationHelper.createNotification(cordova.getActivity(), Constants.TRACKING_ERROR_ID, "Unable to resolve issue");
Expand Down Expand Up @@ -198,15 +198,17 @@ public void onRequestPermissionResult(int requestCode, String[] permissions,
{
case ENABLE_LOCATION_PERMISSION:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
NotificationHelper.cancelNotification(cordova.getActivity(), ENABLE_LOCATION_PERMISSION);
TripDiaryStateMachineService.restartFSMIfStartState(cordova.getActivity());
} else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
TripDiaryStateMachineService.generateLocationEnableNotification(cordova.getActivity());
}
break;
default:
Log.e(cordova.getActivity(), TAG, "Unknown permission code "+requestCode+" ignoring");
}
}

/*
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(cordova.getActivity(), TAG, "received onActivityResult("+requestCode+","+
Expand All @@ -217,6 +219,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(mAct, TAG, requestCode + " is our code, handling callback");
cordova.setActivityResultCallback(null);
final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);
Log.d(cordova.getActivity(), TAG, "at this point, isLocationUsable = "+states.isLocationUsable());
switch (resultCode) {
case Activity.RESULT_OK:
// All required changes were successfully made
Expand All @@ -229,13 +232,13 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.e(cordova.getActivity(), TAG, "User chose not to change settings, dunno what to do");
break;
default:
Log.e(cordova.getActivity(), TAG, "Unknown result code while enabling location "+resultCode);
break;
}
break;
default:
Log.d(cordova.getActivity(), TAG, "Got unsupported request code "+requestCode+ " , ignoring...");
}
}
*/

}
14 changes: 12 additions & 2 deletions src/android/location/TripDiaryStateMachineReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public void onReceive(Context context, Intent intent) {
context.getString(R.string.transition_stopped_moving),
context.getString(R.string.transition_stop_tracking),
context.getString(R.string.transition_start_tracking),
context.getString(R.string.transition_tracking_error),
LocationManager.MODE_CHANGED_ACTION
context.getString(R.string.transition_tracking_error)
}));

if (!validTransitions.contains(intent.getAction())) {
Expand Down Expand Up @@ -125,11 +124,22 @@ public static void performPeriodicActivity(Context ctxt) {
* help with issues we have seen in the field where location updates pause mysteriously, or
* geofences are never exited.
*/
checkLocationStillAvailable(ctxt);
validateAndCleanupState(ctxt);
initOnUpgrade(ctxt);
saveBatteryAndSimulateUser(ctxt);
}

public static void checkLocationStillAvailable(Context ctxt) {
GoogleApiClient mApiClient = new GoogleApiClient.Builder(ctxt)
.addApi(LocationServices.API)
.build();
// This runs as part of the service thread and not the UI thread, so can block
// can switch to Tasks later anyway
mApiClient.blockingConnect();
TripDiaryStateMachineService.checkLocationSettingsAndPermissions(ctxt, mApiClient);
}

public static void validateAndCleanupState(Context ctxt) {
/*
* Check for being in geofence if in waiting_for_trip_state.
Expand Down
15 changes: 8 additions & 7 deletions src/android/location/TripDiaryStateMachineService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@





import edu.berkeley.eecs.emission.cordova.tracker.location.actions.ActivityRecognitionActions;
import edu.berkeley.eecs.emission.cordova.tracker.location.actions.GeofenceActions;
import edu.berkeley.eecs.emission.cordova.tracker.location.actions.LocationTrackingActions;
Expand Down Expand Up @@ -278,11 +280,6 @@ private void handleAction(Context ctxt, GoogleApiClient apiClient, String currSt
BatteryUtils.getBatteryInfo(ctxt));
if (actionString.equals(ctxt.getString(R.string.transition_initialize))) {
handleStart(ctxt, apiClient, actionString);
} else if (LocationManager.MODE_CHANGED_ACTION.equals(actionString)) {
// should we do a handleXXX() wrapper for this too?
checkLocationSettingsAndPermissions(ctxt, apiClient);
// stay in the current state, but do all the service cleanup stuff
setNewState(currState);
} else if (currState.equals(ctxt.getString(R.string.state_start))) {
handleStart(ctxt, apiClient, actionString);
} else if (currState.equals(ctxt.getString(R.string.state_waiting_for_trip_start))) {
Expand Down Expand Up @@ -641,14 +638,18 @@ public static boolean checkLocationPermissions(final Context ctxt,
if (PackageManager.PERMISSION_GRANTED == result) {
return true;
} else {
generateLocationEnableNotification(ctxt);
return false;
}
}

public static void generateLocationEnableNotification(Context ctxt) {
Intent activityIntent = new Intent(ctxt, MainActivity.class);
activityIntent.setAction(DataCollectionPlugin.ENABLE_LOCATION_PERMISSION_ACTION);
PendingIntent pi = PendingIntent.getActivity(ctxt, DataCollectionPlugin.ENABLE_LOCATION_PERMISSION,
activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationHelper.createNotification(ctxt, DataCollectionPlugin.ENABLE_LOCATION_PERMISSION,
"Location permission off, click to enable", pi);
return false;
}
}

public static void checkLocationSettings(final Context ctxt,
Expand Down
3 changes: 0 additions & 3 deletions src/android/location/TripDiaryStateMachineServiceOngoing.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,6 @@ private void handleAction(Context ctxt, GoogleApiClient apiClient, String currSt
// - have initialize function as a reset, which stops any current stuff and starts the new one
if (actionString.equals(ctxt.getString(R.string.transition_initialize))) {
handleStart(ctxt, apiClient, actionString);
} else if (LocationManager.MODE_CHANGED_ACTION.equals(actionString)) {
// should we do a handleXXX() wrapper for this too?
TripDiaryStateMachineService.checkLocationSettingsAndPermissions(ctxt, apiClient);
} else if (currState.equals(ctxt.getString(R.string.state_start))) {
handleStart(ctxt, apiClient, actionString);
} else if (currState.equals(ctxt.getString(R.string.state_waiting_for_trip_start))) {
Expand Down

0 comments on commit cd6bfea

Please sign in to comment.