Add possibility to update the device name

This commit is contained in:
AsamK 2021-09-05 11:41:38 +02:00
parent 5a2e37a6e2
commit 299671480f
5 changed files with 24 additions and 6 deletions

View file

@ -311,7 +311,7 @@ public class Manager implements Closeable {
if (account.getUuid() == null) {
account.setUuid(dependencies.getAccountManager().getOwnUuid());
}
updateAccountAttributes();
updateAccountAttributes(null);
}
/**
@ -343,14 +343,21 @@ public class Manager implements Closeable {
}));
}
public void updateAccountAttributes() throws IOException {
public void updateAccountAttributes(String deviceName) throws IOException {
final String encryptedDeviceName;
if (deviceName == null) {
encryptedDeviceName = account.getEncryptedDeviceName();
} else {
final var privateKey = account.getIdentityKeyPair().getPrivateKey();
encryptedDeviceName = DeviceNameUtil.encryptDeviceName(deviceName, privateKey);
account.setEncryptedDeviceName(encryptedDeviceName);
}
dependencies.getAccountManager()
.setAccountAttributes(account.getEncryptedDeviceName(),
.setAccountAttributes(encryptedDeviceName,
null,
account.getLocalRegistrationId(),
true,
// set legacy pin only if no KBS master key is set
account.getPinMasterKey() == null ? account.getRegistrationLockPin() : null,
null,
account.getPinMasterKey() == null ? null : account.getPinMasterKey().deriveRegistrationLock(),
account.getSelfUnidentifiedAccessKey(),
account.isUnrestrictedUnidentifiedAccess(),

View file

@ -818,6 +818,11 @@ public class SignalAccount implements Closeable {
return encryptedDeviceName;
}
public void setEncryptedDeviceName(final String encryptedDeviceName) {
this.encryptedDeviceName = encryptedDeviceName;
save();
}
public int getDeviceId() {
return deviceId;
}