Prevent crash when sending SMS message if the mLocationFinder variable is null - don't know why it would ever be null, but a user reported a crash in this condition.

This commit is contained in:
Graham Jones
2022-03-24 20:46:45 +00:00
parent ed1de99044
commit 5c633e3fdd
4 changed files with 14 additions and 9 deletions

View File

@@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="uk.org.openseizuredetector"
android:versionCode="98"
android:versionName="4.0.1">
android:versionCode="99"
android:versionName="4.0.2">
<!-- android:allowBackup="false" -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

View File

@@ -1289,14 +1289,19 @@ public class SdServer extends Service implements SdDataReceiver {
public void onFinish() {
Log.v(TAG, "SmsTimer.onFinish()");
mTimeLeft = 0;
mLocationFinder.getLocation(this);
Location loc = mLocationFinder.getLastLocation();
if (loc != null) {
mUtil.showToast(getString(R.string.send_sms_last_location)
+ loc.getLongitude() + ","
+ loc.getLatitude());
if (mLocationFinder != null) {
mLocationFinder.getLocation(this);
Location loc = mLocationFinder.getLastLocation();
if (loc != null) {
mUtil.showToast(getString(R.string.send_sms_last_location)
+ loc.getLongitude() + ","
+ loc.getLatitude());
} else {
Log.i(TAG, "SmsTimer.onFinish() - Last Location is Null so sending first SMS without location.");
}
} else {
Log.i(TAG, "SmsTimer.onFinish() - Last Location is Null so sending first SMS without location.");
Log.e(TAG,"SmsTImer.onFinish() - mLocationFinder is NULL - this should not happen!");
mUtil.showToast("Error Finding Location - mLocationFinder is null - please report this issue!");
}
Log.i(TAG, "SmsTimer.onFinish() - Sending to " + mSMSNumbers.length + " Numbers");
mUtil.writeToSysLogFile("SdServer.SmsTimer.onFinish()");