Update enum for phone number sharing mode.

This commit is contained in:
Greyson Parrelli
2023-10-20 08:20:13 -07:00
committed by Cody Henthorne
parent 6295041341
commit d866646f66
11 changed files with 90 additions and 91 deletions

View File

@@ -1,6 +1,6 @@
package org.thoughtcrime.securesms.keyvalue;
public enum CertificateType {
UUID_AND_E164,
UUID_ONLY
ACI_AND_E164,
ACI_ONLY
}

View File

@@ -9,8 +9,8 @@ import java.util.List;
public final class CertificateValues extends SignalStoreValues {
private static final String UD_CERTIFICATE_UUID_AND_E164 = "certificate.uuidAndE164";
private static final String UD_CERTIFICATE_UUID_ONLY = "certificate.uuidOnly";
private static final String SEALED_SENDER_CERT_ACI_AND_E164 = "certificate.uuidAndE164";
private static final String SEALED_SENDER_CERT_ACI_ONLY = "certificate.uuidOnly";
CertificateValues(@NonNull KeyValueStore store) {
super(store);
@@ -32,9 +32,9 @@ public final class CertificateValues extends SignalStoreValues {
KeyValueStore.Writer writer = getStore().beginWrite();
switch (certificateType) {
case UUID_AND_E164: writer.putBlob(UD_CERTIFICATE_UUID_AND_E164, certificate); break;
case UUID_ONLY : writer.putBlob(UD_CERTIFICATE_UUID_ONLY, certificate); break;
default : throw new AssertionError();
case ACI_AND_E164: writer.putBlob(SEALED_SENDER_CERT_ACI_AND_E164, certificate); break;
case ACI_ONLY : writer.putBlob(SEALED_SENDER_CERT_ACI_ONLY, certificate); break;
default : throw new AssertionError();
}
writer.commit();
@@ -42,9 +42,9 @@ public final class CertificateValues extends SignalStoreValues {
public @Nullable byte[] getUnidentifiedAccessCertificate(@NonNull CertificateType certificateType) {
switch (certificateType) {
case UUID_AND_E164: return getBlob(UD_CERTIFICATE_UUID_AND_E164, null);
case UUID_ONLY : return getBlob(UD_CERTIFICATE_UUID_ONLY, null);
default : throw new AssertionError();
case ACI_AND_E164: return getBlob(SEALED_SENDER_CERT_ACI_AND_E164, null);
case ACI_ONLY : return getBlob(SEALED_SENDER_CERT_ACI_ONLY, null);
default : throw new AssertionError();
}
}

View File

@@ -2,8 +2,6 @@ package org.thoughtcrime.securesms.keyvalue;
import androidx.annotation.NonNull;
import org.thoughtcrime.securesms.util.FeatureFlags;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -15,9 +13,9 @@ public final class PhoneNumberPrivacyValues extends SignalStoreValues {
public static final String LISTING_MODE = "phoneNumberPrivacy.listingMode";
public static final String LISTING_TIMESTAMP = "phoneNumberPrivacy.listingMode.timestamp";
private static final Collection<CertificateType> REGULAR_CERTIFICATE = Collections.singletonList(CertificateType.UUID_AND_E164);
private static final Collection<CertificateType> PRIVACY_CERTIFICATE = Collections.singletonList(CertificateType.UUID_ONLY);
private static final Collection<CertificateType> BOTH_CERTIFICATES = Collections.unmodifiableCollection(Arrays.asList(CertificateType.UUID_AND_E164, CertificateType.UUID_ONLY));
private static final Collection<CertificateType> ACI_AND_E164_CERTIFICATE = Collections.singletonList(CertificateType.ACI_AND_E164);
private static final Collection<CertificateType> ACI_ONLY_CERTIFICATE = Collections.singletonList(CertificateType.ACI_ONLY);
private static final Collection<CertificateType> BOTH_CERTIFICATES = Collections.unmodifiableCollection(Arrays.asList(CertificateType.ACI_AND_E164, CertificateType.ACI_ONLY));
PhoneNumberPrivacyValues(@NonNull KeyValueStore store) {
super(store);
@@ -36,14 +34,30 @@ public final class PhoneNumberPrivacyValues extends SignalStoreValues {
return Arrays.asList(SHARING_MODE, LISTING_MODE, LISTING_TIMESTAMP);
}
/**
* Note: Only giving raw access to the underlying value for storage service.
* Most callers should use {@link #isPhoneNumberSharingEnabled()}.
*/
public @NonNull PhoneNumberSharingMode getPhoneNumberSharingMode() {
return PhoneNumberSharingMode.deserialize(getInteger(SHARING_MODE, PhoneNumberSharingMode.EVERYONE.serialize()));
return PhoneNumberSharingMode.deserialize(getInteger(SHARING_MODE, PhoneNumberSharingMode.DEFAULT.serialize()));
}
public boolean isPhoneNumberSharingEnabled() {
// TODO [pnp] When we launch usernames, the default should return false
return switch (getPhoneNumberSharingMode()) {
case DEFAULT, EVERYBODY -> true;
case NOBODY -> false;
};
}
public void setPhoneNumberSharingMode(@NonNull PhoneNumberSharingMode phoneNumberSharingMode) {
putInteger(SHARING_MODE, phoneNumberSharingMode.serialize());
}
public boolean isDiscoverableByPhoneNumber() {
return getPhoneNumberListingMode() == PhoneNumberPrivacyValues.PhoneNumberListingMode.LISTED;
}
public @NonNull PhoneNumberListingMode getPhoneNumberListingMode() {
return PhoneNumberListingMode.deserialize(getInteger(LISTING_MODE, PhoneNumberListingMode.LISTED.serialize()));
}
@@ -65,11 +79,10 @@ public final class PhoneNumberPrivacyValues extends SignalStoreValues {
* these certificates types.
*/
public Collection<CertificateType> getRequiredCertificateTypes() {
switch (getPhoneNumberSharingMode()) {
case EVERYONE: return REGULAR_CERTIFICATE;
case CONTACTS: return BOTH_CERTIFICATES;
case NOBODY : return PRIVACY_CERTIFICATE;
default : throw new AssertionError();
if (isPhoneNumberSharingEnabled()) {
return ACI_AND_E164_CERTIFICATE;
} else {
return ACI_ONLY_CERTIFICATE;
}
}
@@ -81,8 +94,8 @@ public final class PhoneNumberPrivacyValues extends SignalStoreValues {
}
public enum PhoneNumberSharingMode {
EVERYONE(0),
CONTACTS(1),
DEFAULT(0),
EVERYBODY(1),
NOBODY(2);
private final int code;