use of org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob in project Signal-Android by signalapp.
the class EditSelfProfileRepository method uploadProfile.
@Override
public void uploadProfile(@NonNull ProfileName profileName, @NonNull String displayName, boolean displayNameChanged, @NonNull String description, boolean descriptionChanged, @Nullable byte[] avatar, boolean avatarChanged, @NonNull Consumer<UploadResult> uploadResultConsumer) {
SimpleTask.run(() -> {
SignalDatabase.recipients().setProfileName(Recipient.self().getId(), profileName);
if (avatarChanged) {
try {
AvatarHelper.setAvatar(context, Recipient.self().getId(), avatar != null ? new ByteArrayInputStream(avatar) : null);
} catch (IOException e) {
return UploadResult.ERROR_IO;
}
}
ApplicationDependencies.getJobManager().startChain(new ProfileUploadJob()).then(Arrays.asList(new MultiDeviceProfileKeyUpdateJob(), new MultiDeviceProfileContentUpdateJob())).enqueue();
RegistrationUtil.maybeMarkRegistrationComplete(context);
if (avatar != null) {
SignalStore.misc().markHasEverHadAnAvatar();
}
return UploadResult.SUCCESS;
}, uploadResultConsumer::accept);
}
use of org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob in project Signal-Android by signalapp.
the class RegistrationCompleteFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
FragmentActivity activity = requireActivity();
RegistrationViewModel viewModel = new ViewModelProvider(activity).get(RegistrationViewModel.class);
if (SignalStore.storageService().needsAccountRestore()) {
Log.i(TAG, "Performing pin restore");
activity.startActivity(new Intent(activity, PinRestoreActivity.class));
} else if (!viewModel.isReregister()) {
boolean needsProfile = Recipient.self().getProfileName().isEmpty() || !AvatarHelper.hasAvatar(activity, Recipient.self().getId());
boolean needsPin = !SignalStore.kbsValues().hasPin();
Log.i(TAG, "Pin restore flow not required." + " profile name: " + Recipient.self().getProfileName().isEmpty() + " profile avatar: " + !AvatarHelper.hasAvatar(activity, Recipient.self().getId()) + " needsPin:" + needsPin);
Intent startIntent = MainActivity.clearTop(activity);
if (needsPin) {
startIntent = chainIntents(CreateKbsPinActivity.getIntentForPinCreate(requireContext()), startIntent);
}
if (needsProfile) {
startIntent = chainIntents(EditProfileActivity.getIntentForUserProfile(activity), startIntent);
}
if (!needsProfile && !needsPin) {
ApplicationDependencies.getJobManager().startChain(new ProfileUploadJob()).then(Arrays.asList(new MultiDeviceProfileKeyUpdateJob(), new MultiDeviceProfileContentUpdateJob())).enqueue();
RegistrationUtil.maybeMarkRegistrationComplete(requireContext());
}
activity.startActivity(startIntent);
}
activity.finish();
ActivityNavigator.applyPopAnimationsToPendingTransition(activity);
}
use of org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob in project Signal-Android by WhisperSystems.
the class RegistrationCompleteFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
FragmentActivity activity = requireActivity();
RegistrationViewModel viewModel = new ViewModelProvider(activity).get(RegistrationViewModel.class);
if (SignalStore.storageService().needsAccountRestore()) {
Log.i(TAG, "Performing pin restore");
activity.startActivity(new Intent(activity, PinRestoreActivity.class));
} else if (!viewModel.isReregister()) {
boolean needsProfile = Recipient.self().getProfileName().isEmpty() || !AvatarHelper.hasAvatar(activity, Recipient.self().getId());
boolean needsPin = !SignalStore.kbsValues().hasPin();
Log.i(TAG, "Pin restore flow not required." + " profile name: " + Recipient.self().getProfileName().isEmpty() + " profile avatar: " + !AvatarHelper.hasAvatar(activity, Recipient.self().getId()) + " needsPin:" + needsPin);
Intent startIntent = MainActivity.clearTop(activity);
if (needsPin) {
startIntent = chainIntents(CreateKbsPinActivity.getIntentForPinCreate(requireContext()), startIntent);
}
if (needsProfile) {
startIntent = chainIntents(EditProfileActivity.getIntentForUserProfile(activity), startIntent);
}
if (!needsProfile && !needsPin) {
ApplicationDependencies.getJobManager().startChain(new ProfileUploadJob()).then(Arrays.asList(new MultiDeviceProfileKeyUpdateJob(), new MultiDeviceProfileContentUpdateJob())).enqueue();
RegistrationUtil.maybeMarkRegistrationComplete(requireContext());
}
activity.startActivity(startIntent);
}
activity.finish();
ActivityNavigator.applyPopAnimationsToPendingTransition(activity);
}
use of org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob in project Signal-Android by signalapp.
the class CreateProfileActivity method handleUpload.
private void handleUpload() {
final String name;
final StreamDetails avatar;
if (TextUtils.isEmpty(this.name.getText().toString()))
name = null;
else
name = this.name.getText().toString();
if (avatarBytes == null || avatarBytes.length == 0)
avatar = null;
else
avatar = new StreamDetails(new ByteArrayInputStream(avatarBytes), "image/jpeg", avatarBytes.length);
new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
Context context = CreateProfileActivity.this;
byte[] profileKey = ProfileKeyUtil.getProfileKey(CreateProfileActivity.this);
try {
accountManager.setProfileName(profileKey, name);
TextSecurePreferences.setProfileName(context, name);
} catch (IOException e) {
Log.w(TAG, e);
return false;
}
try {
accountManager.setProfileAvatar(profileKey, avatar);
AvatarHelper.setAvatar(CreateProfileActivity.this, Address.fromSerialized(TextSecurePreferences.getLocalNumber(context)), avatarBytes);
TextSecurePreferences.setProfileAvatarId(CreateProfileActivity.this, new SecureRandom().nextInt());
} catch (IOException e) {
Log.w(TAG, e);
return false;
}
ApplicationContext.getInstance(context).getJobManager().add(new MultiDeviceProfileKeyUpdateJob(context));
return true;
}
@Override
public void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (result) {
if (captureFile != null)
captureFile.delete();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
handleFinishedLollipop();
else
handleFinishedLegacy();
} else {
Toast.makeText(CreateProfileActivity.this, R.string.CreateProfileActivity_problem_setting_profile, Toast.LENGTH_LONG).show();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob in project Signal-Android by WhisperSystems.
the class EditSelfProfileRepository method uploadProfile.
@Override
public void uploadProfile(@NonNull ProfileName profileName, @NonNull String displayName, boolean displayNameChanged, @NonNull String description, boolean descriptionChanged, @Nullable byte[] avatar, boolean avatarChanged, @NonNull Consumer<UploadResult> uploadResultConsumer) {
SimpleTask.run(() -> {
SignalDatabase.recipients().setProfileName(Recipient.self().getId(), profileName);
if (avatarChanged) {
try {
AvatarHelper.setAvatar(context, Recipient.self().getId(), avatar != null ? new ByteArrayInputStream(avatar) : null);
} catch (IOException e) {
return UploadResult.ERROR_IO;
}
}
ApplicationDependencies.getJobManager().startChain(new ProfileUploadJob()).then(Arrays.asList(new MultiDeviceProfileKeyUpdateJob(), new MultiDeviceProfileContentUpdateJob())).enqueue();
RegistrationUtil.maybeMarkRegistrationComplete(context);
if (avatar != null) {
SignalStore.misc().markHasEverHadAnAvatar();
}
return UploadResult.SUCCESS;
}, uploadResultConsumer::accept);
}
Aggregations