diff --git a/app/release/app-release-4.0.0i.apk b/app/release/app-release-4.0.0i.apk new file mode 100644 index 0000000..167e2d4 Binary files /dev/null and b/app/release/app-release-4.0.0i.apk differ diff --git a/app/release/old_versions/app-release-4.0.0a.apk b/app/release/old_versions/app-release-4.0.0a.apk new file mode 100644 index 0000000..2e7b8fa Binary files /dev/null and b/app/release/old_versions/app-release-4.0.0a.apk differ diff --git a/app/release/old_versions/app-release-4.0.0b.apk b/app/release/old_versions/app-release-4.0.0b.apk new file mode 100644 index 0000000..089b419 Binary files /dev/null and b/app/release/old_versions/app-release-4.0.0b.apk differ diff --git a/app/release/old_versions/app-release-4.0.0d.apk b/app/release/old_versions/app-release-4.0.0d.apk new file mode 100644 index 0000000..36634da Binary files /dev/null and b/app/release/old_versions/app-release-4.0.0d.apk differ diff --git a/app/release/old_versions/app-release-4.0.0f.apk b/app/release/old_versions/app-release-4.0.0f.apk new file mode 100644 index 0000000..813450a Binary files /dev/null and b/app/release/old_versions/app-release-4.0.0f.apk differ diff --git a/app/release/old_versions/app-release-4.0.0g.apk b/app/release/old_versions/app-release-4.0.0g.apk new file mode 100644 index 0000000..4be2b0b Binary files /dev/null and b/app/release/old_versions/app-release-4.0.0g.apk differ diff --git a/app/release/app-release-4.0.0h.apk b/app/release/old_versions/app-release-4.0.0h.apk similarity index 100% rename from app/release/app-release-4.0.0h.apk rename to app/release/old_versions/app-release-4.0.0h.apk diff --git a/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java b/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java index aae30b8..f0e454c 100644 --- a/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java @@ -31,11 +31,17 @@ public class AuthenticateActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - Log.v(TAG, "onCreate()"); + Log.d(TAG, "onCreate()"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_authenticate); mUtil = new OsdUtil(getApplicationContext(), serverStatusHandler); + + if (!mUtil.isServerRunning()) { + mUtil.showToast(getString(R.string.error_server_not_running)); + finish(); + return; + } mConnection = new SdServiceConnection(getApplicationContext()); Button cancelBtn = @@ -61,13 +67,21 @@ public class AuthenticateActivity extends AppCompatActivity { @Override protected void onStart() { + Log.d(TAG, "onStart()"); super.onStart(); mUtil.bindToServer(getApplicationContext(), mConnection); waitForConnection(); - updateUi(); } + @Override + protected void onStop() { + Log.d(TAG, "onStop()"); + super.onStop(); + mUtil.unbindFromServer(getApplicationContext(), mConnection); + } + + private void waitForConnection() { // We want the UI to update as soon as it is displayed, but it takes a finite time for // the mConnection to bind to the service, so we delay half a second to give it chance diff --git a/app/src/main/java/uk/org/openseizuredetector/LogManagerControlActivity.java b/app/src/main/java/uk/org/openseizuredetector/LogManagerControlActivity.java index d1484e5..a7b0729 100644 --- a/app/src/main/java/uk/org/openseizuredetector/LogManagerControlActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/LogManagerControlActivity.java @@ -68,6 +68,13 @@ public class LogManagerControlActivity extends AppCompatActivity { super.onCreate(savedInstanceState); mContext = this; mUtil = new OsdUtil(getApplicationContext(), serverStatusHandler); + + if (!mUtil.isServerRunning()) { + mUtil.showToast(getString(R.string.error_server_not_running)); + finish(); + return; + } + mConnection = new SdServiceConnection(getApplicationContext()); setContentView(R.layout.activity_log_manager_control); @@ -137,7 +144,7 @@ public class LogManagerControlActivity extends AppCompatActivity { Log.v(TAG, "onStop()"); super.onStop(); stopUiTimer(); - mUtil.unbindFromServer(this, mConnection); + mUtil.unbindFromServer(getApplicationContext(), mConnection); } @Override @@ -559,7 +566,7 @@ public class LogManagerControlActivity extends AppCompatActivity { public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); Map dataItem = (Map)getItem(position); - Log.i(TAG,dataItem.toString()); + Log.v(TAG,"getView() "+dataItem.toString()); switch(dataItem.get("type").toString()) { case "null": v.setBackgroundColor(Color.parseColor("#ffaaaa")); diff --git a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java index a0331b6..9bf9e00 100644 --- a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java @@ -98,7 +98,7 @@ public class MainActivity extends AppCompatActivity { //int i = 5/0; // Force exception to test handler. mUtil = new OsdUtil(getApplicationContext(),serverStatusHandler); - mConnection = new SdServiceConnection(this); + mConnection = new SdServiceConnection(getApplicationContext()); mUtil.writeToSysLogFile(""); mUtil.writeToSysLogFile("* MainActivity Started *"); mUtil.writeToSysLogFile("MainActivity.onCreate()"); @@ -236,14 +236,14 @@ public class MainActivity extends AppCompatActivity { Log.i(TAG, "action_sart_stop"); if (mConnection.mBound) { Log.i(TAG, "Stopping Server"); - mUtil.unbindFromServer(this, mConnection); + mUtil.unbindFromServer(getApplicationContext(), mConnection); stopServer(); } else { Log.i(TAG, "Starting Server"); startServer(); // and bind to it so we can see its data Log.i(TAG, "Binding to Server"); - mUtil.bindToServer(this, mConnection); + mUtil.bindToServer(getApplicationContext(), mConnection); } return true; /* fault beep test does not work with fault timer, so disable test option. @@ -369,7 +369,7 @@ public class MainActivity extends AppCompatActivity { @Override protected void onStart() { super.onStart(); - Log.i(TAG,"onStart()"); + Log.d(TAG,"onStart()"); mUtil.writeToSysLogFile("MainActivity.onStart()"); SharedPreferences SP = PreferenceManager .getDefaultSharedPreferences(getBaseContext()); @@ -383,7 +383,7 @@ public class MainActivity extends AppCompatActivity { if (mUtil.isServerRunning()) { mUtil.writeToSysLogFile("MainActivity.onStart - Binding to Server"); - mUtil.bindToServer(this, mConnection); + mUtil.bindToServer(getApplicationContext(), mConnection); } else { Log.i(TAG,"onStart() - Server Not Running"); mUtil.writeToSysLogFile("MainActivity.onStart - Server Not Running"); @@ -403,9 +403,9 @@ public class MainActivity extends AppCompatActivity { @Override protected void onStop() { super.onStop(); - Log.i(TAG,"onStop() - unbinding from server"); + Log.d(TAG,"onStop() - unbinding from server"); mUtil.writeToSysLogFile("MainActivity.onStop()"); - mUtil.unbindFromServer(this, mConnection); + mUtil.unbindFromServer(getApplicationContext(), mConnection); mUiTimer.cancel(); } @@ -903,14 +903,14 @@ public class MainActivity extends AppCompatActivity { @Override protected void onPause() { super.onPause(); - Log.i(TAG,"onPause()"); + Log.d(TAG,"onPause()"); mUtil.writeToSysLogFile("MainActivity.onPause()"); } @Override protected void onResume() { super.onResume(); - Log.i(TAG,"onResume()"); + Log.d(TAG,"onResume()"); mUtil.writeToSysLogFile("MainActivity.onResume()"); } diff --git a/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java b/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java index 46de791..9ad5947 100644 --- a/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java +++ b/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java @@ -226,7 +226,7 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac /** * unbind an activity from server */ - public void unbindFromServer(Activity activity, SdServiceConnection sdServiceConnection) { + public void unbindFromServer(Context activity, SdServiceConnection sdServiceConnection) { // unbind this activity from the service if it is bound. if (sdServiceConnection.mBound) { Log.i(TAG, "unbindFromServer() - unbinding"); diff --git a/app/src/main/java/uk/org/openseizuredetector/ReportSeizureActivity.java b/app/src/main/java/uk/org/openseizuredetector/ReportSeizureActivity.java index 42c0549..29ddce1 100644 --- a/app/src/main/java/uk/org/openseizuredetector/ReportSeizureActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/ReportSeizureActivity.java @@ -36,26 +36,27 @@ public class ReportSeizureActivity extends AppCompatActivity { private LogManager mLm; private int mYear, mMonth, mDay, mHour, mMinute; private String mMsg = "Messages"; - private OsdUtil osdUtil; private SdServiceConnection mConnection; private OsdUtil mUtil; final Handler serverStatusHandler = new Handler(); - @Override protected void onCreate(Bundle savedInstanceState) { Log.v(TAG, "onCreate()"); super.onCreate(savedInstanceState); - mContext = this; - Handler h = new Handler(); - osdUtil = new OsdUtil(mContext, h); - setContentView(R.layout.activity_report_seizure); mUtil = new OsdUtil(this, serverStatusHandler); - mConnection = new SdServiceConnection(this); + if (!mUtil.isServerRunning()) { + mUtil.showToast(getString(R.string.error_server_not_running)); + finish(); + return; + } + mConnection = new SdServiceConnection(getApplicationContext()); + setContentView(R.layout.activity_report_seizure); // It takes a finite time for // the mConnection to bind to the service, so we delay half a second to give it chance // to connect before trying to get the SdServer LogManager instance) + // FIXME: We should probably implement a WaitForConnection function like we do in some of the other activities new Handler().postDelayed(new Runnable() { @Override public void run() { @@ -97,7 +98,7 @@ public class ReportSeizureActivity extends AppCompatActivity { @Override protected void onStart() { super.onStart(); - mUtil.bindToServer(this, mConnection); + mUtil.bindToServer(getApplicationContext(), mConnection); //startUiTimer(); } @@ -116,7 +117,7 @@ public class ReportSeizureActivity extends AppCompatActivity { @Override protected void onStop() { super.onStop(); - mUtil.unbindFromServer(this, mConnection); + mUtil.unbindFromServer(getApplicationContext(), mConnection); } @@ -153,11 +154,11 @@ public class ReportSeizureActivity extends AppCompatActivity { if (id!=-1) { mLm.setDatapointStatus(id,5); mMsg = mMsg + "\nSet Datapoint to Manual Alarm Status"; - osdUtil.showToast(getString(R.string.createdNewEvent)); + mUtil.showToast(getString(R.string.createdNewEvent)); finish(); } else { mMsg = mMsg + "\n*** Datapoint not found - not doing anything ***"; - osdUtil.showToast(getString(R.string.DatapointNotFound)); + mUtil.showToast(getString(R.string.DatapointNotFound)); } }); } diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index 64c6ee1..e826d22 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -360,7 +360,7 @@ public class SdServer extends Service implements SdDataReceiver { if (mWakeLock != null) { try { mWakeLock.release(); - Log.v(TAG, "Released Wake Lock to allow device to sleep."); + Log.d(TAG, "Released Wake Lock to allow device to sleep."); } catch (Exception e) { Log.e(TAG, "Error Releasing Wakelock - " + e.toString()); mUtil.writeToSysLogFile("SdServer.onDestroy() - Error releasing wakelock."); @@ -372,7 +372,7 @@ public class SdServer extends Service implements SdDataReceiver { } if (mSdDataSource != null) { - Log.i(TAG, "stopping mSdDataSource"); + Log.d(TAG, "stopping mSdDataSource"); mUtil.writeToSysLogFile("SdServer.onDestroy() - stopping mSdDataSource"); mSdDataSource.stop(); } else { @@ -382,7 +382,7 @@ public class SdServer extends Service implements SdDataReceiver { // Stop the Cancel Audible timer if (mCancelAudibleTimer != null) { - Log.v(TAG, "onDestroy(): cancelling Cancel_Audible timer"); + Log.d(TAG, "onDestroy(): cancelling Cancel_Audible timer"); mCancelAudibleTimer.cancel(); //mCancelAudibleTimer.purge(); mCancelAudibleTimer = null; @@ -391,23 +391,25 @@ public class SdServer extends Service implements SdDataReceiver { // Stop the Fault timer if (mFaultTimer != null) { - Log.v(TAG, "onDestroy(): cancelling fault timer"); + Log.d(TAG, "onDestroy(): cancelling fault timer"); mFaultTimer.cancel(); mFaultTimer = null; } // Stop the Event timer if (mEventsTimer != null) { - Log.v(TAG, "onDestroy(): Cancelling events timer"); + Log.d(TAG, "onDestroy(): Cancelling events timer"); stopValidatedEventsTimer(); } // Stop the Cancel Alarm Latch timer + Log.d(TAG,"onDestroy(): stopping alarm latch timer"); stopLatchTimer(); // Stop the location finder. if (mLocationFinder != null) { + Log.d(TAG,"onDestroy(): stopping Location Finder"); mLocationFinder.destroy(); mLocationFinder = null; } @@ -415,7 +417,7 @@ public class SdServer extends Service implements SdDataReceiver { try { // Stop web server - Log.v(TAG, "onDestroy(): stopping web server"); + Log.d(TAG, "onDestroy(): stopping web server"); mUtil.writeToSysLogFile("SdServer.onDestroy() - stopping Web Server"); stopWebServer(); @@ -425,24 +427,24 @@ public class SdServer extends Service implements SdDataReceiver { this.stopForeground(true); // Cancel the notification. - Log.v(TAG, "onDestroy(): cancelling notification"); + Log.d(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()"); + Log.d(TAG, "onDestroy(): calling stopSelf()"); mUtil.writeToSysLogFile("SdServer.onDestroy() - stopping self"); stopSelf(); } catch (Exception e) { - Log.v(TAG, "Error in onDestroy() - " + e.toString()); + Log.e(TAG, "Error in onDestroy() - " + e.toString()); mUtil.writeToSysLogFile("SdServer.onDestroy() -error " + e.toString()); } if (mLm != null) { - Log.i(TAG, "Closing Down Log Manager"); + Log.d(TAG, "Closing Down Log Manager"); mLm.close(); } @@ -1594,10 +1596,10 @@ public class SdServer extends Service implements SdDataReceiver { public void stopValidatedEventsTimer() { if (mEventsTimer != null) { Log.v(TAG, "stopEventsTimer(): timer already running - cancelling it."); - mUtil.writeToSysLogFile("stopEventsTimer() - stopping timer"); + mUtil.writeToSysLogFile("stopEventsTimer() - stopping timer, setting mIsRunning to false"); mEventsTimer.mIsRunning = false; mEventsTimer.cancel(); - mEventsTimer = null; + //mEventsTimer = null; } else { Log.v(TAG, "stopEventsTimer(): timer not running - not doing anything."); } @@ -1658,6 +1660,7 @@ public class SdServer extends Service implements SdDataReceiver { } if (mIsRunning) { // Restart this timer. + Log.v(TAG,"CheckUnvalidatedEventsTimer.onFinish() - mIsRunning is true, so re-starting timer"); start(); } } diff --git a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java index accf8a1..2cf22e7 100644 --- a/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/StartupActivity.java @@ -144,7 +144,7 @@ public class StartupActivity extends Activity { } }); - mConnection = new SdServiceConnection(this); + mConnection = new SdServiceConnection(getApplicationContext()); } @Override @@ -186,7 +186,7 @@ public class StartupActivity extends Activity { // Bind to the service. Log.i(TAG,"onStart() - binding to server"); mUtil.writeToSysLogFile("StartupActivity.onStart() - binding to server"); - mUtil.bindToServer(this, mConnection); + mUtil.bindToServer(getApplicationContext(), mConnection); // Check power management settings PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); @@ -221,7 +221,7 @@ public class StartupActivity extends Activity { super.onStop(); Log.i(TAG, "onStop() - unbinding from server"); mUtil.writeToSysLogFile("StartupActivity.onStop() - unbinding from server"); - mUtil.unbindFromServer(this, mConnection); + mUtil.unbindFromServer(getApplicationContext(), mConnection); mUiTimer.cancel(); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3bd6b0a..67a3222 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -347,4 +347,5 @@ Shared Data Prune Database Please select the events highlighted in pink to say if they are real seizures or false alarms + ERROR: OpenSeizureDetector Server is not running - please re-start it