diff --git a/app/release/app-release-4.0.0s.apk b/app/release/app-release-4.0.0s.apk
new file mode 100644
index 0000000..97c8a20
Binary files /dev/null and b/app/release/app-release-4.0.0s.apk differ
diff --git a/app/release/app-release-4.0.0r.apk b/app/release/old_versions/app-release-4.0.0r.apk
similarity index 100%
rename from app/release/app-release-4.0.0r.apk
rename to app/release/old_versions/app-release-4.0.0r.apk
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index e8b226b..0017ad4 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -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">
diff --git a/app/src/main/java/uk/org/openseizuredetector/LogManager.java b/app/src/main/java/uk/org/openseizuredetector/LogManager.java
index 28c1f01..9bb8f99 100644
--- a/app/src/main/java/uk/org/openseizuredetector/LogManager.java
+++ b/app/src/main/java/uk/org/openseizuredetector/LogManager.java
@@ -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 {
// 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.
*/
diff --git a/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java b/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java
index 77a1407..8d0227f 100644
--- a/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java
+++ b/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java
@@ -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();
diff --git a/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java b/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java
index 793cc27..24757cc 100644
--- a/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java
+++ b/app/src/main/java/uk/org/openseizuredetector/SdDataSource.java
@@ -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;
}
}
diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java
index 9cbd28d..c71383e 100644
--- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java
+++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java
@@ -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");
+ }
}
}
diff --git a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java
index 76ba0f3..2e34d1c 100644
--- a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java
+++ b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java
@@ -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);
-
}