implement Dbus addDevice and removeDevice

update documentation as well
This commit is contained in:
John Freed 2021-09-21 13:18:02 +02:00
parent b875465eff
commit 8b19312a03
3 changed files with 37 additions and 0 deletions

View file

@ -334,6 +334,11 @@ Exceptions: Failure, InvalidNumber
=== Other methods
addDevice(deviceUri<s>) -> <>::
* deviceUri : URI in the form of tsdevice:/?uuid=... Normally received from Signal desktop or smartphone app
Exception: Failure
listDevices() -> devices<as>::
* devices : String array of linked devices
@ -346,6 +351,11 @@ This is a concatenated list of all defined contacts as well of profiles known (e
Exceptions: None
removeDevice(deviceId<i>) -> <>::
* deviceId : Device ID to remove, obtained from listDevices() command
Exception: Failure
sendNoteToSelfMessage(message<s>, attachments<as>) -> timestamp<x>::
* message : Text to send (can be UTF8)
* attachments : String array of filenames to send as attachments (passed as filename, so need to be readable by the user signal-cli is running under)

View file

@ -83,6 +83,10 @@ public interface Signal extends DBusInterface {
boolean isRegistered();
void addDevice(String uri) throws Error.Failure;
void removeDevice(int deviceId) throws Error.Failure;
List<String> listDevices() throws Error.Failure;
void updateAccount(String deviceName) throws Error.Failure;

View file

@ -20,6 +20,7 @@ import org.asamk.signal.manager.storage.identities.IdentityInfo;
import org.asamk.signal.util.ErrorUtils;
import org.asamk.signal.util.Util;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.whispersystems.libsignal.InvalidKeyException;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
@ -29,6 +30,8 @@ import org.whispersystems.signalservice.api.util.InvalidNumberException;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@ -61,6 +64,26 @@ public class DbusSignalImpl implements Signal {
return objectPath;
}
@Override
public void addDevice(String uri) {
try {
m.addDeviceLink(new URI(uri));
} catch (IOException | InvalidKeyException e) {
throw new Error.Failure(e.getClass().getSimpleName() + " Add device link failed. " + e.getMessage());
} catch (URISyntaxException e) {
throw new Error.Failure(e.getClass().getSimpleName() + " Device link uri has invalid format: " + e.getMessage());
}
}
@Override
public void removeDevice(int deviceId) {
try {
m.removeLinkedDevices(deviceId);
} catch (IOException e) {
throw new Error.Failure(e.getClass().getSimpleName() + ": Error while removing device: " + e.getMessage());
}
}
@Override
public List<String> listDevices() {
List<Device> devices;