Index: res/values/strings.xml =================================================================== --- res/values/strings.xml +++ res/values/strings.xml @@ -216,5 +216,7 @@ To read and write SMS from your desktop you need to give permission to SMS To see phone calls and SMS from the desktop you need to give permission to phone calls and SMS To see a contact name instead of a phone number you need to give access to the phone\'s contacts + Blocked numbers + Don\'t show calls and SMS from these numbers. Please specify one number per line Index: res/xml/telephonyplugin_preferences.xml =================================================================== --- /dev/null +++ res/xml/telephonyplugin_preferences.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file Index: src/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java =================================================================== --- src/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java +++ src/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java @@ -25,10 +25,12 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.media.AudioManager; import android.os.Build; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; import android.telephony.SmsMessage; import android.telephony.TelephonyManager; @@ -49,6 +51,7 @@ private final static String PACKAGE_TYPE_TELEPHONY = "kdeconnect.telephony"; public final static String PACKAGE_TYPE_TELEPHONY_REQUEST = "kdeconnect.telephony.request"; + private static final String KEY_PREF_BLOCKED_NUMBERS = "telephony_blocked_numbers"; private int lastState = TelephonyManager.CALL_STATE_IDLE; private NetworkPackage lastPackage = null; @@ -114,6 +117,9 @@ private void callBroadcastReceived(int state, String phoneNumber) { + if (isNumberBlocked(phoneNumber)) + return; + NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY); int permissionCheck = ContextCompat.checkSelfPermission(context, @@ -234,6 +240,9 @@ String phoneNumber = messages.get(0).getOriginatingAddress(); + if (isNumberBlocked(phoneNumber)) + return; + int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS); @@ -289,6 +298,18 @@ return true; } + private boolean isNumberBlocked(String number) { + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); + String[] blockedNumbers = sharedPref.getString(KEY_PREF_BLOCKED_NUMBERS, "").split("\n"); + + for (String s: blockedNumbers) { + if (number.equals(s)) + return true; + } + + return false; + } + @Override public String[] getSupportedPackageTypes() { return new String[]{PACKAGE_TYPE_TELEPHONY_REQUEST}; @@ -308,4 +329,9 @@ public String[] getOptionalPermissions() { return new String[]{Manifest.permission.READ_CONTACTS}; } + + @Override + public boolean hasSettings() { + return true; + } }