further cleaning on V1 multi device

This commit is contained in:
Ryan ZHAO
2021-02-18 15:12:30 +11:00
parent 8e5e2fdc49
commit 0d2f5e0cde
20 changed files with 26 additions and 152 deletions

View File

@@ -555,12 +555,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
if (publicChatAPI == null) { return; }
byte[] profileKey = ProfileKeyUtil.getProfileKey(this);
String url = TextSecurePreferences.getProfilePictureURL(this);
String userMasterDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(this);
if (userMasterDevice != null) {
Recipient userMasterDeviceAsRecipient = Recipient.from(this, Address.fromSerialized(userMasterDevice), false).resolve();
profileKey = userMasterDeviceAsRecipient.getProfileKey();
url = userMasterDeviceAsRecipient.getProfileAvatar();
}
Set<String> servers = DatabaseFactory.getLokiThreadDatabase(this).getAllPublicChatServers();
for (String server : servers) {
if (profileKey != null) {

View File

@@ -92,7 +92,6 @@ public class SignalCommunicationModule {
new DynamicCredentialsProvider(context),
new SignalProtocolStoreImpl(context),
BuildConfig.USER_AGENT,
TextSecurePreferences.isMultiDevice(context),
Optional.fromNullable(IncomingMessageObserver.getPipe()),
Optional.fromNullable(IncomingMessageObserver.getUnidentifiedPipe()),
Optional.of(new MessageSenderEventListener(context)),
@@ -108,7 +107,6 @@ public class SignalCommunicationModule {
((ApplicationContext)context.getApplicationContext()).broadcaster);
} else {
this.messageSender.setMessagePipe(IncomingMessageObserver.getPipe(), IncomingMessageObserver.getUnidentifiedPipe());
this.messageSender.setIsMultiDevice(TextSecurePreferences.isMultiDevice(context));
}
return this.messageSender;

View File

@@ -73,10 +73,9 @@ public class GroupManager {
final Set<Address> memberAddresses = getMemberAddresses(members);
final Set<Address> adminAddresses = getMemberAddresses(admins);
String masterPublicKeyOrNull = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
String masterPublicKey = masterPublicKeyOrNull != null ? masterPublicKeyOrNull : TextSecurePreferences.getLocalNumber(context);
String userPublicKey = TextSecurePreferences.getLocalNumber(context);
memberAddresses.add(Address.fromSerialized(masterPublicKey));
memberAddresses.add(Address.fromSerialized(userPublicKey));
groupDatabase.create(groupId, name, new LinkedList<>(memberAddresses), null, null, new LinkedList<>(adminAddresses), System.currentTimeMillis());
groupDatabase.updateProfilePicture(groupId, avatarBytes);

View File

@@ -125,10 +125,9 @@ public class GroupMessageProcessor {
Address address = Address.fromExternal(context, GroupUtil.getEncodedId(group));
Recipient recipient = Recipient.from(context, address, false);
String userMasterDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
if (userMasterDevice == null) { userMasterDevice = TextSecurePreferences.getLocalNumber(context); }
String userPublicKey = TextSecurePreferences.getLocalNumber(context);
if (content.getSender().equals(userMasterDevice)) {
if (content.getSender().equals(userPublicKey)) {
long threadId = threadDatabase.getThreadIdIfExistsFor(recipient);
return threadId == -1 ? null : threadId;
}
@@ -141,9 +140,9 @@ public class GroupMessageProcessor {
}
// Loki - Only process update messages if we're part of the group
Address userMasterDeviceAddress = Address.fromSerialized(userMasterDevice);
Address userMasterDeviceAddress = Address.fromSerialized(userPublicKey);
if (!groupRecord.getMembers().contains(userMasterDeviceAddress) &&
!group.getMembers().or(Collections.emptyList()).contains(userMasterDevice)) {
!group.getMembers().or(Collections.emptyList()).contains(userPublicKey)) {
Log.d("Loki", "Received a group update message from a group we're not a member of: " + id + "; ignoring.");
database.setActive(id, false);
return null;
@@ -193,7 +192,7 @@ public class GroupMessageProcessor {
}
// If we were removed then we need to disable the chat
if (removedMembers.contains(Address.fromSerialized(userMasterDevice))) {
if (removedMembers.contains(Address.fromSerialized(userPublicKey))) {
database.setActive(id, false);
} else {
if (!groupRecord.isActive()) database.setActive(id, true);

View File

@@ -276,17 +276,5 @@ public abstract class PushSendJob extends SendJob {
// Loki - We don't need verification on sender certificates
}
protected SignalServiceSyncMessage buildSelfSendSyncMessage(@NonNull Context context, @NonNull SignalServiceDataMessage message, Optional<UnidentifiedAccessPair> syncAccess) {
String masterPublicKeyOrNull = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
String masterPublicKey = masterPublicKeyOrNull != null ? masterPublicKeyOrNull : TextSecurePreferences.getLocalNumber(context);
SentTranscriptMessage transcript = new SentTranscriptMessage(masterPublicKey,
message.getTimestamp(),
message,
message.getExpiresInSeconds(),
Collections.singletonMap(masterPublicKey, syncAccess.isPresent()));
return SignalServiceSyncMessage.forSentTranscript(transcript);
}
protected abstract void onPushSend() throws Exception;
}

View File

@@ -62,10 +62,7 @@ class CreatePrivateChatActivity : PassphraseRequiredActionBarActivity(), ScanQRC
fun createPrivateChatIfPossible(hexEncodedPublicKey: String) {
if (!PublicKeyValidation.isValid(hexEncodedPublicKey)) { return Toast.makeText(this, R.string.invalid_session_id, Toast.LENGTH_SHORT).show() }
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(this)
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this)!!
val targetHexEncodedPublicKey = if (hexEncodedPublicKey == masterHexEncodedPublicKey) userHexEncodedPublicKey else hexEncodedPublicKey
val recipient = Recipient.from(this, Address.fromSerialized(targetHexEncodedPublicKey), false)
val recipient = Recipient.from(this, Address.fromSerialized(hexEncodedPublicKey), false)
val intent = Intent(this, ConversationActivity::class.java)
intent.putExtra(ConversationActivity.ADDRESS_EXTRA, recipient.address)
intent.putExtra(ConversationActivity.TEXT_EXTRA, getIntent().getStringExtra(ConversationActivity.TEXT_EXTRA))
@@ -115,9 +112,7 @@ class EnterPublicKeyFragment : Fragment() {
private val hexEncodedPublicKey: String
get() {
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(requireContext())
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(requireContext())!!
return masterHexEncodedPublicKey ?: userHexEncodedPublicKey
return TextSecurePreferences.getLocalNumber(requireContext())!!
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {

View File

@@ -84,9 +84,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
private val publicKey: String
get() {
val masterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(this)
val userPublicKey = TextSecurePreferences.getLocalNumber(this)!!
return masterPublicKey ?: userPublicKey
return TextSecurePreferences.getLocalNumber(this)!!
}
// region Lifecycle
@@ -111,9 +109,8 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
pathStatusViewContainer.disableClipping()
pathStatusViewContainer.setOnClickListener { showPath() }
// Set up seed reminder view
val isMasterDevice = (TextSecurePreferences.getMasterHexEncodedPublicKey(this) == null)
val hasViewedSeed = TextSecurePreferences.getHasViewedSeed(this)
if (!hasViewedSeed && isMasterDevice) {
if (!hasViewedSeed) {
val seedReminderViewTitle = SpannableString("You're almost finished! 80%") // Intentionally not yet translated
seedReminderViewTitle.setSpan(ForegroundColorSpan(resources.getColorWithID(R.color.accent, theme)), 24, 27, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
seedReminderView.title = seedReminderViewTitle
@@ -191,9 +188,8 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
super.onResume()
if (TextSecurePreferences.getLocalNumber(this) == null) { return; } // This can be the case after a secondary device is auto-cleared
profileButton.update()
val isMasterDevice = (TextSecurePreferences.getMasterHexEncodedPublicKey(this) == null)
val hasViewedSeed = TextSecurePreferences.getHasViewedSeed(this)
if (hasViewedSeed || !isMasterDevice) {
if (hasViewedSeed) {
seedReminderView.visibility = View.GONE
}
showKeyPairMigrationSheetIfNeeded()

View File

@@ -28,10 +28,6 @@ class LandingActivity : BaseActionBarActivity() {
findViewById<View>(R.id.restoreButton).setOnClickListener { restoreFromRecoveryPhrase() }
findViewById<View>(R.id.restoreBackupButton).setOnClickListener { restoreFromBackup() }
if (TextSecurePreferences.getWasUnlinked(this)) {
Toast.makeText(this, R.string.activity_landing_device_unlinked_dialog_title, Toast.LENGTH_LONG).show()
}
// Setup essentials for a new user.
IdentityKeyUtil.generateIdentityKeyPair(this)

View File

@@ -53,10 +53,7 @@ class QRCodeActivity : PassphraseRequiredActionBarActivity(), ScanQRCodeWrapperF
fun createPrivateChatIfPossible(hexEncodedPublicKey: String) {
if (!PublicKeyValidation.isValid(hexEncodedPublicKey)) { return Toast.makeText(this, R.string.invalid_session_id, Toast.LENGTH_SHORT).show() }
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(this)
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this)
val targetHexEncodedPublicKey = if (hexEncodedPublicKey == masterHexEncodedPublicKey) userHexEncodedPublicKey else hexEncodedPublicKey
val recipient = Recipient.from(this, Address.fromSerialized(targetHexEncodedPublicKey!!), false)
val recipient = Recipient.from(this, Address.fromSerialized(hexEncodedPublicKey), false)
val intent = Intent(this, ConversationActivity::class.java)
intent.putExtra(ConversationActivity.ADDRESS_EXTRA, recipient.address)
intent.putExtra(ConversationActivity.TEXT_EXTRA, getIntent().getStringExtra(ConversationActivity.TEXT_EXTRA))
@@ -105,9 +102,7 @@ class ViewMyQRCodeFragment : Fragment() {
private val hexEncodedPublicKey: String
get() {
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(requireContext())
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(requireContext())!!
return masterHexEncodedPublicKey ?: userHexEncodedPublicKey
return TextSecurePreferences.getLocalNumber(requireContext())!!
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {

View File

@@ -63,9 +63,7 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
private val hexEncodedPublicKey: String
get() {
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(this)
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this)!!
return masterHexEncodedPublicKey ?: userHexEncodedPublicKey
return TextSecurePreferences.getLocalNumber(this)!!
}
// region Lifecycle
@@ -85,17 +83,11 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
publicKeyTextView.text = hexEncodedPublicKey
copyButton.setOnClickListener { copyPublicKey() }
shareButton.setOnClickListener { sharePublicKey() }
val isMasterDevice = (TextSecurePreferences.getMasterHexEncodedPublicKey(this) == null)
linkedDevicesButtonTopSeparator.visibility = View.GONE
linkedDevicesButton.visibility = View.GONE
if (!isMasterDevice) {
seedButtonTopSeparator.visibility = View.GONE
seedButton.visibility = View.GONE
}
privacyButton.setOnClickListener { showPrivacySettings() }
notificationsButton.setOnClickListener { showNotificationSettings() }
chatsButton.setOnClickListener { showChatSettings() }
// linkedDevicesButton.setOnClickListener { showLinkedDevices() }
sendInvitationButton.setOnClickListener { sendInvitation() }
seedButton.setOnClickListener { showSeed() }
clearAllDataButton.setOnClickListener { clearAllData() }

View File

@@ -204,7 +204,7 @@ class PublicChatPoller(private val context: Context, private val group: PublicCh
}
// If we got a message from our master device then make sure our mapping stays in sync
val recipient = Recipient.from(context, Address.fromSerialized(message.senderPublicKey), false)
if (recipient.isUserMasterDevice && message.profilePicture != null) {
if (message.profilePicture != null) {
val profileKey = message.profilePicture!!.profileKey
val url = message.profilePicture!!.url
if (recipient.profileKey == null || !MessageDigest.isEqual(recipient.profileKey, profileKey)) {

View File

@@ -37,11 +37,7 @@ class MultiDeviceRemovalBottomSheet : BottomSheetDialogFragment() {
}
private val explanation by lazy {
if (TextSecurePreferences.getMasterHexEncodedPublicKey(requireContext()) != null) {
"Youre seeing this because this is a secondary device in a multi-device setup. To improve reliability and stability, weve decided to temporarily disable Sessions multi-device functionality. Device linking has been disabled, and existing secondary clients will be erased on $removalDateDescription.\n\nTo read more about this change, visit the Session FAQ at getsession.org/faq."
} else {
"Youre seeing this because you have a secondary device linked to your Session ID. To improve reliability and stability, weve decided to temporarily disable Sessions multi-device functionality. Device linking has been disabled, and existing secondary clients will be erased on $removalDateDescription.\n\nTo read more about this change, visit the Session FAQ at getsession.org/faq"
}
"Youre seeing this because you have a secondary device linked to your Session ID. To improve reliability and stability, weve decided to temporarily disable Sessions multi-device functionality. Device linking has been disabled, and existing secondary clients will be erased on $removalDateDescription.\n\nTo read more about this change, visit the Session FAQ at getsession.org/faq"
}
private val decoratedExplanation by lazy {

View File

@@ -47,9 +47,8 @@ object SessionMetaProtocol {
val displayName = content.senderDisplayName.orNull() ?: return
if (displayName.isBlank()) { return }
val userPublicKey = TextSecurePreferences.getLocalNumber(context)
val userMasterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context)
val sender = content.sender.toLowerCase()
if (userMasterPublicKey == sender) {
if (userPublicKey == sender) {
// Update the user's local name if the message came from their master device
TextSecurePreferences.setProfileName(context, displayName)
}
@@ -67,8 +66,8 @@ object SessionMetaProtocol {
database.setUnidentifiedAccessMode(recipient, Recipient.UnidentifiedAccessMode.UNKNOWN)
val url = content.senderProfilePictureURL.or("")
ApplicationContext.getInstance(context).jobManager.add(RetrieveProfileAvatarJob(recipient, url))
val userMasterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context)
if (userMasterPublicKey == content.sender) {
val userPublicKey = TextSecurePreferences.getLocalNumber(context)
if (userPublicKey == content.sender) {
ApplicationContext.getInstance(context).updateOpenGroupProfilePicturesIfNeeded()
}
}

View File

@@ -18,7 +18,7 @@ class GroupDescription(context: Context, groupContext: SignalServiceProtos.Group
private val groupContext: SignalServiceProtos.GroupContext?
private val newMembers: MutableList<Recipient>
private val removedMembers: MutableList<Recipient>
private var wasCurrentUserRemoved: Boolean
private var wasCurrentUserRemoved: Boolean = false
private fun toRecipient(hexEncodedPublicKey: String): Recipient {
val address = Address.fromSerialized(hexEncodedPublicKey)
return Recipient.from(context, address, false)
@@ -74,7 +74,6 @@ class GroupDescription(context: Context, groupContext: SignalServiceProtos.Group
this.groupContext = groupContext
newMembers = LinkedList()
removedMembers = LinkedList()
wasCurrentUserRemoved = false
if (groupContext != null) {
val newMembers = groupContext.newMembersList
for (member in newMembers) {
@@ -84,15 +83,7 @@ class GroupDescription(context: Context, groupContext: SignalServiceProtos.Group
for (member in removedMembers) {
this.removedMembers.add(toRecipient(member))
}
// If we were the one that quit then we need to leave the group (only relevant for slave
// devices in a multi device context)
if (!removedMembers.isEmpty()) {
val masterPublicKeyOrNull = TextSecurePreferences.getMasterHexEncodedPublicKey(context)
val masterPublicKey = masterPublicKeyOrNull
?: TextSecurePreferences.getLocalNumber(context)
wasCurrentUserRemoved = removedMembers.contains(masterPublicKey)
}
wasCurrentUserRemoved = removedMembers.contains(TextSecurePreferences.getLocalNumber(context))
}
}

View File

@@ -75,10 +75,6 @@ class ProfilePictureView : RelativeLayout {
if (recipient.isGroupRecipient && !isOpenGroupWithProfilePicture(recipient)) {
val users = MentionsManager.shared.userPublicKeyCache[threadID]?.toMutableList() ?: mutableListOf()
users.remove(TextSecurePreferences.getLocalNumber(context))
val masterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context)
if (masterPublicKey != null) {
users.remove(masterPublicKey)
}
val randomUsers = users.sorted().toMutableList() // Sort to provide a level of stability
if (users.count() == 1) {
val userPublicKey = TextSecurePreferences.getLocalNumber(context)!!
@@ -159,13 +155,11 @@ class ProfilePictureView : RelativeLayout {
imagesCached.add(publicKey)
} else {
val sizeInPX = resources.getDimensionPixelSize(sizeResId)
val masterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context)
val hepk = if (recipient.isLocalNumber && masterPublicKey != null) masterPublicKey else publicKey
glide.clear(imageView)
glide.load(AvatarPlaceholderGenerator.generate(
context,
sizeInPX,
hepk,
publicKey,
displayName
)).diskCacheStrategy(DiskCacheStrategy.ALL).circleCrop().into(imageView)
imagesCached.add(publicKey)

View File

@@ -326,10 +326,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
private static Drawable getPlaceholderDrawable(Context context, Recipient recipient) {
String publicKey = recipient.getAddress().serialize();
String hepk = (recipient.isLocalNumber() && publicKey == null)
? TextSecurePreferences.getMasterHexEncodedPublicKey(context)
: publicKey;
String displayName = recipient.getName();
return AvatarPlaceholderGenerator.generate(context, 128, hepk, displayName);
return AvatarPlaceholderGenerator.generate(context, 128, publicKey, displayName);
}
}

View File

@@ -211,8 +211,7 @@ public class MessageSender {
private static boolean isLocalSelfSend(@NonNull Context context, @NonNull Recipient recipient, boolean forceSms) {
return recipient.isLocalNumber() &&
!forceSms &&
TextSecurePreferences.isPushRegistered(context) &&
!TextSecurePreferences.isMultiDevice(context);
TextSecurePreferences.isPushRegistered(context);
}
private static void sendLocalMediaSelf(Context context, long messageId) {