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 ed5863b16a
6 changed files with 70 additions and 50 deletions

Binary file not shown.

View File

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

View File

@@ -804,6 +804,10 @@ public class LogManager {
public void close() { public void close() {
mOSDDb.close(); mOSDDb.close();
stopRemoteLogTimer(); 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 * Stop the SdServer service
*/ */
public void stopServer() { 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"); writeToSysLogFile("stopserver() - stopping server");
// then send an Intent to stop the service. // 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"); Log.v(TAG, "onDestroy(): cancelling notification");
mUtil.writeToSysLogFile("SdServer.onDestroy - cancelling notification"); mUtil.writeToSysLogFile("SdServer.onDestroy - cancelling notification");
mNM.cancel(NOTIFICATION_ID); mNM.cancel(NOTIFICATION_ID);
mNM.cancel(EVENT_NOTIFICATION_ID);
// stop this service. // stop this service.
Log.v(TAG, "onDestroy(): calling stopSelf()"); Log.v(TAG, "onDestroy(): calling stopSelf()");
@@ -439,6 +441,11 @@ public class SdServer extends Service implements SdDataReceiver {
mUtil.writeToSysLogFile("SdServer.onDestroy() -error " + e.toString()); mUtil.writeToSysLogFile("SdServer.onDestroy() -error " + e.toString());
} }
if (mLm != null) {
Log.i(TAG, "Closing Down Log Manager");
mLm.close();
}
super.onDestroy(); 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. * 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. * 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 class SmsTimer extends CountDownTimer implements SdLocationReceiver {
public long mTimeLeft = -1; public long mTimeLeft = -1;
public SmsTimer(long startTime, long interval) { public SmsTimer(long startTime, long interval) {
super(startTime, 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. * Start the events timer.
*/ */
@@ -1576,7 +1579,7 @@ public class SdServer extends Service implements SdDataReceiver {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
mEventsTimer = mEventsTimer =
// Run every 5 minutes (convert to ms.) // Run every 10 sec (convert to ms.)
new CheckUnvalidatedEventsTimer(10 * 1000, 1000); new CheckUnvalidatedEventsTimer(10 * 1000, 1000);
mEventsTimer.mIsRunning = true; mEventsTimer.mIsRunning = true;
mEventsTimer.start(); mEventsTimer.start();
@@ -1604,6 +1607,7 @@ public class SdServer extends Service implements SdDataReceiver {
private class CheckUnvalidatedEventsTimer extends CountDownTimer { private class CheckUnvalidatedEventsTimer extends CountDownTimer {
long mFirstUnvalidatedEvent; long mFirstUnvalidatedEvent;
public boolean mIsRunning = true; public boolean mIsRunning = true;
public CheckUnvalidatedEventsTimer(long startTime, long interval) { public CheckUnvalidatedEventsTimer(long startTime, long interval) {
super(startTime, interval); super(startTime, interval);
} }
@@ -1612,7 +1616,7 @@ public class SdServer extends Service implements SdDataReceiver {
public void onFinish() { public void onFinish() {
Log.v(TAG, "CheckUnvalidatedEventsTimer.onFinish()"); Log.v(TAG, "CheckUnvalidatedEventsTimer.onFinish()");
// Retrieve events from remote database // Retrieve events from remote database
mLm.mWac.getEvents((JSONObject remoteEventsObj) -> { if (mLm.mWac.getEvents((JSONObject remoteEventsObj) -> {
Log.v(TAG, "CheckUnvalidatedEventsTimer.onFinish.getEvents.Callback()"); Log.v(TAG, "CheckUnvalidatedEventsTimer.onFinish.getEvents.Callback()");
if (remoteEventsObj == null) { if (remoteEventsObj == null) {
Log.e(TAG, "CheckUnvalidatedEventsTimer.onFinish() Callback: Error Retrieving events"); 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!!!"); //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) { if (mIsRunning) {
// Restart this timer. // Restart this timer.
start(); 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. * 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()); 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 * 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. * the authentication token on success or null on failure.