From f21fda1421f29173790af9741c703b64246eb746 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 13 Mar 2018 16:55:25 +0100 Subject: [PATCH] scanned results are always a trusted source --- .../conversations/ui/StartConversationActivity.java | 10 +++++----- .../siacs/conversations/ui/UriHandlerActivity.java | 13 +++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index a01265ef4..83f13a734 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -273,7 +273,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU try { Jid jid = Jid.of(searchString); if (jid.getLocal() != null && jid.isBareJid() && jid.getDomain().contains(".")) { - showCreateContactDialog(jid.toString(),null); + showCreateContactDialog(jid.toString(), null); return; } } catch (IllegalArgumentException ignored) { @@ -475,7 +475,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } else if (contact.showInRoster()) { throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists)); } else { - xmppConnectionService.createContact(contact,true); + xmppConnectionService.createContact(contact, true); if (invite != null && invite.hasFingerprints()) { xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints()); } @@ -494,7 +494,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null); final Spinner spinner = dialogView.findViewById(R.id.account); final AutoCompleteTextView jid = dialogView.findViewById(R.id.jid); - DelayedHintHelper.setHint(R.string.conference_address_example,jid); + DelayedHintHelper.setHint(R.string.conference_address_example, jid); jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts)); if (prefilledJid != null) { jid.append(prefilledJid); @@ -752,7 +752,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { if (grantResults.length > 0) if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - ScanActivity.onRequestPermissionResult(this,requestCode,grantResults); + ScanActivity.onRequestPermissionResult(this, requestCode, grantResults); if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) { xmppConnectionService.loadPhoneContacts(); } @@ -821,7 +821,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU case Intent.ACTION_VIEW: Uri uri = intent.getData(); if (uri != null) { - Invite invite = new Invite(intent.getData(), false); + Invite invite = new Invite(intent.getData(), intent.getBooleanExtra("scanned", false)); invite.account = intent.getStringExtra("account"); return invite.invite(); } else { diff --git a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java index e51f59247..793cc3d63 100644 --- a/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/UriHandlerActivity.java @@ -53,7 +53,7 @@ public class UriHandlerActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - this.handled = savedInstanceState != null && savedInstanceState.getBoolean("handled",false); + this.handled = savedInstanceState != null && savedInstanceState.getBoolean("handled", false); } @Override @@ -74,6 +74,10 @@ public class UriHandlerActivity extends AppCompatActivity { } private void handleUri(Uri uri) { + handleUri(uri, false); + } + + private void handleUri(Uri uri, final boolean scanned) { final Intent intent; final XmppUri xmppUri = new XmppUri(uri); final List accounts = DatabaseBackend.getInstance(this).getAccountJids(); //TODO only look at enabled accounts @@ -104,13 +108,14 @@ public class UriHandlerActivity extends AppCompatActivity { intent.setAction(Intent.ACTION_VIEW); intent.putExtra("jid", xmppUri.getJid().asBareJid().toString()); intent.setData(uri); - } else if (xmppUri.isJidValid()){ + } else if (xmppUri.isJidValid()) { intent = new Intent(getApplicationContext(), StartConversationActivity.class); intent.setAction(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + intent.putExtra("scanned", scanned); intent.setData(uri); } else { - Toast.makeText(this,R.string.invalid_jid,Toast.LENGTH_SHORT).show(); + Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show(); return; } @@ -149,7 +154,7 @@ public class UriHandlerActivity extends AppCompatActivity { String result = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT); if (result != null) { Uri uri = Uri.parse(result); - handleUri(uri); + handleUri(uri, true); } } finish();