Remove TextSecurePreferences.getProfileName()

master
Greyson Parrelli 2020-03-25 17:58:33 -04:00
parent a860315587
commit 6aac3baa55
16 changed files with 61 additions and 42 deletions

View File

@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.migrations.ApplicationMigrations;
import org.thoughtcrime.securesms.profiles.ProfileName;
import org.thoughtcrime.securesms.profiles.edit.EditProfileActivity;
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.registration.RegistrationNavigationActivity;
import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.util.CensorshipUtil;
@ -187,7 +188,7 @@ public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarA
}
private boolean userMustSetProfileName() {
return !SignalStore.registrationValues().isRegistrationComplete() && TextSecurePreferences.getProfileName(this) == ProfileName.EMPTY;
return !SignalStore.registrationValues().isRegistrationComplete() && Recipient.self().getProfileName() == ProfileName.EMPTY;
}
private Intent getCreatePassphraseIntent() {

View File

@ -21,6 +21,8 @@ import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteDatabaseHook;
import net.sqlcipher.database.SQLiteOpenHelper;
import org.thoughtcrime.securesms.profiles.ProfileName;
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
import org.thoughtcrime.securesms.crypto.DatabaseSecret;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.AttachmentDatabase;
@ -115,8 +117,9 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
private static final int STORAGE_SERVICE_ACTIVE = 50;
private static final int GROUPS_V2_RECIPIENT_CAPABILITY = 51;
private static final int TRANSFER_FILE_CLEANUP = 52;
private static final int PROFILE_DATA_MIGRATION = 53;
private static final int DATABASE_VERSION = 52;
private static final int DATABASE_VERSION = 53;
private static final String DATABASE_NAME = "signal.db";
private final Context context;
@ -545,11 +548,10 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
values.put("phone", localNumber);
values.put("registered", 1);
values.put("profile_sharing", 1);
values.put("signal_profile_name", TextSecurePreferences.getProfileName(context).getGivenName());
db.insert("recipient", null, values);
} else {
db.execSQL("UPDATE recipient SET registered = ?, profile_sharing = ?, signal_profile_name = ? WHERE phone = ?",
new String[] { "1", "1", TextSecurePreferences.getProfileName(context).getGivenName(), localNumber });
db.execSQL("UPDATE recipient SET registered = ?, profile_sharing = ? WHERE phone = ?",
new String[] { "1", "1", localNumber });
}
}
}
@ -789,6 +791,17 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
}
}
if (oldVersion < PROFILE_DATA_MIGRATION) {
String localNumber = TextSecurePreferences.getLocalNumber(context);
if (localNumber != null) {
String encodedProfileName = PreferenceManager.getDefaultSharedPreferences(context).getString("pref_profile_name", null);
ProfileName profileName = ProfileName.fromSerialized(encodedProfileName);
db.execSQL("UPDATE recipient SET signal_profile_name = ?, profile_family_name = ?, profile_joined_name = ? WHERE phone = ?",
new String[] { profileName.getGivenName(), profileName.getFamilyName(), profileName.toString(), localNumber });
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();

View File

@ -67,7 +67,7 @@ public class InsightsRepository implements InsightsDashboardViewModel.Repository
public void getUserAvatar(@NonNull Consumer<InsightsUserAvatar> avatarConsumer) {
SimpleTask.run(() -> {
Recipient self = Recipient.self().resolve();
String name = Optional.fromNullable(self.getName(context)).or(Optional.fromNullable(TextSecurePreferences.getProfileName(context).toString())).or("");
String name = Optional.fromNullable(self.getName(context)).or("");
MaterialColor fallbackColor = self.getColor();
if (fallbackColor == ContactColors.UNKNOWN_COLOR && !TextUtils.isEmpty(name)) {

View File

@ -49,19 +49,19 @@ public final class ProfileUploadJob extends BaseJob {
@Override
protected void onRun() throws Exception {
ProfileKey profileKey = ProfileKeyUtil.getSelfProfileKey();
ProfileName profileName = TextSecurePreferences.getProfileName(context);
ProfileName profileName = Recipient.self().getProfileName();
String avatarPath = null;
try (StreamDetails avatar = AvatarHelper.getSelfProfileAvatarStream(context)) {
if (FeatureFlags.VERSIONED_PROFILES) {
accountManager.setVersionedProfile(Recipient.self().getUuid().get(), profileKey, profileName.serialize(), avatar);
avatarPath = accountManager.setVersionedProfile(Recipient.self().getUuid().get(), profileKey, profileName.serialize(), avatar);
} else {
accountManager.setProfileName(profileKey, profileName.serialize());
accountManager.setProfileAvatar(profileKey, avatar);
avatarPath = accountManager.setProfileAvatar(profileKey, avatar);
}
}
ProfileAndCredential profile = ProfileUtil.retrieveProfile(context, Recipient.self(), SignalServiceProfile.RequestType.PROFILE);
DatabaseFactory.getRecipientDatabase(context).setProfileAvatar(Recipient.self().getId(), profile.getProfile().getAvatar());
DatabaseFactory.getRecipientDatabase(context).setProfileAvatar(Recipient.self().getId(), avatarPath);
}
@Override

View File

@ -106,7 +106,6 @@ public class RefreshOwnProfileJob extends BaseJob {
ProfileName profileName = ProfileName.fromSerialized(plaintextName);
DatabaseFactory.getRecipientDatabase(context).setProfileName(Recipient.self().getId(), profileName);
TextSecurePreferences.setProfileName(context, profileName);
} catch (InvalidCiphertextException | IOException e) {
Log.w(TAG, e);
}

View File

@ -59,10 +59,10 @@ public class RotateProfileKeyJob extends BaseJob {
if (FeatureFlags.VERSIONED_PROFILES) {
accountManager.setVersionedProfile(self.getUuid().get(),
profileKey,
TextSecurePreferences.getProfileName(context).serialize(),
Recipient.self().getProfileName().serialize(),
avatarStream);
} else {
accountManager.setProfileName(profileKey, TextSecurePreferences.getProfileName(context).serialize());
accountManager.setProfileName(profileKey, Recipient.self().getProfileName().serialize());
accountManager.setProfileAvatar(profileKey, avatarStream);
}
}

View File

@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.messagerequests.MessageRequestMegaphoneActivity;
import org.thoughtcrime.securesms.profiles.ProfileName;
import org.thoughtcrime.securesms.profiles.edit.EditProfileActivity;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.AvatarUtil;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
@ -202,7 +203,7 @@ public final class Megaphones {
}
private static @NonNull Megaphone buildProfileNamesMegaphone(@NonNull Context context) {
short requestCode = TextSecurePreferences.getProfileName(context) != ProfileName.EMPTY
short requestCode = Recipient.self().getProfileName() != ProfileName.EMPTY
? ConversationListFragment.PROFILE_NAMES_REQUEST_CODE_CONFIRM_NAME
: ConversationListFragment.PROFILE_NAMES_REQUEST_CODE_CREATE_NAME;
@ -210,7 +211,7 @@ public final class Megaphones {
.enableSnooze(null)
.setImageRequest(AvatarUtil.getSelfAvatarOrFallbackIcon(context, R.drawable.ic_profilename_64));
if (TextSecurePreferences.getProfileName(ApplicationDependencies.getApplication()) == ProfileName.EMPTY) {
if (Recipient.self().getProfileName() == ProfileName.EMPTY) {
return builder.setTitle(R.string.ProfileNamesMegaphone__add_a_profile_name)
.setBody(R.string.ProfileNamesMegaphone__this_will_be_displayed_when_you_start)
.setActionButton(R.string.ProfileNamesMegaphone__add_profile_name, (megaphone, listener) -> {
@ -241,7 +242,7 @@ public final class Megaphones {
}
private static boolean shouldShowMessageRequestsMegaphone() {
boolean userHasAProfileName = TextSecurePreferences.getProfileName(ApplicationDependencies.getApplication()) != ProfileName.EMPTY;
boolean userHasAProfileName = Recipient.self().getProfileName() != ProfileName.EMPTY;
return FeatureFlags.messageRequests() && !userHasAProfileName;
}

View File

@ -14,6 +14,7 @@ import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.megaphone.Megaphones;
import org.thoughtcrime.securesms.profiles.ProfileName;
import org.thoughtcrime.securesms.profiles.edit.EditProfileActivity;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
@ -53,7 +54,7 @@ public class MessageRequestMegaphoneActivity extends PassphraseRequiredActionBar
if (requestCode == EDIT_PROFILE_REQUEST_CODE &&
resultCode == RESULT_OK &&
TextSecurePreferences.getProfileName(this) != ProfileName.EMPTY) {
Recipient.self().getProfileName() != ProfileName.EMPTY) {
ApplicationDependencies.getMegaphoneRepository().markFinished(Megaphones.Event.MESSAGE_REQUESTS);
setResult(RESULT_OK);
finish();

View File

@ -65,7 +65,7 @@ public class ProfilePreference extends Preference {
if (profileSubtextView == null) return;
final Recipient self = Recipient.self();
final String profileName = TextSecurePreferences.getProfileName(getContext()).toString();
final String profileName = Recipient.self().getProfileName().toString();
GlideApp.with(getContext().getApplicationContext())
.load(new ProfileContactPhoto(self.getId(), String.valueOf(TextSecurePreferences.getProfileAvatarId(getContext()))))

View File

@ -47,7 +47,7 @@ class EditProfileRepository {
}
void getCurrentProfileName(@NonNull Consumer<ProfileName> profileNameConsumer) {
ProfileName storedProfileName = TextSecurePreferences.getProfileName(context);
ProfileName storedProfileName = Recipient.self().getProfileName();
if (!storedProfileName.isEmpty()) {
profileNameConsumer.accept(storedProfileName);
} else if (!excludeSystem) {
@ -102,7 +102,6 @@ class EditProfileRepository {
void uploadProfile(@NonNull ProfileName profileName, @Nullable byte[] avatar, @NonNull Consumer<UploadResult> uploadResultConsumer) {
SimpleTask.run(() -> {
TextSecurePreferences.setProfileName(context, profileName);
DatabaseFactory.getRecipientDatabase(context).setProfileName(Recipient.self().getId(), profileName);
try {

View File

@ -89,7 +89,7 @@ public class RecipientDetails {
this.blocked = settings.isBlocked();
this.expireMessages = settings.getExpireMessages();
this.participants = participants == null ? new LinkedList<>() : participants;
this.profileName = isLocalNumber ? TextSecurePreferences.getProfileName(context) : settings.getProfileName();
this.profileName = settings.getProfileName();
this.defaultSubscriptionId = settings.getDefaultSubscriptionId();
this.registered = settings.getRegistered();
this.profileKey = settings.getProfileKey();

View File

@ -340,7 +340,6 @@ public final class StorageSyncHelper {
DatabaseFactory.getRecipientDatabase(context).applyStorageSyncUpdates(storageId, update);
DatabaseFactory.getThreadDatabase(context).setArchived(Recipient.self().getId(), update.isNoteToSelfArchived());
TextSecurePreferences.setProfileName(context, ProfileName.fromParts(update.getGivenName().orNull(), update.getFamilyName().orNull()));
TextSecurePreferences.setReadReceiptsEnabled(context, update.isReadReceiptsEnabled());
TextSecurePreferences.setTypingIndicatorsEnabled(context, update.isTypingIndicatorsEnabled());
TextSecurePreferences.setShowUnidentifiedDeliveryIndicatorsEnabled(context, update.isSealedSenderIndicatorsEnabled());

View File

@ -61,7 +61,7 @@ public final class AvatarUtil {
}
private static Drawable getFallback(@NonNull Context context, @NonNull Recipient recipient) {
String name = Optional.fromNullable(recipient.getDisplayName(context)).or(Optional.fromNullable(TextSecurePreferences.getProfileName(context).toString())).or("");
String name = Optional.fromNullable(recipient.getDisplayName(context)).or("");
MaterialColor fallbackColor = recipient.getColor();
if (fallbackColor == ContactColors.UNKNOWN_COLOR && !TextUtils.isEmpty(name)) {

View File

@ -434,14 +434,6 @@ public class TextSecurePreferences {
setBooleanPreference(context, GIF_GRID_LAYOUT, isGrid);
}
public static void setProfileName(Context context, ProfileName name) {
setStringPreference(context, PROFILE_NAME_PREF, name.serialize());
}
public static ProfileName getProfileName(Context context) {
return ProfileName.fromSerialized(getStringPreference(context, PROFILE_NAME_PREF, null));
}
public static void setProfileAvatarId(Context context, int id) {
setIntegerPrefrence(context, PROFILE_AVATAR_ID_PREF, id);
}

View File

@ -641,7 +641,7 @@ public class SignalServiceAccountManager {
this.pushServiceSocket.setProfileName(ciphertextName);
}
public void setProfileAvatar(ProfileKey key, StreamDetails avatar)
public String setProfileAvatar(ProfileKey key, StreamDetails avatar)
throws IOException
{
if (FeatureFlags.VERSIONED_PROFILES) {
@ -657,10 +657,13 @@ public class SignalServiceAccountManager {
new ProfileCipherOutputStreamFactory(key));
}
this.pushServiceSocket.setProfileAvatar(profileAvatarData);
return this.pushServiceSocket.setProfileAvatar(profileAvatarData);
}
public void setVersionedProfile(UUID uuid, ProfileKey profileKey, String name, StreamDetails avatar)
/**
* @return The avatar URL path, if one was written.
*/
public String setVersionedProfile(UUID uuid, ProfileKey profileKey, String name, StreamDetails avatar)
throws IOException
{
if (!FeatureFlags.VERSIONED_PROFILES) {
@ -680,11 +683,11 @@ public class SignalServiceAccountManager {
new ProfileCipherOutputStreamFactory(profileKey));
}
this.pushServiceSocket.writeProfile(new SignalServiceProfileWrite(profileKey.getProfileKeyVersion(uuid).serialize(),
ciphertextName,
hasAvatar,
profileKey.getCommitment(uuid).serialize()),
profileAvatarData);
return this.pushServiceSocket.writeProfile(new SignalServiceProfileWrite(profileKey.getProfileKeyVersion(uuid).serialize(),
ciphertextName,
hasAvatar,
profileKey.getCommitment(uuid).serialize()),
profileAvatarData);
}
public void setUsername(String username) throws IOException {

View File

@ -604,7 +604,7 @@ public class PushServiceSocket {
makeServiceRequest(String.format(PROFILE_PATH, "name/" + (name == null ? "" : URLEncoder.encode(name))), "PUT", "");
}
public void setProfileAvatar(ProfileAvatarData profileAvatar)
public String setProfileAvatar(ProfileAvatarData profileAvatar)
throws NonSuccessfulResponseCodeException, PushNetworkException
{
if (FeatureFlags.VERSIONED_PROFILES) {
@ -628,10 +628,17 @@ public class PushServiceSocket {
formAttributes.getSignature(), profileAvatar.getData(),
profileAvatar.getContentType(), profileAvatar.getDataLength(),
profileAvatar.getOutputStreamFactory(), null, null);
return formAttributes.getKey();
}
return null;
}
public void writeProfile(SignalServiceProfileWrite signalServiceProfileWrite, ProfileAvatarData profileAvatar)
/**
* @return The avatar URL path, if one was written.
*/
public String writeProfile(SignalServiceProfileWrite signalServiceProfileWrite, ProfileAvatarData profileAvatar)
throws NonSuccessfulResponseCodeException, PushNetworkException
{
if (!FeatureFlags.VERSIONED_PROFILES) {
@ -657,7 +664,11 @@ public class PushServiceSocket {
formAttributes.getSignature(), profileAvatar.getData(),
profileAvatar.getContentType(), profileAvatar.getDataLength(),
profileAvatar.getOutputStreamFactory(), null, null);
return formAttributes.getKey();
}
return null;
}
public void setUsername(String username) throws IOException {