+
+ private byte[] nullIfEmpty(final byte[] array) {
+ return array.length == 0 ? null : array;
+ }
+
+ private String nullIfEmpty(final String name) {
+ return name.isEmpty() ? null : name;
+ }
+
+ private static String getDeviceObjectPath(String basePath, long deviceId) {
+ return basePath + "/Devices/" + deviceId;
+ }
+
+ public class DbusSignalDeviceImpl extends DbusProperties implements Signal.Device {
+
+ private final org.asamk.signal.manager.api.Device device;
+
+ public DbusSignalDeviceImpl(final org.asamk.signal.manager.api.Device device) {
+ super();
+ super.addPropertiesHandler(new DbusInterfacePropertiesHandler("org.asamk.Signal.Device",
+ List.of(new DbusProperty<>("Id", device::getId),
+ new DbusProperty<>("Name",
+ () -> device.getName() == null ? "" : device.getName(),
+ this::setDeviceName),
+ new DbusProperty<>("Created", device::getCreated),
+ new DbusProperty<>("LastSeen", device::getLastSeen))));
+ this.device = device;
+ }
+
+ @Override
+ public String getObjectPath() {
+ return getDeviceObjectPath(objectPath, device.getId());
+ }
+
+ @Override
+ public void removeDevice() throws Error.Failure {
+ try {
+ m.removeLinkedDevices(device.getId());
+ updateDevices();
+ } catch (IOException e) {
+ throw new Error.Failure(e.getMessage());
+ }
+ }
+
+ private void setDeviceName(String name) {
+ if (!device.isThisDevice()) {
+ throw new Error.Failure("Only the name of this device can be changed");
+ }
+ try {
+ m.updateAccountAttributes(name);
+ // update device list
+ updateDevices();
+ } catch (IOException e) {
+ throw new Error.Failure(e.getMessage());
+ }
+ }
+ }