parse allowed phone numbers
This commit is contained in:
parent
82f4c8ffac
commit
80a463a56d
1 changed files with 31 additions and 4 deletions
|
@ -16,12 +16,14 @@ import java.text.Normalizer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.Services.Intents;
|
import info.nightscout.androidaps.Services.Intents;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
|
||||||
|
@ -41,6 +43,8 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
|
|
||||||
final long CONFIRM_TIMEOUT = 5 * 60 * 1000L;
|
final long CONFIRM_TIMEOUT = 5 * 60 * 1000L;
|
||||||
|
|
||||||
|
List<String> allowedNumbers = new ArrayList<String>();
|
||||||
|
|
||||||
public class Sms {
|
public class Sms {
|
||||||
String phoneNumber;
|
String phoneNumber;
|
||||||
String text;
|
String text;
|
||||||
|
@ -81,6 +85,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
|
|
||||||
public SmsCommunicatorPlugin() {
|
public SmsCommunicatorPlugin() {
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
|
processSettings(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,6 +128,29 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
SmsCommunicatorPlugin.fragmentVisible = fragmentVisible;
|
SmsCommunicatorPlugin.fragmentVisible = fragmentVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void processSettings(final EventPreferenceChange ev) {
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||||
|
String settings = sharedPreferences.getString("smscommunicator_allowednumbers", "");
|
||||||
|
|
||||||
|
String pattern = ";";
|
||||||
|
|
||||||
|
String[] substrings = settings.split(pattern);
|
||||||
|
for (String number: substrings)
|
||||||
|
{
|
||||||
|
String cleaned = number.replaceAll("\\s+","");
|
||||||
|
allowedNumbers.add(cleaned);
|
||||||
|
log.debug("Found allowed number: " + cleaned);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isAllowedNumber(String number) {
|
||||||
|
for (String num: allowedNumbers) {
|
||||||
|
if (num.equals(number)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventNewSMS ev) {
|
public void onStatusEvent(final EventNewSMS ev) {
|
||||||
|
|
||||||
|
@ -135,14 +163,13 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processSms(Sms receivedSms) {
|
private void processSms(Sms receivedSms) {
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||||
|
|
||||||
if (!isEnabled(PluginBase.GENERAL)) {
|
if (!isEnabled(PluginBase.GENERAL)) {
|
||||||
log.debug("Ignoring SMS. Plugin disabled.");
|
log.debug("Ignoring SMS. Plugin disabled.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
if (!isAllowedNumber(receivedSms.phoneNumber)) {
|
||||||
String allowedNumbers = sharedPreferences.getString("smscommunicator_allowednumbers", "");
|
|
||||||
|
|
||||||
if (!allowedNumbers.contains(receivedSms.phoneNumber)) {
|
|
||||||
log.debug("Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed");
|
log.debug("Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue