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;
|
2016-09-04 02:08:02 +02:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2017-06-06 18:03:09 -07:00
|
|
|
import android.os.AsyncTask;
|
2016-09-04 02:08:02 +02:00
|
|
|
import android.os.Build;
|
2011-12-20 10:20:44 -08:00
|
|
|
import android.os.Bundle;
|
2016-08-24 18:51:45 -07:00
|
|
|
import android.os.Vibrator;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.DrawableRes;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
|
|
import androidx.appcompat.widget.SwitchCompat;
|
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;
|
|
|
|
import android.view.animation.Animation;
|
|
|
|
import android.view.animation.AnticipateInterpolator;
|
|
|
|
import android.view.animation.OvershootInterpolator;
|
|
|
|
import android.view.animation.ScaleAnimation;
|
2017-06-06 18:03:09 -07:00
|
|
|
import android.widget.CompoundButton;
|
2016-08-24 18:51:45 -07:00
|
|
|
import android.widget.ImageView;
|
2011-12-20 10:20:44 -08:00
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2016-09-04 02:08:02 +02:00
|
|
|
import org.thoughtcrime.securesms.color.MaterialColor;
|
2016-08-24 18:51:45 -07:00
|
|
|
import org.thoughtcrime.securesms.components.camera.CameraView;
|
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;
|
2017-07-26 09:59:15 -07:00
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2017-06-06 18:03:09 -07:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus;
|
|
|
|
import org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob;
|
2019-07-24 12:30:23 +10:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
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;
|
2013-11-25 17:00:20 -08:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2017-08-01 08:56:00 -07:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
2016-08-24 18:51:45 -07:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
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.FingerprintParsingException;
|
|
|
|
import org.whispersystems.libsignal.fingerprint.FingerprintVersionMismatchException;
|
|
|
|
import org.whispersystems.libsignal.fingerprint.NumericFingerprintGenerator;
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.nio.charset.Charset;
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
import static org.whispersystems.libsignal.SessionCipher.SESSION_LOCK;
|
|
|
|
|
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")
|
2017-08-01 08:56:00 -07:00
|
|
|
public class VerifyIdentityActivity extends PassphraseRequiredActionBarActivity implements RecipientModifiedListener, ScanListener, View.OnClickListener {
|
2016-08-24 18:51:45 -07:00
|
|
|
|
|
|
|
private static final String TAG = VerifyIdentityActivity.class.getSimpleName();
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2017-07-26 09:59:15 -07:00
|
|
|
public static final String ADDRESS_EXTRA = "address";
|
|
|
|
public static final String IDENTITY_EXTRA = "recipient_identity";
|
|
|
|
public static final String VERIFIED_EXTRA = "verified_state";
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
|
|
|
private VerifyDisplayFragment displayFragment = new VerifyDisplayFragment();
|
|
|
|
private VerifyScanFragment scanFragment = new VerifyScanFragment();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreCreate() {
|
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.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
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
getSupportActionBar().setTitle(R.string.AndroidManifest__verify_safety_number);
|
|
|
|
|
2017-08-21 18:32:38 -07:00
|
|
|
Recipient recipient = Recipient.from(this, (Address)getIntent().getParcelableExtra(ADDRESS_EXTRA), true);
|
2017-07-26 09:59:15 -07:00
|
|
|
recipient.addListener(this);
|
|
|
|
|
|
|
|
setActionBarNotificationBarColor(recipient.getColor());
|
|
|
|
|
|
|
|
Bundle extras = new Bundle();
|
|
|
|
extras.putParcelable(VerifyDisplayFragment.REMOTE_ADDRESS, getIntent().getParcelableExtra(ADDRESS_EXTRA));
|
|
|
|
extras.putParcelable(VerifyDisplayFragment.REMOTE_IDENTITY, getIntent().getParcelableExtra(IDENTITY_EXTRA));
|
|
|
|
extras.putString(VerifyDisplayFragment.REMOTE_NUMBER, recipient.getAddress().toPhoneString());
|
|
|
|
extras.putParcelable(VerifyDisplayFragment.LOCAL_IDENTITY, new IdentityKeyParcelable(IdentityKeyUtil.getIdentityKey(this)));
|
|
|
|
extras.putString(VerifyDisplayFragment.LOCAL_NUMBER, TextSecurePreferences.getLocalNumber(this));
|
|
|
|
extras.putBoolean(VerifyDisplayFragment.VERIFIED_STATE, getIntent().getBooleanExtra(VERIFIED_EXTRA, false));
|
|
|
|
|
|
|
|
scanFragment.setScanListener(this);
|
|
|
|
displayFragment.setClickListener(this);
|
|
|
|
|
2018-02-01 19:22:48 -08:00
|
|
|
initFragment(android.R.id.content, displayFragment, dynamicLanguage.getCurrentLocale(), 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-09-04 02:08:02 +02:00
|
|
|
@Override
|
|
|
|
public void onModified(final Recipient recipient) {
|
2017-11-24 22:00:30 -08:00
|
|
|
Util.runOnMain(() -> setActionBarNotificationBarColor(recipient.getColor()));
|
2016-09-04 02:08:02 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
@Override
|
|
|
|
public void onQrDataFound(final String data) {
|
2017-11-24 22:00:30 -08:00
|
|
|
Util.runOnMain(() -> {
|
|
|
|
((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)
|
|
|
|
.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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-09-04 02:08:02 +02:00
|
|
|
private void setActionBarNotificationBarColor(MaterialColor color) {
|
|
|
|
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color.toActionBarColor(this)));
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
getWindow().setStatusBarColor(color.toStatusBarColor(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-01 08:56:00 -07:00
|
|
|
public static class VerifyDisplayFragment extends Fragment implements RecipientModifiedListener, CompoundButton.OnCheckedChangeListener {
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2017-07-26 09:59:15 -07:00
|
|
|
public static final String REMOTE_ADDRESS = "remote_address";
|
|
|
|
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
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
private Recipient recipient;
|
|
|
|
private String localNumber;
|
|
|
|
private String remoteNumber;
|
2016-08-24 18:51:45 -07:00
|
|
|
|
|
|
|
private IdentityKey localIdentity;
|
|
|
|
private IdentityKey remoteIdentity;
|
|
|
|
|
|
|
|
private Fingerprint fingerprint;
|
|
|
|
|
|
|
|
private View container;
|
2016-11-14 19:50:29 -08:00
|
|
|
private View numbersContainer;
|
2016-08-24 18:51:45 -07:00
|
|
|
private ImageView qrCode;
|
|
|
|
private ImageView qrVerified;
|
2017-06-06 18:03:09 -07:00
|
|
|
private TextView tapLabel;
|
2016-08-29 17:49:49 -07:00
|
|
|
private TextView description;
|
2016-08-24 18:51:45 -07:00
|
|
|
private View.OnClickListener clickListener;
|
2017-06-06 18:03:09 -07:00
|
|
|
private SwitchCompat verified;
|
2016-08-24 18:51:45 -07:00
|
|
|
|
|
|
|
private TextView[] codes = new TextView[12];
|
|
|
|
private boolean animateSuccessOnDraw = false;
|
|
|
|
private boolean animateFailureOnDraw = false;
|
|
|
|
|
|
|
|
@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);
|
|
|
|
this.numbersContainer = ViewUtil.findById(container, R.id.number_table);
|
|
|
|
this.qrCode = ViewUtil.findById(container, R.id.qr_code);
|
2017-06-06 18:03:09 -07:00
|
|
|
this.verified = ViewUtil.findById(container, R.id.verified_switch);
|
2016-11-14 19:50:29 -08:00
|
|
|
this.qrVerified = ViewUtil.findById(container, R.id.qr_verified);
|
|
|
|
this.description = ViewUtil.findById(container, R.id.description);
|
2017-06-06 18:03:09 -07:00
|
|
|
this.tapLabel = ViewUtil.findById(container, R.id.tap_label);
|
2016-11-14 19:50:29 -08:00
|
|
|
this.codes[0] = ViewUtil.findById(container, R.id.code_first);
|
|
|
|
this.codes[1] = ViewUtil.findById(container, R.id.code_second);
|
|
|
|
this.codes[2] = ViewUtil.findById(container, R.id.code_third);
|
|
|
|
this.codes[3] = ViewUtil.findById(container, R.id.code_fourth);
|
|
|
|
this.codes[4] = ViewUtil.findById(container, R.id.code_fifth);
|
|
|
|
this.codes[5] = ViewUtil.findById(container, R.id.code_sixth);
|
|
|
|
this.codes[6] = ViewUtil.findById(container, R.id.code_seventh);
|
|
|
|
this.codes[7] = ViewUtil.findById(container, R.id.code_eighth);
|
|
|
|
this.codes[8] = ViewUtil.findById(container, R.id.code_ninth);
|
|
|
|
this.codes[9] = ViewUtil.findById(container, R.id.code_tenth);
|
|
|
|
this.codes[10] = ViewUtil.findById(container, R.id.code_eleventh);
|
|
|
|
this.codes[11] = ViewUtil.findById(container, R.id.code_twelth);
|
2016-08-24 18:51:45 -07:00
|
|
|
|
|
|
|
this.qrCode.setOnClickListener(clickListener);
|
2016-11-14 19:50:29 -08:00
|
|
|
this.registerForContextMenu(numbersContainer);
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
this.verified.setChecked(getArguments().getBoolean(VERIFIED_STATE, false));
|
|
|
|
this.verified.setOnCheckedChangeListener(this);
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-07-26 09:59:15 -07:00
|
|
|
Address address = getArguments().getParcelable(REMOTE_ADDRESS);
|
|
|
|
IdentityKeyParcelable localIdentityParcelable = getArguments().getParcelable(LOCAL_IDENTITY);
|
|
|
|
IdentityKeyParcelable remoteIdentityParcelable = getArguments().getParcelable(REMOTE_IDENTITY);
|
|
|
|
|
|
|
|
if (address == null) throw new AssertionError("Address required");
|
|
|
|
if (localIdentityParcelable == null) throw new AssertionError("local identity required");
|
|
|
|
if (remoteIdentityParcelable == null) throw new AssertionError("remote identity required");
|
|
|
|
|
2016-08-24 18:51:45 -07:00
|
|
|
this.localNumber = getArguments().getString(LOCAL_NUMBER);
|
2017-07-26 09:59:15 -07:00
|
|
|
this.localIdentity = localIdentityParcelable.get();
|
2016-08-24 18:51:45 -07:00
|
|
|
this.remoteNumber = getArguments().getString(REMOTE_NUMBER);
|
2017-08-21 18:32:38 -07:00
|
|
|
this.recipient = Recipient.from(getActivity(), address, true);
|
2017-07-26 09:59:15 -07:00
|
|
|
this.remoteIdentity = remoteIdentityParcelable.get();
|
2016-08-29 17:49:49 -07:00
|
|
|
|
|
|
|
this.recipient.addListener(this);
|
2017-06-06 18:03:09 -07:00
|
|
|
|
|
|
|
new AsyncTask<Void, Void, Fingerprint>() {
|
|
|
|
@Override
|
|
|
|
protected Fingerprint doInBackground(Void... params) {
|
|
|
|
return new NumericFingerprintGenerator(5200).createFor(localNumber, localIdentity,
|
|
|
|
remoteNumber, remoteIdentity);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Fingerprint fingerprint) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-06-06 18:03:09 -07:00
|
|
|
public void onModified(final Recipient recipient) {
|
2017-11-24 22:00:30 -08:00
|
|
|
Util.runOnMain(() -> setRecipientText(recipient));
|
2016-08-24 18:51:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2017-06-06 18:03:09 -07:00
|
|
|
setRecipientText(recipient);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|
2012-07-23 13:42:29 -07:00
|
|
|
|
2016-08-29 17:49:49 -07:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
recipient.removeListener(this);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
2016-08-24 18:51:45 -07:00
|
|
|
} catch (FingerprintParsingException e) {
|
|
|
|
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();
|
2016-08-24 18:51:45 -07:00
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
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) {
|
|
|
|
description.setText(Html.fromHtml(String.format(getActivity().getString(R.string.verify_display_fragment__if_you_wish_to_verify_the_security_of_your_end_to_end_encryption_with_s), recipient.toShortString())));
|
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
qrCode.setVisibility(View.VISIBLE);
|
|
|
|
tapLabel.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
|
|
|
|
@Override
|
|
|
|
public void onAnimationUpdate(ValueAnimator animation) {
|
|
|
|
int value = (int) animation.getAnimatedValue();
|
|
|
|
codeView.setText(String.format("%05d", value));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
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);
|
|
|
|
|
|
|
|
animateVerified();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void animateVerified() {
|
|
|
|
ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1,
|
|
|
|
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
|
|
|
|
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
|
|
|
|
scaleAnimation.setInterpolator(new OvershootInterpolator());
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animation animation) {}
|
|
|
|
});
|
|
|
|
|
|
|
|
ViewUtil.animateIn(qrVerified, scaleAnimation);
|
|
|
|
}
|
2017-06-06 18:03:09 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, final boolean isChecked) {
|
|
|
|
new AsyncTask<Recipient, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Recipient... params) {
|
|
|
|
synchronized (SESSION_LOCK) {
|
|
|
|
if (isChecked) {
|
2018-08-02 09:25:33 -04:00
|
|
|
Log.i(TAG, "Saving identity: " + params[0].getAddress());
|
2017-06-06 18:03:09 -07:00
|
|
|
DatabaseFactory.getIdentityDatabase(getActivity())
|
2017-07-26 09:59:15 -07:00
|
|
|
.saveIdentity(params[0].getAddress(),
|
2017-06-06 18:03:09 -07:00
|
|
|
remoteIdentity,
|
|
|
|
VerifiedStatus.VERIFIED, false,
|
|
|
|
System.currentTimeMillis(), true);
|
|
|
|
} else {
|
|
|
|
DatabaseFactory.getIdentityDatabase(getActivity())
|
2017-07-26 09:59:15 -07:00
|
|
|
.setVerified(params[0].getAddress(),
|
2017-06-06 18:03:09 -07:00
|
|
|
remoteIdentity,
|
|
|
|
VerifiedStatus.DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
ApplicationContext.getInstance(getActivity())
|
|
|
|
.getJobManager()
|
2019-03-28 08:56:35 -07:00
|
|
|
.add(new MultiDeviceVerifiedUpdateJob(recipient.getAddress(),
|
2017-06-06 18:03:09 -07:00
|
|
|
remoteIdentity,
|
|
|
|
isChecked ? VerifiedStatus.VERIFIED :
|
|
|
|
VerifiedStatus.DEFAULT));
|
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
IdentityUtil.markIdentityVerified(getActivity(), recipient, isChecked, false);
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 13:03:32 -07:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, recipient);
|
2017-06-06 18:03:09 -07:00
|
|
|
}
|
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;
|
|
|
|
private ScanningThread scanningThread;
|
|
|
|
private ScanListener scanListener;
|
|
|
|
|
2019-05-22 13:51:56 -03:00
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle bundle) {
|
2016-08-24 18:51:45 -07:00
|
|
|
this.container = ViewUtil.inflate(inflater, viewGroup, R.layout.verify_scan_fragment);
|
|
|
|
this.cameraView = ViewUtil.findById(container, R.id.scanner);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-08-24 18:51:45 -07:00
|
|
|
|
2011-12-20 10:20:44 -08:00
|
|
|
}
|