remove NFC handling + let edit account handle own jids

This commit is contained in:
Daniel Gultsch 2017-12-15 18:25:21 +01:00
parent 6a9abd0e49
commit cc6a001ac2
5 changed files with 46 additions and 54 deletions

View file

@ -59,7 +59,8 @@
<activity <activity
android:name=".ui.UriHandlerActivity" android:name=".ui.UriHandlerActivity"
android:label="@string/title_activity_start_conversation" android:label="@string/title_activity_start_conversation"
android:launchMode="singleTop"> android:launchMode="singleTop"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
@ -80,7 +81,6 @@
<data android:pathPrefix="/j/" /> <data android:pathPrefix="/j/" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<action android:name="android.intent.action.SENDTO" /> <action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />

View file

@ -746,7 +746,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return getAccounts(db); return getAccounts(db);
} }
public Collection<Jid> getAccountJids() { public List<Jid> getAccountJids() {
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
final List<Jid> jids = new ArrayList<>(); final List<Jid> jids = new ArrayList<>();
final String[] columns = new String[]{Account.USERNAME, Account.SERVER}; final String[] columns = new String[]{Account.USERNAME, Account.SERVER};

View file

@ -271,6 +271,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private String mSavedInstanceAccount; private String mSavedInstanceAccount;
private boolean mSavedInstanceInit = false; private boolean mSavedInstanceInit = false;
private Button mClearDevicesButton; private Button mClearDevicesButton;
private XmppUri pendingUri = null;
public void refreshUiReal() { public void refreshUiReal() {
invalidateOptionsMenu(); invalidateOptionsMenu();
@ -403,11 +404,16 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
@Override @Override
protected void processFingerprintVerification(XmppUri uri) { 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 (mAccount != null && mAccount.getJid().toBareJid().equals(uri.getJid()) && uri.hasFingerprints()) {
if (xmppConnectionService.verifyFingerprints(mAccount,uri.getFingerprints())) { if (xmppConnectionService.verifyFingerprints(mAccount,uri.getFingerprints())) {
Toast.makeText(this,R.string.verified_fingerprints,Toast.LENGTH_SHORT).show(); 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(); 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) { } catch (final InvalidJidException | NullPointerException ignored) {
this.jidToEdit = null; 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); boolean init = getIntent().getBooleanExtra("init", false);
this.mInitMode = init || this.jidToEdit == null; this.mInitMode = init || this.jidToEdit == null;
this.messageFingerprint = getIntent().getStringExtra("fingerprint"); this.messageFingerprint = getIntent().getStringExtra("fingerprint");
@ -662,6 +676,18 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE); 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 @Override
public void onSaveInstanceState(final Bundle savedInstanceState) { public void onSaveInstanceState(final Bundle savedInstanceState) {
if (mAccount != null) { if (mAccount != null) {
@ -697,7 +723,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} }
} }
if (mPendingFingerprintVerificationUri != null) { if (mPendingFingerprintVerificationUri != null) {
processFingerprintVerification(mPendingFingerprintVerificationUri); processFingerprintVerification(mPendingFingerprintVerificationUri, false);
mPendingFingerprintVerificationUri = null; mPendingFingerprintVerificationUri = null;
} }
updateAccountInformation(init); updateAccountInformation(init);
@ -717,6 +743,12 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
xmppConnectionService.getKnownHosts()); xmppConnectionService.getKnownHosts());
this.mAccountJid.setAdapter(mKnownHostsAdapter); this.mAccountJid.setAdapter(mKnownHostsAdapter);
} }
if (pendingUri != null) {
processFingerprintVerification(pendingUri, false);
pendingUri = null;
}
updateSaveButton(); updateSaveButton();
invalidateOptionsMenu(); invalidateOptionsMenu();
} }

View file

@ -821,15 +821,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
private boolean handleJid(Invite invite) { 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<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(),invite.account); List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(),invite.account);
if (invite.isAction(XmppUri.ACTION_JOIN)) { if (invite.isAction(XmppUri.ACTION_JOIN)) {
Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid()); Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());

View file

@ -1,19 +1,14 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; 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.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult; import com.google.zxing.integration.android.IntentResult;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import eu.siacs.conversations.persistance.DatabaseBackend; import eu.siacs.conversations.persistance.DatabaseBackend;
import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.utils.XmppUri;
@ -33,17 +28,12 @@ public class UriHandlerActivity extends Activity {
handleIntent(intent); handleIntent(intent);
} }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
Uri getInviteJellyBean(NdefRecord record) {
return record.toUri();
}
private void handleUri(Uri uri) { private void handleUri(Uri uri) {
final Intent intent; final Intent intent;
final XmppUri xmppUri = new XmppUri(uri); final XmppUri xmppUri = new XmppUri(uri);
final int numAccounts = DatabaseBackend.getInstance(this).getAccountJids().size(); final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids();
if (numAccounts == 0) { if (accounts.size() == 0) {
intent = new Intent(getApplicationContext(), WelcomeActivity.class); intent = new Intent(getApplicationContext(), WelcomeActivity.class);
startActivity(intent); startActivity(intent);
return; return;
@ -63,6 +53,11 @@ public class UriHandlerActivity extends Activity {
intent.setType("text/plain"); intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, body); 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 { } else {
intent = new Intent(getApplicationContext(), StartConversationActivity.class); intent = new Intent(getApplicationContext(), StartConversationActivity.class);
intent.setAction(Intent.ACTION_VIEW); intent.setAction(Intent.ACTION_VIEW);
@ -73,32 +68,8 @@ public class UriHandlerActivity extends Activity {
startActivity(intent); 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) { private void handleIntent(Intent data) {
if (data == null) { if (data == null || data.getAction() == null) {
finish(); finish();
return; return;
} }
@ -111,8 +82,6 @@ public class UriHandlerActivity extends Activity {
case ACTION_SCAN_QR_CODE: case ACTION_SCAN_QR_CODE:
new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC", "QR_CODE")); new IntentIntegrator(this).initiateScan(Arrays.asList("AZTEC", "QR_CODE"));
return; return;
case NfcAdapter.ACTION_NDEF_DISCOVERED:
handleNfcIntent(data);
} }
finish(); finish();