From cc6a001ac21e7334e4cd54bdb78dfba2879b54f0 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 15 Dec 2017 18:25:21 +0100 Subject: [PATCH] remove NFC handling + let edit account handle own jids --- src/main/AndroidManifest.xml | 4 +- .../persistance/DatabaseBackend.java | 2 +- .../conversations/ui/EditAccountActivity.java | 36 +++++++++++++- .../ui/StartConversationActivity.java | 9 ---- .../conversations/ui/UriHandlerActivity.java | 49 ++++--------------- 5 files changed, 46 insertions(+), 54 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 344eb0545..28b6d0bbe 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -59,7 +59,8 @@ + android:launchMode="singleTop" + android:theme="@android:style/Theme.Translucent.NoTitleBar"> @@ -80,7 +81,6 @@ - diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index 39b71e849..3caf41299 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -746,7 +746,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { return getAccounts(db); } - public Collection getAccountJids() { + public List getAccountJids() { SQLiteDatabase db = this.getReadableDatabase(); final List jids = new ArrayList<>(); final String[] columns = new String[]{Account.USERNAME, Account.SERVER}; diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index cd5a2276d..78aa95310 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -271,6 +271,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat private String mSavedInstanceAccount; private boolean mSavedInstanceInit = false; private Button mClearDevicesButton; + private XmppUri pendingUri = null; public void refreshUiReal() { invalidateOptionsMenu(); @@ -403,11 +404,16 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat @Override protected void processFingerprintVerification(XmppUri uri) { + processFingerprintVerification(uri,true); + } + + + protected void processFingerprintVerification(XmppUri uri, boolean showWarningToast) { if (mAccount != null && mAccount.getJid().toBareJid().equals(uri.getJid()) && uri.hasFingerprints()) { if (xmppConnectionService.verifyFingerprints(mAccount,uri.getFingerprints())) { Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show(); } - } else { + } else if (showWarningToast) { Toast.makeText(this,R.string.invalid_barcode,Toast.LENGTH_SHORT).show(); } } @@ -635,6 +641,14 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } catch (final InvalidJidException | NullPointerException ignored) { this.jidToEdit = null; } + if (jidToEdit != null && getIntent().getData() != null) { + final XmppUri uri = new XmppUri(getIntent().getData()); + if (xmppConnectionServiceBound) { + processFingerprintVerification(uri, false); + } else { + this.pendingUri = uri; + } + } boolean init = getIntent().getBooleanExtra("init", false); this.mInitMode = init || this.jidToEdit == null; this.messageFingerprint = getIntent().getStringExtra("fingerprint"); @@ -662,6 +676,18 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE); } + @Override + public void onNewIntent(Intent intent) { + if (intent != null && intent.getData() != null) { + final XmppUri uri = new XmppUri(intent.getData()); + if (xmppConnectionServiceBound) { + processFingerprintVerification(uri, false); + } else { + this.pendingUri = uri; + } + } + } + @Override public void onSaveInstanceState(final Bundle savedInstanceState) { if (mAccount != null) { @@ -697,7 +723,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } } if (mPendingFingerprintVerificationUri != null) { - processFingerprintVerification(mPendingFingerprintVerificationUri); + processFingerprintVerification(mPendingFingerprintVerificationUri, false); mPendingFingerprintVerificationUri = null; } updateAccountInformation(init); @@ -717,6 +743,12 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat xmppConnectionService.getKnownHosts()); this.mAccountJid.setAdapter(mKnownHostsAdapter); } + + if (pendingUri != null) { + processFingerprintVerification(pendingUri, false); + pendingUri = null; + } + updateSaveButton(); invalidateOptionsMenu(); } diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 912c19712..702350105 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -821,15 +821,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } private boolean handleJid(Invite invite) { - Account account = xmppConnectionService.findAccountByJid(invite.getJid()); - if (account != null && account.isEnabled()) { - if (invite.hasFingerprints() && xmppConnectionService.verifyFingerprints(account,invite.getFingerprints())) { - Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show(); - } - switchToAccount(account); - finish(); - return true; - } List contacts = xmppConnectionService.findContacts(invite.getJid(),invite.account); if (invite.isAction(XmppUri.ACTION_JOIN)) { Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid()); diff --git a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java index 9ffa1b11f..d28c1b340 100644 --- a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java @@ -1,19 +1,14 @@ package eu.siacs.conversations.ui; -import android.annotation.TargetApi; import android.app.Activity; import android.content.Intent; import android.net.Uri; -import android.nfc.NdefMessage; -import android.nfc.NdefRecord; -import android.nfc.NfcAdapter; -import android.os.Build; -import android.os.Parcelable; import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentResult; import java.util.Arrays; +import java.util.List; import eu.siacs.conversations.persistance.DatabaseBackend; import eu.siacs.conversations.utils.XmppUri; @@ -33,17 +28,12 @@ public class UriHandlerActivity extends Activity { handleIntent(intent); } - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - Uri getInviteJellyBean(NdefRecord record) { - return record.toUri(); - } - private void handleUri(Uri uri) { final Intent intent; final XmppUri xmppUri = new XmppUri(uri); - final int numAccounts = DatabaseBackend.getInstance(this).getAccountJids().size(); + final List accounts = DatabaseBackend.getInstance(this).getAccountJids(); - if (numAccounts == 0) { + if (accounts.size() == 0) { intent = new Intent(getApplicationContext(), WelcomeActivity.class); startActivity(intent); return; @@ -63,6 +53,11 @@ public class UriHandlerActivity extends Activity { intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, body); } + } else if (accounts.contains(xmppUri.getJid())) { + intent = new Intent(getApplicationContext(), EditAccountActivity.class); + intent.setAction(Intent.ACTION_VIEW); + intent.putExtra("jid", xmppUri.getJid().toBareJid().toString()); + intent.setData(uri); } else { intent = new Intent(getApplicationContext(), StartConversationActivity.class); intent.setAction(Intent.ACTION_VIEW); @@ -73,32 +68,8 @@ public class UriHandlerActivity extends Activity { startActivity(intent); } - private void handleNfcIntent(Intent data) { - for (Parcelable message : data.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) { - if (message instanceof NdefMessage) { - for (NdefRecord record : ((NdefMessage) message).getRecords()) { - switch (record.getTnf()) { - case NdefRecord.TNF_WELL_KNOWN: - if (Arrays.equals(record.getType(), NdefRecord.RTD_URI)) { - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - handleUri(getInviteJellyBean(record)); - } else { - byte[] payload = record.getPayload(); - if (payload[0] == 0) { - Uri uri = Uri.parse(new String(Arrays.copyOfRange( - payload, 1, payload.length))); - handleUri(uri); - } - } - } - } - } - } - } - } - private void handleIntent(Intent data) { - if (data == null) { + if (data == null || data.getAction() == null) { finish(); return; } @@ -111,8 +82,6 @@ public class UriHandlerActivity extends Activity { case ACTION_SCAN_QR_CODE: new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC", "QR_CODE")); return; - case NfcAdapter.ACTION_NDEF_DISCOVERED: - handleNfcIntent(data); } finish();