V4.0.0s - fixed issue with system not shutting down properly after enabling SMS alarms.

This commit is contained in:
Graham Jones
2022-03-04 20:47:34 +00:00
parent 8371171be4
commit 952a4a9304
8 changed files with 47 additions and 39 deletions

Binary file not shown.

View File

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

View File

@@ -246,6 +246,8 @@ public class LogManager {
} catch (SQLException e) {
Log.e(TAG, "writeToLocalDb(): Error Writing Data: " + e.toString());
Log.e(TAG, "SQLStr was " + SQLStr);
} catch (NullPointerException e) {
Log.e(TAG, "writeToLocalDb(): Null Pointer Exception: " + e.toString());
}
}
@@ -532,7 +534,6 @@ public class LogManager {
/**
* Executes the sqlite query (=SELECT statement)
* Use as new SelectQueryTask(xxx,xxx,xx,xxxx).execute()
*
*/
static private class SelectQueryTask extends AsyncTask<Void, Void, Cursor> {
// Based on https://stackoverflow.com/a/21120199/2104584
@@ -579,6 +580,9 @@ public class LogManager {
} catch (IllegalArgumentException e) {
Log.e(TAG, "SelectQueryTask.doInBackground(): Illegal Argument Exception: " + e.toString());
return (null);
} catch (NullPointerException e) {
Log.e(TAG, "SelectQueryTask.doInBackground(): Null Pointer Exception: " + e.toString());
return (null);
}
}
@@ -910,7 +914,6 @@ public class LogManager {
}
/**
* Upload recorded data to the remote database periodically.
*/

View File

@@ -144,6 +144,8 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
Log.i(TAG, "SharedPreference " + s + " Changed.");
// if we have enabled the SMS alarm, we may need extra permissions approving. This is handled in
// StartUpActivity, so we exit this activity and start start-up activity.
if (s.equals("SMSAlarm")) {
if (sharedPreferences.getBoolean("SMSAlarm", false) == true) {
Log.i(TAG, "onSharedPreferenceChanged(): SMS Alarm Enabled - Restarting start-up activity to check permissions");
@@ -152,10 +154,12 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
startActivity(i);
Log.i(TAG,"onSharedPreferenceChanged() - finishing PrefActivity");
finish();
return;
} else {
Log.i(TAG, "OnSharedPreferenceChanged(): SMS Alarm disabled so do not need permissions");
}
}
// For all other preference changes we just restart SdServer so it is not as alarming for the user!
//mUtil.showToast("Setting " + s + " Changed - restarting server");
mPrefChanged = true;
mUtil.stopServer();

View File

@@ -691,11 +691,11 @@ public abstract class SdDataSource {
// get time since the last data was received from the watch.
tdiff = (tnow.toMillis(false) - mDataStatusTime.toMillis(false));
Log.v(TAG, "faultCheck() - tdiff=" + tdiff + ", mDataUpatePeriod=" + mDataUpdatePeriod + ", mAppRestartTimeout=" + mAppRestartTimeout
+ ", combined = " + (mDataUpdatePeriod + mAppRestartTimeout) * 1000);
//Log.v(TAG, "faultCheck() - tdiff=" + tdiff + ", mDataUpatePeriod=" + mDataUpdatePeriod + ", mAppRestartTimeout=" + mAppRestartTimeout
// + ", combined = " + (mDataUpdatePeriod + mAppRestartTimeout) * 1000);
if (!mWatchAppRunningCheck &&
(tdiff > (mDataUpdatePeriod + mAppRestartTimeout) * 1000)) {
Log.v(TAG, "faultCheck() - watch app not running so not doing anything");
//Log.v(TAG, "faultCheck() - watch app not running so not doing anything");
mAlarmCount = 0;
}
}

View File

@@ -1132,9 +1132,13 @@ public class SdServer extends Service implements SdDataReceiver {
*/
public void logData() {
if (mLogData) {
if (mLm != null) {
Log.v(TAG, "logData() - writing data to Database");
//writeToSD();
mLm.writeDatapointToLocalDb(mSdData);
} else {
Log.e(TAG,"logData() - mLm is null - this should not happen");
}
}
}

View File

@@ -182,18 +182,24 @@ public class StartupActivity extends AppCompatActivity {
if (mUtil.isServerRunning()) {
Log.i(TAG, "onStart() - server running - stopping it");
Log.i(TAG, "onStart() - server running - stopping it - isServerRunning="+mUtil.isServerRunning());
mUtil.writeToSysLogFile("StartupActivity.onStart() - server already running - stopping it.");
mUtil.stopServer();
} else {
Log.i(TAG, "onStart() - server not running - isServerRunning="+mUtil.isServerRunning());
}
mUtil.writeToSysLogFile("StartupActivity.onStart() - starting server");
Log.i(TAG, "onStart() - starting server");
// Wait 0.1 second to give the server chance to shutdown in case we have just shut it down below, then start it
mHandler.postDelayed(new Runnable() {
public void run() {
mUtil.writeToSysLogFile("StartupActivity.onStart() - starting server after delay - isServerRunning="+mUtil.isServerRunning());
Log.i(TAG, "onStart() - starting server after delay -isServerRunning="+mUtil.isServerRunning());
mUtil.startServer();
// Bind to the service.
Log.i(TAG, "onStart() - binding to server");
mUtil.writeToSysLogFile("StartupActivity.onStart() - binding to server");
mUtil.bindToServer(getApplicationContext(), mConnection);
}
}, 100);
// Check power management settings
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
@@ -218,7 +224,7 @@ public class StartupActivity extends AppCompatActivity {
mHandler.post(serverStatusRunnable);
//updateServerStatus();
}
}, 0, 2000);
}, 0, 5000);
}
@@ -641,15 +647,6 @@ public class StartupActivity extends AppCompatActivity {
for (int i = 0; i < permissions.length; i++) {
Log.i(TAG, "Permission " + permissions[i] + " = " + grantResults[i]);
}
//mUtil.showToast(getString(R.string.RestartingServerMsg));
//mUtil.stopServer();
// Wait 0.1 second to give the server chance to shutdown, then re-start it
//mHandler.postDelayed(new Runnable() {
//public void run() {
//mUtil.startServer();
//}
//}, 100);
}