Reexport dbus objects when self number changes

This commit is contained in:
AsamK 2022-02-11 17:59:02 +01:00
parent 796f4d0d96
commit f207c2abc3
5 changed files with 36 additions and 9 deletions

View file

@ -261,6 +261,8 @@ public interface Manager extends Closeable {
*/ */
boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient) throws UnregisteredRecipientException; boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient) throws UnregisteredRecipientException;
void addAddressChangedListener(Runnable listener);
void addClosedListener(Runnable listener); void addClosedListener(Runnable listener);
@Override @Override

View file

@ -109,6 +109,7 @@ class ManagerImpl implements Manager {
private final Set<ReceiveMessageHandler> weakHandlers = new HashSet<>(); private final Set<ReceiveMessageHandler> weakHandlers = new HashSet<>();
private final Set<ReceiveMessageHandler> messageHandlers = new HashSet<>(); private final Set<ReceiveMessageHandler> messageHandlers = new HashSet<>();
private final List<Runnable> closedListeners = new ArrayList<>(); private final List<Runnable> closedListeners = new ArrayList<>();
private final List<Runnable> addressChangedListeners = new ArrayList<>();
private final CompositeDisposable disposable = new CompositeDisposable(); private final CompositeDisposable disposable = new CompositeDisposable();
ManagerImpl( ManagerImpl(
@ -139,12 +140,12 @@ class ManagerImpl implements Manager {
final var attachmentStore = new AttachmentStore(pathConfig.attachmentsPath()); final var attachmentStore = new AttachmentStore(pathConfig.attachmentsPath());
final var stickerPackStore = new StickerPackStore(pathConfig.stickerPacksPath()); final var stickerPackStore = new StickerPackStore(pathConfig.stickerPacksPath());
this.context = new Context(account, this.context = new Context(account, (number, aci) -> {
accountFileUpdater, accountFileUpdater.updateAccountIdentifiers(number, aci);
dependencies, synchronized (addressChangedListeners) {
avatarStore, addressChangedListeners.forEach(Runnable::run);
attachmentStore, }
stickerPackStore); }, dependencies, avatarStore, attachmentStore, stickerPackStore);
this.context.getAccountHelper().setUnregisteredListener(this::close); this.context.getAccountHelper().setUnregisteredListener(this::close);
this.context.getReceiveHelper().setAuthenticationFailureListener(this::close); this.context.getReceiveHelper().setAuthenticationFailureListener(this::close);
this.context.getReceiveHelper().setCaughtUpWithOldMessagesListener(() -> { this.context.getReceiveHelper().setCaughtUpWithOldMessagesListener(() -> {
@ -998,6 +999,13 @@ class ManagerImpl implements Manager {
return updated; return updated;
} }
@Override
public void addAddressChangedListener(final Runnable listener) {
synchronized (addressChangedListeners) {
addressChangedListeners.add(listener);
}
}
@Override @Override
public void addClosedListener(final Runnable listener) { public void addClosedListener(final Runnable listener) {
synchronized (closedListeners) { synchronized (closedListeners) {

View file

@ -314,7 +314,6 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
} }
} catch (DBusException ignored) { } catch (DBusException ignored) {
} }
connection.unExportObject(path);
}); });
final var initThreads = c.getManagers() final var initThreads = c.getManagers()
@ -370,7 +369,6 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
final DBusConnection conn, final String objectPath, final Manager m, final boolean noReceiveOnStart final DBusConnection conn, final String objectPath, final Manager m, final boolean noReceiveOnStart
) throws DBusException { ) throws DBusException {
final var signal = new DbusSignalImpl(m, conn, objectPath, noReceiveOnStart); final var signal = new DbusSignalImpl(m, conn, objectPath, noReceiveOnStart);
conn.exportObject(signal);
final var initThread = new Thread(signal::initObjects); final var initThread = new Thread(signal::initObjects);
initThread.setName("dbus-init"); initThread.setName("dbus-init");
initThread.start(); initThread.start();

View file

@ -621,6 +621,10 @@ public class DbusManagerImpl implements Manager {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public void addAddressChangedListener(final Runnable listener) {
}
@Override @Override
public void addClosedListener(final Runnable listener) { public void addClosedListener(final Runnable listener) {
synchronized (closedListeners) { synchronized (closedListeners) {

View file

@ -3,7 +3,6 @@ package org.asamk.signal.dbus;
import org.asamk.Signal; import org.asamk.Signal;
import org.asamk.signal.BaseConfig; import org.asamk.signal.BaseConfig;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.api.StickerPackInvalidException;
import org.asamk.signal.manager.api.AttachmentInvalidException; import org.asamk.signal.manager.api.AttachmentInvalidException;
import org.asamk.signal.manager.api.Identity; import org.asamk.signal.manager.api.Identity;
import org.asamk.signal.manager.api.InactiveGroupLinkException; import org.asamk.signal.manager.api.InactiveGroupLinkException;
@ -16,6 +15,7 @@ import org.asamk.signal.manager.api.Pair;
import org.asamk.signal.manager.api.RecipientIdentifier; import org.asamk.signal.manager.api.RecipientIdentifier;
import org.asamk.signal.manager.api.SendMessageResult; import org.asamk.signal.manager.api.SendMessageResult;
import org.asamk.signal.manager.api.SendMessageResults; import org.asamk.signal.manager.api.SendMessageResults;
import org.asamk.signal.manager.api.StickerPackInvalidException;
import org.asamk.signal.manager.api.TypingAction; import org.asamk.signal.manager.api.TypingAction;
import org.asamk.signal.manager.api.UnregisteredRecipientException; import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup; import org.asamk.signal.manager.api.UpdateGroup;
@ -79,12 +79,22 @@ public class DbusSignalImpl implements Signal {
this.connection = connection; this.connection = connection;
this.objectPath = objectPath; this.objectPath = objectPath;
this.noReceiveOnStart = noReceiveOnStart; this.noReceiveOnStart = noReceiveOnStart;
m.addAddressChangedListener(() -> {
unExportObjects();
exportObjects();
});
} }
public void initObjects() { public void initObjects() {
exportObjects();
if (!noReceiveOnStart) { if (!noReceiveOnStart) {
subscribeReceive(); subscribeReceive();
} }
}
private void exportObjects() {
exportObject(this);
updateDevices(); updateDevices();
updateGroups(); updateGroups();
@ -96,9 +106,14 @@ public class DbusSignalImpl implements Signal {
m.removeReceiveHandler(dbusMessageHandler); m.removeReceiveHandler(dbusMessageHandler);
dbusMessageHandler = null; dbusMessageHandler = null;
} }
unExportObjects();
}
private void unExportObjects() {
unExportDevices(); unExportDevices();
unExportGroups(); unExportGroups();
unExportConfiguration(); unExportConfiguration();
connection.unExportObject(this.objectPath);
} }
@Override @Override