2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 06:05:12 +00:00

Allow to blacklist numbers in the telephony plugin

Summary:
Depends on D10519

Allow to specify a newline separated list of blocked numbers. This can be useful for 2FA/TAN that could be leaked to the desktop.

The protection is incomplete because the notification might be leaked trough the notificationsplugin anyway (T6651).

Test Plan:
Block my number, send SMS to self -> only notification from Notificationsplugin is shown.
Unblock it again -> both notifications are shown

Reviewers: #kde_connect, albertvaka, mtijink

Reviewed By: #kde_connect, albertvaka, mtijink

Subscribers: mtijink, albertvaka, #kde_connect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D10520
This commit is contained in:
Nicolas Fella
2018-02-24 15:49:39 +01:00
parent 101918f323
commit e9a35d3bb2
3 changed files with 39 additions and 0 deletions

View File

@@ -217,5 +217,7 @@
<string name="telephony_permission_explanation">To see phone calls and SMS from the desktop you need to give permission to phone calls and SMS</string>
<string name="telephony_optional_permission_explanation">To see a contact name instead of a phone number you need to give access to the phone\'s contacts</string>
<string name="select_ringtone">Select a ringtone</string>
<string name="telephony_pref_blocked_title">Blocked numbers</string>
<string name="telephony_pref_blocked_dialog_desc">Don\'t show calls and SMS from these numbers. Please specify one number per line</string>
</resources>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="telephony_blocked_numbers"
android:title="@string/telephony_pref_blocked_title"
android:dialogMessage="@string/telephony_pref_blocked_dialog_desc">
</EditTextPreference>
</PreferenceScreen>

View File

@@ -25,11 +25,14 @@ import android.content.BroadcastReceiver;
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.PhoneNumberUtils;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -49,6 +52,7 @@ public class TelephonyPlugin extends Plugin {
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 +118,9 @@ public class TelephonyPlugin extends Plugin {
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 +241,9 @@ public class TelephonyPlugin extends Plugin {
String phoneNumber = messages.get(0).getOriginatingAddress();
if (isNumberBlocked(phoneNumber))
return;
int permissionCheck = ContextCompat.checkSelfPermission(context,
Manifest.permission.READ_CONTACTS);
@@ -289,6 +299,18 @@ public class TelephonyPlugin extends Plugin {
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 (PhoneNumberUtils.compare(number, s))
return true;
}
return false;
}
@Override
public String[] getSupportedPackageTypes() {
return new String[]{PACKAGE_TYPE_TELEPHONY_REQUEST};
@@ -308,4 +330,9 @@ public class TelephonyPlugin extends Plugin {
public String[] getOptionalPermissions() {
return new String[]{Manifest.permission.READ_CONTACTS};
}
@Override
public boolean hasSettings() {
return true;
}
}