Skip to content

Commit

Permalink
Read the new GV1 Migration capability.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal authored and alan-signal committed Oct 22, 2020
1 parent 3357475 commit d217826
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ public final class AppCapabilities {
private AppCapabilities() {
}

private static final boolean UUID_CAPABLE = false;
private static final boolean GV2_CAPABLE = true;
private static final boolean UUID_CAPABLE = false;
private static final boolean GV2_CAPABLE = true;
private static final boolean GV1_MIGRATION_CAPABLE = false;

/**
* @param storageCapable Whether or not the user can use storage service. This is another way of
* asking if the user has set a Signal PIN or not.
*/
public static AccountAttributes.Capabilities getCapabilities(boolean storageCapable) {
return new AccountAttributes.Capabilities(UUID_CAPABLE, GV2_CAPABLE, storageCapable);
return new AccountAttributes.Capabilities(UUID_CAPABLE, GV2_CAPABLE, storageCapable, GV1_MIGRATION_CAPABLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ public class RecipientDatabase extends Database {

private static final class Capabilities {
static final int BIT_LENGTH = 2;
static final int GROUPS_V2 = 0;

static final int GROUPS_V2 = 0;
static final int GROUPS_V1_MIGRATION = 1;
}

private static final String[] RECIPIENT_PROJECTION = new String[] {
Expand Down Expand Up @@ -1410,7 +1412,8 @@ public void setUnidentifiedAccessMode(@NonNull RecipientId id, @NonNull Unidenti
public void setCapabilities(@NonNull RecipientId id, @NonNull SignalServiceProfile.Capabilities capabilities) {
long value = 0;

value = Bitmask.update(value, Capabilities.GROUPS_V2, Capabilities.BIT_LENGTH, Recipient.Capability.fromBoolean(capabilities.isGv2()).serialize());
value = Bitmask.update(value, Capabilities.GROUPS_V2, Capabilities.BIT_LENGTH, Recipient.Capability.fromBoolean(capabilities.isGv2()).serialize());
value = Bitmask.update(value, Capabilities.GROUPS_V1_MIGRATION, Capabilities.BIT_LENGTH, Recipient.Capability.fromBoolean(capabilities.isGv1Migration()).serialize());

ContentValues values = new ContentValues(1);
values.put(CAPABILITIES, value);
Expand Down Expand Up @@ -2599,6 +2602,7 @@ public static class RecipientSettings {
private final boolean forceSmsSelection;
private final long capabilities;
private final Recipient.Capability groupsV2Capability;
private final Recipient.Capability groupsV1MigrationCapability;
private final InsightsBannerTier insightsBannerTier;
private final byte[] storageId;
private final MentionSetting mentionSetting;
Expand Down Expand Up @@ -2641,43 +2645,44 @@ public static class RecipientSettings {
@NonNull MentionSetting mentionSetting,
@NonNull SyncExtras syncExtras)
{
this.id = id;
this.uuid = uuid;
this.username = username;
this.e164 = e164;
this.email = email;
this.groupId = groupId;
this.groupType = groupType;
this.blocked = blocked;
this.muteUntil = muteUntil;
this.messageVibrateState = messageVibrateState;
this.callVibrateState = callVibrateState;
this.messageRingtone = messageRingtone;
this.callRingtone = callRingtone;
this.color = color;
this.defaultSubscriptionId = defaultSubscriptionId;
this.expireMessages = expireMessages;
this.registered = registered;
this.profileKey = profileKey;
this.profileKeyCredential = profileKeyCredential;
this.systemDisplayName = systemDisplayName;
this.systemContactPhoto = systemContactPhoto;
this.systemPhoneLabel = systemPhoneLabel;
this.systemContactUri = systemContactUri;
this.signalProfileName = signalProfileName;
this.signalProfileAvatar = signalProfileAvatar;
this.hasProfileImage = hasProfileImage;
this.profileSharing = profileSharing;
this.lastProfileFetch = lastProfileFetch;
this.notificationChannel = notificationChannel;
this.unidentifiedAccessMode = unidentifiedAccessMode;
this.forceSmsSelection = forceSmsSelection;
this.capabilities = capabilities;
this.groupsV2Capability = Recipient.Capability.deserialize((int) Bitmask.read(capabilities, Capabilities.GROUPS_V2, Capabilities.BIT_LENGTH));
this.insightsBannerTier = insightsBannerTier;
this.storageId = storageId;
this.mentionSetting = mentionSetting;
this.syncExtras = syncExtras;
this.id = id;
this.uuid = uuid;
this.username = username;
this.e164 = e164;
this.email = email;
this.groupId = groupId;
this.groupType = groupType;
this.blocked = blocked;
this.muteUntil = muteUntil;
this.messageVibrateState = messageVibrateState;
this.callVibrateState = callVibrateState;
this.messageRingtone = messageRingtone;
this.callRingtone = callRingtone;
this.color = color;
this.defaultSubscriptionId = defaultSubscriptionId;
this.expireMessages = expireMessages;
this.registered = registered;
this.profileKey = profileKey;
this.profileKeyCredential = profileKeyCredential;
this.systemDisplayName = systemDisplayName;
this.systemContactPhoto = systemContactPhoto;
this.systemPhoneLabel = systemPhoneLabel;
this.systemContactUri = systemContactUri;
this.signalProfileName = signalProfileName;
this.signalProfileAvatar = signalProfileAvatar;
this.hasProfileImage = hasProfileImage;
this.profileSharing = profileSharing;
this.lastProfileFetch = lastProfileFetch;
this.notificationChannel = notificationChannel;
this.unidentifiedAccessMode = unidentifiedAccessMode;
this.forceSmsSelection = forceSmsSelection;
this.capabilities = capabilities;
this.groupsV2Capability = Recipient.Capability.deserialize((int) Bitmask.read(capabilities, Capabilities.GROUPS_V2, Capabilities.BIT_LENGTH));
this.groupsV1MigrationCapability = Recipient.Capability.deserialize((int) Bitmask.read(capabilities, Capabilities.GROUPS_V1_MIGRATION, Capabilities.BIT_LENGTH));
this.insightsBannerTier = insightsBannerTier;
this.storageId = storageId;
this.mentionSetting = mentionSetting;
this.syncExtras = syncExtras;
}

public RecipientId getId() {
Expand Down Expand Up @@ -2808,10 +2813,14 @@ public boolean isForceSmsSelection() {
return forceSmsSelection;
}

public Recipient.Capability getGroupsV2Capability() {
public @NonNull Recipient.Capability getGroupsV2Capability() {
return groupsV2Capability;
}

public @NonNull Recipient.Capability getGroupsV1MigrationCapability() {
return groupsV1MigrationCapability;
}

public @Nullable byte[] getStorageId() {
return storageId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void onRun() throws IOException {
"\n Capabilities:" +
"\n Storage? " + capabilities.isStorage() +
"\n GV2? " + capabilities.isGv2() +
"\n GV1 Migration? " + capabilities.isGv1Migration() +
"\n UUID? " + capabilities.isUuid());

SignalServiceAccountManager signalAccountManager = ApplicationDependencies.getSignalServiceAccountManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public final class LogSectionCapabilities implements LogSection {

AccountAttributes.Capabilities capabilities = AppCapabilities.getCapabilities(false);

return new StringBuilder().append("Local device GV2: ").append(capabilities.isGv2()).append("\n")
.append("Global GV2 : ").append(self.getGroupsV2Capability()).append("\n");
return new StringBuilder().append("-- Local").append("\n")
.append("GV2 : ").append(capabilities.isGv2()).append("\n")
.append("GV1 Migration: ").append(capabilities.isGv1Migration()).append("\n")
.append("\n")
.append("-- Global").append("\n")
.append("GV2 : ").append(self.getGroupsV2Capability()).append("\n")
.append("GV1 Migration: ").append(self.getGroupsV1MigrationCapability()).append("\n");
}
}
161 changes: 84 additions & 77 deletions app/src/main/java/org/thoughtcrime/securesms/recipients/Recipient.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class Recipient {
private final UnidentifiedAccessMode unidentifiedAccessMode;
private final boolean forceSmsSelection;
private final Capability groupsV2Capability;
private final Capability groupsV1MigrationCapability;
private final InsightsBannerTier insightsBannerTier;
private final byte[] storageId;
private final MentionSetting mentionSetting;
Expand Down Expand Up @@ -275,85 +276,87 @@ public class Recipient {
}

Recipient(@NonNull RecipientId id) {
this.id = id;
this.resolving = true;
this.uuid = null;
this.username = null;
this.e164 = null;
this.email = null;
this.groupId = null;
this.participants = Collections.emptyList();
this.groupAvatarId = Optional.absent();
this.isSelf = false;
this.blocked = false;
this.muteUntil = 0;
this.messageVibrate = VibrateState.DEFAULT;
this.callVibrate = VibrateState.DEFAULT;
this.messageRingtone = null;
this.callRingtone = null;
this.color = null;
this.insightsBannerTier = InsightsBannerTier.TIER_TWO;
this.defaultSubscriptionId = Optional.absent();
this.expireMessages = 0;
this.registered = RegisteredState.UNKNOWN;
this.profileKey = null;
this.profileKeyCredential = null;
this.name = null;
this.systemContactPhoto = null;
this.customLabel = null;
this.contactUri = null;
this.profileName = ProfileName.EMPTY;
this.profileAvatar = null;
this.hasProfileImage = false;
this.profileSharing = false;
this.lastProfileFetch = 0;
this.notificationChannel = null;
this.unidentifiedAccessMode = UnidentifiedAccessMode.DISABLED;
this.forceSmsSelection = false;
this.groupsV2Capability = Capability.UNKNOWN;
this.storageId = null;
this.mentionSetting = MentionSetting.ALWAYS_NOTIFY;
this.id = id;
this.resolving = true;
this.uuid = null;
this.username = null;
this.e164 = null;
this.email = null;
this.groupId = null;
this.participants = Collections.emptyList();
this.groupAvatarId = Optional.absent();
this.isSelf = false;
this.blocked = false;
this.muteUntil = 0;
this.messageVibrate = VibrateState.DEFAULT;
this.callVibrate = VibrateState.DEFAULT;
this.messageRingtone = null;
this.callRingtone = null;
this.color = null;
this.insightsBannerTier = InsightsBannerTier.TIER_TWO;
this.defaultSubscriptionId = Optional.absent();
this.expireMessages = 0;
this.registered = RegisteredState.UNKNOWN;
this.profileKey = null;
this.profileKeyCredential = null;
this.name = null;
this.systemContactPhoto = null;
this.customLabel = null;
this.contactUri = null;
this.profileName = ProfileName.EMPTY;
this.profileAvatar = null;
this.hasProfileImage = false;
this.profileSharing = false;
this.lastProfileFetch = 0;
this.notificationChannel = null;
this.unidentifiedAccessMode = UnidentifiedAccessMode.DISABLED;
this.forceSmsSelection = false;
this.groupsV2Capability = Capability.UNKNOWN;
this.groupsV1MigrationCapability = Capability.UNKNOWN;
this.storageId = null;
this.mentionSetting = MentionSetting.ALWAYS_NOTIFY;
}

public Recipient(@NonNull RecipientId id, @NonNull RecipientDetails details, boolean resolved) {
this.id = id;
this.resolving = !resolved;
this.uuid = details.uuid;
this.username = details.username;
this.e164 = details.e164;
this.email = details.email;
this.groupId = details.groupId;
this.participants = details.participants;
this.groupAvatarId = details.groupAvatarId;
this.isSelf = details.isSelf;
this.blocked = details.blocked;
this.muteUntil = details.mutedUntil;
this.messageVibrate = details.messageVibrateState;
this.callVibrate = details.callVibrateState;
this.messageRingtone = details.messageRingtone;
this.callRingtone = details.callRingtone;
this.color = details.color;
this.insightsBannerTier = details.insightsBannerTier;
this.defaultSubscriptionId = details.defaultSubscriptionId;
this.expireMessages = details.expireMessages;
this.registered = details.registered;
this.profileKey = details.profileKey;
this.profileKeyCredential = details.profileKeyCredential;
this.name = details.name;
this.systemContactPhoto = details.systemContactPhoto;
this.customLabel = details.customLabel;
this.contactUri = details.contactUri;
this.profileName = details.profileName;
this.profileAvatar = details.profileAvatar;
this.hasProfileImage = details.hasProfileImage;
this.profileSharing = details.profileSharing;
this.lastProfileFetch = details.lastProfileFetch;
this.notificationChannel = details.notificationChannel;
this.unidentifiedAccessMode = details.unidentifiedAccessMode;
this.forceSmsSelection = details.forceSmsSelection;
this.groupsV2Capability = details.groupsV2Capability;
this.storageId = details.storageId;
this.mentionSetting = details.mentionSetting;
this.id = id;
this.resolving = !resolved;
this.uuid = details.uuid;
this.username = details.username;
this.e164 = details.e164;
this.email = details.email;
this.groupId = details.groupId;
this.participants = details.participants;
this.groupAvatarId = details.groupAvatarId;
this.isSelf = details.isSelf;
this.blocked = details.blocked;
this.muteUntil = details.mutedUntil;
this.messageVibrate = details.messageVibrateState;
this.callVibrate = details.callVibrateState;
this.messageRingtone = details.messageRingtone;
this.callRingtone = details.callRingtone;
this.color = details.color;
this.insightsBannerTier = details.insightsBannerTier;
this.defaultSubscriptionId = details.defaultSubscriptionId;
this.expireMessages = details.expireMessages;
this.registered = details.registered;
this.profileKey = details.profileKey;
this.profileKeyCredential = details.profileKeyCredential;
this.name = details.name;
this.systemContactPhoto = details.systemContactPhoto;
this.customLabel = details.customLabel;
this.contactUri = details.contactUri;
this.profileName = details.profileName;
this.profileAvatar = details.profileAvatar;
this.hasProfileImage = details.hasProfileImage;
this.profileSharing = details.profileSharing;
this.lastProfileFetch = details.lastProfileFetch;
this.notificationChannel = details.notificationChannel;
this.unidentifiedAccessMode = details.unidentifiedAccessMode;
this.forceSmsSelection = details.forceSmsSelection;
this.groupsV2Capability = details.groupsV2Capability;
this.groupsV1MigrationCapability = details.groupsV1MigrationCapability;
this.storageId = details.storageId;
this.mentionSetting = details.mentionSetting;
}

public @NonNull RecipientId getId() {
Expand Down Expand Up @@ -737,10 +740,14 @@ public boolean isForceSmsSelection() {
return forceSmsSelection;
}

public Capability getGroupsV2Capability() {
public @NonNull Capability getGroupsV2Capability() {
return groupsV2Capability;
}

public @NonNull Capability getGroupsV1MigrationCapability() {
return groupsV1MigrationCapability;
}

public @Nullable byte[] getProfileKey() {
return profileKey;
}
Expand Down

0 comments on commit d217826

Please sign in to comment.