2017-11-24 22:00:30 -08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016-2017 Open Whisper Systems
|
2012-07-23 13:42:29 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2012-07-23 13:42:29 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
import android.Manifest;
|
2017-06-06 18:03:09 -07:00
|
|
|
import android.animation.TypeEvaluator;
|
|
|
|
import android.animation.ValueAnimator;
|
2017-11-24 22:00:30 -08:00
|
|
|
import android.annotation.SuppressLint;
|
2016-11-12 12:59:54 +01:00
|
|
|
import android.content.ActivityNotFoundException;
|
2016-08-24 18:51:45 -07:00
|
|
|
import android.content.Context;
|
2016-11-12 12:59:54 +01:00
|
|
|
import android.content.Intent;
|
2016-08-24 18:51:45 -07:00
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
2017-06-06 18:03:09 -07:00
|
|
|
import android.os.AsyncTask;
|
2011-12-20 10:20:44 -08:00
|
|
|
import android.os.Bundle;
|
2016-08-24 18:51:45 -07:00
|
|
|
import android.os.Vibrator;
|
2016-11-13 10:58:51 -08:00
|
|
|
import android.text.Html;
|
2016-11-14 19:50:29 -08:00
|
|
|
import android.text.TextUtils;
|
2016-11-13 10:58:51 -08:00
|
|
|
import android.text.method.LinkMovementMethod;
|
2016-11-14 19:50:29 -08:00
|
|
|
import android.view.ContextMenu;
|
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
2016-08-24 18:51:45 -07:00
|
|
|
import android.view.LayoutInflater;
|
2016-11-12 12:59:54 +01:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2016-08-24 18:51:45 -07:00
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2021-09-07 17:50:36 -03:00
|
|
|
import android.view.ViewTreeObserver;
|
2016-08-24 18:51:45 -07:00
|
|
|
import android.view.animation.Animation;
|
|
|
|
import android.view.animation.AnticipateInterpolator;
|
|
|
|
import android.view.animation.ScaleAnimation;
|
2021-08-27 15:56:54 -03:00
|
|
|
import android.widget.Button;
|
2016-08-24 18:51:45 -07:00
|
|
|
import android.widget.ImageView;
|
2021-09-07 17:50:36 -03:00
|
|
|
import android.widget.ScrollView;
|
2021-08-27 15:56:54 -03:00
|
|
|
import android.widget.TextSwitcher;
|
2011-12-20 10:20:44 -08:00
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2020-04-21 09:47:59 -03:00
|
|
|
import androidx.annotation.DrawableRes;
|
|
|
|
import androidx.annotation.NonNull;
|
2021-09-07 17:50:36 -03:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
2021-08-27 15:56:54 -03:00
|
|
|
import androidx.core.view.OneShotPreDrawListener;
|
2020-04-21 09:47:59 -03:00
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
2021-08-27 15:56:54 -03:00
|
|
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
|
2020-04-21 09:47:59 -03:00
|
|
|
|
2021-10-28 15:39:36 -04:00
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|
|
|
|
2021-03-01 15:44:33 -05:00
|
|
|
import org.signal.core.util.ThreadUtil;
|
2021-02-23 12:48:20 -04:00
|
|
|
import org.signal.core.util.concurrent.SignalExecutors;
|
2020-12-04 18:31:58 -05:00
|
|
|
import org.signal.core.util.logging.Log;
|
2021-08-27 15:56:54 -03:00
|
|
|
import org.thoughtcrime.securesms.components.ShapeScrim;
|
2016-08-24 18:51:45 -07:00
|
|
|
import org.thoughtcrime.securesms.components.camera.CameraView;
|
2021-06-15 10:07:41 -04:00
|
|
|
import org.thoughtcrime.securesms.crypto.ReentrantSessionLock;
|
2014-11-12 09:09:55 -08:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyParcelable;
|
2012-07-23 13:42:29 -07:00
|
|
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
2020-04-21 09:47:59 -03:00
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus;
|
2021-09-01 09:41:49 -04:00
|
|
|
import org.thoughtcrime.securesms.database.model.IdentityRecord;
|
2020-04-21 09:47:59 -03:00
|
|
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob;
|
2017-11-24 22:00:30 -08:00
|
|
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
2016-08-24 18:51:45 -07:00
|
|
|
import org.thoughtcrime.securesms.qr.QrCode;
|
|
|
|
import org.thoughtcrime.securesms.qr.ScanListener;
|
|
|
|
import org.thoughtcrime.securesms.qr.ScanningThread;
|
2019-08-07 14:22:51 -04:00
|
|
|
import org.thoughtcrime.securesms.recipients.LiveRecipient;
|
2013-11-25 17:00:20 -08:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2019-08-07 14:22:51 -04:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
2020-03-18 16:31:45 -04:00
|
|
|
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
|
2021-09-07 17:50:36 -03:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
2016-08-24 18:51:45 -07:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2019-11-04 09:03:18 -05:00
|
|
|
import org.thoughtcrime.securesms.util.FeatureFlags;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.util.IdentityUtil;
|
2016-08-24 18:51:45 -07:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.libsignal.IdentityKey;
|
2016-08-24 18:51:45 -07:00
|
|
|
import org.whispersystems.libsignal.fingerprint.Fingerprint;
|
|
|
|
import org.whispersystems.libsignal.fingerprint.FingerprintVersionMismatchException;
|
|
|
|
import org.whispersystems.libsignal.fingerprint.NumericFingerprintGenerator;
|
2021-02-19 14:18:05 -05:00
|
|
|
import org.whispersystems.signalservice.api.SignalSessionLock;
|
2019-11-04 09:03:18 -05:00
|
|
|
import org.whispersystems.signalservice.api.util.UuidUtil;
|
2016-08-24 18:51:45 -07:00
|
|
|
|
|
|
|
import java.nio.charset.Charset;
|
2019-07-17 14:07:39 -04:00
|
|
|
import java.util.Locale;
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
/**
|
|
|
|
* Activity for verifying identity keys.
|
2012-07-23 13:42:29 -07:00
|
|
|
*
|
2011-12-20 10:20:44 -08:00
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*/
|
2017-11-24 22:00:30 -08:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2020-06-22 17:01:40 -07:00
|
|
|
public class VerifyIdentityActivity extends PassphraseRequiredActivity implements ScanListener, View.OnClickListener {
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2020-04-21 09:47:59 -03:00
|
|
|
private static final String TAG = Log.tag(VerifyIdentityActivity.class);
|
|
|
|
|
|
|
|
private static final String RECIPIENT_EXTRA = "recipient_id";
|
|
|
|
private static final String IDENTITY_EXTRA = "recipient_identity";
|
|
|
|
private static final String VERIFIED_EXTRA = "verified_state";
|
|
|
|
|
2021-09-07 17:50:36 -03:00
|
|
|
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2020-04-21 09:47:59 -03:00
|
|
|
private final VerifyDisplayFragment displayFragment = new VerifyDisplayFragment();
|
|
|
|
private final VerifyScanFragment scanFragment = new VerifyScanFragment();
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2020-04-21 09:47:59 -03:00
|
|
|
public static Intent newIntent(@NonNull Context context,
|
2021-09-01 09:41:49 -04:00
|
|
|
@NonNull IdentityRecord identityRecord)
|
2020-04-21 09:47:59 -03:00
|
|
|
{
|
|
|
|
return newIntent(context,
|
|
|
|
identityRecord.getRecipientId(),
|
|
|
|
identityRecord.getIdentityKey(),
|
|
|
|
identityRecord.getVerifiedStatus() == IdentityDatabase.VerifiedStatus.VERIFIED);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Intent newIntent(@NonNull Context context,
|
2021-09-01 09:41:49 -04:00
|
|
|
@NonNull IdentityRecord identityRecord,
|
2020-04-21 09:47:59 -03:00
|
|
|
boolean verified)
|
|
|
|
{
|
|
|
|
return newIntent(context,
|
|
|
|
identityRecord.getRecipientId(),
|
|
|
|
identityRecord.getIdentityKey(),
|
|
|
|
verified);
|
|
|
|
}
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2020-04-21 09:47:59 -03:00
|
|
|
public static Intent newIntent(@NonNull Context context,
|
|
|
|
@NonNull RecipientId recipientId,
|
|
|
|
@NonNull IdentityKey identityKey,
|
|
|
|
boolean verified)
|
|
|
|
{
|
|
|
|
Intent intent = new Intent(context, VerifyIdentityActivity.class);
|
|
|
|
|
|
|
|
intent.putExtra(RECIPIENT_EXTRA, recipientId);
|
|
|
|
intent.putExtra(IDENTITY_EXTRA, new IdentityKeyParcelable(identityKey));
|
|
|
|
intent.putExtra(VERIFIED_EXTRA, verified);
|
|
|
|
|
|
|
|
return intent;
|
|
|
|
}
|
2016-08-24 18:51:45 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreCreate() {
|
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
}
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2014-12-15 12:25:55 -08:00
|
|
|
@Override
|
2018-02-01 19:22:48 -08:00
|
|
|
protected void onCreate(Bundle state, boolean ready) {
|
2017-07-26 09:59:15 -07:00
|
|
|
Bundle extras = new Bundle();
|
2019-08-07 14:22:51 -04:00
|
|
|
extras.putParcelable(VerifyDisplayFragment.RECIPIENT_ID, getIntent().getParcelableExtra(RECIPIENT_EXTRA));
|
2017-07-26 09:59:15 -07:00
|
|
|
extras.putParcelable(VerifyDisplayFragment.REMOTE_IDENTITY, getIntent().getParcelableExtra(IDENTITY_EXTRA));
|
|
|
|
extras.putParcelable(VerifyDisplayFragment.LOCAL_IDENTITY, new IdentityKeyParcelable(IdentityKeyUtil.getIdentityKey(this)));
|
2021-11-17 15:08:28 -05:00
|
|
|
extras.putString(VerifyDisplayFragment.LOCAL_NUMBER, Recipient.self().requireE164());
|
2017-07-26 09:59:15 -07:00
|
|
|
extras.putBoolean(VerifyDisplayFragment.VERIFIED_STATE, getIntent().getBooleanExtra(VERIFIED_EXTRA, false));
|
|
|
|
|
|
|
|
scanFragment.setScanListener(this);
|
|
|
|
displayFragment.setClickListener(this);
|
|
|
|
|
2020-04-21 09:47:59 -03:00
|
|
|
initFragment(android.R.id.content, displayFragment, Locale.getDefault(), extras);
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2014-04-09 13:26:06 -07:00
|
|
|
@Override
|
2016-08-24 18:51:45 -07:00
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2017-06-19 10:39:15 -07:00
|
|
|
case android.R.id.home: finish(); return true;
|
2016-08-24 18:51:45 -07:00
|
|
|
}
|
2014-04-09 13:26:06 -07:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
return false;
|
|
|
|
}
|
2015-09-06 11:45:19 -07:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
@Override
|
|
|
|
public void onQrDataFound(final String data) {
|
2021-03-01 15:44:33 -05:00
|
|
|
ThreadUtil.runOnMain(() -> {
|
2017-11-24 22:00:30 -08:00
|
|
|
((Vibrator)getSystemService(Context.VIBRATOR_SERVICE)).vibrate(50);
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2017-11-24 22:00:30 -08:00
|
|
|
getSupportFragmentManager().popBackStack();
|
|
|
|
displayFragment.setScannedFingerprint(data);
|
2016-08-24 18:51:45 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-11-24 22:00:30 -08:00
|
|
|
Permissions.with(this)
|
|
|
|
.request(Manifest.permission.CAMERA)
|
|
|
|
.ifNecessary()
|
|
|
|
.withPermanentDenialDialog(getString(R.string.VerifyIdentityActivity_signal_needs_the_camera_permission_in_order_to_scan_a_qr_code_but_it_has_been_permanently_denied))
|
|
|
|
.onAllGranted(() -> {
|
|
|
|
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
|
|
|
transaction.setCustomAnimations(R.anim.slide_from_top, R.anim.slide_to_bottom,
|
|
|
|
R.anim.slide_from_bottom, R.anim.slide_to_top);
|
|
|
|
|
|
|
|
transaction.replace(android.R.id.content, scanFragment)
|
|
|
|
.addToBackStack(null)
|
|
|
|
.commitAllowingStateLoss();
|
|
|
|
})
|
|
|
|
.onAnyDenied(() -> Toast.makeText(this, R.string.VerifyIdentityActivity_unable_to_scan_qr_code_without_camera_permission, Toast.LENGTH_LONG).show())
|
|
|
|
.execute();
|
|
|
|
}
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2021-07-20 13:08:52 -03:00
|
|
|
@SuppressLint("MissingSuperCall")
|
2017-11-24 22:00:30 -08:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
2014-04-09 13:26:06 -07:00
|
|
|
}
|
|
|
|
|
2021-09-07 17:50:36 -03:00
|
|
|
public static class VerifyDisplayFragment extends Fragment implements ViewTreeObserver.OnScrollChangedListener {
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
public static final String RECIPIENT_ID = "recipient_id";
|
2017-07-26 09:59:15 -07:00
|
|
|
public static final String REMOTE_NUMBER = "remote_number";
|
|
|
|
public static final String REMOTE_IDENTITY = "remote_identity";
|
|
|
|
public static final String LOCAL_IDENTITY = "local_identity";
|
|
|
|
public static final String LOCAL_NUMBER = "local_number";
|
|
|
|
public static final String VERIFIED_STATE = "verified_state";
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
private LiveRecipient recipient;
|
2019-11-04 09:03:18 -05:00
|
|
|
private IdentityKey localIdentity;
|
|
|
|
private IdentityKey remoteIdentity;
|
|
|
|
private Fingerprint fingerprint;
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2021-09-07 17:50:36 -03:00
|
|
|
private Toolbar toolbar;
|
|
|
|
private ScrollView scrollView;
|
2016-08-24 18:51:45 -07:00
|
|
|
private View container;
|
2016-11-14 19:50:29 -08:00
|
|
|
private View numbersContainer;
|
2021-08-27 15:56:54 -03:00
|
|
|
private View loading;
|
|
|
|
private View qrCodeContainer;
|
2016-08-24 18:51:45 -07:00
|
|
|
private ImageView qrCode;
|
|
|
|
private ImageView qrVerified;
|
2021-08-27 15:56:54 -03:00
|
|
|
private TextSwitcher tapLabel;
|
2016-08-29 17:49:49 -07:00
|
|
|
private TextView description;
|
2016-08-24 18:51:45 -07:00
|
|
|
private View.OnClickListener clickListener;
|
2021-08-27 15:56:54 -03:00
|
|
|
private Button verifyButton;
|
2021-09-07 17:50:36 -03:00
|
|
|
private View toolbarShadow;
|
|
|
|
private View bottomShadow;
|
2016-08-24 18:51:45 -07:00
|
|
|
|
|
|
|
private TextView[] codes = new TextView[12];
|
|
|
|
private boolean animateSuccessOnDraw = false;
|
|
|
|
private boolean animateFailureOnDraw = false;
|
2021-08-27 15:56:54 -03:00
|
|
|
private boolean currentVerifiedState = false;
|
2016-08-24 18:51:45 -07:00
|
|
|
|
|
|
|
@Override
|
2019-05-22 13:51:56 -03:00
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
|
2016-11-14 19:50:29 -08:00
|
|
|
this.container = ViewUtil.inflate(inflater, viewGroup, R.layout.verify_display_fragment);
|
2021-09-07 17:50:36 -03:00
|
|
|
this.toolbar = container.findViewById(R.id.toolbar);
|
|
|
|
this.scrollView = container.findViewById(R.id.scroll_view);
|
2020-12-17 11:01:40 -04:00
|
|
|
this.numbersContainer = container.findViewById(R.id.number_table);
|
2021-08-27 15:56:54 -03:00
|
|
|
this.loading = container.findViewById(R.id.loading);
|
|
|
|
this.qrCodeContainer = container.findViewById(R.id.qr_code_container);
|
2020-12-17 11:01:40 -04:00
|
|
|
this.qrCode = container.findViewById(R.id.qr_code);
|
2021-08-27 15:56:54 -03:00
|
|
|
this.verifyButton = container.findViewById(R.id.verify_button);
|
2020-12-17 11:01:40 -04:00
|
|
|
this.qrVerified = container.findViewById(R.id.qr_verified);
|
|
|
|
this.description = container.findViewById(R.id.description);
|
|
|
|
this.tapLabel = container.findViewById(R.id.tap_label);
|
2021-09-07 17:50:36 -03:00
|
|
|
this.toolbarShadow = container.findViewById(R.id.toolbar_shadow);
|
|
|
|
this.bottomShadow = container.findViewById(R.id.verify_identity_bottom_shadow);
|
2020-12-17 11:01:40 -04:00
|
|
|
this.codes[0] = container.findViewById(R.id.code_first);
|
|
|
|
this.codes[1] = container.findViewById(R.id.code_second);
|
|
|
|
this.codes[2] = container.findViewById(R.id.code_third);
|
|
|
|
this.codes[3] = container.findViewById(R.id.code_fourth);
|
|
|
|
this.codes[4] = container.findViewById(R.id.code_fifth);
|
|
|
|
this.codes[5] = container.findViewById(R.id.code_sixth);
|
|
|
|
this.codes[6] = container.findViewById(R.id.code_seventh);
|
|
|
|
this.codes[7] = container.findViewById(R.id.code_eighth);
|
|
|
|
this.codes[8] = container.findViewById(R.id.code_ninth);
|
|
|
|
this.codes[9] = container.findViewById(R.id.code_tenth);
|
|
|
|
this.codes[10] = container.findViewById(R.id.code_eleventh);
|
|
|
|
this.codes[11] = container.findViewById(R.id.code_twelth);
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2021-08-27 15:56:54 -03:00
|
|
|
this.qrCodeContainer.setOnClickListener(clickListener);
|
2016-11-14 19:50:29 -08:00
|
|
|
this.registerForContextMenu(numbersContainer);
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2021-08-27 15:56:54 -03:00
|
|
|
updateVerifyButton(getArguments().getBoolean(VERIFIED_STATE, false), false);
|
|
|
|
this.verifyButton.setOnClickListener((button -> updateVerifyButton(!currentVerifiedState, true)));
|
2017-06-06 18:03:09 -07:00
|
|
|
|
2021-09-07 17:50:36 -03:00
|
|
|
this.scrollView.getViewTreeObserver().addOnScrollChangedListener(this);
|
|
|
|
|
|
|
|
((AppCompatActivity)requireActivity()).setSupportActionBar(toolbar);
|
|
|
|
((AppCompatActivity)requireActivity()).setTitle(R.string.AndroidManifest__verify_safety_number);
|
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
return container;
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2021-09-07 17:50:36 -03:00
|
|
|
@Override public void onDestroyView() {
|
|
|
|
this.scrollView.getViewTreeObserver().removeOnScrollChangedListener(this);
|
|
|
|
super.onDestroyView();
|
|
|
|
}
|
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle bundle) {
|
|
|
|
super.onCreate(bundle);
|
2013-09-14 13:33:23 -07:00
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
RecipientId recipientId = getArguments().getParcelable(RECIPIENT_ID);
|
2017-07-26 09:59:15 -07:00
|
|
|
IdentityKeyParcelable localIdentityParcelable = getArguments().getParcelable(LOCAL_IDENTITY);
|
|
|
|
IdentityKeyParcelable remoteIdentityParcelable = getArguments().getParcelable(REMOTE_IDENTITY);
|
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
if (recipientId == null) throw new AssertionError("RecipientId required");
|
2017-07-26 09:59:15 -07:00
|
|
|
if (localIdentityParcelable == null) throw new AssertionError("local identity required");
|
|
|
|
if (remoteIdentityParcelable == null) throw new AssertionError("remote identity required");
|
|
|
|
|
|
|
|
this.localIdentity = localIdentityParcelable.get();
|
2019-08-07 14:22:51 -04:00
|
|
|
this.recipient = Recipient.live(recipientId);
|
2017-07-26 09:59:15 -07:00
|
|
|
this.remoteIdentity = remoteIdentityParcelable.get();
|
2016-08-29 17:49:49 -07:00
|
|
|
|
2019-11-04 09:03:18 -05:00
|
|
|
int version;
|
|
|
|
byte[] localId;
|
|
|
|
byte[] remoteId;
|
|
|
|
|
2020-10-25 18:22:28 -04:00
|
|
|
//noinspection WrongThread
|
2020-10-12 12:14:13 -04:00
|
|
|
Recipient resolved = recipient.resolve();
|
|
|
|
|
2021-10-28 15:39:36 -04:00
|
|
|
if (FeatureFlags.verifyV2() && resolved.getAci().isPresent()) {
|
2019-11-04 09:03:18 -05:00
|
|
|
Log.i(TAG, "Using UUID (version 2).");
|
|
|
|
version = 2;
|
2021-11-17 15:08:28 -05:00
|
|
|
localId = Recipient.self().requireAci().toByteArray();
|
2021-10-28 15:39:36 -04:00
|
|
|
remoteId = resolved.requireAci().toByteArray();
|
2020-10-12 12:14:13 -04:00
|
|
|
} else if (!FeatureFlags.verifyV2() && resolved.getE164().isPresent()) {
|
2019-11-04 09:03:18 -05:00
|
|
|
Log.i(TAG, "Using E164 (version 1).");
|
|
|
|
version = 1;
|
2021-11-17 15:08:28 -05:00
|
|
|
localId = Recipient.self().requireE164().getBytes();
|
2020-10-12 12:14:13 -04:00
|
|
|
remoteId = resolved.requireE164().getBytes();
|
|
|
|
} else {
|
2021-10-28 15:39:36 -04:00
|
|
|
Log.w(TAG, String.format(Locale.ENGLISH, "Could not show proper verification! verifyV2: %s, hasUuid: %s, hasE164: %s", FeatureFlags.verifyV2(), resolved.getAci().isPresent(), resolved.getE164().isPresent()));
|
|
|
|
new MaterialAlertDialogBuilder(requireContext())
|
|
|
|
.setMessage(getString(R.string.VerifyIdentityActivity_you_must_first_exchange_messages_in_order_to_view, resolved.getDisplayName(requireContext())))
|
|
|
|
.setPositiveButton(android.R.string.ok, (dialog, which) -> requireActivity().finish())
|
|
|
|
.setOnDismissListener(dialog -> {
|
|
|
|
requireActivity().finish();
|
|
|
|
dialog.dismiss();
|
|
|
|
})
|
|
|
|
.show();
|
2020-10-12 12:14:13 -04:00
|
|
|
return;
|
2019-09-06 23:40:06 -04:00
|
|
|
}
|
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
this.recipient.observe(this, this::setRecipientText);
|
2017-06-06 18:03:09 -07:00
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Fingerprint>() {
|
|
|
|
@Override
|
|
|
|
protected Fingerprint doInBackground(Void... params) {
|
2019-11-04 09:03:18 -05:00
|
|
|
return new NumericFingerprintGenerator(5200).createFor(version,
|
|
|
|
localId, localIdentity,
|
|
|
|
remoteId, remoteIdentity);
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Fingerprint fingerprint) {
|
2021-08-27 15:56:54 -03:00
|
|
|
if (getActivity() == null) return;
|
2017-06-06 18:03:09 -07:00
|
|
|
VerifyDisplayFragment.this.fingerprint = fingerprint;
|
|
|
|
setFingerprintViews(fingerprint, true);
|
2017-06-19 10:39:15 -07:00
|
|
|
getActivity().supportInvalidateOptionsMenu();
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
2017-06-19 10:39:15 -07:00
|
|
|
|
|
|
|
setHasOptionsMenu(true);
|
2016-08-29 17:49:49 -07:00
|
|
|
}
|
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2019-08-07 14:22:51 -04:00
|
|
|
setRecipientText(recipient.get());
|
2017-06-06 18:03:09 -07:00
|
|
|
|
|
|
|
if (fingerprint != null) {
|
|
|
|
setFingerprintViews(fingerprint, false);
|
|
|
|
}
|
2016-08-24 18:51:45 -07:00
|
|
|
|
|
|
|
if (animateSuccessOnDraw) {
|
|
|
|
animateSuccessOnDraw = false;
|
|
|
|
animateVerifiedSuccess();
|
|
|
|
} else if (animateFailureOnDraw) {
|
|
|
|
animateFailureOnDraw = false;
|
2017-06-19 10:39:15 -07:00
|
|
|
animateVerifiedFailure();
|
2016-08-24 18:51:45 -07:00
|
|
|
}
|
2021-09-07 17:50:36 -03:00
|
|
|
|
|
|
|
ThreadUtil.postToMain(this::onScrollChanged);
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2016-11-14 19:50:29 -08:00
|
|
|
@Override
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View view,
|
|
|
|
ContextMenuInfo menuInfo)
|
|
|
|
{
|
|
|
|
super.onCreateContextMenu(menu, view, menuInfo);
|
|
|
|
|
2017-06-19 10:39:15 -07:00
|
|
|
if (fingerprint != null) {
|
|
|
|
MenuInflater inflater = getActivity().getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.verify_display_fragment_context_menu, menu);
|
|
|
|
}
|
2016-11-14 19:50:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
2017-06-19 10:39:15 -07:00
|
|
|
if (fingerprint == null) return super.onContextItemSelected(item);
|
|
|
|
|
2016-11-14 19:50:29 -08:00
|
|
|
switch (item.getItemId()) {
|
2017-06-19 10:39:15 -07:00
|
|
|
case R.id.menu_copy: handleCopyToClipboard(fingerprint, codes.length); return true;
|
|
|
|
case R.id.menu_compare: handleCompareWithClipboard(fingerprint); return true;
|
2016-11-14 19:50:29 -08:00
|
|
|
default: return super.onContextItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 10:39:15 -07:00
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
|
|
|
|
if (fingerprint != null) {
|
|
|
|
inflater.inflate(R.menu.verify_identity, menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.verify_identity__share: handleShare(fingerprint, codes.length); return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
public void setScannedFingerprint(String scanned) {
|
|
|
|
try {
|
|
|
|
if (fingerprint.getScannableFingerprint().compareTo(scanned.getBytes("ISO-8859-1"))) {
|
|
|
|
this.animateSuccessOnDraw = true;
|
|
|
|
} else {
|
|
|
|
this.animateFailureOnDraw = true;
|
|
|
|
}
|
|
|
|
} catch (FingerprintVersionMismatchException e) {
|
|
|
|
Log.w(TAG, e);
|
2016-11-13 10:58:51 -08:00
|
|
|
if (e.getOurVersion() < e.getTheirVersion()) {
|
|
|
|
Toast.makeText(getActivity(), R.string.VerifyIdentityActivity_your_contact_is_running_a_newer_version_of_Signal, Toast.LENGTH_LONG).show();
|
|
|
|
} else {
|
|
|
|
Toast.makeText(getActivity(), R.string.VerifyIdentityActivity_your_contact_is_running_an_old_version_of_signal, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
2021-09-07 17:50:36 -03:00
|
|
|
this.animateFailureOnDraw = true;
|
2021-05-24 09:42:19 -04:00
|
|
|
} catch (Exception e) {
|
2016-08-24 18:51:45 -07:00
|
|
|
Log.w(TAG, e);
|
2016-09-25 19:50:03 -07:00
|
|
|
Toast.makeText(getActivity(), R.string.VerifyIdentityActivity_the_scanned_qr_code_is_not_a_correctly_formatted_safety_number, Toast.LENGTH_LONG).show();
|
2021-09-07 17:50:36 -03:00
|
|
|
this.animateFailureOnDraw = true;
|
2016-08-24 18:51:45 -07:00
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
public void setClickListener(View.OnClickListener listener) {
|
|
|
|
this.clickListener = listener;
|
|
|
|
}
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2017-06-19 10:39:15 -07:00
|
|
|
private @NonNull String getFormattedSafetyNumbers(@NonNull Fingerprint fingerprint, int segmentCount) {
|
|
|
|
String[] segments = getSegments(fingerprint, segmentCount);
|
|
|
|
StringBuilder result = new StringBuilder();
|
2016-11-12 12:59:54 +01:00
|
|
|
|
2017-06-19 10:39:15 -07:00
|
|
|
for (int i = 0; i < segments.length; i++) {
|
|
|
|
result.append(segments[i]);
|
2016-11-12 12:59:54 +01:00
|
|
|
|
2017-06-19 10:39:15 -07:00
|
|
|
if (i != segments.length - 1) {
|
2016-11-12 12:59:54 +01:00
|
|
|
if (((i+1) % 4) == 0) result.append('\n');
|
|
|
|
else result.append(' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result.toString();
|
|
|
|
}
|
|
|
|
|
2017-06-19 10:39:15 -07:00
|
|
|
private void handleCopyToClipboard(Fingerprint fingerprint, int segmentCount) {
|
|
|
|
Util.writeTextToClipboard(getActivity(), getFormattedSafetyNumbers(fingerprint, segmentCount));
|
2016-11-14 19:50:29 -08:00
|
|
|
}
|
|
|
|
|
2017-06-19 10:39:15 -07:00
|
|
|
private void handleCompareWithClipboard(Fingerprint fingerprint) {
|
2016-11-14 19:50:29 -08:00
|
|
|
String clipboardData = Util.readTextFromClipboard(getActivity());
|
|
|
|
|
|
|
|
if (clipboardData == null) {
|
2016-11-26 21:40:25 +01:00
|
|
|
Toast.makeText(getActivity(), R.string.VerifyIdentityActivity_no_safety_number_to_compare_was_found_in_the_clipboard, Toast.LENGTH_LONG).show();
|
2016-11-14 19:50:29 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String numericClipboardData = clipboardData.replaceAll("\\D", "");
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(numericClipboardData) || numericClipboardData.length() != 60) {
|
2016-11-26 21:40:25 +01:00
|
|
|
Toast.makeText(getActivity(), R.string.VerifyIdentityActivity_no_safety_number_to_compare_was_found_in_the_clipboard, Toast.LENGTH_LONG).show();
|
2016-11-14 19:50:29 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fingerprint.getDisplayableFingerprint().getDisplayText().equals(numericClipboardData)) {
|
|
|
|
animateVerifiedSuccess();
|
|
|
|
} else {
|
|
|
|
animateVerifiedFailure();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 10:39:15 -07:00
|
|
|
private void handleShare(@NonNull Fingerprint fingerprint, int segmentCount) {
|
|
|
|
String shareString =
|
|
|
|
getString(R.string.VerifyIdentityActivity_our_signal_safety_number) + "\n" +
|
|
|
|
getFormattedSafetyNumbers(fingerprint, segmentCount) + "\n";
|
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setAction(Intent.ACTION_SEND);
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, shareString);
|
|
|
|
intent.setType("text/plain");
|
|
|
|
|
|
|
|
try {
|
|
|
|
startActivity(Intent.createChooser(intent, getString(R.string.VerifyIdentityActivity_share_safety_number_via)));
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
Toast.makeText(getActivity(), R.string.VerifyIdentityActivity_no_app_to_share_to, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
private void setRecipientText(Recipient recipient) {
|
2021-08-27 15:56:54 -03:00
|
|
|
description.setText(Html.fromHtml(String.format(getActivity().getString(R.string.verify_display_fragment__to_verify_the_security_of_your_end_to_end_encryption_with_s), recipient.getDisplayName(getContext()))));
|
2017-06-06 18:03:09 -07:00
|
|
|
description.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setFingerprintViews(Fingerprint fingerprint, boolean animate) {
|
2017-06-19 10:39:15 -07:00
|
|
|
String[] segments = getSegments(fingerprint, codes.length);
|
2016-08-24 18:51:45 -07:00
|
|
|
|
|
|
|
for (int i=0;i<codes.length;i++) {
|
2017-06-19 10:39:15 -07:00
|
|
|
if (animate) setCodeSegment(codes[i], segments[i]);
|
|
|
|
else codes[i].setText(segments[i]);
|
2016-08-24 18:51:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
byte[] qrCodeData = fingerprint.getScannableFingerprint().getSerialized();
|
|
|
|
String qrCodeString = new String(qrCodeData, Charset.forName("ISO-8859-1"));
|
|
|
|
Bitmap qrCodeBitmap = QrCode.create(qrCodeString);
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
qrCode.setImageBitmap(qrCodeBitmap);
|
2017-06-06 18:03:09 -07:00
|
|
|
|
|
|
|
if (animate) {
|
|
|
|
ViewUtil.fadeIn(qrCode, 1000);
|
|
|
|
ViewUtil.fadeIn(tapLabel, 1000);
|
2021-08-27 15:56:54 -03:00
|
|
|
ViewUtil.fadeOut(loading, 300, View.GONE);
|
2017-06-06 18:03:09 -07:00
|
|
|
} else {
|
|
|
|
qrCode.setVisibility(View.VISIBLE);
|
|
|
|
tapLabel.setVisibility(View.VISIBLE);
|
2021-08-27 15:56:54 -03:00
|
|
|
loading.setVisibility(View.GONE);
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setCodeSegment(final TextView codeView, String segment) {
|
2019-03-20 15:09:27 -07:00
|
|
|
ValueAnimator valueAnimator = new ValueAnimator();
|
|
|
|
valueAnimator.setObjectValues(0, Integer.parseInt(segment));
|
|
|
|
|
|
|
|
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationUpdate(ValueAnimator animation) {
|
|
|
|
int value = (int) animation.getAnimatedValue();
|
2019-07-17 14:07:39 -04:00
|
|
|
codeView.setText(String.format(Locale.getDefault(), "%05d", value));
|
2019-03-20 15:09:27 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
valueAnimator.setEvaluator(new TypeEvaluator<Integer>() {
|
|
|
|
public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
|
|
|
|
return Math.round(startValue + (endValue - startValue) * fraction);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
valueAnimator.setDuration(1000);
|
|
|
|
valueAnimator.start();
|
2012-07-23 13:42:29 -07:00
|
|
|
}
|
|
|
|
|
2017-06-19 10:39:15 -07:00
|
|
|
private String[] getSegments(Fingerprint fingerprint, int segmentCount) {
|
|
|
|
String[] segments = new String[segmentCount];
|
|
|
|
String digits = fingerprint.getDisplayableFingerprint().getDisplayText();
|
|
|
|
int partSize = digits.length() / segmentCount;
|
|
|
|
|
|
|
|
for (int i=0;i<segmentCount;i++) {
|
|
|
|
segments[i] = digits.substring(i * partSize, (i * partSize) + partSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
return segments;
|
|
|
|
}
|
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
private Bitmap createVerifiedBitmap(int width, int height, @DrawableRes int id) {
|
|
|
|
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
|
|
Canvas canvas = new Canvas(bitmap);
|
|
|
|
Bitmap check = BitmapFactory.decodeResource(getResources(), id);
|
|
|
|
float offset = (width - check.getWidth()) / 2;
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
canvas.drawBitmap(check, offset, offset, null);
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
return bitmap;
|
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
private void animateVerifiedSuccess() {
|
|
|
|
Bitmap qrBitmap = ((BitmapDrawable)qrCode.getDrawable()).getBitmap();
|
|
|
|
Bitmap qrSuccess = createVerifiedBitmap(qrBitmap.getWidth(), qrBitmap.getHeight(), R.drawable.ic_check_white_48dp);
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
qrVerified.setImageBitmap(qrSuccess);
|
|
|
|
qrVerified.getBackground().setColorFilter(getResources().getColor(R.color.green_500), PorterDuff.Mode.MULTIPLY);
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2021-08-27 15:56:54 -03:00
|
|
|
tapLabel.setText(getString(R.string.verify_display_fragment__successful_match));
|
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
animateVerified();
|
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
private void animateVerifiedFailure() {
|
|
|
|
Bitmap qrBitmap = ((BitmapDrawable)qrCode.getDrawable()).getBitmap();
|
|
|
|
Bitmap qrSuccess = createVerifiedBitmap(qrBitmap.getWidth(), qrBitmap.getHeight(), R.drawable.ic_close_white_48dp);
|
2011-12-20 10:20:44 -08:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
qrVerified.setImageBitmap(qrSuccess);
|
|
|
|
qrVerified.getBackground().setColorFilter(getResources().getColor(R.color.red_500), PorterDuff.Mode.MULTIPLY);
|
|
|
|
|
2021-08-27 15:56:54 -03:00
|
|
|
tapLabel.setText(getString(R.string.verify_display_fragment__failed_to_verify_safety_number));
|
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
animateVerified();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void animateVerified() {
|
|
|
|
ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1,
|
|
|
|
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
|
|
|
|
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
|
2021-08-27 15:56:54 -03:00
|
|
|
scaleAnimation.setInterpolator(new FastOutSlowInInterpolator());
|
2016-08-24 18:51:45 -07:00
|
|
|
scaleAnimation.setDuration(800);
|
|
|
|
scaleAnimation.setAnimationListener(new Animation.AnimationListener() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animation animation) {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animation animation) {
|
|
|
|
qrVerified.postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0, 1, 0,
|
|
|
|
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
|
|
|
|
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
|
|
|
|
|
|
|
|
scaleAnimation.setInterpolator(new AnticipateInterpolator());
|
|
|
|
scaleAnimation.setDuration(500);
|
|
|
|
ViewUtil.animateOut(qrVerified, scaleAnimation, View.GONE);
|
2021-08-27 15:56:54 -03:00
|
|
|
ViewUtil.fadeIn(qrCode, 800);
|
|
|
|
qrCodeContainer.setEnabled(true);
|
|
|
|
tapLabel.setText(getString(R.string.verify_display_fragment__tap_to_scan));
|
2016-08-24 18:51:45 -07:00
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animation animation) {}
|
|
|
|
});
|
|
|
|
|
2021-08-27 15:56:54 -03:00
|
|
|
ViewUtil.fadeOut(qrCode, 200, View.INVISIBLE);
|
2016-08-24 18:51:45 -07:00
|
|
|
ViewUtil.animateIn(qrVerified, scaleAnimation);
|
2021-08-27 15:56:54 -03:00
|
|
|
qrCodeContainer.setEnabled(false);
|
2016-08-24 18:51:45 -07:00
|
|
|
}
|
2017-06-06 18:03:09 -07:00
|
|
|
|
2021-08-27 15:56:54 -03:00
|
|
|
private void updateVerifyButton(boolean verified, boolean update) {
|
|
|
|
currentVerifiedState = verified;
|
2017-06-06 18:03:09 -07:00
|
|
|
|
2021-08-27 15:56:54 -03:00
|
|
|
if (verified) {
|
|
|
|
verifyButton.setText(R.string.verify_display_fragment__clear_verification);
|
|
|
|
} else {
|
|
|
|
verifyButton.setText(R.string.verify_display_fragment__mark_as_verified);
|
|
|
|
}
|
2017-06-06 18:03:09 -07:00
|
|
|
|
2021-08-27 15:56:54 -03:00
|
|
|
if (update) {
|
|
|
|
final RecipientId recipientId = recipient.getId();
|
|
|
|
|
|
|
|
SignalExecutors.BOUNDED.execute(() -> {
|
|
|
|
try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
|
|
|
|
if (verified) {
|
|
|
|
Log.i(TAG, "Saving identity: " + recipientId);
|
2021-09-01 09:41:49 -04:00
|
|
|
ApplicationDependencies.getIdentityStore()
|
|
|
|
.saveIdentityWithoutSideEffects(recipientId,
|
|
|
|
remoteIdentity,
|
|
|
|
VerifiedStatus.VERIFIED,
|
|
|
|
false,
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
true);
|
2021-08-27 15:56:54 -03:00
|
|
|
} else {
|
2021-09-01 09:41:49 -04:00
|
|
|
ApplicationDependencies.getIdentityStore().setVerified(recipientId, remoteIdentity, VerifiedStatus.DEFAULT);
|
2021-08-27 15:56:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
ApplicationDependencies.getJobManager()
|
|
|
|
.add(new MultiDeviceVerifiedUpdateJob(recipientId,
|
|
|
|
remoteIdentity,
|
|
|
|
verified ? VerifiedStatus.VERIFIED
|
|
|
|
: VerifiedStatus.DEFAULT));
|
|
|
|
StorageSyncHelper.scheduleSyncForDataChange();
|
|
|
|
|
|
|
|
IdentityUtil.markIdentityVerified(getActivity(), recipient.get(), verified, false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
2021-08-27 15:56:54 -03:00
|
|
|
|
2021-09-07 17:50:36 -03:00
|
|
|
|
|
|
|
@Override public void onScrollChanged() {
|
|
|
|
if (scrollView.canScrollVertically(-1)) {
|
|
|
|
if (toolbarShadow.getVisibility() != View.VISIBLE) {
|
|
|
|
ViewUtil.fadeIn(toolbarShadow, 250);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (toolbarShadow.getVisibility() != View.GONE) {
|
|
|
|
ViewUtil.fadeOut(toolbarShadow, 250);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scrollView.canScrollVertically(1)) {
|
|
|
|
if (bottomShadow.getVisibility() != View.VISIBLE) {
|
|
|
|
ViewUtil.fadeIn(bottomShadow, 250);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ViewUtil.fadeOut(bottomShadow, 250);
|
|
|
|
}
|
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2014-04-22 14:33:29 -07:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
public static class VerifyScanFragment extends Fragment {
|
|
|
|
|
|
|
|
private View container;
|
|
|
|
private CameraView cameraView;
|
2021-08-27 15:56:54 -03:00
|
|
|
private ShapeScrim cameraScrim;
|
|
|
|
private ImageView cameraMarks;
|
2016-08-24 18:51:45 -07:00
|
|
|
private ScanningThread scanningThread;
|
|
|
|
private ScanListener scanListener;
|
|
|
|
|
2019-05-22 13:51:56 -03:00
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
|
2021-08-27 15:56:54 -03:00
|
|
|
this.container = ViewUtil.inflate(inflater, viewGroup, R.layout.verify_scan_fragment);
|
|
|
|
this.cameraView = container.findViewById(R.id.scanner);
|
|
|
|
this.cameraScrim = container.findViewById(R.id.camera_scrim);
|
|
|
|
this.cameraMarks = container.findViewById(R.id.camera_marks);
|
|
|
|
|
|
|
|
OneShotPreDrawListener.add(cameraScrim, () -> {
|
|
|
|
int width = cameraScrim.getScrimWidth();
|
|
|
|
int height = cameraScrim.getScrimHeight();
|
|
|
|
|
|
|
|
ViewUtil.updateLayoutParams(cameraMarks, width, height);
|
|
|
|
});
|
2015-09-06 11:45:19 -07:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
return container;
|
2015-09-06 11:45:19 -07:00
|
|
|
}
|
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
this.scanningThread = new ScanningThread();
|
|
|
|
this.scanningThread.setScanListener(scanListener);
|
|
|
|
this.scanningThread.setCharacterSet("ISO-8859-1");
|
|
|
|
this.cameraView.onResume();
|
|
|
|
this.cameraView.setPreviewCallback(scanningThread);
|
|
|
|
this.scanningThread.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
this.cameraView.onPause();
|
|
|
|
this.scanningThread.stopScanning();
|
|
|
|
}
|
2014-04-22 14:33:29 -07:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfiguration) {
|
|
|
|
super.onConfigurationChanged(newConfiguration);
|
|
|
|
this.cameraView.onPause();
|
|
|
|
this.cameraView.onResume();
|
|
|
|
this.cameraView.setPreviewCallback(scanningThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setScanListener(ScanListener listener) {
|
|
|
|
if (this.scanningThread != null) scanningThread.setScanListener(listener);
|
|
|
|
this.scanListener = listener;
|
2014-04-22 14:33:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|