Search in sources :

Example 1 with MultiDeviceProfileKeyUpdateJob

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MultiDeviceProfileKeyUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob) IOException(java.io.IOException) ProfileUploadJob(org.thoughtcrime.securesms.jobs.ProfileUploadJob) MultiDeviceProfileContentUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob)

Example 2 with MultiDeviceProfileKeyUpdateJob

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);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Intent(android.content.Intent) MultiDeviceProfileKeyUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob) ProfileUploadJob(org.thoughtcrime.securesms.jobs.ProfileUploadJob) MultiDeviceProfileContentUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob) RegistrationViewModel(org.thoughtcrime.securesms.registration.viewmodel.RegistrationViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) PinRestoreActivity(org.thoughtcrime.securesms.pin.PinRestoreActivity)

Example 3 with MultiDeviceProfileKeyUpdateJob

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);
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) Intent(android.content.Intent) MultiDeviceProfileKeyUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob) ProfileUploadJob(org.thoughtcrime.securesms.jobs.ProfileUploadJob) MultiDeviceProfileContentUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob) RegistrationViewModel(org.thoughtcrime.securesms.registration.viewmodel.RegistrationViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) PinRestoreActivity(org.thoughtcrime.securesms.pin.PinRestoreActivity)

Example 4 with MultiDeviceProfileKeyUpdateJob

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);
}
Also used : Context(android.content.Context) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamDetails(org.whispersystems.signalservice.api.util.StreamDetails) SecureRandom(java.security.SecureRandom) MultiDeviceProfileKeyUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob) IOException(java.io.IOException)

Example 5 with MultiDeviceProfileKeyUpdateJob

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MultiDeviceProfileKeyUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob) IOException(java.io.IOException) ProfileUploadJob(org.thoughtcrime.securesms.jobs.ProfileUploadJob) MultiDeviceProfileContentUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob)

Aggregations

MultiDeviceProfileKeyUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob)5 MultiDeviceProfileContentUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob)4 ProfileUploadJob (org.thoughtcrime.securesms.jobs.ProfileUploadJob)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 Intent (android.content.Intent)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 ViewModelProvider (androidx.lifecycle.ViewModelProvider)2 PinRestoreActivity (org.thoughtcrime.securesms.pin.PinRestoreActivity)2 RegistrationViewModel (org.thoughtcrime.securesms.registration.viewmodel.RegistrationViewModel)2 Context (android.content.Context)1 SecureRandom (java.security.SecureRandom)1 StreamDetails (org.whispersystems.signalservice.api.util.StreamDetails)1