return new DeviceLinkInfo(deviceUuid, identityKey.getPublicKey().getPublicKey()).createDeviceLinkUri();
}
- public String finishDeviceLink(String deviceName) throws IOException, InvalidKeyException, TimeoutException, UserAlreadyExists {
+ public Manager finishDeviceLink(String deviceName) throws IOException, InvalidKeyException, TimeoutException, UserAlreadyExists {
var ret = accountManager.finishNewDeviceRegistration(identityKey, false, true, registrationId, deviceName);
var username = ret.getNumber();
}
}
- try (var account = SignalAccount.createLinkedAccount(pathConfig.getDataPath(),
- username,
- ret.getUuid(),
- password,
- ret.getDeviceId(),
- ret.getIdentity(),
- registrationId,
- profileKey)) {
+ SignalAccount account = null;
+ try {
+ account = SignalAccount.createLinkedAccount(pathConfig.getDataPath(),
+ username,
+ ret.getUuid(),
+ password,
+ ret.getDeviceId(),
+ ret.getIdentity(),
+ registrationId,
+ profileKey);
account.save();
- try (var m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent)) {
+ Manager m = null;
+ try {
+ m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent);
try {
m.refreshPreKeys();
throw e;
}
- m.close(false);
- }
+ account.save();
- account.save();
- }
+ final var result = m;
+ account = null;
+ m = null;
- return username;
+ return result;
+ } finally {
+ if (m != null) {
+ m.close();
+ }
+ }
+ } finally {
+ if (account != null) {
+ account.close();
+ }
+ }
}
}
account.save();
}
- public void verifyAccount(
+ public Manager verifyAccount(
String verificationCode, String pin
) throws IOException, KeyBackupSystemNoDataException, KeyBackupServicePinException {
verificationCode = verificationCode.replace("-", "");
account.getSignalProtocolStore().getIdentityKeyPair().getPublicKey(),
TrustLevel.TRUSTED_VERIFIED);
- try (var m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent)) {
+ Manager m = null;
+ try {
+ m = new Manager(account, pathConfig, serviceEnvironmentConfig, userAgent);
m.refreshPreKeys();
- m.close(false);
- }
+ account.save();
- account.save();
+ final var result = m;
+ account = null;
+ m = null;
+
+ return result;
+ } finally {
+ if (m != null) {
+ m.close();
+ }
+ }
}
private VerifyAccountResponse verifyAccountWithCode(
}
try {
writer.println("{}", m.getDeviceLinkUri());
- var username = m.finishDeviceLink(deviceName);
- writer.println("Associated with: {}", username);
+ try (var manager = m.finishDeviceLink(deviceName)) {
+ writer.println("Associated with: {}", manager.getUsername());
+ }
} catch (TimeoutException e) {
throw new UserErrorException("Link request timed out, please try again.");
} catch (IOException e) {
var pin = ns.getString("pin");
try {
- m.verifyAccount(verificationCode, pin);
+ final var manager = m.verifyAccount(verificationCode, pin);
+ manager.close();
} catch (LockedException e) {
throw new UserErrorException(
"Verification failed! This number is locked with a pin. Hours remaining until reset: "