Skip to content

Commit

Permalink
Improve logging and the naming of some fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Jan 23, 2024
1 parent 64fff2a commit e361795
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 63 deletions.
Expand Up @@ -255,7 +255,7 @@ class BackupTest {
SignalStore.donationsValues().setSubscriber(Subscriber(SubscriberId.generate(), "USD"))
SignalStore.donationsValues().setDisplayBadgesOnProfile(false)

SignalStore.phoneNumberPrivacy().phoneNumberListingMode = PhoneNumberPrivacyValues.PhoneNumberListingMode.UNLISTED
SignalStore.phoneNumberPrivacy().phoneNumberDiscoverabilityMode = PhoneNumberPrivacyValues.PhoneNumberDiscoverabilityMode.NOT_DISCOVERABLE
SignalStore.phoneNumberPrivacy().phoneNumberSharingMode = PhoneNumberPrivacyValues.PhoneNumberSharingMode.NOBODY

SignalStore.settings().isLinkPreviewsEnabled = false
Expand Down
Expand Up @@ -56,7 +56,7 @@ object AccountDataProcessor {
readReceipts = TextSecurePreferences.isReadReceiptsEnabled(context),
sealedSenderIndicators = TextSecurePreferences.isShowUnidentifiedDeliveryIndicatorsEnabled(context),
linkPreviews = SignalStore.settings().isLinkPreviewsEnabled,
notDiscoverableByPhoneNumber = SignalStore.phoneNumberPrivacy().phoneNumberListingMode.isUnlisted,
notDiscoverableByPhoneNumber = SignalStore.phoneNumberPrivacy().phoneNumberDiscoverabilityMode.isUndiscoverable,
phoneNumberSharingMode = SignalStore.phoneNumberPrivacy().phoneNumberSharingMode.toBackupPhoneNumberSharingMode(),
preferContactAvatars = SignalStore.settings().isPreferSystemContactPhotos,
universalExpireTimer = SignalStore.settings().universalExpireTimer,
Expand Down Expand Up @@ -86,7 +86,7 @@ object AccountDataProcessor {
TextSecurePreferences.setTypingIndicatorsEnabled(context, settings.typingIndicators)
TextSecurePreferences.setShowUnidentifiedDeliveryIndicatorsEnabled(context, settings.sealedSenderIndicators)
SignalStore.settings().isLinkPreviewsEnabled = settings.linkPreviews
SignalStore.phoneNumberPrivacy().phoneNumberListingMode = if (settings.notDiscoverableByPhoneNumber) PhoneNumberPrivacyValues.PhoneNumberListingMode.UNLISTED else PhoneNumberPrivacyValues.PhoneNumberListingMode.LISTED
SignalStore.phoneNumberPrivacy().phoneNumberDiscoverabilityMode = if (settings.notDiscoverableByPhoneNumber) PhoneNumberPrivacyValues.PhoneNumberDiscoverabilityMode.NOT_DISCOVERABLE else PhoneNumberPrivacyValues.PhoneNumberDiscoverabilityMode.DISCOVERABLE
SignalStore.phoneNumberPrivacy().phoneNumberSharingMode = settings.phoneNumberSharingMode.toLocalPhoneNumberMode()
SignalStore.settings().isPreferSystemContactPhotos = settings.preferContactAvatars
SignalStore.settings().universalExpireTimer = settings.universalExpireTimer
Expand Down
Expand Up @@ -8,7 +8,7 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.jobs.ProfileUploadJob
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob
import org.thoughtcrime.securesms.jobs.RefreshOwnProfileJob
import org.thoughtcrime.securesms.keyvalue.PhoneNumberPrivacyValues.PhoneNumberListingMode
import org.thoughtcrime.securesms.keyvalue.PhoneNumberPrivacyValues.PhoneNumberDiscoverabilityMode
import org.thoughtcrime.securesms.keyvalue.PhoneNumberPrivacyValues.PhoneNumberSharingMode
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.recipients.Recipient
Expand Down Expand Up @@ -51,7 +51,7 @@ class PhoneNumberPrivacySettingsViewModel : ViewModel() {
}

private fun setDiscoverableByPhoneNumber(discoverable: Boolean) {
SignalStore.phoneNumberPrivacy().phoneNumberListingMode = if (discoverable) PhoneNumberListingMode.LISTED else PhoneNumberListingMode.UNLISTED
SignalStore.phoneNumberPrivacy().phoneNumberDiscoverabilityMode = if (discoverable) PhoneNumberDiscoverabilityMode.DISCOVERABLE else PhoneNumberDiscoverabilityMode.NOT_DISCOVERABLE
StorageSyncHelper.scheduleSyncForDataChange()
ApplicationDependencies.getJobManager().startChain(RefreshAttributesJob()).then(RefreshOwnProfileJob()).enqueue()
refresh()
Expand Down
Expand Up @@ -3677,7 +3677,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
SqlUtil.buildCollectionQuery(ID, missingFromCds).forEach { query ->
writableDatabase
.update(TABLE_NAME)
.values(PHONE_NUMBER_DISCOVERABLE to PhoneNumberDiscoverableState.UNDISCOVERABLE.id)
.values(PHONE_NUMBER_DISCOVERABLE to PhoneNumberDiscoverableState.NOT_DISCOVERABLE.id)
.where(query.where, query.whereArgs)
.run()
}
Expand Down Expand Up @@ -4189,15 +4189,15 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
put(SYSTEM_CONTACT_URI, systemContactUri)
}

val updateQuery = SqlUtil.buildTrueUpdateQuery("$ID = ? AND $PHONE_NUMBER_DISCOVERABLE != ?", SqlUtil.buildArgs(id, PhoneNumberDiscoverableState.UNDISCOVERABLE.id), refreshQualifyingValues)
val updateQuery = SqlUtil.buildTrueUpdateQuery("$ID = ? AND $PHONE_NUMBER_DISCOVERABLE != ?", SqlUtil.buildArgs(id, PhoneNumberDiscoverableState.NOT_DISCOVERABLE.id), refreshQualifyingValues)
if (update(updateQuery, refreshQualifyingValues)) {
pendingRecipients.add(id)
}

writableDatabase
.update(TABLE_NAME)
.values(SYSTEM_INFO_PENDING to 0)
.where("$ID = ? AND $PHONE_NUMBER_DISCOVERABLE != ?", id, PhoneNumberDiscoverableState.UNDISCOVERABLE.id)
.where("$ID = ? AND $PHONE_NUMBER_DISCOVERABLE != ?", id, PhoneNumberDiscoverableState.NOT_DISCOVERABLE.id)
.run()
}

Expand Down Expand Up @@ -4548,7 +4548,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
}

enum class PhoneNumberDiscoverableState(val id: Int) {
UNKNOWN(0), DISCOVERABLE(1), UNDISCOVERABLE(2);
UNKNOWN(0), DISCOVERABLE(1), NOT_DISCOVERABLE(2);

companion object {
fun fromId(id: Int): PhoneNumberDiscoverableState {
Expand Down
Expand Up @@ -97,7 +97,7 @@ public void onRun() throws IOException {
registrationLockV2 = svrValues.getRegistrationLockToken();
}

boolean phoneNumberDiscoverable = SignalStore.phoneNumberPrivacy().getPhoneNumberListingMode().isDiscoverable();
boolean phoneNumberDiscoverable = SignalStore.phoneNumberPrivacy().getPhoneNumberDiscoverabilityMode().isDiscoverable();

String deviceName = SignalStore.account().getDeviceName();
byte[] encryptedDeviceName = (deviceName == null) ? null : DeviceNameCipher.encryptDeviceName(deviceName.getBytes(StandardCharsets.UTF_8), SignalStore.account().getAciIdentityKey());
Expand Down
Expand Up @@ -9,9 +9,9 @@

public final class PhoneNumberPrivacyValues extends SignalStoreValues {

public static final String SHARING_MODE = "phoneNumberPrivacy.sharingMode";
public static final String LISTING_MODE = "phoneNumberPrivacy.listingMode";
public static final String LISTING_TIMESTAMP = "phoneNumberPrivacy.listingMode.timestamp";
public static final String SHARING_MODE = "phoneNumberPrivacy.sharingMode";
public static final String DISCOVERABILITY_MODE = "phoneNumberPrivacy.listingMode";
public static final String DISCOVERABILITY_TIMESTAMP = "phoneNumberPrivacy.listingMode.timestamp";

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);
Expand All @@ -31,7 +31,7 @@ void onFirstEverAppLaunch() {

@Override
@NonNull List<String> getKeysToIncludeInBackup() {
return Arrays.asList(SHARING_MODE, LISTING_MODE, LISTING_TIMESTAMP);
return Arrays.asList(SHARING_MODE, DISCOVERABILITY_MODE, DISCOVERABILITY_TIMESTAMP);
}

/**
Expand All @@ -55,23 +55,23 @@ public void setPhoneNumberSharingMode(@NonNull PhoneNumberSharingMode phoneNumbe
}

public boolean isDiscoverableByPhoneNumber() {
return getPhoneNumberListingMode() == PhoneNumberPrivacyValues.PhoneNumberListingMode.LISTED;
return getPhoneNumberDiscoverabilityMode() == PhoneNumberDiscoverabilityMode.DISCOVERABLE;
}

public @NonNull PhoneNumberListingMode getPhoneNumberListingMode() {
return PhoneNumberListingMode.deserialize(getInteger(LISTING_MODE, PhoneNumberListingMode.LISTED.serialize()));
public @NonNull PhoneNumberDiscoverabilityMode getPhoneNumberDiscoverabilityMode() {
return PhoneNumberDiscoverabilityMode.deserialize(getInteger(DISCOVERABILITY_MODE, PhoneNumberDiscoverabilityMode.DISCOVERABLE.serialize()));
}

public void setPhoneNumberListingMode(@NonNull PhoneNumberListingMode phoneNumberListingMode) {
public void setPhoneNumberDiscoverabilityMode(@NonNull PhoneNumberDiscoverabilityMode phoneNumberDiscoverabilityMode) {
getStore()
.beginWrite()
.putInteger(LISTING_MODE, phoneNumberListingMode.serialize())
.putLong(LISTING_TIMESTAMP, System.currentTimeMillis())
.putInteger(DISCOVERABILITY_MODE, phoneNumberDiscoverabilityMode.serialize())
.putLong(DISCOVERABILITY_TIMESTAMP, System.currentTimeMillis())
.apply();
}

public long getPhoneNumberListingModeTimestamp() {
return getLong(LISTING_TIMESTAMP, 0);
public long getPhoneNumberDiscoverabilityModeTimestamp() {
return getLong(DISCOVERABILITY_TIMESTAMP, 0);
}

/**
Expand Down Expand Up @@ -119,30 +119,30 @@ public static PhoneNumberSharingMode deserialize(int code) {
}
}

public enum PhoneNumberListingMode {
LISTED(0),
UNLISTED(1);
public enum PhoneNumberDiscoverabilityMode {
DISCOVERABLE(0),
NOT_DISCOVERABLE(1);

private final int code;

PhoneNumberListingMode(int code) {
PhoneNumberDiscoverabilityMode(int code) {
this.code = code;
}

public boolean isDiscoverable() {
return this == LISTED;
return this == DISCOVERABLE;
}

public boolean isUnlisted() {
return this == UNLISTED;
public boolean isUndiscoverable() {
return this == NOT_DISCOVERABLE;
}

public int serialize() {
return code;
}

public static PhoneNumberListingMode deserialize(int code) {
for (PhoneNumberListingMode value : PhoneNumberListingMode.values()) {
public static PhoneNumberDiscoverabilityMode deserialize(int code) {
for (PhoneNumberDiscoverabilityMode value : PhoneNumberDiscoverabilityMode.values()) {
if (value.code == code) {
return value;
}
Expand Down
Expand Up @@ -19,22 +19,24 @@ final class LogSectionKeyPreferences implements LogSection {

@Override
public @NonNull CharSequence getContent(@NonNull Context context) {
return new StringBuilder().append("Screen Lock : ").append(TextSecurePreferences.isScreenLockEnabled(context)).append("\n")
.append("Screen Lock Timeout : ").append(TextSecurePreferences.getScreenLockTimeout(context)).append("\n")
.append("Password Disabled : ").append(TextSecurePreferences.isPasswordDisabled(context)).append("\n")
.append("Prefer Contact Photos: ").append(SignalStore.settings().isPreferSystemContactPhotos()).append("\n")
.append("Call Data Mode : ").append(SignalStore.settings().getCallDataMode()).append("\n")
.append("Media Quality : ").append(SignalStore.settings().getSentMediaQuality()).append("\n")
.append("Client Deprecated : ").append(SignalStore.misc().isClientDeprecated()).append("\n")
.append("Push Registered : ").append(SignalStore.account().isRegistered()).append("\n")
.append("Unauthorized Received: ").append(TextSecurePreferences.isUnauthorizedReceived(context)).append("\n")
.append("self.isRegistered() : ").append(SignalStore.account().getAci() == null ? "false" : Recipient.self().isRegistered()).append("\n")
.append("Thread Trimming : ").append(getThreadTrimmingString()).append("\n")
.append("Censorship Setting : ").append(SignalStore.settings().getCensorshipCircumventionEnabled()).append("\n")
.append("Network Reachable : ").append(SignalStore.misc().isServiceReachableWithoutCircumvention()).append(", last checked: ").append(SignalStore.misc().getLastCensorshipServiceReachabilityCheckTime()).append("\n")
.append("Wifi Download : ").append(Util.join(TextSecurePreferences.getWifiMediaDownloadAllowed(context), ",")).append("\n")
.append("Roaming Download : ").append(Util.join(TextSecurePreferences.getRoamingMediaDownloadAllowed(context), ",")).append("\n")
.append("Mobile Download : ").append(Util.join(TextSecurePreferences.getMobileMediaDownloadAllowed(context), ",")).append("\n");
return new StringBuilder().append("Screen Lock : ").append(TextSecurePreferences.isScreenLockEnabled(context)).append("\n")
.append("Screen Lock Timeout : ").append(TextSecurePreferences.getScreenLockTimeout(context)).append("\n")
.append("Password Disabled : ").append(TextSecurePreferences.isPasswordDisabled(context)).append("\n")
.append("Prefer Contact Photos : ").append(SignalStore.settings().isPreferSystemContactPhotos()).append("\n")
.append("Call Data Mode : ").append(SignalStore.settings().getCallDataMode()).append("\n")
.append("Media Quality : ").append(SignalStore.settings().getSentMediaQuality()).append("\n")
.append("Client Deprecated : ").append(SignalStore.misc().isClientDeprecated()).append("\n")
.append("Push Registered : ").append(SignalStore.account().isRegistered()).append("\n")
.append("Unauthorized Received : ").append(TextSecurePreferences.isUnauthorizedReceived(context)).append("\n")
.append("self.isRegistered() : ").append(SignalStore.account().getAci() == null ? "false" : Recipient.self().isRegistered()).append("\n")
.append("Thread Trimming : ").append(getThreadTrimmingString()).append("\n")
.append("Censorship Setting : ").append(SignalStore.settings().getCensorshipCircumventionEnabled()).append("\n")
.append("Network Reachable : ").append(SignalStore.misc().isServiceReachableWithoutCircumvention()).append(", last checked: ").append(SignalStore.misc().getLastCensorshipServiceReachabilityCheckTime()).append("\n")
.append("Wifi Download : ").append(Util.join(TextSecurePreferences.getWifiMediaDownloadAllowed(context), ",")).append("\n")
.append("Roaming Download : ").append(Util.join(TextSecurePreferences.getRoamingMediaDownloadAllowed(context), ",")).append("\n")
.append("Mobile Download : ").append(Util.join(TextSecurePreferences.getMobileMediaDownloadAllowed(context), ",")).append("\n")
.append("Phone Number Sharing : ").append(SignalStore.phoneNumberPrivacy().isPhoneNumberSharingEnabled()).append(" (").append(SignalStore.phoneNumberPrivacy().getPhoneNumberSharingMode()).append(")\n")
.append("Phone Number Discoverable: ").append(SignalStore.phoneNumberPrivacy().isDiscoverableByPhoneNumber()).append(" (").append(SignalStore.phoneNumberPrivacy().getPhoneNumberDiscoverabilityMode()).append(")\n");
}

private static String getThreadTrimmingString() {
Expand Down
Expand Up @@ -415,12 +415,12 @@ private static boolean shouldShowAddAProfilePhotoMegaphone(@NonNull Context cont
private static boolean shouldShowSetUpYourUsernameMegaphone(@NonNull Map<Event, MegaphoneRecord> records) {
boolean hasUsername = SignalStore.account().isRegistered() && SignalStore.account().getUsername() != null;
boolean hasCompleted = MapUtil.mapOrDefault(records, Event.SET_UP_YOUR_USERNAME, MegaphoneRecord::isFinished, false);
long phoneNumberDiscoveryDisabledAt = SignalStore.phoneNumberPrivacy().getPhoneNumberListingModeTimestamp();
PhoneNumberPrivacyValues.PhoneNumberListingMode listingMode = SignalStore.phoneNumberPrivacy().getPhoneNumberListingMode();
long phoneNumberDiscoveryDisabledAt = SignalStore.phoneNumberPrivacy().getPhoneNumberDiscoverabilityModeTimestamp();
PhoneNumberPrivacyValues.PhoneNumberDiscoverabilityMode listingMode = SignalStore.phoneNumberPrivacy().getPhoneNumberDiscoverabilityMode();

return FeatureFlags.usernames() &&
!hasUsername &&
listingMode.isUnlisted() &&
listingMode.isUndiscoverable() &&
!hasCompleted &&
phoneNumberDiscoveryDisabledAt > 0 &&
(System.currentTimeMillis() - phoneNumberDiscoveryDisabledAt) >= TimeUnit.DAYS.toMillis(3);
Expand Down
Expand Up @@ -212,13 +212,13 @@ private void initializeResources(@Nullable GroupId groupId) {
if (FeatureFlags.phoneNumberPrivacy()) {
getParentFragmentManager().setFragmentResultListener(WhoCanFindMeByPhoneNumberFragment.REQUEST_KEY, getViewLifecycleOwner(), (requestKey, result) -> {
if (WhoCanFindMeByPhoneNumberFragment.REQUEST_KEY.equals(requestKey)) {
presentWhoCanFindMeDescription(SignalStore.phoneNumberPrivacy().getPhoneNumberListingMode());
presentWhoCanFindMeDescription(SignalStore.phoneNumberPrivacy().getPhoneNumberDiscoverabilityMode());
}
});

binding.whoCanFindMeContainer.setVisibility(View.VISIBLE);
binding.whoCanFindMeContainer.setOnClickListener(v -> SafeNavigation.safeNavigate(Navigation.findNavController(v), CreateProfileFragmentDirections.actionCreateProfileFragmentToPhoneNumberPrivacy()));
presentWhoCanFindMeDescription(SignalStore.phoneNumberPrivacy().getPhoneNumberListingMode());
presentWhoCanFindMeDescription(SignalStore.phoneNumberPrivacy().getPhoneNumberDiscoverabilityMode());
}
}

Expand Down Expand Up @@ -285,12 +285,12 @@ private static void updateFieldIfNeeded(@NonNull EditText field, @NonNull String
}
}

private void presentWhoCanFindMeDescription(PhoneNumberPrivacyValues.PhoneNumberListingMode phoneNumberListingMode) {
private void presentWhoCanFindMeDescription(PhoneNumberPrivacyValues.PhoneNumberDiscoverabilityMode phoneNumberListingMode) {
switch (phoneNumberListingMode) {
case LISTED:
case DISCOVERABLE:
binding.whoCanFindMeDescription.setText(R.string.PhoneNumberPrivacy_everyone);
break;
case UNLISTED:
case NOT_DISCOVERABLE:
binding.whoCanFindMeDescription.setText(R.string.PhoneNumberPrivacy_nobody);
break;
}
Expand Down

0 comments on commit e361795

Please sign in to comment.