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 DATALOG = "DataLog";
|
||||||
|
|
||||||
private final String[] REQUIRED_PERMISSIONS = {
|
private final String[] REQUIRED_PERMISSIONS = {
|
||||||
Manifest.permission.SEND_SMS,
|
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||||
//Manifest.permission.SYSTEM_ALERT_WINDOW,
|
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION,
|
|
||||||
Manifest.permission.WAKE_LOCK,
|
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
|
* 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 mLogSystem = true;
|
||||||
private boolean mLogData = true;
|
private boolean mLogData = true;
|
||||||
private boolean mPermissionsRequested = false;
|
private boolean mPermissionsRequested = false;
|
||||||
|
private boolean mSMSPermissionsRequested = false;
|
||||||
|
|
||||||
private static int mNbound = 0;
|
private static int mNbound = 0;
|
||||||
|
|
||||||
@@ -442,6 +446,21 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac
|
|||||||
return allOk;
|
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) {
|
public void requestPermissions(Activity activity) {
|
||||||
if (mPermissionsRequested) {
|
if (mPermissionsRequested) {
|
||||||
Log.i(TAG,"requestPermissions() - request already sent - not doing anything");
|
Log.i(TAG,"requestPermissions() - request already sent - not doing anything");
|
||||||
@@ -458,10 +477,27 @@ public class OsdUtil implements ActivityCompat.OnRequestPermissionsResultCallbac
|
|||||||
42);
|
42);
|
||||||
mPermissionsRequested = true;
|
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
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode,
|
public void onRequestPermissionsResult(int requestCode,
|
||||||
String permissions[], int[] grantResults) {
|
String permissions[], int[] grantResults) {
|
||||||
|
|||||||
@@ -117,6 +117,19 @@ public class PrefActivity extends PreferenceActivity implements SharedPreference
|
|||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
|
||||||
Log.i(TAG, "SharedPreference " + s + " Changed.");
|
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");
|
mUtil.showToast("Setting " + s + " Changed - restarting server");
|
||||||
mPrefChanged = true;
|
mPrefChanged = true;
|
||||||
mUtil.stopServer();
|
mUtil.stopServer();
|
||||||
|
|||||||
@@ -401,13 +401,18 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
|
|||||||
PendingIntent contentIntent =
|
PendingIntent contentIntent =
|
||||||
PendingIntent.getActivity(this,
|
PendingIntent.getActivity(this,
|
||||||
0, i, PendingIntent.FLAG_UPDATE_CURRENT);
|
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)
|
mNotification = mNotificationBuilder.setContentIntent(contentIntent)
|
||||||
.setSmallIcon(iconId)
|
.setSmallIcon(iconId)
|
||||||
.setColor(0xff000000)
|
.setColor(0x00ffffff)
|
||||||
.setTicker("OpenSeizureDetector")
|
|
||||||
.setAutoCancel(false)
|
.setAutoCancel(false)
|
||||||
.setContentTitle("OpenSeizureDetector")
|
.setContentTitle("OpenSeizureDetector:"+mSdDataSourceName + " Data Source")
|
||||||
.setContentText(mSdDataSourceName + " Data Source")
|
.setContentText(smsStr)
|
||||||
.setOnlyAlertOnce(true)
|
.setOnlyAlertOnce(true)
|
||||||
.build();
|
.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
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="SMSAlarm"
|
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" />
|
android:title="Enable SMS Alarm" />
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue=""
|
android:defaultValue=""
|
||||||
|
|||||||
Reference in New Issue
Block a user