implement Dbus unregister/unlisten methods

implemented two related Dbus methods:
- unregister
- unlisten

improved error handling for Dbus method:
- link

fixed logic error in Manager.java (line 876) because daemon
could still be running after a particular account is unregistered.

broadened WebSocketUnavailableException (line 913) to catch all
IOExceptions caused by unregistering account while daemon is running.

specified error message handling in ProvisioningManager.java and
DbusSignalControlImpl.java for link subcommand.

helper methods:
- getPathConfig in Manager.java
- private removeUserData in DbusSignalImpl.java
This commit is contained in:
John Freed 2021-09-23 16:35:47 +02:00
parent 982e887c9f
commit 10274cdb3f
8 changed files with 210 additions and 11 deletions

View file

@ -132,6 +132,7 @@ public class Manager implements Closeable {
private final ProfileHelper profileHelper;
private final PinHelper pinHelper;
private final PathConfig pathConfig;
private final StorageHelper storageHelper;
private final SendHelper sendHelper;
private final SyncHelper syncHelper;
@ -152,6 +153,7 @@ public class Manager implements Closeable {
) {
this.account = account;
this.serviceEnvironmentConfig = serviceEnvironmentConfig;
this.pathConfig = pathConfig;
final var credentialsProvider = new DynamicCredentialsProvider(account.getUuid(),
account.getUsername(),
@ -243,6 +245,10 @@ public class Manager implements Closeable {
jobExecutor);
}
public PathConfig getPathConfig() {
return pathConfig;
}
public String getUsername() {
return account.getUsername();
}
@ -867,8 +873,12 @@ public class Manager implements Closeable {
while (!Thread.interrupted()) {
SignalServiceEnvelope envelope;
final CachedMessage[] cachedMessage = {null};
account.setLastReceiveTimestamp(System.currentTimeMillis());
if (account == null) {
logger.debug("Account closed.");
break;
}
logger.debug("Checking for new message from server");
account.setLastReceiveTimestamp(System.currentTimeMillis());
try {
var result = signalWebSocket.readOrEmpty(unit.toMillis(timeout), envelope1 -> {
final var recipientId = envelope1.hasSourceUuid()
@ -900,7 +910,7 @@ public class Manager implements Closeable {
} else {
throw e;
}
} catch (WebSocketUnavailableException e) {
} catch (IOException e) {
logger.debug("Pipe unexpectedly unavailable, connecting");
signalWebSocket.connect();
continue;

View file

@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.util.KeyHelper;
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
import org.whispersystems.signalservice.api.SignalServiceAccountManager.NewDeviceRegistrationReturn;
import org.whispersystems.signalservice.api.groupsv2.ClientZkOperations;
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
@ -90,7 +91,13 @@ public class ProvisioningManager {
}
public Manager finishDeviceLink(String deviceName) throws IOException, TimeoutException, UserAlreadyExists {
var ret = accountManager.getNewDeviceRegistration(tempIdentityKey);
NewDeviceRegistrationReturn ret;
logger.info("Waiting for addDevice request...");
try {
ret = accountManager.getNewDeviceRegistration(tempIdentityKey);
} catch (IOException | TimeoutException e) {
throw new TimeoutException(e.getMessage());
}
var number = ret.getNumber();
logger.info("Received link information from {}, linking in progress ...", number);