mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 18:00:02 +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
@@ -7,6 +7,9 @@ import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.TextAppearanceSpan;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -14,6 +17,7 @@ import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.autofill.HintConstants;
|
||||
@@ -37,6 +41,7 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceConfigurationUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.KbsValues;
|
||||
import org.thoughtcrime.securesms.keyvalue.PhoneNumberPrivacyValues;
|
||||
import org.thoughtcrime.securesms.keyvalue.PinValues;
|
||||
import org.thoughtcrime.securesms.keyvalue.SettingsValues;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
@@ -45,13 +50,13 @@ import org.thoughtcrime.securesms.lock.v2.CreateKbsPinActivity;
|
||||
import org.thoughtcrime.securesms.lock.v2.KbsConstants;
|
||||
import org.thoughtcrime.securesms.lock.v2.RegistrationLockUtil;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.megaphone.MegaphoneRepository;
|
||||
import org.thoughtcrime.securesms.megaphone.Megaphones;
|
||||
import org.thoughtcrime.securesms.pin.RegistrationLockV2Dialog;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
||||
import org.thoughtcrime.securesms.util.CommunicationActions;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
@@ -67,8 +72,10 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
||||
|
||||
private static final String TAG = Log.tag(AppProtectionPreferenceFragment.class);
|
||||
|
||||
private static final String PREFERENCE_CATEGORY_BLOCKED = "preference_category_blocked";
|
||||
private static final String PREFERENCE_UNIDENTIFIED_LEARN_MORE = "pref_unidentified_learn_more";
|
||||
private static final String PREFERENCE_CATEGORY_BLOCKED = "preference_category_blocked";
|
||||
private static final String PREFERENCE_UNIDENTIFIED_LEARN_MORE = "pref_unidentified_learn_more";
|
||||
private static final String PREFERENCE_WHO_CAN_SEE_PHONE_NUMBER = "pref_who_can_see_phone_number";
|
||||
private static final String PREFERENCE_WHO_CAN_FIND_BY_PHONE_NUMBER = "pref_who_can_find_by_phone_number";
|
||||
|
||||
private CheckBoxPreference disablePassphrase;
|
||||
|
||||
@@ -99,6 +106,18 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
||||
this.findPreference(PREFERENCE_UNIDENTIFIED_LEARN_MORE).setOnPreferenceClickListener(new UnidentifiedLearnMoreClickListener());
|
||||
disablePassphrase.setOnPreferenceChangeListener(new DisablePassphraseClickListener());
|
||||
|
||||
if (FeatureFlags.phoneNumberPrivacy()) {
|
||||
Preference whoCanSeePhoneNumber = this.findPreference(PREFERENCE_WHO_CAN_SEE_PHONE_NUMBER);
|
||||
Preference whoCanFindByPhoneNumber = this.findPreference(PREFERENCE_WHO_CAN_FIND_BY_PHONE_NUMBER);
|
||||
|
||||
whoCanSeePhoneNumber.setPreferenceDataStore(null);
|
||||
whoCanSeePhoneNumber.setOnPreferenceClickListener(new PhoneNumberPrivacyWhoCanSeeClickListener());
|
||||
|
||||
whoCanFindByPhoneNumber.setPreferenceDataStore(null);
|
||||
whoCanFindByPhoneNumber.setOnPreferenceClickListener(new PhoneNumberPrivacyWhoCanFindClickListener());
|
||||
} else {
|
||||
this.findPreference("category_phone_number_privacy").setVisible(false);
|
||||
}
|
||||
|
||||
SwitchPreferenceCompat linkPreviewPref = (SwitchPreferenceCompat) this.findPreference(SettingsValues.LINK_PREVIEWS);
|
||||
linkPreviewPref.setChecked(SignalStore.settings().isLinkPreviewsEnabled());
|
||||
@@ -138,6 +157,9 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
||||
signalPinReminders.setEnabled(false);
|
||||
registrationLockV2.setEnabled(false);
|
||||
}
|
||||
|
||||
initializePhoneNumberPrivacyWhoCanSeeSummary();
|
||||
initializePhoneNumberPrivacyWhoCanFindSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -164,6 +186,27 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
||||
String.format(Locale.getDefault(), "%02d:%02d:%02d", hours, minutes, seconds));
|
||||
}
|
||||
|
||||
private void initializePhoneNumberPrivacyWhoCanSeeSummary() {
|
||||
Preference preference = findPreference(PREFERENCE_WHO_CAN_SEE_PHONE_NUMBER);
|
||||
|
||||
switch (SignalStore.phoneNumberPrivacy().getPhoneNumberSharingMode()) {
|
||||
case EVERYONE: preference.setSummary(R.string.PhoneNumberPrivacy_everyone); break;
|
||||
case CONTACTS: preference.setSummary(R.string.PhoneNumberPrivacy_my_contacts); break;
|
||||
case NOBODY : preference.setSummary(R.string.PhoneNumberPrivacy_nobody); break;
|
||||
default : throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
private void initializePhoneNumberPrivacyWhoCanFindSummary() {
|
||||
Preference preference = findPreference(PREFERENCE_WHO_CAN_FIND_BY_PHONE_NUMBER);
|
||||
|
||||
switch (SignalStore.phoneNumberPrivacy().getPhoneNumberListingMode()) {
|
||||
case LISTED : preference.setSummary(R.string.PhoneNumberPrivacy_everyone); break;
|
||||
case UNLISTED: preference.setSummary(R.string.PhoneNumberPrivacy_nobody); break;
|
||||
default : throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeVisibility() {
|
||||
if (TextSecurePreferences.isPasswordDisabled(getContext())) {
|
||||
findPreference("pref_enable_passphrase_temporary").setVisible(false);
|
||||
@@ -504,4 +547,86 @@ public class AppProtectionPreferenceFragment extends CorrectedPreferenceFragment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class PhoneNumberPrivacyWhoCanSeeClickListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
PhoneNumberPrivacyValues phoneNumberPrivacyValues = SignalStore.phoneNumberPrivacy();
|
||||
|
||||
final PhoneNumberPrivacyValues.PhoneNumberSharingMode[] value = { phoneNumberPrivacyValues.getPhoneNumberSharingMode() };
|
||||
|
||||
new AlertDialog.Builder(requireActivity())
|
||||
.setTitle(R.string.preferences_app_protection__see_my_phone_number)
|
||||
.setCancelable(true)
|
||||
.setSingleChoiceItems(items(requireContext()), value[0].ordinal(), (dialog, which) -> value[0] = PhoneNumberPrivacyValues.PhoneNumberSharingMode.values()[which])
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
PhoneNumberPrivacyValues.PhoneNumberSharingMode phoneNumberSharingMode = value[0];
|
||||
phoneNumberPrivacyValues.setPhoneNumberSharingMode(phoneNumberSharingMode);
|
||||
Log.i(TAG, String.format("PhoneNumberSharingMode changed to %s. Scheduling storage value sync", phoneNumberSharingMode));
|
||||
StorageSyncHelper.scheduleSyncForDataChange();
|
||||
initializePhoneNumberPrivacyWhoCanSeeSummary();
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private CharSequence[] items(Context context) {
|
||||
return new CharSequence[]{
|
||||
titleAndDescription(context, context.getString(R.string.PhoneNumberPrivacy_everyone), context.getString(R.string.PhoneNumberPrivacy_everyone_see_description)),
|
||||
titleAndDescription(context, context.getString(R.string.PhoneNumberPrivacy_my_contacts), context.getString(R.string.PhoneNumberPrivacy_my_contacts_see_description)),
|
||||
context.getString(R.string.PhoneNumberPrivacy_nobody) };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final class PhoneNumberPrivacyWhoCanFindClickListener implements Preference.OnPreferenceClickListener {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
PhoneNumberPrivacyValues phoneNumberPrivacyValues = SignalStore.phoneNumberPrivacy();
|
||||
|
||||
final PhoneNumberPrivacyValues.PhoneNumberListingMode[] value = { phoneNumberPrivacyValues.getPhoneNumberListingMode() };
|
||||
|
||||
new AlertDialog.Builder(requireActivity())
|
||||
.setTitle(R.string.preferences_app_protection__find_me_by_phone_number)
|
||||
.setCancelable(true)
|
||||
.setSingleChoiceItems(items(requireContext()),
|
||||
value[0].ordinal(),
|
||||
(dialog, which) -> value[0] = PhoneNumberPrivacyValues.PhoneNumberListingMode.values()[which])
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
PhoneNumberPrivacyValues.PhoneNumberListingMode phoneNumberListingMode = value[0];
|
||||
phoneNumberPrivacyValues.setPhoneNumberListingMode(phoneNumberListingMode);
|
||||
Log.i(TAG, String.format("PhoneNumberListingMode changed to %s. Scheduling storage value sync", phoneNumberListingMode));
|
||||
StorageSyncHelper.scheduleSyncForDataChange();
|
||||
initializePhoneNumberPrivacyWhoCanFindSummary();
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private CharSequence[] items(Context context) {
|
||||
return new CharSequence[]{
|
||||
titleAndDescription(context, context.getString(R.string.PhoneNumberPrivacy_everyone), context.getString(R.string.PhoneNumberPrivacy_everyone_find_description)),
|
||||
context.getString(R.string.PhoneNumberPrivacy_nobody) };
|
||||
}
|
||||
}
|
||||
|
||||
/** Adds a detail row for radio group descriptions. */
|
||||
private static CharSequence titleAndDescription(@NonNull Context context, @NonNull String header, @NonNull String description) {
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder();
|
||||
|
||||
builder.append("\n");
|
||||
builder.append(header);
|
||||
builder.append("\n");
|
||||
|
||||
builder.setSpan(new TextAppearanceSpan(context, android.R.style.TextAppearance_Small), builder.length(), builder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||
|
||||
builder.append(description);
|
||||
builder.append("\n");
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user