Implement unregister command for jsonrpc and dbus daemon

This commit is contained in:
AsamK 2021-11-12 16:07:35 +01:00
parent b78573021d
commit c73c58723c
11 changed files with 98 additions and 9 deletions

View file

@ -248,6 +248,8 @@ public interface Manager extends Closeable {
boolean trustIdentityAllKeys(RecipientIdentifier.Single recipient);
void addClosedListener(Runnable listener);
@Override
void close() throws IOException;

View file

@ -95,6 +95,7 @@ import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.SignatureException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@ -142,6 +143,7 @@ public class ManagerImpl implements Manager {
private Thread receiveThread;
private final Set<ReceiveMessageHandler> weakHandlers = new HashSet<>();
private final Set<ReceiveMessageHandler> messageHandlers = new HashSet<>();
private final List<Runnable> closedListeners = new ArrayList<>();
private boolean isReceivingSynchronous;
ManagerImpl(
@ -385,6 +387,7 @@ public class ManagerImpl implements Manager {
dependencies.getAccountManager().setGcmId(Optional.absent());
account.setRegistered(false);
close();
}
@Override
@ -399,6 +402,7 @@ public class ManagerImpl implements Manager {
dependencies.getAccountManager().deleteAccount();
account.setRegistered(false);
close();
}
@Override
@ -1325,6 +1329,13 @@ public class ManagerImpl implements Manager {
return identityHelper.trustIdentityAllKeys(recipientId);
}
@Override
public void addClosedListener(final Runnable listener) {
synchronized (closedListeners) {
closedListeners.add(listener);
}
}
private void handleIdentityFailure(
final RecipientId recipientId,
final org.whispersystems.signalservice.api.messages.SendMessageResult.IdentityFailure identityFailure
@ -1390,10 +1401,6 @@ public class ManagerImpl implements Manager {
@Override
public void close() throws IOException {
close(true);
}
private void close(boolean closeAccount) throws IOException {
Thread thread;
synchronized (messageHandlers) {
weakHandlers.clear();
@ -1408,7 +1415,12 @@ public class ManagerImpl implements Manager {
dependencies.getSignalWebSocket().disconnect();
if (closeAccount && account != null) {
synchronized (closedListeners) {
closedListeners.forEach(Runnable::run);
closedListeners.clear();
}
if (account != null) {
account.close();
}
account = null;

View file

@ -36,6 +36,7 @@ public class MultiAccountManagerImpl implements MultiAccountManager {
final String userAgent
) {
this.managers.addAll(managers);
managers.forEach(m -> m.addClosedListener(() -> this.removeManager(m)));
this.dataPath = dataPath;
this.serviceEnvironment = serviceEnvironment;
this.userAgent = userAgent;
@ -54,6 +55,7 @@ public class MultiAccountManagerImpl implements MultiAccountManager {
return;
}
managers.add(m);
m.addClosedListener(() -> this.removeManager(m));
}
synchronized (onManagerAddedHandlers) {
for (final var handler : onManagerAddedHandlers) {
@ -69,6 +71,19 @@ public class MultiAccountManagerImpl implements MultiAccountManager {
}
}
void removeManager(final Manager m) {
synchronized (managers) {
if (!managers.remove(m)) {
return;
}
}
synchronized (onManagerRemovedHandlers) {
for (final var handler : onManagerRemovedHandlers) {
handler.accept(m);
}
}
}
@Override
public void addOnManagerRemovedHandler(final Consumer<Manager> handler) {
synchronized (onManagerRemovedHandlers) {