mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 10:20:25 +01:00
Phone number privacy settings and certificate support behind feature flag.
This commit is contained in:
committed by
Cody Henthorne
parent
abd3d4b546
commit
7b24e66ed3
@@ -0,0 +1,6 @@
|
||||
package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
public enum CertificateType {
|
||||
UUID_AND_E164,
|
||||
UUID_ONLY
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
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";
|
||||
|
||||
CertificateValues(@NonNull KeyValueStore store) {
|
||||
super(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onFirstEverAppLaunch() {
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public void setUnidentifiedAccessCertificate(@NonNull CertificateType certificateType,
|
||||
@Nullable byte[] certificate)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
writer.commit();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
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;
|
||||
|
||||
public final class PhoneNumberPrivacyValues extends SignalStoreValues {
|
||||
|
||||
public static final String SHARING_MODE = "phoneNumberPrivacy.sharingMode";
|
||||
public static final String LISTING_MODE = "phoneNumberPrivacy.listingMode";
|
||||
|
||||
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));
|
||||
|
||||
PhoneNumberPrivacyValues(@NonNull KeyValueStore store) {
|
||||
super(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onFirstEverAppLaunch() {
|
||||
// TODO [ALAN] PhoneNumberPrivacy: During registration, set the attribute to so that new registrations start out as not listed
|
||||
//getStore().beginWrite()
|
||||
// .putInteger(LISTING_MODE, PhoneNumberListingMode.UNLISTED.ordinal())
|
||||
// .apply();
|
||||
}
|
||||
|
||||
public @NonNull PhoneNumberSharingMode getPhoneNumberSharingMode() {
|
||||
if (!FeatureFlags.phoneNumberPrivacy()) return PhoneNumberSharingMode.EVERYONE;
|
||||
return PhoneNumberSharingMode.values()[getInteger(SHARING_MODE, PhoneNumberSharingMode.EVERYONE.ordinal())];
|
||||
}
|
||||
|
||||
public void setPhoneNumberSharingMode(@NonNull PhoneNumberSharingMode phoneNumberSharingMode) {
|
||||
putInteger(SHARING_MODE, phoneNumberSharingMode.ordinal());
|
||||
}
|
||||
|
||||
public @NonNull PhoneNumberListingMode getPhoneNumberListingMode() {
|
||||
if (!FeatureFlags.phoneNumberPrivacy()) return PhoneNumberListingMode.LISTED;
|
||||
return PhoneNumberListingMode.values()[getInteger(LISTING_MODE, PhoneNumberListingMode.LISTED.ordinal())];
|
||||
}
|
||||
|
||||
public void setPhoneNumberListingMode(@NonNull PhoneNumberListingMode phoneNumberListingMode) {
|
||||
putInteger(LISTING_MODE, phoneNumberListingMode.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* If you respect {@link #getPhoneNumberSharingMode}, then you will only ever need to fetch and store
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All certificate types required according to the feature flags.
|
||||
*/
|
||||
public Collection<CertificateType> getAllCertificateTypes() {
|
||||
return FeatureFlags.phoneNumberPrivacy() ? BOTH_CERTIFICATES : REGULAR_CERTIFICATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialized, do not change ordinal/order
|
||||
*/
|
||||
public enum PhoneNumberSharingMode {
|
||||
EVERYONE,
|
||||
CONTACTS,
|
||||
NOBODY
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialized, do not change ordinal/order
|
||||
*/
|
||||
public enum PhoneNumberListingMode {
|
||||
LISTED,
|
||||
UNLISTED
|
||||
}
|
||||
}
|
||||
@@ -13,32 +13,36 @@ public final class SignalStore {
|
||||
|
||||
private static final SignalStore INSTANCE = new SignalStore();
|
||||
|
||||
private final KeyValueStore store;
|
||||
private final KbsValues kbsValues;
|
||||
private final RegistrationValues registrationValues;
|
||||
private final PinValues pinValues;
|
||||
private final RemoteConfigValues remoteConfigValues;
|
||||
private final StorageServiceValues storageServiceValues;
|
||||
private final UiHints uiHints;
|
||||
private final TooltipValues tooltipValues;
|
||||
private final MiscellaneousValues misc;
|
||||
private final InternalValues internalValues;
|
||||
private final EmojiValues emojiValues;
|
||||
private final SettingsValues settingsValues;
|
||||
private final KeyValueStore store;
|
||||
private final KbsValues kbsValues;
|
||||
private final RegistrationValues registrationValues;
|
||||
private final PinValues pinValues;
|
||||
private final RemoteConfigValues remoteConfigValues;
|
||||
private final StorageServiceValues storageServiceValues;
|
||||
private final UiHints uiHints;
|
||||
private final TooltipValues tooltipValues;
|
||||
private final MiscellaneousValues misc;
|
||||
private final InternalValues internalValues;
|
||||
private final EmojiValues emojiValues;
|
||||
private final SettingsValues settingsValues;
|
||||
private final CertificateValues certificateValues;
|
||||
private final PhoneNumberPrivacyValues phoneNumberPrivacyValues;
|
||||
|
||||
private SignalStore() {
|
||||
this.store = ApplicationDependencies.getKeyValueStore();
|
||||
this.kbsValues = new KbsValues(store);
|
||||
this.registrationValues = new RegistrationValues(store);
|
||||
this.pinValues = new PinValues(store);
|
||||
this.remoteConfigValues = new RemoteConfigValues(store);
|
||||
this.storageServiceValues = new StorageServiceValues(store);
|
||||
this.uiHints = new UiHints(store);
|
||||
this.tooltipValues = new TooltipValues(store);
|
||||
this.misc = new MiscellaneousValues(store);
|
||||
this.internalValues = new InternalValues(store);
|
||||
this.emojiValues = new EmojiValues(store);
|
||||
this.settingsValues = new SettingsValues(store);
|
||||
this.store = ApplicationDependencies.getKeyValueStore();
|
||||
this.kbsValues = new KbsValues(store);
|
||||
this.registrationValues = new RegistrationValues(store);
|
||||
this.pinValues = new PinValues(store);
|
||||
this.remoteConfigValues = new RemoteConfigValues(store);
|
||||
this.storageServiceValues = new StorageServiceValues(store);
|
||||
this.uiHints = new UiHints(store);
|
||||
this.tooltipValues = new TooltipValues(store);
|
||||
this.misc = new MiscellaneousValues(store);
|
||||
this.internalValues = new InternalValues(store);
|
||||
this.emojiValues = new EmojiValues(store);
|
||||
this.settingsValues = new SettingsValues(store);
|
||||
this.certificateValues = new CertificateValues(store);
|
||||
this.phoneNumberPrivacyValues = new PhoneNumberPrivacyValues(store);
|
||||
}
|
||||
|
||||
public static void onFirstEverAppLaunch() {
|
||||
@@ -52,6 +56,8 @@ public final class SignalStore {
|
||||
misc().onFirstEverAppLaunch();
|
||||
internalValues().onFirstEverAppLaunch();
|
||||
settings().onFirstEverAppLaunch();
|
||||
certificateValues().onFirstEverAppLaunch();
|
||||
phoneNumberPrivacy().onFirstEverAppLaunch();
|
||||
}
|
||||
|
||||
public static @NonNull KbsValues kbsValues() {
|
||||
@@ -98,6 +104,14 @@ public final class SignalStore {
|
||||
return INSTANCE.settingsValues;
|
||||
}
|
||||
|
||||
public static @NonNull CertificateValues certificateValues() {
|
||||
return INSTANCE.certificateValues;
|
||||
}
|
||||
|
||||
public static @NonNull PhoneNumberPrivacyValues phoneNumberPrivacy() {
|
||||
return INSTANCE.phoneNumberPrivacyValues;
|
||||
}
|
||||
|
||||
public static @NonNull GroupsV2AuthorizationSignalStoreCache groupsV2AuthorizationCache() {
|
||||
return new GroupsV2AuthorizationSignalStoreCache(getStore());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user