Progress with app shutdown - it now usually shuts down correctly, but logging out of data sharing is still a problem.

This commit is contained in:
Graham Jones
2022-02-11 06:44:31 +00:00
parent b24c448528
commit 26fb3f6811
5 changed files with 70 additions and 50 deletions

View File

@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
package="uk.org.openseizuredetector"
android:versionCode="92"
android:versionName="4.0.0f">
android:versionName="4.0.0g">
<!-- android:allowBackup="false" -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

View File

@@ -804,6 +804,10 @@ public class LogManager {
public void close() {
mOSDDb.close();
stopRemoteLogTimer();
if (mWac != null) {
Log.i(TAG,"Stopping Remote Database");
mWac.close();
}
}
/*

View File

@@ -200,7 +200,7 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac
* Stop the SdServer service
*/
public void stopServer() {
Log.d(TAG, "OsdUtil.stopServer() - stopping Server... - mNbound=" + mNbound);
Log.i(TAG, "OsdUtil.stopServer() - stopping Server... - mNbound=" + mNbound);
writeToSysLogFile("stopserver() - stopping server");
// then send an Intent to stop the service.

View File

@@ -428,6 +428,8 @@ public class SdServer extends Service implements SdDataReceiver {
Log.v(TAG, "onDestroy(): cancelling notification");
mUtil.writeToSysLogFile("SdServer.onDestroy - cancelling notification");
mNM.cancel(NOTIFICATION_ID);
mNM.cancel(EVENT_NOTIFICATION_ID);
// stop this service.
Log.v(TAG, "onDestroy(): calling stopSelf()");
@@ -439,6 +441,11 @@ public class SdServer extends Service implements SdDataReceiver {
mUtil.writeToSysLogFile("SdServer.onDestroy() -error " + e.toString());
}
if (mLm != null) {
Log.i(TAG, "Closing Down Log Manager");
mLm.close();
}
super.onDestroy();
}
@@ -928,7 +935,6 @@ public class SdServer extends Service implements SdDataReceiver {
};
/*
* Start the timer that will send and SMS alert after a given period.
*/
@@ -961,8 +967,6 @@ public class SdServer extends Service implements SdDataReceiver {
}
/*
* Start the timer that will automatically re-set a latched alarm after a given period.
*/
@@ -1330,6 +1334,7 @@ public class SdServer extends Service implements SdDataReceiver {
*/
public class SmsTimer extends CountDownTimer implements SdLocationReceiver {
public long mTimeLeft = -1;
public SmsTimer(long startTime, long interval) {
super(startTime, interval);
}
@@ -1445,7 +1450,6 @@ public class SdServer extends Service implements SdDataReceiver {
}
}
@@ -1562,7 +1566,6 @@ public class SdServer extends Service implements SdDataReceiver {
}
/**
* Start the events timer.
*/
@@ -1576,7 +1579,7 @@ public class SdServer extends Service implements SdDataReceiver {
runOnUiThread(new Runnable() {
public void run() {
mEventsTimer =
// Run every 5 minutes (convert to ms.)
// Run every 10 sec (convert to ms.)
new CheckUnvalidatedEventsTimer(10 * 1000, 1000);
mEventsTimer.mIsRunning = true;
mEventsTimer.start();
@@ -1604,6 +1607,7 @@ public class SdServer extends Service implements SdDataReceiver {
private class CheckUnvalidatedEventsTimer extends CountDownTimer {
long mFirstUnvalidatedEvent;
public boolean mIsRunning = true;
public CheckUnvalidatedEventsTimer(long startTime, long interval) {
super(startTime, interval);
}
@@ -1612,7 +1616,7 @@ public class SdServer extends Service implements SdDataReceiver {
public void onFinish() {
Log.v(TAG, "CheckUnvalidatedEventsTimer.onFinish()");
// Retrieve events from remote database
mLm.mWac.getEvents((JSONObject remoteEventsObj) -> {
if (mLm.mWac.getEvents((JSONObject remoteEventsObj) -> {
Log.v(TAG, "CheckUnvalidatedEventsTimer.onFinish.getEvents.Callback()");
if (remoteEventsObj == null) {
Log.e(TAG, "CheckUnvalidatedEventsTimer.onFinish() Callback: Error Retrieving events");
@@ -1643,14 +1647,21 @@ public class SdServer extends Service implements SdDataReceiver {
//mUtil.showToast("Error Parsing remoteEventsObj - this should not happen!!!");
}
}
});
})) {
Log.v(TAG,"CheckUnvalidatedEventsTimer() - requested events");
} else {
Log.v(TAG,"CheckUnvalidatedEventsTimer() - Not Logged In");
mNM.cancel(EVENT_NOTIFICATION_ID);
}
if (mIsRunning) {
// Restart this timer.
start();
}
}
@Override public void onTick(long msRemaining) { }
@Override
public void onTick(long msRemaining) {
}
/**
* Show a notification to tell the user that we have unvalidated events.

View File

@@ -50,6 +50,11 @@ public class WebApiConnection {
mUtil = new OsdUtil(mContext, new Handler());
}
public void close() {
Log.i(TAG,"stop()");
mQueue.stop();
}
/**
* Attempt to authenticate with the web API using user name uname and password passwd. Calls function callback with either
* the authentication token on success or null on failure.