2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-03 07:35:08 +00:00

Add a per-device confirmation before copying the contacts

The contacts plugin is the only one that copies (and persists) data to the
remote device just by connecting. By adding this extra confirmation once
per device, we prevent this from happening in cases where someone paired
with a friend to transfer a file, or paired by accident.
This commit is contained in:
Albert Vaca Cintora
2023-09-13 10:23:48 +02:00
parent 9fdb71096e
commit 14e61246ff
3 changed files with 38 additions and 1 deletions

View File

@@ -337,6 +337,8 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
<string name="telephony_permission_explanation">To see phone calls on the desktop you need to give permission to phone call logs and phone state</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="contacts_permission_explanation">To share your contacts book with the desktop, you need to give contacts permission</string>
<string name="contacts_per_device_confirmation">Your phone contacts will be copied over to this device, so they can be used by the KDE Connect SMS app and other apps.</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>

View File

@@ -13,6 +13,7 @@ import android.Manifest;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import org.kde.kdeconnect.Helpers.ContactsHelper;
import org.kde.kdeconnect.Helpers.ContactsHelper.ContactNotFoundException;
@@ -21,6 +22,7 @@ import org.kde.kdeconnect.Helpers.ContactsHelper.uID;
import org.kde.kdeconnect.NetworkPacket;
import org.kde.kdeconnect.Plugins.Plugin;
import org.kde.kdeconnect.Plugins.PluginFactory;
import org.kde.kdeconnect.UserInterface.AlertDialogFragment;
import org.kde.kdeconnect_tp.R;
import java.util.ArrayList;
@@ -109,6 +111,39 @@ public class ContactsPlugin extends Plugin {
// One day maybe we will also support WRITE_CONTACTS, but not yet
}
@Override
public boolean checkRequiredPermissions() {
if (!arePermissionsGranted(getRequiredPermissions())) {
return false;
}
return preferences.getBoolean("acceptedToTransferContacts", false);
}
@Override
public boolean supportsDeviceSpecificSettings() {
return true;
}
public @NonNull DialogFragment getPermissionExplanationDialog() {
if (!arePermissionsGranted(getRequiredPermissions())) {
return super.getPermissionExplanationDialog();
}
AlertDialogFragment dialog = new AlertDialogFragment.Builder()
.setTitle(getDisplayName())
.setMessage(R.string.contacts_per_device_confirmation)
.setPositiveButton(R.string.ok)
.setNegativeButton(R.string.cancel)
.create();
dialog.setCallback(new AlertDialogFragment.Callback() {
@Override
public void onPositiveButtonClicked() {
preferences.edit().putBoolean("acceptedToTransferContacts", true).apply();
device.reloadPluginsFromSettings();
}
});
return dialog;
}
/**
* Add custom fields to the vcard to keep track of KDE Connect-specific fields
* <p>

View File

@@ -265,7 +265,7 @@ public abstract class Plugin {
return (result == PackageManager.PERMISSION_GRANTED);
}
private boolean arePermissionsGranted(@NonNull String[] permissions) {
protected boolean arePermissionsGranted(@NonNull String[] permissions) {
for (String permission : permissions) {
if (!isPermissionGranted(permission)) {
return false;