Skip to content

Commit

Permalink
#298 New setting for suppressing irrelevant SMS (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
frimtec authored Feb 9, 2022
1 parent 4003147 commit 831a34d
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 3 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ If the warning system of your operations center does not support confirmation me

#### Confirmation reply
Defines the text to send back as alarm acknowledgement to your operations center.


#### SMS ignore filter
[Regular expression](https://en.wikipedia.org/wiki/Regular_expression) pattern to identify SMS messages
to be ignored.
If empty, SMS filtering is disabled.
_WARNING_: Be careful, if the pattern is not well designed and triggers for a real alarm, you won't be alerted!

#### Alarm ringtone
Defines the ringtone that is used to alert for on-call alarms.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,28 @@ public void onReceive(Context context, Intent intent) {
ApplicationPreferences.instance().setSuperviseTestContexts(context, supervisedTestAlarmContexts);
}
} else {
Log.i(TAG, "New alert");
new AlertService(context).newAlert(sms);
if(isMetaSms(context, sms)) {
Toast.makeText(context, context.getString(R.string.sms_listener_meta_sms_filtered), Toast.LENGTH_LONG).show();
Log.i(TAG, "New meta SMS filtered: " + sms);
} else {
Log.i(TAG, "New alert");
new AlertService(context).newAlert(sms);
}
}
}
}
context.sendBroadcast(new Intent(Action.REFRESH.getId()));
}
}

private boolean isMetaSms(Context context, Sms sms) {
String metaSmsMessagePattern = ApplicationPreferences.instance().getMetaSmsMessagePattern(context);
if(metaSmsMessagePattern.isEmpty()) {
return false;
}
Pattern pattern = Pattern.compile(metaSmsMessagePattern, Pattern.DOTALL);
Matcher matcher = pattern.matcher(sms.getText());
return matcher.matches();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ static ApplicationPreferences instance() {

String getSmsTestMessagePattern(Context context);

String getMetaSmsMessagePattern(Context context);

boolean getSendConfirmSms(Context context);

String getSmsConfirmText(Context context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class SharedPreferencesApplicationPreferences implements ApplicationPrefer
private static final String PREF_KEY_PRE_POST_RUN_TIME_SECONDS = "pre_post_run_time_seconds";
private static final String PREF_KEY_ALARM_OPERATIONS_CENTER_CONTACT = "alarm_operations_center_contact";
private static final String PREF_KEY_TEST_ALARM_MESSAGE_PATTERN = "test_alarm_message_pattern";
private static final String PREF_KEY_META_SMS_MESSAGE_PATTERN = "meta_sms_message_pattern";
private static final String PREF_KEY_TEST_ALARM_CHECK_TIME = "test_alarm_check_time";
private static final String PREF_KEY_TEST_ALARM_CHECK_WEEKDAYS = "test_alarm_check_weekdays";
private static final String PREF_KEY_TEST_ALARM_ENABLED = "test_alarm_enabled";
Expand Down Expand Up @@ -92,6 +93,11 @@ public String getSmsTestMessagePattern(Context context) {
return getSharedPreferences(context, PREF_KEY_TEST_ALARM_MESSAGE_PATTERN, context.getString(R.string.pref_default_test_alarm_message_pattern)).trim();
}

@Override
public String getMetaSmsMessagePattern(Context context) {
return getSharedPreferences(context, PREF_KEY_META_SMS_MESSAGE_PATTERN, "").trim();
}

@Override
public boolean getSendConfirmSms(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_baseline_filter_alt_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M4.25,5.61C6.27,8.2 10,13 10,13v6c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-6c0,0 3.72,-4.8 5.74,-7.39C20.25,4.95 19.78,4 18.95,4H5.04C4.21,4 3.74,4.95 4.25,5.61z"/>
</vector>
3 changes: 3 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<string name="pref_default_calendar_event_pikett_title_pattern">.*Pikett.*</string>
<string name="pref_title_pre_post_time_seconds">Vor-/Nachlaufzeit</string>
<string name="pref_default_pre_post_run_time_seconds">300</string>
<string name="pref_title_meta_sms_message_pattern">SMS Ignorierfilter</string>
<string name="pref_meta_sms_message_pattern">Gültige RegExp eingeben die komplette SMS erkennt die zu ignorieren sind</string>

<string name="pref_title_supervise_battery_level">Akkufüllstand überwachen</string>
<string name="pref_title_battery_warn_level">Minimaler Füllstand</string>
Expand Down Expand Up @@ -183,6 +185,7 @@
<string name="state_fragment_phone_numbers_blocked">Nummer blockiert</string>
<string name="state_fragment_loopback_sms_sent">Test-SMS gesendet…</string>
<string name="sms_listener_loopback_sms_received">Test-SMS empfangen!</string>
<string name="sms_listener_meta_sms_filtered">SMS empfangen und gefiltert!</string>
<string name="state_fragment_s2msp_requires_update">Benötigt Update</string>

<string name="permission_sms_title">SMS-Adapter Installation</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<string name="pref_default_partner_search_pattern" translatable="false">Deputy:\\s([a-z,0-9]{5})(\\s|$)</string>
<string name="pref_title_pre_post_time_seconds">Pre-/post-run time</string>
<string name="pref_default_pre_post_run_time_seconds">300</string>
<string name="pref_title_meta_sms_message_pattern">SMS ignore filter</string>
<string name="pref_meta_sms_message_pattern">Enter a valid regexp that fully matches SMS to be ignored</string>

<string name="pref_title_supervise_battery_level">Supervise battery level</string>
<string name="pref_title_battery_warn_level">Minimal battery level</string>
Expand Down Expand Up @@ -187,6 +189,7 @@
<string name="state_fragment_phone_numbers_blocked">Number blocked</string>
<string name="state_fragment_loopback_sms_sent">Test-SMS sent…</string>
<string name="sms_listener_loopback_sms_received">Test-SMS received!</string>
<string name="sms_listener_meta_sms_filtered">SMS received and filtered!</string>
<string name="state_fragment_s2msp_requires_update">Requires update</string>

<string name="permission_sms_title">SMS adapter installation</string>
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
app:title="@string/pref_title_sms_confirm_text"
app:useSimpleSummaryProvider="true" />

<com.github.frimtec.android.pikettassist.ui.settings.RegExpTextPreference
app:defaultValue=""
app:icon="@drawable/ic_baseline_filter_alt_24"
app:key="meta_sms_message_pattern"
app:singleLine="true"
app:singleLineTitle="false"
app:title="@string/pref_title_meta_sms_message_pattern"
app:dialogMessage="@string/pref_meta_sms_message_pattern"
app:useSimpleSummaryProvider="true"
/>

<RingtonePreference
android:dialogTitle="@string/pref_title_alarm_ring_tone"
android:icon="@drawable/ic_notifications_black_24dp"
Expand Down
1 change: 1 addition & 0 deletions google-play/whatsnew/whatsnew-de-DE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Funktionen und Verbesserungen:
* Neue Einstellung für das Unterdrücken von irrelevanten SMS
* Abhängigkeiten aktualisiert
1 change: 1 addition & 0 deletions google-play/whatsnew/whatsnew-en-US
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Features and improvements:
* New setting for suppressing irrelevant SMS
* Update dependencies

0 comments on commit 831a34d

Please sign in to comment.