mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 04:28:35 +00:00
Add additional log around change number and set PNI.
This commit is contained in:
@@ -17,6 +17,7 @@ import org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter
|
||||
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme
|
||||
import org.thoughtcrime.securesms.util.LifecycleDisposable
|
||||
import org.whispersystems.signalservice.api.push.PNI
|
||||
import java.util.Objects
|
||||
|
||||
private val TAG: String = Log.tag(ChangeNumberLockActivity::class.java)
|
||||
@@ -57,7 +58,7 @@ class ChangeNumberLockActivity : PassphraseRequiredActivity() {
|
||||
Single.just(false)
|
||||
} else {
|
||||
Log.i(TAG, "Local (${SignalStore.account().e164}) and remote (${whoAmI.number}) numbers do not match, updating local.")
|
||||
changeNumberRepository.changeLocalNumber(whoAmI.number)
|
||||
changeNumberRepository.changeLocalNumber(whoAmI.number, PNI.parseOrThrow(whoAmI.pni))
|
||||
.map { true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,17 @@ import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.pin.KbsRepository
|
||||
import org.thoughtcrime.securesms.pin.KeyBackupSystemWrongPinException
|
||||
import org.thoughtcrime.securesms.pin.TokenData
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.registration.VerifyAccountRepository
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper
|
||||
import org.whispersystems.signalservice.api.KbsPinData
|
||||
import org.whispersystems.signalservice.api.KeyBackupSystemNoDataException
|
||||
import org.whispersystems.signalservice.api.push.PNI
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse
|
||||
import org.whispersystems.signalservice.internal.push.VerifyAccountResponse
|
||||
import org.whispersystems.signalservice.internal.push.WhoAmIResponse
|
||||
import java.io.IOException
|
||||
import java.security.MessageDigest
|
||||
|
||||
private val TAG: String = Log.tag(ChangeNumberRepository::class.java)
|
||||
|
||||
@@ -61,10 +65,26 @@ class ChangeNumberRepository(private val context: Context) {
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun changeLocalNumber(e164: String): Single<Unit> {
|
||||
fun changeLocalNumber(e164: String, pni: PNI): Single<Unit> {
|
||||
val oldStorageId: ByteArray? = Recipient.self().storageServiceId
|
||||
SignalDatabase.recipients.updateSelfPhone(e164)
|
||||
val newStorageId: ByteArray? = Recipient.self().storageServiceId
|
||||
|
||||
if (MessageDigest.isEqual(oldStorageId, newStorageId)) {
|
||||
Log.w(TAG, "Self storage id was not rotated, attempting to rotate again")
|
||||
SignalDatabase.recipients.rotateStorageId(Recipient.self().id)
|
||||
Recipient.self().live().refresh()
|
||||
StorageSyncHelper.scheduleSyncForDataChange()
|
||||
val secondAttemptStorageId: ByteArray? = Recipient.self().storageServiceId
|
||||
if (MessageDigest.isEqual(oldStorageId, secondAttemptStorageId)) {
|
||||
Log.w(TAG, "Second attempt also failed to rotate storage id")
|
||||
}
|
||||
}
|
||||
|
||||
SignalDatabase.recipients.setPni(Recipient.self().id, pni)
|
||||
|
||||
SignalStore.account().setE164(e164)
|
||||
SignalStore.account().setPni(pni)
|
||||
|
||||
ApplicationDependencies.closeConnections()
|
||||
ApplicationDependencies.getIncomingMessageObserver()
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.registration.VerifyProcessor
|
||||
import org.thoughtcrime.securesms.registration.viewmodel.BaseRegistrationViewModel
|
||||
import org.thoughtcrime.securesms.registration.viewmodel.NumberViewState
|
||||
import org.thoughtcrime.securesms.util.DefaultValueLiveData
|
||||
import org.whispersystems.signalservice.api.push.PNI
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse
|
||||
import org.whispersystems.signalservice.internal.push.VerifyAccountResponse
|
||||
import java.util.Objects
|
||||
@@ -145,7 +146,7 @@ class ChangeNumberViewModel(
|
||||
|
||||
@WorkerThread
|
||||
override fun onVerifySuccess(processor: VerifyAccountResponseProcessor): Single<VerifyAccountResponseProcessor> {
|
||||
return changeNumberRepository.changeLocalNumber(number.e164Number)
|
||||
return changeNumberRepository.changeLocalNumber(number.e164Number, PNI.parseOrThrow(processor.result.pni))
|
||||
.map { processor }
|
||||
.onErrorReturn { t ->
|
||||
Log.w(TAG, "Error attempting to change local number", t)
|
||||
@@ -154,7 +155,7 @@ class ChangeNumberViewModel(
|
||||
}
|
||||
|
||||
override fun onVerifySuccessWithRegistrationLock(processor: VerifyCodeWithRegistrationLockResponseProcessor, pin: String): Single<VerifyCodeWithRegistrationLockResponseProcessor> {
|
||||
return changeNumberRepository.changeLocalNumber(number.e164Number)
|
||||
return changeNumberRepository.changeLocalNumber(number.e164Number, PNI.parseOrThrow(processor.result.verifyAccountResponse.pni))
|
||||
.map { processor }
|
||||
.onErrorReturn { t ->
|
||||
Log.w(TAG, "Error attempting to change local number", t)
|
||||
|
||||
@@ -99,6 +99,7 @@ import java.util.LinkedHashSet
|
||||
import java.util.LinkedList
|
||||
import java.util.Objects
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.jvm.Throws
|
||||
import kotlin.math.max
|
||||
|
||||
open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) : Database(context, databaseHelper) {
|
||||
@@ -418,14 +419,14 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
fetch.id
|
||||
}
|
||||
is RecipientFetch.MatchAndUpdateE164 -> {
|
||||
setPhoneNumber(fetch.id, fetch.e164)
|
||||
setPhoneNumberOrThrowSilent(fetch.id, fetch.e164)
|
||||
recipientsNeedingRefresh = listOf(fetch.id)
|
||||
recipientChangedNumber = fetch.changedNumber
|
||||
fetch.id
|
||||
}
|
||||
is RecipientFetch.MatchAndReassignE164 -> {
|
||||
removePhoneNumber(fetch.e164Id, db)
|
||||
setPhoneNumber(fetch.id, fetch.e164)
|
||||
setPhoneNumberOrThrowSilent(fetch.id, fetch.e164)
|
||||
recipientsNeedingRefresh = listOf(fetch.id, fetch.e164Id)
|
||||
recipientChangedNumber = fetch.changedNumber
|
||||
fetch.id
|
||||
@@ -1749,12 +1750,16 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
putNull(PHONE)
|
||||
putNull(PNI_COLUMN)
|
||||
}
|
||||
db.update(TABLE_NAME, values, ID_WHERE, SqlUtil.buildArgs(recipientId))
|
||||
|
||||
if (update(recipientId, values)) {
|
||||
rotateStorageId(recipientId)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should only use if you are confident that this will not result in any contact merging.
|
||||
*/
|
||||
@Throws(SQLiteConstraintException::class)
|
||||
fun setPhoneNumberOrThrow(id: RecipientId, e164: String) {
|
||||
val contentValues = ContentValues(1).apply {
|
||||
put(PHONE, e164)
|
||||
@@ -1766,6 +1771,16 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(SQLiteConstraintException::class)
|
||||
fun setPhoneNumberOrThrowSilent(id: RecipientId, e164: String) {
|
||||
val contentValues = ContentValues(1).apply {
|
||||
put(PHONE, e164)
|
||||
}
|
||||
if (update(id, contentValues)) {
|
||||
rotateStorageId(id)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSelfPhone(e164: String) {
|
||||
val db = writableDatabase
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ public class PushServiceSocket {
|
||||
String requestBody = JsonUtil.toJson(changePhoneNumberRequest);
|
||||
String responseBody = makeServiceRequest(CHANGE_NUMBER_PATH, "PUT", requestBody);
|
||||
|
||||
return new VerifyAccountResponse();
|
||||
return JsonUtil.fromJson(responseBody, VerifyAccountResponse.class);
|
||||
}
|
||||
|
||||
public void setAccountAttributes(String signalingKey,
|
||||
|
||||
Reference in New Issue
Block a user