mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-02 15:15:09 +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:
@@ -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_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="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="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>
|
</resources>
|
||||||
|
10
res/xml/telephonyplugin_preferences.xml
Normal file
10
res/xml/telephonyplugin_preferences.xml
Normal 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>
|
@@ -25,11 +25,14 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.telephony.PhoneNumberUtils;
|
||||||
import android.telephony.SmsMessage;
|
import android.telephony.SmsMessage;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -49,6 +52,7 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
|
|
||||||
private final static String PACKAGE_TYPE_TELEPHONY = "kdeconnect.telephony";
|
private final static String PACKAGE_TYPE_TELEPHONY = "kdeconnect.telephony";
|
||||||
public final static String PACKAGE_TYPE_TELEPHONY_REQUEST = "kdeconnect.telephony.request";
|
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 int lastState = TelephonyManager.CALL_STATE_IDLE;
|
||||||
private NetworkPackage lastPackage = null;
|
private NetworkPackage lastPackage = null;
|
||||||
@@ -114,6 +118,9 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
|
|
||||||
private void callBroadcastReceived(int state, String phoneNumber) {
|
private void callBroadcastReceived(int state, String phoneNumber) {
|
||||||
|
|
||||||
|
if (isNumberBlocked(phoneNumber))
|
||||||
|
return;
|
||||||
|
|
||||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY);
|
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY);
|
||||||
|
|
||||||
int permissionCheck = ContextCompat.checkSelfPermission(context,
|
int permissionCheck = ContextCompat.checkSelfPermission(context,
|
||||||
@@ -234,6 +241,9 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
|
|
||||||
String phoneNumber = messages.get(0).getOriginatingAddress();
|
String phoneNumber = messages.get(0).getOriginatingAddress();
|
||||||
|
|
||||||
|
if (isNumberBlocked(phoneNumber))
|
||||||
|
return;
|
||||||
|
|
||||||
int permissionCheck = ContextCompat.checkSelfPermission(context,
|
int permissionCheck = ContextCompat.checkSelfPermission(context,
|
||||||
Manifest.permission.READ_CONTACTS);
|
Manifest.permission.READ_CONTACTS);
|
||||||
|
|
||||||
@@ -289,6 +299,18 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
return true;
|
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
|
@Override
|
||||||
public String[] getSupportedPackageTypes() {
|
public String[] getSupportedPackageTypes() {
|
||||||
return new String[]{PACKAGE_TYPE_TELEPHONY_REQUEST};
|
return new String[]{PACKAGE_TYPE_TELEPHONY_REQUEST};
|
||||||
@@ -308,4 +330,9 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
public String[] getOptionalPermissions() {
|
public String[] getOptionalPermissions() {
|
||||||
return new String[]{Manifest.permission.READ_CONTACTS};
|
return new String[]{Manifest.permission.READ_CONTACTS};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasSettings() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user