diff --git a/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java b/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java index 36f3a69..239d3de 100644 --- a/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java +++ b/app/src/main/java/uk/org/openseizuredetector/OsdUtil.java @@ -89,13 +89,16 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac private final String DATALOG = "DataLog"; private final String[] REQUIRED_PERMISSIONS = { - Manifest.permission.SEND_SMS, Manifest.permission.WRITE_EXTERNAL_STORAGE, - //Manifest.permission.SYSTEM_ALERT_WINDOW, - Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WAKE_LOCK, }; + private final String[] SMS_PERMISSIONS = { + Manifest.permission.SEND_SMS, + Manifest.permission.ACCESS_FINE_LOCATION, + }; + + /** * Based on http://stackoverflow.com/questions/7440473/android-how-to-check-if-the-intent-service-is-still-running-or-has-stopped-running */ @@ -106,6 +109,7 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac private boolean mLogSystem = true; private boolean mLogData = true; private boolean mPermissionsRequested = false; + private boolean mSMSPermissionsRequested = false; private static int mNbound = 0; @@ -442,6 +446,21 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac return allOk; } + public boolean areSMSPermissionsOK() { + boolean allOk = true; + Log.v(TAG,"areSMSPermissionsOK()"); + for (int i = 0; i< SMS_PERMISSIONS.length; i++) { + if (ContextCompat.checkSelfPermission(mContext, SMS_PERMISSIONS[i]) + != PackageManager.PERMISSION_GRANTED) { + Log.i(TAG, SMS_PERMISSIONS[i] + " Permission Not Granted"); + allOk = false; + } + } + return allOk; + } + + + public void requestPermissions(Activity activity) { if (mPermissionsRequested) { Log.i(TAG,"requestPermissions() - request already sent - not doing anything"); @@ -458,10 +477,27 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac 42); mPermissionsRequested = true; } - - } + public void requestSMSPermissions(Activity activity) { + if (mSMSPermissionsRequested) { + Log.i(TAG,"requestSMSPermissions() - request already sent - not doing anything"); + } else { + Log.i(TAG, "requestSMSPermissions() - requesting permissions"); + for (int i = 0; i < SMS_PERMISSIONS.length; i++) { + if (ActivityCompat.shouldShowRequestPermissionRationale(activity, + SMS_PERMISSIONS[i])) { + Log.i(TAG, "shouldShowRationale for permission" + SMS_PERMISSIONS[i]); + } + } + ActivityCompat.requestPermissions(activity, + SMS_PERMISSIONS, + 43); + mSMSPermissionsRequested = true; + } + } + + @Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { diff --git a/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java b/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java index 430161c..63d8a37 100644 --- a/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/PrefActivity.java @@ -117,6 +117,19 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { Log.i(TAG, "SharedPreference " + s + " Changed."); + + if (s.equals("SMSAlarm")) { + if (sharedPreferences.getBoolean("SMSAlarm",false)==true) { + if (mUtil.areSMSPermissionsOK()==false) { + Log.i(TAG,"onSharedPreferenceChanged(): SMS Alarm Enabled - Requesting Permissions"); + mUtil.requestSMSPermissions(this); + } else { + Log.i(TAG,"OnSharedPreferenceCHanged(): SMS Permissions already granted, doing nothing"); + } + } else { + Log.i(TAG,"OnSharedPreferenceChanged(): SMS Alarm disabled so do not need permissions"); + } + } mUtil.showToast("Setting " + s + " Changed - restarting server"); mPrefChanged = true; mUtil.stopServer(); diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index 7b86cb6..0af2976 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -401,13 +401,18 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); + String smsStr; + if (mSMSAlarm) { + smsStr = "WARNING: SMS Location Alarm Active"; + } else { + smsStr = "SMS Location Alarm Disabled"; + } mNotification = mNotificationBuilder.setContentIntent(contentIntent) .setSmallIcon(iconId) - .setColor(0xff000000) - .setTicker("OpenSeizureDetector") + .setColor(0x00ffffff) .setAutoCancel(false) - .setContentTitle("OpenSeizureDetector") - .setContentText(mSdDataSourceName + " Data Source") + .setContentTitle("OpenSeizureDetector:"+mSdDataSourceName + " Data Source") + .setContentText(smsStr) .setOnlyAlertOnce(true) .build(); diff --git a/app/src/main/res/drawable/star_of_life_24x24.png b/app/src/main/res/drawable/star_of_life_24x24.png index 1fef3d8..a46afb6 100644 Binary files a/app/src/main/res/drawable/star_of_life_24x24.png and b/app/src/main/res/drawable/star_of_life_24x24.png differ diff --git a/app/src/main/res/drawable/star_of_life_red_24x24.png b/app/src/main/res/drawable/star_of_life_red_24x24.png index 22175c7..2ac6605 100644 Binary files a/app/src/main/res/drawable/star_of_life_red_24x24.png and b/app/src/main/res/drawable/star_of_life_red_24x24.png differ diff --git a/app/src/main/res/drawable/star_of_life_yellow_24x24.png b/app/src/main/res/drawable/star_of_life_yellow_24x24.png index 2e8fcf2..795ec68 100644 Binary files a/app/src/main/res/drawable/star_of_life_yellow_24x24.png and b/app/src/main/res/drawable/star_of_life_yellow_24x24.png differ diff --git a/app/src/main/res/xml/alarm_prefs.xml b/app/src/main/res/xml/alarm_prefs.xml index 348934c..9c15c30 100644 --- a/app/src/main/res/xml/alarm_prefs.xml +++ b/app/src/main/res/xml/alarm_prefs.xml @@ -48,7 +48,7 @@