Upate to V2.5.5 beta - Corrected some network logging messages, and made NetworkDataSource use the timeout settings in the preferences screen (it used to ignore them!)

This commit is contained in:
Graham Jones
2018-02-23 15:01:53 +00:00
parent 538592bb4b
commit bae32ca54f
5 changed files with 43 additions and 33 deletions

View File

@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":40},"path":"app-release.apk","properties":{"packageId":"uk.org.openseizuredetector","split":"","minSdkVersion":"14"}}] [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":41},"path":"app-release.apk","properties":{"packageId":"uk.org.openseizuredetector","split":"","minSdkVersion":"14"}}]

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.org.openseizuredetector" package="uk.org.openseizuredetector"
android:versionCode="40" android:versionCode="41"
android:versionName="2.5.5"> android:versionName="2.5.5">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />

View File

@@ -28,6 +28,8 @@ public class SdDataSourceNetwork extends SdDataSource {
private Time mStatusTime; private Time mStatusTime;
private Timer mDataUpdateTimer; private Timer mDataUpdateTimer;
private int mDataUpdatePeriod = 2000; private int mDataUpdatePeriod = 2000;
private int mConnnectTimeoutPeriod = 5000;
private int mReadTimeoutPeriod = 5000;
private String mServerIP = "unknown"; private String mServerIP = "unknown";
private int ALARM_STATE_NETFAULT = 7; private int ALARM_STATE_NETFAULT = 7;
@@ -92,6 +94,12 @@ public class SdDataSourceNetwork extends SdDataSource {
String dataUpdatePeriodStr = SP.getString("DataUpdatePeriod","2000"); String dataUpdatePeriodStr = SP.getString("DataUpdatePeriod","2000");
mDataUpdatePeriod = Integer.parseInt(dataUpdatePeriodStr); mDataUpdatePeriod = Integer.parseInt(dataUpdatePeriodStr);
Log.v(TAG,"updatePrefs() - mDataUpdatePeriod = "+mDataUpdatePeriod); Log.v(TAG,"updatePrefs() - mDataUpdatePeriod = "+mDataUpdatePeriod);
String connectTimeoutPeriodStr = SP.getString("ConnectTimeoutPeriod","5000");
mConnnectTimeoutPeriod = Integer.parseInt(connectTimeoutPeriodStr);
Log.v(TAG,"updatePrefs() - mConnectTimeoutPeriod = "+mConnnectTimeoutPeriod);
String readTimeoutPeriodStr = SP.getString("ReadTimeoutPeriod","5000");
mReadTimeoutPeriod = Integer.parseInt(readTimeoutPeriodStr);
Log.v(TAG,"updatePrefs() - mReadTimeoutPeriod = "+mReadTimeoutPeriod);
} catch (Exception ex) { } catch (Exception ex) {
Log.v(TAG,"updatePrefs() - Problem parsing preferences!"); Log.v(TAG,"updatePrefs() - Problem parsing preferences!");
mUtil.writeToSysLogFile("SdDataSourceNetwork().updatePrefs() - " +ex.toString()); mUtil.writeToSysLogFile("SdDataSourceNetwork().updatePrefs() - " +ex.toString());
@@ -156,9 +164,7 @@ public class SdDataSourceNetwork extends SdDataSource {
} }
/** /**
* Retrive the current Seizure Detector Data from the server. * Accept an alarm remotely using a http GET request.
* Uses the DownloadSdDataTask class to download the data in the
* background. The data is processed in DownloadSdDataTask.onPostExecute().
*/ */
@Override @Override
public void acceptAlarm() { public void acceptAlarm() {
@@ -203,8 +209,8 @@ public class SdDataSourceNetwork extends SdDataSource {
try { try {
URL url = new URL(myurl); URL url = new URL(myurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(5000 /* milliseconds */); conn.setReadTimeout(mReadTimeoutPeriod /* milliseconds */);
conn.setConnectTimeout(5000 /* milliseconds */); conn.setConnectTimeout(mConnnectTimeoutPeriod /* milliseconds */);
conn.setRequestMethod("GET"); conn.setRequestMethod("GET");
conn.setDoInput(true); conn.setDoInput(true);
// Starts the query // Starts the query

View File

@@ -548,12 +548,12 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
} else { } else {
if (mAudibleFaultWarning) { if (mAudibleFaultWarning) {
if (mMp3Alarm) { if (mMp3Alarm) {
Log.v(TAG,"making MP3 alarm beep"); Log.v(TAG, "making MP3 alarm beep");
// From https://stackoverflow.com/questions/4441334/how-to-play-an-android-notification-sound // From https://stackoverflow.com/questions/4441334/how-to-play-an-android-notification-sound
// This plays an audio file as a notification, using the notification sound channel. // This plays an audio file as a notification, using the notification sound channel.
NotificationManager notificationManager = NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = Uri.parse("android.resource://"+getPackageName()+"/raw/fault"); Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/raw/fault");
NotificationCompat.Builder mBuilder = NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext()) new NotificationCompat.Builder(getApplicationContext())
.setSound(soundUri); //This sets the sound to play .setSound(soundUri); //This sets the sound to play
@@ -570,6 +570,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
} else { } else {
startFaultTimer(); startFaultTimer();
Log.v(TAG, "faultWarningBeep() - starting Fault Timer"); Log.v(TAG, "faultWarningBeep() - starting Fault Timer");
mUtil.writeToSysLogFile("faultWarningBeep() - starting Fault Timer");
} }
} }
@@ -584,15 +585,15 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
} else { } else {
if (mAudibleAlarm) { if (mAudibleAlarm) {
if (mMp3Alarm) { if (mMp3Alarm) {
Log.v(TAG,"making MP3 alarm beep"); Log.v(TAG, "making MP3 alarm beep");
// From https://stackoverflow.com/questions/4441334/how-to-play-an-android-notification-sound // From https://stackoverflow.com/questions/4441334/how-to-play-an-android-notification-sound
// This plays an audio file as a notification, using the notification sound channel. // This plays an audio file as a notification, using the notification sound channel.
NotificationManager notificationManager = NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = Uri.parse("android.resource://"+getPackageName()+"/raw/alarm"); Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/raw/alarm");
NotificationCompat.Builder mBuilder = NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext()) new NotificationCompat.Builder(getApplicationContext())
.setSound(soundUri); //This sets the sound to play .setSound(soundUri); //This sets the sound to play
notificationManager.notify(0, mBuilder.build()); notificationManager.notify(0, mBuilder.build());
} else { } else {
beep(3000); beep(3000);
@@ -614,12 +615,12 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
} else { } else {
if (mAudibleWarning) { if (mAudibleWarning) {
if (mMp3Alarm) { if (mMp3Alarm) {
Log.v(TAG,"making MP3 alarm beep"); Log.v(TAG, "making MP3 alarm beep");
// From https://stackoverflow.com/questions/4441334/how-to-play-an-android-notification-sound // From https://stackoverflow.com/questions/4441334/how-to-play-an-android-notification-sound
// This plays an audio file as a notification, using the notification sound channel. // This plays an audio file as a notification, using the notification sound channel.
NotificationManager notificationManager = NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = Uri.parse("android.resource://"+getPackageName()+"/raw/warning"); Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/raw/warning");
NotificationCompat.Builder mBuilder = NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext()) new NotificationCompat.Builder(getApplicationContext())
.setSound(soundUri); //This sets the sound to play .setSound(soundUri); //This sets the sound to play
@@ -819,7 +820,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
mNetworkBroadcastReceiver = new NetworkBroadcastReceiver(); mNetworkBroadcastReceiver = new NetworkBroadcastReceiver();
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
//filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); //filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
getApplicationContext().registerReceiver(mNetworkBroadcastReceiver,filter); getApplicationContext().registerReceiver(mNetworkBroadcastReceiver, filter);
} }
/** /**
@@ -843,37 +844,36 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
private class NetworkBroadcastReceiver extends BroadcastReceiver { private class NetworkBroadcastReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.v(TAG,"NetworkBroadCastReceiver.onReceive"); Log.v(TAG, "NetworkBroadCastReceiver.onReceive");
mUtil.writeToSysLogFile("Network State Changed" + intent.getAction()); //mUtil.writeToSysLogFile("Network State Changed" + intent.getAction());
//mUtil.showToast("Network State Changed" + intent.getAction()); //mUtil.showToast("Network State Changed" + intent.getAction());
ConnectivityManager cm = ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = null; NetworkInfo activeNetwork = null;
try { try {
activeNetwork = cm.getActiveNetworkInfo(); activeNetwork = cm.getActiveNetworkInfo();
} catch (Exception e) { } catch (Exception e) {
Log.v(TAG,"NetworkBroadcastReceiver - failed to retrieve active network info"); Log.v(TAG, "NetworkBroadcastReceiver - failed to retrieve active network info");
mUtil.writeToSysLogFile("NetworkBroadcastReceiver - failed to retrieve active network info"); mUtil.writeToSysLogFile("NetworkBroadcastReceiver - failed to retrieve active network info");
Log.v(TAG,e.toString()); Log.v(TAG, e.toString());
} }
if (activeNetwork != null) { boolean isConnected = activeNetwork != null &&
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
activeNetwork.isConnectedOrConnecting(); if (isConnected) {
boolean isWiFi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI; boolean isWiFi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
if (!isWiFi) { if (!isWiFi) {
Log.v(TAG,"NetworkBroadcastReceiver - no Wifi Connection"); Log.v(TAG, "NetworkBroadcastReceiver - no Wifi Connection");
mUtil.writeToSysLogFile("Network State Changed - no Wifi Connection"); mUtil.writeToSysLogFile("Network State Changed - no Wifi Connection");
mUtil.showToast("Network State Changed - no Wifi Connection"); mUtil.showToast("Network State Changed - no Wifi Connection");
} else { } else {
Log.v(TAG,"NetworkBroadcastReceiver - Wifi Connected"); Log.v(TAG, "NetworkBroadcastReceiver - Wifi Connected");
mUtil.writeToSysLogFile("Network State Changed - Wifi Connected"); mUtil.writeToSysLogFile("Network State Changed - Wifi Connected");
mUtil.showToast("Network State Changed - Wifi Connected"); mUtil.showToast("Network State Changed - Wifi Connected");
} }
} else { } else {
Log.v(TAG,"NetworkBroadcastReceiver - No Active Network"); Log.v(TAG, "NetworkBroadcastReceiver - No Active Network");
mUtil.writeToSysLogFile("Network State Changed - No Active Network"); mUtil.writeToSysLogFile("Network State Changed - No Active Network");
mUtil.showToast("Network State Changed - No Active Network"); mUtil.showToast("Network State Changed - No Active Network");
} }
@@ -1065,8 +1065,10 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
public void startFaultTimer() { public void startFaultTimer() {
if (mFaultTimer != null) { if (mFaultTimer != null) {
Log.v(TAG, "startFaultTimer(): fault timer already running - not doing anything."); Log.v(TAG, "startFaultTimer(): fault timer already running - not doing anything.");
mUtil.writeToSysLogFile("startFaultTimer() - fault timer already running");
} else { } else {
Log.v(TAG, "startFaultTimer(): starting fault timer."); Log.v(TAG, "startFaultTimer(): starting fault timer.");
mUtil.writeToSysLogFile("startFaultTimer() - starting fault timer");
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
public void run() { public void run() {
mFaultTimerCompleted = false; mFaultTimerCompleted = false;
@@ -1082,11 +1084,13 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
public void stopFaultTimer() { public void stopFaultTimer() {
if (mFaultTimer != null) { if (mFaultTimer != null) {
Log.v(TAG, "stopFaultTimer(): fault timer already running - cancelling it."); Log.v(TAG, "stopFaultTimer(): fault timer already running - cancelling it.");
mUtil.writeToSysLogFile("stopFaultTimer() - stopping fault timer");
mFaultTimer.cancel(); mFaultTimer.cancel();
mFaultTimer = null; mFaultTimer = null;
mFaultTimerCompleted = false; mFaultTimerCompleted = false;
} else { } else {
Log.v(TAG, "stopFaultTimer(): fault timer not running - not doing anything."); Log.v(TAG, "stopFaultTimer(): fault timer not running - not doing anything.");
//mUtil.writeToSysLogFile("stopFaultTimer() - fault timer not running");
} }
} }

View File

@@ -12,15 +12,15 @@
android:summary="Period between server data requests in miliseconds." android:summary="Period between server data requests in miliseconds."
android:title="Data Update Period (ms)" /> android:title="Data Update Period (ms)" />
<EditTextPreference <EditTextPreference
android:defaultValue="2000" android:defaultValue="5000"
android:key="ConnTimeout" android:key="ConnectTimeoutPeriod"
android:numeric="integer" android:numeric="integer"
android:summary="" android:summary=""
android:title="Connection Timeout (ms)" /> android:title="Connection Timeout Period (ms)" />
<EditTextPreference <EditTextPreference
android:defaultValue="2000" android:defaultValue="5000"
android:key="SoTimeout" android:key="ReadTimeoutPeriod"
android:numeric="integer" android:numeric="integer"
android:summary="" android:summary=""
android:title="So Timeout (ms)" /> android:title="Read Timeout Period (ms)" />
</PreferenceScreen> </PreferenceScreen>