Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
/*
|
|
|
|
* ContactsPlugin.java - This file is part of KDE Connect's Android App
|
|
|
|
* Implement a way to request and send contact information
|
|
|
|
*
|
2020-08-17 16:17:20 +02:00
|
|
|
* SPDX-FileCopyrightText: 2018 Simon Redman <simon@ergotech.com>
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
*
|
2020-08-17 16:17:20 +02:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2018-09-29 20:28:47 +02:00
|
|
|
*/
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
|
|
|
|
package org.kde.kdeconnect.Plugins.ContactsPlugin;
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import org.kde.kdeconnect.Helpers.ContactsHelper;
|
2023-03-05 22:03:58 +01:00
|
|
|
import org.kde.kdeconnect.Helpers.ContactsHelper.ContactNotFoundException;
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
import org.kde.kdeconnect.Helpers.ContactsHelper.VCardBuilder;
|
|
|
|
import org.kde.kdeconnect.Helpers.ContactsHelper.uID;
|
|
|
|
import org.kde.kdeconnect.NetworkPacket;
|
|
|
|
import org.kde.kdeconnect.Plugins.Plugin;
|
2019-02-11 20:04:40 +01:00
|
|
|
import org.kde.kdeconnect.Plugins.PluginFactory;
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
import org.kde.kdeconnect_tp.R;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2019-02-11 20:04:40 +01:00
|
|
|
@PluginFactory.LoadablePlugin
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
public class ContactsPlugin extends Plugin {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to request the device send the unique ID of every contact
|
|
|
|
*/
|
2018-09-29 20:28:47 +02:00
|
|
|
private static final String PACKET_TYPE_CONTACTS_REQUEST_ALL_UIDS_TIMESTAMPS = "kdeconnect.contacts.request_all_uids_timestamps";
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to request the names for the contacts corresponding to a list of UIDs
|
|
|
|
* <p>
|
|
|
|
* It shall contain the key "uids", which will have a list of uIDs (long int, as string)
|
|
|
|
*/
|
2018-09-29 20:28:47 +02:00
|
|
|
private static final String PACKET_TYPE_CONTACTS_REQUEST_VCARDS_BY_UIDS = "kdeconnect.contacts.request_vcards_by_uid";
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Response indicating the packet contains a list of contact uIDs
|
|
|
|
* <p>
|
|
|
|
* It shall contain the key "uids", which will mark a list of uIDs (long int, as string)
|
|
|
|
* The returned IDs can be used in future requests for more information about the contact
|
|
|
|
*/
|
2018-09-29 20:28:47 +02:00
|
|
|
private static final String PACKET_TYPE_CONTACTS_RESPONSE_UIDS_TIMESTAMPS = "kdeconnect.contacts.response_uids_timestamps";
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Response indicating the packet contains a list of contact names
|
|
|
|
* <p>
|
|
|
|
* It shall contain the key "uids", which will mark a list of uIDs (long int, as string)
|
|
|
|
* then, for each UID, there shall be a field with the key of that UID and the value of the name of the contact
|
|
|
|
* <p>
|
|
|
|
* For example:
|
2018-11-01 12:51:57 -06:00
|
|
|
* { 'uids' : ['1', '3', '15'],
|
|
|
|
* '1' : 'John Smith',
|
|
|
|
* '3' : 'Abe Lincoln',
|
|
|
|
* '15' : 'Mom'
|
|
|
|
* }
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
*/
|
2018-09-29 20:28:47 +02:00
|
|
|
private static final String PACKET_TYPE_CONTACTS_RESPONSE_VCARDS = "kdeconnect.contacts.response_vcards";
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDisplayName() {
|
|
|
|
return context.getResources().getString(R.string.pref_plugin_contacts);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDescription() {
|
|
|
|
return context.getResources().getString(R.string.pref_plugin_contacts_desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String[] getSupportedPacketTypes() {
|
|
|
|
return new String[]{
|
|
|
|
PACKET_TYPE_CONTACTS_REQUEST_ALL_UIDS_TIMESTAMPS,
|
|
|
|
PACKET_TYPE_CONTACTS_REQUEST_VCARDS_BY_UIDS
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String[] getOutgoingPacketTypes() {
|
|
|
|
return new String[]{
|
|
|
|
PACKET_TYPE_CONTACTS_RESPONSE_UIDS_TIMESTAMPS,
|
|
|
|
PACKET_TYPE_CONTACTS_RESPONSE_VCARDS
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreate() {
|
|
|
|
permissionExplanation = R.string.contacts_permission_explanation;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabledByDefault() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String[] getRequiredPermissions() {
|
|
|
|
return new String[]{Manifest.permission.READ_CONTACTS};
|
|
|
|
// One day maybe we will also support WRITE_CONTACTS, but not yet
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add custom fields to the vcard to keep track of KDE Connect-specific fields
|
|
|
|
* <p>
|
|
|
|
* These include the local device's uID as well as last-changed timestamp
|
|
|
|
* <p>
|
|
|
|
* This might be extended in the future to include more fields
|
|
|
|
*
|
|
|
|
* @param vcard vcard to apply metadata to
|
|
|
|
* @param uID uID to which the vcard corresponds
|
2019-10-27 21:23:52 +00:00
|
|
|
* @throws ContactNotFoundException If the given ID for some reason does not match a contact
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
* @return The same VCard as was passed in, but now with KDE Connect-specific fields
|
|
|
|
*/
|
2019-10-27 21:23:52 +00:00
|
|
|
private VCardBuilder addVCardMetadata(VCardBuilder vcard, uID uID) throws ContactNotFoundException {
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
// Append the device ID line
|
|
|
|
// Unclear if the deviceID forms a valid name per the vcard spec. Worry about that later..
|
|
|
|
vcard.appendLine("X-KDECONNECT-ID-DEV-" + device.getDeviceId(),
|
|
|
|
uID.toString());
|
|
|
|
|
|
|
|
// Build the timestamp line
|
|
|
|
// Maybe one day this should be changed into the vcard-standard REV key
|
2019-10-27 21:23:52 +00:00
|
|
|
Long timestamp = ContactsHelper.getContactTimestamp(context, uID);
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
vcard.appendLine("X-KDECONNECT-TIMESTAMP",
|
2019-10-27 21:23:52 +00:00
|
|
|
timestamp.toString());
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
|
|
|
|
return vcard;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a unique identifier (Contacts.LOOKUP_KEY) for all contacts in the Contacts database
|
|
|
|
* <p>
|
|
|
|
* The identifiers returned can be used in future requests to get more information
|
|
|
|
* about the contact
|
|
|
|
*
|
|
|
|
* @param np The package containing the request
|
|
|
|
* @return true if successfully handled, false otherwise
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("SameReturnValue")
|
2018-10-26 23:53:58 +02:00
|
|
|
private boolean handleRequestAllUIDsTimestamps(@SuppressWarnings("unused") NetworkPacket np) {
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
NetworkPacket reply = new NetworkPacket(PACKET_TYPE_CONTACTS_RESPONSE_UIDS_TIMESTAMPS);
|
|
|
|
|
2019-10-27 21:23:52 +00:00
|
|
|
Map<uID, Long> uIDsToTimestamps = ContactsHelper.getAllContactTimestamps(context);
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
|
2019-10-27 21:23:52 +00:00
|
|
|
int contactCount = uIDsToTimestamps.size();
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
|
2019-10-27 21:23:52 +00:00
|
|
|
List<String> uIDs = new ArrayList<>(contactCount);
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
|
2019-10-27 21:23:52 +00:00
|
|
|
for (uID contactID : uIDsToTimestamps.keySet()) {
|
|
|
|
Long timestamp = uIDsToTimestamps.get(contactID);
|
|
|
|
reply.set(contactID.toString(), timestamp);
|
|
|
|
uIDs.add(contactID.toString());
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
}
|
|
|
|
|
2019-10-27 21:23:52 +00:00
|
|
|
reply.set("uids", uIDs);
|
|
|
|
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
device.sendPacket(reply);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-26 23:53:58 +02:00
|
|
|
private boolean handleRequestVCardsByUIDs(NetworkPacket np) {
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
if (!np.has("uids")) {
|
|
|
|
Log.e("ContactsPlugin", "handleRequestNamesByUIDs received a malformed packet with no uids key");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> uIDsAsStrings = np.getStringList("uids");
|
|
|
|
|
|
|
|
// Convert to Collection<uIDs> to call getVCardsForContactIDs
|
|
|
|
Set<uID> uIDs = new HashSet<>(uIDsAsStrings.size());
|
|
|
|
for (String uID : uIDsAsStrings) {
|
|
|
|
uIDs.add(new uID(uID));
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<uID, VCardBuilder> uIDsToVCards = ContactsHelper.getVCardsForContactIDs(context, uIDs);
|
|
|
|
|
|
|
|
// ContactsHelper.getVCardsForContactIDs(..) is allowed to reply without
|
|
|
|
// some of the requested uIDs if they were not in the database, so update our list
|
|
|
|
uIDsAsStrings = new ArrayList<>(uIDsToVCards.size());
|
|
|
|
|
|
|
|
NetworkPacket reply = new NetworkPacket(PACKET_TYPE_CONTACTS_RESPONSE_VCARDS);
|
|
|
|
|
|
|
|
// Add the vcards to the packet
|
|
|
|
for (uID uID : uIDsToVCards.keySet()) {
|
|
|
|
VCardBuilder vcard = uIDsToVCards.get(uID);
|
|
|
|
|
2019-10-27 21:23:52 +00:00
|
|
|
try {
|
|
|
|
vcard = this.addVCardMetadata(vcard, uID);
|
|
|
|
|
|
|
|
// Store this as a valid uID
|
|
|
|
uIDsAsStrings.add(uID.toString());
|
|
|
|
// Add the uid -> vcard pairing to the packet
|
|
|
|
reply.set(uID.toString(), vcard.toString());
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
|
2019-10-27 21:23:52 +00:00
|
|
|
} catch (ContactsHelper.ContactNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
Add contacts-reading plugin (Android side)
Summary:
Add a plugin to the KDE Connect Android application which supports reading the Android contacts databases and sending the requested data as vcards
- Android automatically has support for exporting vcards with all the fields you would expect (phone, email, photo, etc.)
- I add two custom fields, one for the modification timestamp and another for the NAME_RAW_CONTACT_ID so that the contacts can be correlated back to the Android database
This does not (yet) support writing contacts back to the phone nor does it automatically listen to the phone's contacts database to change
BUG: 367999
Test Plan:
Connect the device to the desktop and verify that vcards are created in QStandardPaths::GenericDataLocation / kpeoplevcard". On my system this is ~/.local/share/kpeoplevcard
Create a dummy contact on the device and verify it is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Modify the dummy contact and verify the modifications are synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Delete the dummy contact and verify the deletion is synchronized (Currently not automatic, have to disconnect and reconnect or use dbus)
Reviewers: #kde_connect, mtijink, nicolasfella
Reviewed By: #kde_connect, nicolasfella
Subscribers: MatMaul, philipc, kdeconnect, nicolasfella, andyholmes, mtijink
Tags: #kde_connect
Maniphest Tasks: T8283
Differential Revision: https://phabricator.kde.org/D9690
2018-05-30 18:33:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the valid uIDs to the packet
|
|
|
|
reply.set("uids", uIDsAsStrings);
|
|
|
|
|
|
|
|
device.sendPacket(reply);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPacketReceived(NetworkPacket np) {
|
|
|
|
switch (np.getType()) {
|
|
|
|
case PACKET_TYPE_CONTACTS_REQUEST_ALL_UIDS_TIMESTAMPS:
|
|
|
|
return this.handleRequestAllUIDsTimestamps(np);
|
|
|
|
case PACKET_TYPE_CONTACTS_REQUEST_VCARDS_BY_UIDS:
|
|
|
|
return this.handleRequestVCardsByUIDs(np);
|
|
|
|
default:
|
|
|
|
Log.e("ContactsPlugin", "Contacts plugin received an unexpected packet!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|