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

@@ -120,15 +120,15 @@ public class LogManager {
mUtil = new OsdUtil(mContext, handler);
openDb();
Log.i(TAG,"Starting Remote Database Interface");
Log.i(TAG, "Starting Remote Database Interface");
mWac = new WebApiConnection(mContext);
mWac.setStoredToken(mAuthToken);
if (mLogRemote) {
Log.i(TAG,"Starting Remote Log Timer");
Log.i(TAG, "Starting Remote Log Timer");
startRemoteLogTimer();
} else {
Log.i(TAG,"mLogRemote is false - not starting remote log timer");
Log.i(TAG, "mLogRemote is false - not starting remote log timer");
}
if (mAutoPruneDb) {
@@ -182,13 +182,13 @@ public class LogManager {
Log.d(TAG, "openDb");
try {
if (mOsdDb == null) {
Log.i(TAG,"openDb: mOsdDb is null - initialising");
Log.i(TAG, "openDb: mOsdDb is null - initialising");
mOsdDb = new OsdDbHelper(mContext).getWritableDatabase();
} else {
Log.i(TAG,"openDb: mOsdDb has been initialised already so not doing anything");
Log.i(TAG, "openDb: mOsdDb has been initialised already so not doing anything");
}
if (!checkTableExists(mOsdDb, mDpTableName)) {
Log.e(TAG, "ERROR - Table "+mDpTableName+" does not exist");
Log.e(TAG, "ERROR - Table " + mDpTableName + " does not exist");
return false;
} else {
Log.d(TAG, "table " + mDpTableName + " exists ok");
@@ -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());
}
}
@@ -297,7 +299,7 @@ public class LogManager {
/**
* setDatapointStatus() - Update the status of data point id.
*
* @param id datapont id
* @param id datapont id
* @param statusVal the status to set for the datapoint.
* @return true on success or false on failure
*/
@@ -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);
}
}
@@ -799,13 +803,13 @@ public class LogManager {
* WARNING - this should only be called by the final destructor of the app (not individual class destructors)
* because it will close the DB for all instances of LogManger, not just the one on which it is called.
* FIXME: If I was keen I would keep a count of how many instances of LogManager there are, and have this function do nothing
* unless it was the last instance.
* unless it was the last instance.
*/
public static void close() {
mOsdDb.close();
mOsdDb = null;
if (mWac != null) {
Log.i(TAG,"Stopping Remote Database Interface");
Log.i(TAG, "Stopping Remote Database Interface");
mWac.close();
}
}
@@ -898,19 +902,18 @@ public class LogManager {
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// This database is only a cache for online data, so its upgrade policy is
// to simply to discard the data and start over
Log.i(TAG,"onUpgrade()");
Log.i(TAG, "onUpgrade()");
db.execSQL("Drop table if exists " + mDpTableName + ";");
onCreate(db);
}
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.i(TAG,"onDowngrade()");
Log.i(TAG, "onDowngrade()");
onUpgrade(db, oldVersion, newVersion);
}
}
/**
* 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) {
Log.v(TAG, "logData() - writing data to Database");
//writeToSD();
mLm.writeDatapointToLocalDb(mSdData);
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");
mUtil.startServer();
// Bind to the service.
Log.i(TAG, "onStart() - binding to server");
mUtil.writeToSysLogFile("StartupActivity.onStart() - binding to server");
mUtil.bindToServer(getApplicationContext(), mConnection);
// 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);
}