Updated system so it will run without SMS permissions granted. Changed notification to warn the user if SMS alarms are enabled. Fixed notification icon background.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 210 B After Width: | Height: | Size: 241 B |
Binary file not shown.
|
Before Width: | Height: | Size: 221 B After Width: | Height: | Size: 232 B |
Binary file not shown.
|
Before Width: | Height: | Size: 231 B After Width: | Height: | Size: 252 B |
@@ -48,7 +48,7 @@
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="SMSAlarm"
|
||||
android:summary="Issue a SMS (Text Message) alarm if the seizure detector enters an alarm condition."
|
||||
android:summary="Issue a SMS (Text Message) alarm if the seizure detector enters an alarm condition. NOTE: THE MESSAGE WILL INCLUDE THE USER's LOCATION. Disable this option if sharing your location is a concern."
|
||||
android:title="Enable SMS Alarm" />
|
||||
<EditTextPreference
|
||||
android:defaultValue=""
|
||||
|
||||
Reference in New Issue
Block a user