Skip to content

Commit

Permalink
Remove uuidOnlyContacts feature flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Jul 21, 2020
1 parent 4e55d2d commit 870cee5
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void onCreate(Bundle bundle) {
byte[] localId;
byte[] remoteId;

if (FeatureFlags.uuidOnlyContacts() && recipient.resolve().getUuid().isPresent()) {
if (FeatureFlags.cds() && recipient.resolve().getUuid().isPresent()) {
Log.i(TAG, "Using UUID (version 2).");
version = 2;
localId = UuidUtil.toByteArray(TextSecurePreferences.getLocalUuid(requireContext()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,13 +689,13 @@ public void applyStorageSyncUpdates(@NonNull Collection<SignalContactRecord>

try {
for (SignalContactRecord insert : contactInserts) {
ContentValues values = validateContactValuesForInsert(getValuesForStorageContact(insert, true));
ContentValues values = getValuesForStorageContact(insert, true);
long id = db.insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE);

RecipientId recipientId;

if (id < 0) {
values = validateContactValuesForInsert(getValuesForStorageContact(insert, false));
values = getValuesForStorageContact(insert, false);
Log.w(TAG, "Failed to insert! It's likely that these were newly-registered users that were missed in the merge. Doing an update instead.");

if (insert.getAddress().getNumber().isPresent()) {
Expand Down Expand Up @@ -2145,17 +2145,6 @@ private boolean update(@NonNull SqlUtil.UpdateQuery updateQuery, @NonNull Conten
}
}

private static ContentValues validateContactValuesForInsert(ContentValues values) {
if (!FeatureFlags.uuidOnlyContacts() &&
values.getAsString(UUID) != null &&
values.getAsString(PHONE) == null)
{
throw new UuidRecipientError();
} else {
return values;
}
}

/**
* Merges one UUID recipient with an E164 recipient. It is assumed that the E164 recipient does
* *not* have a UUID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,7 @@ public class Recipient {

if (UuidUtil.isUuid(identifier)) {
UUID uuid = UuidUtil.parseOrThrow(identifier);

if (FeatureFlags.uuidOnlyContacts()) {
id = db.getOrInsertFromUuid(uuid);
} else {
Optional<RecipientId> possibleId = db.getByUuid(uuid);

if (possibleId.isPresent()) {
id = possibleId.get();
} else {
if (!FeatureFlags.uuidOnlyContacts() && FeatureFlags.groupsV2()) {
throw new RuntimeException(new UuidRecipientError());
} else {
throw new UuidRecipientError();
}
}
}
id = db.getOrInsertFromUuid(uuid);
} else if (GroupId.isEncodedGroup(identifier)) {
id = db.getOrInsertFromGroupId(GroupId.parseOrThrow(identifier));
} else if (NumberUtil.isValidEmail(identifier)) {
Expand Down Expand Up @@ -728,7 +713,7 @@ public boolean isUuidSupported() {
if (FeatureFlags.usernames()) {
return true;
} else {
return FeatureFlags.uuidOnlyContacts() && uuidCapability == Capability.SUPPORTED;
return uuidCapability == Capability.SUPPORTED;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public final class StorageSyncHelper {
public static @NonNull MergeResult resolveConflict(@NonNull Collection<SignalStorageRecord> remoteOnlyRecords,
@NonNull Collection<SignalStorageRecord> localOnlyRecords)
{
List<SignalContactRecord> remoteOnlyContacts = Stream.of(remoteOnlyRecords).filter(r -> r.getContact().isPresent() && isValidContact(r.getContact().get())).map(r -> r.getContact().get()).toList();
List<SignalContactRecord> remoteOnlyContacts = Stream.of(remoteOnlyRecords).filter(r -> r.getContact().isPresent()).map(r -> r.getContact().get()).toList();
List<SignalContactRecord> localOnlyContacts = Stream.of(localOnlyRecords).filter(r -> r.getContact().isPresent()).map(r -> r.getContact().get()).toList();

List<SignalGroupV1Record> remoteOnlyGroupV1 = Stream.of(remoteOnlyRecords).filter(r -> r.getGroupV1().isPresent()).map(r -> r.getGroupV1().get()).toList();
Expand All @@ -241,7 +241,7 @@ public final class StorageSyncHelper {
List<SignalGroupV2Record> remoteOnlyGroupV2 = Stream.of(remoteOnlyRecords).filter(r -> r.getGroupV2().isPresent()).map(r -> r.getGroupV2().get()).toList();
List<SignalGroupV2Record> localOnlyGroupV2 = Stream.of(localOnlyRecords).filter(r -> r.getGroupV2().isPresent()).map(r -> r.getGroupV2().get()).toList();

List<SignalStorageRecord> remoteOnlyUnknowns = Stream.of(remoteOnlyRecords).filter(r -> r.isUnknown() || (r.getContact().isPresent() && !isValidContact(r.getContact().get()))).toList();
List<SignalStorageRecord> remoteOnlyUnknowns = Stream.of(remoteOnlyRecords).filter(SignalStorageRecord::isUnknown).toList();
List<SignalStorageRecord> localOnlyUnknowns = Stream.of(localOnlyRecords).filter(SignalStorageRecord::isUnknown).toList();

List<SignalAccountRecord> remoteOnlyAccount = Stream.of(remoteOnlyRecords).filter(r -> r.getAccount().isPresent()).map(r -> r.getAccount().get()).toList();
Expand Down Expand Up @@ -440,10 +440,6 @@ public static void scheduleRoutineSync() {
}
}

private static boolean isValidContact(@NonNull SignalContactRecord contact) {
return FeatureFlags.uuidOnlyContacts() || contact.getAddress().getNumber().isPresent();
}

public static final class KeyDifferenceResult {
private final List<StorageId> remoteOnlyKeys;
private final List<StorageId> localOnlyKeys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public final class FeatureFlags {

private static final long FETCH_INTERVAL = TimeUnit.HOURS.toMillis(0);

private static final String UUIDS = "android.uuids";
private static final String USERNAMES = "android.usernames";
private static final String ATTACHMENTS_V3 = "android.attachmentsV3.2";
private static final String REMOTE_DELETE = "android.remoteDelete";
Expand Down Expand Up @@ -169,16 +168,9 @@ public static synchronized void update(@NonNull Map<String, Object> config) {
Log.i(TAG, "[Disk] After : " + result.getDisk().toString());
}

/** Whether or not we allow UUID-only contacts. */
public static synchronized boolean uuidOnlyContacts() {
return getBoolean(UUIDS, false);
}

/** Creating usernames, sending messages by username. Requires {@link #uuidOnlyContacts()}. */
public static synchronized boolean usernames() {
boolean value = getBoolean(USERNAMES, false);
if (value && !uuidOnlyContacts()) throw new MissingFlagRequirementError();
return value;
return getBoolean(USERNAMES, false);
}

/** Whether or not we use the attachments v3 form. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ public void resolveConflict_unknowns() {

@Test
public void resolveConflict_complex() {
when(FeatureFlags.uuidOnlyContacts()).thenReturn(true);

SignalContactRecord remote1 = contact(1, UUID_A, null, "a");
SignalContactRecord local1 = contact(2, UUID_A, E164_A, "a");

Expand Down

0 comments on commit 870cee5

Please sign in to comment.