Fixed unvalidated events notification and possible crash when sending SMS if mLocationFinder is null (As reported by a user)
This commit is contained in:
@@ -1289,6 +1289,7 @@ public class SdServer extends Service implements SdDataReceiver {
|
||||
public void onFinish() {
|
||||
Log.v(TAG, "SmsTimer.onFinish()");
|
||||
mTimeLeft = 0;
|
||||
if (mLocationFinder!=null) {
|
||||
mLocationFinder.getLocation(this);
|
||||
Location loc = mLocationFinder.getLastLocation();
|
||||
if (loc != null) {
|
||||
@@ -1298,6 +1299,10 @@ public class SdServer extends Service implements SdDataReceiver {
|
||||
} else {
|
||||
Log.i(TAG, "SmsTimer.onFinish() - Last Location is Null so sending first SMS without location.");
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG,"SmsTimer.onFinish - mLocationFinder is null - this should not happen!");
|
||||
mUtil.showToast("SmsTimer.onFinish - mLocationFinder is null - this should not happen! - Please report this issue!")
|
||||
}
|
||||
Log.i(TAG, "SmsTimer.onFinish() - Sending to " + mSMSNumbers.length + " Numbers");
|
||||
mUtil.writeToSysLogFile("SdServer.SmsTimer.onFinish()");
|
||||
Time tnow = new Time(Time.getCurrentTimezone());
|
||||
@@ -1550,28 +1555,26 @@ public class SdServer extends Service implements SdDataReceiver {
|
||||
// Retrieve events from remote database
|
||||
if (mLm.mWac.getEvents((JSONObject remoteEventsObj) -> {
|
||||
Log.v(TAG, "CheckEvents.getEvents.Callback()");
|
||||
long firstUnvalidatedEvent;
|
||||
Boolean haveUnvalidatedEvent = false;
|
||||
if (remoteEventsObj == null) {
|
||||
Log.e(TAG, "CheckEvents.Callback: Error Retrieving events");
|
||||
} else {
|
||||
try {
|
||||
JSONArray eventsArray = remoteEventsObj.getJSONArray("events");
|
||||
// A bit of a hack to display in reverse chronological order
|
||||
firstUnvalidatedEvent = -1;
|
||||
for (int i = eventsArray.length() - 1; i >= 0; i--) {
|
||||
JSONObject eventObj = eventsArray.getJSONObject(i);
|
||||
Long id = eventObj.getLong("id");
|
||||
String typeStr = eventObj.getString("type");
|
||||
//Log.v(TAG,"CheckEventsTimer: id="+id+", typeStr="+typeStr);
|
||||
if (typeStr.equals("null")) {
|
||||
firstUnvalidatedEvent = id;
|
||||
if (typeStr.equals("null") || typeStr.equals("")) {
|
||||
haveUnvalidatedEvent = true;
|
||||
//Log.v(TAG,"CheckEventsTimer:setting firstUnvalidatedEvent to "+firstUnvalidatedEvent);
|
||||
}
|
||||
}
|
||||
Log.v(TAG, "CheckEventsTimer.onFinish.callback - firstUnvalidatedEvent = " +
|
||||
firstUnvalidatedEvent);
|
||||
if (firstUnvalidatedEvent >= 0) {
|
||||
showEventNotification(firstUnvalidatedEvent);
|
||||
Log.v(TAG, "CheckEventsTimer.onFinish.callback - haveUnvalidatedEvent = " +
|
||||
haveUnvalidatedEvent);
|
||||
if (haveUnvalidatedEvent) {
|
||||
showEventNotification();
|
||||
mNM.cancel(DATASHARE_NOTIFICATION_ID);
|
||||
} else {
|
||||
mNM.cancel(EVENT_NOTIFICATION_ID);
|
||||
@@ -1622,7 +1625,7 @@ public class SdServer extends Service implements SdDataReceiver {
|
||||
/**
|
||||
* Show a notification to tell the user that we have unvalidated events.
|
||||
*/
|
||||
private void showEventNotification(long eventId) {
|
||||
private void showEventNotification() {
|
||||
Log.v(TAG, "showEventNotification()");
|
||||
int iconId;
|
||||
String titleStr;
|
||||
|
||||
Reference in New Issue
Block a user