diff --git a/CHANGELOG.md b/CHANGELOG.md index 4da1019..97fc68d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ OpenSeizureDetector Android App - Change Log ============================================ - V3.0.1 - 21feb201 + V3.0.2 - 27feb2019 + - Corrected issue with app not re-starting properly when run-time permissions changed + (e.g. send_sms permission) + - Fixed crash when using MP3 alarms (issue with new android notification system) + V3.0.1 - 21feb2019 - Simplified data log output to CSV format for easier processing, and had it log every update rather than one point per minute. V3.0.0 - 15feb2019 diff --git a/app/release/app-release-3.0.2.apk b/app/release/app-release-3.0.2.apk new file mode 100644 index 0000000..f54be88 Binary files /dev/null and b/app/release/app-release-3.0.2.apk differ diff --git a/app/release/output.json b/app/release/output.json index d0af5c2..378d536 100644 --- a/app/release/output.json +++ b/app/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":50,"versionName":"3.0.1","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":51,"versionName":"3.0.2","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index dc68e49..23e36ee 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ diff --git a/app/src/main/java/uk/org/openseizuredetector/LocationFinder.java b/app/src/main/java/uk/org/openseizuredetector/LocationFinder.java index 8dda2b9..5bdce75 100644 --- a/app/src/main/java/uk/org/openseizuredetector/LocationFinder.java +++ b/app/src/main/java/uk/org/openseizuredetector/LocationFinder.java @@ -9,6 +9,7 @@ import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; +import android.os.Looper; import android.util.Log; import java.util.Timer; @@ -49,9 +50,18 @@ public class LocationFinder implements LocationListener // Acquire a reference to the system Location Manager mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); // Register with the Location Manager to receive location updates using both network and GPS - mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); - mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); + try { + mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, + 0, 0, this, Looper.getMainLooper()); + mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, + 0, 0, this, Looper.getMainLooper()); + } catch (SecurityException e) { + Log.e(TAG, "LocationFinder - Failed to get Location - Security Exception"); + mUtil.writeToSysLogFile("LocationFinder - Failed to get Location - Security Exception"); + Log.e(TAG, e.toString()); + mUtil.showToast("Failed to get Location for SMS Message - Permissions Denied?"); + } mTimeoutTimer = new Timer(); mTimeoutTimer.schedule(new TimerTask() { @Override diff --git a/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java b/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java index 239d3de..84a7ba1 100644 --- a/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java +++ b/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java @@ -501,6 +501,15 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { - Log.i(TAG,"onequestPermissionsResult - Permission" + permissions + " = " + grantResults); + Log.i(TAG,"onRequestPermissionsResult - Permission" + permissions + " = " + grantResults); + showToast("Permissions Changed - restarting server"); + stopServer(); + // Wait 0.1 second to give the server chance to shutdown, then re-start it + mHandler.postDelayed(new Runnable() { + public void run() { + startServer(); + } + }, 100); + } } diff --git a/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java b/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java index d338d0a..3f50d5a 100644 --- a/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java @@ -148,6 +148,20 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference } + @Override + public void onRequestPermissionsResult(int requestCode, + String permissions[], int[] grantResults) { + Log.i(TAG,"onRequestPermissionsResult - Permission" + permissions + " = " + grantResults); + mUtil.showToast("Permissions Changed - restarting server"); + 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); + + } @Override public void onResume() { diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index d7948ad..e5034e2 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -386,27 +386,42 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei Log.v(TAG, "showNotification() - alarmLevel="+alarmLevel); int iconId; String titleStr; + Uri soundUri = null; switch (alarmLevel) { case 0: iconId = R.drawable.star_of_life_24x24; titleStr = "OK"; + soundUri = null; break; case 1: iconId = R.drawable.star_of_life_yellow_24x24; titleStr = "WARNING"; + if (mAudibleWarning) + soundUri = Uri.parse("android.resource://" + getPackageName() + "/raw/warning"); break; case 2: iconId = R.drawable.star_of_life_red_24x24; titleStr = "ALARM"; + if (mAudibleAlarm) + soundUri = Uri.parse("android.resource://" + getPackageName() + "/raw/alarm"); break; case -1: iconId = R.drawable.star_of_life_fault_24x24; titleStr = "FAULT"; + if (mAudibleFaultWarning) + soundUri = Uri.parse("android.resource://" + getPackageName() + "/raw/fault"); break; default: iconId = R.drawable.star_of_life_24x24; + soundUri = null; titleStr = "OK"; } + + if (mCancelAudible) { + Log.v(TAG,"ShowNotification - Not beeping because mCancelAudible set"); + soundUri = null; + } + Intent i = new Intent(getApplicationContext(), MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); PendingIntent contentIntent = @@ -427,7 +442,12 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei .setContentText(smsStr) .setOnlyAlertOnce(true) .build(); - + if (mMp3Alarm) { + if (soundUri != null) { + Log.v(TAG, "showNotification - setting Notification Sound to "+soundUri.toString()); + mNotificationBuilder.setSound(soundUri); + } + } mNM.notify(NOTIFICATION_ID, mNotification); } else { Log.i(TAG, "showNotification() - notification builder is null, so not showing notification."); @@ -638,16 +658,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei } else { if (mAudibleFaultWarning) { if (mMp3Alarm) { - Log.v(TAG, "making MP3 alarm beep"); - // 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. - NotificationManager notificationManager = - (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/raw/fault"); - NotificationCompat.Builder mBuilder = - new NotificationCompat.Builder(getApplicationContext()) - .setSound(soundUri); //This sets the sound to play - notificationManager.notify(0, mBuilder.build()); + Log.v(TAG, "Not making MP3 fault beep - handled by notification"); } else { beep(10); } @@ -675,16 +686,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei } else { if (mAudibleAlarm) { if (mMp3Alarm) { - Log.v(TAG, "making MP3 alarm beep"); - // 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. - NotificationManager notificationManager = - (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/raw/alarm"); - NotificationCompat.Builder mBuilder = - new NotificationCompat.Builder(getApplicationContext()) - .setSound(soundUri); //This sets the sound to play - notificationManager.notify(0, mBuilder.build()); + Log.v(TAG, "Not making MP3 alarm beep - handled by ShowNotification"); } else { beep(3000); } @@ -705,16 +707,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei } else { if (mAudibleWarning) { if (mMp3Alarm) { - Log.v(TAG, "making MP3 alarm beep"); - // 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. - NotificationManager notificationManager = - (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/raw/warning"); - NotificationCompat.Builder mBuilder = - new NotificationCompat.Builder(getApplicationContext()) - .setSound(soundUri); //This sets the sound to play - notificationManager.notify(0, mBuilder.build()); + Log.v(TAG, "not making MP3 alarm beep - handled by showNotification"); } else { beep(100); }